Skip to content

fix: return a result instead of throwing when the host passes no context - #24

Merged
isamu merged 1 commit into
mainfrom
fix/null-context-20260803
Aug 2, 2026
Merged

fix: return a result instead of throwing when the host passes no context#24
isamu merged 1 commit into
mainfrom
fix/null-context-20260803

Conversation

@isamu

@isamu isamu commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

host が execute()null の context を渡すためクラッシュしていたのを修正した。
receptron/mulmoclaude#2709 と同じ原因で、調査の結果 14 プラグインが同じ問題を抱えていた
(receptron/mulmoclaude#2758 に横断報告)。

TypeError: Cannot read properties of null (reading 'app')

Items to Confirm / Review

  1. 型が実態と食い違っているのが根本原因gui-chat-protocol
    execute: (context: ToolContext, args: A) => ... は context を non-nullable と宣言しているが、
    MulmoClaude の server bridge は実際には null を渡す。型が嘘をついているのでガードを書く動機が無かった。
    プロトコル側の型修正を #2758 で提案している。
  2. 修正は最小限に留めたcontextToolContext | null | undefined に広げ、
    src/core/plugin.ts:28 の参照を ?. でガードしただけ。ガード後の呼び出し
    (context.app.xxx(...) 等)はそのまま残してある。TypeScript が optional chaining 経由で
    narrowing してくれるうえ、メソッド呼び出しの形を保つことで this 束縛を壊さないため。
  3. 回帰テストを追加したtests/plugin.test.ts。修正を戻すと実際に fail することを確認済み
    (テストが常に通るだけの飾りになっていない)。

変更内容

  • src/core/plugin.ts — context を nullable にし、src/core/plugin.ts:28 をガード
  • tests/plugin.test.ts — null / undefined / 空オブジェクトの 3 ケース
  • package.jsontest script と tsx(MindMap の修正と同じ構成)、patch version bump
  • .github/workflows/pull_request.yaml — CI で yarn test を実行
  • eslint.config.jstests/** を lint 対象外に(ガイド §3: 型プログラムを小さく保つ)

検証

node_modules を消してからのクリーン install で確認済み
(warm な node_modules は lockfile 変更後の CI を再現しないため):

rm -rf node_modules && yarn install --frozen-lockfile
yarn typecheck  → pass
yarn lint       → pass
yarn build      → pass
yarn test       → pass

さらに execute(null, args) を直接呼んで、修正前は TypeError、修正後は正常な
ToolResult が返ることを実機で確認した。

🤖 Generated with Claude Code

`execute` declares `context: ToolContext` (non-nullable), but MulmoClaude's
server bridge passes null. Reading `context.app` unguarded threw
`Cannot read properties of null (reading 'app')`, which surfaced as an
HTTP 500 for every call.

Widen the parameter to `ToolContext | null | undefined` and guard the
dereference, so the plugin returns its existing "not available" result.

Adds a regression test covering null / undefined / empty context.

refs receptron/mulmoclaude#2709, receptron/mulmoclaude#2758

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedtsx@​4.23.4991008194100

View full report

@isamu
isamu merged commit 33a9681 into main Aug 2, 2026
11 checks passed
@isamu
isamu deleted the fix/null-context-20260803 branch August 2, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant