Skip to content

Commit 452d856

Browse files
committed
Read every page of the five account-wide lists Basecamp now pages
Basecamp answers the overdue to-dos and cards, completed assignments, the timesheet report and the assigned to-dos report 50 records a page (basecamp/bc3#14537), where each used to come whole. Once that ships, basecamp-sdk v0.37.0 would hand those commands the first page as if it were the whole list. They now read every page, so a list longer than 50 is still complete. Pins basecamp-sdk to basecamp/basecamp-sdk#1102, which follows these pages, until a release carries it, and re-syncs the MCP server's model from it, so its five matching actions take a page. The new go.sum changes the Nix vendorHash. https://app.basecamp.com/2914079/buckets/27/card_tables/cards/10516396199
1 parent fcf74ac commit 452d856

18 files changed

Lines changed: 294 additions & 56 deletions

‎ACCOUNT-WIDE-LISTINGS.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ under project rules before the account-wide branch is reached is a defect: the
5151
paginated aggregates accept **any positive page**, while several project-scoped
5252
commands only permit page 1.
5353

54-
Conversely `--page` must return `ErrUsage` against the **unpaginated** overdue
55-
endpoints, which take no page argument at all.
54+
Conversely `--page` must return `ErrUsage` against the overdue listings, which
55+
the CLI reads whole, following every page, so there is no page to address.
5656

5757
### I2 — Scope precedence
5858

@@ -230,7 +230,7 @@ rows that differ for stated reasons. `--all` is how you ask for the account.
230230
| `checkins answers` | cap 100 | **changed** from "all pages" |
231231
| `forwards list` | cap 100 | **changed** from "all pages" |
232232
| `files list` | cap 100 | **changed** from "all pages" |
233-
| `todos list --overdue` | cap 100 | unpaginated endpoint; accepts `--all`, rejects `--page` |
233+
| `todos list --overdue` | cap 100 | read whole, every page followed; accepts `--all`, rejects `--page` |
234234
| `cards list --overdue` | cap 100 | **changed** from uncapped; same rules as above |
235235
| `bookmarks list` | cap 100 | personal feed — see below |
236236
| `drafts list` | cap 100 | personal feed; server caps the full listing at 250 |
@@ -259,7 +259,8 @@ options struct does not honor a page number at all, so it takes `--limit` (a
259259
real SDK-side bound) and deliberately registers no `--page`. Under I3 a flag
260260
that cannot act on its value is worse than an absent one.
261261

262-
**The two overdue rows.** Both endpoints are unpaginated, so `--page` has
262+
**The two overdue rows.** The CLI reads both listings whole, following every
263+
page Basecamp sends (50 a page since basecamp/bc3#14537), so `--page` has
263264
nothing to address and stays an error. `--all` is a different question: it means
264265
"skip the cap", and since the complete array is already in hand it costs no
265266
extra request. Previously `todos --overdue` capped at 100 *and* rejected `--all`,

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
charm.land/bubbles/v2 v2.2.1
99
charm.land/bubbletea/v2 v2.1.0
1010
charm.land/lipgloss/v2 v2.0.6
11-
github.com/basecamp/basecamp-sdk/go v0.37.0
11+
github.com/basecamp/basecamp-sdk/go v0.37.1-0.20261120012501-1d0f5e04225d
1212
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9
1313
github.com/basecamp/mcp v0.0.0-20261118214004-663b2e5d2836
1414
github.com/basecamp/surfguard/go v0.1.0

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
8989
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
9090
github.com/basecamp/actioncable-go v1.2.0 h1:t0MxlfMTcmaGXZ5ztgKRs7ZiY1MwXtBRwSSSAh1ofVg=
9191
github.com/basecamp/actioncable-go v1.2.0/go.mod h1:ezaV5z1GXQAsqyejqTs6wCFl2D8Wj+COLQkHc/kwoRs=
92-
github.com/basecamp/basecamp-sdk/go v0.37.0 h1:/Tv7GALbwmj0/gk8y2kwAi9/OiiWEQlJcVDH9PfMHWM=
93-
github.com/basecamp/basecamp-sdk/go v0.37.0/go.mod h1:ynVJME8mVV3UHMUMnzBgygTnMtadQFxz1iYg7fqwUeM=
92+
github.com/basecamp/basecamp-sdk/go v0.37.1-0.20261120012501-1d0f5e04225d h1:HOnC8h7DRBSlsiaZn1kCRXLYgYdoKZ+gWR0grlXwXXo=
93+
github.com/basecamp/basecamp-sdk/go v0.37.1-0.20261120012501-1d0f5e04225d/go.mod h1:ynVJME8mVV3UHMUMnzBgygTnMtadQFxz1iYg7fqwUeM=
9494
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9 h1:3NfGs+zx23Tp6cf+97+UewrJHlzZMLzmvEXOmOJyQAk=
9595
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9/go.mod h1:iTBTaWvsPEFIcZfkxQHEfISyJ6sZ7036K6bNx0RY3EE=
9696
github.com/basecamp/mcp v0.0.0-20261118214004-663b2e5d2836 h1:ND4te8b+HVFFrgcm7+n8P83MKKPqBpIyoJ63tT9liRU=

‎internal/commands/assignments.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,11 @@ func newAssignmentsCompletedCmd() *cobra.Command {
317317
return err
318318
}
319319

320-
items, err := app.Account().MyAssignments().Completed(cmd.Context())
320+
result, err := app.Account().MyAssignments().Completed(cmd.Context(), 0)
321321
if err != nil {
322322
return convertSDKError(err)
323323
}
324+
items := result.Assignments
324325

325326
return app.OK(items,
326327
output.WithSummary(fmt.Sprintf("%d completed assignment(s)", len(items))),

‎internal/commands/cards.go‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ func cardsAccountWideSelector(opts cardsListOptions) (selector, flag string, err
268268
}
269269

270270
// runCardsListAccountWide lists cards across every accessible project. The
271-
// paginated aggregates come back grouped by project; --overdue comes back flat
272-
// and unpaginated.
271+
// paginated aggregates come back grouped by project; --overdue comes back flat,
272+
// every page followed.
273273
func runCardsListAccountWide(cmd *cobra.Command, app *appctx.App, opts cardsListOptions, selector string) error {
274274
if err := rejectAccountWideTodolist(app, "card"); err != nil {
275275
return err
@@ -313,12 +313,12 @@ func runCardsListAccountWide(cmd *cobra.Command, app *appctx.App, opts cardsList
313313
}
314314

315315
if selector == cardsSelectorOverdue {
316-
// --page has nothing to address on an unpaginated endpoint, but --all
316+
// --page has nothing to address on a listing read whole, but --all
317317
// does: the listing is capped by default, and --all is how you reach
318318
// past the cap. Rejecting both would leave card 101 unreachable.
319319
if opts.pageSet {
320320
return output.ErrUsageHint(
321-
"--page is not supported with --overdue (the overdue listing is not paginated)",
321+
"--page is not supported with --overdue (the overdue listing is read whole)",
322322
"Cap the results instead: basecamp cards list --overdue --limit <n>",
323323
)
324324
}
@@ -432,8 +432,8 @@ func runCardsListAccountWide(cmd *cobra.Command, app *appctx.App, opts cardsList
432432
return app.OK(groups, respOpts...)
433433
}
434434

435-
// runCardsListOverdue lists overdue cards across every project. The endpoint
436-
// returns a flat, oldest-due-first array, so it renders like the
435+
// runCardsListOverdue lists overdue cards across every project. The SDK follows
436+
// every page of a flat, oldest-due-first list, so it renders like the
437437
// project-scoped path and accepts the sort flags.
438438
func runCardsListOverdue(cmd *cobra.Command, app *appctx.App, opts cardsListOptions) error {
439439
if opts.sortField == "position" {
@@ -450,18 +450,19 @@ func runCardsListOverdue(cmd *cobra.Command, app *appctx.App, opts cardsListOpti
450450
return err
451451
}
452452

453-
cards, err := app.Account().Everything().OverdueCards(cmd.Context(), taskFilters)
453+
result, err := app.Account().Everything().OverdueCards(cmd.Context(), 0, taskFilters)
454454
if err != nil {
455455
return convertSDKError(err)
456456
}
457+
cards := result.Cards
457458

458459
// Sort before truncating: truncating first would sort only the survivors.
459460
if opts.sortField != "" {
460461
sortCards(cards, opts.sortField, opts.reverse)
461462
}
462463

463-
// The endpoint is unpaginated, so the complete array is already in hand and
464-
// --all costs nothing beyond skipping the cap. --limit trims locally.
464+
// The complete list is already in hand, so --all costs nothing beyond
465+
// skipping the cap. --limit trims locally.
465466
total := len(cards)
466467
limit := opts.limit
467468
if limit == 0 {
@@ -476,7 +477,10 @@ func runCardsListOverdue(cmd *cobra.Command, app *appctx.App, opts cardsListOpti
476477
output.WithBreadcrumbs(cardsAccountWideBreadcrumbs()...),
477478
output.WithDisplayData(flattenOverdueCards(cards)),
478479
}
479-
if len(cards) < total {
480+
switch {
481+
case result.Meta.Truncated:
482+
respOpts = append(respOpts, output.WithNotice("More pages are available; results were truncated"))
483+
case len(cards) < total:
480484
respOpts = append(respOpts, output.WithNotice(fmt.Sprintf(
481485
"Showing the first %d of %d overdue cards (use --all for the complete list, or --limit to raise the cap)",
482486
len(cards), total)))

‎internal/commands/cards_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ const cardsGroupsFixture = `[
25492549
{"id":22,"title":"Beta two","status":"active","due_on":"2026-03-01"}]}
25502550
]`
25512551

2552-
// cardsOverdueFixture is the flat, unpaginated overdue payload.
2552+
// cardsOverdueFixture is the flat overdue payload, on one page.
25532553
const cardsOverdueFixture = `[
25542554
{"id":31,"title":"Zeta late","status":"active","due_on":"2025-02-01"},
25552555
{"id":32,"title":"Alpha late","status":"active","due_on":"2025-01-01"}
@@ -2800,7 +2800,7 @@ func TestCardsListAccountWideRejectsBadPaging(t *testing.T) {
28002800
}
28012801

28022802
// TestCardsListOverdueRejectsPage tests that --page is refused rather than
2803-
// accepted and dropped: there is no page to address on an unpaginated endpoint.
2803+
// accepted and dropped: the overdue listing is read whole, every page followed.
28042804
func TestCardsListOverdueRejectsPage(t *testing.T) {
28052805
app, _ := setupRecordingTestApp(t, cardsAllAggregateRoutes()...)
28062806
err := executeRecordingCommand(NewCardsCmd(), app, "list", "--all-projects", "--overdue", "--page", "1")
@@ -2809,9 +2809,9 @@ func TestCardsListOverdueRejectsPage(t *testing.T) {
28092809

28102810
// --all is a different question from --page. The overdue listing is capped at
28112811
// 100 by default, so rejecting --all as well would leave card 101 unreachable —
2812-
// capped with no escape hatch is the defect, not the fix. The endpoint is
2813-
// unpaginated, so honoring --all costs nothing: the complete array is already
2814-
// in hand.
2812+
// capped with no escape hatch is the defect, not the fix. The listing is read
2813+
// whole, so honoring --all costs nothing: the complete array is already in
2814+
// hand.
28152815
func TestCardsListOverdueAcceptsAll(t *testing.T) {
28162816
app, transport, buf := setupCardsAccountWideApp(t, output.FormatJSON, cardsAllAggregateRoutes()...)
28172817
require.NoError(t, executeRecordingCommand(NewCardsCmd(), app, "list", "--all-projects", "--overdue", "--all"))
@@ -2824,7 +2824,7 @@ func TestCardsListOverdueAcceptsAll(t *testing.T) {
28242824
assert.Len(t, envelope.Data, 2, "--all returns the complete array")
28252825
assert.Empty(t, envelope.Notice, "nothing was withheld, so there is nothing to warn about")
28262826
assert.Len(t, transport.queriesFor(cardsAggregatePath("overdue")), 1,
2827-
"--all costs no extra request on an unpaginated endpoint")
2827+
"--all costs no extra request on a listing already read whole")
28282828
}
28292829

28302830
// TestCardsListAccountWideSorting tests that sorting is rejected for the
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package commands
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/basecamp/basecamp-cli/internal/output"
12+
)
13+
14+
func TestAccountWideListsReadEveryPage(t *testing.T) {
15+
cases := []struct {
16+
name string
17+
cmd func() *cobra.Command
18+
args []string
19+
path string
20+
pages []string
21+
ids func(records any) []any
22+
also []stubRoute
23+
}{
24+
{
25+
name: "overdue todos", cmd: NewTodosCmd, args: []string{"list", "--overdue"},
26+
path: "/99999/todos/overdue.json",
27+
pages: []string{`[{"id":1,"title":"Alpha","due_on":"2020-01-01"}]`, `[{"id":2,"title":"Bravo","due_on":"2020-02-01"}]`},
28+
ids: listIDs,
29+
},
30+
{
31+
name: "overdue cards", cmd: NewCardsCmd, args: []string{"list", "--all-projects", "--overdue"},
32+
path: "/99999/cards/overdue.json",
33+
pages: []string{`[{"id":1,"title":"Alpha","due_on":"2020-01-01"}]`, `[{"id":2,"title":"Bravo","due_on":"2020-02-01"}]`},
34+
ids: listIDs,
35+
},
36+
{
37+
name: "completed assignments", cmd: NewAssignmentsCmd, args: []string{"completed"},
38+
path: "/99999/my/assignments/completed.json",
39+
pages: []string{`[{"id":1,"content":"Alpha"}]`, `[{"id":2,"content":"Bravo"}]`},
40+
ids: listIDs,
41+
},
42+
{
43+
name: "timesheet report", cmd: NewTimesheetCmd, args: []string{"report"},
44+
path: "/99999/reports/timesheet.json",
45+
pages: []string{`[{"id":1,"hours":"1.0"}]`, `[{"id":2,"hours":"2.0"}]`},
46+
ids: listIDs,
47+
},
48+
{
49+
name: "assigned todos", cmd: NewReportsCmd, args: []string{"assigned", "42"},
50+
path: "/99999/reports/todos/assigned/42",
51+
pages: []string{
52+
`{"person":{"id":42,"name":"Ann"},"grouped_by":"","todos":[{"id":1,"title":"Alpha"}]}`,
53+
`{"person":{"id":42,"name":"Ann"},"grouped_by":"","todos":[{"id":2,"title":"Bravo"}]}`,
54+
},
55+
ids: func(report any) []any { return listIDs(report.(map[string]any)["todos"]) },
56+
also: []stubRoute{{method: http.MethodGet, path: "/99999/people.json", status: http.StatusOK,
57+
body: `[{"id":42,"name":"Ann"}]`}},
58+
},
59+
}
60+
61+
for _, tc := range cases {
62+
t.Run(tc.name, func(t *testing.T) {
63+
listRoute := stubRoute{method: http.MethodGet, path: tc.path, status: http.StatusOK, pages: tc.pages, linked: true}
64+
app, transport, buf := setupAccountWideTodosApp(t, output.FormatJSON, append(tc.also, listRoute)...)
65+
66+
require.NoError(t, executeRecordingCommand(tc.cmd(), app, tc.args...))
67+
68+
assert.Equal(t, []string{"", "page=2"}, transport.queriesFor(tc.path))
69+
assert.Equal(t, []any{float64(1), float64(2)}, tc.ids(decodeTodosEnvelope(t, buf)["data"]))
70+
})
71+
}
72+
}
73+
74+
func listIDs(records any) []any {
75+
list := records.([]any)
76+
ids := make([]any, 0, len(list))
77+
for _, record := range list {
78+
ids = append(ids, record.(map[string]any)["id"])
79+
}
80+
return ids
81+
}

‎internal/commands/recording_test.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ type stubRoute struct {
5353
// would walk all the way to the cap and hide the behavior under test.
5454
pages []string
5555

56+
// linked, with pages, serves pages the way Basecamp's Link-paged lists do:
57+
// no page number is page 1, and every page but the last names the next in
58+
// a Link rel="next" header, so the SDK follows them.
59+
linked bool
60+
5661
// bodies, when set, serves bodies[i] to the i-th request this route
5762
// matches and repeats the last entry past the end. Routes match on method
5863
// and path alone, so a walk that re-requests one path with a different
@@ -76,6 +81,39 @@ func pagedBody(route stubRoute, rawPage string) string {
7681
return route.pages[n-1]
7782
}
7883

84+
// linkedPageNumber is the page a request to a linked route asks for, 1 when it
85+
// names none.
86+
func linkedPageNumber(req *http.Request) int {
87+
n, err := strconv.Atoi(req.URL.Query().Get("page"))
88+
if err != nil || n < 1 {
89+
return 1
90+
}
91+
return n
92+
}
93+
94+
// linkedPage serves a linked route's page, or an empty array past its end.
95+
func linkedPage(route stubRoute, req *http.Request) string {
96+
n := linkedPageNumber(req)
97+
if n > len(route.pages) {
98+
return "[]"
99+
}
100+
return route.pages[n-1]
101+
}
102+
103+
// linkedNextPage is the URL of the page after the one requested, or "" on the
104+
// last page.
105+
func linkedNextPage(route stubRoute, req *http.Request) string {
106+
n := linkedPageNumber(req)
107+
if n >= len(route.pages) {
108+
return ""
109+
}
110+
next := *req.URL
111+
query := next.Query()
112+
query.Set("page", strconv.Itoa(n+1))
113+
next.RawQuery = query.Encode()
114+
return next.String()
115+
}
116+
79117
// recordingTransport is an http.RoundTripper that records every request and
80118
// serves canned responses from its route table. Unmatched requests get an
81119
// error response — a wrong route fails the command rather than passing
@@ -115,10 +153,17 @@ func (t *recordingTransport) RoundTrip(req *http.Request) (*http.Response, error
115153
switch {
116154
case route.bodies != nil:
117155
responseBody = route.bodies[t.nextBody(index, len(route.bodies))]
156+
case route.linked:
157+
responseBody = linkedPage(route, req)
118158
case route.pages != nil:
119159
responseBody = pagedBody(route, req.URL.Query().Get("page"))
120160
}
121161
header := http.Header{"Content-Type": []string{"application/json"}}
162+
if route.linked {
163+
if next := linkedNextPage(route, req); next != "" {
164+
header.Set("Link", fmt.Sprintf(`<%s>; rel="next"`, next))
165+
}
166+
}
122167
for name, values := range route.header {
123168
header[name] = values
124169
}

‎internal/commands/timesheet.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ func runTimesheetReport(cmd *cobra.Command, startDate, endDate, personID string)
9090
opts.PersonID = pid
9191
}
9292

93-
entries, err := app.Account().Timesheet().Report(cmd.Context(), opts)
93+
result, err := app.Account().Timesheet().Report(cmd.Context(), opts)
9494
if err != nil {
9595
return convertSDKError(err)
9696
}
97+
entries := result.Entries
9798

9899
totalHours := sumTimesheetHours(entries)
99100

‎internal/commands/todos.go‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,12 @@ func listGroupedTodosAcrossProjects(cmd *cobra.Command, app *appctx.App, flags t
461461
}
462462

463463
// listOverdueTodosAcrossProjects fetches the overdue aggregate, which is a flat
464-
// oldest-due-first array rather than a paginated, project-grouped listing.
464+
// oldest-due-first list rather than a project-grouped one. The SDK follows its
465+
// pages, so the whole list is in hand.
465466
func listOverdueTodosAcrossProjects(cmd *cobra.Command, app *appctx.App, flags todosListFlags) error {
466467
if cmd.Flags().Changed("page") {
467468
return output.ErrUsageHint(
468-
"--page is not supported with --overdue (the overdue listing is not paginated)",
469+
"--page is not supported with --overdue (the overdue listing is read whole)",
469470
"Cap the results instead: basecamp todos list --overdue --limit <n>")
470471
}
471472
if flags.sortField == "position" {
@@ -477,19 +478,20 @@ func listOverdueTodosAcrossProjects(cmd *cobra.Command, app *appctx.App, flags t
477478
return err
478479
}
479480

480-
todos, err := app.Account().Everything().OverdueTodos(cmd.Context(), taskFilters)
481+
result, err := app.Account().Everything().OverdueTodos(cmd.Context(), 0, taskFilters)
481482
if err != nil {
482483
return convertSDKError(err)
483484
}
485+
todos := result.Todos
484486
total := len(todos)
485487

486488
// Sort before truncating — truncating first would sort only the survivors.
487489
if flags.sortField != "" {
488490
sortTodos(todos, flags.sortField, flags.reverse)
489491
}
490492

491-
// The endpoint is unpaginated, so the complete array is already in hand and
492-
// --all costs nothing beyond skipping the cap. --limit trims locally.
493+
// The complete list is already in hand, so --all costs nothing beyond
494+
// skipping the cap. --limit trims locally.
493495
limit := flags.limit
494496
if limit == 0 {
495497
limit = accountWideDefaultLimit
@@ -518,7 +520,10 @@ func listOverdueTodosAcrossProjects(cmd *cobra.Command, app *appctx.App, flags t
518520
},
519521
),
520522
}
521-
if total > len(todos) {
523+
switch {
524+
case result.Meta.Truncated:
525+
respOpts = append(respOpts, output.WithNotice("More pages are available; results were truncated"))
526+
case total > len(todos):
522527
respOpts = append(respOpts, output.WithNotice(fmt.Sprintf(
523528
"Showing %d of %d overdue todos (use --all for the complete list, or --limit to raise the cap)",
524529
len(todos), total)))

0 commit comments

Comments
 (0)