auth: show active sessions in `auth status`; logout targets same core · Entire
auth: show active sessions in auth status; logout targets same core
35830c7→main·
toothbrush·1mo ago·3 files·+196 added/-44 removed
Bring back the sessions table now that it correctly lists entire-core login
sessions (not entire.io PATs), so the effect of logout / logout --all is
visible:
auth statuslists the active sessions (NAME / CREATED / LAST USED / EXPIRES) on the active context's core, after the profile/context lines, with a hint tying the table tologoutandlogout --all. Best-effort: a listing failure is a soft note (liveness already confirmed via /me).logoutnow revokes against the active context's core too (shared resolveStatusTarget), so it acts on exactly the sessions status shows — not a static AuthBaseURL. Fixes the same multi-core mismatch for logout.- newSessionsClient takes an explicit coreURL.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
8159eed97febView transcript
Changes
3
cmd/entire/cli
Mauth.go+106/-18
Mauth_test.go+65/-7
Mlogout.go+25/-19
5 unmodified lines
6
7
8
9
10
11
12
13
14
14 unmodified lines
29
30
31
32
33
34
35
31 unmodified lines
67
68
69
67
68
69
70
71
72
73
74
75
70
71
72
73
74
75
76
77
78
96 unmodified lines
175
176
177
178
178
179
180
181
14 unmodified lines
196
197
198
199
200
201
202
203
204
205
206
207
203
204
205
208
209
210
211
212
213
214
51 unmodified lines
266
267
268
263
264
265
266
267
269
270
271
272
273
274
275
276
277
278
279
280
281
17 unmodified lines
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
98 unmodified lines
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
5 unmodified lines
"fmt"
"io"
"net/http"
"sort"
"strings"
"time"
"charm.land/lipgloss/v2"
"github.com/entireio/cli/cmd/entire/cli/api"
// formatRelativeDuration in status.go.
const (
placeholderDash = "-"
lastUsedNever = "never"
lastUsedJustNow = "just now"
)
// newSessionsClient builds an api.Client for entire-core's login-session
// endpoints (coreSessionsPath). It targets the auth host (api.AuthBaseURL()),
// since that's where the session/refresh-token families live; the supplied
// bearer must be the session-scoped login JWT, obtained via
// resolveAuthHostToken (a same-host resolution that returns the login token
// unchanged, preserving its entire:session scope — entire-core's session
// routes require it).
func newSessionsClient(token string) *api.Client {
return api.NewClientWithBaseURL(token, api.AuthBaseURL()).
WithSessionsPath(coreSessionsPath)
}
// resolveAuthHostToken returns a bearer scoped for the auth host (entire-core).
96 unmodified lines
func renderSessionsTable(w io.Writer, sty authTableStyles, sessions []api.Session) {
header := []string{
sy.render(sty.header, "NAME"),
sy.render(sty.header, "CREATED"),
sy.render(sty.header, "LAST USED"),
sy.render(sty.header, "EXPIRES"),
}
rows := make([][]string, 0, len(sessions))
for _, s := range sessions {
rows = append(rows, []string{
sy.render(sty.name, fallback(s.Name, placeholderDash)),
sy.render(sty.value, formatAuthDate(s.CreatedAt)),
sy.render(sty.value, formatLastUsed(s.LastUsedAt)),
sy.render(sty.value, formatAuthDate(s.ExpiresAt)),
})
}
renderAlignedTable(w, header, rows)
}
// sortSessionsByRecency orders sessions most-recently-used first, then most
// recently created, then by id — a fully specified order independent of the
// server's response ordering.
func sortSessionsByRecency(sessions []api.Session) {
sort.Slice(sessions, func(i, j int) bool {
li, lj := lastUsedSortKey(sessions[i]), lastUsedSortKey(sessions[j])
if li != lj {
return li > lj
}
if sessions[i].CreatedAt != sessions[j].CreatedAt {
return sessions[i].CreatedAt > sessions[j].CreatedAt
}
return sessions[i].ID < sessions[j].ID
})
}
func lastUsedSortKey(s api.Session) string {
if s.LastUsedAt == nil {
return ""
}
return *s.LastUsedAt
}
func formatAuthDate(s string) string {
if s == "" {
return placeholderDash
}
if ts, err := time.Parse(time.RFC3339, s); err == nil {
return ts.Local().Format("2006-01-02")
}
return s
}
func formatLastUsed(s *string) string {
if s == nil || *s == "" {
return lastUsedNever
}
return formatAuthDate(*s)
}