Skip to content

Commit b011ee9

Browse files
screen-gdclaude
andcommitted
feat(usage): track Devin tokens and estimated cost
Read Devin CLI session history into the Usage page so Devin shows token totals and API-equivalent cost next to other providers. Totals appear as sessions finish and saved progress means restarts read only new messages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 108d0d5 commit b011ee9

18 files changed

Lines changed: 1575 additions & 32 deletions

File tree

‎apps/mobile/src/features/usage/usageProviders.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const PROVIDER_ORDER: readonly UsageProviderKind[] = [
1010
"antigravity",
1111
"pi",
1212
"muse",
13+
"devin",
1314
];
1415

1516
export function usageProviderKind(driver: string): UsageProviderKind | null {
@@ -26,6 +27,7 @@ export const PROVIDER_LABEL: Record<UsageProviderKind, string> = {
2627
antigravity: "Antigravity",
2728
pi: "Pi",
2829
muse: "Muse Code",
30+
devin: "Devin",
2931
};
3032

3133
export function useProviderColors(): Record<UsageProviderKind, string> {
@@ -39,6 +41,7 @@ export function useProviderColors(): Record<UsageProviderKind, string> {
3941
antigravity: "#8c7bd1",
4042
pi: "#4d9f8a",
4143
muse: "#0866ff",
44+
devin: "#5e9ce6",
4245
};
4346
}
4447

‎apps/server/src/provider/builtInDrivers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const BUILT_IN_DRIVERS: ReadonlyArray<AnyProviderDriver<BuiltInDriversEnv
4545
];
4646

4747
export type BuiltInUsageReadersEnv =
48+
| ProviderUsageReaderEnv<typeof AcpRegistryDriver>
4849
| ProviderUsageReaderEnv<typeof ClaudeDriver>
4950
| ProviderUsageReaderEnv<typeof CodexDriver>
5051
| ProviderUsageReaderEnv<typeof GrokDriver>
@@ -66,4 +67,5 @@ export const BUILT_IN_USAGE_DRIVERS: ReadonlyArray<
6667
MuseDriver,
6768
AntigravityDriver,
6869
CursorDriver,
70+
AcpRegistryDriver,
6971
];

‎apps/server/src/server.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ import * as ProcessGroupMetrics from "./resourceTelemetry/ProcessGroupMetrics.ts
186186
import * as ResourceTelemetry from "./resourceTelemetry/ResourceTelemetry.ts";
187187
import * as AntigravityUsage from "./provider/Drivers/AntigravityUsage.ts";
188188
import { MuseUsageHome } from "@t3tools/provider-muse/server";
189+
import { DevinUsage } from "@t3tools/provider-acp-registry/server";
189190
import * as CursorAccountReader from "@t3tools/provider-cursor/server/CursorAccountReader";
190191
import * as CursorKeychain from "@t3tools/provider-cursor/server/CursorKeychain";
191192
import * as CursorUsageAccounts from "@t3tools/provider-cursor/server/CursorUsageAccounts";
@@ -289,11 +290,12 @@ const layerUsage = UsageService.layer.pipe(
289290
Layer.mergeAll(
290291
AntigravityUsage.layer,
291292
MuseUsageHome.layer,
293+
DevinUsage.layer,
292294
CodexUsageHistory.layer,
293295
CursorUsageAccounts.layer.pipe(
294296
Layer.provide(CursorAccountReader.layer.pipe(Layer.provide(CursorKeychain.layer))),
295297
),
296-
).pipe(Layer.provide(ProviderHostLive.layer.pipe(Layer.provide(ServerSecretStore.layer)))),
298+
).pipe(Layer.provideMerge(ProviderHostLive.layer.pipe(Layer.provide(ServerSecretStore.layer)))),
297299
),
298300
Layer.provide(layerServerSettings),
299301
);

‎apps/server/src/usage/UsageService.test.ts‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { totalTokens, type UsageRecord } from "@t3tools/provider-core/server/usa
5353
import * as UsageService from "./UsageService.ts";
5454
import * as MuseSdk from "../../../../packages/provider-muse/src/server/sdk.ts";
5555
import { MuseUsageHome } from "@t3tools/provider-muse/server";
56+
import { DevinUsage } from "@t3tools/provider-acp-registry/server";
5657
import { makeScanCacheWriter, SCAN_CACHE_FILE_NAME } from "./usageScanCache.ts";
5758

