@@ -2,15 +2,14 @@ import * as Config from "effect/Config";
22import * as Layer from "effect/Layer" ;
33import * as Path from "effect/Path" ;
44import { FetchHttpClient } from "effect/http" ;
5- import * as Console from "effect/Console" ;
65import * as Effect from "effect/Effect" ;
76import * as Option from "effect/Option" ;
87import { Command , Flag , Prompt } from "effect/cli" ;
98
109import packageJson from "../../package.json" with { type : "json" } ;
1110import * as BootService from "../cloud/bootService.ts" ;
1211import * as ProcessRunner from "../processRunner.ts" ;
13- import { createDoctorProgress } from "./doctorProgress.ts" ;
12+ import { createDoctorProgress , doctorEmphasis } from "./doctorProgress.ts" ;
1413import { baseDirFlag } from "./config.ts" ;
1514import { resolveBaseDir } from "../os-jank.ts" ;
1615import * as DatabaseMaintenance from "../persistence/DatabaseMaintenance.ts" ;
@@ -20,15 +19,18 @@ export interface DoctorRepair {
2019 readonly title : string ;
2120 readonly description : string ;
2221 readonly recommended : boolean ;
22+ readonly details : ReadonlyArray < string > ;
2323}
2424
2525export const chooseDoctorRepairs = ( repairs : ReadonlyArray < DoctorRepair > ) =>
2626 Prompt . run (
2727 Prompt . MultiSelect ( {
28- message : "Choose repairs to run (Space toggles, Enter starts; Ctrl+C cancels)" ,
28+ message : "Choose repairs to run" ,
29+ selectAll : "Select all" ,
30+ selectNone : "Select none" ,
31+ inverseSelection : "Invert selection" ,
2932 choices : repairs . map ( ( repair ) => ( {
30- title : repair . title + ( repair . recommended ? " (recommended)" : "" ) ,
31- description : repair . description ,
33+ title : doctorEmphasis ( repair . title ) + ( repair . recommended ? " · Recommended" : "" ) ,
3234 value : repair . id ,
3335 selected : repair . recommended ,
3436 } ) ) ,
@@ -42,60 +44,53 @@ export const runDoctor = Effect.fn("runDoctor")(function* (
4244) {
4345 const maintenance = yield * DatabaseMaintenance . DatabaseMaintenance ;
4446 const status = yield * maintenance . inspect ( directory ) ;
45- const gib = ( bytes : number ) => ( bytes / 1024 ** 3 ) . toFixed ( 2 ) ;
46- yield * Console . log (
47- `Database: ${ gib ( status . databaseBytes ) } GiB; reusable space: ${ gib ( status . reclaimableBytes ) } GiB.` ,
48- ) ;
47+ const progress = createDoctorProgress ( ) ;
48+ progress . intro ( status . databaseBytes , status . reclaimableBytes ) ;
4949 const repairs : ReadonlyArray < DoctorRepair > =
5050 status . incrementalVacuumEnabled && status . reclaimableBytes === 0
5151 ? [ ]
5252 : [
5353 {
5454 id : "database" ,
5555 title : "Reclaim database space" ,
56- description :
57- "Compact history and enable automatic shrinking. Pauses the background service; may take several minutes and needs temporary disk space." ,
56+ description : "Frees unused database space and enables automatic shrinking." ,
57+ details : [
58+ "Pauses the background service. May take several minutes." ,
59+ "Requires temporary free disk space." ,
60+ ] ,
5861 recommended : ! status . incrementalVacuumEnabled || status . reclaimableBytes >= 1024 ** 3 ,
5962 } ,
6063 ] ;
6164 if ( repairs . length === 0 ) {
62- yield * Console . log ( " No repairs available .") ;
65+ progress . note ( "Everything looks good. No repairs needed .") ;
6366 return ;
6467 }
65- for ( const repair of repairs ) {
66- yield * Console . log (
67- `${ repair . recommended ? "[recommended]" : "[optional]" } ${ repair . title } : ${ repair . description } ` ,
68- ) ;
69- }
68+ progress . repairs ( repairs ) ;
7069 if ( options . dryRun ) {
71- yield * Console . log ( "Dry run: no repairs applied and no services stopped ." ) ;
70+ progress . note ( "Dry run complete. No changes made ." ) ;
7271 return ;
7372 }
7473 const interactive = options . interactive ?? Boolean ( process . stdin . isTTY && process . stdout . isTTY ) ;
7574 if ( ! options . fix && ! interactive ) {
76- yield * Console . log (
77- "Run t3 doctor in a terminal to choose repairs, or use --fix to apply the recommended set." ,
78- ) ;
75+ progress . note ( "Run in a terminal to choose repairs, or use --fix for the recommended set." ) ;
7976 return ;
8077 }
78+ if ( ! options . fix ) progress . note ( "↑/↓ Move Space Select Enter Run Ctrl+C Cancel" ) ;
8179 const selected = options . fix
8280 ? repairs . filter ( ( repair ) => repair . recommended ) . map ( ( repair ) => repair . id )
8381 : yield * chooseRepairs ( repairs ) . pipe ( Effect . catchTags ( { QuitError : ( ) => Effect . succeed ( [ ] ) } ) ) ;
8482 if ( selected . length === 0 ) {
85- yield * Console . log ( "No repairs selected." ) ;
83+ progress . note ( "No repairs selected. No changes made ." ) ;
8684 return ;
8785 }
8886 const service = yield * BootService . BootService ;
89- const progress = createDoctorProgress ( ) ;
87+ progress . start ( ) ;
9088 const report = ( stage : Parameters < typeof progress . report > [ 0 ] ) =>
9189 Effect . sync ( ( ) => progress . report ( stage ) ) ;
9290 const result = yield * service
9391 . withStopped ( maintenance . compact ( directory , report ) , report )
9492 . pipe ( Effect . ensuring ( Effect . sync ( progress . finish ) ) ) ;
95- progress . complete ( ) ;
96- yield * Console . log (
97- `Removed ${ result . deletedEventCount } events and ${ result . deletedReceiptCount } receipts. Database: ${ gib ( result . beforeBytes ) } → ${ gib ( result . afterBytes ) } GiB.` ,
98- ) ;
93+ progress . complete ( result . beforeBytes , result . afterBytes ) ;
9994} ) ;
10095
10196export const doctorCommand = Command . make ( "doctor" , {
0 commit comments