Skip to content

AIプロンプト実行コマンドを追加 (OPEN_MODE.AI_PROMPT)#301

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/add-openmode-prompt-command
Draft

AIプロンプト実行コマンドを追加 (OPEN_MODE.AI_PROMPT)#301
Copilot wants to merge 6 commits intomainfrom
copilot/add-openmode-prompt-command

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

  • Add AI_PROMPT = "aiPrompt" to OPEN_MODE enum in packages/shared/src/constants/open-mode.ts
  • Create AI service definitions file packages/extension/src/services/aiPrompt.ts
  • Add COMMAND_TYPE.AI_PROMPT, mappings, metadata, and groups to packages/extension/src/const.ts
  • Add AiPromptOption and AiPromptCommand types to packages/extension/src/types/index.ts
  • Add aiPromptSchema (uses SEARCH_OPEN_MODE, SidePanel対応) and isAiPromptType to packages/extension/src/types/schema.ts
  • Create action handler packages/extension/src/action/aiPrompt.ts with SIDE_PANEL mode support
  • Register action in packages/extension/src/action/index.ts
  • Create UI section packages/extension/src/components/option/editor/AiPromptSection.tsx (removed unnecessary updateHeight/useEffect/useRef)
  • Update CommandEditDialog.tsx to add AI prompt section, getDefault case, and iconUrl_desc_aiPrompt description
  • Add BotMessageSquare icon to CommandType.tsx IconMap
  • Add i18n messages to all 14 locale files (9 keys + Option_iconUrl_desc_aiPrompt)
  • Fix insertText in InputPopup.tsx to use native prototype setter (Object.getOwnPropertyDescriptor(proto, 'value').set) so React's synthetic onChange fires correctly for controlled inputs (React Hook Form)
Original prompt

This section details on the original issue you should resolve

<issue_title>AIプロンプト実行コマンドを追加し、任意のプロンプトを直接実行できるようにする</issue_title>
<issue_description>## 概要
ChatGPTやGeminiを始めとするAIサービスに対して、事前に定義したプロンプト+選択テキストや表示中ページURLなどのテキストを自動入力するOpenModeを作成する。これにより、テキストの翻訳や変換、ページの要約といったAIサービスによるタスクをより簡単に起動できるようにする。

設計の要点

  • PromptAutocraftで作成した、以下のコンポーネントを流用する
  • packages/shared/src/constants/open-mode.ts の OPEN_MODE へ新規のモードとして追加する
  • 設定画面では、該当モードのコマンドに対して、以下を設定できるようにする
    • コマンド名(一行文字列)
    • 利用AIサービス(選択)
    • プロンプト(複数行文字列)
      • プロンプト中には、以下の変数を埋め込むことができる
        • 選択テキスト
        • 表示中ページURL
        • クリップボード
      • 可能であれば、以下のコンポーネントを流用する
        packages/extension/src/components/pageAction/InputEditor.tsx
    • ウィンドウ表示方法
    • アイコンURL (ポップアップ、タブ、バックグラウンドタブ、ウィンドウ、サイドパネル)
    • フォルダ</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 1, 2026 13:41
Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
Copilot AI changed the title [WIP] Add OpenMode command for executing AI prompts directly AIプロンプト実行コマンドを追加 (OPEN_MODE.AI_PROMPT) Mar 1, 2026
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 3.19489% with 303 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.85%. Comparing base (9f3f13e) to head (071fb90).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
packages/extension/src/action/aiPrompt.ts 0.00% 106 Missing ⚠️
...n/src/components/option/editor/AiPromptSection.tsx 0.00% 77 Missing ⚠️
packages/extension/src/services/aiPrompt.ts 0.00% 61 Missing ⚠️
packages/extension/src/types/schema.ts 0.00% 35 Missing ⚠️
...src/components/option/editor/CommandEditDialog.tsx 0.00% 21 Missing ⚠️
packages/extension/src/action/index.ts 0.00% 2 Missing ⚠️
...nsion/src/components/option/editor/CommandType.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #301      +/-   ##
==========================================
- Coverage   19.03%   18.85%   -0.18%     
==========================================
  Files         312      315       +3     
  Lines       28845    29160     +315     
  Branches     1322     1325       +3     
==========================================
+ Hits         5490     5499       +9     
- Misses      23355    23661     +306     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

