Activity: terminal session rows read as sentences
Paul's check of the session audit rows after rootfs Plan 6's dev checklist found they read "Recorded interactive-start", "Recorded interactive-end" and "Recorded interactive-refused", beside run rows that read "Started bin/rails runner puts 6*7 (v4)". The one formatter every audit feed reads through (auditWhatOf) now turns them into sentences, as it does run rows: - "Opened a terminal running bin/rails console (v4)" - "Terminal session ended with exit code 0 after 2m14s on box-1" - "Terminal session ended: <reason>". The reason is one of the box's approved words (idle, limit, hangup, lost, replaced) or the box's own explanation for an interrupted end, such as "the instance was restarted". - "No box opened the terminal session", "Terminal session was cancelled before it started", "Terminal session was refused (<why>)", and "Terminal session ended" for an end it does not know. The stored JSON stays under each sentence on the operator pages. A row that does not read keeps today's fallback. interactiveEndDetail also stores the End's Detail, so an interrupted end keeps the box's words. Rows written before this read "Terminal session was interrupted". Copy RFS-6-C76 to C84 approved unchanged by Paul (copy review 2026-11-01). Console only: no box change, nothing in the root binary. Review: Astra READY (reason mapping, escaping, end-row dedup unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from activity-session-labels into main.
5 files changed,
+220
−3
approved_rootfs_copy_test.go+4 −0docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md+11 −0internal/console/apiinteractive.go+5 −2internal/console/auditdetail.go+122 −1internal/console/auditdetail_session_test.go+78 −0
CI passed — run details
diff --git a/approved_rootfs_copy_test.go b/approved_rootfs_copy_test.go| index 4ccc24f14..f63bcfbc3 100644 |
| --- a/approved_rootfs_copy_test.go |
| +++ b/approved_rootfs_copy_test.go |
| @@ -144,6 +144,7 @@ var rootfsCopyIDs = []string{ |
| // Plan 6's copy gaps, approved by Paul 2026-10-31 |
| "RFS-6-C66", "RFS-6-C67", "RFS-6-C68", "RFS-6-C69", |
| "RFS-6-C70", "RFS-6-C71", "RFS-6-C72", "RFS-6-C73", "RFS-6-C74", "RFS-6-C75", |
| + "RFS-6-C76", "RFS-6-C77", "RFS-6-C78", "RFS-6-C79", "RFS-6-C80", "RFS-6-C81", "RFS-6-C82", "RFS-6-C83", "RFS-6-C84", |
| } |
| // rootfsCopyStruck is every id the deck marks struck, pinned, so a row can |
| @@ -281,6 +282,9 @@ var rootfsCopyBuilt = []string{ |
| // line (main.go), C21's three reasons, the signal line and the |
| // restore-failure line (interactive_cli.go) |
| "RFS-6-C70", "RFS-6-C71", "RFS-6-C72", "RFS-6-C73", "RFS-6-C74", "RFS-6-C75", |
| + // The Activity sentences for terminal session rows (approved 2026-11-01; |
| + // internal/console/auditdetail.go) |
| + "RFS-6-C76", "RFS-6-C77", "RFS-6-C78", "RFS-6-C79", "RFS-6-C80", "RFS-6-C81", "RFS-6-C82", "RFS-6-C83", "RFS-6-C84", |
| // Plan 6 Task 13: carlos run -it and carlos console (run.go, |
| // interactive_cli.go, interactive_term_other.go); RFS-6-C27 is Task 10's |
| "RFS-6-C01", "RFS-6-C02", "RFS-6-C03", "RFS-6-C04", "RFS-6-C05", "RFS-6-C06", "RFS-6-C07", "RFS-6-C08", |
diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md| index d4472e98d..890c5b9ce 100644 |
| --- a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md |
| +++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md |
| @@ -18,6 +18,8 @@ Added 2026-10-31: RFS-6-C70 to C74, the copy gaps Plan 6 Task 13 left (Astra's P |
| Added 2026-10-31: RFS-6-C75, the line for a terminal a session could not restore (Task 13 fix round 1, Astra's re-review). Paul approved it unchanged in his copy review on 2026-10-31. The gate's inventory and built list gained it in the same commit. |
| +Added 2026-11-01: RFS-6-C76 to C84, the Activity sentences for terminal session rows (they read "Recorded interactive-start" before), found when Paul checked the session audit rows after Plan 6's dev checklist. Paul approved all nine unchanged in his copy review on 2026-11-01. |
| + |
| The rules: |
| - A row is `pending` until Paul approves it in the copy review. His edits are |
| @@ -554,6 +556,15 @@ From the plan: Every string is human text the plan introduces. Existing approved |
| | RFS-6-C73 | interactive_cli.go (sessionExit: RFS-6-C21's reason for an end code this CLI does not know, the code; added 2026-10-31, approved unchanged by Paul in his copy review 2026-10-31) | the box gave a reason this version of carlos does not know (%s) | approved | |
| | RFS-6-C74 | interactive_cli.go (session: carlos got SIGTERM, SIGHUP or an outside SIGINT after the session started; the host, then the signal's name; exit 128+n; added 2026-10-31, approved unchanged by Paul in his copy review 2026-10-31) | %s: the session ended because carlos received %s | approved | |
| | RFS-6-C75 | interactive_cli.go (restoreFailedMsg: printed to stderr when a session's terminal could not be restored, after the retry; the error; added 2026-10-31, approved unchanged by Paul in his copy review 2026-10-31) | carlos could not put your terminal back to normal: %v. run reset to fix it | approved | |
| +| RFS-6-C76 | internal/console/auditdetail.go (auditSessionSentence: interactive-start row's Activity sentence: the command, then the release; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Opened a terminal running %s (%s) | approved | |
| +| RFS-6-C77 | internal/console/auditdetail.go (auditSessionSentence: interactive-start row with no release recorded; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Opened a terminal running %s | approved | |
| +| RFS-6-C78 | internal/console/auditdetail.go (auditSessionSentence: interactive-end row for a command that exited; the run rows' after/on tails follow; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Terminal session ended with exit code %d | approved | |
| +| RFS-6-C79 | internal/console/auditdetail.go (auditSessionSentence: interactive-end row ended for a reason: RFS-6-C51 to C54, C69, or the box's own words; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Terminal session ended: %s | approved | |
| +| RFS-6-C80 | internal/console/auditdetail.go (auditSessionSentence: interactive-end row interrupted with no words recorded; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Terminal session was interrupted | approved | |
| +| RFS-6-C81 | internal/console/auditdetail.go (auditSessionSentence: interactive-end row no box opened; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | No box opened the terminal session | approved | |
| +| RFS-6-C82 | internal/console/auditdetail.go (auditSessionSentence: interactive-end row cancelled before it started; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Terminal session was cancelled before it started | approved | |
| +| RFS-6-C83 | internal/console/auditdetail.go (auditSessionSentence: interactive-refused row (the console's sentence) and an interactive-end row the box refused (its code); added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Terminal session was refused (%s) | approved | |
| +| RFS-6-C84 | internal/console/auditdetail.go (auditSessionSentence: interactive-end row with an end it does not know; added 2026-11-01, approved unchanged by Paul in his copy review 2026-11-01) | Terminal session ended | approved | |
| ## Conflicts |
diff --git a/internal/console/apiinteractive.go b/internal/console/apiinteractive.go| index 7dc76ef4e..f8560f45c 100644 |
| --- a/internal/console/apiinteractive.go |
| +++ b/internal/console/apiinteractive.go |
| @@ -743,16 +743,19 @@ func interactiveStartDetail(sess *hubSession) string { |
| return string(raw) |
| } |
| -// interactiveEndDetail is the interactive-end row's detail. |
| +// interactiveEndDetail is the interactive-end row's detail. Detail keeps |
| +// the box's own words for an interrupted end ("the instance was |
| +// restarted"), which the Activity sentence shows. |
| func interactiveEndDetail(id string, e interactive.End) string { |
| raw, _ := json.Marshal(struct { |
| ID string `json:"id"` |
| Reason string `json:"reason"` |
| Refused string `json:"refused,omitempty"` |
| + Detail string `json:"detail,omitempty"` |
| Exit int `json:"exit"` |
| Started time.Time `json:"started,omitzero"` |
| Ended time.Time `json:"ended"` |
| Box string `json:"box,omitempty"` |
| - }{id, e.Reason, e.Refused, e.Exit, e.Started, e.Ended, e.Box}) |
| + }{id, e.Reason, e.Refused, e.Detail, e.Exit, e.Started, e.Ended, e.Box}) |
| return string(raw) |
| } |
diff --git a/internal/console/auditdetail.go b/internal/console/auditdetail.go| index 912b28e20..bbc4d3b7b 100644 |
| --- a/internal/console/auditdetail.go |
| +++ b/internal/console/auditdetail.go |
| @@ -8,6 +8,7 @@ import ( |
| "time" |
| "unicode/utf8" |
| + "github.com/carlosframework/platform/internal/interactive" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/runs" |
| ) |
| @@ -51,6 +52,27 @@ const ( |
| auditRunNoExit = "Run ended with no exit code recorded" |
| ) |
| +// Terminal session rows (RFS-6-C76 to C84, approved by Paul 2026-11-01), |
| +// beside the run rows they mirror. The end reasons are the box's words |
| +// for carlos logs (internal/host/interactive.go, RFS-6-C51 to C54 and |
| +// C69), repeated here because the console does not import the box. |
| +const ( |
| + auditSessionOpened = "Opened a terminal running %s (%s)" |
| + auditSessionOpenedBare = "Opened a terminal running %s" |
| + auditSessionExit = "Terminal session ended with exit code %d" |
| + auditSessionEndedBecause = "Terminal session ended: %s" |
| + auditSessionInterrupted = "Terminal session was interrupted" |
| + auditSessionNotOpened = "No box opened the terminal session" |
| + auditSessionCancelled = "Terminal session was cancelled before it started" |
| + auditSessionRefused = "Terminal session was refused (%s)" |
| + auditSessionEnded = "Terminal session ended" |
| + auditSessionIdleWords = "30 minutes passed without a keystroke" |
| + auditSessionLimitWords = "it reached its 6 hour limit" |
| + auditSessionHangupWords = "the person's connection closed" |
| + auditSessionLostWords = "the box lost its connection to the console" |
| + auditSessionReplacedWords = "a newer session on the same instance replaced it" |
| +) |
| + |
| // The rows the formatter reads, and how it lays them out. |
| const ( |
| auditActionRunStart = "run-start" |
| @@ -83,7 +105,11 @@ func auditWhatOf(action, detail string) auditWhat { |
| w.JSON = buf.String() |
| } |
| } |
| - switch text, ok := auditRunSentence(action, detail); { |
| + text, ok := auditRunSentence(action, detail) |
| + if !ok { |
| + text, ok = auditSessionSentence(action, detail) |
| + } |
| + switch { |
| case ok: |
| w.Text = text |
| case w.JSON != "": |
| @@ -237,3 +263,98 @@ func auditRunEndSentence(outcome string, res *runs.Result, exitKnown bool) strin |
| } |
| return s |
| } |
| + |
| +// The terminal session rows the console writes (apiinteractive.go). |
| +const ( |
| + auditActionSessionStart = "interactive-start" |
| + auditActionSessionEnd = "interactive-end" |
| + auditActionSessionRefused = "interactive-refused" |
| +) |
| + |
| +// auditSessionSentence is the sentence of a terminal session row whose |
| +// Detail reads as the JSON that row stores (interactiveStartDetail, |
| +// interactiveEndDetail, auditInteractiveRefused); ok is false for any |
| +// other row, and for one whose Detail does not read. |
| +func auditSessionSentence(action, detail string) (string, bool) { |
| + switch action { |
| + case auditActionSessionStart: |
| + var d struct { |
| + Argv []string `json:"argv"` |
| + Version string `json:"version"` |
| + } |
| + if json.Unmarshal([]byte(detail), &d) != nil || len(d.Argv) == 0 { |
| + return "", false |
| + } |
| + command := strings.Join(d.Argv, " ") |
| + if d.Version == "" { |
| + return fmt.Sprintf(auditSessionOpenedBare, command), true |
| + } |
| + return fmt.Sprintf(auditSessionOpened, command, d.Version), true |
| + case auditActionSessionEnd: |
| + var d struct { |
| + Reason string `json:"reason"` |
| + Refused string `json:"refused"` |
| + Detail string `json:"detail"` |
| + Exit int `json:"exit"` |
| + Started time.Time `json:"started"` |
| + Ended time.Time `json:"ended"` |
| + Box string `json:"box"` |
| + } |
| + if json.Unmarshal([]byte(detail), &d) != nil || d.Reason == "" { |
| + return "", false |
| + } |
| + return auditSessionEndSentence(d.Reason, d.Refused, d.Detail, d.Exit, d.Started, d.Ended, d.Box), true |
| + case auditActionSessionRefused: |
| + var d struct { |
| + Detail string `json:"detail"` |
| + } |
| + if json.Unmarshal([]byte(detail), &d) != nil || d.Detail == "" { |
| + return "", false |
| + } |
| + return fmt.Sprintf(auditSessionRefused, d.Detail), true |
| + } |
| + return "", false |
| +} |
| + |
| +// auditSessionEndSentence is an interactive-end row's sentence: how the |
| +// session ended (interactive.End's reasons), then, for a command that |
| +// exited, how long it ran and on which box, as a run-end row reads. |
| +func auditSessionEndSentence(reason, refused, words string, exit int, started, ended time.Time, box string) string { |
| + because := func(w string) string { return fmt.Sprintf(auditSessionEndedBecause, w) } |
| + switch reason { |
| + case interactive.EndIdle: |
| + return because(auditSessionIdleWords) |
| + case interactive.EndLimit: |
| + return because(auditSessionLimitWords) |
| + case interactive.EndHangup: |
| + return because(auditSessionHangupWords) |
| + case interactive.EndLost: |
| + return because(auditSessionLostWords) |
| + case interactive.EndReplaced: |
| + return because(auditSessionReplacedWords) |
| + case interactive.EndInterrupted: |
| + if words != "" { |
| + return because(words) |
| + } |
| + return auditSessionInterrupted |
| + case interactive.EndExpired: |
| + return auditSessionNotOpened |
| + case interactive.EndCancelled: |
| + return auditSessionCancelled |
| + case interactive.EndRefused: |
| + if refused == "" { |
| + return auditSessionEnded |
| + } |
| + return fmt.Sprintf(auditSessionRefused, refused) |
| + case interactive.EndExited: |
| + s := fmt.Sprintf(auditSessionExit, exit) |
| + if !started.IsZero() && ended.After(started) { |
| + s = fmt.Sprintf(auditRunAfter, s, ended.Sub(started).Round(time.Second)) |
| + } |
| + if box != "" { |
| + s = fmt.Sprintf(auditRunOn, s, box) |
| + } |
| + return s |
| + } |
| + return auditSessionEnded |
| +} |
diff --git a/internal/console/auditdetail_session_test.go b/internal/console/auditdetail_session_test.go| new file mode 100644 |
| index 000000000..f4cc23ab9 |
| --- /dev/null |
| +++ b/internal/console/auditdetail_session_test.go |
| @@ -0,0 +1,78 @@ |
| +package console |
| + |
| +import ( |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/interactive" |
| +) |
| + |
| +// Terminal session rows (interactive-start, interactive-end, |
| +// interactive-refused) read as sentences beside the run rows, not as |
| +// "Recorded interactive-start" (RFS-6-C76 to C84, approved by Paul |
| +// 2026-11-01). Each case is a Detail the console stores today |
| +// (interactiveStartDetail, interactiveEndDetail, auditInteractiveRefused). |
| +func TestTerminalSessionRowsReadAsSentences(t *testing.T) { |
| + for _, tc := range []struct { |
| + name, action, detail, want string |
| + }{ |
| + {"opened", "interactive-start", `{"id":"s1","argv":["bin/rails","console"],"process":"console","version":"v4"}`, |
| + "Opened a terminal running bin/rails console (v4)"}, |
| + {"opened, no release", "interactive-start", `{"id":"s1","argv":["/bin/sh"]}`, |
| + "Opened a terminal running /bin/sh"}, |
| + {"exited", "interactive-end", `{"id":"s1","reason":"exited","exit":0,"started":"2026-11-01T10:00:00Z","ended":"2026-11-01T10:02:14Z","box":"box-1"}`, |
| + "Terminal session ended with exit code 0 after 2m14s on box-1"}, |
| + {"idle", "interactive-end", `{"id":"s1","reason":"idle","exit":124,"ended":"2026-11-01T10:30:00Z"}`, |
| + "Terminal session ended: 30 minutes passed without a keystroke"}, |
| + {"limit", "interactive-end", `{"id":"s1","reason":"limit","exit":124,"ended":"2026-11-01T16:00:00Z"}`, |
| + "Terminal session ended: it reached its 6 hour limit"}, |
| + {"hangup", "interactive-end", `{"id":"s1","reason":"hangup","exit":125,"ended":"2026-11-01T10:00:00Z"}`, |
| + "Terminal session ended: the person's connection closed"}, |
| + {"lost", "interactive-end", `{"id":"s1","reason":"lost","exit":125,"ended":"2026-11-01T10:00:00Z"}`, |
| + "Terminal session ended: the box lost its connection to the console"}, |
| + {"replaced", "interactive-end", `{"id":"s1","reason":"replaced","exit":125,"ended":"2026-11-01T10:00:00Z"}`, |
| + "Terminal session ended: a newer session on the same instance replaced it"}, |
| + {"interrupted with the box's words", "interactive-end", `{"id":"s1","reason":"interrupted","detail":"the instance was restarted","exit":125,"ended":"2026-11-01T10:47:00Z"}`, |
| + "Terminal session ended: the instance was restarted"}, |
| + {"interrupted, an older row with no words", "interactive-end", `{"id":"s1","reason":"interrupted","exit":125,"ended":"2026-11-01T10:47:00Z"}`, |
| + "Terminal session was interrupted"}, |
| + {"expired", "interactive-end", `{"id":"s1","reason":"expired","exit":3,"ended":"2026-11-01T10:00:00Z"}`, |
| + "No box opened the terminal session"}, |
| + {"cancelled", "interactive-end", `{"id":"s1","reason":"cancelled","exit":130,"ended":"2026-11-01T10:00:00Z"}`, |
| + "Terminal session was cancelled before it started"}, |
| + {"refused by the box", "interactive-end", `{"id":"s1","reason":"refused","refused":"start_failed","exit":3,"ended":"2026-11-01T10:00:00Z"}`, |
| + "Terminal session was refused (start_failed)"}, |
| + {"an end it does not know", "interactive-end", `{"id":"s1","reason":"something-new","exit":1,"ended":"2026-11-01T10:00:00Z"}`, |
| + "Terminal session ended"}, |
| + {"refused by the console", "interactive-refused", `{"argv":["/bin/sh"],"status":409,"refused":"interactive_off","detail":"interactive sessions are off for this app"}`, |
| + "Terminal session was refused (interactive sessions are off for this app)"}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + w := auditWhatOf(tc.action, tc.detail) |
| + if w.Text != tc.want { |
| + t.Errorf("Text = %q, want %q", w.Text, tc.want) |
| + } |
| + if w.JSON == "" { |
| + t.Error("the stored object is no longer kept under the sentence") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A session row whose Detail does not read keeps today's fallback. |
| +func TestTerminalSessionRowThatDoesNotReadKeepsTheFallback(t *testing.T) { |
| + if got := auditText("interactive-start", `{"id":"s1"}`); got != "Recorded interactive-start" { |
| + t.Errorf("a start row with no command = %q", got) |
| + } |
| + if got := auditText("interactive-end", "plain words"); got != "plain words" { |
| + t.Errorf("a row that stored a sentence = %q", got) |
| + } |
| +} |
| + |
| +// The end row the console writes carries the box's words for an |
| +// interrupted end, so the restart reads as one. |
| +func TestInterruptedEndRowKeepsTheBoxsWords(t *testing.T) { |
| + d := interactiveEndDetail("s1", interactive.End{Reason: interactive.EndInterrupted, Detail: "the instance was restarted", Exit: 125}) |
| + if got, want := auditText("interactive-end", d), "Terminal session ended: the instance was restarted"; got != want { |
| + t.Errorf("auditText = %q, want %q (detail %s)", got, want, d) |
| + } |
| +} |