Ver Fonte

fix(opencode): avoid org lookup during config startup (#22670)

Kit Langton há 2 dias atrás
pai
commit
672ee28635
2 ficheiros alterados com 11 adições e 35 exclusões
  1. 0 26
      AGENTS.md
  2. 11 9
      packages/opencode/src/config/config.ts

+ 0 - 26
AGENTS.md

@@ -11,36 +11,10 @@
 - Keep things in one function unless composable or reusable
 - Avoid `try`/`catch` where possible
 - Avoid using the `any` type
-- Prefer single word variable names where possible
 - Use Bun APIs when possible, like `Bun.file()`
 - Rely on type inference when possible; avoid explicit type annotations or interfaces unless necessary for exports or clarity
 - Prefer functional array methods (flatMap, filter, map) over for loops; use type guards on filter to maintain type inference downstream
 
-### Naming
-
-Prefer single word names for variables and functions. Only use multiple words if necessary.
-
-### Naming Enforcement (Read This)
-
-THIS RULE IS MANDATORY FOR AGENT WRITTEN CODE.
-
-- Use single word names by default for new locals, params, and helper functions.
-- Multi-word names are allowed only when a single word would be unclear or ambiguous.
-- Do not introduce new camelCase compounds when a short single-word alternative is clear.
-- Before finishing edits, review touched lines and shorten newly introduced identifiers where possible.
-- Good short names to prefer: `pid`, `cfg`, `err`, `opts`, `dir`, `root`, `child`, `state`, `timeout`.
-- Examples to avoid unless truly required: `inputPID`, `existingClient`, `connectTimeout`, `workerPath`.
-
-```ts
-// Good
-const foo = 1
-function journal(dir: string) {}
-
-// Bad
-const fooBar = 1
-function prepareJournal(dir: string) {}
-```
-
 Reduce total variable count by inlining when a value is only used once.
 
 ```ts

+ 11 - 9
packages/opencode/src/config/config.ts

@@ -1277,7 +1277,7 @@ export namespace Config {
         return yield* cachedGlobal
       })
 
-      const install = Effect.fnUntraced(function* (dir: string) {
+      const install = Effect.fn("Config.install")(function* (dir: string) {
         const pkg = path.join(dir, "package.json")
         const gitignore = path.join(dir, ".gitignore")
         const plugin = path.join(dir, "node_modules", "@opencode-ai", "plugin", "package.json")
@@ -1345,7 +1345,7 @@ export namespace Config {
         )
       })
 
-      const loadInstanceState = Effect.fnUntraced(function* (ctx: InstanceContext) {
+      const loadInstanceState = Effect.fn("Config.loadInstanceState")(function* (ctx: InstanceContext) {
         const auth = yield* authSvc.all().pipe(Effect.orDie)
 
         let result: Info = {}
@@ -1468,13 +1468,16 @@ export namespace Config {
           log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
         }
 
-        const activeOrg = Option.getOrUndefined(
-          yield* accountSvc.activeOrg().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
+        const activeAccount = Option.getOrUndefined(
+          yield* accountSvc.active().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
         )
-        if (activeOrg) {
+        if (activeAccount?.active_org_id) {
+          const accountID = activeAccount.id
+          const orgID = activeAccount.active_org_id
+          const url = activeAccount.url
           yield* Effect.gen(function* () {
             const [configOpt, tokenOpt] = yield* Effect.all(
-              [accountSvc.config(activeOrg.account.id, activeOrg.org.id), accountSvc.token(activeOrg.account.id)],
+              [accountSvc.config(accountID, orgID), accountSvc.token(accountID)],
               { concurrency: 2 },
             )
             if (Option.isSome(tokenOpt)) {
@@ -1482,10 +1485,8 @@ export namespace Config {
               yield* env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
             }
 
-            activeOrgName = activeOrg.org.name
-
             if (Option.isSome(configOpt)) {
-              const source = `${activeOrg.account.url}/api/config`
+              const source = `${url}/api/config`
               const next = yield* loadConfig(JSON.stringify(configOpt.value), {
                 dir: path.dirname(source),
                 source,
@@ -1496,6 +1497,7 @@ export namespace Config {
               yield* merge(source, next, "global")
             }
           }).pipe(
+            Effect.withSpan("Config.loadActiveOrgConfig"),
             Effect.catch((err) => {
               log.debug("failed to fetch remote account config", {
                 error: err instanceof Error ? err.message : String(err),