@@ -15,6 +15,7 @@ import * as ServerConfig from "../config.ts";
1515import { resolveBaseDir } from "../os-jank.ts" ;
1616import { buildTriageLaunchPrompt } from "../triage/triagePrompt.ts" ;
1717import { describeServerProcess , writeTriageSession } from "../triage/triageSession.ts" ;
18+ import { RECOVERY_MANUAL_INSTRUCTIONS } from "../triage/recoveryPrompt.ts" ;
1819import { baseDirFlag } from "./config.ts" ;
1920import { interactiveStdin } from "./consoleStdin.ts" ;
2021import { resolveCliCommand } from "./invocation.ts" ;
@@ -57,7 +58,7 @@ export class TriageAgentSpawnError extends Schema.TaggedError<TriageAgentSpawnEr
5758 }
5859}
5960
60- const pickAgent = ( agents : ReadonlyArray < TriageAgent > ) =>
61+ const pickAgent = ( agents : ReadonlyArray < TriageAgent > , command : "triage" | "unfuck" ) =>
6162 Effect . promise ( async ( ) => {
6263 const readline = NodeReadlinePromises . createInterface ( {
6364 input : process . stdin ,
@@ -68,7 +69,7 @@ const pickAgent = (agents: ReadonlyArray<TriageAgent>) =>
6869 . map ( ( agent , index ) => ` [${ String ( index + 1 ) } ] ${ agent . label } ` )
6970 . join ( "\n" ) ;
7071 for ( ; ; ) {
71- const answer = ( await readline . question ( `Run triage with:\n${ menu } \n> ` ) ) . trim ( ) ;
72+ const answer = ( await readline . question ( `Run ${ command } with:\n${ menu } \n> ` ) ) . trim ( ) ;
7273 const byNumber = agents [ Number . parseInt ( answer , 10 ) - 1 ] ;
7374 if ( byNumber !== undefined ) {
7475 return byNumber ;
@@ -112,85 +113,93 @@ const modelFlag = Flag.String("model").pipe(
112113 Flag . optional ,
113114) ;
114115
115- export const triageCommand = Command . make ( "triage" , {
116- baseDir : baseDirFlag ,
117- agent : agentFlag ,
118- model : modelFlag ,
119- } ) . pipe (
120- Command . withDescription (
121- "Investigate a T3 Code problem on this machine with claude or codex, and help file a good issue." ,
122- ) ,
123- Command . withHandler ( ( flags ) =>
124- Effect . gen ( function * ( ) {
125- // Triage is a user-facing feature: always the userdata state, never dev.
126- const explicitBaseDir = Option . getOrUndefined ( flags . baseDir ) ;
127- const envHome = yield * Config . String ( "T3CODE_HOME" ) . pipe ( Config . option ) ;
128- const baseDir = yield * resolveBaseDir ( explicitBaseDir ?? Option . getOrUndefined ( envHome ) ) ;
129- const paths = yield * ServerConfig . deriveServerPaths ( baseDir , undefined , { } ) ;
130-
131- const session = yield * writeTriageSession ( {
132- baseDir,
133- paths,
134- entry : {
135- kind : "cli" ,
136- cliVersion : packageJson . version ,
137- launchedAs : yield * resolveCliCommand ( "triage" ) ,
138- } ,
139- server : yield * describeServerProcess ( paths . serverRuntimeStatePath ) ,
140- } ) ;
141-
142- const installed : Array < TriageAgent > = [ ] ;
143- for ( const agent of TRIAGE_AGENTS ) {
144- if ( yield * isCommandAvailable ( agent . command ) ) {
145- installed . push ( agent ) ;
116+ const makeSupportCommand = ( command : "triage" | "unfuck" ) =>
117+ Command . make ( command , {
118+ baseDir : baseDirFlag ,
119+ agent : agentFlag ,
120+ model : modelFlag ,
121+ } ) . pipe (
122+ Command . withDescription (
123+ command === "unfuck"
124+ ? "Recover a broken T3 Code install with guided update instructions in claude or codex."
125+ : "Investigate a T3 Code problem on this machine with claude or codex, and help file a good issue." ,
126+ ) ,
127+ Command . withHandler ( ( flags ) =>
128+ Effect . gen ( function * ( ) {
129+ // Support commands inspect the installed userdata state, never dev.
130+ const explicitBaseDir = Option . getOrUndefined ( flags . baseDir ) ;
131+ const envHome = yield * Config . String ( "T3CODE_HOME" ) . pipe ( Config . option ) ;
132+ const baseDir = yield * resolveBaseDir ( explicitBaseDir ?? Option . getOrUndefined ( envHome ) ) ;
133+ const paths = yield * ServerConfig . deriveServerPaths ( baseDir , undefined , { } ) ;
134+
135+ const session = yield * writeTriageSession ( {
136+ command,
137+ baseDir,
138+ paths,
139+ entry : {
140+ kind : "cli" ,
141+ cliVersion : packageJson . version ,
142+ launchedAs : yield * resolveCliCommand ( command ) ,
143+ } ,
144+ server : yield * describeServerProcess ( paths . serverRuntimeStatePath ) ,
145+ } ) ;
146+
147+ const installed : Array < TriageAgent > = [ ] ;
148+ for ( const agent of TRIAGE_AGENTS ) {
149+ if ( yield * isCommandAvailable ( agent . command ) ) {
150+ installed . push ( agent ) ;
151+ }
146152 }
147- }
148153
149- const requested = Option . getOrUndefined ( flags . agent ) ;
150- let selected : TriageAgent | undefined ;
151- if ( requested !== undefined ) {
152- selected = installed . find ( ( agent ) => agent . id === requested ) ;
153- if ( selected === undefined ) {
154- return yield * new TriageAgentUnavailableError ( { agent : requested } ) ;
154+ const requested = Option . getOrUndefined ( flags . agent ) ;
155+ let selected : TriageAgent | undefined ;
156+ if ( requested !== undefined ) {
157+ selected = installed . find ( ( agent ) => agent . id === requested ) ;
158+ if ( selected === undefined ) {
159+ return yield * new TriageAgentUnavailableError ( { agent : requested } ) ;
160+ }
161+ } else if ( installed . length === 1 ) {
162+ selected = installed [ 0 ] ;
163+ } else if ( installed . length > 1 ) {
164+ // The picker needs terminal output too, or its invisible prompt hangs.
165+ if ( ! process . stdin . isTTY || ! process . stdout . isTTY ) {
166+ return yield * new TriageAgentChoiceRequiredError ( ) ;
167+ }
168+ selected = yield * pickAgent ( installed , command ) ;
155169 }
156- } else if ( installed . length === 1 ) {
157- selected = installed [ 0 ] ;
158- } else if ( installed . length > 1 ) {
159- // The picker needs terminal output too, or its invisible prompt hangs.
160- if ( ! process . stdin . isTTY || ! process . stdout . isTTY ) {
161- return yield * new TriageAgentChoiceRequiredError ( ) ;
170+
171+ // Windows .cmd shims cannot carry multiline argv; the prompt file also serves as the paste fallback.
172+ const { sessionDir, promptFilePath, contextFilePath } = session ;
173+
174+ if ( selected === undefined ) {
175+ yield * Console . log (
176+ [
177+ "No supported agent CLI (claude, codex) was found on this machine." ,
178+ "" ,
179+ `The ${ command } prompt and machine context were written to:` ,
180+ ` ${ promptFilePath } ` ,
181+ ` ${ contextFilePath } ` ,
182+ "" ,
183+ `Paste the prompt file into any coding agent to run ${ command } by hand.` ,
184+ ...( command === "unfuck" ? [ "" , RECOVERY_MANUAL_INSTRUCTIONS ] : [ ] ) ,
185+ ] . join ( "\n" ) ,
186+ ) ;
187+ return ;
162188 }
163- selected = yield * pickAgent ( installed ) ;
164- }
165189
166- // Windows .cmd shims cannot carry multiline argv; the prompt file also serves as the paste fallback.
167- const { sessionDir, promptFilePath, contextFilePath } = session ;
168-
169- if ( selected === undefined ) {
170- yield * Console . log (
171- [
172- "No supported agent CLI (claude, codex) was found on this machine." ,
173- "" ,
174- "The triage prompt and machine context were written to:" ,
175- ` ${ promptFilePath } ` ,
176- ` ${ contextFilePath } ` ,
177- "" ,
178- "Paste the prompt file into any coding agent to run triage by hand." ,
179- ] . join ( "\n" ) ,
180- ) ;
181- return ;
182- }
190+ const model = Option . getOrUndefined ( flags . model ) ;
191+ const spawnSpec = yield * resolveSpawnCommand ( selected . command , [
192+ ...( model === undefined ? [ ] : [ "--model" , model ] ) ,
193+ buildTriageLaunchPrompt ( promptFilePath , command ) ,
194+ ] ) ;
195+ yield * Console . log ( `Starting ${ selected . label } . It will ask what went wrong.\n` ) ;
196+ const exitCode = yield * runInteractiveSession ( { ...spawnSpec , cwd : sessionDir } ) ;
197+ if ( exitCode !== 0 ) {
198+ process . exitCode = exitCode ;
199+ }
200+ } ) ,
201+ ) ,
202+ ) ;
183203
184- const model = Option . getOrUndefined ( flags . model ) ;
185- const spawnSpec = yield * resolveSpawnCommand ( selected . command , [
186- ...( model === undefined ? [ ] : [ "--model" , model ] ) ,
187- buildTriageLaunchPrompt ( promptFilePath ) ,
188- ] ) ;
189- yield * Console . log ( `Starting ${ selected . label } . It will ask what went wrong.\n` ) ;
190- const exitCode = yield * runInteractiveSession ( { ...spawnSpec , cwd : sessionDir } ) ;
191- if ( exitCode !== 0 ) {
192- process . exitCode = exitCode ;
193- }
194- } ) ,
195- ) ,
196- ) ;
204+ export const triageCommand = makeSupportCommand ( "triage" ) ;
205+ export const unfuckCommand = makeSupportCommand ( "unfuck" ) ;
0 commit comments