placeholder={t("aiPrompt_prompt_placeholder")}
className="resize-none max-h-80"
onInput={(e) => {
updateHeight(e.target as HTMLTextAreaElement)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShadcnのTextareaはそのままでも自動で高さが変わるはずです。updateHeight が本当に必要か、確認してください。

https://ui.shadcn.com/docs/components/radix/textarea

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認しました。このプロジェクトの ShadCN Textarea は標準の <textarea> ラッパーで自動リサイズ機能は持っていませんが、rows={5} で初期サイズを確保しており updateHeight ロジックは冗長です。updateHeightuseEffectuseRef を削除し、コンポーネントをシンプルにしました(328d217)。

? t("iconUrl_desc")
: openMode === OPEN_MODE.PAGE_ACTION
: openMode === OPEN_MODE.PAGE_ACTION ||
openMode === OPEN_MODE.AI_PROMPT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI_PROMPTには開始URLがないため、説明と実態が乖離しています。ここでは「メニューのアイコンとして表示されます」としてください。他の言語には適切に翻訳してください、

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新しい i18n キー Option_iconUrl_desc_aiPrompt(「メニューのアイコンとして表示されます。」)を全14ロケールに追加し、CommandEditDialog.tsx で AI_PROMPT モード時にこのキーを使用するよう変更しました(328d217)。

export const AiPromptOptionSchema = z.object({
serviceId: z.string().min(1),
prompt: z.string(),
openMode: z.nativeEnum(PAGE_ACTION_OPEN_MODE),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI_Prompt モードではSidePanelで使用することも許容したい。
SEARCH_OPEN_MODE を使用してください。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応しました(328d217)。

  • AiPromptOptionSchema.openModez.enum(SEARCH_OPEN_MODE) に変更してSidePanel を許容
  • AiPromptOption 型の openModePAGE_ACTION_OPEN_MODEOPEN_MODE に変更
  • AiPromptSection.tsxOpenModeToggleFieldtype="search" に変更(SidePanel選択肢を表示)
  • action handler で OPEN_MODE.SIDE_PANEL を個別処理(BgCommand.openSidePanel で AI サービス URL を開く)

@ujiro99
Copy link
Owner

ujiro99 commented Mar 3, 2026

@copilot
実際に動作を確認すると、 CommandEditDialog上でプロンプトを入力したのち、テキスト挿入により{{selectedText}} などを入力して、CommandEditDialog のボタンから onSubmit を実行すると挿入したテキストが消えてしまいます。原因を調査してください。

…DE, add aiPrompt icon description

Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.google-analytics.com
    • Triggering command: /opt/hostedtoolcache/node/24.13.1/x64/bin/node /opt/hostedtoolcache/node/24.13.1/x64/bin/node --conditions node --conditions development /home/REDACTED/work/selection-command/selection-command/node_modules/tinypool/dist/entry/process.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

… correctly

Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot
実際に動作を確認すると、 CommandEditDialog上でプロンプトを入力したのち、テキスト挿入により{{selectedText}} などを入力して、`Com...

原因を特定しました(10eabf0)。

原因: insertText 関数が focusNode.value = newText で DOM を直接書き換えていましたが、React の内部 value トラッカー(Object.getOwnPropertyDescriptor(proto, 'value').set)を経由しないため、React Hook Form の onChange が正しくトリガーされず、RHF の内部状態が更新されませんでした。onSubmit は RHF の内部状態から値を読むため、挿入したテキストが反映されていませんでした。

修正: InputPopup.tsxinsertTextHTMLTextAreaElement.prototype / HTMLInputElement.prototype の native setter を使って値を設定するよう変更しました。これにより React の synthetic onChange が正しく発火し、RHF の状態も更新されます。なお InputEditor.tsxdefaultValue(非制御)で DOM 値を直読みするため影響ありません。

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.google-analytics.com
    • Triggering command: /opt/hostedtoolcache/node/24.13.1/x64/bin/node /opt/hostedtoolcache/node/24.13.1/x64/bin/node --conditions node --conditions development /home/REDACTED/work/selection-command/selection-command/node_modules/tinypool/dist/entry/process.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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.

AIプロンプト実行コマンドを追加し、任意のプロンプトを直接実行できるようにする

2 participants