File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ export const defaultStaleTTL = 7 * 24 * 60 * 60 * 1000
2020export const defaultContextLimit = 128_000
2121export const defaultOutputLimit = 32_000
2222
23+ export function resolveStateDirectory ( home : string , environment : NodeJS . ProcessEnv = process . env ) {
24+ return (
25+ environment [ stateDirectoryEnvironment ] ??
26+ environment . COPILOT_BRIDGE_STATE_DIR ??
27+ path . join ( home , ".copilot" , "opencode-copilot-bridge-state" )
28+ )
29+ }
30+
2331export class InvalidURLError extends Schema . TaggedErrorClass < InvalidURLError > ( ) ( "CopilotBridge.InvalidURL" , {
2432 url : Schema . String ,
2533 message : Schema . String ,
@@ -308,15 +316,7 @@ export function config(stateDirectory: string): Config {
308316
309317export const configLayer = Layer . effect (
310318 ConfigService ,
311- Global . Service . use ( ( global ) =>
312- Effect . succeed (
313- config (
314- process . env [ stateDirectoryEnvironment ] ??
315- process . env . COPILOT_BRIDGE_STATE_DIR ??
316- path . join ( global . state , "copilot-bridge" ) ,
317- ) ,
318- ) ,
319- ) ,
319+ Global . Service . use ( ( global ) => Effect . succeed ( config ( resolveStateDirectory ( global . home ) ) ) ) ,
320320)
321321
322322export const configNode = makeGlobalNode ( {
Original file line number Diff line number Diff line change @@ -52,6 +52,23 @@ async function fixture(fetch: (request: Request) => Response | Promise<Response>
5252}
5353
5454describe ( "CopilotBridge descriptor authentication" , ( ) => {
55+ test ( "resolves the durable state directory for normal desktop launches" , ( ) => {
56+ expect ( CopilotBridge . resolveStateDirectory ( "/Users/test" , { } ) ) . toBe (
57+ "/Users/test/.copilot/opencode-copilot-bridge-state" ,
58+ )
59+ expect (
60+ CopilotBridge . resolveStateDirectory ( "/Users/test" , {
61+ OPENCODE_COPILOT_BRIDGE_STATE_DIR : "/private/opencode" ,
62+ COPILOT_BRIDGE_STATE_DIR : "/private/bridge" ,
63+ } ) ,
64+ ) . toBe ( "/private/opencode" )
65+ expect (
66+ CopilotBridge . resolveStateDirectory ( "/Users/test" , {
67+ COPILOT_BRIDGE_STATE_DIR : "/private/bridge" ,
68+ } ) ,
69+ ) . toBe ( "/private/bridge" )
70+ } )
71+
5572 test ( "accepts only literal HTTP loopback /v1 endpoints" , ( ) => {
5673 expect ( CopilotBridge . baseURL ( "http://127.0.0.1:4142/v1/" ) ) . toBe ( "http://127.0.0.1:4142/v1" )
5774 expect ( ( ) => CopilotBridge . baseURL ( "https://127.0.0.1:4142/v1" ) ) . toThrow ( )
You can’t perform that action at this time.
0 commit comments