@2cmddev/2cmd 0.0.0-stage → 0.1.2
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/.opencode/command/2cmd-audit.md +5 -0
- package/.opencode/command/2cmd-debt.md +5 -0
- package/.opencode/command/2cmd-gain.md +5 -0
- package/.opencode/command/2cmd-help.md +5 -0
- package/.opencode/command/2cmd-review.md +5 -0
- package/.opencode/command/2cmd.md +5 -0
- package/.opencode/plugins/2cmd-frontmatter.cjs +63 -0
- package/.opencode/plugins/2cmd.mjs +206 -0
- package/.opencode/plugins/index.js +4 -0
- package/.qoder/rules/2cmd.md +31 -0
- package/.qoder-plugin/plugin.json +16 -0
- package/.zcode-plugin/plugin.json +13 -0
- package/AGENTS.md +33 -0
- package/LICENSE +22 -0
- package/README.md +133 -2
- package/codex/answer.mjs +164 -0
- package/codex/data.mjs +31 -0
- package/codex/pty.py +80 -0
- package/codex/stats.mjs +105 -0
- package/codex/terminal.mjs +388 -0
- package/dsh/LICENSE +22 -0
- package/dsh/board.js +782 -0
- package/dsh/build.mjs +47 -0
- package/dsh/bundle.json +2104 -0
- package/dsh/client.js +877 -0
- package/dsh/cordis.patch.yml +3 -0
- package/dsh/index.js +185 -0
- package/dsh/ledger.js +50 -0
- package/dsh/market.js +152 -0
- package/dsh/package.json +24 -0
- package/dsh/prices.json +1812 -0
- package/dsh/settings-text.mjs +520 -0
- package/dsh/settings.js +42 -0
- package/dsh/stats.js +106 -0
- package/dsh/store.js +32 -0
- package/dsh/update-prices.mjs +9 -0
- package/dsh/update.js +27 -0
- package/dsh/voice-helper/Info.plist +13 -0
- package/dsh/voice-helper/Transcript.swift +21 -0
- package/dsh/voice-helper/build.sh +10 -0
- package/dsh/voice-helper/main.swift +70 -0
- package/dsh/voice-helper/test.swift +17 -0
- package/dsh/voice.js +63 -0
- package/hooks/2cmd-activate.js +219 -0
- package/hooks/2cmd-antigravity.js +64 -0
- package/hooks/2cmd-band-import.js +305 -0
- package/hooks/2cmd-config.js +186 -0
- package/hooks/2cmd-instructions.js +104 -0
- package/hooks/2cmd-map.js +200 -0
- package/hooks/2cmd-mode-tracker.js +248 -0
- package/hooks/2cmd-runtime.js +245 -0
- package/hooks/2cmd-statusline.ps1 +24 -0
- package/hooks/2cmd-statusline.sh +18 -0
- package/hooks/2cmd-subagent.js +100 -0
- package/hooks/band/board.ts +720 -0
- package/hooks/band/buttons.ts +60 -0
- package/hooks/band/i18n/de.ts +149 -0
- package/hooks/band/i18n/en.ts +150 -0
- package/hooks/band/i18n/es.ts +149 -0
- package/hooks/band/i18n/fr.ts +149 -0
- package/hooks/band/i18n/index.ts +42 -0
- package/hooks/band/i18n/ja.ts +149 -0
- package/hooks/band/i18n/ko.ts +149 -0
- package/hooks/band/i18n/pt.ts +149 -0
- package/hooks/band/i18n/ru.ts +149 -0
- package/hooks/band/i18n/vi.ts +149 -0
- package/hooks/band/i18n/zh-Hans.ts +149 -0
- package/hooks/band/i18n/zh-Hant.ts +149 -0
- package/hooks/band/logo.ts +3 -0
- package/hooks/band/metrics.ts +373 -0
- package/hooks/band/register.tsx +681 -0
- package/hooks/band/types.d.ts +45 -0
- package/hooks/band/windows-board.mjs +20 -0
- package/hooks/claude-band.json +6 -0
- package/hooks/claude-codex-hooks.json +41 -0
- package/hooks/codebuddy-hooks.json +20 -0
- package/hooks/copilot-hooks.json +21 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/qoder-hooks.json +26 -0
- package/hooks/zcode-hooks.json +26 -0
- package/package.json +56 -4
- package/pi-extension/index.js +258 -0
- package/pi-extension/names.js +19 -0
- package/pi-extension/package.json +8 -0
- package/scripts/cursor-hooks.js +145 -0
- package/scripts/uninstall.js +92 -0
- package/skills/2cmd/SKILL.md +55 -0
- package/skills/2cmd-audit/SKILL.md +105 -0
- package/skills/2cmd-debt/SKILL.md +46 -0
- package/skills/2cmd-gain/SKILL.md +53 -0
- package/skills/2cmd-help/SKILL.md +87 -0
- package/skills/2cmd-review/SKILL.md +143 -0
- package/skills/plugin.json +5 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type Tests = {
|
|
2
|
+
state: 'none' | 'pass' | 'fail' | 'stale'
|
|
3
|
+
passed?: number
|
|
4
|
+
failed?: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type Tokens = { input: number; output: number; cacheRead: number; cacheWrite: number }
|
|
8
|
+
|
|
9
|
+
// 主对话的缓存数据(不含子任务):last 是最近一轮的命中率,read / input 是 turns 轮的累计。
|
|
10
|
+
export type Cache = { last: number | null; read: number; input: number; turns: number }
|
|
11
|
+
|
|
12
|
+
export type Band = {
|
|
13
|
+
level: string
|
|
14
|
+
// 已选择、等下条消息生效的档位;没有时为空。
|
|
15
|
+
pending: string
|
|
16
|
+
// 最近选过的启用档位,点“启用”时恢复。
|
|
17
|
+
lastLevel: string
|
|
18
|
+
model: string
|
|
19
|
+
cost: number
|
|
20
|
+
spent: number
|
|
21
|
+
turns: number
|
|
22
|
+
turnCosts: number[]
|
|
23
|
+
tokens: Tokens
|
|
24
|
+
cache: Cache
|
|
25
|
+
busyMs: number
|
|
26
|
+
name: string
|
|
27
|
+
project: string
|
|
28
|
+
session: string
|
|
29
|
+
transcript: string
|
|
30
|
+
reused: string[]
|
|
31
|
+
created: string[]
|
|
32
|
+
removed: string[]
|
|
33
|
+
openCallers: string[]
|
|
34
|
+
tests: Tests
|
|
35
|
+
details: boolean
|
|
36
|
+
// 面板上看板和收起前的三个按钮,由 /2cmd-buttons 设置。
|
|
37
|
+
// Same shape as PanelButton in buttons.ts; this file may not import.
|
|
38
|
+
buttons: { kind: 'copy' | 'review' | 'audit' | 'tool' | 'prompt' | 'none'; label?: string; text?: string }[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare module 'claude-code' {
|
|
42
|
+
interface PluginState {
|
|
43
|
+
'2cmd': { band: Band }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @param {string} file */
|
|
2
|
+
export function windowsBoardCommand(file) {
|
|
3
|
+
return {
|
|
4
|
+
argv: ['powershell.exe', '-NoProfile', '-NonInteractive', '-Command', String.raw`
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
$board = [IO.Path]::GetFullPath($env:TWOCMD_BOARD_FILE)
|
|
7
|
+
$browser = @(
|
|
8
|
+
"$env:ProgramFiles\Google\Chrome\Application\chrome.exe"
|
|
9
|
+
"$([Environment]::GetEnvironmentVariable('ProgramFiles(x86)'))\Microsoft\Edge\Application\msedge.exe"
|
|
10
|
+
"$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe"
|
|
11
|
+
) | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
|
|
12
|
+
if ($browser) {
|
|
13
|
+
Start-Process -FilePath $browser -ArgumentList @('--new-tab', [Uri]::new($board).AbsoluteUri)
|
|
14
|
+
} else {
|
|
15
|
+
Start-Process -FilePath $board
|
|
16
|
+
}
|
|
17
|
+
`],
|
|
18
|
+
env: { TWOCMD_BOARD_FILE: file },
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "startup|resume|clear|compact",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node -e \"require(require('path').join(process.env.CLAUDE_PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-activate.js'))\"",
|
|
10
|
+
"timeout": 15,
|
|
11
|
+
"statusMessage": "Loading 2cmd mode..."
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"SubagentStart": [
|
|
17
|
+
{
|
|
18
|
+
"hooks": [
|
|
19
|
+
{
|
|
20
|
+
"type": "command",
|
|
21
|
+
"command": "node -e \"require(require('path').join(process.env.CLAUDE_PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-subagent.js'))\"",
|
|
22
|
+
"timeout": 15,
|
|
23
|
+
"statusMessage": "Loading 2cmd mode..."
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"UserPromptSubmit": [
|
|
29
|
+
{
|
|
30
|
+
"hooks": [
|
|
31
|
+
{
|
|
32
|
+
"type": "command",
|
|
33
|
+
"command": "node -e \"require(require('path').join(process.env.CLAUDE_PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-mode-tracker.js'))\"",
|
|
34
|
+
"timeout": 15,
|
|
35
|
+
"statusMessage": "Tracking 2cmd mode..."
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "startup|resume|clear|compact",
|
|
6
|
+
"hooks": [{ "type": "command", "command": "node \"${CODEBUDDY_PLUGIN_ROOT}/hooks/2cmd-activate.js\"", "timeout": 15 }]
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"UserPromptSubmit": [
|
|
10
|
+
{
|
|
11
|
+
"hooks": [{ "type": "command", "command": "node \"${CODEBUDDY_PLUGIN_ROOT}/hooks/2cmd-mode-tracker.js\"", "timeout": 15 }]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"SubagentStart": [
|
|
15
|
+
{
|
|
16
|
+
"hooks": [{ "type": "command", "command": "node \"${CODEBUDDY_PLUGIN_ROOT}/hooks/2cmd-subagent.js\"", "timeout": 15 }]
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"hooks": {
|
|
4
|
+
"sessionStart": [
|
|
5
|
+
{
|
|
6
|
+
"type": "command",
|
|
7
|
+
"bash": "node -e \"require(require('path').join(process.env.PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-activate.js'))\" || exit 0",
|
|
8
|
+
"powershell": "if (Get-Command node -ErrorAction SilentlyContinue) { node -e \"require(require('path').join(process.env.PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-activate.js'))\" }",
|
|
9
|
+
"timeoutSec": 15
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"userPromptSubmitted": [
|
|
13
|
+
{
|
|
14
|
+
"type": "command",
|
|
15
|
+
"bash": "node -e \"require(require('path').join(process.env.PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-mode-tracker.js'))\" || exit 0",
|
|
16
|
+
"powershell": "if (Get-Command node -ErrorAction SilentlyContinue) { node -e \"require(require('path').join(process.env.PLUGIN_ROOT.split(String.fromCharCode(92)).join('/'), 'hooks/2cmd-mode-tracker.js'))\" }",
|
|
17
|
+
"timeoutSec": 15
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"hooks": {
|
|
4
|
+
"sessionStart": [
|
|
5
|
+
{
|
|
6
|
+
"command": "node \"TWOCMD_DIR/hooks/2cmd-activate.js\"",
|
|
7
|
+
"timeout": 15
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"beforeSubmitPrompt": [
|
|
11
|
+
{
|
|
12
|
+
"command": "node \"TWOCMD_DIR/hooks/2cmd-mode-tracker.js\"",
|
|
13
|
+
"timeout": 15
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Loaded live by .qoder-plugin/plugin.json (\"hooks\": \"./hooks/qoder-hooks.json\"). Qoder expands ${QODER_PLUGIN_ROOT} (the plugin install root) at runtime; see https://docs.qoder.com/en/cli/plugins#writing-plugin-hooks.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"UserPromptSubmit": [
|
|
5
|
+
{
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node \"${QODER_PLUGIN_ROOT}/hooks/2cmd-mode-tracker.js\""
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"PreToolUse": [
|
|
15
|
+
{
|
|
16
|
+
"matcher": "task|Task",
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "node \"${QODER_PLUGIN_ROOT}/hooks/2cmd-subagent.js\""
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "node \"${ZCODE_PLUGIN_ROOT}/hooks/2cmd-activate.js\"",
|
|
9
|
+
"timeout": 15
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"UserPromptSubmit": [
|
|
15
|
+
{
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "node \"${ZCODE_PLUGIN_ROOT}/hooks/2cmd-mode-tracker.js\"",
|
|
20
|
+
"timeout": 15
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@2cmddev/2cmd",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Lazy senior dev mode for AI agents. The best code is the code you never wrote.",
|
|
5
|
+
"keywords": ["opencode-plugin", "opencode", "2cmd", "pi-package", "pi", "skills", "qoder"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "2cmddev",
|
|
9
|
+
"url": "https://github.com/2cmddev"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/2cmddev/2Cmd",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/2cmddev/2Cmd.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/2cmddev/2Cmd/issues"
|
|
18
|
+
},
|
|
19
|
+
"main": "./.opencode/plugins/2cmd.mjs",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./.opencode/plugins/2cmd.mjs",
|
|
22
|
+
"./plugin": "./.opencode/plugins/2cmd.mjs"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"AGENTS.md",
|
|
26
|
+
"hooks/",
|
|
27
|
+
"skills/",
|
|
28
|
+
".opencode/",
|
|
29
|
+
".qoder/",
|
|
30
|
+
".qoder-plugin/",
|
|
31
|
+
".zcode-plugin/",
|
|
32
|
+
"pi-extension/",
|
|
33
|
+
"!pi-extension/test/",
|
|
34
|
+
"scripts/uninstall.js",
|
|
35
|
+
"scripts/cursor-hooks.js",
|
|
36
|
+
"codex/terminal.mjs",
|
|
37
|
+
"codex/pty.py",
|
|
38
|
+
"codex/data.mjs",
|
|
39
|
+
"codex/answer.mjs",
|
|
40
|
+
"codex/stats.mjs",
|
|
41
|
+
"dsh/",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"bin": {
|
|
45
|
+
"2cmd-codex": "codex/terminal.mjs"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "node --test tests/*.test.js && npm test --prefix pi-extension"
|
|
49
|
+
},
|
|
50
|
+
"pi": {
|
|
51
|
+
"extensions": ["./pi-extension/index.js"],
|
|
52
|
+
"skills": ["./skills"]
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { modeNames } from "./names.js";
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const {
|
|
6
|
+
DEFAULT_MODE,
|
|
7
|
+
RUNTIME_MODES,
|
|
8
|
+
getDefaultMode,
|
|
9
|
+
getQuietStartup,
|
|
10
|
+
getHideStatus,
|
|
11
|
+
getLanguage,
|
|
12
|
+
normalizeMode,
|
|
13
|
+
normalizePersistedMode,
|
|
14
|
+
isDeactivationCommand,
|
|
15
|
+
writeDefaultMode,
|
|
16
|
+
} = require("../hooks/2cmd-config.js");
|
|
17
|
+
const { get2CmdInstructions, filterSkillBodyForMode } = require("../hooks/2cmd-instructions.js");
|
|
18
|
+
|
|
19
|
+
export { filterSkillBodyForMode };
|
|
20
|
+
export const readDefaultMode = getDefaultMode;
|
|
21
|
+
export const readQuietStartup = getQuietStartup;
|
|
22
|
+
|
|
23
|
+
const RUNTIME_MODE_LIST = RUNTIME_MODES.join("|");
|
|
24
|
+
const TWOCMD_COMMAND_DESCRIPTION = `Set mode: ${RUNTIME_MODE_LIST}. Commands: status, default <mode>`;
|
|
25
|
+
|
|
26
|
+
// Every item is a complete command: pi submits on Enter, so a bare "default" would run without a mode.
|
|
27
|
+
// Values only: per-level descriptions would be a second copy of the Levels table in SKILL.md.
|
|
28
|
+
export function complete2CmdArgs(prefix) {
|
|
29
|
+
const typed = String(prefix || "").trimStart();
|
|
30
|
+
const values = [...RUNTIME_MODES, "status", ...RUNTIME_MODES.map((m) => `default ${m}`)].filter((v) => v.startsWith(typed));
|
|
31
|
+
return values.length ? values.map((value) => ({ value, label: value })) : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function resolveSessionMode(entries, fallbackMode = DEFAULT_MODE) {
|
|
35
|
+
const fallback = normalizePersistedMode(fallbackMode) || DEFAULT_MODE;
|
|
36
|
+
if (!Array.isArray(entries)) return fallback;
|
|
37
|
+
|
|
38
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
39
|
+
const entry = entries[i];
|
|
40
|
+
if (entry?.type !== "custom" || entry?.customType !== "2cmd-mode") continue;
|
|
41
|
+
|
|
42
|
+
const mode = normalizePersistedMode(entry?.data?.mode);
|
|
43
|
+
if (mode) return mode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function parse2CmdCommand(text, defaultMode = DEFAULT_MODE, currentMode = null) {
|
|
50
|
+
const fallback = normalizePersistedMode(defaultMode) || DEFAULT_MODE;
|
|
51
|
+
const normalizedText = String(text || "").trim().toLowerCase();
|
|
52
|
+
|
|
53
|
+
if (!normalizedText) {
|
|
54
|
+
// Bare /2cmd switches 2cmd on, or reports the level when it already is (#639).
|
|
55
|
+
if (currentMode && currentMode !== "off") return { type: "status" };
|
|
56
|
+
return { type: "set-mode", mode: fallback === "off" ? "reuse" : fallback };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [primary, secondary] = normalizedText.split(/\s+/);
|
|
60
|
+
|
|
61
|
+
if (primary === "status") return { type: "status" };
|
|
62
|
+
|
|
63
|
+
if (primary === "default") {
|
|
64
|
+
// 2cmd: a default must be a runtime level; review is session-only (#377).
|
|
65
|
+
const mode = normalizeMode(secondary);
|
|
66
|
+
return mode ? { type: "set-default", mode } : { type: "invalid", reason: "invalid-default-mode" };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const mode = normalizeMode(primary);
|
|
70
|
+
return mode ? { type: "set-mode", mode } : { type: "invalid", reason: "invalid-mode", mode: primary };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { writeDefaultMode };
|
|
74
|
+
|
|
75
|
+
export default function twoCmdExtension(pi) {
|
|
76
|
+
let currentMode = DEFAULT_MODE;
|
|
77
|
+
let configuredDefaultMode = getDefaultMode();
|
|
78
|
+
let hideStatus = getHideStatus();
|
|
79
|
+
let names = modeNames(getLanguage());
|
|
80
|
+
let isActive = false;
|
|
81
|
+
let lastCtx = null;
|
|
82
|
+
|
|
83
|
+
// -- Status bar --
|
|
84
|
+
function syncStatus(ctx) {
|
|
85
|
+
if (ctx) lastCtx = ctx;
|
|
86
|
+
const c = ctx || lastCtx;
|
|
87
|
+
// 2cmd: hide the indicator but keep the ruleset active (#324).
|
|
88
|
+
if (hideStatus) return;
|
|
89
|
+
if (!c?.ui?.setStatus) return;
|
|
90
|
+
// 2cmd: try/catch guards against pi-web theme proxy throwing before initTheme
|
|
91
|
+
let theme;
|
|
92
|
+
try { theme = c.ui.theme; if (!theme?.fg) return; } catch { return; }
|
|
93
|
+
if (currentMode === "off") {
|
|
94
|
+
c.ui.setStatus("2cmd", undefined);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const levelIcons = { hindsight: "🌿", reuse: "⚡", pushback: "🔥", scout: "🔭" };
|
|
98
|
+
const icon = levelIcons[currentMode] || "";
|
|
99
|
+
const label = names[currentMode] ?? currentMode;
|
|
100
|
+
const indicator = isActive ? theme.fg("accent", "●") : theme.fg("dim", "○");
|
|
101
|
+
c.ui.setStatus("2cmd", indicator + " 🐴 " + theme.fg("muted", "2cmd: ") + theme.fg("text", icon + " " + label));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const setMode = (mode, ctx) => {
|
|
105
|
+
const normalized = normalizePersistedMode(mode);
|
|
106
|
+
if (!normalized) return;
|
|
107
|
+
|
|
108
|
+
currentMode = normalized;
|
|
109
|
+
pi.appendEntry("2cmd-mode", { mode: normalized });
|
|
110
|
+
syncStatus(ctx);
|
|
111
|
+
ctx?.ui?.notify?.(`2Cmd: ${names[normalized] ?? normalized}`, "info");
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const sendAlias = (skillName, args, ctx) => {
|
|
115
|
+
const normalized = String(args || "").trim();
|
|
116
|
+
const message = normalized ? `${skillName} ${normalized}` : skillName;
|
|
117
|
+
|
|
118
|
+
// pi.sendUserMessage does not expand skill commands on its own, so without
|
|
119
|
+
// expandPromptTemplates the alias lands as the literal text
|
|
120
|
+
// "/skill:2cmd-review" and the skill body never reaches the agent.
|
|
121
|
+
if (ctx?.isIdle?.() === false) {
|
|
122
|
+
pi.sendUserMessage(message, { expandPromptTemplates: true, deliverAs: "followUp" });
|
|
123
|
+
ctx?.ui?.notify?.(`${skillName} queued as follow-up.`, "info");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pi.sendUserMessage(message, { expandPromptTemplates: true });
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
pi.registerCommand("2cmd", {
|
|
131
|
+
description: TWOCMD_COMMAND_DESCRIPTION,
|
|
132
|
+
getArgumentCompletions: (prefix) => complete2CmdArgs(prefix),
|
|
133
|
+
handler: async (args, ctx) => {
|
|
134
|
+
const parsed = parse2CmdCommand(args, configuredDefaultMode, currentMode);
|
|
135
|
+
|
|
136
|
+
if (parsed.type === "status") {
|
|
137
|
+
ctx?.ui?.notify?.(`2Cmd: current ${names[currentMode] ?? currentMode} • default ${names[configuredDefaultMode] ?? configuredDefaultMode}`, "info");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (parsed.type === "set-default") {
|
|
142
|
+
try {
|
|
143
|
+
const written = writeDefaultMode(parsed.mode);
|
|
144
|
+
if (written) {
|
|
145
|
+
configuredDefaultMode = getDefaultMode();
|
|
146
|
+
const message = configuredDefaultMode === written
|
|
147
|
+
? `Default 2Cmd mode set to ${written}.`
|
|
148
|
+
: `Saved default ${written}, but env override keeps default at ${configuredDefaultMode}.`;
|
|
149
|
+
ctx?.ui?.notify?.(message, "info");
|
|
150
|
+
}
|
|
151
|
+
} catch (e) {
|
|
152
|
+
ctx?.ui?.notify?.(`Failed to save default mode: ${e.message}`, "error");
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (parsed.type === "set-mode") {
|
|
158
|
+
setMode(parsed.mode, ctx);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
ctx?.ui?.notify?.("Unknown or unsupported /2cmd mode.", "warning");
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
pi.registerCommand("2cmd-review", {
|
|
167
|
+
description: "Run /skill:2cmd-review",
|
|
168
|
+
handler: (args, ctx) => sendAlias("/skill:2cmd-review", args, ctx),
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
pi.registerCommand("2cmd-audit", {
|
|
172
|
+
description: "Run /skill:2cmd-audit",
|
|
173
|
+
handler: (args, ctx) => sendAlias("/skill:2cmd-audit", args, ctx),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
pi.registerCommand("2cmd-gain", {
|
|
177
|
+
description: "Run /skill:2cmd-gain",
|
|
178
|
+
handler: (args, ctx) => sendAlias("/skill:2cmd-gain", args, ctx),
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
pi.registerCommand("2cmd-debt", {
|
|
182
|
+
description: "Run /skill:2cmd-debt",
|
|
183
|
+
handler: (args, ctx) => sendAlias("/skill:2cmd-debt", args, ctx),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
pi.registerCommand("2cmd-help", {
|
|
187
|
+
description: "Run /skill:2cmd-help",
|
|
188
|
+
handler: (args, ctx) => sendAlias("/skill:2cmd-help", args, ctx),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
pi.on("input", async (event, ctx) => {
|
|
192
|
+
if (event?.source === "extension") return;
|
|
193
|
+
|
|
194
|
+
const text = String(event?.text || "");
|
|
195
|
+
if (currentMode !== "off" && isDeactivationCommand(text)) {
|
|
196
|
+
setMode("off", ctx);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const restoreSessionMode = (ctx) => {
|
|
201
|
+
const entries = ctx?.sessionManager?.getBranch?.() || ctx?.sessionManager?.getEntries?.() || [];
|
|
202
|
+
currentMode = resolveSessionMode(entries, configuredDefaultMode);
|
|
203
|
+
syncStatus(ctx);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
207
|
+
configuredDefaultMode = getDefaultMode();
|
|
208
|
+
hideStatus = getHideStatus();
|
|
209
|
+
names = modeNames(getLanguage());
|
|
210
|
+
restoreSessionMode(ctx);
|
|
211
|
+
if (!getQuietStartup()) {
|
|
212
|
+
ctx?.ui?.notify?.(`2Cmd: ${names[currentMode] ?? currentMode}`, "info");
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// Both hosts emit session_tree. Pi re-emits session_start on /new, /resume and
|
|
217
|
+
// /fork; OMP emits session_switch and session_branch instead.
|
|
218
|
+
for (const eventName of ["session_tree", "session_switch", "session_branch"]) {
|
|
219
|
+
pi.on(eventName, async (_event, ctx) => {
|
|
220
|
+
restoreSessionMode(ctx);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
pi.on("agent_start", async (_event, ctx) => {
|
|
225
|
+
isActive = true;
|
|
226
|
+
syncStatus(ctx);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
230
|
+
isActive = false;
|
|
231
|
+
syncStatus(ctx);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
pi.on("before_agent_start", async (event) => {
|
|
235
|
+
if (!currentMode || currentMode === "off") {
|
|
236
|
+
// Clear a stale section when the mode is off so a previous turn does not linger (#953).
|
|
237
|
+
if (event?.systemPromptOptions?.sections) delete event.systemPromptOptions.sections['2cmd'];
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const instructions = get2CmdInstructions(currentMode);
|
|
241
|
+
// Prefer structured sections so Pi can keep the cached prefix when other
|
|
242
|
+
// extensions change their own section (#953). Fall back to replacement
|
|
243
|
+
// for older Pi versions without systemPromptOptions.sections.
|
|
244
|
+
const sections = event?.systemPromptOptions?.sections;
|
|
245
|
+
if (sections && typeof sections === "object") {
|
|
246
|
+
sections['2cmd'] = instructions;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
// OMP passes the system prompt as an array of parts; keep it one (#776).
|
|
250
|
+
if (Array.isArray(event?.systemPrompt)) {
|
|
251
|
+
return { systemPrompt: [...event.systemPrompt, instructions] };
|
|
252
|
+
}
|
|
253
|
+
// Guard a null/undefined event or a missing systemPrompt: don't crash, and
|
|
254
|
+
// don't prepend the literal string "undefined" to the prompt (#439, #440).
|
|
255
|
+
const base = event?.systemPrompt ? `${event.systemPrompt}\n\n` : "";
|
|
256
|
+
return { systemPrompt: `${base}${instructions}` };
|
|
257
|
+
});
|
|
258
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Pi cannot load the TypeScript packs in hooks/band/i18n, so it keeps only the mode names.
|
|
2
|
+
// test/names.test.js checks that they match.
|
|
3
|
+
export const MODE_NAMES = {
|
|
4
|
+
"en": { off: "Off", hindsight: "Hindsight", reuse: "Reuse First", pushback: "Pushback", scout: "Scout" },
|
|
5
|
+
"zh-Hans": { off: "停用", hindsight: "马后炮", reuse: "不造车", pushback: "唱反调", scout: "找对标" },
|
|
6
|
+
"zh-Hant": { off: "停用", hindsight: "馬後炮", reuse: "不造輪子", pushback: "唱反調", scout: "找參考" },
|
|
7
|
+
"ja": { off: "オフ", hindsight: "後出し", reuse: "再利用優先", pushback: "ツッコミ", scout: "参考探し" },
|
|
8
|
+
"ko": { off: "꺼짐", hindsight: "뒷북", reuse: "재사용 우선", pushback: "딴지", scout: "참고 찾기" },
|
|
9
|
+
"es": { off: "Inactivo", hindsight: "Repaso", reuse: "Reutilizar", pushback: "Réplica", scout: "Explorar" },
|
|
10
|
+
"fr": { off: "Inactif", hindsight: "Après-coup", reuse: "Réutiliser", pushback: "Objection", scout: "Repérage" },
|
|
11
|
+
"de": { off: "Aus", hindsight: "Rückblick", reuse: "Nachnutzen", pushback: "Einspruch", scout: "Vorbilder" },
|
|
12
|
+
"pt": { off: "Inativo", hindsight: "Revisão", reuse: "Reusar", pushback: "Objeção", scout: "Explorar" },
|
|
13
|
+
"ru": { off: "Выкл.", hindsight: "Итог", reuse: "Готовое", pushback: "Спор", scout: "Примеры" },
|
|
14
|
+
"vi": { off: "Đã tắt", hindsight: "Góp ý sau", reuse: "Tái sử dụng", pushback: "Phản biện", scout: "Tham khảo" },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// An unknown or missing language falls back to English.
|
|
18
|
+
export const modeNames = (language) =>
|
|
19
|
+
(Object.hasOwn(MODE_NAMES, String(language)) ? MODE_NAMES[language] : MODE_NAMES.en);
|