codemini-cli 0.5.10 → 0.5.12
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/OPERATIONS.md +242 -242
- package/README.md +588 -588
- package/codemini-web/dist/assets/{highlighted-body-OFNGDK62-7HL7yft8.js → highlighted-body-OFNGDK62-B-G99D0A.js} +1 -1
- package/codemini-web/dist/assets/{index-BK75hMb2.js → index-DIGUEzan.js} +108 -108
- package/codemini-web/dist/assets/index-Dkq1DdDX.css +2 -0
- package/codemini-web/dist/assets/mermaid-GHXKKRXX-va2Kl89u.js +1 -0
- package/codemini-web/dist/index.html +35 -23
- package/codemini-web/lib/approval-manager.js +32 -32
- package/codemini-web/lib/runtime-bridge.js +17 -11
- package/codemini-web/server.js +534 -205
- package/deployment.md +212 -212
- package/package.json +2 -2
- package/skills/brainstorm/SKILL.md +77 -77
- package/skills/codemini.skills.json +40 -40
- package/skills/grill-me/SKILL.md +30 -30
- package/skills/superpowers-lite/SKILL.md +82 -82
- package/src/cli.js +74 -74
- package/src/commands/chat.js +210 -210
- package/src/commands/run.js +313 -313
- package/src/commands/skill.js +438 -304
- package/src/commands/web.js +57 -57
- package/src/core/agent-loop.js +980 -980
- package/src/core/ast.js +309 -307
- package/src/core/chat-runtime.js +6261 -6253
- package/src/core/command-evaluator.js +72 -72
- package/src/core/command-loader.js +311 -311
- package/src/core/command-policy.js +301 -301
- package/src/core/command-risk.js +156 -156
- package/src/core/config-store.js +286 -285
- package/src/core/constants.js +18 -1
- package/src/core/context-compact.js +365 -365
- package/src/core/default-system-prompt.js +114 -107
- package/src/core/dream-audit.js +105 -105
- package/src/core/dream-consolidate.js +229 -229
- package/src/core/dream-evaluator.js +185 -185
- package/src/core/fff-adapter.js +383 -383
- package/src/core/memory-store.js +543 -543
- package/src/core/project-index.js +737 -548
- package/src/core/project-instructions.js +98 -98
- package/src/core/provider/anthropic.js +514 -514
- package/src/core/provider/openai-compatible.js +501 -501
- package/src/core/reflect-skill.js +178 -178
- package/src/core/reply-language.js +40 -40
- package/src/core/session-store.js +474 -474
- package/src/core/shell-profile.js +237 -237
- package/src/core/shell.js +323 -323
- package/src/core/soul.js +69 -69
- package/src/core/system-prompt-composer.js +52 -52
- package/src/core/tool-args.js +199 -154
- package/src/core/tool-output.js +184 -184
- package/src/core/tool-result-store.js +206 -206
- package/src/core/tools.js +3024 -2893
- package/src/core/version.js +11 -11
- package/src/tui/chat-app.js +5173 -5171
- package/src/tui/tool-activity/presenters/misc.js +30 -30
- package/src/tui/tool-activity/presenters/system.js +20 -20
- package/templates/project-requirements/report-shell.html +582 -582
- package/codemini-web/dist/assets/index-BSdIdn3L.css +0 -2
- package/codemini-web/dist/assets/mermaid-GHXKKRXX-Dg9qh8mg.js +0 -1
package/src/core/command-risk.js
CHANGED
|
@@ -1,156 +1,156 @@
|
|
|
1
|
-
import { collectCommandTokens, firstToken } from './command-policy.js';
|
|
2
|
-
|
|
3
|
-
/* ── 只读命令 token ───────────────────────────────────────────── */
|
|
4
|
-
export const READ_ONLY_TOKENS = new Set([
|
|
5
|
-
'ls', 'cat', 'head', 'tail', 'pwd', 'wc', 'sort', 'uniq',
|
|
6
|
-
'cut', 'tr', 'basename', 'dirname', 'test', 'true', 'false',
|
|
7
|
-
'whoami', 'uname', 'date', 'env', 'printenv', 'hostname',
|
|
8
|
-
'rg', 'find', 'grep', 'ag', 'ack', 'fd', 'bat',
|
|
9
|
-
'get-childitem', 'get-content', 'get-location', 'get-command', 'get-help',
|
|
10
|
-
'get-item', 'get-process', 'select-string', 'select-object', 'where-object',
|
|
11
|
-
'foreach-object', 'measure-object', 'sort-object', 'compare-object',
|
|
12
|
-
'resolve-path', 'test-path',
|
|
13
|
-
'git', 'node', 'npm', 'npx', 'python', 'python3', 'py', 'pip', 'pip3',
|
|
14
|
-
'echo', 'printf', 'seq', 'yes'
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
export function getReadOnlyCommandTokens() {
|
|
18
|
-
return [...READ_ONLY_TOKENS].sort();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/* 只读时需要检查子命令的 token */
|
|
22
|
-
const READ_ONLY_SUBCOMMANDS = {
|
|
23
|
-
git: new Set([
|
|
24
|
-
'status', 'log', 'diff', 'branch', 'show', 'tag', 'stash',
|
|
25
|
-
'list', 'remote', 'rev-parse', 'describe', 'blame',
|
|
26
|
-
'shortlog', 'count', 'ls-files', 'ls-remote', 'ls-tree',
|
|
27
|
-
'config', '--version', 'var', 'for-each-ref', 'name-rev',
|
|
28
|
-
'merge-base', 'cherry'
|
|
29
|
-
]),
|
|
30
|
-
node: new Set(['--version', '-v', '-e', '--eval', '--print', '-p', '--help']),
|
|
31
|
-
npm: new Set([
|
|
32
|
-
'--version', '-v', 'view', 'info', 'list', 'ls', 'll', 'la',
|
|
33
|
-
'outdated', 'audit', 'pack', 'cache', 'config', 'doctor',
|
|
34
|
-
'help', 'explore', 'run', 'run-script', 'start', 'test',
|
|
35
|
-
'restart', 'stop', 'version', 'whoami'
|
|
36
|
-
]),
|
|
37
|
-
npx: new Set(['--version', '-v', '--help']),
|
|
38
|
-
python: new Set(['--version', '-V', '--help', '-c', '-m']),
|
|
39
|
-
python3: new Set(['--version', '-V', '--help', '-c', '-m']),
|
|
40
|
-
py: new Set(['--version', '-V', '--help', '-c', '-m']),
|
|
41
|
-
pip: new Set(['--version', '-V', 'list', 'show', 'search', 'check', 'debug', 'help']),
|
|
42
|
-
pip3: new Set(['--version', '-V', 'list', 'show', 'search', 'check', 'debug', 'help'])
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/* ── 高风险 pattern ────────────────────────────────────────────── */
|
|
46
|
-
const HIGH_RISK_PATTERNS = [
|
|
47
|
-
/\binstall\b/i,
|
|
48
|
-
/\bpublish\b/i,
|
|
49
|
-
/\bpush\b/i,
|
|
50
|
-
/\bcommit\b/i,
|
|
51
|
-
/\brebase\b/i,
|
|
52
|
-
/\breset\s/i,
|
|
53
|
-
/\bcheckout\s+--/i,
|
|
54
|
-
/\brm\b/i,
|
|
55
|
-
/\bdel\b/i,
|
|
56
|
-
/\bmkdi[ri]\b/i,
|
|
57
|
-
/\btouch\b/i,
|
|
58
|
-
/\bcp\b/i,
|
|
59
|
-
/\bmv\b/i,
|
|
60
|
-
/\bchmod\b/i,
|
|
61
|
-
/\bchown\b/i,
|
|
62
|
-
/\bmktemp\b/i,
|
|
63
|
-
/\btee\b/i,
|
|
64
|
-
/\bsudo\b/i,
|
|
65
|
-
/\bsu\b/,
|
|
66
|
-
/\bkill\b/i,
|
|
67
|
-
/\bpkill\b/i,
|
|
68
|
-
/\bcurl\s+.*-[A-Z]\s*(POST|PUT|DELETE|PATCH)/i,
|
|
69
|
-
/\bwget\b/i,
|
|
70
|
-
/\bdocker\s+(rm|stop|kill|rmi)\b/i,
|
|
71
|
-
/\bsystemctl\b/i,
|
|
72
|
-
/\bservice\b/i,
|
|
73
|
-
/\blaunchctl\b/i,
|
|
74
|
-
/>\s*\S/,
|
|
75
|
-
/>>\s*\S/,
|
|
76
|
-
/\|&\s*\S/
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
/* ── 核心分类逻辑 ──────────────────────────────────────────────── */
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 判断单个 token 是否为只读命令(含子命令检查)。
|
|
83
|
-
*/
|
|
84
|
-
function isReadOnlyToken(token, rawSegment) {
|
|
85
|
-
if (!READ_ONLY_TOKENS.has(token)) return false;
|
|
86
|
-
|
|
87
|
-
/* 需要 子命令 校验的 token */
|
|
88
|
-
const allowedSubs = READ_ONLY_SUBCOMMANDS[token];
|
|
89
|
-
if (!allowedSubs) return true; // 如 ls, pwd 等本身只读
|
|
90
|
-
|
|
91
|
-
/* 提取子命令:去掉 token 后第一个非 flag 参数 */
|
|
92
|
-
const rest = String(rawSegment || '').trim().slice(token.length).trim();
|
|
93
|
-
const parts = rest.split(/\s+/).filter(Boolean);
|
|
94
|
-
/* 以 - 开头的 flag 视为安全,取第一个非 flag 参数 */
|
|
95
|
-
let subcmd = '';
|
|
96
|
-
for (const part of parts) {
|
|
97
|
-
if (part.startsWith('-')) continue;
|
|
98
|
-
subcmd = part;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
/* 只有 token 本身或全部是 flags → 视为安全 */
|
|
102
|
-
if (!subcmd) return true;
|
|
103
|
-
if (allowedSubs.has(subcmd)) return true;
|
|
104
|
-
/* 子命令 不在白名单 → 不确定 */
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 对命令文本做快速 高风险 pattern 扫描。
|
|
110
|
-
*/
|
|
111
|
-
function matchesHighRiskPattern(text) {
|
|
112
|
-
return HIGH_RISK_PATTERNS.some((p) => p.test(text));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 分类命令风险等级。
|
|
117
|
-
* @param {string} command
|
|
118
|
-
* @param {string} [shellName='bash']
|
|
119
|
-
* @returns {'read-only'|'write-high-risk'|'ambiguous'}
|
|
120
|
-
*/
|
|
121
|
-
export function classifyCommandRisk(command, shellName = 'bash') {
|
|
122
|
-
const cmd = String(command || '').trim();
|
|
123
|
-
if (!cmd) return 'read-only';
|
|
124
|
-
|
|
125
|
-
/* 高风险 pattern 优先判断 */
|
|
126
|
-
if (matchesHighRiskPattern(cmd)) return 'write-high-risk';
|
|
127
|
-
|
|
128
|
-
/* 解析链式命令的每个 segment */
|
|
129
|
-
const tokens = collectCommandTokens(cmd);
|
|
130
|
-
if (tokens.length === 0) return 'ambiguous';
|
|
131
|
-
|
|
132
|
-
let highestRisk = 'read-only';
|
|
133
|
-
const RISK_ORDER = { 'read-only': 0, ambiguous: 1, 'write-high-risk': 2 };
|
|
134
|
-
|
|
135
|
-
for (const { token, raw } of tokens) {
|
|
136
|
-
if (isReadOnlyToken(token, raw)) {
|
|
137
|
-
/* 保持当前级别 */
|
|
138
|
-
} else {
|
|
139
|
-
/* 不在只读集合 → 至少 ambiguous */
|
|
140
|
-
const segRisk = matchesHighRiskPattern(raw) ? 'write-high-risk' : 'ambiguous';
|
|
141
|
-
if (RISK_ORDER[segRisk] > RISK_ORDER[highestRisk]) {
|
|
142
|
-
highestRisk = segRisk;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return highestRisk;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* 是否需要进入审批评估流程。
|
|
152
|
-
* 只读命令跳过,其余都需要。
|
|
153
|
-
*/
|
|
154
|
-
export function requiresApprovalEvaluation(command, shellName = 'bash') {
|
|
155
|
-
return classifyCommandRisk(command, shellName) !== 'read-only';
|
|
156
|
-
}
|
|
1
|
+
import { collectCommandTokens, firstToken } from './command-policy.js';
|
|
2
|
+
|
|
3
|
+
/* ── 只读命令 token ───────────────────────────────────────────── */
|
|
4
|
+
export const READ_ONLY_TOKENS = new Set([
|
|
5
|
+
'ls', 'cat', 'head', 'tail', 'pwd', 'wc', 'sort', 'uniq',
|
|
6
|
+
'cut', 'tr', 'basename', 'dirname', 'test', 'true', 'false',
|
|
7
|
+
'whoami', 'uname', 'date', 'env', 'printenv', 'hostname',
|
|
8
|
+
'rg', 'find', 'grep', 'ag', 'ack', 'fd', 'bat',
|
|
9
|
+
'get-childitem', 'get-content', 'get-location', 'get-command', 'get-help',
|
|
10
|
+
'get-item', 'get-process', 'select-string', 'select-object', 'where-object',
|
|
11
|
+
'foreach-object', 'measure-object', 'sort-object', 'compare-object',
|
|
12
|
+
'resolve-path', 'test-path',
|
|
13
|
+
'git', 'node', 'npm', 'npx', 'python', 'python3', 'py', 'pip', 'pip3',
|
|
14
|
+
'echo', 'printf', 'seq', 'yes'
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
export function getReadOnlyCommandTokens() {
|
|
18
|
+
return [...READ_ONLY_TOKENS].sort();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* 只读时需要检查子命令的 token */
|
|
22
|
+
const READ_ONLY_SUBCOMMANDS = {
|
|
23
|
+
git: new Set([
|
|
24
|
+
'status', 'log', 'diff', 'branch', 'show', 'tag', 'stash',
|
|
25
|
+
'list', 'remote', 'rev-parse', 'describe', 'blame',
|
|
26
|
+
'shortlog', 'count', 'ls-files', 'ls-remote', 'ls-tree',
|
|
27
|
+
'config', '--version', 'var', 'for-each-ref', 'name-rev',
|
|
28
|
+
'merge-base', 'cherry'
|
|
29
|
+
]),
|
|
30
|
+
node: new Set(['--version', '-v', '-e', '--eval', '--print', '-p', '--help']),
|
|
31
|
+
npm: new Set([
|
|
32
|
+
'--version', '-v', 'view', 'info', 'list', 'ls', 'll', 'la',
|
|
33
|
+
'outdated', 'audit', 'pack', 'cache', 'config', 'doctor',
|
|
34
|
+
'help', 'explore', 'run', 'run-script', 'start', 'test',
|
|
35
|
+
'restart', 'stop', 'version', 'whoami'
|
|
36
|
+
]),
|
|
37
|
+
npx: new Set(['--version', '-v', '--help']),
|
|
38
|
+
python: new Set(['--version', '-V', '--help', '-c', '-m']),
|
|
39
|
+
python3: new Set(['--version', '-V', '--help', '-c', '-m']),
|
|
40
|
+
py: new Set(['--version', '-V', '--help', '-c', '-m']),
|
|
41
|
+
pip: new Set(['--version', '-V', 'list', 'show', 'search', 'check', 'debug', 'help']),
|
|
42
|
+
pip3: new Set(['--version', '-V', 'list', 'show', 'search', 'check', 'debug', 'help'])
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/* ── 高风险 pattern ────────────────────────────────────────────── */
|
|
46
|
+
const HIGH_RISK_PATTERNS = [
|
|
47
|
+
/\binstall\b/i,
|
|
48
|
+
/\bpublish\b/i,
|
|
49
|
+
/\bpush\b/i,
|
|
50
|
+
/\bcommit\b/i,
|
|
51
|
+
/\brebase\b/i,
|
|
52
|
+
/\breset\s/i,
|
|
53
|
+
/\bcheckout\s+--/i,
|
|
54
|
+
/\brm\b/i,
|
|
55
|
+
/\bdel\b/i,
|
|
56
|
+
/\bmkdi[ri]\b/i,
|
|
57
|
+
/\btouch\b/i,
|
|
58
|
+
/\bcp\b/i,
|
|
59
|
+
/\bmv\b/i,
|
|
60
|
+
/\bchmod\b/i,
|
|
61
|
+
/\bchown\b/i,
|
|
62
|
+
/\bmktemp\b/i,
|
|
63
|
+
/\btee\b/i,
|
|
64
|
+
/\bsudo\b/i,
|
|
65
|
+
/\bsu\b/,
|
|
66
|
+
/\bkill\b/i,
|
|
67
|
+
/\bpkill\b/i,
|
|
68
|
+
/\bcurl\s+.*-[A-Z]\s*(POST|PUT|DELETE|PATCH)/i,
|
|
69
|
+
/\bwget\b/i,
|
|
70
|
+
/\bdocker\s+(rm|stop|kill|rmi)\b/i,
|
|
71
|
+
/\bsystemctl\b/i,
|
|
72
|
+
/\bservice\b/i,
|
|
73
|
+
/\blaunchctl\b/i,
|
|
74
|
+
/>\s*\S/,
|
|
75
|
+
/>>\s*\S/,
|
|
76
|
+
/\|&\s*\S/
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
/* ── 核心分类逻辑 ──────────────────────────────────────────────── */
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 判断单个 token 是否为只读命令(含子命令检查)。
|
|
83
|
+
*/
|
|
84
|
+
function isReadOnlyToken(token, rawSegment) {
|
|
85
|
+
if (!READ_ONLY_TOKENS.has(token)) return false;
|
|
86
|
+
|
|
87
|
+
/* 需要 子命令 校验的 token */
|
|
88
|
+
const allowedSubs = READ_ONLY_SUBCOMMANDS[token];
|
|
89
|
+
if (!allowedSubs) return true; // 如 ls, pwd 等本身只读
|
|
90
|
+
|
|
91
|
+
/* 提取子命令:去掉 token 后第一个非 flag 参数 */
|
|
92
|
+
const rest = String(rawSegment || '').trim().slice(token.length).trim();
|
|
93
|
+
const parts = rest.split(/\s+/).filter(Boolean);
|
|
94
|
+
/* 以 - 开头的 flag 视为安全,取第一个非 flag 参数 */
|
|
95
|
+
let subcmd = '';
|
|
96
|
+
for (const part of parts) {
|
|
97
|
+
if (part.startsWith('-')) continue;
|
|
98
|
+
subcmd = part;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
/* 只有 token 本身或全部是 flags → 视为安全 */
|
|
102
|
+
if (!subcmd) return true;
|
|
103
|
+
if (allowedSubs.has(subcmd)) return true;
|
|
104
|
+
/* 子命令 不在白名单 → 不确定 */
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 对命令文本做快速 高风险 pattern 扫描。
|
|
110
|
+
*/
|
|
111
|
+
function matchesHighRiskPattern(text) {
|
|
112
|
+
return HIGH_RISK_PATTERNS.some((p) => p.test(text));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 分类命令风险等级。
|
|
117
|
+
* @param {string} command
|
|
118
|
+
* @param {string} [shellName='bash']
|
|
119
|
+
* @returns {'read-only'|'write-high-risk'|'ambiguous'}
|
|
120
|
+
*/
|
|
121
|
+
export function classifyCommandRisk(command, shellName = 'bash') {
|
|
122
|
+
const cmd = String(command || '').trim();
|
|
123
|
+
if (!cmd) return 'read-only';
|
|
124
|
+
|
|
125
|
+
/* 高风险 pattern 优先判断 */
|
|
126
|
+
if (matchesHighRiskPattern(cmd)) return 'write-high-risk';
|
|
127
|
+
|
|
128
|
+
/* 解析链式命令的每个 segment */
|
|
129
|
+
const tokens = collectCommandTokens(cmd);
|
|
130
|
+
if (tokens.length === 0) return 'ambiguous';
|
|
131
|
+
|
|
132
|
+
let highestRisk = 'read-only';
|
|
133
|
+
const RISK_ORDER = { 'read-only': 0, ambiguous: 1, 'write-high-risk': 2 };
|
|
134
|
+
|
|
135
|
+
for (const { token, raw } of tokens) {
|
|
136
|
+
if (isReadOnlyToken(token, raw)) {
|
|
137
|
+
/* 保持当前级别 */
|
|
138
|
+
} else {
|
|
139
|
+
/* 不在只读集合 → 至少 ambiguous */
|
|
140
|
+
const segRisk = matchesHighRiskPattern(raw) ? 'write-high-risk' : 'ambiguous';
|
|
141
|
+
if (RISK_ORDER[segRisk] > RISK_ORDER[highestRisk]) {
|
|
142
|
+
highestRisk = segRisk;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return highestRisk;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 是否需要进入审批评估流程。
|
|
152
|
+
* 只读命令跳过,其余都需要。
|
|
153
|
+
*/
|
|
154
|
+
export function requiresApprovalEvaluation(command, shellName = 'bash') {
|
|
155
|
+
return classifyCommandRisk(command, shellName) !== 'read-only';
|
|
156
|
+
}
|