aaif-goose / aaif-goose/goose

Show aggregate session cost per project in Desktop

Đang mở
#11,790 1 bình luận 0 reaction 1 người được giao Được @Abhijay007 nhận Xem trên GitHub
Ngôn ngữ chính
Rust
Star
54.2k
Fork
6.2k
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
262

Mô tả

**What problem would this solve?**

Goose tracks accumulated cost per session and the Desktop groups recent sessions into projects by working directory, but users cannot see how much a project has cost across all of its sessions.

This is especially hard to answer for long-running projects with many sessions: the sidebar only loads a recent subset, Session History is paginated and date-grouped, and loading every session to sum its cost would be slow and could still produce a silently incomplete total.

This is a narrower project-level rollup than the general analytics/dashboard proposals in #10569 and #6766.

**What would a good outcome look like?**

- Desktop project headings show the lifetime accumulated cost for the same project/directory grouping users already see in navigation.
- The total covers the complete matching session population and is independent of sidebar limits, Session History pagination, search, and filters.
- The display respects the existing **Cost Tracking / Show model pricing and usage costs** preference.
- Known zero cost is distinguishable from unavailable cost.
- Partial totals are qualified, for example `$12.34+` or “At least $12.34,” with accessible detail such as “15 of 17 sessions have cost data.”
- Totals that include estimates are identified as such; provider-reported cost remains authoritative.
- Different currencies are never silently added together.
- The full working-directory path remains available to disambiguate projects with the same directory name.

For the initial scope, the UI could place a compact, right-aligned total in each collapsible project heading in the Desktop navigation panel, with details in an accessible tooltip/description. A broader analytics dashboard, charts, budgets, and per-provider breakdowns are out of scope.

**Possible approaches**

Backend:

- Add a `SessionManager` aggregate query over SQLite rather than summing paginated `session/list` results in the client.
- Reuse the canonical per-session cost reconciliation semantics used by `get_session_usage_totals`: account for persisted legacy totals and usage-ledger totals without double counting.
- Sum each selected session's own canonical cost exactly once. Recursive parent totals must not cause subagent costs to be counted again when child sessions are also selected.
- Return coverage metadata, not just a number, for example:

```json
{
"costs": [{ "currency": "USD", "amount": 12.34 }],
"sessionCount": 17,
"knownCostSessionCount": 15,
"unknownCostSessionCount": 2,
"includesEstimates": true
}
```

- Expose this through a focused Goose ACP custom request such as `_goose/unstable/session/cost/aggregate`, rather than attaching a global aggregate to every `SessionInfo` or coupling it to the 50-row list cursor.
- Define project identity explicitly. Desktop currently groups by a lightly normalized `workingDir`, while sessions can also carry `project_id` and configured projects can have multiple working directories. Prefer `project_id` when it is present, with normalized working-directory aggregation as the directory-based fallback used by the current UI.

Semantics to decide during design:

- Default session types: user and scheduled only, or user/scheduled/ACP.
- Whether archived sessions contribute to the lifetime total. A reasonable default is to include archived but exclude deleted sessions; deletion currently removes the accounting rows.
- Whether descendant subagent sessions belong to the parent project's total when their own working directory differs.
- Path identity policy for trailing separators, relative paths, symlinks, renamed directories, and projects configured with multiple working directories. Filesystem canonicalization alone is not sufficient because historical directories may no longer exist.
- Currency source and behavior for mixed currencies.

Desktop:

- Extend the project navigation model with server-derived aggregate data; do not derive it from the 25 recent sessions currently loaded.
- Use a shared locale-aware currency formatter with adaptive precision for small costs.
- Hide project totals when `showPricing` is disabled and react to `showPricingChanged`.
- Render unavailable as an em dash / “Cost unavailable,” never as `$0.00`.
- Keep qualifiers visible or accessible rather than relying on color or tooltip alone.

Relevant implementation areas:

- `crates/goose/src/session/session_manager.rs` — session schema, ledger reconciliation, aggregate query and tests
- `crates/goose-sdk-types/src/custom_requests.rs` — Goose ACP request/response types
- `crates/goose/src/acp/server/custom_dispatch.rs` — request dispatch
- `ui/desktop/src/acp/sessions.ts` — Desktop ACP adapter
- `ui/desktop/src/utils/projectSessions.ts` — current directory-based project grouping
- `ui/desktop/src/hooks/useNavigationSessions.ts` — recent-session limit
- `ui/desktop/src/components/Layout/NavigationPanel.tsx` — project heading presentation
- `ui/desktop/src/utils/usageFormatting.ts` — shared cost formatting

Suggested verification:

- Aggregate remains correct with more than 50 sessions and beyond the Desktop's 25-session recent limit.
- Known, unknown, partial, zero, estimated, reported, and mixed-currency costs render distinctly.
- Legacy totals and usage-ledger totals reconcile without duplication.
- Parent/subagent trees do not double count.
- Project/directory isolation, multiple directories, path normalization, archived/deleted sessions, and relevant session types are covered.
- Search, pagination, and the ACP-session toggle do not change a lifetime project total.
- `showPricing=false` hides totals; project collapse remains keyboard-operable and correctly announced.

**Additional context**

Goose already persists `working_dir`, `project_id`, `parent_session_id`, and nullable `accumulated_cost` on sessions. The missing pieces are a complete backend aggregation contract and project-level presentation.

Related but not duplicate:

- #10569 proposed a much broader usage dashboard and was closed as not planned.
- #6766 proposed general session intelligence/analytics and was closed as not planned.
- #7877 implemented recursive session/subagent cost totals and per-message usage, which this feature should reuse without double counting.
- #11786 tracks improving cost estimation coverage; project totals must remain honest when some sessions are still unpriced.

- [x] I have verified this does not duplicate an existing feature request

Please add this issue to the [Goose Issues board](https://github.com/orgs/aaif-goose/projects/1) and move it to **Ready** if the scope and semantics are approved. Implementation should not begin before that gate.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.