Waiting turns stay quiet; Connections page updates live
Turns waiting for a connection, and those queued behind them, show no thinking line or timer: a quiet "Waiting for a connection" under each message and one card after them; they run in order once a connection is usable, and Recover no longer restarts them. The Connections page shows its card the moment Add is tapped, the three-step Codex and Claude cards with Copy, and lands an approval in place. No page reloads itself any more; the event stream drives both pages. Kept-session logs only on change or hourly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 files changed,
+740
−80
docs/mockups/built/2026-11-08/conn-claude-terminal-1280.pngbinarydocs/mockups/built/2026-11-08/conn-claude-terminal-390.pngbinarydocs/mockups/built/2026-11-08/conn-codex-code-1280.pngbinarydocs/mockups/built/2026-11-08/conn-codex-code-390.pngbinarydocs/mockups/built/2026-11-08/conn-codex-connected-1280.pngbinarydocs/mockups/built/2026-11-08/conn-codex-connected-390.pngbinarydocs/mockups/built/2026-11-08/conn-waiting-1280.pngbinarydocs/mockups/built/2026-11-08/conn-waiting-390.pngbinarydocs/superpowers/plans/CONN1-PROGRESS.md+64 −9docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+27 −4internal/equipo/app.go+1 −0internal/equipo/chat/connections.go+21 −0internal/equipo/chat_connections.go+85 −11internal/equipo/chat_page.go+29 −8internal/equipo/copy.go+27 −4internal/equipo/handlers.go+1 −0internal/equipo/render.go+1 −1internal/equipo/static/chat-stream.js+38 −11internal/equipo/static/connections.js+173 −0internal/equipo/static/equipo.css+30 −0internal/equipo/templates/chat.html+1 −0internal/equipo/templates/chrome.html+1 −1internal/equipo/templates/models.html+36 −12internal/headless/browser_connections_test.go+95 −15internal/headless/connections_test.go+6 −2internal/runner/thin/ask.go+10 −1internal/runner/thin/engineer.go+6 −0internal/runner/thin/state.go+9 −0internal/runner/thin/waiting_test.go+50 −0scripts/runner-reference-allowlist.json+29 −1
CI passed — run details
Intent
diff --git a/docs/mockups/built/2026-11-08/conn-claude-terminal-1280.png b/docs/mockups/built/2026-11-08/conn-claude-terminal-1280.png| new file mode 100644 |
| index 00000000..0ad4dbb9 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-claude-terminal-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-claude-terminal-390.png b/docs/mockups/built/2026-11-08/conn-claude-terminal-390.png| new file mode 100644 |
| index 00000000..4ec86333 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-claude-terminal-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-codex-code-1280.png b/docs/mockups/built/2026-11-08/conn-codex-code-1280.png| new file mode 100644 |
| index 00000000..74c51915 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-codex-code-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-codex-code-390.png b/docs/mockups/built/2026-11-08/conn-codex-code-390.png| new file mode 100644 |
| index 00000000..facd0537 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-codex-code-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-codex-connected-1280.png b/docs/mockups/built/2026-11-08/conn-codex-connected-1280.png| new file mode 100644 |
| index 00000000..797b42c9 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-codex-connected-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-codex-connected-390.png b/docs/mockups/built/2026-11-08/conn-codex-connected-390.png| new file mode 100644 |
| index 00000000..6461cfdd |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-codex-connected-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-waiting-1280.png b/docs/mockups/built/2026-11-08/conn-waiting-1280.png| new file mode 100644 |
| index 00000000..75c88343 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-waiting-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/conn-waiting-390.png b/docs/mockups/built/2026-11-08/conn-waiting-390.png| new file mode 100644 |
| index 00000000..3404a507 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/conn-waiting-390.png differ |
diff --git a/docs/superpowers/plans/CONN1-PROGRESS.md b/docs/superpowers/plans/CONN1-PROGRESS.md| index 15a10db7..a60fb9a9 100644 |
| --- a/docs/superpowers/plans/CONN1-PROGRESS.md |
| +++ b/docs/superpowers/plans/CONN1-PROGRESS.md |
| @@ -274,20 +274,75 @@ model output; the waiting turn was cancelled). |
| - CI flake seen once: `TestContractNoRetroactiveMerge` (4c) got a 401 on |
| an Answer; a rerun of the same commit was green. |
| +## Round: waiting turns, live Connections page (2026-11-08) |
| + |
| +- Waiting turns: a turn waiting with no_connection, and every turn queued |
| + behind it, render no thinking line, sparkle or timer, live or after a |
| + reload; each person's message gets a quiet "Waiting for a connection" |
| + under it and one no_connection card stands after the last of them. |
| + The thinking line comes back only when an attempt starts. |
| +- Messages sent while waiting queue behind the waiting turn (no joining): |
| + they keep their own turn, reply and receipt, and run in order once a |
| + connection is usable. Chosen because joining would merge two person |
| + turns into one reply and break exactly-once per turn. |
| +- Waiting turns start on their own when a connection is added or a limit |
| + resets; Recover no longer restarts a run whose last report was waiting |
| + no_connection at the same attempt (test `TestRecoverKeepsWaitingTurns`, |
| + mutation shown). |
| +- No page refreshes: the meta refresh and every location.reload are gone |
| + from the chat and Connections pages; both re-read the page in place |
| + from their event stream. Without scripts, an open attempt shows a |
| + "Check again" link only. |
| +- Connections page: Add shows a loading card at once (rotating phrases, |
| + still under reduced motion), then the three-step card. Codex: Open |
| + OpenAI (new tab), the code once with Copy, approve then come back, a |
| + living "Waiting for you to approve…" line, the device sign-in small |
| + print, Cancel. Claude terminal: open a terminal on the runner, the |
| + command with Copy, sign in in the browser it opens. Approval lands in |
| + place with a short flourish and "Codex connected". Rows: provider mark, |
| + account, state with a dot, usage today, Sign out under ⋯ (visual layout |
| + waits for Fable's mockup). |
| +- Logging: "kept sessions" logs only on change, or hourly. |
| +- Browser tests: `TestBrowserWaitingTurns` (1280 and 390, after a reload: |
| + zero thinking lines, one card, both turns answer in order once Codex is |
| + added; mutation shown), `TestBrowserConnectionsAdd` (390 and 1280: card |
| + at once, code once, Copy shows "Copied", approval with no reload or |
| + navigation; mutation shown; Claude terminal card). Screenshots in |
| + `docs/mockups/built/2026-11-08/conn-*.png` (EQUIPO_CONN_SHOTS=1). |
| +- Fixed on the way: the Claude terminal card returned a 500 (template |
| + read a field the line did not carry). |
| + |
| ## Copy for review |
| Accepted for now with the existing marker in `copy.go`: |
| - `chat.connections.title` "Connections", `.empty` "Nothing is |
| connected yet.", `.add_codex` "Add Codex", `.add_claude` "Add Claude", |
| - `.connecting` "Connecting %s", `.device` "Go to %s and enter %s", |
| - `.sign_in_claude` "Sign in to Claude", `.finish_on` "Finish signing in |
| - on %s", `.finish_how` "Claude sign-in finishes on the machine that |
| - runs your runner. In a terminal there, run:", `.same_machine` "I am at |
| - this machine", `.cancel` "Cancel", `.healthy` "Healthy", `.limited` |
| - "Limited, no reset time reported", `.limited_until` "Limited until |
| - %s", `.signed_out` "Signed out", `.sign_in_again` "Needs signing in |
| - again", `.error` "Not working", `.offline` "Your runner is offline. |
| - Start it to add a connection." |
| + `.same_machine` "I am at this machine", `.cancel` "Cancel", `.healthy` |
| + "Healthy", `.limited` "Limited, no reset time reported", |
| + `.limited_until` "Limited until %s", `.signed_out` "Signed out", |
| + `.sign_in_again` "Needs signing in again", `.error` "Not working", |
| + `.offline` "Your runner is offline. Start it to add a connection." |
| +- Connect cards: `.title_codex` "Connect Codex", `.title_claude` "Connect |
| + Claude", `.open_openai` "Open OpenAI", `.enter_code` "Enter this code:", |
| + `.approve_back` "Approve, then come back. Equipo connects on its own.", |
| + `.waiting_approve` "Waiting for you to approve…", `.device_off` "OpenAI |
| + says device sign-in is off? Turn it on in ChatGPT, Settings, |
| + Security.", `.copy` "Copy", `.copied` "Copied", `.open_terminal` "Open |
| + a terminal on %s.", `.run` "Run:", `.browser_back` "Sign in in the |
| + browser it opens, then come back.", `.waiting_sign_in` "Waiting for you |
| + to sign in…", `.open_claude` "Open Claude", `.claude_back` "Sign in, |
| + then come back. Equipo connects on its own.", `.connected` "%s |
| + connected", `.check_again` "Check again" |
| +- Loading phrases: `.loading_codex_1` "Knocking on OpenAI's door…", |
| + `_2` "Asking for a pairing code…", `_3` "Warming up a fresh desk for |
| + Codex…"; `.loading_claude_1` "Finding your runner…", `_2` "Warming up a |
| + fresh desk for Claude…", `_3` "Starting Claude's own sign-in…" |
| +- Rows: `.usage_today` "%s tokens today", `.sign_out` "Sign out", |
| + `.more` "More"; conversation: `chat.waiting_connection` "Waiting for a |
| + connection" |
| +- Removed: `.device` "Go to %s and enter %s", `.sign_in_claude`, |
| + `.finish_on`, `.finish_how`. `.connecting` "Connecting %s" stays in |
| + copy but is no longer shown. |
| - `chat.connections.reason.timed_out` "The sign-in was not finished in |
| time.", `.cancelled` "Cancelled.", `.provider_refused` "The provider |
| did not complete the sign-in.", `.runner_offline` "Your runner went |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 416e2b27..c591de9a 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -5039,10 +5039,6 @@ records remain unchanged. |
| | `chat.connections.add_codex` | Add Codex | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.connections.add_claude` | Add Claude | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.connections.connecting` | Connecting %s | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| -| `chat.connections.device` | Go to %s and enter %s | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| -| `chat.connections.sign_in_claude` | Sign in to Claude | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| -| `chat.connections.finish_on` | Finish signing in on %s | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| -| `chat.connections.finish_how` | Claude sign-in finishes on the machine that runs your runner. In a terminal there, run: | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.connections.same_machine` | I am at this machine | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.connections.cancel` | Cancel | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.connections.healthy` | Healthy | Connections slice 1 (Connections page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| @@ -5069,6 +5065,33 @@ records remain unchanged. |
| | `work.reason.limited` | its model account reached its limit | Connections slice 1 (task card and pages) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.reason.no_connection` | nothing connected can run it | Connections slice 1 (task card and pages) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.switched` | %s was limited | Connections slice 1 (task card and pages) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.waiting_connection` | Waiting for a connection | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.title_codex` | Connect Codex | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.title_claude` | Connect Claude | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.open_openai` | Open OpenAI | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.enter_code` | Enter this code: | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.approve_back` | Approve, then come back. Equipo connects on its own. | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.waiting_approve` | Waiting for you to approve… | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.device_off` | OpenAI says device sign-in is off? Turn it on in ChatGPT, Settings, Security. | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.copy` | Copy | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.copied` | Copied | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.open_terminal` | Open a terminal on %s. | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.run` | Run: | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.browser_back` | Sign in in the browser it opens, then come back. | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.waiting_sign_in` | Waiting for you to sign in… | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.open_claude` | Open Claude | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.claude_back` | Sign in, then come back. Equipo connects on its own. | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.connected` | %s connected | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.check_again` | Check again | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.usage_today` | %s tokens today | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.sign_out` | Sign out | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.more` | More | Connections slice 1 (Connections page and conversation, round 2) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.loading_codex_1` | Knocking on OpenAI's door… | Connections slice 1 (Connections page, loading line) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.loading_codex_2` | Asking for a pairing code… | Connections slice 1 (Connections page, loading line) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.loading_codex_3` | Warming up a fresh desk for Codex… | Connections slice 1 (Connections page, loading line) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.loading_claude_1` | Finding your runner… | Connections slice 1 (Connections page, loading line) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.loading_claude_2` | Warming up a fresh desk for Claude… | Connections slice 1 (Connections page, loading line) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.connections.loading_claude_3` | Starting Claude's own sign-in… | Connections slice 1 (Connections page, loading line) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.merge_now` | Merge | Thin v1 slice 4c review round 2 (task card and page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.step` | %s, attempt %d: %s | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.steps` | Steps | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 93fdc879..f6914b90 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -216,6 +216,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| r.Get("/conversation/connections", a.connectionsView) |
| r.Post("/conversation/connections", a.connectionsStart) |
| r.Post("/conversation/connections/{id}/cancel", a.connectionsCancel) |
| + r.Post("/conversation/connections/{id}/sign-out", a.connectionsSignOut) |
| a.conversationHandler().Routes(r) |
| a.planHandler().Routes(r) |
| r.Post("/tasks/{id}/steps/{key}/selection", a.confirmPlanSelection) |
diff --git a/internal/equipo/chat/connections.go b/internal/equipo/chat/connections.go| index 73a55d6a..7a40c82e 100644 |
| --- a/internal/equipo/chat/connections.go |
| +++ b/internal/equipo/chat/connections.go |
| @@ -463,3 +463,24 @@ func (s *Store) NoConnection(ctx context.Context, person string) (out []NoConnec |
| } |
| return out, err |
| } |
| + |
| +// UsageToday sums the person's recorded tokens (input and output) per |
| +// connection since midnight UTC. |
| +func (s *Store) UsageToday(ctx context.Context, person string) (map[string]int64, error) { |
| + out := map[string]int64{} |
| + err := s.read(ctx, func(tx *gorm.DB) error { |
| + var rows []struct { |
| + Connection string |
| + N int64 |
| + } |
| + day := s.now().UTC().Truncate(24 * time.Hour) |
| + if err := tx.Raw("SELECT connection, sum(coalesce(input_tokens,0) + coalesce(output_tokens,0)) AS n FROM chat_usage WHERE person = ? AND recorded_at >= ? GROUP BY connection", person, day).Scan(&rows).Error; err != nil { |
| + return err |
| + } |
| + for _, r := range rows { |
| + out[r.Connection] = r.N |
| + } |
| + return nil |
| + }) |
| + return out, err |
| +} |
diff --git a/internal/equipo/chat_connections.go b/internal/equipo/chat_connections.go| index 29b717fc..69bc80b3 100644 |
| --- a/internal/equipo/chat_connections.go |
| +++ b/internal/equipo/chat_connections.go |
| @@ -16,21 +16,68 @@ import ( |
| // The person's connections page (Equipo Connections slice 1): the |
| // accounts their coordinator and specialists run on, how each stands, |
| -// and adding one from the app. Scriptless: a connecting attempt reloads |
| -// the page every few seconds until it ends. |
| +// and adding one from the app. It follows the event stream |
| +// (connections.js): an attempt's sign-in steps, approval and every change |
| +// of state arrive in place, never by a reload; without scripts, Check |
| +// again. |
| type modelLine struct { |
| - ID, Name, Label, State string |
| - Connecting bool |
| - Prompt *wire.ConnectPrompt |
| - Note string |
| + ID, Provider, Name, Label, State string |
| + // Tone is the state's dot: ok, limited or off. |
| + Tone string |
| + Connecting bool |
| + Prompt *wire.ConnectPrompt |
| + Note string |
| + // Usage is today's tokens in words, when any were recorded. |
| + Usage string |
| + // Phrases are the loading line's rotating words while the runner has |
| + // not yet shown the provider's sign-in. |
| + Phrases string |
| + // SignOut is offered for a connection the runner holds. |
| + SignOut bool |
| + // Runner names the machine a terminal sign-in finishes on. |
| + Runner string |
| } |
| type modelsView struct { |
| Items []modelLine |
| Runner string |
| Offline bool |
| - Refresh bool |
| + // Cursor is where the page's event stream resumes; Connecting says an |
| + // attempt is open (without scripts the page offers Check again). |
| + Cursor int64 |
| + Connecting bool |
| +} |
| + |
| +// loadingLine is the card an Add shows at once, before the server has |
| +// the attempt (the page's template for connections.js). |
| +func loadingLine(provider string) modelLine { |
| + return modelLine{ID: "pending", Provider: provider, Name: providerName(provider), Connecting: true, Phrases: loadingPhrases(provider)} |
| +} |
| + |
| +// loadingPhrases are the loading line's turning words, joined for the |
| +// page's data attribute. |
| +func loadingPhrases(provider string) string { |
| + var out []string |
| + for i := 1; i <= 3; i++ { |
| + if p := copyText(fmt.Sprintf("chat.connections.loading_%s_%d", provider, i)); p != "" { |
| + out = append(out, p) |
| + } |
| + } |
| + return strings.Join(out, "|") |
| +} |
| + |
| +// tokensText is a token count in words: 840, 12.4k, 3.1M. |
| +func tokensText(n int64) string { |
| + switch { |
| + case n >= 1_000_000: |
| + return fmt.Sprintf("%.1fM", float64(n)/1e6) |
| + case n >= 10_000: |
| + return fmt.Sprintf("%.0fk", float64(n)/1e3) |
| + case n >= 1_000: |
| + return fmt.Sprintf("%.1fk", float64(n)/1e3) |
| + } |
| + return fmt.Sprint(n) |
| } |
| // providerName is how a provider is named to a person. |
| @@ -126,12 +173,31 @@ func (a *application) connectionsView(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| data.Title = "chat.connections.title" |
| - v := modelsView{Offline: !snap.Runner.Online, Runner: a.runnerLabel(ctx, address, snap.Runner.ID)} |
| + v := modelsView{Offline: !snap.Runner.Online, Runner: a.runnerLabel(ctx, address, snap.Runner.ID), Cursor: snap.Cursor} |
| + today, err := a.store.Chat().UsageToday(ctx, address) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| if v.Runner == "" { |
| v.Runner = copyText("chat.connections.title") |
| } |
| for _, c := range snap.Connections { |
| - line := modelLine{ID: c.ID, Name: providerName(c.Provider), Label: c.Label, State: connectionState(c), Connecting: c.State == wire.ConnConnecting, Prompt: c.Prompt} |
| + line := modelLine{ID: c.ID, Provider: c.Provider, Name: providerName(c.Provider), Label: c.Label, State: connectionState(c), Connecting: c.State == wire.ConnConnecting, Prompt: c.Prompt, SignOut: c.LocalID != "" && c.State != wire.ConnSignedOut, Runner: v.Runner} |
| + switch c.State { |
| + case wire.ConnHealthy: |
| + line.Tone = "ok" |
| + case wire.ConnLimited: |
| + line.Tone = "limited" |
| + default: |
| + line.Tone = "off" |
| + } |
| + if n := today[c.LocalID]; n > 0 && c.LocalID != "" { |
| + line.Usage = fmt.Sprintf(copyText("chat.connections.usage_today"), tokensText(n)) |
| + } |
| + if line.Connecting && line.Prompt == nil { |
| + line.Phrases = loadingPhrases(c.Provider) |
| + } |
| if c.State == wire.ConnError && c.LocalID == "" { |
| // An attempt that ended says why once, then the page moves on. |
| if time.Since(c.UpdatedAt) > 10*time.Minute { |
| @@ -139,10 +205,10 @@ func (a *application) connectionsView(w http.ResponseWriter, r *http.Request) { |
| } |
| line.State, line.Note = "", copyText("chat.connections.reason."+c.Reason) |
| } |
| - v.Refresh = v.Refresh || line.Connecting |
| + v.Connecting = v.Connecting || line.Connecting |
| v.Items = append(v.Items, line) |
| } |
| - data.Models = v |
| + data.Models, data.ConnectionsStream = v, true |
| render(w, "models", data) |
| } |
| @@ -172,6 +238,14 @@ func (a *application) connectionsStart(w http.ResponseWriter, r *http.Request) { |
| }) |
| } |
| +// connectionsSignOut is a connection's quiet Sign out. |
| +func (a *application) connectionsSignOut(w http.ResponseWriter, r *http.Request) { |
| + a.chatActionTo(w, r, "/conversation/connections", func(ctx context.Context, address string) error { |
| + _, err := a.store.Chat().SignOut(ctx, address, chi.URLParam(r, "id")) |
| + return err |
| + }) |
| +} |
| + |
| func (a *application) connectionsCancel(w http.ResponseWriter, r *http.Request) { |
| a.chatActionTo(w, r, "/conversation/connections", func(ctx context.Context, address string) error { |
| _, err := a.store.Chat().CancelConnection(ctx, address, chi.URLParam(r, "id")) |
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go| index 30a78937..3321cdbf 100644 |
| --- a/internal/equipo/chat_page.go |
| +++ b/internal/equipo/chat_page.go |
| @@ -37,7 +37,10 @@ type noConnectionCard struct{ TurnID, Line string } |
| type chatLine struct { |
| // Switched is the quiet line under a reply that moved connection. |
| - Switched string |
| + Switched string |
| + // Waiting is the quiet status under a person's message whose turn |
| + // waits for a connection (no thinking line, no timer). |
| + Waiting string |
| ID, Text, TurnID string |
| Own bool |
| CreatedAt time.Time |
| @@ -203,24 +206,42 @@ func (a *application) chatPage(w http.ResponseWriter, r *http.Request) { |
| at := sort.Search(len(view.Messages), func(i int) bool { return view.Messages[i].CreatedAt.After(l.CreatedAt) }) |
| view.Messages = slices.Insert(view.Messages, at, l) |
| } |
| + // Nothing can answer: no turn shows the thinking line or a timer |
| + // until an attempt starts on a connection. A turn waiting for one, and |
| + // any queued behind it, get a quiet status under the person's message; |
| + // one card stands after them for the conversation. |
| + held := false |
| + for _, t := range snap.Turns { |
| + held = held || t.State == wire.TurnWaiting && t.Reason == wire.ReasonNoConnection |
| + } |
| + waitingTurns := map[string]bool{} |
| var latest *wire.Turn |
| for i, t := range snap.Turns { |
| if !wire.Terminal(t.State) { |
| - view.Waiting = append(view.Waiting, t) |
| - if t.State == wire.TurnWaiting && t.Reason == wire.ReasonNoConnection && view.NoConnection == nil { |
| - lines, err := a.store.Chat().NoConnection(ctx, address) |
| - if err != nil { |
| - a.failure(w, r, chatError(err)) |
| - return |
| + if held && (t.State == wire.TurnWaiting && t.Reason == wire.ReasonNoConnection || t.State == wire.TurnQueued) { |
| + waitingTurns[t.ID] = true |
| + if view.NoConnection == nil { |
| + lines, err := a.store.Chat().NoConnection(ctx, address) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| + view.NoConnection = &noConnectionCard{TurnID: t.ID, Line: noConnectionText(lines)} |
| } |
| - view.NoConnection = &noConnectionCard{TurnID: t.ID, Line: noConnectionText(lines)} |
| + continue |
| } |
| + view.Waiting = append(view.Waiting, t) |
| } |
| // Turns the coordinator takes on its own never end in a note. |
| if t.Kind == wire.TurnPerson && (latest == nil || t.CreatedAt.After(latest.CreatedAt)) { |
| latest = &snap.Turns[i] |
| } |
| } |
| + for i := range view.Messages { |
| + if view.Messages[i].Own && waitingTurns[view.Messages[i].TurnID] { |
| + view.Messages[i].Waiting = copyText("chat.waiting_connection") |
| + } |
| + } |
| if latest != nil && (latest.State == wire.TurnFailed || latest.State == wire.TurnCancelled) { |
| view.Ended = &chatEnded{ID: latest.ID, Key: "chat." + latest.State} |
| } |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 19b785ad..a33d02e4 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -594,10 +594,6 @@ var pageCopy = map[string]string{ |
| "chat.connections.add_codex": "Add Codex", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.add_claude": "Add Claude", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.connecting": "Connecting %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "chat.connections.device": "Go to %s and enter %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "chat.connections.sign_in_claude": "Sign in to Claude", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "chat.connections.finish_on": "Finish signing in on %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "chat.connections.finish_how": "Claude sign-in finishes on the machine that runs your runner. In a terminal there, run:", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.same_machine": "I am at this machine", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.cancel": "Cancel", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.healthy": "Healthy", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| @@ -613,6 +609,33 @@ var pageCopy = map[string]string{ |
| "chat.connections.reason.identity_mismatch": "The sign-in did not match an account.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.reason.already_connected": "That account is already connected.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.offline": "Your runner is offline. Start it to add a connection.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.waiting_connection": "Waiting for a connection", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.title_codex": "Connect Codex", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.title_claude": "Connect Claude", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.open_openai": "Open OpenAI", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.enter_code": "Enter this code:", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.approve_back": "Approve, then come back. Equipo connects on its own.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.waiting_approve": "Waiting for you to approve…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.device_off": "OpenAI says device sign-in is off? Turn it on in ChatGPT, Settings, Security.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.copy": "Copy", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.copied": "Copied", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.open_terminal": "Open a terminal on %s.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.run": "Run:", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.browser_back": "Sign in in the browser it opens, then come back.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.waiting_sign_in": "Waiting for you to sign in…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.open_claude": "Open Claude", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.claude_back": "Sign in, then come back. Equipo connects on its own.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.connected": "%s connected", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.check_again": "Check again", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.usage_today": "%s tokens today", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.sign_out": "Sign out", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.more": "More", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.loading_codex_1": "Knocking on OpenAI's door…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.loading_codex_2": "Asking for a pairing code…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.loading_codex_3": "Warming up a fresh desk for Codex…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.loading_claude_1": "Finding your runner…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.loading_claude_2": "Warming up a fresh desk for Claude…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.loading_claude_3": "Starting Claude's own sign-in…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.switched": "Switched to %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.switched_reset": "Switched to %s; %s resets %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.no_connection": "Nothing can answer right now. %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/internal/equipo/handlers.go b/internal/equipo/handlers.go| index 0eb7b53f..1fd66c26 100644 |
| --- a/internal/equipo/handlers.go |
| +++ b/internal/equipo/handlers.go |
| @@ -42,6 +42,7 @@ type pageData struct { |
| Thin workView |
| Notebook []notebookLine |
| Models modelsView |
| + ConnectionsStream bool |
| ChatStream bool |
| Coordinator conversation.CoordinatorPage |
| Plan planning.Page |
diff --git a/internal/equipo/render.go b/internal/equipo/render.go| index 571d4f9a..9b98ead4 100644 |
| --- a/internal/equipo/render.go |
| +++ b/internal/equipo/render.go |
| @@ -36,7 +36,7 @@ func init() { |
| for _, name := range []string{"person_devices", "person_device", "teams", "onboarding", "invite", "playbooks", "playbook_form", "playbook_diff", "specialist_form", "template_library", "template_diff", "conversation", "chat", "thread", "plan", "coordinator", "preferences", "index", "empty", "projects", "project", "project_form", "people", "settings", "specialist", "errors", "signin_page", "form_error", "runners", "tasks", "task", "task_form", "question", "merge", "connections", "recovery", "recovery_form", "rendered_approval", "notebook", "work_tasks", "work_task", "work_projects", "work_project", "models", "work_needs"} { |
| page := template.Must(template.New("layout"). |
| Funcs(ui.Funcs(ui.WithIcons(icons.Icon, icons.Assets))). |
| - Funcs(template.FuncMap{"chatMarkdown": chatmarkdown.Render, "since": sinceMillis, "elapsed": elapsedText, "short": short, "agoData": agoData, "agoFormats": agoFormats, "projectAllows": library.ProjectAllowed, "asset": assets.Path, "copy": copyText, "taskGroups": func() []string { return []string{"needs-person", "running", "queued", "finished"} }, |
| + Funcs(template.FuncMap{"chatMarkdown": chatmarkdown.Render, "loadingLine": loadingLine, "split": strings.Split, "since": sinceMillis, "elapsed": elapsedText, "short": short, "agoData": agoData, "agoFormats": agoFormats, "projectAllows": library.ProjectAllowed, "asset": assets.Path, "copy": copyText, "taskGroups": func() []string { return []string{"needs-person", "running", "queued", "finished"} }, |
| "kindKey": func(k ProjectKind) string { return "kind." + string(k) }, |
| "ownerKey": func(k string) string { return "owner." + k }, |
| "roleKey": func(k Role) string { return "role." + string(k) }, |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index fd7b5075..6ed50699 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -339,11 +339,17 @@ |
| inflight = null; |
| if (again) { |
| again = false; |
| - refresh().catch(function () { location.reload(); }); |
| + refreshSoon(); |
| } |
| }); |
| return inflight; |
| } |
| + // A failed refresh is tried again shortly, then again: never a reload. |
| + function refreshSoon() { |
| + refresh().catch(function () { |
| + setTimeout(function () { refresh().catch(function () { setTimeout(refreshSoon, 5000); }); }, 1500); |
| + }); |
| + } |
| function load() { |
| return fetch(location.pathname, { credentials: "same-origin", headers: { "Accept": "text/html" } }) |
| .then(function (r) { if (!r.ok) throw new Error("refresh"); return r.text(); }) |
| @@ -403,11 +409,11 @@ |
| var waiting = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]'); |
| if (waiting) setActivity(waiting, root.dataset.thinking); |
| } |
| - refresh().catch(function () { location.reload(); }); |
| + refreshSoon(); |
| return; |
| } |
| if (type === "task" || type === "step") { |
| - if (v.id === thread || v.task_id === thread) refresh().catch(function () { location.reload(); }); |
| + if (v.id === thread || v.task_id === thread) refreshSoon(); |
| return; |
| } |
| if ((type !== "delta" && type !== "activity") || !question || !(v.turn_id in asked)) return; |
| @@ -426,7 +432,7 @@ |
| clearEmpty(); |
| if (v.role === "coordinator") { |
| delete drafts[v.turn_id]; |
| - refresh().catch(function () { location.reload(); }); |
| + refreshSoon(); |
| return; |
| } |
| var own = template("equipo-own-template"); |
| @@ -437,7 +443,15 @@ |
| feed.insertBefore(own, waiting); |
| scroll(); |
| } else if (type === "turn") { |
| - if (v.state === "queued" || v.state === "running" || v.state === "waiting") { |
| + var heldNow = !!feed.querySelector("[data-no-connection]"); |
| + if (v.state === "waiting" && v.reason === "no_connection" || v.state === "queued" && heldNow) { |
| + // Nothing can answer yet: no thinking line, no timer; the quiet |
| + // status and the one card are the server's. |
| + delete drafts[v.id]; |
| + var thinking = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]'); |
| + if (thinking) thinking.remove(); |
| + refreshSoon(); |
| + } else if (v.state === "queued" || v.state === "running" || v.state === "waiting") { |
| var shownDraft = bubble(v.id, v.kind); |
| if (drafts[v.id] && drafts[v.id].attempt !== v.attempt) { |
| // The refused attempt's words go; the next attempt's follow. |
| @@ -445,9 +459,8 @@ |
| var body = shownDraft && shownDraft.querySelector("[data-stream-text]"); |
| if (body) body.textContent = ""; |
| } |
| - // Held for a connection, or going again: the card is the server's. |
| - var held = !!feed.querySelector('[data-no-connection="' + CSS.escape(v.id) + '"]'); |
| - if ((v.state === "waiting" && v.reason === "no_connection") !== held) refresh().catch(function () { location.reload(); }); |
| + // Going again on a connection: the status and the card go. |
| + if (heldNow || feed.querySelector('[data-message] [data-waiting-connection]')) refreshSoon(); |
| } else if (v.state === "replied" && !v.reply_id) { |
| // A turn that ended with nothing to say (an empty explore). |
| delete drafts[v.id]; |
| @@ -471,7 +484,7 @@ |
| } else if (type === "card" || type === "task" || type === "step") { |
| // Cards (and the tasks on them) are rendered by the server, like |
| // committed replies. |
| - refresh().catch(function () { location.reload(); }); |
| + refreshSoon(); |
| } else if (type === "runner" && offline) { |
| offline.hidden = !!v.online; |
| } |
| @@ -495,7 +508,7 @@ |
| f.querySelectorAll("button").forEach(function (b) { b.disabled = true; }); |
| fetch(f.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: body }) |
| .then(function (r) { if (!r.ok) throw new Error("card"); return refresh(); }) |
| - .catch(function () { location.reload(); }); |
| + .catch(function () { refreshSoon(); }); |
| }); |
| // Sending stays on this page: no navigation, so no page transition. The |
| // bubble shows at once; the background post uses the form's own action |
| @@ -578,7 +591,21 @@ |
| source.close(); |
| // A cursor past retention (410) or a lost session: the page itself |
| // is the snapshot. |
| - if (++failures > 4) { location.reload(); return; } |
| + // Past retention (410) or a lost session: read the page again in |
| + // place, take its cursor, and follow from there. |
| + if (++failures > 4) { |
| + failures = 0; |
| + fetch(location.pathname, { credentials: "same-origin", headers: { "Accept": "text/html" } }) |
| + .then(function (r) { return r.text(); }) |
| + .then(function (body) { |
| + var page = new DOMParser().parseFromString(body, "text/html").querySelector("[data-chat-stream]"); |
| + if (page) cursor = Math.max(cursor, Number(page.dataset.cursor) || 0); |
| + refreshSoon(); |
| + open(); |
| + }) |
| + .catch(function () { setTimeout(open, 10000); }); |
| + return; |
| + } |
| setTimeout(open, 1000 * failures); |
| }; |
| } |
diff --git a/internal/equipo/static/connections.js b/internal/equipo/static/connections.js| new file mode 100644 |
| index 00000000..32c17bf1 |
| --- /dev/null |
| +++ b/internal/equipo/static/connections.js |
| @@ -0,0 +1,173 @@ |
| +// The Connections page follows the person's event stream: an attempt's |
| +// sign-in steps, its approval and every change of a connection's state |
| +// arrive in place, rendered by the server. Nothing reloads the page. Add, |
| +// Cancel, "I am at this machine" and Sign out post in the background. |
| +(function () { |
| + "use strict"; |
| + var root = document.querySelector("[data-connections]"); |
| + if (!root || !window.fetch) return; |
| + var list = root.querySelector("[data-connection-list]"); |
| + var cursor = Number(root.dataset.cursor) || 0; |
| + var still = window.matchMedia ? matchMedia("(prefers-reduced-motion: reduce)") : null; |
| + function moving() { return !(still && still.matches); } |
| + |
| + // The loading line's words turn while the runner asks the provider. |
| + function animate(scope) { |
| + scope.querySelectorAll("[data-loading][data-phrases]").forEach(function (line) { |
| + if (line.turning) return; |
| + line.turning = true; |
| + var phrases = line.dataset.phrases.split("|"), i = 0; |
| + var span = line.querySelector("[data-phrase]"); |
| + if (!span || phrases.length < 2 || !moving()) return; |
| + var timer = setInterval(function () { |
| + if (!line.isConnected) { clearInterval(timer); return; } |
| + i = (i + 1) % phrases.length; |
| + span.setAttribute("data-out", ""); |
| + setTimeout(function () { span.textContent = phrases[i]; span.removeAttribute("data-out"); }, 220); |
| + }, 2200); |
| + }); |
| + } |
| + |
| + // A connection that just finished connecting: a brief flourish, then |
| + // its row. |
| + function celebrate(row, provider) { |
| + var name = provider === "codex" ? "Codex" : provider === "claude" ? "Claude" : provider; |
| + var note = document.createElement("p"); |
| + note.setAttribute("equipo-conn-live", ""); |
| + note.setAttribute("data-celebrate", ""); |
| + var spark = document.querySelector("[data-loading-template]").content.querySelector("[equipo-sparkle]").cloneNode(true); |
| + if (moving()) { |
| + spark.setAttribute("data-flourish", ""); |
| + spark.dataset.spin = "whirl"; |
| + for (var k = 0; k < 7; k++) { |
| + var mote = document.createElement("i"); |
| + mote.setAttribute("data-mote", k % 3 === 1 ? "warm" : k % 2 ? "light" : ""); |
| + mote.style.setProperty("--dx", (1.2 + (k * 0.9) % 2.6).toFixed(2) + "em"); |
| + mote.style.setProperty("--dy", ((k * 0.53) % 1.4 - 0.7).toFixed(2) + "em"); |
| + mote.style.setProperty("--d", (k * 60) + "ms"); |
| + spark.append(mote); |
| + } |
| + } |
| + var text = document.createElement("span"); |
| + text.textContent = (root.dataset.connected || "%s connected").replace("%s", name); |
| + note.append(spark, text); |
| + row.prepend(note); |
| + setTimeout(function () { if (note.isConnected) note.remove(); }, 4000); |
| + } |
| + |
| + // Refreshes run one at a time; a request during one runs once after it. |
| + var inflight = null, again = false; |
| + function refresh() { |
| + if (inflight) { again = true; return inflight; } |
| + inflight = load().finally(function () { |
| + inflight = null; |
| + if (again) { again = false; refresh(); } |
| + }); |
| + return inflight; |
| + } |
| + function load() { |
| + var connecting = {}; |
| + list.querySelectorAll("[data-connecting]").forEach(function (el) { connecting[el.dataset.connection] = el.dataset.provider; }); |
| + return fetch(location.pathname, { credentials: "same-origin", headers: { "Accept": "text/html" } }) |
| + .then(function (r) { if (!r.ok) throw new Error("refresh"); return r.text(); }) |
| + .then(function (body) { |
| + var doc = new DOMParser().parseFromString(body, "text/html"); |
| + var next = doc.querySelector("[data-connection-list]"); |
| + if (!next) return; |
| + // An attempt the server has not shown yet keeps its loading card. |
| + var pending = list.querySelector('[data-connection="pending"]'); |
| + var kept = pending && !next.querySelector('[data-connecting][data-provider="' + pending.dataset.provider + '"]') ? pending : null; |
| + list.replaceChildren.apply(list, Array.from(next.children)); |
| + if (kept) { |
| + var empty = list.querySelector("[data-empty-state]"); |
| + if (empty) empty.remove(); |
| + list.prepend(kept); |
| + } |
| + Object.keys(connecting).forEach(function (id) { |
| + var row = list.querySelector('[data-connection="' + CSS.escape(id) + '"]'); |
| + if (row && !row.hasAttribute("data-connecting") && row.querySelector('[data-tone="ok"]')) celebrate(row, connecting[id]); |
| + }); |
| + animate(list); |
| + }); |
| + } |
| + // A failed refresh is tried again shortly: never a reload. |
| + function refreshSoon() { |
| + refresh().catch(function () { setTimeout(function () { refresh().catch(function () {}); }, 2000); }); |
| + } |
| + |
| + // Copy: the clipboard where it can, the text selected otherwise. |
| + root.addEventListener("click", function (event) { |
| + var button = event.target.closest("[data-copy]"); |
| + if (!button) return; |
| + var text = button.dataset.copy, label = button.textContent; |
| + function done() { |
| + button.textContent = button.dataset.copied; |
| + button.setAttribute("data-done", ""); |
| + setTimeout(function () { button.textContent = label; button.removeAttribute("data-done"); }, 1800); |
| + } |
| + function select() { |
| + var code = button.parentNode.querySelector("code"); |
| + if (code) { |
| + var range = document.createRange(); |
| + range.selectNodeContents(code); |
| + var sel = getSelection(); |
| + sel.removeAllRanges(); |
| + sel.addRange(range); |
| + try { document.execCommand("copy"); } catch (e) { /* selected for the person to copy */ } |
| + } |
| + done(); |
| + } |
| + if (navigator.clipboard && window.isSecureContext) navigator.clipboard.writeText(text).then(done, select); |
| + else select(); |
| + }); |
| + |
| + // Forms post in the background; Add shows its loading card at once. |
| + root.addEventListener("submit", function (event) { |
| + var form = event.target; |
| + if (!form.matches || !form.matches("form")) return; |
| + event.preventDefault(); |
| + if (form.matches("[data-add-form]")) { |
| + var provider = form.querySelector('[name="provider"]').value; |
| + if (!list.querySelector('[data-connecting][data-provider="' + provider + '"]')) { |
| + var tpl = document.querySelector(provider === "claude" ? "[data-loading-template-claude]" : "[data-loading-template]"); |
| + var card = tpl.content.firstElementChild.cloneNode(true); |
| + var empty = list.querySelector("[data-empty-state]"); |
| + if (empty) empty.remove(); |
| + list.prepend(card); |
| + animate(card); |
| + } |
| + } |
| + fetch(form.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: new URLSearchParams(new FormData(form)) }) |
| + .then(function (r) { if (!r.ok) throw new Error("post"); refreshSoon(); }) |
| + .catch(function () { form.submit(); }); |
| + }); |
| + |
| + animate(list); |
| + if (!window.EventSource) return; |
| + var source, failures = 0; |
| + function open() { |
| + source = new EventSource("/api/v1/events?after=" + cursor); |
| + source.addEventListener("connection", function (event) { |
| + failures = 0; |
| + try { cursor = Math.max(cursor, JSON.parse(event.data).cursor || 0); } catch (e) { /* keep */ } |
| + refreshSoon(); |
| + }); |
| + ["runner", "ping"].forEach(function (type) { source.addEventListener(type, function () { failures = 0; }); }); |
| + source.onerror = function () { |
| + source.close(); |
| + // Past retention or a lost session: read the page again in place and |
| + // follow from its cursor. |
| + failures++; |
| + setTimeout(function () { |
| + fetch(location.pathname, { credentials: "same-origin" }).then(function (r) { return r.text(); }).then(function (body) { |
| + var doc = new DOMParser().parseFromString(body, "text/html"); |
| + var page = doc.querySelector("[data-connections]"); |
| + if (page) cursor = Number(page.dataset.cursor) || cursor; |
| + refreshSoon(); |
| + open(); |
| + }).catch(function () { setTimeout(open, 1000 * Math.min(failures, 10)); }); |
| + }, 1000 * Math.min(failures, 10)); |
| + }; |
| + } |
| + open(); |
| +})(); |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index 42c7583c..b946b1b5 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -709,3 +709,33 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| [equipo-chat-header] { block-size: auto; min-block-size: calc(3.5rem + env(safe-area-inset-top, 0px)); padding-block: env(safe-area-inset-top, 0px) 0; } |
| [equipo-chat-header] h1 { line-height: 1.25; } |
| } |
| + |
| +/* Connections (slice 1, functional; the page is restyled to Fable's |
| + mockup next). Hairline cards, quiet actions, no coloured borders. */ |
| +[equipo-connections] { max-inline-size: 46rem; } |
| +[equipo-conn-list] { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--rst-sp-3); } |
| +[equipo-conn-row], [equipo-conn-card] { border: 1px solid var(--rst-line); border-radius: var(--rst-radius); padding: var(--rst-sp-4); background: var(--rst-surface); } |
| +[equipo-conn-row] { display: flex; align-items: center; gap: var(--rst-sp-3); flex-wrap: wrap; } |
| +[equipo-conn-row] > [data-celebrate] { flex-basis: 100%; } |
| +[equipo-conn-mark] { flex: none; display: grid; place-items: center; inline-size: 2rem; block-size: 2rem; border: 1px solid var(--rst-line); border-radius: 50%; font-weight: 600; } |
| +[equipo-conn-who] { flex: 1; min-inline-size: 0; } |
| +[equipo-conn-who] p { margin: 0; } |
| +[equipo-conn-account] { color: var(--rst-text-muted); overflow-wrap: anywhere; } |
| +[equipo-conn-state] { display: flex; align-items: center; gap: .4em; margin: 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); } |
| +[equipo-conn-dot] { flex: none; inline-size: .5em; block-size: .5em; border-radius: 50%; background: var(--rst-tone-positive-fg); } |
| +[equipo-conn-dot][data-tone="limited"] { background: var(--rst-tone-warning-fg); } |
| +[equipo-conn-dot][data-tone="off"] { background: var(--rst-tone-neutral-fg); } |
| +[equipo-conn-more] summary { list-style: none; cursor: pointer; padding-inline: .5em; color: var(--rst-text-muted); } |
| +[equipo-conn-more] summary::-webkit-details-marker { display: none; } |
| +[equipo-conn-card] h2 { margin: 0 0 var(--rst-sp-3); font-size: var(--rst-fs-md, 1.05rem); } |
| +[equipo-conn-steps] { margin: 0; padding-inline-start: 1.4em; display: grid; gap: var(--rst-sp-3); } |
| +[equipo-conn-code] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.5rem; letter-spacing: .08em; padding: .05em .35em; border: 1px solid var(--rst-line); border-radius: var(--rst-radius); background: var(--rst-surface-2); white-space: nowrap; display: inline-block; } |
| +[equipo-conn-code][data-command] { font-size: 1rem; letter-spacing: 0; white-space: normal; overflow-wrap: anywhere; } |
| +[equipo-conn-live] { display: flex; align-items: center; margin: var(--rst-sp-4) 0 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); } |
| +[equipo-conn-live] [data-phrase] { transition: opacity .2s ease; } |
| +[equipo-conn-live] [data-phrase][data-out] { opacity: 0; } |
| +[equipo-conn-small] { margin: var(--rst-sp-2) 0 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); } |
| +[equipo-inline-form] { display: inline; } |
| +[equipo-conn-add] { display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); margin-block-start: var(--rst-sp-4); } |
| +[data-copy][data-done] { color: var(--rst-tone-positive-fg); } |
| +@media (prefers-reduced-motion: reduce) { [equipo-connections] [equipo-sparkle] *, [equipo-connections] [equipo-sparkle] svg { animation: none !important; } } |
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html| index b224bcd0..3d58e97a 100644 |
| --- a/internal/equipo/templates/chat.html |
| +++ b/internal/equipo/templates/chat.html |
| @@ -26,6 +26,7 @@ |
| <li equipo-message="{{if .Own}}own{{else}}incoming{{end}}" data-message="{{.ID}}" data-turn-id="{{.TurnID}}"> |
| <div equipo-message-meta><strong{{if .Own}} equipo-visually-hidden{{end}}>{{if .Own}}{{$.Address}}{{else}}{{icon "message-circle"}}{{copy "conversation.coordinator"}}{{end}}</strong><time datetime="{{.CreatedAt.Format "2006-01-02T15:04:05Z07:00"}}">{{.CreatedAt.Format "15:04"}}</time></div> |
| <div equipo-bubble>{{if .Own}}<p equipo-message-body>{{.Text}}</p>{{else}}<div equipo-message-body equipo-markdown>{{chatMarkdown .Text}}</div>{{end}}</div> |
| +{{with .Waiting}}<p equipo-card-note data-waiting-connection>{{.}}</p>{{end}} |
| {{with .Switched}}<p equipo-card-note data-switched>{{.}}</p>{{end}} |
| </li> |
| {{range .Cards}}{{template "chat-card" .}}{{end}}{{end}} |
diff --git a/internal/equipo/templates/chrome.html b/internal/equipo/templates/chrome.html| index a635ab58..7c4ac0d9 100644 |
| --- a/internal/equipo/templates/chrome.html |
| +++ b/internal/equipo/templates/chrome.html |
| @@ -1,6 +1,6 @@ |
| {{define "rail-brand"}}<span hidden></span>{{end}} |
| {{define "title"}}{{copy .Title}} · {{copy "brand"}}{{end}} |
| -{{define "head"}}{{.Live.Head (T "rastrillo.ui.live.paused") (T "rastrillo.ui.live.unconfirmed")}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}"><script defer src="{{asset "static/nav-stream.js"}}"></script><script defer src="{{asset "static/work-stream.js"}}"></script>{{if .ChatStream}}<script defer src="{{asset "static/chat-stream.js"}}"></script><script defer src="{{asset "static/chat-compose.js"}}"></script><script defer src="{{asset "static/ask-target.js"}}"></script>{{if eq .Key "conversation"}}<script defer src="{{asset "static/chat-anchor.js"}}"></script>{{end}}{{else if eq .Key "conversation"}}<script defer blocking="render" src="{{asset "static/chat-navigation.js"}}"></script><script defer src="{{asset "static/chat.js"}}"></script><script defer src="{{asset "static/chat-send.js"}}"></script>{{end}}{{end}} |
| +{{define "head"}}{{.Live.Head (T "rastrillo.ui.live.paused") (T "rastrillo.ui.live.unconfirmed")}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}"><script defer src="{{asset "static/nav-stream.js"}}"></script><script defer src="{{asset "static/work-stream.js"}}"></script>{{if .ConnectionsStream}}<script defer src="{{asset "static/connections.js"}}"></script>{{end}}{{if .ChatStream}}<script defer src="{{asset "static/chat-stream.js"}}"></script><script defer src="{{asset "static/chat-compose.js"}}"></script><script defer src="{{asset "static/ask-target.js"}}"></script>{{if eq .Key "conversation"}}<script defer src="{{asset "static/chat-anchor.js"}}"></script>{{end}}{{else if eq .Key "conversation"}}<script defer blocking="render" src="{{asset "static/chat-navigation.js"}}"></script><script defer src="{{asset "static/chat.js"}}"></script><script defer src="{{asset "static/chat-send.js"}}"></script>{{end}}{{end}} |
| {{define "up"}}/work{{if .Key}}#nav-{{.Key}}{{end}}{{end}} |
| {{define "up-label"}}{{.TeamName}}{{end}} |
| {{define "brand"}}<a rst-shell-brand href="/work">{{icon "users"}}{{.TeamName}}</a>{{end}} |
diff --git a/internal/equipo/templates/models.html b/internal/equipo/templates/models.html| index 3ab1f175..5469f1f1 100644 |
| --- a/internal/equipo/templates/models.html |
| +++ b/internal/equipo/templates/models.html |
| @@ -1,20 +1,44 @@ |
| {{define "up-label"}}{{copy "conversation.title"}}{{end}} |
| {{define "up"}}/conversation{{end}} |
| {{define "title"}}{{copy "chat.connections.title"}}{{end}} |
| +{{define "conn-star"}}<span equipo-sparkle aria-hidden="true"><svg viewBox="0 0 16 16" focusable="false"><path d="M8 0C8.6 4.6 11.4 7.4 16 8 11.4 8.6 8.6 11.4 8 16 7.4 11.4 4.6 8.6 0 8 4.6 7.4 7.4 4.6 8 0Z"/><circle cx="8" cy="8" r="1.7"/></svg><i data-sat="1"></i><i data-sat="2"></i><i data-sat="3"></i></span>{{end}} |
| +{{define "conn-copy"}}<button type="button" equipo-link data-copy="{{.}}" data-copied="{{copy "chat.connections.copied"}}">{{copy "chat.connections.copy"}}</button>{{end}} |
| +{{define "conn-attempt"}}<li equipo-conn-card data-connection="{{.ID}}" data-connecting data-provider="{{.Provider}}"> |
| +<h2>{{if eq .Provider "codex"}}{{copy "chat.connections.title_codex"}}{{else}}{{copy "chat.connections.title_claude"}}{{end}}</h2> |
| +{{if not .Prompt}}<p equipo-conn-live data-loading data-phrases="{{.Phrases}}">{{template "conn-star"}}<span data-phrase>{{index (split .Phrases "|") 0}}</span></p> |
| +{{else if eq .Prompt.Kind "device_code"}}<ol equipo-conn-steps data-device-code> |
| +<li><a rst-btn="primary" href="{{.Prompt.URL}}" rel="noopener" target="_blank" data-open-provider>{{copy "chat.connections.open_openai"}}</a></li> |
| +<li>{{copy "chat.connections.enter_code"}} <code equipo-conn-code data-code>{{.Prompt.Code}}</code> {{template "conn-copy" .Prompt.Code}}</li> |
| +<li>{{copy "chat.connections.approve_back"}}</li> |
| +</ol> |
| +<p equipo-conn-live>{{template "conn-star"}}<span>{{copy "chat.connections.waiting_approve"}}</span></p> |
| +<p equipo-conn-small>{{copy "chat.connections.device_off"}}</p> |
| +{{else if eq .Prompt.Kind "link"}}<ol equipo-conn-steps data-sign-in-steps> |
| +<li><a rst-btn="primary" href="{{.Prompt.URL}}" rel="noopener" target="_blank" data-sign-in>{{copy "chat.connections.open_claude"}}</a></li> |
| +<li>{{copy "chat.connections.claude_back"}}</li> |
| +</ol> |
| +<p equipo-conn-live>{{template "conn-star"}}<span>{{copy "chat.connections.waiting_sign_in"}}</span></p> |
| +{{else if eq .Prompt.Kind "terminal"}}<ol equipo-conn-steps data-finish-on> |
| +<li>{{printf (copy "chat.connections.open_terminal") .Runner}}</li> |
| +<li>{{copy "chat.connections.run"}} <code equipo-conn-code data-command>{{.Prompt.Code}}</code> {{template "conn-copy" .Prompt.Code}}</li> |
| +<li>{{copy "chat.connections.browser_back"}}</li> |
| +</ol> |
| +<p equipo-conn-live>{{template "conn-star"}}<span>{{copy "chat.connections.waiting_sign_in"}}</span></p> |
| +<div equipo-conn-small><form method="post" action="/conversation/connections" equipo-inline-form><input type="hidden" name="provider" value="claude"><input type="hidden" name="same_machine" value="1"><button equipo-link type="submit" data-same-machine>{{copy "chat.connections.same_machine"}}</button></form></div> |
| +{{end}} |
| +<div equipo-conn-small><form method="post" action="/conversation/connections/{{.ID}}/cancel" equipo-inline-form><button equipo-link type="submit" data-connection-cancel>{{copy "chat.connections.cancel"}}</button></form></div> |
| +</li>{{end}} |
| {{define "content"}} |
| -{{if .Models.Refresh}}<meta http-equiv="refresh" content="3">{{end}} |
| -<section equipo-notebook data-connections> |
| +<section equipo-connections data-connections data-cursor="{{.Models.Cursor}}" data-connected="{{copy "chat.connections.connected"}}"> |
| <header equipo-notebook-head><h1>{{copy "chat.connections.title"}}</h1></header> |
| {{if .Models.Offline}}<p equipo-offline role="status">{{copy "chat.connections.offline"}}</p>{{end}} |
| -{{if .Models.Items}}<ul equipo-notes role="list">{{range .Models.Items}}<li equipo-note data-connection="{{.ID}}"{{if .Connecting}} data-connecting{{end}}> |
| -<p><strong>{{.Name}}</strong>{{with .Label}} {{.}}{{end}}</p> |
| -{{with .State}}<p equipo-note-caption data-connection-state><span>{{.}}</span></p>{{end}} |
| -{{with .Note}}<p equipo-note-caption data-connection-note><span>{{.}}</span></p>{{end}} |
| -{{if .Connecting}}{{with .Prompt}}{{if eq .Kind "device_code"}}<p data-device-code>{{printf (copy "chat.connections.device") .URL .Code}}</p><p><a rst-btn="primary" href="{{.URL}}" rel="noopener" target="_blank">{{.URL}}</a> <code>{{.Code}}</code></p> |
| -{{else if eq .Kind "link"}}<p><a rst-btn="primary" href="{{.URL}}" rel="noopener" target="_blank" data-sign-in>{{copy "chat.connections.sign_in_claude"}}</a></p> |
| -{{else if eq .Kind "terminal"}}<p data-finish-on>{{printf (copy "chat.connections.finish_on") $.Models.Runner}}</p><p>{{copy "chat.connections.finish_how"}}</p><p><code>{{.Code}}</code></p><form method="post" action="/conversation/connections"><input type="hidden" name="provider" value="claude"><input type="hidden" name="same_machine" value="1"><button equipo-link type="submit" data-same-machine>{{copy "chat.connections.same_machine"}}</button></form>{{end}}{{end}} |
| -<form method="post" action="/conversation/connections/{{.ID}}/cancel"><button equipo-link type="submit" data-connection-cancel>{{copy "chat.connections.cancel"}}</button></form>{{end}} |
| -</li>{{end}}</ul>{{else}}<p data-empty-state="chat.connections.empty">{{copy "chat.connections.empty"}}</p>{{end}} |
| -<footer equipo-notebook-foot><form method="post" action="/conversation/connections" equipo-actions><input type="hidden" name="provider" value="codex"><button rst-btn type="submit" data-add="codex">{{copy "chat.connections.add_codex"}}</button></form><form method="post" action="/conversation/connections" equipo-actions><input type="hidden" name="provider" value="claude"><button rst-btn type="submit" data-add="claude">{{copy "chat.connections.add_claude"}}</button></form></footer> |
| +<ul equipo-conn-list role="list" data-connection-list aria-live="polite"> |
| +{{range .Models.Items}}{{if .Connecting}}{{template "conn-attempt" .}}{{else}}<li equipo-conn-row data-connection="{{.ID}}" data-provider="{{.Provider}}"><span equipo-conn-mark data-provider="{{.Provider}}" aria-hidden="true">{{slice .Name 0 1}}</span><div equipo-conn-who><p><strong>{{.Name}}</strong>{{with .Label}} <span equipo-conn-account>{{.}}</span>{{end}}</p>{{if .State}}<p equipo-conn-state data-connection-state><i equipo-conn-dot data-tone="{{.Tone}}" aria-hidden="true"></i>{{.State}}{{with .Usage}} <span equipo-conn-usage>· {{.}}</span>{{end}}</p>{{end}}{{with .Note}}<p equipo-conn-state data-connection-note>{{.}}</p>{{end}}</div>{{if .SignOut}}<details equipo-conn-more><summary aria-label="{{copy "chat.connections.more"}}">⋯</summary><form method="post" action="/conversation/connections/{{.ID}}/sign-out"><button equipo-link type="submit" data-sign-out>{{copy "chat.connections.sign_out"}}</button></form></details>{{end}}</li>{{end}} |
| +{{else}}<li data-empty-state="chat.connections.empty">{{copy "chat.connections.empty"}}</li>{{end}} |
| +</ul> |
| +{{if .Models.Connecting}}<noscript><p equipo-conn-small><a href="/conversation/connections">{{copy "chat.connections.check_again"}}</a></p></noscript>{{end}} |
| +<footer equipo-conn-add><form method="post" action="/conversation/connections" data-add-form><input type="hidden" name="provider" value="codex"><button rst-btn type="submit" data-add="codex">{{copy "chat.connections.add_codex"}}</button></form><form method="post" action="/conversation/connections" data-add-form><input type="hidden" name="provider" value="claude"><button rst-btn type="submit" data-add="claude">{{copy "chat.connections.add_claude"}}</button></form></footer> |
| </section> |
| +<template data-loading-template>{{template "conn-attempt" (loadingLine "codex")}}</template> |
| +<template data-loading-template-claude>{{template "conn-attempt" (loadingLine "claude")}}</template> |
| {{end}} |
diff --git a/internal/headless/browser_connections_test.go b/internal/headless/browser_connections_test.go| index 6f806a9f..dcc4dc69 100644 |
| --- a/internal/headless/browser_connections_test.go |
| +++ b/internal/headless/browser_connections_test.go |
| @@ -5,7 +5,9 @@ package headless |
| import ( |
| "context" |
| "fmt" |
| + "os" |
| "path/filepath" |
| + "strconv" |
| "testing" |
| "time" |
| @@ -43,23 +45,101 @@ func connectionsPage(t *testing.T, inst *thintest.Instance) *page { |
| return p |
| } |
| -// A1 and A4: Add Codex shows OpenAI's page and the code, and the page |
| -// turns to the connection once the person approves; Add Claude, with the |
| -// browser elsewhere, shows only the finish-on-runner card. |
| +// connShot writes docs/mockups/built/2026-11-08/conn-<name>-<width>.png |
| +// when EQUIPO_CONN_SHOTS is set. |
| +func connShot(t *testing.T, p *page, name string, width int64) { |
| + t.Helper() |
| + if os.Getenv("EQUIPO_CONN_SHOTS") == "" { |
| + return |
| + } |
| + dir := filepath.Join("..", "..", "docs", "mockups", "built", "2026-11-08") |
| + if err := os.MkdirAll(dir, 0755); err != nil { |
| + t.Fatal(err) |
| + } |
| + var shot []byte |
| + p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| + var err error |
| + shot, err = chromedp.FullScreenshot(90)(ctx, target) |
| + return err |
| + })) |
| + if err := os.WriteFile(filepath.Join(dir, "conn-"+name+"-"+strconv.FormatInt(width, 10)+".png"), shot, 0644); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// stayed is true while the page is the one first loaded: a reload or a |
| +// navigation loses the mark. |
| +const stayed = `window.__equipoStayed === true && performance.getEntriesByType('navigation').length === 1` |
| + |
| +// A1 and A4: Add Codex shows its card at once (a loading line, then the |
| +// three steps with the code once), Copy copies, and the approval lands in |
| +// place, with no reload; Add Claude, with the browser elsewhere, shows |
| +// only the finish-on-runner steps. |
| func TestBrowserConnectionsAdd(t *testing.T) { |
| - _, inst, r := localEnv(t) |
| + for _, width := range []int64{390, 1280} { |
| + t.Run(strconv.FormatInt(width, 10), func(t *testing.T) { |
| + _, inst, r := localEnv(t) |
| + r.start(t) |
| + c := inst.Cookie() |
| + p := openPage(t, inst.URL, c.Name, c.Value, width, 900, width > 600) |
| + t.Cleanup(p.stop) |
| + p.run(chromedp.Navigate(inst.URL+"/conversation/connections"), browsertest.Wait(`!!document.querySelector('[data-connections]')`)) |
| + p.check(`(()=>{window.__equipoStayed=true;return !!document.querySelector('[data-add="codex"]') && !!document.querySelector('[data-add="claude"]')})()`, "no Add buttons") |
| + p.check(`!document.querySelector('meta[http-equiv="refresh"]')`, "the page refreshes itself") |
| + p.check(`(()=>{document.querySelector('[data-add="codex"]').click();return !!document.querySelector('[data-connecting][data-provider="codex"]')})()`, "no card the instant Add Codex is tapped") |
| + p.run(browsertest.Wait(`!!document.querySelector('[data-device-code]')`)) |
| + p.check(`(()=>{const card=document.querySelector('[data-connecting][data-provider="codex"]');const code=card.querySelector('[data-code]').textContent;const open=card.querySelector('[data-open-provider]');return /^FAKE-/.test(code) && card.textContent.split(code).length===2 && open.getAttribute('href')==='https://auth.openai.com/codex/device' && open.target==='_blank' && !card.textContent.includes('auth.openai.com') && card.querySelectorAll('ol > li').length===3})()`, "the device code card is not the three steps with the code once") |
| + connShot(t, p, "codex-code", width) |
| + p.check(`(()=>{document.querySelector('[data-device-code] [data-copy]').click();return true})()`, "Copy") |
| + p.run(browsertest.Wait(`document.querySelector('[data-device-code] [data-copy]').textContent==='Copied'`)) |
| + writeJSON(t, filepath.Join(r.root, "accounts", ".fake-device.json"), map[string]any{"email": second, "plan": "pro"}) |
| + p.run(waitLong(`[...document.querySelectorAll('[data-connection-state]')].some(e=>e.textContent.includes('Healthy')) && document.body.textContent.includes('` + second + `') && !document.querySelector('[data-device-code]')`)) |
| + p.check(stayed, "the page reloaded or navigated while the code was approved") |
| + connShot(t, p, "codex-connected", width) |
| + p.check(`(()=>{document.querySelector('[data-add="claude"]').click();return !!document.querySelector('[data-connecting][data-provider="claude"]')})()`, "no card the instant Add Claude is tapped") |
| + p.run(browsertest.Wait(`!!document.querySelector('[data-finish-on]')`)) |
| + p.check(`document.querySelector('[data-finish-on] [data-command]').textContent.includes('equipo-runner login claude') && document.querySelectorAll('[data-finish-on] > li').length===3 && !!document.querySelector('[data-finish-on] [data-copy]') && !!document.querySelector('[data-same-machine]') && !document.querySelector('[data-sign-in]') && !document.querySelector('input[type="password"],input[name="code"]')`, "the finish-on-runner card is not the only way shown, or it asks for a paste") |
| + connShot(t, p, "claude-terminal", width) |
| + p.check(`(()=>{document.querySelector('[data-connecting][data-provider="claude"] [data-connection-cancel]').click();return true})()`, "Cancel") |
| + p.run(waitLong(`!document.querySelector('[data-connecting]')`)) |
| + p.check(stayed, "the page reloaded or navigated") |
| + }) |
| + } |
| +} |
| + |
| +// Paul, 2026-11-08: turns that wait for a connection show no thinking |
| +// line and no timer, live or after a reload: a quiet status under each |
| +// waiting message and one card for the conversation; once a connection |
| +// is added they run, in order. |
| +func TestBrowserWaitingTurns(t *testing.T) { |
| + env, inst, r := localEnv(t) |
| r.start(t) |
| - p := connectionsPage(t, inst) |
| - p.run(chromedp.Navigate(inst.URL+"/conversation/connections"), browsertest.Wait(`!!document.querySelector('[data-connections]')`)) |
| - p.check(`!!document.querySelector('[data-add="codex"]') && !!document.querySelector('[data-add="claude"]')`, "no Add buttons") |
| - p.check(`(()=>{document.querySelector('[data-add="codex"]').click();return true})()`, "Add Codex") |
| - p.run(browsertest.Wait(`!!document.querySelector('[data-device-code]')`)) |
| - p.check(`document.querySelector('[data-device-code]').textContent.includes('https://auth.openai.com/codex/device') && /FAKE-/.test(document.querySelector('[data-device-code]').textContent)`, "the device code card does not show the page and the code") |
| - writeJSON(t, filepath.Join(r.root, "accounts", ".fake-device.json"), map[string]any{"email": second, "plan": "pro"}) |
| - p.run(waitLong(`[...document.querySelectorAll('[data-connection-state]')].some(e=>e.textContent.includes('Healthy')) && document.body.textContent.includes('` + second + `') && !document.querySelector('[data-device-code]')`)) |
| - p.check(`(()=>{document.querySelector('[data-add="claude"]').click();return true})()`, "Add Claude") |
| - p.run(browsertest.Wait(`!!document.querySelector('[data-finish-on]')`)) |
| - p.check(`document.body.textContent.includes('equipo-runner login claude') && !!document.querySelector('[data-same-machine]') && !document.querySelector('[data-sign-in]') && !document.querySelector('input[type="password"],input[name="code"]')`, "the finish-on-runner card is not the only way shown, or it asks for a paste") |
| + c := inst.Cookie() |
| + const quiet = `document.querySelectorAll('[equipo-thinking]').length===0 && document.querySelectorAll('[data-no-connection]').length===1 && document.querySelectorAll('[data-waiting-connection]').length===%d && [...document.querySelectorAll('[data-waiting-connection]')].every(e=>e.textContent==='Waiting for a connection') && !document.body.textContent.includes('Thinking')` |
| + p := openPage(t, inst.URL, c.Name, c.Value, 1280, 900, true) |
| + t.Cleanup(p.stop) |
| + p.send("Can we work on the shop? limit:" + thintest.Owner) |
| + p.run(waitLong(fmt.Sprintf(quiet, 1))) |
| + p.send("And the docs after that.") |
| + p.run(waitLong(fmt.Sprintf(quiet, 2))) |
| + // The card stands after the last waiting message. |
| + p.check(`(()=>{const own=[...document.querySelectorAll('[equipo-message="own"]')];return !!(own[own.length-1].compareDocumentPosition(document.querySelector('[data-no-connection]'))&4)})()`, "the card is not after the last waiting message") |
| + time.Sleep(1500 * time.Millisecond) |
| + p.check(fmt.Sprintf(quiet, 2), "a thinking line or a timer came back") |
| + p.run(chromedp.Reload(), browsertest.Wait(`!!document.querySelector('[data-chat-stream]')`)) |
| + p.check(fmt.Sprintf(quiet, 2), "after a reload, a waiting turn shows a thinking line, or not one card") |
| + connShot(t, p, "waiting", 1280) |
| + small := openPage(t, inst.URL, c.Name, c.Value, 390, 844, false) |
| + t.Cleanup(small.stop) |
| + small.check(fmt.Sprintf(quiet, 2), "at 390, a waiting turn shows a thinking line, or not one card") |
| + connShot(t, small, "waiting", 390) |
| + // A connection arrives: both turns start on their own, in order. |
| + writeJSON(t, filepath.Join(r.root, "accounts", ".fake-device.json"), map[string]any{"email": "third@example.com", "plan": "pro"}) |
| + if _, err := env.Client.Connect(t.Context(), wire.Connect{Provider: "codex"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + p.run(waitLong(`!document.querySelector('[data-no-connection]') && !document.querySelector('[data-waiting-connection]') && document.querySelectorAll('[equipo-message="incoming"]:not([equipo-thinking])').length>=2 && document.querySelectorAll('[equipo-thinking]').length===0`)) |
| + p.check(`(()=>{const own=[...document.querySelectorAll('[equipo-message="own"]')].map(e=>e.dataset.turnId);const replies=[...document.querySelectorAll('[equipo-message="incoming"]:not([equipo-thinking])')].map(e=>e.dataset.turnId).filter(id=>own.includes(id));return replies.length===2 && replies[0]===own[0] && replies[1]===own[1]})()`, "the waiting turns did not answer in order") |
| } |
| // F1 and F7 on the conversation page: the switched line under a reply |
diff --git a/internal/headless/connections_test.go b/internal/headless/connections_test.go| index d11890ec..8d198cc1 100644 |
| --- a/internal/headless/connections_test.go |
| +++ b/internal/headless/connections_test.go |
| @@ -221,8 +221,12 @@ func connCodexDeviceCode(t *testing.T, env *Env, inst *thintest.Instance, r *loc |
| t.Fatalf("prompt %+v", code.Prompt) |
| } |
| page := inst.Get(t, "/conversation/connections") |
| - if !strings.Contains(page, "data-device-code") || !strings.Contains(page, code.Prompt.Code) || !strings.Contains(page, `http-equiv="refresh"`) { |
| - t.Fatal("device code not on the page") |
| + if !strings.Contains(page, "data-device-code") || strings.Count(page, ">"+code.Prompt.Code+"<") != 1 || !strings.Contains(page, `href="`+code.Prompt.URL+`"`) { |
| + t.Fatal("the device code is not on the page once, or OpenAI's page is not its link") |
| + } |
| + // The page never reloads itself: it follows the event stream. |
| + if strings.Contains(page, `http-equiv="refresh"`) || strings.Contains(page, ">"+code.Prompt.URL+"<") { |
| + t.Fatal("the page refreshes itself, or shows OpenAI's address as text") |
| } |
| writeJSON(t, approve, map[string]any{"email": second, "plan": "pro"}) |
| s.wait(t, "codex healthy", time.Minute, func(cv *thintest.Conversation) bool { |
diff --git a/internal/runner/thin/ask.go b/internal/runner/thin/ask.go| index 77dddb09..3aaa0f8f 100644 |
| --- a/internal/runner/thin/ask.go |
| +++ b/internal/runner/thin/ask.go |
| @@ -462,8 +462,17 @@ func (e *Engineer) sweepKept(ctx context.Context, s *State) { |
| } |
| } |
| } |
| + // Logged when the kept sessions change, or hourly, not on every sweep. |
| if e.O.Logger != nil && (len(dirs) > 0 || kept > 0) { |
| - e.O.Logger.Info("kept sessions", "kept", kept, "bytes", bytes, "expired", len(dirs)) |
| + e.keptLog.Lock() |
| + changed := kept != e.keptLast[0] || bytes != e.keptLast[1] || len(dirs) > 0 || time.Since(e.keptAt) >= time.Hour |
| + if changed { |
| + e.keptLast, e.keptAt = [2]int64{int64(kept), bytes}, time.Now() |
| + } |
| + e.keptLog.Unlock() |
| + if changed { |
| + e.O.Logger.Info("kept sessions", "kept", kept, "bytes", bytes, "expired", len(dirs)) |
| + } |
| } |
| } |
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go| index b7f59579..60880a8a 100644 |
| --- a/internal/runner/thin/engineer.go |
| +++ b/internal/runner/thin/engineer.go |
| @@ -14,6 +14,7 @@ import ( |
| "path/filepath" |
| "slices" |
| "strings" |
| + "sync" |
| "time" |
| "amadan.net/oficina/equipo/internal/runner" |
| @@ -46,6 +47,11 @@ const ( |
| // (workspace read-write, nothing else), the runner's own commit, and the |
| // push through forge. |
| type Engineer struct { |
| + // keptLog holds the last kept-sessions figures logged and when. |
| + keptLog sync.Mutex |
| + keptLast [2]int64 |
| + keptAt time.Time |
| + |
| O ClaudeOptions |
| Clones *Clones |
| Forge Forge |
diff --git a/internal/runner/thin/state.go b/internal/runner/thin/state.go| index 595b3b11..b978e92a 100644 |
| --- a/internal/runner/thin/state.go |
| +++ b/internal/runner/thin/state.go |
| @@ -467,6 +467,15 @@ func (s *State) Recover(ctx context.Context) error { |
| } |
| rows.Close() |
| for _, x := range all { |
| + // A run held waiting for a connection ran nothing: a restart is |
| + // not a crash for it. It stays as it is and is held again. |
| + var body string |
| + if err := t.QueryRow("SELECT body FROM outbox WHERE turn_id=? AND kind=? ORDER BY seq DESC LIMIT 1", x.turn, wire.FrameTurn).Scan(&body); err == nil && x.cancel == 0 { |
| + var last wire.TurnReport |
| + if json.Unmarshal([]byte(body), &last) == nil && last.State == wire.TurnWaiting && last.Reason == wire.ReasonNoConnection && last.Attempt == x.attempt { |
| + continue |
| + } |
| + } |
| if x.cancel != 0 { |
| // The previous process is gone (its namespaces die with it, |
| // and their exits are verified at start): the cancelled |
diff --git a/internal/runner/thin/waiting_test.go b/internal/runner/thin/waiting_test.go| new file mode 100644 |
| index 00000000..1244e7b2 |
| --- /dev/null |
| +++ b/internal/runner/thin/waiting_test.go |
| @@ -0,0 +1,50 @@ |
| +package thin |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// A turn held waiting for a connection ran nothing: restarting the runner |
| +// (twice, as two restages would) neither fails it runner_restarted nor |
| +// moves it to a new attempt; it stays held. |
| +func TestRecoverKeepsWaitingTurns(t *testing.T) { |
| + ctx := context.Background() |
| + s, err := OpenState(ctx, t.TempDir()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer s.Close() |
| + if err = s.Accept(ctx, "c1", wire.MessageCommand{Person: "p@example.com", TurnID: "t1", Attempt: 1, Text: "hello", Tail: []wire.TailMessage{}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + r, ok, err := s.next(ctx, "p@example.com") |
| + if err != nil || !ok { |
| + t.Fatal(ok, err) |
| + } |
| + if err = s.Hold(ctx, r, wire.ReasonNoConnection); err != nil { |
| + t.Fatal(err) |
| + } |
| + for i := 0; i < 2; i++ { |
| + if err = s.Recover(ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + held, ok, err := s.next(ctx, "p@example.com") |
| + if err != nil || !ok || held.Attempt != 1 { |
| + t.Fatalf("after two restarts: %+v %v %v", held, ok, err) |
| + } |
| + frames, _, err := s.Unacked(ctx, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, f := range frames { |
| + var v wire.TurnReport |
| + if f.Type == wire.FrameTurn && json.Unmarshal(f.Data, &v) == nil && (v.Reason == "runner_restarted" || v.State == wire.TurnRunning) { |
| + t.Fatalf("a restart reported %+v for a waiting turn", v) |
| + } |
| + } |
| +} |
diff --git a/scripts/runner-reference-allowlist.json b/scripts/runner-reference-allowlist.json| index f2e89301..36c57582 100644 |
| --- a/scripts/runner-reference-allowlist.json |
| +++ b/scripts/runner-reference-allowlist.json |
| @@ -10592,7 +10592,7 @@ |
| }, |
| { |
| "path": "internal/headless/browser_connections_test.go", |
| - "line_sha256": "53a8c0511e427787bec4a3821f78e163b9a941fa4cc399b5c919efff9ed918f3", |
| + "line_sha256": "c5e34cedcb824cb0e876850dee24c3911cef71569b56d93da85bb03133e71165", |
| "match": "equipo-runner", |
| "count": 1, |
| "reason": "Browser test checks the finish-on-runner card shows the equipo-runner login claude command" |
| @@ -10694,5 +10694,33 @@ |
| "match": "equipo-runner", |
| "count": 1, |
| "reason": "Connections slice 1 progress log names the equipo-runner terminal sign-in command people run" |
| + }, |
| + { |
| + "path": "internal/equipo/static/connections.js", |
| + "line_sha256": "77b314967005adac99f81c78610dc45226c91f970e7b27509270e80670ffacc3", |
| + "match": "Node", |
| + "count": 1, |
| + "reason": "DOM API name (cloneNode, parentNode, selectNodeContents) in the Connections page script, not Node.js" |
| + }, |
| + { |
| + "path": "internal/equipo/static/connections.js", |
| + "line_sha256": "f86cd8a0d0a25a9fb9f011fa5b4f2ae8e11e007f19971a7128afb02a3be98d3d", |
| + "match": "Node", |
| + "count": 1, |
| + "reason": "DOM API name (cloneNode, parentNode, selectNodeContents) in the Connections page script, not Node.js" |
| + }, |
| + { |
| + "path": "internal/equipo/static/connections.js", |
| + "line_sha256": "8ef5405a661a07623128daf44bd2f832b8440580f0471bd723b1ca0241daf5aa", |
| + "match": "Node", |
| + "count": 1, |
| + "reason": "DOM API name (cloneNode, parentNode, selectNodeContents) in the Connections page script, not Node.js" |
| + }, |
| + { |
| + "path": "internal/equipo/static/connections.js", |
| + "line_sha256": "11ce757fe94e222c9db55dd4cfcc8a79d52b1bd5da0a4baed7b9d47949166145", |
| + "match": "Node", |
| + "count": 1, |
| + "reason": "DOM API name (cloneNode, parentNode, selectNodeContents) in the Connections page script, not Node.js" |
| } |
| ] |