oficina / base Public

Paused jobs on the web: clock mark, Carry on now relay, team zone to Equipo

Human

Prompt

Build Base's half of Paul's approved "clearer paused work" design: a paused job pill (clock mark, calm indigo, "Paused until 21:00"), the job view's detail and "Carry on now", a distinct stopped mark, the carry_on relay, the member's zone to Equipo, and Europe/Dublin as the default BASE_TIMEZONE.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Equipo client opts in to job_states=paused on the snapshot and events, keeps carry_on on paused job cards only, relays POST cards/{id}/carry_on, and PUTs the team's zone (BASE_TIMEZONE) to assistant/time-zone once per connection and per member per start. New route POST /ask/cards/{id}/carry_on (form 303 /ask with scripts off, JSON {card} for ask.js and the apps; 409 {state:ready} redraws). chat.html and ask.js draw paused (clock on --st-pause #4B55C9/#AEB8FF) and a square for stopped. The fake Equipo follows Equipo's feat/paused-work contract (52563a02, implemented at dce7c015). Default BASE_TIMEZONE is Europe/Dublin.
Agent notes
An older Equipo never sends paused (and an Equipo that predates the opt-in ignores the query): nothing changes, the JSON is byte-identical (carry_on omitempty). Equipo 404 on PUT time-zone is treated as done until restart. Browser test TestAskJobPausedCarriesOn covers ask.js (contrast in both themes).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 02e4f8d2d060389236d40343cefdc29869155ffd parent 1c97c4d
18 files changed, +738 −29
  • .env.local.example +1 −1
  • README.md +1 −1
  • docs/api/base-native-v1.md +19 −3
  • internal/browsertest/cards_test.go +65 −0
  • internal/config/config.go +1 −1
  • internal/config/config_test.go +1 −1
  • internal/equipo/chat.go +42 −6
  • internal/equipo/equipo_test.go +121 −0
  • internal/equipo/equipotest/chat.go +131 −2
  • internal/look/static/app.css +10 −2
  • internal/look/static/ask.js +50 −4
  • internal/web/app.go +1 −1
  • internal/web/ask.go +14 −2
  • internal/web/ask_connect.go +24 −0
  • internal/web/ask_relay.go +21 −0
  • internal/web/templates/partials/chat.html +5 −4
  • internal/webtest/ask_native_contract_test.go +41 −0
  • internal/webtest/ask_test.go +190 −1