5859
vi.mock("node:fs/promises", { spy: true });
@@ -158,6 +159,7 @@ const layerService = (input: {
158159
).pipe(
159160
Layer.provideMerge(AntigravityUsage.layer),
160161
Layer.provideMerge(MuseUsageHome.layer),
162+
Layer.provideMerge(DevinUsage.layer),
161163
Layer.provideMerge(ProviderHostLive.layer),
162164
Layer.provideMerge(CodexUsageHistory.layer.pipe(Layer.provideMerge(Sqlite.layerMemory))),
163165
Layer.provideMerge(Layer.mock(BackgroundPolicy.BackgroundPolicy)({})),
@@ -487,6 +489,148 @@ describe("Codex usage history", () => {
487489
});
488490

489491
describe("UsageService", () => {
492+
it.live("includes Devin Fusion history with Devin pricing and custom overrides", () =>
493+
Effect.gen(function* () {
494+
const { home, settings } = yield* setup;
495+
const dataHome = NodePath.join(home, "data");
496+
const dir = NodePath.join(dataHome, "devin", "cli");
497+
yield* Effect.promise(() => NodeFSP.mkdir(dir, { recursive: true }));
498+
const db = yield* Effect.acquireRelease(
499+
Effect.sync(() => new NodeSqlite.DatabaseSync(NodePath.join(dir, "sessions.db"))),
500+
(db) => Effect.sync(() => db.close()),
501+
);
502+
db.exec("CREATE TABLE sessions (id TEXT PRIMARY KEY, model TEXT, last_activity_at INTEGER)");
503+
db.exec(
504+
"CREATE TABLE message_nodes (row_id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT, node_id INTEGER, chat_message TEXT, created_at INTEGER, UNIQUE(session_id, node_id))",
505+
);
506+
db.exec("CREATE INDEX idx_message_nodes_session ON message_nodes(session_id)");
507+
const time = Date.parse("2026-08-01T10:00:00Z");
508+
db.prepare("INSERT INTO sessions VALUES (?, ?, ?)").run(
509+
"fusion",
510+
"fusion-opus-swe",
511+
time / 1000,
512+
);
513+
const insert = db.prepare(
514+
"INSERT INTO message_nodes (session_id, node_id, chat_message, created_at) VALUES (?, ?, ?, ?)",
515+
);
516+
const models = [
517+
"claude-opus-5-5-medium",
518+
"claude-opus-5-5-medium",
519+
"swe-2-high",
520+
"compactor",
521+
];
522+
for (const [index, model] of models.entries()) {
523+
insert.run(
524+
"fusion",
525+
index,
526+
encodeUnknownJsonString({
527+
role: "assistant",
528+
metadata: {
529+
request_id: index < 2 ? "opus-request" : `request-${index}`,
530+
generation_model: model,
531+
created_at: "2026-08-01T10:00:00Z",
532+
metrics: {
533+
input_tokens: 100,
534+
output_tokens: 20,
535+
cache_read_tokens: 300,
536+
cache_creation_tokens: 50,
537+
},
538+
},
539+
}),
540+
time / 1000,
541+
);
542+
}
543+
yield* Effect.gen(function* () {
544+
const service = yield* UsageService.make.pipe(
545+
Effect.provideService(DevinUsage.DevinUsage, {
546+
history: ({ dir, sinceMs }) =>
547+
DevinUsage.readDevinUsage({ dir, sinceMs }).pipe(
548+
Effect.map((read) => read.result),
549+
Effect.provide(NodeServices.layer),
550+
),
551+
awaitPersisted: Effect.void,
552+
prices: () =>
553+
Effect.succeed(
554+
DevinUsage.parseDevinModelRates({
555+
families: [
556+
{
557+
variants: [
558+
{
559+
model_uid: "claude-opus-5-5-medium",
560+
cost_summary: "$4 / 1M Input · $0.2 / 1M Cached input · $20 / 1M Output",
561+
},
562+
{ model_uid: "swe-2-high", cost_tier: "Free" },
563+
],
564+
},
565+
],
566+
}),
567+
),
568+
}),
569+
);
570+
const summary = yield* service.readSummary(WINDOW);
571+
const buckets = summary.buckets.filter((bucket) => bucket.provider === "devin");
572+
assert.strictEqual(buckets.length, 3);
573+
const lead = buckets.find((bucket) => bucket.model === "claude-opus-5-5-medium");
574+
assert.strictEqual(lead?.records, 1);
575+
assert.strictEqual(lead?.costSource, "modelPriced");
576+
assert.strictEqual(totalTokens(lead!.totals), 470);
577+
assert.closeTo(lead?.costUsd ?? NaN, 0.00106, 1e-12);
578+
assert.strictEqual(
579+
buckets.find((bucket) => bucket.model === "swe-2-high")?.unpricedRecords,
580+
0,
581+
);
582+
assert.strictEqual(
583+
buckets.find((bucket) => bucket.model === "compactor")?.unpricedRecords,
584+
1,
585+
);
586+
const sources = summary.sources.filter((source) => source.fingerprint.provider === "devin");
587+
assert.strictEqual(sources.length, 1);
588+
assert.strictEqual(sources[0]?.distinctSessions, 1);
589+
const settingsService = yield* ServerSettings.ServerSettingsService;
590+
yield* settingsService.updateSettings({
591+
usagePriceOverrides: {
592+
"claude-opus-5-5-medium": {
593+
inputCostPerMillionTokens: 2,
594+
outputCostPerMillionTokens: 5,
595+
cacheReadCostPerMillionTokens: 0.1,
596+
cacheWriteCostPerMillionTokens: 3,
597+
},
598+
},
599+
});
600+
const repriced = (yield* service.readSummary(WINDOW)).buckets.find(
601+
(bucket) => bucket.provider === "devin" && bucket.model === "claude-opus-5-5-medium",
602+
);
603+
assert.closeTo(repriced?.costUsd ?? NaN, 0.00048, 1e-12);
604+
}).pipe(
605+
Effect.provide(
606+
layerService({
607+
prefix: "usage-devin",
608+
home,
609+
settings: {
610+
...settings,
611+
providerInstances: {
612+
...settings.providerInstances,
613+
[ProviderInstanceId.make("devin-one")]: {
614+
driver: ProviderDriverKind.make("acpRegistry"),
615+
config: { agentId: "devin" },
616+
},
617+
[ProviderInstanceId.make("devin-disabled")]: {
618+
driver: ProviderDriverKind.make("acpRegistry"),
619+
config: { agentId: "devin" },
620+
enabled: false,
621+
},
622+
},
623+
},
624+
environment: { XDG_DATA_HOME: dataHome },
625+
ratesDocument: {
626+
"claude-opus-5-5-medium": { input_cost_per_token: 1, output_cost_per_token: 2 },
627+
},
628+
}),
629+
),
630+
);
631+
}).pipe(Effect.scoped),
632+
);
633+
490634
it.live("counts compressed Codex rollouts across refresh, rewrites, and cache restarts", () =>
491635
Effect.gen(function* () {
492636
const { home, settings } = yield* setup;

‎apps/server/src/usage/UsageService.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type {
3838
ProviderUsageInstance,
3939
TranscriptUsageFormat,
4040
UsageRecord,
41+
UsageTokenRates,
4142
} from "@t3tools/provider-core/server/usage";
4243
import { canonicalModelFilter, resolveModelAliases, UsageAggregator } from "./usageAggregation.ts";
4344
import { createOverrideRateTable, parseRateTable, type RateTable } from "./usagePricing.ts";
@@ -554,6 +555,7 @@ export const make = Effect.gen(function* () {
554555
}[]
555556
| null;
556557
readonly refreshing?: true;
558+
readonly modelRates?: ReadonlyMap<string, UsageTokenRates>;
557559
}
558560

559561
const scanTranscriptDir = Effect.fn("UsageService.scanTranscriptDir")(function* (
@@ -715,13 +717,20 @@ export const make = Effect.gen(function* () {
715717
{ concurrency: 2 },
716718
);
717719

720+
const providerRates = scannedDirs.flatMap((source) =>
721+
Array.from(
722+
source.modelRates ?? [],
723+
([model, rate]) => [model, { ...rate, fast: null, ultrafast: null }] as const,
724+
),
725+
);
726+
const scanRates = providerRates.length === 0 ? rates : new Map([...rates, ...providerRates]);
718727
const aggregator = new UsageAggregator({
719728
timeZone: input.timeZone,
720729
sinceDay: input.sinceDay,
721730
untilDay: input.untilDay,
722731
resolution: input.resolution ?? "day",
723732
...hourlyWindow,
724-
rates,
733+
rates: scanRates,
725734
priceOverrides: createOverrideRateTable(settings.usagePriceOverrides),
726735
modelAliases: resolveModelAliases(settings.usageModelAliases),
727736
...(input.modelFilter === undefined ? {} : { modelFilter: input.modelFilter }),

‎apps/server/src/usage/usagePricing.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ import type {
55
UsageTokenTotals,
66
} from "@t3tools/contracts";
77

8-
import type { UsageRecord, UsageSpeed } from "@t3tools/provider-core/server/usage";
8+
import type { UsageRecord, UsageSpeed, UsageTokenRates } from "@t3tools/provider-core/server/usage";
99

10-
export interface TokenRates {
11-
readonly inputCostPerToken: number;
12-
readonly outputCostPerToken: number;
13-
readonly cacheReadCostPerToken: number;
14-
readonly cacheCreationCostPerToken: number;
15-
}
10+
export type TokenRates = UsageTokenRates;
1611

1712
/** Omits LiteLLM's above_272k_tokens, flex and batches variants, which transcripts do not record. */
1813
export interface ModelRate extends TokenRates {

‎apps/web/src/components/usage/UsagePage.tsx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { primaryServerKeybindingsAtom, serverEnvironment } from "../../state/ser
4242
import { isCommandPaletteOpen } from "../../commandPaletteBus";
4343
import { isModelPickerOpen } from "../../modelPickerVisibility";
4444
import { shortcutLabelForCommand } from "../../keybindings";
45+
import { observeVisibleAnimation } from "~/lib/visibleAnimation";
4546
import { useUsage, type EnvironmentUsageStatus } from "../../state/usage";
4647
import { useAtomCommand } from "../../state/use-atom-command";
4748
import {
@@ -60,6 +61,7 @@ import {
6061
} from "@t3tools/shared/usageFormat";
6162
import { Button, InlineButton } from "../ui/button";
6263
import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
64+
import { ActivityShimmerOverlay } from "../chat/TimelineRowParts";
6365
import {
6466
Menu,
6567
MenuCheckboxItem,
@@ -769,7 +771,20 @@ function UsageOverview({
769771
/>
770772
<ProviderMark provider={provider} className="size-4" />
771773
<span className="flex min-w-0 items-baseline gap-1.5">
772-
<span className="truncate">{PROVIDER_PRESENTATION[provider].label}</span>
774+
<span
775+
ref={providerLoading ? observeVisibleAnimation : undefined}
776+
className={cn(
777+
"relative truncate",
778+
providerLoading && "text-muted-foreground",
779+
)}
780+
>
781+
{PROVIDER_PRESENTATION[provider].label}
782+
{providerLoading ? (
783+
<ActivityShimmerOverlay>
784+
{PROVIDER_PRESENTATION[provider].label}
785+
</ActivityShimmerOverlay>
786+
) : null}
787+
</span>
773788
<span
774789
className={cn(
775790
"shrink-0 whitespace-nowrap text-2xs text-muted-foreground tabular-nums",
@@ -1212,6 +1227,7 @@ function ProviderMark({
12121227
return (
12131228
<ProviderInstanceIcon
12141229
driverKind={presentation.driverKind}
1230+
{...(provider === "devin" ? { acpRegistryAgentId: "devin" } : {})}
12151231
displayName={presentation.label}
12161232
iconClassName={className}
12171233
/>

‎apps/web/src/components/usage/UsageProviderChart.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ describe("buildPeriodColumns", () => {
99
"2026-08-01",
1010
{
1111
day: "2026-08-01",
12-
costUsd: 42,
13-
totalTokens: 420,
12+
costUsd: 45,
13+
totalTokens: 450,
1414
byProvider: new Map([
1515
["codex" as const, { costUsd: 10, totalTokens: 100 }],
1616
["claude" as const, { costUsd: 20, totalTokens: 200 }],
1717
["pi" as const, { costUsd: 5, totalTokens: 50 }],
1818
["muse" as const, { costUsd: 7, totalTokens: 70 }],
19+
["devin" as const, { costUsd: 3, totalTokens: 30 }],
1920
]),
2021
},
2122
],
@@ -42,6 +43,7 @@ describe("buildPeriodColumns", () => {
4243
{ provider: "antigravity", value: 0 },
4344
{ provider: "pi", value: 5 },
4445
{ provider: "muse", value: 7 },
46+
{ provider: "devin", value: 3 },
4547
]);
4648
});
4749
});

‎apps/web/src/components/usage/usageProviders.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export const PROVIDER_PRESENTATION = {
4545
color: "#0866ff",
4646
driverKind: ProviderDriverKind.make("muse"),
4747
},
48+
devin: {
49+
label: "Devin",
50+
color: "#5e9ce6",
51+
driverKind: ProviderDriverKind.make("acpRegistry"),
52+
},
4853
} satisfies Record<UsageProviderKind, UsageProviderPresentation>;
4954

5055
export const PROVIDER_ORDER = Object.keys(PROVIDER_PRESENTATION) as UsageProviderKind[];

‎docs/user/usage.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ On mobile, choose **Usage** in the workspace navigation.
88

99
## Understand your usage
1010

11-
**Usage** combines Codex, Claude Code, Grok Build, OpenCode, Antigravity, Pi, Muse Code, and Cursor history
11+
**Usage** combines Codex, Claude Code, Grok Build, OpenCode, Antigravity, Pi, Muse Code, Devin, and Cursor history
1212
from your connected environments. It shows token use, cache savings, model breakdowns, and estimated API-equivalent
1313
cost, split by token type and by speed. These estimates are not your subscription bill.
1414
**Premium** is what Fast and Ultrafast requests cost above standard rates. Cost that cannot be
@@ -46,6 +46,14 @@ Use absolute paths or `~/` paths in the account's environment settings; relative
4646
depend on each project's working directory and cannot be reliably discovered by Usage. Accounts
4747
sharing a history directory count once.
4848

49+
Devin reads saved CLI history, including both models in Fusion sessions. Costs use the model prices
50+
reported by the installed Devin CLI. Models without a known price still contribute tokens and show
51+
as unpriced; set custom prices to estimate their cost. These estimates do not measure your remaining
52+
subscription allowance. Devin follows `XDG_DATA_HOME`, or `%APPDATA%` on Windows, for its history directory.
53+
The first read of a large Devin history can take a few minutes. Totals appear as sessions finish
54+
and stay marked as updating until the scan completes. T3 Code saves completed sessions during the
55+
scan, so refreshes and restarts reuse that progress and read only new messages.
56+
4957
The server saves its first hostname in `<T3 home>/usage-host-id`, so a recreated container keeps
5058
its usage identity when T3 home is persisted. Set `T3CODE_HOST_ID` to choose the identity
5159
explicitly.
@@ -103,7 +111,7 @@ To count only some models, or to leave some out, add `usageModelFilter` to the s
103111
```
104112

105113
`include` keeps only the listed models and `exclude` leaves the listed models out. `provider` is
106-
one of `claude`, `codex`, `cursor`, `grok`, `opencode`, `antigravity`, `pi`, or `muse`; omit it
114+
one of `claude`, `codex`, `cursor`, `grok`, `opencode`, `antigravity`, `pi`, `muse`, or `devin`; omit it
107115
to match a model ID from any provider. Use the model ID that Usage shows without **Map to**, such
108116
as a provider-prefixed ID for Pi. Filters apply before **Map to**, so a model you leave out is not
109117
counted under its mapped name. Usage applies each environment's own filter. Remove the setting to

0 commit comments

Comments
 (0)