@2cmddev/2cmd 0.0.0-stage → 0.1.5
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,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 2cmd — Antigravity hook entry (hooks.json at the plugin root runs it for SessionStart and PreInvocation).
|
|
3
|
+
// It hands Antigravity's input to 2Cmd's own hooks and turns their answer into injectSteps.
|
|
4
|
+
// Injected steps stay in the conversation, so rules go in only at the start and when the mode changes.
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { createHash } = require('crypto');
|
|
10
|
+
const { spawnSync } = require('child_process');
|
|
11
|
+
|
|
12
|
+
const none = () => { fs.writeSync(1, '{}'); process.exit(0); };
|
|
13
|
+
|
|
14
|
+
let data;
|
|
15
|
+
try {
|
|
16
|
+
data = JSON.parse(fs.readFileSync(0, 'utf8').replace(/^/, ''));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
none();
|
|
19
|
+
}
|
|
20
|
+
// Only Antigravity's shape: another tool that reads a root hooks.json gets nothing.
|
|
21
|
+
const id = data && data.conversationId;
|
|
22
|
+
if (typeof id !== 'string' || !/^[\w-]{1,100}$/.test(id)) none();
|
|
23
|
+
|
|
24
|
+
const data2cmd = path.join(os.homedir(), '.gemini', '2cmd');
|
|
25
|
+
let script;
|
|
26
|
+
let input;
|
|
27
|
+
if (data.hookEventName === 'SessionStart') {
|
|
28
|
+
// A conversation opened again keeps the mode it had.
|
|
29
|
+
const known = fs.existsSync(path.join(data2cmd, 'live', id + '.json'));
|
|
30
|
+
script = '2cmd-activate.js';
|
|
31
|
+
input = { session_id: id, cwd: data.cwd, source: known ? 'resume' : 'startup' };
|
|
32
|
+
} else if (data.hookEventName === 'PreInvocation') {
|
|
33
|
+
// This runs before every model call, several times in one reply. Each message is looked at once.
|
|
34
|
+
const prompt = typeof data.lastUserInput === 'string' ? data.lastUserInput : '';
|
|
35
|
+
const seen = path.join(data2cmd, 'seen', id);
|
|
36
|
+
const mark = createHash('sha256').update(prompt).digest('hex');
|
|
37
|
+
try {
|
|
38
|
+
if (fs.readFileSync(seen, 'utf8') === mark) none();
|
|
39
|
+
} catch (e) { /* first message */ }
|
|
40
|
+
try {
|
|
41
|
+
fs.mkdirSync(path.dirname(seen), { recursive: true, mode: 0o700 });
|
|
42
|
+
fs.writeFileSync(seen, mark, { mode: 0o600 });
|
|
43
|
+
} catch (e) {
|
|
44
|
+
none(); // without the mark every model call would add the rules again
|
|
45
|
+
}
|
|
46
|
+
script = '2cmd-mode-tracker.js';
|
|
47
|
+
input = { session_id: id, cwd: data.cwd, prompt };
|
|
48
|
+
} else {
|
|
49
|
+
none();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const run = spawnSync(process.execPath, [path.join(__dirname, script)], {
|
|
53
|
+
input: JSON.stringify(input),
|
|
54
|
+
env: { ...process.env, TWOCMD_HOST: 'antigravity' },
|
|
55
|
+
encoding: 'utf8',
|
|
56
|
+
timeout: 10000,
|
|
57
|
+
});
|
|
58
|
+
let context = '';
|
|
59
|
+
try {
|
|
60
|
+
context = JSON.parse(run.stdout).hookSpecificOutput.additionalContext || '';
|
|
61
|
+
} catch (e) { /* nothing to add */ }
|
|
62
|
+
fs.writeSync(1, JSON.stringify(context
|
|
63
|
+
? { injectSteps: [{ systemMessage: { systemMessage: context, metadata: { source: '2cmd' } } }] }
|
|
64
|
+
: {}));
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 2cmd — imports past Claude Code sessions into the band's task ledger, so the board can
|
|
3
|
+
// compare them: cost, agent time, tokens, turns, name and model. Started in the background by
|
|
4
|
+
// `/2cmd band import`; also runs by hand. Sessions already in the ledger are left alone.
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { spawnSync } = require('child_process');
|
|
10
|
+
const { StringDecoder } = require('string_decoder');
|
|
11
|
+
const { getClaudeDir } = require('./2cmd-config');
|
|
12
|
+
|
|
13
|
+
// The band's columns (CSV_HEADER in hooks/band/metrics.ts; a test keeps the two equal).
|
|
14
|
+
const CSV_HEADER = 'key,started,project,name,cost_usd,turns,agent_minutes,tokens_total,tokens_output,reuse_pct,reused,new,callers_open,tests,level,model';
|
|
15
|
+
|
|
16
|
+
// USD per million tokens from https://platform.claude.com/docs/en/about-claude/pricing, checked
|
|
17
|
+
// 2026-10-17: [input, 5-minute cache write, 1-hour cache write, cache read, output]. Opus 5.5 and
|
|
18
|
+
// Fable 5.1 also match Claude Code's own totals in real transcripts. A model missing here, or a
|
|
19
|
+
// fast-mode reply, gets no estimate: an empty cost beats a guessed one.
|
|
20
|
+
const OPUS = [5, 6.25, 10, 0.5, 25];
|
|
21
|
+
const PRICES = {
|
|
22
|
+
'claude-fable-5-1': [10, 12.5, 20, 0.25, 50],
|
|
23
|
+
'claude-fable-5': [10, 12.5, 20, 1, 50],
|
|
24
|
+
'claude-opus-5-5': [4, 5, 8, 0.2, 20],
|
|
25
|
+
'claude-opus-5': OPUS,
|
|
26
|
+
'claude-opus-4-8': OPUS,
|
|
27
|
+
'claude-opus-4-7': OPUS,
|
|
28
|
+
'claude-opus-4-6': OPUS,
|
|
29
|
+
'claude-opus-4-5': OPUS,
|
|
30
|
+
'claude-sonnet-5-5': [2, 2.5, 4, 0.1, 10],
|
|
31
|
+
'claude-sonnet-5': [2, 2.5, 4, 0.2, 10],
|
|
32
|
+
'claude-sonnet-4-6': [3, 3.75, 6, 0.3, 15],
|
|
33
|
+
'claude-sonnet-4-5': [3, 3.75, 6, 0.3, 15],
|
|
34
|
+
'claude-haiku-5-5': [0.1, 0.125, 0.2, 0.01, 0.5],
|
|
35
|
+
'claude-haiku-4-5': [1, 1.25, 2, 0.1, 5],
|
|
36
|
+
};
|
|
37
|
+
// Haiku 5.5 bills a request whose prompt (input, cache reads and writes) is over 100,000 tokens higher.
|
|
38
|
+
const HAIKU_55_LONG = [0.5, 0.625, 1, 0.05, 2.5];
|
|
39
|
+
const WEB_SEARCH = 10 / 1000;
|
|
40
|
+
const IDLE_MS = 30 * 60000;
|
|
41
|
+
const modelId = m => m.replace(/\[.*\]$/, '').replace(/-\d{8}$/, '');
|
|
42
|
+
|
|
43
|
+
// One reply's price from its usage, or null when the price is not known.
|
|
44
|
+
function replyCost(model, u) {
|
|
45
|
+
let p = PRICES[modelId(model)];
|
|
46
|
+
if (!p || u.speed === 'fast') return null;
|
|
47
|
+
const cc = u.cache_creation || {};
|
|
48
|
+
const split = cc.ephemeral_5m_input_tokens !== undefined || cc.ephemeral_1h_input_tokens !== undefined;
|
|
49
|
+
const w5 = split ? cc.ephemeral_5m_input_tokens || 0 : u.cache_creation_input_tokens || 0;
|
|
50
|
+
const w1 = split ? cc.ephemeral_1h_input_tokens || 0 : 0;
|
|
51
|
+
const input = u.input_tokens || 0;
|
|
52
|
+
const read = u.cache_read_input_tokens || 0;
|
|
53
|
+
if (modelId(model) === 'claude-haiku-5-5' && input + read + w5 + w1 > 100000) p = HAIKU_55_LONG;
|
|
54
|
+
const searches = (u.server_tool_use && u.server_tool_use.web_search_requests) || 0;
|
|
55
|
+
return (input * p[0] + w5 * p[1] + w1 * p[2] + read * p[3] + (u.output_tokens || 0) * p[4]) / 1e6 + searches * WEB_SEARCH;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const human = r => r.type === 'user' && (r.turnOrigin === 'human' || (r.origin && r.origin.kind === 'human'));
|
|
59
|
+
const promptText = r => {
|
|
60
|
+
const c = r.message && r.message.content;
|
|
61
|
+
const t = typeof c === 'string' ? c : Array.isArray(c) ? (c.find(b => b && b.type === 'text') || {}).text || '' : '';
|
|
62
|
+
return t.trim();
|
|
63
|
+
};
|
|
64
|
+
const ms = r => (r.timestamp ? Date.parse(r.timestamp) : NaN);
|
|
65
|
+
const toolResult = r => (r.toolResult !== undefined ? r.toolResult
|
|
66
|
+
: Array.isArray(r.message && r.message.content) && r.message.content.some(b => b && b.type === 'tool_result'));
|
|
67
|
+
|
|
68
|
+
// 2Cmd's hooks start their output with the rules they put in, e.g. "TWOCMD MODE ACTIVE — level: reuse" or
|
|
69
|
+
// "TWOCMD MODE OFF"; PONYTAIL is the project 2Cmd grew from. Only hook output counts, not a file or tool
|
|
70
|
+
// result that happens to quote it. Levels from before the rename get their new names.
|
|
71
|
+
const MARK = /(TWOCMD|PONYTAIL) MODE (ACTIVE|CHANGED|OFF)(?: — level: ([a-z]+))?/g;
|
|
72
|
+
const RENAMED = { lite: 'hindsight', full: 'reuse', ultra: 'pushback' };
|
|
73
|
+
const marksOf = r => (r.type === 'attachment' && r.attachment && /^hook/.test(r.attachment.type)
|
|
74
|
+
? [...JSON.stringify(r.attachment).matchAll(MARK)].map(m => (m[1] !== 'TWOCMD' ? 'other' : m[2] === 'OFF' ? 'off' : RENAMED[m[3]] || m[3] || 'reuse'))
|
|
75
|
+
: []);
|
|
76
|
+
|
|
77
|
+
// The session's level for the board: off when 2Cmd never put rules in, else the last level it used. A
|
|
78
|
+
// session that also ran with 2Cmd off, or with the earlier project's rules, is neither: it stays "import".
|
|
79
|
+
function levelOf(records) {
|
|
80
|
+
const marks = records.flatMap(r => r.marks || []);
|
|
81
|
+
if (marks.length === 0) return 'off';
|
|
82
|
+
if (marks.includes('other') || (marks.includes('off') && marks.some(m => m !== 'off'))) return 'import';
|
|
83
|
+
return marks[marks.length - 1];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Only what the numbers need from one record: a long session's transcript can pass 500 MB.
|
|
87
|
+
function slim(r) {
|
|
88
|
+
const m = r.message || {};
|
|
89
|
+
const marks = marksOf(r);
|
|
90
|
+
const c = human(r) ? m.content : undefined;
|
|
91
|
+
const text = typeof c === 'string' ? c.slice(0, 500)
|
|
92
|
+
: Array.isArray(c) ? c.filter(b => b && b.type === 'text').slice(0, 1).map(b => ({ type: 'text', text: String(b.text).slice(0, 500) })) : undefined;
|
|
93
|
+
return {
|
|
94
|
+
type: r.type, timestamp: r.timestamp, turnOrigin: r.turnOrigin, origin: r.origin && { kind: r.origin.kind },
|
|
95
|
+
isMeta: r.isMeta, toolResult: toolResult(r),
|
|
96
|
+
sessionId: r.sessionId, customTitle: r.customTitle, totalCostUSD: r.totalCostUSD, marks: marks.length ? marks : undefined,
|
|
97
|
+
message: { id: m.id, model: m.model, usage: m.usage, content: text },
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// A JSONL file line by line, so no transcript is too big to read (one string stops at 512 MB).
|
|
102
|
+
function readRecords(file) {
|
|
103
|
+
const out = [];
|
|
104
|
+
const take = l => { if (l.startsWith('{')) try { out.push(slim(JSON.parse(l))); } catch (e) {} };
|
|
105
|
+
const fd = fs.openSync(file, 'r');
|
|
106
|
+
const buf = Buffer.alloc(1 << 20);
|
|
107
|
+
const dec = new StringDecoder('utf8');
|
|
108
|
+
let rest = '';
|
|
109
|
+
try {
|
|
110
|
+
for (let n; (n = fs.readSync(fd, buf, 0, buf.length, null)) > 0;) {
|
|
111
|
+
const parts = (rest + dec.write(buf.subarray(0, n))).split('\n');
|
|
112
|
+
rest = parts.pop();
|
|
113
|
+
parts.forEach(take);
|
|
114
|
+
}
|
|
115
|
+
take(rest + dec.end());
|
|
116
|
+
} finally {
|
|
117
|
+
fs.closeSync(fd);
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// One session's numbers from its transcript records and its subagents' records. Null for a session
|
|
123
|
+
// nobody typed into (benchmarks, `claude -p`, scripts) or one without a model reply.
|
|
124
|
+
function sessionStats(records, subagentRecords = [], sessionId = '') {
|
|
125
|
+
const prompts = records.filter(human);
|
|
126
|
+
if (prompts.length === 0) return null;
|
|
127
|
+
|
|
128
|
+
// Usage repeats on every record of one message: count each message id once, subagents included.
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
const replies = {};
|
|
131
|
+
let tokens = 0;
|
|
132
|
+
let output = 0;
|
|
133
|
+
let estimate = 0;
|
|
134
|
+
const reply = r => r.type === 'assistant' && r.message && r.message.model && r.message.model !== '<synthetic>';
|
|
135
|
+
for (const r of records) if (reply(r)) replies[r.message.model] = (replies[r.message.model] || 0) + 1;
|
|
136
|
+
for (const r of [...records, ...subagentRecords]) {
|
|
137
|
+
if (!reply(r)) continue;
|
|
138
|
+
const { id, model, usage } = r.message;
|
|
139
|
+
if (!usage || !id || seen.has(id)) continue;
|
|
140
|
+
seen.add(id);
|
|
141
|
+
tokens += (usage.input_tokens || 0) + (usage.output_tokens || 0) + (usage.cache_read_input_tokens || 0) + (usage.cache_creation_input_tokens || 0);
|
|
142
|
+
output += usage.output_tokens || 0;
|
|
143
|
+
const c = replyCost(model, usage);
|
|
144
|
+
estimate = estimate === null || c === null ? null : estimate + c;
|
|
145
|
+
}
|
|
146
|
+
const models = Object.keys(replies);
|
|
147
|
+
if (models.length === 0) return null;
|
|
148
|
+
|
|
149
|
+
// A turn starts with any new message: a typed prompt, a slash command (not marked as typed) or a
|
|
150
|
+
// background notification. It lasts until the model's last reply or tool result before the next
|
|
151
|
+
// one, so time waiting between messages, even days before a session is reopened, never counts.
|
|
152
|
+
let turns = 0;
|
|
153
|
+
let agentMs = 0;
|
|
154
|
+
const starts = r => r.type === 'user' && !toolResult(r) && !r.isMeta;
|
|
155
|
+
const at = records.map((r, i) => (starts(r) ? i : -1)).filter(i => i >= 0);
|
|
156
|
+
for (let k = 0; k < at.length; k++) {
|
|
157
|
+
const work = records.slice(at[k] + 1, k + 1 < at.length ? at[k + 1] : records.length)
|
|
158
|
+
.filter(r => r.type === 'assistant' || (r.type === 'user' && toolResult(r)));
|
|
159
|
+
if (!work.some(r => r.type === 'assistant')) continue;
|
|
160
|
+
turns++;
|
|
161
|
+
// A pause of over 30 minutes inside a turn is someone not answering a permission prompt, not work.
|
|
162
|
+
// shortcut: a single tool run over 30 minutes counts as zero; raise IDLE_MS if long builds go missing.
|
|
163
|
+
let prev = ms(records[at[k]]);
|
|
164
|
+
for (const t of work.map(ms).filter(Number.isFinite)) {
|
|
165
|
+
if (Number.isFinite(prev) && t > prev && t - prev <= IDLE_MS) agentMs += t - prev;
|
|
166
|
+
prev = Math.max(Number.isFinite(prev) ? prev : t, t);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (turns === 0) return null;
|
|
170
|
+
|
|
171
|
+
// Two sources, and each can only miss calls: Claude Code's own total covers just its last
|
|
172
|
+
// process run (a reopened session can say $0), the estimate misses side calls the transcript
|
|
173
|
+
// does not log (titles, compaction, internal Haiku). So the larger one wins.
|
|
174
|
+
// shortcut: without an own total the estimate runs 0-15% low in real sessions; nothing better is logged.
|
|
175
|
+
const last = (a, f) => { for (let i = a.length - 1; i >= 0; i--) if (f(a[i])) return i; return -1; };
|
|
176
|
+
const costAt = last(records, r => r.type === 'cost-state' && (!sessionId || r.sessionId === sessionId));
|
|
177
|
+
const own = costAt >= 0 && last(records, r => r.type === 'assistant') < costAt ? records[costAt].totalCostUSD : null;
|
|
178
|
+
const known = [own, estimate].filter(v => typeof v === 'number' && Number.isFinite(v) && v > 0);
|
|
179
|
+
const cost = known.length ? Math.max(...known) : null;
|
|
180
|
+
const titled = records.filter(r => r.type === 'custom-title' && typeof r.customTitle === 'string' && r.customTitle.trim());
|
|
181
|
+
const first = prompts.map(promptText).find(t => t && !t.startsWith('<') && !t.startsWith('/')) || '';
|
|
182
|
+
const started = records.map(ms).find(Number.isFinite);
|
|
183
|
+
return {
|
|
184
|
+
startedMs: started,
|
|
185
|
+
name: (titled.length ? titled[titled.length - 1].customTitle.trim() : first.split('\n')[0]).slice(0, 60),
|
|
186
|
+
model: models.sort((a, b) => replies[b] - replies[a])[0],
|
|
187
|
+
cost,
|
|
188
|
+
own,
|
|
189
|
+
estimate,
|
|
190
|
+
turns,
|
|
191
|
+
agentMs,
|
|
192
|
+
tokens,
|
|
193
|
+
output,
|
|
194
|
+
level: levelOf(records),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Same stamp and quoting as the band (hooks/band/metrics.ts), so the board reads both alike.
|
|
199
|
+
const two = n => String(n).padStart(2, '0');
|
|
200
|
+
const stamp = t => { const d = new Date(t); return `${d.getFullYear()}-${two(d.getMonth() + 1)}-${two(d.getDate())} ${two(d.getHours())}:${two(d.getMinutes())}`; };
|
|
201
|
+
const field = v => { const s = v === null || v === undefined ? '' : String(v); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; };
|
|
202
|
+
|
|
203
|
+
function csvRow(sessionId, project, s) {
|
|
204
|
+
return [`${sessionId.slice(0, 8)}-${s.startedMs}`, stamp(s.startedMs), project, s.name, s.cost === null ? '' : s.cost.toFixed(2), s.turns,
|
|
205
|
+
(s.agentMs / 60000).toFixed(1), s.tokens, s.output, '', '', '', '', '', s.level || 'import', s.model].map(field).join(',');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// New rows go in after the ledger's own: a newer header replaces an older one, and a session
|
|
209
|
+
// already recorded anywhere in the ledger (same session id prefix) is never imported twice. A row an
|
|
210
|
+
// earlier import marked "import" (2Cmd on or off unknown) is the one exception: it is imported again.
|
|
211
|
+
const sessionOf = row => row.slice(0, 9);
|
|
212
|
+
// The level is the field before the model, and a model id has no comma.
|
|
213
|
+
const unknownLevel = row => row.split(',').at(-2) === 'import';
|
|
214
|
+
function mergeRows(existing, rows, have = new Set()) {
|
|
215
|
+
const lines = existing.split('\n').filter(l => l !== '' && !l.startsWith('key,'));
|
|
216
|
+
const known = lines.filter(l => !unknownLevel(l));
|
|
217
|
+
const added = rows.filter(r => !have.has(sessionOf(r)) && !known.some(l => sessionOf(l) === sessionOf(r)));
|
|
218
|
+
const redone = new Set(added.map(sessionOf));
|
|
219
|
+
const kept = lines.filter(l => !redone.has(sessionOf(l)));
|
|
220
|
+
const fresh = added.filter(r => !lines.some(l => sessionOf(l) === sessionOf(r) && l === r)).length;
|
|
221
|
+
return { text: [CSV_HEADER, ...kept, ...added].join('\n') + '\n', added: fresh };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const TEMP = [os.tmpdir(), '/tmp/', '/private/tmp/', '/var/folders/', '/private/var/folders/'];
|
|
225
|
+
// A worktree counts for its main repo: the desktop app's <repo>/.claude/worktrees/<name> even
|
|
226
|
+
// after it is gone, and any git worktree through its common .git dir.
|
|
227
|
+
function projectOf(cwd, cache) {
|
|
228
|
+
if (!cache.has(cwd)) {
|
|
229
|
+
let root = cwd.split(/[\\/]\.claude[\\/]worktrees[\\/]/)[0];
|
|
230
|
+
if (fs.existsSync(root)) {
|
|
231
|
+
const git = spawnSync('git', ['-C', root, 'rev-parse', '--path-format=absolute', '--git-common-dir'], { encoding: 'utf8' });
|
|
232
|
+
if (git.status === 0 && /[\\/]\.git$/.test(git.stdout.trim())) root = path.dirname(git.stdout.trim());
|
|
233
|
+
}
|
|
234
|
+
cache.set(cwd, path.basename(root.replace(/[\\/]+$/, '')));
|
|
235
|
+
}
|
|
236
|
+
return cache.get(cwd);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function ledgerDir() {
|
|
240
|
+
return path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), '2cmd', 'band');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function run() {
|
|
244
|
+
const root = path.join(getClaudeDir(), 'projects');
|
|
245
|
+
const byProject = new Map();
|
|
246
|
+
const roots = new Map();
|
|
247
|
+
let dirs = [];
|
|
248
|
+
try { dirs = fs.readdirSync(root); } catch (e) { return { sessions: 0, added: 0 }; }
|
|
249
|
+
let sessions = 0;
|
|
250
|
+
for (const dir of dirs) {
|
|
251
|
+
let files = [];
|
|
252
|
+
try { files = fs.readdirSync(path.join(root, dir)).filter(f => f.endsWith('.jsonl')); } catch (e) { continue; }
|
|
253
|
+
for (const file of files) {
|
|
254
|
+
const p = path.join(root, dir, file);
|
|
255
|
+
// The working dir sits in the first records; scratch and temp dirs are never real projects.
|
|
256
|
+
let head = '';
|
|
257
|
+
try { const fd = fs.openSync(p, 'r'); const b = Buffer.alloc(65536); head = b.toString('utf8', 0, fs.readSync(fd, b, 0, b.length, 0)); fs.closeSync(fd); } catch (e) { continue; }
|
|
258
|
+
const m = /"cwd":"((?:[^"\\]|\\.)*)"/.exec(head);
|
|
259
|
+
if (!m) continue;
|
|
260
|
+
const cwd = JSON.parse(`"${m[1]}"`);
|
|
261
|
+
if (TEMP.some(t => cwd.startsWith(t)) || cwd === '/tmp') continue;
|
|
262
|
+
// A session's first prompt is typed by a person; automated runs (benchmarks, `claude -p`) never are.
|
|
263
|
+
if (head.includes('"type":"user"') && !/"turnOrigin":"human"|"origin":\{"kind":"human"/.test(head)) continue;
|
|
264
|
+
const id = file.slice(0, -'.jsonl'.length);
|
|
265
|
+
let records;
|
|
266
|
+
try { records = readRecords(p); } catch (e) { continue; }
|
|
267
|
+
const sub = path.join(root, dir, id, 'subagents');
|
|
268
|
+
let subRecords = [];
|
|
269
|
+
try {
|
|
270
|
+
subRecords = fs.readdirSync(sub).filter(f => /^agent-.*\.jsonl$/.test(f)).flatMap(f => {
|
|
271
|
+
try { return readRecords(path.join(sub, f)); } catch (e) { return []; }
|
|
272
|
+
});
|
|
273
|
+
} catch (e) {}
|
|
274
|
+
const stats = sessionStats(records, subRecords, id);
|
|
275
|
+
if (!stats || !Number.isFinite(stats.startedMs)) continue;
|
|
276
|
+
sessions++;
|
|
277
|
+
const project = projectOf(cwd, roots);
|
|
278
|
+
if (!byProject.has(project)) byProject.set(project, []);
|
|
279
|
+
byProject.get(project).push(csvRow(id, project, stats));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const dir = ledgerDir();
|
|
283
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
284
|
+
const have = new Set();
|
|
285
|
+
for (const f of fs.readdirSync(dir).filter(f => f.endsWith('.csv'))) {
|
|
286
|
+
try { fs.readFileSync(path.join(dir, f), 'utf8').split('\n').forEach(l => l && !l.startsWith('key,') && !unknownLevel(l) && have.add(sessionOf(l))); } catch (e) {}
|
|
287
|
+
}
|
|
288
|
+
let added = 0;
|
|
289
|
+
for (const [project, rows] of byProject) {
|
|
290
|
+
const file = path.join(dir, `${project.replace(/[^\w.-]/g, '_')}.csv`);
|
|
291
|
+
let existing = '';
|
|
292
|
+
try { existing = fs.readFileSync(file, 'utf8'); } catch (e) {}
|
|
293
|
+
const merged = mergeRows(existing, rows, have);
|
|
294
|
+
if (merged.added > 0) fs.writeFileSync(file, merged.text);
|
|
295
|
+
added += merged.added;
|
|
296
|
+
}
|
|
297
|
+
return { sessions, added };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (require.main === module) {
|
|
301
|
+
const { sessions, added } = run();
|
|
302
|
+
process.stdout.write(`2cmd band import: ${sessions} past sessions found, ${added} new rows in the board.\n`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
module.exports = { CSV_HEADER, PRICES, replyCost, sessionStats, csvRow, mergeRows, readRecords, run };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 2cmd — shared configuration resolver
|
|
3
|
+
//
|
|
4
|
+
// Resolution order for default mode:
|
|
5
|
+
// 1. TWOCMD_DEFAULT_MODE environment variable
|
|
6
|
+
// 2. Config file defaultMode field:
|
|
7
|
+
// - $XDG_CONFIG_HOME/2cmd/config.json (any platform, if set)
|
|
8
|
+
// - ~/.config/2cmd/config.json (macOS / Linux fallback)
|
|
9
|
+
// - %APPDATA%\2cmd\config.json (Windows fallback)
|
|
10
|
+
// 3. 'reuse'
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const os = require('os');
|
|
15
|
+
|
|
16
|
+
const DEFAULT_MODE = 'reuse';
|
|
17
|
+
const RUNTIME_MODES = ['off', 'hindsight', 'reuse', 'pushback', 'scout'];
|
|
18
|
+
const VALID_MODES = [...RUNTIME_MODES, 'review'];
|
|
19
|
+
|
|
20
|
+
function normalizeMode(mode) {
|
|
21
|
+
if (typeof mode !== 'string') return null;
|
|
22
|
+
const normalized = mode.trim().toLowerCase();
|
|
23
|
+
return RUNTIME_MODES.includes(normalized) ? normalized : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function normalizeConfigMode(mode) {
|
|
27
|
+
if (typeof mode !== 'string') return null;
|
|
28
|
+
const normalized = mode.trim().toLowerCase();
|
|
29
|
+
return VALID_MODES.includes(normalized) ? normalized : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizePersistedMode(mode) {
|
|
33
|
+
return normalizeMode(mode) || normalizeConfigMode(mode);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// "stop 2cmd" / "normal mode" turn 2cmd off, but only as a standalone
|
|
37
|
+
// command. Matching the phrase anywhere in the message turned it off mid-task
|
|
38
|
+
// for ordinary requests like "add a normal mode toggle" — so require the whole
|
|
39
|
+
// message to be the command, ignoring case and trailing punctuation.
|
|
40
|
+
function isDeactivationCommand(text) {
|
|
41
|
+
const t = String(text || '').trim().toLowerCase().replace(/[.!?\s]+$/, '');
|
|
42
|
+
return t === 'stop 2cmd' || t === 'normal mode';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 2cmd: only embed the plugin install path in a statusline shell command when
|
|
46
|
+
// it's made of ordinary path characters. An allowlist beats escaping every shell's
|
|
47
|
+
// metacharacters; a hostile clone path (quotes, &, $, backtick, ;, etc.) falls back
|
|
48
|
+
// to manual setup instead. Allows : \ / for normal Windows and POSIX paths. Full
|
|
49
|
+
// per-shell escaper only if a real need appears.
|
|
50
|
+
function isShellSafe(p) {
|
|
51
|
+
return typeof p === 'string' && /^[A-Za-z0-9 _.\-:/\\~]+$/.test(p);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getConfigDir() {
|
|
55
|
+
if (process.env.XDG_CONFIG_HOME) {
|
|
56
|
+
return path.join(process.env.XDG_CONFIG_HOME, '2cmd');
|
|
57
|
+
}
|
|
58
|
+
if (process.platform === 'win32') {
|
|
59
|
+
return path.join(
|
|
60
|
+
process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'),
|
|
61
|
+
'2cmd'
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return path.join(os.homedir(), '.config', '2cmd');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getConfigPath() {
|
|
68
|
+
return path.join(getConfigDir(), 'config.json');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getClaudeDir() {
|
|
72
|
+
// 2cmd: CLAUDE_CONFIG_DIR overrides ~/.claude, matching Claude Code.
|
|
73
|
+
return process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getQoderDir() {
|
|
77
|
+
return process.env.QODER_CONFIG_DIR || path.join(os.homedir(), '.qoder');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getDefaultMode() {
|
|
81
|
+
// 1. Environment variable (highest priority)
|
|
82
|
+
// 2cmd: a default must be a runtime level (off/hindsight/reuse/pushback/scout); review is
|
|
83
|
+
// a session-only mode, never a valid default (#377). Normalize here so values
|
|
84
|
+
// with whitespace or mixed casing still resolve correctly.
|
|
85
|
+
const envMode = normalizeMode(process.env.TWOCMD_DEFAULT_MODE);
|
|
86
|
+
if (envMode) {
|
|
87
|
+
return envMode;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 2. Config file
|
|
91
|
+
try {
|
|
92
|
+
const configPath = getConfigPath();
|
|
93
|
+
// Strip UTF-8 BOM (common on Windows-saved files) so JSON.parse doesn't choke
|
|
94
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, ''));
|
|
95
|
+
const configMode = normalizeMode(config.defaultMode);
|
|
96
|
+
if (configMode) {
|
|
97
|
+
return configMode;
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
// Config file doesn't exist or is invalid — fall through
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 3. Default
|
|
104
|
+
return DEFAULT_MODE;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Silence the pi "2Cmd loaded" startup toast while keeping 2cmd active.
|
|
108
|
+
// TWOCMD_QUIET_STARTUP=1 (or any truthy value; 0/false/empty mean "show it")
|
|
109
|
+
// takes precedence, else config.quietStartup === true. Mirrors getHideStatus.
|
|
110
|
+
function getQuietStartup() {
|
|
111
|
+
const env = process.env.TWOCMD_QUIET_STARTUP;
|
|
112
|
+
if (env !== undefined) {
|
|
113
|
+
const v = env.trim().toLowerCase();
|
|
114
|
+
return v !== '' && v !== '0' && v !== 'false' && v !== 'no';
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const config = JSON.parse(fs.readFileSync(getConfigPath(), 'utf8').replace(/^\uFEFF/, ''));
|
|
118
|
+
return config.quietStartup === true;
|
|
119
|
+
} catch (_) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Hide the status-bar indicator while keeping 2cmd active (#324).
|
|
125
|
+
// TWOCMD_HIDE_STATUS=1 (or any truthy value; 0/false/empty mean "don't hide")
|
|
126
|
+
// takes precedence, else config.hideStatus === true.
|
|
127
|
+
function getHideStatus() {
|
|
128
|
+
const env = process.env.TWOCMD_HIDE_STATUS;
|
|
129
|
+
if (env !== undefined) {
|
|
130
|
+
const v = env.trim().toLowerCase();
|
|
131
|
+
return v !== '' && v !== '0' && v !== 'false' && v !== 'no';
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const config = JSON.parse(fs.readFileSync(getConfigPath(), 'utf8').replace(/^\uFEFF/, ''));
|
|
135
|
+
return config.hideStatus === true;
|
|
136
|
+
} catch (_) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Language of the Pi status: TWOCMD_LANGUAGE, else config.language. Claude Code has its own plugin setting.
|
|
142
|
+
function getLanguage() {
|
|
143
|
+
if (process.env.TWOCMD_LANGUAGE !== undefined) return process.env.TWOCMD_LANGUAGE.trim();
|
|
144
|
+
try {
|
|
145
|
+
return JSON.parse(fs.readFileSync(getConfigPath(), 'utf8').replace(/^\uFEFF/, '')).language;
|
|
146
|
+
} catch (_) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function writeDefaultMode(mode) {
|
|
152
|
+
// 2cmd: only a runtime level can be a default; review is session-only (#377).
|
|
153
|
+
const normalized = normalizeMode(mode);
|
|
154
|
+
if (!normalized) return null;
|
|
155
|
+
|
|
156
|
+
const configPath = getConfigPath();
|
|
157
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
158
|
+
let config = {};
|
|
159
|
+
try {
|
|
160
|
+
config = JSON.parse(fs.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, ''));
|
|
161
|
+
if (!config || typeof config !== 'object' || Array.isArray(config)) config = {};
|
|
162
|
+
} catch (_) {}
|
|
163
|
+
config.defaultMode = normalized;
|
|
164
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8');
|
|
165
|
+
return normalized;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = {
|
|
169
|
+
DEFAULT_MODE,
|
|
170
|
+
VALID_MODES,
|
|
171
|
+
RUNTIME_MODES,
|
|
172
|
+
getDefaultMode,
|
|
173
|
+
getConfigDir,
|
|
174
|
+
getConfigPath,
|
|
175
|
+
getClaudeDir,
|
|
176
|
+
getQoderDir,
|
|
177
|
+
getHideStatus,
|
|
178
|
+
getLanguage,
|
|
179
|
+
getQuietStartup,
|
|
180
|
+
isShellSafe,
|
|
181
|
+
normalizeMode,
|
|
182
|
+
normalizeConfigMode,
|
|
183
|
+
normalizePersistedMode,
|
|
184
|
+
isDeactivationCommand,
|
|
185
|
+
writeDefaultMode,
|
|
186
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Shared 2Cmd instruction builder for Claude hooks and Pi extension.
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { DEFAULT_MODE, normalizeMode, normalizePersistedMode } = require('./2cmd-config');
|
|
7
|
+
|
|
8
|
+
const INDEPENDENT_MODES = new Set(['review']);
|
|
9
|
+
// hindsight leaves the work alone, so it gets only this rule. Picking a level with a command loads all of
|
|
10
|
+
// SKILL.md, so the hindsight row there must match.
|
|
11
|
+
const HINDSIGHT_RULE = "Do not use the other rules of this skill, including any loaded earlier in this session. Do the task the way you would without this skill. When it is done, briefly list improvements worth making and any leaner option. Do not apply them: the user decides. If nothing is worth changing, say nothing. Subagents only do the task and make no suggestions.";
|
|
12
|
+
const SKILL_PATH = path.join(__dirname, '..', 'skills', '2cmd', 'SKILL.md');
|
|
13
|
+
|
|
14
|
+
function filterSkillBodyForMode(body, mode) {
|
|
15
|
+
const effectiveMode = normalizeMode(mode) || DEFAULT_MODE;
|
|
16
|
+
const withoutFrontmatter = String(body || '').replace(/^---[\s\S]*?---\s*/, '');
|
|
17
|
+
|
|
18
|
+
// Only the intensity table rows and worked examples are mode-specific, and
|
|
19
|
+
// both are keyed by a mode name (hindsight/reuse/pushback/scout). A bullet whose label is
|
|
20
|
+
// not a mode — e.g. "No unrequested abstractions: ..." — is a normal rule
|
|
21
|
+
// and must be kept verbatim.
|
|
22
|
+
return withoutFrontmatter
|
|
23
|
+
.split(/\r?\n/)
|
|
24
|
+
.filter((line) => {
|
|
25
|
+
const tableLabel = line.match(/^\|\s*\*\*(.+?)\*\*\s*\|/);
|
|
26
|
+
if (tableLabel) {
|
|
27
|
+
const labelMode = normalizeMode(tableLabel[1].trim());
|
|
28
|
+
if (labelMode) return labelMode === effectiveMode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Require a quoted value: every worked example is `- hindsight: "..."`. Without
|
|
32
|
+
// this, an ordinary rule bullet that happens to start with a mode word
|
|
33
|
+
// (e.g. "- Reuse: ...") is silently dropped in every other mode — it looks
|
|
34
|
+
// like a worked example but is really prose meant to survive verbatim.
|
|
35
|
+
const exampleLabel = line.match(/^-\s*([^:]+):\s*"/);
|
|
36
|
+
if (exampleLabel) {
|
|
37
|
+
const labelMode = normalizeMode(exampleLabel[1].trim());
|
|
38
|
+
if (labelMode) return labelMode === effectiveMode;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
})
|
|
43
|
+
.join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getFallbackInstructions(mode) {
|
|
47
|
+
// Used only when SKILL.md cannot be read: the same rules as AGENTS.md.
|
|
48
|
+
return 'TWOCMD MODE ACTIVE — level: ' + mode + '\n\n' +
|
|
49
|
+
'Switch level: `/2cmd hindsight|reuse|pushback|scout`. Off: "stop 2cmd" or "normal mode".\n\n' +
|
|
50
|
+
"You are a lazy senior developer. The best code is the code never written. You solve the whole problem with the least new code. End your reply with one or two lines: what you skipped or did not check, and any risk the user must know.\n" +
|
|
51
|
+
"\n" +
|
|
52
|
+
"Reply in the user's language, including reports and their headings. Keep code, commands and file names as they are.\n" +
|
|
53
|
+
"\n" +
|
|
54
|
+
"## Before you write\n" +
|
|
55
|
+
"\n" +
|
|
56
|
+
"Read the task and the code it touches. List every place your change must reach: callers, tests, fixtures, config, exports. Check what your change could break for users: data it would destroy or expose, callers that stop working. That is scope. Extra features are not.\n" +
|
|
57
|
+
"\n" +
|
|
58
|
+
"If the session start gave a snapshot (Git, Checks, Top level, codebase map), use it instead of running `ls` or `git status` again. Reads, searches and checks that do not depend on each other go in one turn; checks that write the same files or use the same port run one after another.\n" +
|
|
59
|
+
"\n" +
|
|
60
|
+
"## The smallest complete change\n" +
|
|
61
|
+
"\n" +
|
|
62
|
+
"Take the first option that fully works:\n" +
|
|
63
|
+
"\n" +
|
|
64
|
+
"1. Does it need to exist? Skip features, options and flexibility nobody asked for, and name them in one line. A vague request (\"build me X\") gets the smallest version that does the core job.\n" +
|
|
65
|
+
"2. Already in this codebase (a helper, component, service, pattern)? Use it the way the surrounding code does.\n" +
|
|
66
|
+
"3. Standard library or a platform feature? Use it, unless the project has its own. A house component beats a native widget.\n" +
|
|
67
|
+
"4. An installed dependency? Use it. Never add a dependency for a few lines.\n" +
|
|
68
|
+
"5. Can it be one line a reader gets at a glance? One line.\n" +
|
|
69
|
+
"6. Otherwise: the minimum code that works.\n" +
|
|
70
|
+
"\n" +
|
|
71
|
+
"- No abstraction, wrapper, type conversion, option, config, boilerplate or \"for later\" code nobody asked for. Keep values in the form the platform already gives you. Deletion beats addition. Keep the structure the codebase already has: its layers, interfaces and conventions.\n" +
|
|
72
|
+
"- The shortest working diff wins, once you know everything it must touch. A one-liner that needs decoding is not short.\n" +
|
|
73
|
+
"- Comment only the why the code cannot show, in one line.\n" +
|
|
74
|
+
"- Lazy code without its check is unfinished: new non-trivial logic (a branch, a loop, a parser, money or security, or a whole new script or app) leaves one small test or an assert-based self-check. Trivial changes need none.\n" +
|
|
75
|
+
"- A shortcut with a known limit gets a code comment in this form: `shortcut: <the limit>, <when to upgrade>`.\n" +
|
|
76
|
+
"- A subagent may not see these rules: when you hand it coding work, put them in its brief: the smallest complete change, reuse what the codebase has, nothing nobody asked for.\n" +
|
|
77
|
+
"\n" +
|
|
78
|
+
"Never cut: validation at trust boundaries, error handling that prevents data loss, security, accessibility, the calibration real hardware needs, anything the user asked for.\n";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function get2CmdInstructions(mode) {
|
|
82
|
+
const configuredMode = normalizePersistedMode(mode) || DEFAULT_MODE;
|
|
83
|
+
|
|
84
|
+
if (INDEPENDENT_MODES.has(configuredMode)) {
|
|
85
|
+
return 'TWOCMD MODE ACTIVE — level: ' + configuredMode + '. Behavior defined by /2cmd-' + configuredMode + ' skill.';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const effectiveMode = normalizeMode(configuredMode) || DEFAULT_MODE;
|
|
89
|
+
|
|
90
|
+
if (effectiveMode === 'hindsight') return 'TWOCMD MODE ACTIVE — level: hindsight\n\n' + HINDSIGHT_RULE;
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
return 'TWOCMD MODE ACTIVE — level: ' + effectiveMode + '\n\n' +
|
|
94
|
+
filterSkillBodyForMode(fs.readFileSync(SKILL_PATH, 'utf8'), effectiveMode);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return getFallbackInstructions(effectiveMode);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = {
|
|
101
|
+
filterSkillBodyForMode,
|
|
102
|
+
getFallbackInstructions,
|
|
103
|
+
get2CmdInstructions,
|
|
104
|
+
};
|