M9 #4.5 (pass-2): project context surfaced in Chat nav + Dashboard rows

Pass-2 UX feedback: "When selecting a per-project chat, we should
update the chat interface to show that we are 'in a project' — and
label them in the sessions list so the user can see the session
and understand what project it belongs to."

Two related changes:

**In-chat indicator** — ChatController gains `currentProjectName`,
set by `resetAndStartInProject` (direct: we have the ProjectEntry)
and by `startResuming` (resolved via SessionAttributionService +
project registry lookup). ChatView's toolbar uses a `.principal`
ToolbarItem with a VStack: "Chat" title on top, `Label(name, systemImage: "folder.fill")`
subtitle underneath when attributed. Mirrors Mac's SessionInfoBar
project-chip pattern but fits the iOS nav-bar real estate instead
of eating a full-width horizontal row.

**Dashboard row labels** — `IOSDashboardViewModel.load()` now does
one additional SFTP read per refresh: pulls the session→project
sidecar + project registry, maps session id → project display name
into `sessionProjectNames`. Row renders a small tinted folder
capsule when attributed. Batched so row renders are O(1) dict
lookups — no extra SFTP traffic per cell. Silent on failure
(attribution is cosmetic).

Not in scope for this commit: Mac's global Sessions list doesn't
currently show project attribution either — that gap exists on
both platforms, but wiring Mac's ProjectsSidebar + SessionsView
for per-row labels is a bigger surgery. Scoped as a post-TestFlight
followup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alan Wizemann
2026-04-24 14:38:02 +02:00
parent 1c2939dbbe
commit 3b3c037fce
3 changed files with 91 additions and 0 deletions
@@ -32,6 +32,13 @@ public final class IOSDashboardViewModel {
public var sessionPreviews: [String: String] = [:]
public var isLoading: Bool = true
/// session-id project display name, for sessions attributed to
/// a registered Scarf project. Populated in `load()` by a single
/// SFTP read of `session_project_map.json` + the project registry;
/// subsequent row renders are O(1) dict lookups. Empty when no
/// sessions on screen are attributed.
public private(set) var sessionProjectNames: [String: String] = [:]
/// Surfaced when the SQLite snapshot or DB open fails. Shown in a
/// yellow banner above the stats with a "Retry" button. `nil` means
/// the last load was healthy.
@@ -58,10 +65,41 @@ public final class IOSDashboardViewModel {
recentSessions = await dataService.fetchSessions(limit: 5)
sessionPreviews = await dataService.fetchSessionPreviews(limit: 5)
// Attribution lookup (pass-2 UX): load the sessionproject
// sidecar + project registry once so Dashboard rows can show
// which project each session belongs to. Batched (not per-row)
// so we don't pay a SFTP round-trip for every Recent Sessions
// cell. Failure is silent the absence of project labels is
// a cosmetic degradation, not a data-loss problem.
let ctx = context
let attributions: [String: String] = await Task.detached {
let attribution = SessionAttributionService(context: ctx)
let projectRegistry = ProjectDashboardService(context: ctx).loadRegistry()
let pathToName = Dictionary(
uniqueKeysWithValues: projectRegistry.projects.map { ($0.path, $0.name) }
)
let map = attribution.load().mappings
var result: [String: String] = [:]
for (sessionID, path) in map {
if let name = pathToName[path] {
result[sessionID] = name
}
}
return result
}.value
sessionProjectNames = attributions
await dataService.close()
isLoading = false
}
/// Helper used by DashboardView rows. Returns the project display
/// name a session is attributed to, or nil for unattributed
/// sessions (CLI-started, or started before v2.3).
public func projectName(for session: HermesSession) -> String? {
sessionProjectNames[session.id]
}
/// Called from the pull-to-refresh gesture.
public func refresh() async {
await load()