diff --git a/.env.local.example b/.env.local.example
index f41012d..9ee7885 100644
--- a/.env.local.example
+++ b/.env.local.example
@@ -9,7 +9,7 @@ BASE_OWNER=owner@example.com
# openssl rand -base64 32
BASE_INSTANCE_KEY=
BASE_APPS_DOMAIN=apps.example.com
-BASE_TIMEZONE=Europe/London
+BASE_TIMEZONE=Europe/Dublin
BASE_PLATFORM_CONSOLE=https://console.example.com
BASE_PLATFORM_ACCOUNT=acme
BASE_PLATFORM_INSTANCE_TOKEN=
diff --git a/README.md b/README.md
index 7b74326..edbf992 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@ Everything is an environment variable. `BASE_ORIGIN`, `BASE_OWNER` and
- `BASE_NAME` is what your team calls Base, such as "Acme" (default `Base`).
- `BASE_SLUG` names the apps' hostnames: `<slug>-<appid>.<BASE_APPS_DOMAIN>`.
Lowercase letters, digits and `-`, at most 19 characters (default `base`).
-- `BASE_TIMEZONE` is where dates are shown (default `Europe/London`).
+- `BASE_TIMEZONE` is where dates are shown, and the time zone Ask sends Equipo so the Assistant writes times in it ("Paused until 21:00"); default `Europe/Dublin`.
- `BASE_ASSERTION_KEY` is Base's signing key. `go run ./tools/keygen` prints
a fresh one. Without it, no one can open an installed app. Keep it stable
across restarts: apps check sign-ins against its public half.
diff --git a/docs/api/base-native-v1.md b/docs/api/base-native-v1.md
index 620fa6d..5717240 100644
--- a/docs/api/base-native-v1.md
+++ b/docs/api/base-native-v1.md
@@ -138,14 +138,18 @@ links to http(s) only, bold and italics).
**Turn** `{"id", "kind", "state": "queued"|"running"|"waiting"|"replied"|"failed"|"cancelled", "reason"}`.
-**Card** `{"id", "revision", "kind", "state", "question", "options": [{"value","label"}], "links": [{"label","url","rel"?}], "result", "job"?, "detail"?, "started_at"?, "turn_id"?}`.
+**Card** `{"id", "revision", "kind", "state", "question", "options": [{"value","label"}], "links": [{"label","url","rel"?}], "result", "job"?, "detail"?, "started_at"?, "carry_on"?, "turn_id"?}`.
- `kind` is `question`, `confirm`, `outcome`, `connect` or `job`; a card is
`open` while it waits for an answer. Every link is absolute http(s).
- `rel` is `equipo` (a job's page in Equipo) or `oficina_connect` (Base's
own `/ask/oficina/connect`, a browser flow).
- A job card has no options; its `state` is `working`, `asking`, `ready`,
- `done` or `stopped`; `result` is its short status, `detail` one sentence
- more and `started_at` when it began.
+ `done`, `paused` or `stopped`; `result` is its short status, `detail` one sentence
+ more and `started_at` when it began. A `paused` job carries on by itself
+ (draw it with the clock mark); its `result` and `detail` are Equipo's,
+ already in the team's time zone ("Paused until 21:00"): show them as
+ given. `carry_on: true` (on a `paused` job card only, else absent) offers
+ "Carry on now" (`POST /ask/cards/{id}/carry_on`).
- `job` names the job card a card belongs to; `turn_id`, on a connect card
from the stream, the turn that raised it.
@@ -202,6 +206,18 @@ Form: `choice` (an option's `value`), `revision` (the card's, as seen) and
- `409 {"state":"ready"}`: the card moved on (answered, or a newer
revision). Reload `/ask/state` to redraw it.
+### `POST /ask/cards/{id}/carry_on`
+
+A paused job's "Carry on now". Form: `revision` (the job card's, as seen)
+and `key`, a fresh idempotency key kept until an answer settles the
+outcome (a resend after a network error or a `502` reuses it).
+
+- `200 {"card": Card}`: the job card as it is now (working again).
+- `409 {"state":"ready"}`: the job moved on (a newer revision), is no longer
+ paused, or no longer offers it (Equipo's `card_stale`, `not_paused`,
+ `carry_on_unavailable`). Reload `/ask/state` to redraw it; never resend.
+- Without scripts, the form answers `303 /ask`.
+
### Every write's other answers
| status | body | meaning |
diff --git a/internal/browsertest/cards_test.go b/internal/browsertest/cards_test.go
index d6cdff6..6a22e9b 100644
--- a/internal/browsertest/cards_test.go
+++ b/internal/browsertest/cards_test.go
@@ -764,3 +764,68 @@ func TestAskJobViewScriptsOffInPlace(t *testing.T) {
rig.Screen(".ask-page", "the job view opened in place, scripts off")
}
}
+
+// A paused job (clearer paused work, 2026-11-24): the pill's clock mark on
+// the calm indigo, its status as Equipo wrote it, and in its view the
+// sentence and "Carry on now" with the line under it, readable in both
+// themes. Carry on now posts once, the card's revision and a key (the
+// body's idempotency_key and the Idempotency-Key header), and the job
+// redraws in place, working, with no button. Stopped's mark is a square.
+func TestAskJobPausedCarriesOn(t *testing.T) {
+ rig, f := askBase(t)
+ openPanel(t, rig)
+ wait := func(js string) {
+ t.Helper()
+ drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second)))
+ }
+ settle := func() { drive(t, rig, chromedp.Sleep(250*time.Millisecond)) }
+ stopped := f.AskJob("Invoice reminders")
+ f.SetJob(stopped, "stopped", "Stopped: needs you", "It needs you.")
+ id := f.AskJob("Bakery website")
+ f.PauseJob(id, "Paused until 21:00", "It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).", true)
+ job := `#ask-panel li.job[data-job="` + id + `"]`
+ wait(`document.querySelector(` + strconv.Quote(job) + `)?.dataset.state === "paused" && document.querySelector(` + strconv.Quote(job+` .jv-act`) + `) !== null`)
+ drive(t, rig, prefersScheme("dark"), chromedp.Sleep(300*time.Millisecond))
+ if got := harness.Evaluate[string](rig, `[document.querySelector(`+strconv.Quote(job+` .pill-stage`)+`).textContent,
+ document.querySelector(`+strconv.Quote(job+` .pill-main .state-mark path`)+`).getAttribute("d"),
+ getComputedStyle(document.querySelector(`+strconv.Quote(job+` .pill-main .state-mark`)+`)).backgroundColor,
+ document.querySelector('#ask-panel li.job[data-job="`+stopped+`"] .pill-main .state-mark path').getAttribute("d")].join("|")`); got !=
+ "Paused until 21:00|M19.2 12a7.2 7.2 0 1 1-14.4 0a7.2 7.2 0 1 1 14.4 0zM12 8.6V12l2.4 1.6|rgb(174, 184, 255)|M9 7.5h6a1.5 1.5 0 0 1 1.5 1.5v6a1.5 1.5 0 0 1-1.5 1.5H9a1.5 1.5 0 0 1-1.5-1.5V9A1.5 1.5 0 0 1 9 7.5z" {
+ t.Errorf("paused pill (status|mark|colour|stopped's mark): %s", got)
+ }
+ drive(t, rig, chromedp.Click(chromedp.CSS(job+` summary`)))
+ settle()
+ view := job + ` .jobview`
+ if got := harness.Evaluate[string](rig, `(() => { const v = document.querySelector(`+strconv.Quote(view)+`);
+ return [v.checkVisibility(), v.querySelector(".jv-stage").textContent, v.querySelector(".jv-detail").textContent,
+ v.querySelector(".jv-act button").textContent, v.querySelector(".jv-act small").textContent].join("|"); })()`); got !=
+ "true|Paused until 21:00|It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).|Carry on now|Uses your other plan, at no extra cost." {
+ t.Errorf("the paused job's view: %s", got)
+ }
+ for _, scheme := range []string{"dark", "light"} {
+ drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond))
+ mobileShot(t, rig, "jobview-paused-"+scheme)
+ checkContrast(t, rig, "the paused job's view, "+scheme, view+" .jv-stage", view+" .jv-detail", view+" .jv-act button", view+" .jv-act small")
+ iconContrast(t, rig, "the paused mark, "+scheme, job+" .pill-main .state-mark svg")
+ }
+ if got := harness.Evaluate[string](rig, `getComputedStyle(document.querySelector(`+strconv.Quote(job+` .pill-main .state-mark`)+`)).backgroundColor`); got != "rgb(75, 85, 201)" {
+ t.Errorf("paused's colour in light: %s", got)
+ }
+ drive(t, rig, prefersScheme("dark"))
+ rig.Screen("#ask-panel", "a paused job's view, with Carry on now")
+
+ drive(t, rig, chromedp.Click(chromedp.CSS(view+` .jv-act button`)))
+ wait(`document.querySelector(` + strconv.Quote(job) + `)?.dataset.state === "working"`)
+ settle()
+ if n := harness.Evaluate[int](rig, `document.querySelectorAll(`+strconv.Quote(job+` .jv-act`)+`).length`); n != 0 {
+ t.Errorf("Carry on now still shows on a working job")
+ }
+ calls := f.Calls("/api/v1/assistant/cards/" + id + "/carry_on")
+ if len(calls) != 1 {
+ t.Fatalf("Carry on now went %d times", len(calls))
+ }
+ key := calls[0].Header.Get("Idempotency-Key")
+ if want := `{"idempotency_key":"` + key + `","revision":3}`; key == "" || strings.TrimSpace(calls[0].Body) != want {
+ t.Errorf("sent %s with key %q, want %s", calls[0].Body, key, want)
+ }
+}
diff --git a/internal/config/config.go b/internal/config/config.go
index 7210701..82b4e39 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -97,7 +97,7 @@ func Load(getenv func(string) string) (Config, error) {
}
tz := get("TIMEZONE")
if tz == "" {
- tz = "Europe/London"
+ tz = "Europe/Dublin"
}
if cfg.Timezone, err = time.LoadLocation(tz); err != nil {
return Config{}, fmt.Errorf("BASE_TIMEZONE: %w", err)
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 48c8a51..ff98072 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -29,7 +29,7 @@ func TestLoadRequiresOriginAndOwner(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if cfg.Owner != "owner@example.com" || cfg.Slug != "base" || cfg.Timezone.String() != "Europe/London" {
+ if cfg.Owner != "owner@example.com" || cfg.Slug != "base" || cfg.Timezone.String() != "Europe/Dublin" {
t.Errorf("defaults wrong: %+v", cfg)
}
}
diff --git a/internal/equipo/chat.go b/internal/equipo/chat.go
index 18332e3..9c119ff 100644
--- a/internal/equipo/chat.go
+++ b/internal/equipo/chat.go
@@ -51,7 +51,9 @@ type Turn struct {
// ended (Result). Base knows no kind's words of its own. A job card's
// question is the job's title, Result its short status, Detail one
// sentence more and StartedAt when it began; Job is the job card a
-// go-ahead or Publish card belongs to.
+// go-ahead or Publish card belongs to. A paused job's Result and Detail
+// are already in the person's time zone ("Paused until 21:00"), and
+// CarryOn says the person may start it again now (CarryOnNow).
type Card struct {
ID string `json:"id"`
Revision int64 `json:"revision"`
@@ -64,6 +66,7 @@ type Card struct {
Job string `json:"job,omitempty"`
Detail string `json:"detail,omitempty"`
StartedAt *time.Time `json:"started_at,omitempty"`
+ CarryOn bool `json:"carry_on,omitempty"`
// Turn is the turn that raised a connect card, as its event said
// (WithTurn); never read from the card's own fields.
Turn string `json:"turn_id,omitempty"`
@@ -101,6 +104,9 @@ const (
JobReady = "ready"
JobDone = "done"
JobStopped = "stopped"
+ // JobPaused is a job held for a while (its allowance or spending limit
+ // reached, its runner offline) that carries on by itself.
+ JobPaused = "paused"
)
// LinkEquipo is the rel of a job card's link to the job's page in Equipo.
@@ -118,7 +124,7 @@ const OficinaConnectPath = "/ask/oficina/connect"
// options and links, and a link only if it is an http(s) URL (WebURL),
// with a rel only if it is LinkEquipo (or, for CleanAt, Base's own connect link). A job card has no options, and is
// kept only in a state Base knows; Detail and StartedAt are kept on a job
-// card only, and Job only when it looks like a card id (validJob). ok is
+// card only, CarryOn only on a paused one, and Job only when it looks like a card id (validJob). ok is
// false for every other kind of card.
func (c Card) Clean() (Card, bool) { return c.CleanAt("") }
@@ -130,7 +136,7 @@ func (c Card) CleanAt(base string) (Card, bool) {
case CardQuestion, CardConfirm, CardOutcome, CardConnect:
case CardJob:
switch c.State {
- case JobWorking, JobAsking, JobReady, JobDone, JobStopped:
+ case JobWorking, JobAsking, JobReady, JobDone, JobStopped, JobPaused:
default:
return Card{}, false
}
@@ -141,6 +147,7 @@ func (c Card) CleanAt(base string) (Card, bool) {
Options: []Option{}, Links: []Link{}, Result: c.Result}
if c.Kind == CardJob {
out.Detail, out.StartedAt = c.Detail, c.StartedAt
+ out.CarryOn = c.CarryOn && c.State == JobPaused
} else {
for _, o := range c.Options {
out.Options = append(out.Options, Option{Value: o.Value, Label: o.Label})
@@ -259,13 +266,27 @@ type Answered struct {
Turn Turn `json:"turn"`
}
+// JobStates is the query that opts in to the job states Base draws
+// beyond the five every Equipo sends: without it, Equipo sends a paused
+// job as working (same result and detail, no carry_on), since an older
+// Base drops a state it does not know.
+const JobStates = "job_states=" + JobPaused
+
// Snapshot reads the person's conversation in one go.
func (c *Client) Snapshot(ctx context.Context, token string) (Snapshot, error) {
var out Snapshot
- _, err := c.call(ctx, http.MethodGet, assistant+"/snapshot", token, "", nil, nil, &out)
+ _, err := c.call(ctx, http.MethodGet, assistant+"/snapshot?"+JobStates, token, "", nil, nil, &out)
return out, err
}
+// SetTimeZone tells Equipo the person's IANA time zone, which the times in
+// the copy it writes for them are in (a paused job's "Paused until
+// 21:00"). Equipo answers 422 invalid_input to a zone it does not know.
+func (c *Client) SetTimeZone(ctx context.Context, token, zone string) error {
+ _, err := c.call(ctx, http.MethodPut, assistant+"/time-zone", token, NewKey(), nil, map[string]string{"time_zone": zone}, nil)
+ return err
+}
+
// Send sends the person's message: ErrNoRunner or ErrRunnerTooOld when
// the person has no runner that can answer. key makes a retry safe:
// Equipo keeps one message per key. It goes as the body's
@@ -292,6 +313,21 @@ func (c *Client) Answer(ctx context.Context, token, id, choice string, revision
return out, err
}
+// CarryOnNow starts paused job card id again now, at the card's revision:
+// what "Carry on now" asks, offered while the card's CarryOn is set. The
+// answer is the card as it is now (200 {"card": …}); the same key again
+// gives the same answer. A 409 says why it cannot: card_stale (the card
+// moved on), not_paused or carry_on_unavailable. key goes as the body's
+// idempotency_key and the Idempotency-Key header.
+func (c *Client) CarryOnNow(ctx context.Context, token, id string, revision int64, key string) (Card, error) {
+ var out struct {
+ Card Card `json:"card"`
+ }
+ in := map[string]any{"revision": revision, "idempotency_key": key}
+ _, err := c.call(ctx, http.MethodPost, assistant+"/cards/"+url.PathEscape(id)+"/carry_on", token, key, nil, in, &out)
+ return out.Card, err
+}
+
// RegisterHost tells Equipo where the person's Base operations live
// (origin) and the token Base minted for them (hostToken), which the
// Assistant presents when it calls them. A second call replaces the
@@ -306,9 +342,9 @@ func (c *Client) RegisterHost(ctx context.Context, token, origin, hostToken stri
// now). It gives up when the headers take longer than StreamHeaderTimeout.
// The caller reads and closes the body; cancelling ctx ends the stream.
func (c *Client) Events(ctx context.Context, token, after string) (*http.Response, error) {
- u := c.origin + assistant + "/events"
+ u := c.origin + assistant + "/events?" + JobStates
if after != "" {
- u += "?after=" + url.QueryEscape(after)
+ u += "&after=" + url.QueryEscape(after)
}
ctx, cancel := context.WithCancel(ctx)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
diff --git a/internal/equipo/equipo_test.go b/internal/equipo/equipo_test.go
index e59e3f1..49a542a 100644
--- a/internal/equipo/equipo_test.go
+++ b/internal/equipo/equipo_test.go
@@ -475,3 +475,124 @@ func TestFakeGlanceIsLiveOnly(t *testing.T) {
}
}
}
+
+// A paused job is kept, with carry_on when Equipo offers it; carry_on on a
+// job in any other state, or on another kind of card, is dropped. A job
+// card from an Equipo that never sends carry_on cleans to the same JSON
+// as before (no carry_on key at all).
+func TestCardCleanPausedJob(t *testing.T) {
+ got, ok := equipo.Card{ID: "c_1", Revision: 4, Kind: equipo.CardJob, State: equipo.JobPaused, Question: "Bakery website",
+ Result: "Paused until 21:00", Detail: "It will carry on by itself at 21:00 (in 9 hours).", CarryOn: true}.Clean()
+ raw, _ := json.Marshal(got)
+ const want = `{"id":"c_1","revision":4,"kind":"job","state":"paused","question":"Bakery website","options":[],"links":[],"result":"Paused until 21:00","detail":"It will carry on by itself at 21:00 (in 9 hours).","carry_on":true}`
+ if !ok || string(raw) != want {
+ t.Errorf("paused: %v\n got %s\nwant %s", ok, raw, want)
+ }
+ for _, c := range []equipo.Card{
+ {ID: "c_2", Kind: equipo.CardJob, State: equipo.JobWorking, CarryOn: true},
+ {ID: "c_3", Kind: equipo.CardJob, State: equipo.JobStopped, CarryOn: true},
+ {ID: "c_4", Kind: equipo.CardOutcome, State: "open", CarryOn: true},
+ } {
+ got, _ := c.Clean()
+ if raw, _ := json.Marshal(got); got.CarryOn || strings.Contains(string(raw), "carry_on") {
+ t.Errorf("%s %s kept carry_on: %s", c.Kind, c.State, raw)
+ }
+ }
+}
+
+// CarryOnNow posts {revision, idempotency_key} with the key as the
+// Idempotency-Key and reads the card back from {"card"}; the same key
+// replays the answer; Equipo's 409s come back as errors with their codes.
+func TestCarryOnNow(t *testing.T) {
+ f := equipotest.New(t)
+ c := equipo.New(f.URL)
+ cred := signIn(t, f, c)
+ ctx := context.Background()
+ job := f.AskJob("Bakery website")
+ f.PauseJob(job, "Paused until 21:00", "It will carry on by itself at 21:00.", true)
+ var e *equipo.Error
+ if _, err := c.CarryOnNow(ctx, cred.Token, job, 1, "k-1"); !errors.As(err, &e) || e.Status != 409 || e.Code != "card_stale" {
+ t.Errorf("stale: %v", err)
+ }
+ card, err := c.CarryOnNow(ctx, cred.Token, job, 3, "k-2")
+ if err != nil || card.ID != job || card.State != equipo.JobWorking || card.Revision != 4 {
+ t.Fatalf("carry on: %+v %v", card, err)
+ }
+ calls := f.Calls("/api/v1/assistant/cards/" + job + "/carry_on")
+ if last := calls[len(calls)-1]; strings.TrimSpace(last.Body) != `{"idempotency_key":"k-2","revision":3}` ||
+ last.Header.Get("Idempotency-Key") != "k-2" {
+ t.Errorf("sent: %+v", last)
+ }
+ if again, err := c.CarryOnNow(ctx, cred.Token, job, 3, "k-2"); err != nil || again.Revision != 4 || again.State != equipo.JobWorking {
+ t.Errorf("replayed: %+v %v", again, err)
+ }
+ if _, err := c.CarryOnNow(ctx, cred.Token, job, 4, "k-3"); !errors.As(err, &e) || e.Code != "not_paused" {
+ t.Errorf("not paused: %v", err)
+ }
+ f.PauseJob(job, "Paused until 22:00", "", false)
+ if _, err := c.CarryOnNow(ctx, cred.Token, job, 5, "k-4"); !errors.As(err, &e) || e.Code != "carry_on_unavailable" {
+ t.Errorf("unavailable: %v", err)
+ }
+}
+
+// Base opts in to the paused state on the snapshot and the event stream
+// (job_states=paused). Without it, as for an older Base, Equipo sends a
+// paused job as working, with its result and detail and no carry_on.
+func TestPausedIsOptIn(t *testing.T) {
+ f := equipotest.New(t)
+ c := equipo.New(f.URL)
+ cred := signIn(t, f, c)
+ ctx := context.Background()
+ job := f.AskJob("Bakery website")
+ f.PauseJob(job, "Paused until 21:00", "It will carry on by itself at 21:00.", true)
+ snap, err := c.Snapshot(ctx, cred.Token)
+ if err != nil || len(snap.Cards) != 1 || snap.Cards[0].State != equipo.JobPaused || !snap.Cards[0].CarryOn {
+ t.Fatalf("opted in: %+v %v", snap.Cards, err)
+ }
+ if calls := f.Calls("/api/v1/assistant/snapshot"); calls[len(calls)-1].Query != "job_states=paused" {
+ t.Errorf("snapshot's query %q", calls[len(calls)-1].Query)
+ }
+ res, err := c.Events(ctx, cred.Token, "40")
+ if err != nil {
+ t.Fatal(err)
+ }
+ res.Body.Close()
+ if calls := f.Calls("/api/v1/assistant/events"); calls[len(calls)-1].Query != "job_states=paused&after=40" {
+ t.Errorf("events' query %q", calls[len(calls)-1].Query)
+ }
+
+ // An older Base, asking without it.
+ req, _ := http.NewRequest(http.MethodGet, f.URL+"/api/v1/assistant/snapshot", nil)
+ req.Header.Set("Authorization", "Bearer "+cred.Token)
+ raw, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer raw.Body.Close()
+ var old equipo.Snapshot
+ if json.NewDecoder(raw.Body).Decode(&old) != nil || len(old.Cards) != 1 || old.Cards[0].State != equipo.JobWorking ||
+ old.Cards[0].CarryOn || old.Cards[0].Result != "Paused until 21:00" {
+ t.Errorf("without the opt-in: %+v", old.Cards)
+ }
+}
+
+// SetTimeZone is PUT time-zone {time_zone}; a zone Equipo does not know is
+// 422 invalid_input.
+func TestSetTimeZone(t *testing.T) {
+ f := equipotest.New(t)
+ c := equipo.New(f.URL)
+ cred := signIn(t, f, c)
+ ctx := context.Background()
+ const dublin = "Europe/Dublin"
+ if err := c.SetTimeZone(ctx, cred.Token, dublin); err != nil || f.TimeZone() != dublin {
+ t.Fatalf("set: %v, zone %q", err, f.TimeZone())
+ }
+ if calls := f.Calls("/api/v1/assistant/time-zone"); len(calls) != 1 || calls[0].Method != http.MethodPut ||
+ strings.TrimSpace(calls[0].Body) != `{"time_zone":"Europe/Dublin"}` || calls[0].Header.Get("Idempotency-Key") == "" {
+ t.Errorf("sent: %+v", calls)
+ }
+ var e *equipo.Error
+ if err := c.SetTimeZone(ctx, cred.Token, "Mars/Olympus"); !errors.As(err, &e) || e.Status != 422 || e.Code != "invalid_input" {
+ t.Errorf("unknown zone: %v", err)
+ }
+}
diff --git a/internal/equipo/equipotest/chat.go b/internal/equipo/equipotest/chat.go
index 34db54f..16e4eea 100644
--- a/internal/equipo/equipotest/chat.go
+++ b/internal/equipo/equipotest/chat.go
@@ -1,6 +1,7 @@
package equipotest
import (
+ "crypto/rand"
"encoding/json"
"fmt"
"io"
@@ -58,6 +59,7 @@ type card struct {
Job string `json:"job,omitempty"`
Detail string `json:"detail,omitempty"`
StartedAt *time.Time `json:"started_at,omitempty"`
+ CarryOn bool `json:"carry_on,omitempty"`
}
type event struct {
@@ -82,12 +84,15 @@ type chat struct {
events []event // in order; a live event (a glance) has cursor 0
cursor int64 // the newest event's cursor, from 40
sent map[string]string // idempotency key to message id
+ carried map[string]card // carry_on's idempotency key to the card it answered
wake chan struct{} // closed at each new event
// runner is why the person's runner cannot answer: "no_runner",
// "runner_too_old", or "" when it can.
runner string
// address is who the bearer speaks for (the snapshot's me.address).
address string
+ // zone is the person's time zone, as PUT time-zone set it.
+ zone string
// hostStatus and hostCode, when set, are what every PUT host gets.
hostStatus int
hostCode string
@@ -100,7 +105,7 @@ type chat struct {
}
func (c *chat) init() {
- c.turns, c.sent, c.wake = map[string]*turn{}, map[string]string{}, make(chan struct{})
+ c.turns, c.sent, c.carried, c.wake = map[string]*turn{}, map[string]string{}, map[string]card{}, make(chan struct{})
c.cursor = 40
c.address = "paul@tito.io"
}
@@ -222,6 +227,21 @@ func (f *Fake) SetJob(id, state, result, detail string, links ...equipo.Link) {
}
}
+// PauseJob moves job card id to paused, with result and detail as Equipo
+// writes them in the person's time zone, and carryOn saying whether the
+// person may carry on now: a new revision, announced.
+func (f *Fake) PauseJob(id, result, detail string, carryOn bool) {
+ f.SetJob(id, equipo.JobPaused, result, detail)
+ f.cmu.Lock()
+ defer f.cmu.Unlock()
+ for _, c := range f.cards {
+ if c.ID == id && c.CarryOn != carryOn {
+ c.CarryOn, c.Revision = carryOn, c.Revision+1
+ f.emit("card", "card", c.ID, c.Revision, "", *c)
+ }
+ }
+}
+
// SetJobStarted moves when job card id started to at: a new revision,
// announced.
func (f *Fake) SetJobStarted(id string, at time.Time) {
@@ -348,6 +368,8 @@ func (f *Fake) serveChat(w http.ResponseWriter, r *http.Request) {
writeError(w, r, 404, "not_found")
case r.Method == http.MethodPut && p == "/host":
f.host(w, r)
+ case r.Method == http.MethodPut && p == "/time-zone":
+ f.timeZone(w, r)
case r.Method == http.MethodGet && p == "/snapshot":
f.snapshot(w, r)
case r.Method == http.MethodGet && p == "/messages":
@@ -360,6 +382,8 @@ func (f *Fake) serveChat(w http.ResponseWriter, r *http.Request) {
f.cancel(w, r, strings.TrimSuffix(strings.TrimPrefix(p, "/turns/"), "/cancel"))
case r.Method == http.MethodPost && strings.HasPrefix(p, "/cards/") && strings.HasSuffix(p, "/answer"):
f.answer(w, r, strings.TrimSuffix(strings.TrimPrefix(p, "/cards/"), "/answer"))
+ case r.Method == http.MethodPost && strings.HasPrefix(p, "/cards/") && strings.HasSuffix(p, "/carry_on"):
+ f.carryOn(w, r, strings.TrimSuffix(strings.TrimPrefix(p, "/cards/"), "/carry_on"))
case r.Method == http.MethodPost && p == "/oficina/connect":
f.oficinaConnect(w, r)
case r.Method == http.MethodPost && p == "/oficina/connect/finish":
@@ -400,7 +424,7 @@ func (f *Fake) snapshot(w http.ResponseWriter, r *http.Request) {
}
cards := []card{}
for _, c := range f.cards {
- cards = append(cards, *c)
+ cards = append(cards, asSeen(*c, pausedOK(r)))
}
writeJSON(w, 200, map[string]any{
"me": map[string]any{"id": f.address, "address": f.address, "role": "owner",
@@ -658,6 +682,107 @@ func (f *Fake) answer(w http.ResponseWriter, r *http.Request, id string) {
go f.answerTurn(t.ID, in.Choice)
}
+// carryOn is POST cards/{id}/carry_on {revision, idempotency_key}, as
+// Equipo's docs/api/equipo-v1.md says: a paused job that offers it
+// (carry_on) starts again now, working, and the answer is 200 {"card"}.
+// A key seen before gets the answer it got then. 409 card_stale at another
+// revision, not_paused when it is not paused, carry_on_unavailable when it
+// does not offer it, each {code, copy_key, request_id, card}; 404 for
+// anything but a job card.
+func (f *Fake) carryOn(w http.ResponseWriter, r *http.Request, id string) {
+ var in struct {
+ Revision int64 `json:"revision"`
+ IdempotencyKey string `json:"idempotency_key"`
+ }
+ if strict(r, &in) != nil || len(in.IdempotencyKey) < 1 || len(in.IdempotencyKey) > 128 {
+ writeError(w, r, 422, "invalid_input")
+ return
+ }
+ f.cmu.Lock()
+ defer f.cmu.Unlock()
+ if done, ok := f.carried[in.IdempotencyKey]; ok {
+ writeJSON(w, 200, map[string]any{"card": done})
+ return
+ }
+ var c *card
+ for _, x := range f.cards {
+ if x.ID == id && x.Kind == equipo.CardJob {
+ c = x
+ }
+ }
+ conflict := func(code string) {
+ request := r.Header.Get("Idempotency-Key")
+ if request == "" || len(request) > 256 {
+ request = rand.Text()
+ }
+ writeJSON(w, 409, map[string]any{"code": code, "copy_key": "api." + code, "request_id": request, "card": *c})
+ }
+ switch {
+ case c == nil:
+ writeError(w, r, 404, "not_found")
+ case c.Revision != in.Revision:
+ conflict("card_stale")
+ case c.State != equipo.JobPaused:
+ conflict("not_paused")
+ case !c.CarryOn:
+ conflict("carry_on_unavailable")
+ default:
+ c.State, c.Result, c.Detail, c.CarryOn, c.Revision = equipo.JobWorking, "Carrying on", "Picking up where it left off.", false, c.Revision+1
+ f.emit("card", "card", c.ID, c.Revision, "", *c)
+ f.carried[in.IdempotencyKey] = *c
+ writeJSON(w, 200, map[string]any{"card": *c})
+ }
+}
+
+// pausedOK reports whether r opted in to the paused job state
+// (job_states=paused, a comma-separated list).
+func pausedOK(r *http.Request) bool {
+ for _, v := range r.URL.Query()["job_states"] {
+ for _, s := range strings.Split(v, ",") {
+ if s == equipo.JobPaused {
+ return true
+ }
+ }
+ }
+ return false
+}
+
+// asSeen is c as a client sees it: without the paused opt-in, a paused
+// job comes as working with the same result and detail and no carry_on.
+func asSeen(c card, paused bool) card {
+ if !paused && c.Kind == equipo.CardJob && c.State == equipo.JobPaused {
+ c.State, c.CarryOn = equipo.JobWorking, false
+ }
+ return c
+}
+
+// timeZone is PUT time-zone {time_zone}: 200 {time_zone} for a zone Go
+// knows (an IANA name), else 422 invalid_input.
+func (f *Fake) timeZone(w http.ResponseWriter, r *http.Request) {
+ var in struct {
+ TimeZone string `json:"time_zone"`
+ }
+ if strict(r, &in) != nil || in.TimeZone == "" || in.TimeZone == "Local" {
+ writeError(w, r, 422, "invalid_input")
+ return
+ }
+ if _, err := time.LoadLocation(in.TimeZone); err != nil {
+ writeError(w, r, 422, "invalid_input")
+ return
+ }
+ f.cmu.Lock()
+ f.zone = in.TimeZone
+ f.cmu.Unlock()
+ writeJSON(w, 200, map[string]string{"time_zone": in.TimeZone})
+}
+
+// TimeZone is the zone the person set (PUT time-zone), "" before any.
+func (f *Fake) TimeZone() string {
+ f.cmu.Lock()
+ defer f.cmu.Unlock()
+ return f.zone
+}
+
// stream is GET events: Server-Sent Events after ?after= (or
// Last-Event-ID), as Equipo writes them: then, live events (cursor 0, no
// id line) that come while the stream is open.
@@ -678,6 +803,7 @@ func (f *Fake) stream(w http.ResponseWriter, r *http.Request) {
}
after = n
}
+ paused := pausedOK(r)
rc := http.NewResponseController(w)
w.Header().Set("Content-Type", "text/event-stream")
w.WriteHeader(200)
@@ -696,6 +822,9 @@ func (f *Fake) stream(w http.ResponseWriter, r *http.Request) {
wake := f.wake
f.cmu.Unlock()
for _, e := range batch {
+ if c, ok := e.Data.(card); ok {
+ e.Data = asSeen(c, paused)
+ }
raw, _ := json.Marshal(e)
id := ""
if e.Cursor != 0 {
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index d2bdb3e..a5c9579 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -113,7 +113,8 @@
--card: rgba(139,92,246,.16);
--card-edge: rgba(139,92,246,.45);
/* A job's pill, and the colours of its states: working, ready and done
- are the accent; asking is warm; stopped is rose. --st-wash is how much
+ are the accent; asking is warm; paused is a calm indigo (white or
+ the dark ink on it is over 6:1); stopped is rose. --st-wash is how much
of the state's colour is washed in behind the pill. */
--pill: rgba(238,242,248,.11);
--pill-edge: rgba(238,242,248,.26);
@@ -121,6 +122,7 @@
--pill-lift: rgba(6,8,22,.55);
--st-ask: #FFB066;
--st-stop: #F9A8D4;
+ --st-pause: #AEB8FF;
--st-wash: .2;
/* The composer's focus edge, teal into violet (each 3:1 on the panel,
in both themes), the glow under it, and the thinking bubble's spark,
@@ -171,7 +173,7 @@
--theirs: rgba(255,255,255,.88); --theirs-edge: rgba(30,36,64,.1); --card: rgba(139,92,246,.1);
--card-edge: rgba(124,77,232,.35); --pill: rgba(255,255,255,.94); --pill-edge: rgba(30,36,64,.16);
--pill-shine: rgba(255,255,255,1); --pill-lift: rgba(40,46,90,.28); --st-ask: #C0651A;
- --st-stop: #C2366F; --st-wash: .13; --edge-a: #0B7A72; --edge-b: #6A3CD6; --edge-hi: #2B58C8;
+ --st-stop: #C2366F; --st-pause: #4B55C9; --st-wash: .13; --edge-a: #0B7A72; --edge-b: #6A3CD6; --edge-hi: #2B58C8;
--edge-glow-a: rgba(15,168,156,.36); --edge-glow-b: rgba(124,77,232,.32); --spk-rose: #C2366F; --spk-amber: #B8641C;
}
:root[data-theme="dark"] { color-scheme: dark; }
@@ -257,6 +259,7 @@
--pill-lift: light-dark(rgba(40,46,90,.28), rgba(6,8,22,.55));
--st-ask: light-dark(#C0651A, #FFB066);
--st-stop: light-dark(#C2366F, #F9A8D4);
+ --st-pause: light-dark(#4B55C9, #AEB8FF);
--edge-a: light-dark(#0B7A72, #6EE7DC);
--edge-b: light-dark(#6A3CD6, #B49CFC);
--edge-hi: light-dark(#2B58C8, #E6FFFB);
@@ -577,6 +580,7 @@ aside.ask-panel { position: absolute; top: 16px; right: 16px; bottom: 16px; widt
.job { align-self: flex-start; max-width: 100%; display: flex; flex-direction: column; gap: 6px; }
.job[data-state="working"], .job[data-state="ready"], .job[data-state="done"] { --st: var(--signal); }
.job[data-state="asking"] { --st: var(--st-ask); }
+.job[data-state="paused"] { --st: var(--st-pause); }
.job[data-state="stopped"] { --st: var(--st-stop); }
.pill { position: relative; display: flex; align-items: center; max-width: 100%; min-height: 44px; border-radius: 999px;
background: linear-gradient(90deg, color-mix(in srgb, var(--st) calc(var(--st-wash) * 100%), transparent), transparent 70%), var(--pill);
@@ -652,6 +656,10 @@ aside.ask-panel { position: absolute; top: 16px; right: 16px; bottom: 16px; widt
.jv-stage { font-weight: 500; }
.jobview > .jv-detail { margin-top: 2px; color: var(--haze); }
.jobview > .jv-started { margin-top: 8px; color: var(--haze); font-size: 13px; }
+/* A paused job's one action, "Carry on now", and the quiet line under it
+ saying what it uses. */
+.jv-act { margin: 12px 10px 0 36px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
+.jv-act small { color: var(--haze); font-size: 13px; }
/* Under the detail, the job's cards that have ended (Paul, 2026-11-16):
each its question, then how it ended, in the status's quieter ink; a
rule above the list keeps them apart from the status. */
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index 8a06515..0401c87 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -586,12 +586,13 @@ function start(root) {
// and so do loose cards of the job, drawn before it was (those that have
// ended to its view), and the ended cards in its view; an open job view
// stays open, and focus stays where it was.
- const jobStates = ["working", "asking", "ready", "done", "stopped"];
+ const jobStates = ["working", "asking", "ready", "done", "paused", "stopped"];
const marks = {
asking: "M9.2 9.2a2.9 2.9 0 0 1 5.6 1c0 2-2.8 2.4-2.8 4.3M12 18.2h.01",
ready: "M8 16L16 8M9.5 8H16v6.5",
done: "M6 12.5l4 4 8-9",
- stopped: "M9.5 7.5v9M14.5 7.5v9",
+ paused: "M19.2 12a7.2 7.2 0 1 1-14.4 0a7.2 7.2 0 1 1 14.4 0zM12 8.6V12l2.4 1.6",
+ stopped: "M9 7.5h6a1.5 1.5 0 0 1 1.5 1.5v6a1.5 1.5 0 0 1-1.5 1.5H9a1.5 1.5 0 0 1-1.5-1.5V9A1.5 1.5 0 0 1 9 7.5z",
};
const svgNS = "http://www.w3.org/2000/svg";
function span(cls, text) {
@@ -702,8 +703,9 @@ function start(root) {
// The job view, opened from the pill, drawn as the server draws it (the
// ask-jobview template): the title, linked to the job's own page (its
// link with rel equipo, the link's label as its tooltip): the only place
- // that link is drawn. Then the status, one sentence more, when it
- // started, and the link to the work once there is something to see.
+ // that link is drawn. Then the status, one sentence more, for a paused
+ // job that offers it "Carry on now" (carryOn), when it started, and the
+ // link to the work once there is something to see.
function jobView(c) {
const view = document.createElement("section");
view.className = "jobview";
@@ -734,6 +736,7 @@ function start(root) {
header.append(stateMark(c.state), h3, close);
view.append(header, para("jv-stage", c.result || ""));
if (c.detail) view.append(para("jv-detail", c.detail));
+ if (c.state === "paused" && c.carry_on === true) view.append(carryOn(c));
const ended = document.createElement("ol");
ended.className = "jv-cards";
view.append(ended);
@@ -752,6 +755,28 @@ function start(root) {
return view;
}
+ // "Carry on now", as the server draws it (the ask-jobview template): a
+ // form posting the card's revision, and the line under it saying what
+ // it uses. Its key is post's, kept until the outcome is known.
+ function carryOn(c) {
+ const form = document.createElement("form");
+ form.className = "jv-act";
+ form.method = "post";
+ form.action = `/ask/cards/${encodeURIComponent(c.id)}/carry_on`;
+ const rev = document.createElement("input");
+ rev.type = "hidden";
+ rev.name = "revision";
+ rev.value = String(c.revision);
+ const b = document.createElement("button");
+ b.className = "btn ghost";
+ b.type = "submit";
+ b.textContent = "Carry on now";
+ const note = document.createElement("small");
+ note.textContent = "Uses your other plan, at no extra cost.";
+ form.append(rev, b, note);
+ return form;
+ }
+
// When a job started (plan decision D19), as the server says it
// (startedText in ask.go): how long ago in minutes or hours, then from a
// day on, the day in Base's time zone (the thread's data-zone; this
@@ -1612,6 +1637,10 @@ function start(root) {
thread.addEventListener("submit", async (e) => {
e.preventDefault();
const form = e.target;
+ if (form.matches("form.jv-act")) {
+ carryOnNow(form);
+ return;
+ }
const choice = e.submitter && e.submitter.value;
if (!choice) return;
for (const b of form.querySelectorAll("button")) b.disabled = true;
@@ -1638,6 +1667,23 @@ function start(root) {
if (out.turn) setTurn(out.turn);
});
+ // Carry on now: once, with post's kept key (a retry after a lost answer
+ // is the same request). The answer is the job card, redrawn in place;
+ // a 409 (the card moved on, or no longer offers it) reads the
+ // conversation afresh. Never resent by itself.
+ async function carryOnNow(form) {
+ const b = form.querySelector("button");
+ if (b.disabled) return;
+ b.disabled = true;
+ const out = await post(form);
+ if (!out && lastStatus === 409 && lastState === "ready") {
+ await load();
+ return;
+ }
+ if (out && out.card) addJob(out.card);
+ else b.disabled = false;
+ }
+
// On a wide screen the field is ready when the page opens: only with the
// chat open and ready, never on a phone (it would raise the keyboard), and
// never over focus the person already has or a link's target (#...).
diff --git a/internal/web/app.go b/internal/web/app.go
index 6f1c435..6df5782 100644
--- a/internal/web/app.go
+++ b/internal/web/app.go
@@ -92,7 +92,7 @@ func App(d *db.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger
}
a := &app{db: d.Writer(), cfg: cfg, inst: inst, logger: logger, pages: pages, mailer: mailer}
if cfg.EquipoOrigin != "" {
- a.ask = newAsker(cfg.EquipoOrigin, cfg.InstanceKey, cfg.Name)
+ a.ask = newAsker(cfg.EquipoOrigin, cfg.InstanceKey, cfg.Name, cfg.Timezone)
}
guard, err := pow.New(pow.Config{InstanceKey: cfg.InstanceKey, Nonces: pow.SQLNonces(d.Writer()), Difficulty: pow.NoProof, MinAge: pow.DefaultMinAge})
if err != nil {
diff --git a/internal/web/ask.go b/internal/web/ask.go
index 5d2c6c2..f80ba8e 100644
--- a/internal/web/ask.go
+++ b/internal/web/ask.go
@@ -31,6 +31,11 @@ type asker struct {
// oficina holds a *sync.Mutex per member id, held while Ask is set up
// with Oficina ID for them (askOficinaLock).
oficina sync.Map
+ // zone is the team's IANA time zone (BASE_TIMEZONE), which Equipo
+ // writes the Assistant's times in; zoned holds the zone told to Equipo
+ // for each member id since Base started (zoneFor).
+ zone string
+ zoned sync.Map
}
// askRoutes mounts the chat, behind the member gate and Base's CSRF check.
@@ -41,6 +46,7 @@ func (a *app) askRoutes(r chi.Router) {
r.Post("/ask/messages", a.askSend)
r.Post("/ask/turns/{id}/cancel", a.askCancel)
r.Post("/ask/cards/{id}/answer", a.askAnswer)
+ r.Post("/ask/cards/{id}/carry_on", a.askCarryOn)
r.Post("/ask/connect", a.askConnectStart)
r.Get("/ask/connect", a.askConnectPage)
r.Post("/ask/connect/check", a.askConnectCheck)
@@ -78,8 +84,14 @@ func (a *app) askDock(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther)
}
-func newAsker(origin, instanceKey, name string) *asker {
- return &asker{client: equipo.New(origin), seal: equipo.NewSealer(instanceKey), label: "Base (" + name + ")"}
+// newAsker is the chat with the Equipo at origin, for the team at zone
+// (BASE_TIMEZONE), which Base tells Equipo for each member (zoneFor).
+func newAsker(origin, instanceKey, name string, zone *time.Location) *asker {
+ a := &asker{client: equipo.New(origin), seal: equipo.NewSealer(instanceKey), label: "Base (" + name + ")"}
+ if zone != nil {
+ a.zone = zone.String()
+ }
+ return a
}
// The states of a member's chat. Connect: nothing connected; pending: a
diff --git a/internal/web/ask_connect.go b/internal/web/ask_connect.go
index 2ed8942..3da30f7 100644
--- a/internal/web/ask_connect.go
+++ b/internal/web/ask_connect.go
@@ -334,6 +334,7 @@ func (a *app) hostFor(ctx context.Context, me store.Member, dev, token string, f
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), storeTimeout)
defer cancel()
defer a.lockMember(me.ID)()
+ a.zoneFor(ctx, me, token, fresh)
if !fresh {
done, err := store.HostRegistered(ctx, a.db, me.ID)
if err != nil {
@@ -349,6 +350,29 @@ func (a *app) hostFor(ctx context.Context, me store.Member, dev, token string, f
}
}
+// zoneFor tells Equipo the member's time zone, the team's (BASE_TIMEZONE),
+// so the times the Assistant writes for them ("Paused until 21:00") are in
+// it: on each new connection (fresh), and otherwise once for each member
+// since Base started, which is when BASE_TIMEZONE can change. A failure is
+// logged and tried again on the next read; an Equipo that has no such
+// route (404) is not asked again until Base restarts. The caller holds the
+// member's lock.
+func (a *app) zoneFor(ctx context.Context, me store.Member, token string, fresh bool) {
+ if a.ask.zone == "" {
+ return
+ }
+ if told, ok := a.ask.zoned.Load(me.ID); ok && told == a.ask.zone && !fresh {
+ return
+ }
+ err := a.ask.client.SetTimeZone(ctx, token, a.ask.zone)
+ var e *equipo.Error
+ if err != nil && !(errors.As(err, &e) && e.Status == http.StatusNotFound) {
+ a.logger.Warn("ask: time zone", "err", err)
+ return
+ }
+ a.ask.zoned.Store(me.ID, a.ask.zone)
+}
+
// memberConn is a member's lock, held while their connection changes or
// their host is registered, and their connection's generation, which every
// change to their link moves on (changeLink). The lock is not reentrant:
diff --git a/internal/web/ask_relay.go b/internal/web/ask_relay.go
index 9d520b9..9499880 100644
--- a/internal/web/ask_relay.go
+++ b/internal/web/ask_relay.go
@@ -170,6 +170,27 @@ func (a *app) askAnswer(w http.ResponseWriter, r *http.Request) {
a.askDone(w, r, c, err, out)
}
+// askCarryOn is POST /ask/cards/{id}/carry_on: a paused job's "Carry on
+// now", at the revision the person saw, relayed as card answers are. The
+// answer is {"card": the job card as it is now}. A 409 (card_stale,
+// not_paused, carry_on_unavailable) is stale: the conversation is read
+// afresh, and nothing is resent.
+func (a *app) askCarryOn(w http.ResponseWriter, r *http.Request) {
+ c, ok := a.askBearer(w, r)
+ if !ok {
+ return
+ }
+ rev, _ := strconv.ParseInt(r.PostFormValue("revision"), 10, 64)
+ in, err := a.ask.client.CarryOnNow(r.Context(), c.token, chi.URLParam(r, "id"), rev, askKey(r.PostFormValue("key")))
+ var out struct {
+ Card *equipo.Card `json:"card"`
+ }
+ if card, ok := in.CleanAt(a.cfg.Origin); ok {
+ out.Card = &card
+ }
+ a.askDone(w, r, c, err, out)
+}
+
// Stream bounds. Equipo pings every 20 seconds, so a minute of silence
// means it is gone; a stream lives at most streamLife, after which the
// browser reconnects with its cursor; one event is at most maxEventBytes
diff --git a/internal/web/templates/partials/chat.html b/internal/web/templates/partials/chat.html
index 56be999..4c388e7 100644
--- a/internal/web/templates/partials/chat.html
+++ b/internal/web/templates/partials/chat.html
@@ -15,13 +15,14 @@
<div class="pill"><details class="job-toggle"><summary class="pill-main" aria-label="{{.Question}}, {{.Result}}"><span class="state-mark" aria-hidden="true">{{template "ask-mark" .State}}</span><span class="pill-title">{{.Question}}</span><span class="pill-stage">{{.Result}}</span></summary>{{template "ask-jobview" .}}</details>
{{- if or (eq .State "ready") (eq .State "done")}}{{with .Go}}<a class="pill-link" href="{{.URL}}" target="_blank" rel="noopener">{{.Label}}</a>{{end}}{{end}}</div>
<ol class="job-cards">{{range .OpenCards}}{{template "ask-card" .}}{{end}}</ol></li>{{end}}
-{{/* A job state's mark: working has none (the mark turns, in CSS); the rest are still icons. ask.js has the same paths (marks). */}}
-{{define "ask-mark"}}{{if eq . "asking"}}<svg viewBox="0 0 24 24"><path d="M9.2 9.2a2.9 2.9 0 0 1 5.6 1c0 2-2.8 2.4-2.8 4.3M12 18.2h.01"/></svg>{{else if eq . "ready"}}<svg viewBox="0 0 24 24"><path d="M8 16L16 8M9.5 8H16v6.5"/></svg>{{else if eq . "done"}}<svg viewBox="0 0 24 24"><path d="M6 12.5l4 4 8-9"/></svg>{{else if eq . "stopped"}}<svg viewBox="0 0 24 24"><path d="M9.5 7.5v9M14.5 7.5v9"/></svg>{{end}}{{end}}
-{{/* The job view, opened from the pill: its title, the status, one sentence more, the job's cards that have ended (each its question and how it ended: ask-jobcard), when it started, and once there is something to see the link to it. The title links to the job's own page in Equipo (Card.Equipo, "Open in Equipo" as its tooltip, an arrow on hover and focus): the only place the chat links there, never a step the person must take. Without scripts it opens in place under the pill; the panel's script makes it a popover beside the pill, or a sheet on a phone, and shows Close (ask.js, jobView). */}}
+{{/* A job state's mark: working has none (the mark turns, in CSS); the rest are still icons: paused a clock (it carries on by itself), stopped a square (it waits for the person). ask.js has the same paths (marks), and so does the native app (BaseIcon). */}}
+{{define "ask-mark"}}{{if eq . "asking"}}<svg viewBox="0 0 24 24"><path d="M9.2 9.2a2.9 2.9 0 0 1 5.6 1c0 2-2.8 2.4-2.8 4.3M12 18.2h.01"/></svg>{{else if eq . "ready"}}<svg viewBox="0 0 24 24"><path d="M8 16L16 8M9.5 8H16v6.5"/></svg>{{else if eq . "done"}}<svg viewBox="0 0 24 24"><path d="M6 12.5l4 4 8-9"/></svg>{{else if eq . "paused"}}<svg viewBox="0 0 24 24"><path d="M19.2 12a7.2 7.2 0 1 1-14.4 0a7.2 7.2 0 1 1 14.4 0zM12 8.6V12l2.4 1.6"/></svg>{{else if eq . "stopped"}}<svg viewBox="0 0 24 24"><path d="M9 7.5h6a1.5 1.5 0 0 1 1.5 1.5v6a1.5 1.5 0 0 1-1.5 1.5H9a1.5 1.5 0 0 1-1.5-1.5V9A1.5 1.5 0 0 1 9 7.5z"/></svg>{{end}}{{end}}
+{{/* The job view, opened from the pill: its title, the status, one sentence more, for a paused job that offers it "Carry on now" (assistant.job.carry_on, with assistant.job.carry_on_note under it: copy review 2026-11-24) posting the card's revision, the job's cards that have ended (each its question and how it ended: ask-jobcard), when it started, and once there is something to see the link to it. The title links to the job's own page in Equipo (Card.Equipo, "Open in Equipo" as its tooltip, an arrow on hover and focus): the only place the chat links there, never a step the person must take. Without scripts it opens in place under the pill; the panel's script makes it a popover beside the pill, or a sheet on a phone, and shows Close (ask.js, jobView). */}}
{{define "ask-jobview"}}<section class="jobview" aria-label="{{.Question}}"><header><span class="state-mark" aria-hidden="true">{{template "ask-mark" .State}}</span>
<h3>{{with .Equipo}}<a class="jv-title" href="{{.URL}}" title="{{.Label}}" target="_blank" rel="noopener">{{$.Question}}<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6h9v9M18 6L7 17"/></svg></a>{{else}}{{.Question}}{{end}}</h3>
<button class="round" type="button" data-job-close aria-label="Close" hidden><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button></header>
-<p class="jv-stage">{{.Result}}</p>{{with .Detail}}<p class="jv-detail">{{.}}</p>{{end}}<ol class="jv-cards">{{range .EndedCards}}{{template "ask-jobcard" .}}{{end}}</ol>{{with .StartedAt}}<p class="jv-started">{{startedText .}}</p>{{end}}
+<p class="jv-stage">{{.Result}}</p>{{with .Detail}}<p class="jv-detail">{{.}}</p>{{end}}
+{{- if and (eq .State "paused") .CarryOn}}<form class="jv-act" method="post" action="/ask/cards/{{.ID}}/carry_on"><input type="hidden" name="revision" value="{{.Revision}}"><input type="hidden" name="key" value="{{newKey}}"><button class="btn ghost" type="submit">Carry on now</button><small>Uses your other plan, at no extra cost.</small></form>{{end}}<ol class="jv-cards">{{range .EndedCards}}{{template "ask-jobcard" .}}{{end}}</ol>{{with .StartedAt}}<p class="jv-started">{{startedText .}}</p>{{end}}
{{- if or (eq .State "ready") (eq .State "done")}}{{with .Go}}<a class="jv-go" href="{{.URL}}" target="_blank" rel="noopener">{{.Label}}</a>{{end}}{{end}}</section>{{end}}
{{/* A job's card that has ended, in its view: the question and how it ended, nothing to press. The panel's script draws the same (ask.js, addCard). */}}
{{define "ask-jobcard"}}<li class="jv-card" data-card="{{.ID}}" data-revision="{{.Revision}}" data-for="{{.Job}}"><p class="jv-q">{{.Question}}</p><p class="jv-result">{{.Result}}</p></li>{{end}}
diff --git a/internal/webtest/ask_native_contract_test.go b/internal/webtest/ask_native_contract_test.go
index 5c07fba..19a3fc3 100644
--- a/internal/webtest/ask_native_contract_test.go
+++ b/internal/webtest/ask_native_contract_test.go
@@ -496,3 +496,44 @@ func (p *pipeWriter) Write(b []byte) (int, error) {
}
func (p *pipeWriter) Flush() {}
+
+// Carry on now (docs/api/base-native-v1.md): a paused job's card says
+// carry_on; the route answers {"card": the job as it is now}; a 409 from
+// Equipo (card_stale, not_paused, carry_on_unavailable) is Ask's stale
+// 409 {"state":"ready"}; before connecting it is the state's 409.
+func TestAskContractCarryOn(t *testing.T) {
+ web, app, f := newNativeAskApp(t)
+ wantBody(t, "not connected", app.nativeForm("/ask/cards/c_1/carry_on", url.Values{"revision": {"1"}, "key": {"k1"}}), 409, `{"state":"connect"}`)
+ web.approveEquipo(f)
+ job := f.AskJob("Bakery website")
+ f.PauseJob(job, "Paused until 21:00", "It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).", true)
+ s, r := app.askState()
+ if len(s.Jobs) != 1 {
+ t.Fatalf("jobs: %s", r.Body)
+ }
+ wantKeys(t, "paused job", string(s.Jobs[0]), "id", "revision", "kind", "state", "question", "options", "links", "result", "detail", "started_at", "carry_on", "cards")
+ var j struct {
+ State, Result string
+ Revision int64
+ CarryOn bool `json:"carry_on"`
+ }
+ if json.Unmarshal(s.Jobs[0], &j) != nil || j.State != "paused" || j.Result != "Paused until 21:00" || !j.CarryOn {
+ t.Fatalf("paused job: %s", s.Jobs[0])
+ }
+ rev := strconv.FormatInt(j.Revision, 10)
+ wantBody(t, "stale", app.nativeForm("/ask/cards/"+job+"/carry_on", url.Values{"revision": {"1"}, "key": {"s-1"}}), 409, `{"state":"ready"}`)
+ ok := app.nativeForm("/ask/cards/"+job+"/carry_on", url.Values{"revision": {rev}, "key": {"s-2"}})
+ wantKeys(t, "carry on", ok.Body, "card")
+ var out struct{ Card struct{ ID, State string } }
+ if ok.Code != 200 || json.Unmarshal([]byte(ok.Body), &out) != nil || out.Card.ID != job || out.Card.State != "working" {
+ t.Errorf("carry on: %d %s", ok.Code, ok.Body)
+ }
+ // Sent again with its key (its answer was lost): the same answer.
+ if again := app.nativeForm("/ask/cards/"+job+"/carry_on", url.Values{"revision": {rev}, "key": {"s-2"}}); again.Code != 200 || again.Body != ok.Body {
+ t.Errorf("resent: %d %s, want %s", again.Code, again.Body, ok.Body)
+ }
+ // No longer paused.
+ s, _ = app.askState()
+ _ = json.Unmarshal(s.Jobs[0], &j)
+ wantBody(t, "not paused", app.nativeForm("/ask/cards/"+job+"/carry_on", url.Values{"revision": {strconv.FormatInt(j.Revision, 10)}, "key": {"s-3"}}), 409, `{"state":"ready"}`)
+}
diff --git a/internal/webtest/ask_test.go b/internal/webtest/ask_test.go
index 2a1bd15..40e3994 100644
--- a/internal/webtest/ask_test.go
+++ b/internal/webtest/ask_test.go
@@ -603,7 +603,7 @@ func TestAskEventsRelay(t *testing.T) {
t.Fatal("the stream carried the bearer")
}
up := f.Calls("/api/v1/assistant/events")
- if len(up) == 0 || up[0].Header.Get("Authorization") != "Bearer "+token || up[0].Query != "after="+strconv64(st.Cursor) {
+ if len(up) == 0 || up[0].Header.Get("Authorization") != "Bearer "+token || up[0].Query != "job_states=paused&after="+strconv64(st.Cursor) {
t.Fatalf("upstream: %+v", up)
}
}
@@ -1592,6 +1592,195 @@ func TestAskJobStates(t *testing.T) {
}
}
+// A paused job (Equipo's "paused", its status and sentence in the person's
+// time zone, as given): the pill's clock mark on the calm indigo, its
+// status, and in the view the sentence and, when the card offers it,
+// "Carry on now" with the line under it, posting the card's revision and
+// a key. Not offered, the view has no form. Stopped has a mark of its own
+// (a square), never paused's or the old pause bars.
+func TestAskJobPaused(t *testing.T) {
+ const clock = `<path d="M19.2 12a7.2 7.2 0 1 1-14.4 0a7.2 7.2 0 1 1 14.4 0zM12 8.6V12l2.4 1.6"/>`
+ const square = `<path d="M9 7.5h6a1.5 1.5 0 0 1 1.5 1.5v6a1.5 1.5 0 0 1-1.5 1.5H9a1.5 1.5 0 0 1-1.5-1.5V9A1.5 1.5 0 0 1 9 7.5z"/>`
+ a, f := newAskApp(t)
+ a.connectEquipo(f)
+ id := f.AskJob("Bakery website")
+ f.PauseJob(id, "Paused until 21:00", "It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).", true)
+ page := a.get("/ask").Body
+ job := jobItem(t, page, id)
+ if !strings.Contains(job, `data-state="paused"`) {
+ t.Errorf("paused job's state:\n%s", job)
+ }
+ expect(t, "stage", job, `<span class="pill-stage">(.*?)</span>`, "Paused until 21:00")
+ if !strings.Contains(job, `<summary class="pill-main" aria-label="Bakery website, Paused until 21:00">`) {
+ t.Errorf("summary's name:\n%s", job)
+ }
+ if n := strings.Count(job, clock); n != 2 {
+ t.Errorf("the clock mark is drawn %d times (pill and view):\n%s", n, job)
+ }
+ view := jobViewOf(t, job)
+ expect(t, "status", view, `<p class="jv-stage">(.*?)</p>`, "Paused until 21:00")
+ expect(t, "detail", view, `<p class="jv-detail">(.*?)</p>`, "It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).")
+ form := regexp.MustCompile(`(?s)<form class="jv-act" method="post" action="/ask/cards/` + id + `/carry_on">(.*?)</form>`).FindStringSubmatch(view)
+ if form == nil || !strings.Contains(form[1], `<button class="btn ghost" type="submit">Carry on now</button><small>Uses your other plan, at no extra cost.</small>`) {
+ t.Fatalf("no Carry on now in the view:\n%s", view)
+ }
+ fields := formFields(t, page, "/ask/cards/"+id+"/carry_on")
+ if fields.Get("revision") != "3" || fields.Get("key") == "" {
+ t.Errorf("Carry on now posts %v", fields)
+ }
+ css, _ := os.ReadFile("../look/static/app.css")
+ for _, rule := range []string{`.job[data-state="paused"] { --st: var(--st-pause); }`, `--st-pause: #AEB8FF;`, `--st-pause: #4B55C9;`, `--st-pause: light-dark(#4B55C9, #AEB8FF);`} {
+ if !strings.Contains(string(css), rule) {
+ t.Errorf("app.css has no %s", rule)
+ }
+ }
+
+ // Not offered: no form, the rest as before.
+ other := f.AskJob("Invoice reminders")
+ f.PauseJob(other, "Paused until midnight", "It has reached today's spending limit. It will carry on by itself at midnight (in 3 hours).", false)
+ view = jobViewOf(t, jobItem(t, a.get("/ask").Body, other))
+ if strings.Contains(view, "<form") || strings.Contains(view, "Carry on now") {
+ t.Errorf("Carry on now without carry_on:\n%s", view)
+ }
+
+ // Stopped: a square, distinct from paused's clock.
+ f.SetJob(other, "stopped", "Stopped", "It needs you.")
+ job = jobItem(t, a.get("/ask").Body, other)
+ if !strings.Contains(job, square) || strings.Contains(job, clock) || strings.Contains(job, "M9.5 7.5v9M14.5 7.5v9") {
+ t.Errorf("stopped's mark:\n%s", job)
+ }
+ // ask.js and the native app draw the same marks.
+ for _, file := range []string{"../look/static/ask.js", "../../native/apple/Sources/BaseKit/Look/Marks.swift"} {
+ raw, _ := os.ReadFile(file)
+ for _, d := range []string{clock, square} {
+ if d = regexp.MustCompile(`d="([^"]*)"`).FindStringSubmatch(d)[1]; !strings.Contains(string(raw), `"`+d+`"`) {
+ t.Errorf("%s has no %s", file, d)
+ }
+ }
+ }
+}
+
+// Carry on now, without scripts: the form posts once to Equipo with its
+// key (the body's idempotency_key and the Idempotency-Key header) and the
+// revision shown, and /ask shows the job carrying on. The same form sent
+// again is the same request. At a stale revision Equipo's 409 is not
+// resent: /ask draws the card as it is now. A job that is no longer paused,
+// or no longer offers it, is a 409 too. Scripts on, the answer is the card.
+func TestAskCarryOnNow(t *testing.T) {
+ a, f := newAskApp(t)
+ a.connectEquipo(f)
+ id := f.AskJob("Bakery website")
+ f.PauseJob(id, "Paused until 21:00", "It will carry on by itself at 21:00 (in 9 hours).", true)
+ path := "/ask/cards/" + id + "/carry_on"
+ form := formFields(t, a.get("/ask").Body, path)
+ for i := range 2 {
+ if r := a.post(path, form); r.Code != 303 || r.Location() != "/ask" {
+ t.Fatalf("carry on %d: %d %q", i, r.Code, r.Location())
+ }
+ }
+ calls := f.Calls("/api/v1/assistant" + path[len("/ask"):])
+ want := `{"idempotency_key":"` + form.Get("key") + `","revision":3}`
+ if len(calls) != 2 || strings.TrimSpace(calls[0].Body) != want || calls[1].Body != calls[0].Body ||
+ calls[0].Header.Get("Idempotency-Key") != form.Get("key") {
+ t.Fatalf("relayed: %+v, want twice %s", calls, want)
+ }
+ job := jobItem(t, a.get("/ask").Body, id)
+ if !strings.Contains(job, `data-state="working"`) || strings.Contains(job, "Carry on now") {
+ t.Errorf("after Carry on now:\n%s", job)
+ }
+
+ // Stale: the job moved on unseen. One call, a 409, and /ask draws it anew.
+ other := f.AskJob("Invoice reminders")
+ f.PauseJob(other, "Paused until 21:00", "It will carry on by itself at 21:00 (in 9 hours).", true)
+ path = "/ask/cards/" + other + "/carry_on"
+ stale := formFields(t, a.get("/ask").Body, path)
+ f.PauseJob(other, "Paused until 22:00", "It will carry on by itself at 22:00 (in 10 hours).", true)
+ if r := a.post(path, stale); r.Code != 303 || r.Location() != "/ask" {
+ t.Fatalf("stale: %d %q", r.Code, r.Location())
+ }
+ if n := len(f.Calls("/api/v1/assistant/cards/" + other + "/carry_on")); n != 1 {
+ t.Errorf("a stale Carry on now went %d times", n)
+ }
+ fresh := formFields(t, a.get("/ask").Body, path)
+ if fresh.Get("revision") != "4" {
+ t.Errorf("after the 409 the job is at revision %q, want 4", fresh.Get("revision"))
+ }
+
+ // Scripts on: the card, at its new revision.
+ json409 := func(form url.Values) Resp {
+ req, _ := http.NewRequest(http.MethodPost, a.base+path, strings.NewReader(form.Encode()))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("Origin", a.origin)
+ req.Header.Set("Accept", "application/json")
+ return a.do(req)
+ }
+ res := json409(fresh)
+ var out struct{ Card struct{ ID, State string } }
+ if res.Code != 200 || json.Unmarshal([]byte(res.Body), &out) != nil || out.Card.ID != other || out.Card.State != "working" {
+ t.Fatalf("JSON carry on: %d %s", res.Code, res.Body)
+ }
+ // No longer paused, then paused without the offer: 409s, the panel reads afresh.
+ fresh.Set("key", "k-again")
+ fresh.Set("revision", "5")
+ if r := json409(fresh); r.Code != 409 || strings.TrimSpace(r.Body) != `{"state":"ready"}` {
+ t.Errorf("not paused: %d %s", r.Code, r.Body)
+ }
+ f.PauseJob(other, "Paused until 23:00", "It will carry on by itself at 23:00.", false)
+ fresh.Set("key", "k-third")
+ fresh.Set("revision", "6")
+ if r := json409(fresh); r.Code != 409 || strings.TrimSpace(r.Body) != `{"state":"ready"}` {
+ t.Errorf("carry on unavailable: %d %s", r.Code, r.Body)
+ }
+}
+
+// Base tells Equipo the team's time zone (BASE_TIMEZONE), so the
+// Assistant's times are in it: once a connection is made, not again on
+// every read. Base opts in to the paused job state on the snapshot and the
+// event stream (job_states=paused).
+func TestAskSendsTheTeamZoneAndOptsInToPaused(t *testing.T) {
+ madrid, err := time.LoadLocation("Europe/Madrid")
+ if err != nil {
+ t.Fatal(err)
+ }
+ f := equipotest.New(t)
+ a := newAppConfigured(t, func(*sql.DB, config.Config) web.Installer { return noInstaller{} }, madrid,
+ func(c *config.Config) { c.EquipoOrigin = f.URL })
+ a.signedInOwner()
+ a.connectEquipo(f)
+ a.get("/ask")
+ a.get("/ask")
+ zones := f.Calls("/api/v1/assistant/time-zone")
+ if len(zones) != 1 || zones[0].Method != http.MethodPut || strings.TrimSpace(zones[0].Body) != `{"time_zone":"Europe/Madrid"}` ||
+ f.TimeZone() != "Europe/Madrid" {
+ t.Errorf("time zone told: %+v", zones)
+ }
+ snaps := f.Calls("/api/v1/assistant/snapshot")
+ if len(snaps) == 0 {
+ t.Fatal("no snapshot read")
+ }
+ for _, c := range snaps {
+ if c.Query != "job_states=paused" {
+ t.Errorf("snapshot's query %q", c.Query)
+ }
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ req, _ := http.NewRequestWithContext(ctx, http.MethodGet, a.base+"/ask/events?after=40", nil)
+ res, err := a.client.Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Its first line comes once Equipo's stream has opened.
+ if line, _ := bufio.NewReader(res.Body).ReadString('\n'); res.StatusCode != 200 || line == "" {
+ t.Fatalf("events: %d %q", res.StatusCode, line)
+ }
+ res.Body.Close()
+ events := f.Calls("/api/v1/assistant/events")
+ if len(events) == 0 || events[0].Query != "job_states=paused&after=40" {
+ t.Errorf("events: %+v", events)
+ }
+}
+
// A go-ahead or Publish card that belongs to a job is drawn under its
// pill while open, and answers as any card does; answered, it is listed
// in the job view. One whose job is not drawn is loose. A redrawn job (a