refactor(oauth): consolidate as unknown as casts in OAuth wiring (patch)#153
Merged
liplus-lin-lay merged 1 commit intoMay 25, 2026
Conversation
src/index.ts に 6 箇所散在していた `as unknown as` キャストを
src/oauth.ts 境界に集約。 call site は cast-free な helper / generic
呼び出しに置換し、 型システムの escape hatch を 1 ファイルに局所化した。
挙動変更なし (refactor のみ)。 tsc --noEmit と wrangler deploy
--dry-run の両方が pass。
変更:
- src/oauth.ts:
- 新 export type McpProps (RagMcpAgentV2 が消費する props shape)
- 新 export helper readGitHubProps / writeMcpProps / readOAuthHelpers
(ctx / env への OAuthProvider injected プロパティ読み書きを集約)
- 新 export interface OAuthWrappedHandler<TEnv> (caller の Env 型を
そのまま返す wrapper の型)
- createOAuthProvider を <TEnv extends OAuthEnv> generic 化し、 library 側
の OAuthEnv & Record<string, unknown> 制約を関数内に閉じ込めた
- src/types.ts:
- Env を interface Env extends OAuthEnv 化。 OAUTH_KV / GITHUB_CLIENT_ID
/ GITHUB_CLIENT_SECRET は extends 経由で継承
- src/index.ts:
- L130 / L137 / L149 / L157 / L174 / L179 の 6 `as unknown as` を
helper 呼び出し / generic 推論で全削除
scope 外 (別 issue 候補):
- src/mcp.ts L719 (Vectorize metadata cast — library 型定義不足)
- src/rerank.ts L157 (Workers AI response cast — library 型定義不足)
Closes #148
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
github-rag-mcp | 777edc5 | May 25 2026, 01:11 AM |
liplus-lin-lay
commented
May 25, 2026
Member
Author
liplus-lin-lay
left a comment
There was a problem hiding this comment.
AI self-review (auto mode)
分類確認
- refactor 100%、 挙動変更ゼロ
tsc --noEmitclean、wrangler deploy --dry-run成功- 型 surface は
createOAuthProviderの signature が generic 化されたが、 caller は内部 (src/index.ts) のみで外部依存なし - → patch 維持
brake 確認
- 本 PR は L3 Task Layer (USER_REPO) スコープなので Evolution_Initiator_Autonomy brake 2 (L1 Model Layer 限定) 不適用
- parallel-subagent-eval 軸 (brake 1) も Evolution_Initiator path 限定なので user repo の auto モード refactor では適用外、 self-review + CI で gate
diff 自己確認
src/oauth.ts:- GitHubUserProps export 既存維持、 OAuthEnv 既存維持
- 新追加 McpProps / readGitHubProps / writeMcpProps / readOAuthHelpers / OAuthWrappedHandler 5 つすべて export、 docstring 完備
- createOAuthProvider の signature 変更点は
<TEnv extends OAuthEnv>追加 + 戻り型OAuthWrappedHandler<TEnv>化のみ。 internal の OAuthProvider 設定 (apiRoute / authorizeEndpoint / TTL / PKCE / tokenExchangeCallback) は完全不変
src/types.ts:- Env を OAuthEnv extends 化、 OAUTH_KV / GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET の重複宣言削除
- 他フィールド (MCP_OBJECT / ISSUE_STORE / VECTORIZE / DB_FTS / AI / GITHUB_TOKEN / POLL_REPOS / GITHUB_WEBHOOK_SECRET) は完全不変
src/index.ts:- import から OAuthEnv / GitHubUserProps を除き、 helper 3 つを追加 import
- L130-160 + L173-183 の cast 全削除、 logic 不変
CI
- test (tsc --noEmit + wrangler deploy --dry-run): pass (26s)
- CI gate: pass (2s)
- Workers Builds: pass
マージ判断
auto mode: AI 自己レビュー pass → AI 直マージ (gh pr merge --squash)。 v0.8.7 milestone 紐付け済み、 次 release 候補として保留。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目的
src/index.tsに散在していた 6 OAuth-wiringas unknown asキャストをsrc/oauth.ts境界に集約。 型システムの escape hatch を 1 ファイルに局所化し、 OAuthProvider 仕様変更時の追従性を向上させる。Closes #148
変更点
削減 (
src/index.ts)6 cast 全削除:
ctx.props読み →readGitHubProps(ctx)ctx.props書き換え →writeMcpProps(ctx, { ... })env.OAUTH_PROVIDER読み →readOAuthHelpers(env)createOAuthProvider/oauthWrapped.fetchの env 型変換 → generic 化により消滅集約 (
src/oauth.ts)McpProps(RagMcpAgentV2 が消費する props shape を独立宣言)readGitHubProps(ctx)— OAuthProvider が ctx.props にセットした GitHubUserProps を読み出すwriteMcpProps(ctx, props)— McpProps shape を ctx.props に書き戻すreadOAuthHelpers(env)— OAuthProvider が env に注入する OAUTH_PROVIDER helper を取り出すOAuthWrappedHandler<TEnv>— caller の Env 型を保ったまま fetch を返す型createOAuthProviderを<TEnv extends OAuthEnv>generic 化。 library 側のOAuthEnv & Record<string, unknown>制約は関数内LibEnvローカル型に閉じ込めた構造化 (
src/types.ts)Env extends OAuthEnv化。 OAUTH_KV / GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET は extends 経由で継承し重複宣言を削除scope 外 (本 PR では据え置き)
src/mcp.tsL719 (Vectorize metadata cast —@cloudflare/workers-typesの VectorizeMatch.metadata 型が unknown のため)src/rerank.tsL157 (Workers AI response cast —env.AI.run戻り値の型推論が AiTextGenerationOutput に固定されるため)両者は外部ライブラリ起因なので、 別 issue で library 型定義 import / 専用型 alias の検討。
AI 自己レビュー (auto モード)
分類
tsc --noEmitclean、wrangler deploy --dry-run成功createOAuthProviderの signature が generic 化) だが内部使用のみで外部影響なしcast 数の変化
src/index.ts(OAuth wiring)src/oauth.tssrc/mcp.ts(library gap)src/rerank.ts(library gap)外部キャスト site が 6 → 0、 oauth.ts 境界に意図のある boundary cast 5 が残る形に。 cast 総数は -1 だが、 主目的は site 集約。
検証
grep "as unknown as" src/→ 7 ヒット (oauth.ts 5 + mcp.ts 1 + rerank.ts 1)、 index.ts ゼロnpx tsc --noEmitcleannpx wrangler deploy --dry-run成功 (bindings 出力正常)CI pass を確認次第、 auto モード規約に従い
gh pr merge --squashで直接マージする。🤖 Generated with Claude Code