opencode-plan-cards-plugin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2026-02-16
6
+
7
+ ### Added
8
+
9
+ - Initial plugin scaffold for original OpenCode desktop + CLI.
10
+ - Session command handling for `/plan card on|off`.
11
+ - Session-level card mode state isolation via `Map<sessionID, boolean>`.
12
+ - `experimental.chat.system.transform` injection for plan card workflow guidance.
13
+ - `tool.definition` enhancement for `question` tool card-format instructions.
14
+ - README with `file://` and npm installation options.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sakura1175
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,87 @@
1
+ # opencode-plan-cards-plugin
2
+
3
+ A plugin that enhances card-based planning interactions for original OpenCode (Desktop + CLI), without replacing `opencode-cli.exe`.
4
+
5
+ ## Features
6
+
7
+ - Provides session commands:
8
+ - `/plan card on`
9
+ - `/plan card off`
10
+ - When enabled, it injects a stricter `plan` workflow: clarify first, confirm, then output a complete plan.
11
+ - Enhances the `question` tool definition to encourage card questions with 2–3 options and clear tradeoff descriptions.
12
+ - Disabled by default; controlled per session.
13
+
14
+ ## Compatibility
15
+
16
+ - OpenCode: `1.2.x` (Desktop / CLI)
17
+ - Plugin distribution: both `file://` and npm package
18
+
19
+ ## Installation (Method A: Git + file://, recommended first)
20
+
21
+ ```powershell
22
+ git clone <your-repo-url> opencode-plan-cards-plugin
23
+ cd opencode-plan-cards-plugin
24
+ npm install
25
+ npm run build
26
+ ```
27
+
28
+ Configure plugin in `~/.config/opencode/opencode.json`:
29
+
30
+ ```json
31
+ {
32
+ "$schema": "https://opencode.ai/config.json",
33
+ "plugin": [
34
+ "file:///ABSOLUTE_PATH_TO/opencode-plan-cards-plugin/dist/index.js"
35
+ ],
36
+ "agent": {
37
+ "ask": {
38
+ "hidden": true
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ > On Windows, use `file:///` paths and encode spaces as `%20`.
45
+
46
+ ## Installation (Method B: npm)
47
+
48
+ After publishing, user config:
49
+
50
+ ```json
51
+ {
52
+ "$schema": "https://opencode.ai/config.json",
53
+ "plugin": [
54
+ "opencode-plan-cards-plugin@0.1.0"
55
+ ],
56
+ "agent": {
57
+ "ask": {
58
+ "hidden": true
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ 1. In a target session, run `/plan card on`
67
+ 2. Continue describing requirements in `plan`; the model prioritizes card-based clarification and confirmation
68
+ 3. To restore default behavior, run `/plan card off`
69
+
70
+ ## Validation Checklist
71
+
72
+ 1. Desktop: card interaction appears after `/plan card on`
73
+ 2. CLI: same command works
74
+ 3. `/plan card off` restores default `plan` behavior
75
+ 4. `agent.ask.hidden=true` hides ask in UI by default
76
+
77
+ ## Publish to npm
78
+
79
+ ```powershell
80
+ npm run build
81
+ npm publish --access public
82
+ ```
83
+
84
+ ## Limitations
85
+
86
+ - This plugin is a workflow-guidance enhancement, not a core-level hard enforcement.
87
+ - For hard guards (for example, strict preconditions before `plan_exit`), maintain a core fork.
package/README.ja.md ADDED
@@ -0,0 +1,87 @@
1
+ # opencode-plan-cards-plugin
2
+
3
+ オリジナルの OpenCode(Desktop + CLI)で、`plan` エージェントのカード型質問フローを強化するプラグインです。`opencode-cli.exe` の差し替えは不要です。
4
+
5
+ ## 機能
6
+
7
+ - セッションコマンドを提供:
8
+ - `/plan card on`
9
+ - `/plan card off`
10
+ - 有効化時、`plan` セッションにのみ「要件確認 → 最終確認 → 完全な実行計画出力」の制約を注入。
11
+ - `question` ツール定義を強化し、2〜3択 + トレードオフ説明のカード質問を促進。
12
+ - デフォルトは無効。セッションごとのスイッチで制御。
13
+
14
+ ## 互換性
15
+
16
+ - OpenCode: `1.2.x`(Desktop / CLI)
17
+ - プラグイン配布形態:`file://` と npm の両対応
18
+
19
+ ## インストール(方式 A:Git + file://、初回推奨)
20
+
21
+ ```powershell
22
+ git clone <your-repo-url> opencode-plan-cards-plugin
23
+ cd opencode-plan-cards-plugin
24
+ npm install
25
+ npm run build
26
+ ```
27
+
28
+ `~/.config/opencode/opencode.json` に以下を設定:
29
+
30
+ ```json
31
+ {
32
+ "$schema": "https://opencode.ai/config.json",
33
+ "plugin": [
34
+ "file:///ABSOLUTE_PATH_TO/opencode-plan-cards-plugin/dist/index.js"
35
+ ],
36
+ "agent": {
37
+ "ask": {
38
+ "hidden": true
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ > Windows では `file:///` 形式を使用し、空白は `%20` にしてください。
45
+
46
+ ## インストール(方式 B:npm)
47
+
48
+ 公開後、ユーザー設定:
49
+
50
+ ```json
51
+ {
52
+ "$schema": "https://opencode.ai/config.json",
53
+ "plugin": [
54
+ "opencode-plan-cards-plugin@0.1.0"
55
+ ],
56
+ "agent": {
57
+ "ask": {
58
+ "hidden": true
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## 使い方
65
+
66
+ 1. 対象セッションで `/plan card on` を入力
67
+ 2. `plan` で要件を入力すると、カードによる確認フローが優先される
68
+ 3. 既定動作に戻す場合は `/plan card off`
69
+
70
+ ## 動作確認チェックリスト
71
+
72
+ 1. Desktop:`/plan card on` 後にカード質問フローが表示される
73
+ 2. CLI:同様にコマンドが有効
74
+ 3. `/plan card off` 後に標準 `plan` 挙動へ復帰
75
+ 4. `agent.ask.hidden=true` で UI の ask を非表示化
76
+
77
+ ## npm 公開
78
+
79
+ ```powershell
80
+ npm run build
81
+ npm publish --access public
82
+ ```
83
+
84
+ ## 制限事項
85
+
86
+ - プラグイン層は「フロー誘導の強化」であり、コアレベルの強制制約ではありません。
87
+ - 例:`plan_exit` 前の厳格な必須チェックなどは、コア分岐の維持が必要です。
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # opencode-plan-cards-plugin
2
+
3
+ Language / 语言 / 言語:
4
+ - [English](./README.en.md)
5
+ - [简体中文](./README.zh-CN.md)
6
+ - [日本語](./README.ja.md)
7
+
8
+ 让原版 OpenCode(桌面端 + CLI)获得更强的 `plan` 卡片问答流程,无需替换 `opencode-cli.exe`。
9
+
10
+ ## 功能
11
+
12
+ - 提供会话命令:
13
+ - `/plan card on`
14
+ - `/plan card off`
15
+ - 开启后仅在 `plan` 会话注入“先澄清、再确认、再输出完整计划”的系统约束。
16
+ - 强化 `question` 工具描述,推动 2–3 选项 + 权衡说明的卡片提问格式。
17
+ - 默认不强开,按会话开关控制。
18
+
19
+ ## 兼容性
20
+
21
+ - OpenCode: `1.2.x`(桌面端 / CLI)
22
+ - 插件形态:`file://` 与 npm 包均可
23
+
24
+ ## 安装(方式 A:Git + file://,推荐首发)
25
+
26
+ ```powershell
27
+ git clone <your-repo-url> opencode-plan-cards-plugin
28
+ cd opencode-plan-cards-plugin
29
+ npm install
30
+ npm run build
31
+ ```
32
+
33
+ 在 `~/.config/opencode/opencode.json` 中配置插件:
34
+
35
+ ```json
36
+ {
37
+ "$schema": "https://opencode.ai/config.json",
38
+ "plugin": [
39
+ "file:///ABSOLUTE_PATH_TO/opencode-plan-cards-plugin/dist/index.js"
40
+ ],
41
+ "agent": {
42
+ "ask": {
43
+ "hidden": true
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ > Windows 路径需要使用 `file:///`,空格写成 `%20`。
50
+
51
+ ## 安装(方式 B:npm)
52
+
53
+ 发布后,用户配置:
54
+
55
+ ```json
56
+ {
57
+ "$schema": "https://opencode.ai/config.json",
58
+ "plugin": [
59
+ "opencode-plan-cards-plugin@0.1.0"
60
+ ],
61
+ "agent": {
62
+ "ask": {
63
+ "hidden": true
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## 使用
70
+
71
+ 1. 在目标会话输入:`/plan card on`
72
+ 2. 继续在 `plan` 中描述需求,模型会优先走卡片澄清与确认流程
73
+ 3. 需要恢复默认行为时输入:`/plan card off`
74
+
75
+ ## 验证清单
76
+
77
+ 1. 桌面端:`/plan card on` 后出现卡片问答流程
78
+ 2. CLI:同样命令生效
79
+ 3. `/plan card off` 后恢复原始 `plan` 行为
80
+ 4. `agent.ask.hidden=true` 后 UI 默认不展示 ask
81
+
82
+ ## 发布 npm
83
+
84
+ ```powershell
85
+ npm run build
86
+ npm publish --access public
87
+ ```
88
+
89
+ ## 限制说明
90
+
91
+ - 插件层是“流程引导增强”,不等于内核级强约束。
92
+ - 如需硬拦截(例如强制 plan_exit 前置条件),仍需维护内核分支。
@@ -0,0 +1,87 @@
1
+ # opencode-plan-cards-plugin
2
+
3
+ 让原版 OpenCode(桌面端 + CLI)获得更强的 `plan` 卡片问答流程,无需替换 `opencode-cli.exe`。
4
+
5
+ ## 功能
6
+
7
+ - 提供会话命令:
8
+ - `/plan card on`
9
+ - `/plan card off`
10
+ - 开启后仅在 `plan` 会话注入“先澄清、再确认、再输出完整计划”的系统约束。
11
+ - 强化 `question` 工具描述,推动 2–3 选项 + 权衡说明的卡片提问格式。
12
+ - 默认不强开,按会话开关控制。
13
+
14
+ ## 兼容性
15
+
16
+ - OpenCode: `1.2.x`(桌面端 / CLI)
17
+ - 插件形态:`file://` 与 npm 包均可
18
+
19
+ ## 安装(方式 A:Git + file://,推荐首发)
20
+
21
+ ```powershell
22
+ git clone <your-repo-url> opencode-plan-cards-plugin
23
+ cd opencode-plan-cards-plugin
24
+ npm install
25
+ npm run build
26
+ ```
27
+
28
+ 在 `~/.config/opencode/opencode.json` 中配置插件:
29
+
30
+ ```json
31
+ {
32
+ "$schema": "https://opencode.ai/config.json",
33
+ "plugin": [
34
+ "file:///ABSOLUTE_PATH_TO/opencode-plan-cards-plugin/dist/index.js"
35
+ ],
36
+ "agent": {
37
+ "ask": {
38
+ "hidden": true
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ > Windows 路径需要使用 `file:///`,空格写成 `%20`。
45
+
46
+ ## 安装(方式 B:npm)
47
+
48
+ 发布后,用户配置:
49
+
50
+ ```json
51
+ {
52
+ "$schema": "https://opencode.ai/config.json",
53
+ "plugin": [
54
+ "opencode-plan-cards-plugin@0.1.0"
55
+ ],
56
+ "agent": {
57
+ "ask": {
58
+ "hidden": true
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## 使用
65
+
66
+ 1. 在目标会话输入:`/plan card on`
67
+ 2. 继续在 `plan` 中描述需求,模型会优先走卡片澄清与确认流程
68
+ 3. 需要恢复默认行为时输入:`/plan card off`
69
+
70
+ ## 验证清单
71
+
72
+ 1. 桌面端:`/plan card on` 后出现卡片问答流程
73
+ 2. CLI:同样命令生效
74
+ 3. `/plan card off` 后恢复原始 `plan` 行为
75
+ 4. `agent.ask.hidden=true` 后 UI 默认不显示 ask
76
+
77
+ ## 发布 npm
78
+
79
+ ```powershell
80
+ npm run build
81
+ npm publish --access public
82
+ ```
83
+
84
+ ## 限制说明
85
+
86
+ - 插件层是“流程引导增强”,不等于内核级强约束。
87
+ - 如需硬拦截(例如强制 `plan_exit` 前置条件),仍需维护内核分支。
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ export declare const PlanCardsPlugin: Plugin;
3
+ export default PlanCardsPlugin;
package/dist/index.js ADDED
@@ -0,0 +1,115 @@
1
+ const CARD_COMMAND_PATTERN = /^\/plan\s+card\s+(on|off)$/i;
2
+ const cardModeBySession = new Map();
3
+ const lastAgentBySession = new Map();
4
+ const PLAN_CARD_SYSTEM_APPENDIX = `
5
+ Plan card mode is enabled for this session.
6
+
7
+ Mandatory workflow:
8
+ 1. Clarify missing requirements before generating a final plan.
9
+ 2. Use the question tool for clarification and confirmation gates.
10
+ 3. Ask 1-3 focused questions per round.
11
+ 4. Each question must represent one decision only, with a short header.
12
+ 5. Provide 2-3 options per question, each with a short tradeoff description.
13
+ 6. Keep custom input available (do not add catch-all "Other" options).
14
+ 7. After clarification, ask one final confirmation question before outputting the final plan.
15
+ 8. Output one complete actionable plan only after user confirmation.
16
+ `.trim();
17
+ const QUESTION_TOOL_APPENDIX = `
18
+ Card interaction requirements:
19
+ - Keep each question focused on one decision.
20
+ - Keep header short (<= 30 chars).
21
+ - Include 2-3 options with clear tradeoffs.
22
+ - Put the recommended option first and suffix it with "(Recommended)" when applicable.
23
+ - Do not add "Other" options; rely on custom input support.
24
+ `.trim();
25
+ function isTextPart(part) {
26
+ return part.type === "text";
27
+ }
28
+ function extractCardModeCommand(parts) {
29
+ const textParts = parts.filter(isTextPart).filter((part) => !part.synthetic);
30
+ if (textParts.length !== 1)
31
+ return;
32
+ const match = CARD_COMMAND_PATTERN.exec(textParts[0].text.trim());
33
+ if (!match)
34
+ return;
35
+ return match[1].toLowerCase();
36
+ }
37
+ function commandConfirmationPrompt(command) {
38
+ if (command === "on") {
39
+ return [
40
+ "The command /plan card on has already been applied for this session.",
41
+ "Reply with exactly one short confirmation sentence in the user's language.",
42
+ "Do not ask extra questions and do not produce a plan in this reply.",
43
+ ].join("\n");
44
+ }
45
+ return [
46
+ "The command /plan card off has already been applied for this session.",
47
+ "Reply with exactly one short confirmation sentence in the user's language.",
48
+ "Do not ask extra questions and do not produce a plan in this reply.",
49
+ ].join("\n");
50
+ }
51
+ function appendUniqueDescription(base, appendix) {
52
+ const normalized = appendix.trim();
53
+ if (!normalized)
54
+ return base;
55
+ if (base.includes(normalized))
56
+ return base;
57
+ if (!base.trim())
58
+ return normalized;
59
+ return `${base.trim()}\n\n${normalized}`;
60
+ }
61
+ function patchQuestionParameters(parameters) {
62
+ const questionItem = parameters?.properties?.questions?.items;
63
+ const questionProps = questionItem?.properties;
64
+ if (!questionProps || typeof questionProps !== "object")
65
+ return;
66
+ if (questionProps.header) {
67
+ questionProps.header.description = "Very short header (<=30 chars) for one decision.";
68
+ }
69
+ if (questionProps.question) {
70
+ questionProps.question.description = "Single clear question for one decision.";
71
+ }
72
+ if (questionProps.options) {
73
+ questionProps.options.description =
74
+ "Provide 2-3 options; each option must include a short tradeoff description.";
75
+ }
76
+ }
77
+ export const PlanCardsPlugin = async () => {
78
+ return {
79
+ event: async ({ event }) => {
80
+ if (event.type !== "session.deleted")
81
+ return;
82
+ const sessionID = event.properties?.sessionID;
83
+ if (!sessionID)
84
+ return;
85
+ cardModeBySession.delete(sessionID);
86
+ lastAgentBySession.delete(sessionID);
87
+ },
88
+ "chat.message": async (input, output) => {
89
+ const sessionID = input.sessionID;
90
+ const command = extractCardModeCommand(output.parts);
91
+ if (command) {
92
+ cardModeBySession.set(sessionID, command === "on");
93
+ output.message.agent = "ask";
94
+ output.message.system = appendUniqueDescription(output.message.system ?? "", commandConfirmationPrompt(command));
95
+ }
96
+ lastAgentBySession.set(sessionID, output.message.agent);
97
+ },
98
+ "experimental.chat.system.transform": async (input, output) => {
99
+ if (!input.sessionID)
100
+ return;
101
+ if (!cardModeBySession.get(input.sessionID))
102
+ return;
103
+ if (lastAgentBySession.get(input.sessionID) !== "plan")
104
+ return;
105
+ output.system.push(PLAN_CARD_SYSTEM_APPENDIX);
106
+ },
107
+ "tool.definition": async (input, output) => {
108
+ if (input.toolID !== "question")
109
+ return;
110
+ output.description = appendUniqueDescription(output.description, QUESTION_TOOL_APPENDIX);
111
+ patchQuestionParameters(output.parameters);
112
+ },
113
+ };
114
+ };
115
+ export default PlanCardsPlugin;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "opencode-plan-cards-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Plan card interaction enhancement plugin for OpenCode",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "CHANGELOG.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "check": "tsc -p tsconfig.json --noEmit"
22
+ },
23
+ "keywords": [
24
+ "opencode",
25
+ "plugin",
26
+ "plan",
27
+ "cards"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "peerDependencies": {
32
+ "@opencode-ai/plugin": ">=1.2.0 <2"
33
+ },
34
+ "devDependencies": {
35
+ "@opencode-ai/plugin": "^1.2.0",
36
+ "@opencode-ai/sdk": "^1.2.0",
37
+ "typescript": "^5.7.3"
38
+ }
39
+ }