ccjk 3.7.3 → 3.8.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/README.md +103 -896
- package/dist/chunks/ccr.mjs +1 -0
- package/dist/chunks/doctor.mjs +58 -0
- package/dist/chunks/index.mjs +6 -0
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/permissions.mjs +164 -342
- package/dist/chunks/thinking.mjs +615 -0
- package/dist/chunks/vim.mjs +891 -0
- package/dist/cli.mjs +49 -0
- package/dist/i18n/locales/en/configuration.json +97 -1
- package/dist/i18n/locales/en/lsp.json +78 -0
- package/dist/i18n/locales/en/mcp.json +11 -0
- package/dist/i18n/locales/en/permissions.json +53 -1
- package/dist/i18n/locales/en/thinking.json +65 -0
- package/dist/i18n/locales/en/vim.json +169 -0
- package/dist/i18n/locales/zh-CN/configuration.json +97 -1
- package/dist/i18n/locales/zh-CN/lsp.json +78 -0
- package/dist/i18n/locales/zh-CN/mcp.json +11 -0
- package/dist/i18n/locales/zh-CN/permissions.json +53 -1
- package/dist/i18n/locales/zh-CN/thinking.json +65 -0
- package/dist/i18n/locales/zh-CN/vim.json +169 -0
- package/dist/shared/ccjk.pi0nsyn3.mjs +1242 -0
- package/package.json +55 -55
- package/templates/claude-code/common/settings.json +63 -30
- package/templates/CLAUDE.md +0 -219
- package/templates/claude-code/CLAUDE.md +0 -250
- package/templates/claude-code/en/workflow/bmad/commands/bmad-init.md +0 -165
- package/templates/claude-code/en/workflow/common/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/en/workflow/common/agents/init-architect.md +0 -114
- package/templates/claude-code/en/workflow/common/commands/init-project.md +0 -53
- package/templates/claude-code/en/workflow/essential/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/en/workflow/essential/agents/init-architect.md +0 -114
- package/templates/claude-code/en/workflow/essential/agents/planner.md +0 -116
- package/templates/claude-code/en/workflow/essential/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/en/workflow/essential/commands/feat.md +0 -250
- package/templates/claude-code/en/workflow/essential/commands/init-project.md +0 -53
- package/templates/claude-code/en/workflow/plan/agents/planner.md +0 -116
- package/templates/claude-code/en/workflow/plan/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/en/workflow/plan/commands/feat.md +0 -105
- package/templates/claude-code/zh-CN/workflow/bmad/commands/bmad-init.md +0 -172
- package/templates/claude-code/zh-CN/workflow/common/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/zh-CN/workflow/common/agents/init-architect.md +0 -114
- package/templates/claude-code/zh-CN/workflow/common/commands/init-project.md +0 -53
- package/templates/claude-code/zh-CN/workflow/essential/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/zh-CN/workflow/essential/agents/init-architect.md +0 -114
- package/templates/claude-code/zh-CN/workflow/essential/agents/planner.md +0 -116
- package/templates/claude-code/zh-CN/workflow/essential/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/zh-CN/workflow/essential/commands/feat.md +0 -248
- package/templates/claude-code/zh-CN/workflow/essential/commands/init-project.md +0 -53
- package/templates/claude-code/zh-CN/workflow/plan/agents/planner.md +0 -116
- package/templates/claude-code/zh-CN/workflow/plan/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/zh-CN/workflow/plan/commands/feat.md +0 -105
- package/templates/codex/common/config.toml +0 -0
- package/templates/common/output-styles/en/casual-friendly.md +0 -97
- package/templates/common/output-styles/en/expert-concise.md +0 -93
- package/templates/common/output-styles/en/pair-programmer.md +0 -177
- package/templates/common/output-styles/en/senior-architect.md +0 -121
- package/templates/common/output-styles/en/speed-coder.md +0 -185
- package/templates/common/output-styles/en/teaching-mode.md +0 -102
- package/templates/common/output-styles/en/technical-precise.md +0 -101
- package/templates/common/output-styles/zh-CN/pair-programmer.md +0 -177
- package/templates/common/output-styles/zh-CN/senior-architect.md +0 -297
- package/templates/common/output-styles/zh-CN/speed-coder.md +0 -185
- package/templates/common/skills/code-review.md +0 -343
- package/templates/common/skills/en/agent-browser.md +0 -258
- package/templates/common/skills/en/brainstorming.md +0 -64
- package/templates/common/skills/en/code-review.md +0 -81
- package/templates/common/skills/en/documentation-gen.md +0 -808
- package/templates/common/skills/en/executing-plans.md +0 -75
- package/templates/common/skills/en/git-commit.md +0 -216
- package/templates/common/skills/en/interview.md +0 -223
- package/templates/common/skills/en/migration-assistant.md +0 -312
- package/templates/common/skills/en/performance-profiling.md +0 -576
- package/templates/common/skills/en/pr-review.md +0 -341
- package/templates/common/skills/en/refactoring.md +0 -384
- package/templates/common/skills/en/security-audit.md +0 -462
- package/templates/common/skills/en/systematic-debugging.md +0 -82
- package/templates/common/skills/en/tdd-workflow.md +0 -93
- package/templates/common/skills/en/verification.md +0 -81
- package/templates/common/skills/en/workflow.md +0 -370
- package/templates/common/skills/en/writing-plans.md +0 -78
- package/templates/common/skills/summarize.md +0 -312
- package/templates/common/skills/translate.md +0 -202
- package/templates/common/skills/zh-CN/agent-browser.md +0 -260
- package/templates/common/skills/zh-CN/documentation-gen.md +0 -807
- package/templates/common/skills/zh-CN/migration-assistant.md +0 -318
- package/templates/common/skills/zh-CN/performance-profiling.md +0 -746
- package/templates/common/skills/zh-CN/pr-review.md +0 -341
- package/templates/common/skills/zh-CN/refactoring.md +0 -384
- package/templates/common/skills/zh-CN/security-audit.md +0 -462
- package/templates/common/smart-guide/en/smart-guide.md +0 -72
- package/templates/common/smart-guide/zh-CN/smart-guide.md +0 -72
- package/templates/common/workflow/git/en/git-cleanBranches.md +0 -102
- package/templates/common/workflow/git/en/git-commit.md +0 -205
- package/templates/common/workflow/git/en/git-rollback.md +0 -90
- package/templates/common/workflow/git/en/git-worktree.md +0 -276
- package/templates/common/workflow/git/zh-CN/git-cleanBranches.md +0 -102
- package/templates/common/workflow/git/zh-CN/git-commit.md +0 -205
- package/templates/common/workflow/git/zh-CN/git-rollback.md +0 -90
- package/templates/common/workflow/git/zh-CN/git-worktree.md +0 -276
- package/templates/common/workflow/interview/en/interview.md +0 -212
- package/templates/common/workflow/interview/zh-CN/interview.md +0 -212
- package/templates/common/workflow/sixStep/en/workflow.md +0 -357
- package/templates/common/workflow/sixStep/zh-CN/workflow.md +0 -357
- package/templates/industry/devops/en/ci-cd-pipeline.md +0 -410
- package/templates/industry/web-dev/en/api-design.md +0 -299
- package/templates/industry/web-dev/en/react-nextjs-setup.md +0 -236
|
@@ -1,428 +1,250 @@
|
|
|
1
1
|
import process__default from 'node:process';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Load permissions from config file
|
|
16
|
-
*/
|
|
17
|
-
loadPermissions() {
|
|
18
|
-
try {
|
|
19
|
-
if (!existsSync(this.configPath)) {
|
|
20
|
-
this.permissions = [];
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const configContent = readFileSync(this.configPath, "utf-8");
|
|
24
|
-
const config = JSON.parse(configContent);
|
|
25
|
-
if (config.permissions) {
|
|
26
|
-
this.permissions = [];
|
|
27
|
-
if (Array.isArray(config.permissions.allow)) {
|
|
28
|
-
config.permissions.allow.forEach((pattern) => {
|
|
29
|
-
this.permissions.push({
|
|
30
|
-
type: "allow",
|
|
31
|
-
pattern,
|
|
32
|
-
scope: "global"
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(config.permissions.deny)) {
|
|
37
|
-
config.permissions.deny.forEach((pattern) => {
|
|
38
|
-
this.permissions.push({
|
|
39
|
-
type: "deny",
|
|
40
|
-
pattern,
|
|
41
|
-
scope: "global"
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} catch (_error) {
|
|
47
|
-
this.permissions = [];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Save permissions to config file
|
|
52
|
-
*/
|
|
53
|
-
savePermissions() {
|
|
54
|
-
try {
|
|
55
|
-
let config = {};
|
|
56
|
-
if (existsSync(this.configPath)) {
|
|
57
|
-
const configContent = readFileSync(this.configPath, "utf-8");
|
|
58
|
-
config = JSON.parse(configContent);
|
|
59
|
-
}
|
|
60
|
-
config.permissions = {
|
|
61
|
-
allow: this.permissions.filter((p) => p.type === "allow").map((p) => p.pattern),
|
|
62
|
-
deny: this.permissions.filter((p) => p.type === "deny").map((p) => p.pattern)
|
|
63
|
-
};
|
|
64
|
-
writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
65
|
-
} catch (error) {
|
|
66
|
-
throw new Error(`Failed to save permissions: ${error instanceof Error ? error.message : String(error)}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if an action on a resource is permitted
|
|
71
|
-
* @param action - The action to check (e.g., "read", "write", "admin")
|
|
72
|
-
* @param resource - The resource identifier (e.g., "Provider(302ai)", "Model(claude-opus)")
|
|
73
|
-
* @returns Permission check result
|
|
74
|
-
*/
|
|
75
|
-
checkPermission(action, resource) {
|
|
76
|
-
const target = `${resource}:${action}`;
|
|
77
|
-
for (const permission of this.permissions) {
|
|
78
|
-
if (permission.type === "deny" && this.matchPattern(permission.pattern, target)) {
|
|
79
|
-
return {
|
|
80
|
-
allowed: false,
|
|
81
|
-
matchedRule: permission,
|
|
82
|
-
reason: `Denied by rule: ${permission.pattern}`
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
for (const permission of this.permissions) {
|
|
87
|
-
if (permission.type === "allow" && this.matchPattern(permission.pattern, target)) {
|
|
88
|
-
return {
|
|
89
|
-
allowed: true,
|
|
90
|
-
matchedRule: permission,
|
|
91
|
-
reason: `Allowed by rule: ${permission.pattern}`
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
allowed: false,
|
|
97
|
-
reason: "No matching permission rule found (default deny)"
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Match a pattern against a target string
|
|
102
|
-
* Supports wildcards: * (any characters), ? (single character)
|
|
103
|
-
* @param pattern - Pattern with wildcards
|
|
104
|
-
* @param target - Target string to match
|
|
105
|
-
* @returns True if pattern matches target
|
|
106
|
-
*/
|
|
107
|
-
matchPattern(pattern, target) {
|
|
108
|
-
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
109
|
-
const regex = new RegExp(`^${regexPattern}$`, "i");
|
|
110
|
-
return regex.test(target);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Add a permission rule
|
|
114
|
-
* @param permission - Permission to add
|
|
115
|
-
*/
|
|
116
|
-
addPermission(permission) {
|
|
117
|
-
const existingIndex = this.permissions.findIndex(
|
|
118
|
-
(p) => p.pattern === permission.pattern && p.type === permission.type
|
|
119
|
-
);
|
|
120
|
-
if (existingIndex >= 0) {
|
|
121
|
-
this.permissions[existingIndex] = {
|
|
122
|
-
...permission,
|
|
123
|
-
createdAt: this.permissions[existingIndex].createdAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
124
|
-
};
|
|
125
|
-
} else {
|
|
126
|
-
this.permissions.push({
|
|
127
|
-
...permission,
|
|
128
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
this.savePermissions();
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Remove a permission rule by pattern
|
|
135
|
-
* @param pattern - Pattern to remove
|
|
136
|
-
* @param type - Optional type filter
|
|
137
|
-
* @returns Number of rules removed
|
|
138
|
-
*/
|
|
139
|
-
removePermission(pattern, type) {
|
|
140
|
-
const initialLength = this.permissions.length;
|
|
141
|
-
this.permissions = this.permissions.filter((p) => {
|
|
142
|
-
if (type) {
|
|
143
|
-
return !(p.pattern === pattern && p.type === type);
|
|
144
|
-
}
|
|
145
|
-
return p.pattern !== pattern;
|
|
146
|
-
});
|
|
147
|
-
const removedCount = initialLength - this.permissions.length;
|
|
148
|
-
if (removedCount > 0) {
|
|
149
|
-
this.savePermissions();
|
|
150
|
-
}
|
|
151
|
-
return removedCount;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* List all permissions
|
|
155
|
-
* @param type - Optional filter by type
|
|
156
|
-
* @param scope - Optional filter by scope
|
|
157
|
-
* @returns Array of permissions
|
|
158
|
-
*/
|
|
159
|
-
listPermissions(type, scope) {
|
|
160
|
-
let filtered = [...this.permissions];
|
|
161
|
-
if (type) {
|
|
162
|
-
filtered = filtered.filter((p) => p.type === type);
|
|
163
|
-
}
|
|
164
|
-
if (scope) {
|
|
165
|
-
filtered = filtered.filter((p) => p.scope === scope);
|
|
166
|
-
}
|
|
167
|
-
return filtered;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Clear all permissions
|
|
171
|
-
* @param type - Optional type to clear (if not specified, clears all)
|
|
172
|
-
*/
|
|
173
|
-
clearPermissions(type) {
|
|
174
|
-
if (type) {
|
|
175
|
-
this.permissions = this.permissions.filter((p) => p.type !== type);
|
|
176
|
-
} else {
|
|
177
|
-
this.permissions = [];
|
|
178
|
-
}
|
|
179
|
-
this.savePermissions();
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Get permission statistics
|
|
183
|
-
*/
|
|
184
|
-
getStats() {
|
|
185
|
-
return {
|
|
186
|
-
total: this.permissions.length,
|
|
187
|
-
allow: this.permissions.filter((p) => p.type === "allow").length,
|
|
188
|
-
deny: this.permissions.filter((p) => p.type === "deny").length
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Export permissions to JSON
|
|
193
|
-
*/
|
|
194
|
-
exportPermissions() {
|
|
195
|
-
return {
|
|
196
|
-
allow: this.permissions.filter((p) => p.type === "allow").map((p) => p.pattern),
|
|
197
|
-
deny: this.permissions.filter((p) => p.type === "deny").map((p) => p.pattern)
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Import permissions from JSON
|
|
202
|
-
* @param config - Permission configuration to import
|
|
203
|
-
* @param merge - If true, merge with existing permissions; if false, replace
|
|
204
|
-
*/
|
|
205
|
-
importPermissions(config, merge = false) {
|
|
206
|
-
if (!merge) {
|
|
207
|
-
this.permissions = [];
|
|
208
|
-
}
|
|
209
|
-
if (Array.isArray(config.allow)) {
|
|
210
|
-
config.allow.forEach((pattern) => {
|
|
211
|
-
this.addPermission({
|
|
212
|
-
type: "allow",
|
|
213
|
-
pattern,
|
|
214
|
-
scope: "global"
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
if (Array.isArray(config.deny)) {
|
|
219
|
-
config.deny.forEach((pattern) => {
|
|
220
|
-
this.addPermission({
|
|
221
|
-
type: "deny",
|
|
222
|
-
pattern,
|
|
223
|
-
scope: "global"
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
let instance = null;
|
|
230
|
-
function getPermissionManager(configPath) {
|
|
231
|
-
if (!instance) {
|
|
232
|
-
instance = new PermissionManager(configPath);
|
|
233
|
-
}
|
|
234
|
-
return instance;
|
|
235
|
-
}
|
|
2
|
+
import ansis from 'ansis';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import 'tinyexec';
|
|
5
|
+
import { i18n } from './index.mjs';
|
|
6
|
+
import { g as getPermissionManager } from '../shared/ccjk.pi0nsyn3.mjs';
|
|
7
|
+
import 'node:fs';
|
|
8
|
+
import 'node:url';
|
|
9
|
+
import 'i18next';
|
|
10
|
+
import 'i18next-fs-backend';
|
|
11
|
+
import 'pathe';
|
|
12
|
+
import 'node:os';
|
|
236
13
|
|
|
237
14
|
const permissionManager = getPermissionManager();
|
|
238
15
|
async function listPermissions(options) {
|
|
239
16
|
const format = options.format || "table";
|
|
240
17
|
const verbose = options.verbose || false;
|
|
241
|
-
const
|
|
18
|
+
const category = options.category;
|
|
19
|
+
const type = options.type;
|
|
20
|
+
let rules = permissionManager.getAllRules();
|
|
21
|
+
if (type) {
|
|
22
|
+
rules = rules.filter((r) => r.type === type);
|
|
23
|
+
}
|
|
24
|
+
if (category) {
|
|
25
|
+
rules = rules.filter((r) => r.category === category);
|
|
26
|
+
}
|
|
242
27
|
if (format === "json") {
|
|
243
|
-
console.log(JSON.stringify(
|
|
28
|
+
console.log(JSON.stringify(rules, null, 2));
|
|
244
29
|
return;
|
|
245
30
|
}
|
|
246
|
-
console.log(
|
|
247
|
-
|
|
248
|
-
|
|
31
|
+
console.log("");
|
|
32
|
+
console.log(ansis.bold("\u{1F4CB} CCJK Permissions\n"));
|
|
33
|
+
const stats = permissionManager.getStats();
|
|
34
|
+
console.log(ansis.dim(`Total: ${stats.total} | Allow: ${stats.allow} | Deny: ${stats.deny}
|
|
35
|
+
`));
|
|
36
|
+
if (rules.length === 0) {
|
|
37
|
+
console.log(ansis.yellow("No permissions configured."));
|
|
249
38
|
return;
|
|
250
39
|
}
|
|
251
40
|
if (format === "list") {
|
|
252
|
-
for (const
|
|
253
|
-
const typeColor =
|
|
254
|
-
console.log(`${
|
|
255
|
-
if (verbose
|
|
256
|
-
|
|
41
|
+
for (const rule of rules) {
|
|
42
|
+
const typeColor = rule.type === "allow" ? ansis.green : ansis.red;
|
|
43
|
+
console.log(`${typeColor(rule.type.padEnd(6))} ${ansis.cyan(rule.pattern)} (${rule.category})`);
|
|
44
|
+
if (verbose) {
|
|
45
|
+
if (rule.description) {
|
|
46
|
+
console.log(ansis.gray(` Description: ${rule.description}`));
|
|
47
|
+
}
|
|
48
|
+
console.log(ansis.gray(` Source: ${rule.source}`));
|
|
49
|
+
if (rule.priority !== void 0) {
|
|
50
|
+
console.log(ansis.gray(` Priority: ${rule.priority}`));
|
|
51
|
+
}
|
|
257
52
|
}
|
|
258
53
|
}
|
|
259
54
|
} else {
|
|
260
|
-
console.log(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
55
|
+
console.log(
|
|
56
|
+
ansis.bold("Type".padEnd(8)) + ansis.bold("Pattern".padEnd(40)) + ansis.bold("Category".padEnd(12)) + ansis.bold("Source")
|
|
57
|
+
);
|
|
58
|
+
console.log(ansis.dim("\u2500".repeat(80)));
|
|
59
|
+
for (const rule of rules) {
|
|
60
|
+
const typeColor = rule.type === "allow" ? ansis.green : ansis.red;
|
|
61
|
+
const type2 = typeColor(rule.type.padEnd(8));
|
|
62
|
+
const pattern = ansis.cyan(rule.pattern.padEnd(40));
|
|
63
|
+
const category2 = ansis.yellow(rule.category.padEnd(12));
|
|
64
|
+
const source = ansis.dim(rule.source);
|
|
65
|
+
console.log(`${type2}${pattern}${category2}${source}`);
|
|
66
|
+
if (verbose && rule.description) {
|
|
67
|
+
console.log(ansis.gray(` \u2514\u2500 ${rule.description}`));
|
|
270
68
|
}
|
|
271
69
|
}
|
|
272
70
|
}
|
|
273
|
-
console.log();
|
|
71
|
+
console.log("");
|
|
274
72
|
}
|
|
275
73
|
async function checkPermission(resource, options) {
|
|
74
|
+
const isZh = i18n.language === "zh-CN";
|
|
276
75
|
if (!resource) {
|
|
277
|
-
console.error(
|
|
278
|
-
console.log("Usage: ccjk permissions check <resource>");
|
|
76
|
+
console.error(ansis.red(isZh ? "\u9519\u8BEF\uFF1A\u9700\u8981\u6307\u5B9A\u8D44\u6E90" : "Error: Resource is required"));
|
|
77
|
+
console.log(isZh ? "\u7528\u6CD5: ccjk permissions check <resource>" : "Usage: ccjk permissions check <resource>");
|
|
279
78
|
process__default.exit(1);
|
|
280
79
|
}
|
|
281
|
-
const action = options.action || "
|
|
80
|
+
const action = options.action || "execute";
|
|
282
81
|
const verbose = options.verbose || false;
|
|
283
|
-
console.log(
|
|
284
|
-
\u{1F50D}
|
|
82
|
+
console.log("");
|
|
83
|
+
console.log(ansis.bold(`${ansis.cyan("\u{1F50D}")} ${isZh ? "\u68C0\u67E5\u6743\u9650" : "Checking Permission"}: ${ansis.cyan(resource)}
|
|
285
84
|
`));
|
|
286
|
-
const result = permissionManager.checkPermission(action, resource);
|
|
85
|
+
const result = await permissionManager.checkPermission(action, resource);
|
|
287
86
|
if (result.allowed) {
|
|
288
|
-
console.log(
|
|
289
|
-
console.log(` Reason: ${result.reason}`);
|
|
87
|
+
console.log(ansis.green(`\u2713 ${isZh ? "\u5141\u8BB8" : "ALLOWED"}`));
|
|
88
|
+
console.log(` ${ansis.dim("Reason:")} ${result.reason}`);
|
|
290
89
|
if (verbose && result.matchedRule) {
|
|
291
|
-
console.log(` Matched rule: ${result.matchedRule.pattern}`);
|
|
292
|
-
console.log(` Rule type: ${result.matchedRule.type}`);
|
|
90
|
+
console.log(` ${ansis.dim("Matched rule:")} ${ansis.cyan(result.matchedRule.pattern)}`);
|
|
91
|
+
console.log(` ${ansis.dim("Rule type:")} ${result.matchedRule.type}`);
|
|
92
|
+
console.log(` ${ansis.dim("Source:")} ${result.matchedRule.source}`);
|
|
293
93
|
}
|
|
294
94
|
} else {
|
|
295
|
-
console.log(
|
|
296
|
-
console.log(` Reason: ${result.reason}`);
|
|
297
|
-
console.log(
|
|
95
|
+
console.log(ansis.red(`\u2717 ${isZh ? "\u62D2\u7EDD" : "DENIED"}`));
|
|
96
|
+
console.log(` ${ansis.dim("Reason:")} ${result.reason}`);
|
|
97
|
+
console.log(ansis.yellow(isZh ? ' \u63D0\u793A\uFF1A\u4F7F\u7528 "ccjk permissions add" \u6DFB\u52A0\u6743\u9650' : ' Tip: Use "ccjk permissions add" to grant permission'));
|
|
298
98
|
}
|
|
299
|
-
console.log();
|
|
99
|
+
console.log("");
|
|
300
100
|
}
|
|
301
|
-
async function grantPermission(resource,
|
|
101
|
+
async function grantPermission(resource, options) {
|
|
102
|
+
const isZh = i18n.language === "zh-CN";
|
|
302
103
|
if (!resource) {
|
|
303
|
-
console.error(
|
|
304
|
-
console.log("Usage: ccjk permissions grant <
|
|
104
|
+
console.error(ansis.red(isZh ? "\u9519\u8BEF\uFF1A\u9700\u8981\u6307\u5B9A\u8D44\u6E90" : "Error: Resource is required"));
|
|
105
|
+
console.log(isZh ? "\u7528\u6CD5: ccjk permissions grant <pattern>" : "Usage: ccjk permissions grant <pattern>");
|
|
106
|
+
process__default.exit(1);
|
|
107
|
+
}
|
|
108
|
+
const validation = permissionManager.validatePattern(resource);
|
|
109
|
+
if (!validation.valid) {
|
|
110
|
+
console.error(ansis.red(`${isZh ? "\u9519\u8BEF" : "Error"}: ${validation.error}`));
|
|
305
111
|
process__default.exit(1);
|
|
306
112
|
}
|
|
307
|
-
console.log(
|
|
308
|
-
\u2713
|
|
113
|
+
console.log("");
|
|
114
|
+
console.log(ansis.bold(`${ansis.cyan("\u2713")} ${isZh ? "\u6388\u4E88\u6743\u9650" : "Granting Permission"}: ${ansis.cyan(resource)}
|
|
309
115
|
`));
|
|
310
116
|
const permission = {
|
|
311
117
|
type: "allow",
|
|
312
118
|
pattern: resource,
|
|
313
119
|
scope: "global",
|
|
314
|
-
description: "Granted via CLI"
|
|
120
|
+
description: options.description || "Granted via CLI"
|
|
315
121
|
};
|
|
316
122
|
permissionManager.addPermission(permission);
|
|
317
|
-
console.log(
|
|
318
|
-
console.log();
|
|
123
|
+
console.log(ansis.green(isZh ? "\u6743\u9650\u5DF2\u6210\u529F\u6388\u4E88\uFF01" : "Permission granted successfully!"));
|
|
124
|
+
console.log("");
|
|
319
125
|
}
|
|
320
126
|
async function revokePermission(resource, _options) {
|
|
127
|
+
const isZh = i18n.language === "zh-CN";
|
|
321
128
|
if (!resource) {
|
|
322
|
-
console.error(
|
|
323
|
-
console.log("Usage: ccjk permissions revoke <
|
|
129
|
+
console.error(ansis.red(isZh ? "\u9519\u8BEF\uFF1A\u9700\u8981\u6307\u5B9A\u8D44\u6E90" : "Error: Resource is required"));
|
|
130
|
+
console.log(isZh ? "\u7528\u6CD5: ccjk permissions revoke <pattern>" : "Usage: ccjk permissions revoke <pattern>");
|
|
324
131
|
process__default.exit(1);
|
|
325
132
|
}
|
|
326
|
-
console.log(
|
|
327
|
-
\u2717
|
|
133
|
+
console.log("");
|
|
134
|
+
console.log(ansis.bold(`${ansis.red("\u2717")} ${isZh ? "\u64A4\u9500\u6743\u9650" : "Revoking Permission"}: ${ansis.cyan(resource)}
|
|
328
135
|
`));
|
|
329
136
|
const removed = permissionManager.removePermission(resource);
|
|
330
|
-
if (removed
|
|
331
|
-
console.log(
|
|
137
|
+
if (removed) {
|
|
138
|
+
console.log(ansis.green(isZh ? "\u6743\u9650\u5DF2\u6210\u529F\u64A4\u9500\uFF01" : "Permission revoked successfully!"));
|
|
332
139
|
} else {
|
|
333
|
-
console.log(
|
|
140
|
+
console.log(ansis.yellow(isZh ? "\u672A\u627E\u5230\u5339\u914D\u7684\u6743\u9650\u89C4\u5219" : "No matching permission found"));
|
|
334
141
|
}
|
|
335
|
-
console.log();
|
|
142
|
+
console.log("");
|
|
336
143
|
}
|
|
337
144
|
async function resetPermissions(_options) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
145
|
+
const isZh = i18n.language === "zh-CN";
|
|
146
|
+
console.log("");
|
|
147
|
+
console.log(ansis.bold.yellow(`${ansis.yellow("\u26A0\uFE0F")} ${isZh ? "\u91CD\u7F6E\u6240\u6709\u6743\u9650" : "Resetting All Permissions"}
|
|
148
|
+
`));
|
|
149
|
+
const { confirm } = await inquirer.prompt({
|
|
150
|
+
type: "confirm",
|
|
151
|
+
name: "confirm",
|
|
152
|
+
message: isZh ? "\u786E\u5B9A\u8981\u6E05\u9664\u6240\u6709\u6743\u9650\u89C4\u5219\u5417\uFF1F" : "Are you sure you want to reset all permissions?",
|
|
153
|
+
default: false
|
|
346
154
|
});
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
console.log(chalk.gray("Operation cancelled."));
|
|
155
|
+
if (!confirm) {
|
|
156
|
+
console.log(ansis.gray(isZh ? "\u64CD\u4F5C\u5DF2\u53D6\u6D88" : "Operation cancelled"));
|
|
350
157
|
return;
|
|
351
158
|
}
|
|
352
159
|
permissionManager.clearPermissions();
|
|
353
|
-
console.log(
|
|
354
|
-
console.log();
|
|
160
|
+
console.log(ansis.green(isZh ? "\u6240\u6709\u6743\u9650\u5DF2\u6E05\u9664\uFF01" : "All permissions have been reset!"));
|
|
161
|
+
console.log("");
|
|
355
162
|
}
|
|
356
163
|
async function exportPermissions(filePath, _options) {
|
|
357
164
|
const fs = await import('node:fs/promises');
|
|
358
165
|
const path = await import('node:path');
|
|
359
166
|
const outputPath = filePath || path.join(process__default.cwd(), "permissions.json");
|
|
360
|
-
console.log(
|
|
361
|
-
|
|
167
|
+
console.log("");
|
|
168
|
+
console.log(ansis.bold(`\u{1F4E4} ${ansis.cyan("Exporting Permissions")} ${ansis.dim("to")} ${ansis.cyan(outputPath)}
|
|
362
169
|
`));
|
|
363
170
|
const permissions = permissionManager.exportPermissions();
|
|
364
171
|
await fs.writeFile(outputPath, JSON.stringify(permissions, null, 2), "utf-8");
|
|
365
|
-
const totalCount = permissions.allow
|
|
366
|
-
console.log(
|
|
367
|
-
console.log();
|
|
172
|
+
const totalCount = (permissions.allow?.length || 0) + (permissions.deny?.length || 0);
|
|
173
|
+
console.log(ansis.green(`\u2713 Exported ${totalCount} permission(s) successfully!`));
|
|
174
|
+
console.log("");
|
|
368
175
|
}
|
|
369
|
-
async function importPermissions(filePath,
|
|
176
|
+
async function importPermissions(filePath, options) {
|
|
177
|
+
const isZh = i18n.language === "zh-CN";
|
|
370
178
|
if (!filePath) {
|
|
371
|
-
console.error(
|
|
372
|
-
console.log("Usage: ccjk permissions import <file>");
|
|
179
|
+
console.error(ansis.red(isZh ? "\u9519\u8BEF\uFF1A\u9700\u8981\u6307\u5B9A\u6587\u4EF6\u8DEF\u5F84" : "Error: File path is required"));
|
|
180
|
+
console.log(isZh ? "\u7528\u6CD5: ccjk permissions import <file>" : "Usage: ccjk permissions import <file>");
|
|
373
181
|
process__default.exit(1);
|
|
374
182
|
}
|
|
375
183
|
const fs = await import('node:fs/promises');
|
|
376
|
-
console.log(
|
|
377
|
-
|
|
184
|
+
console.log("");
|
|
185
|
+
console.log(ansis.bold(`\u{1F4E5} ${ansis.cyan("Importing Permissions")} ${ansis.dim("from")} ${ansis.cyan(filePath)}
|
|
378
186
|
`));
|
|
379
187
|
try {
|
|
380
188
|
const content = await fs.readFile(filePath, "utf-8");
|
|
381
189
|
const config = JSON.parse(content);
|
|
382
190
|
if (!config.allow && !config.deny) {
|
|
383
|
-
throw new TypeError("Invalid permissions file format. Expected { allow: [], deny: [] }");
|
|
191
|
+
throw new TypeError(isZh ? "\u65E0\u6548\u7684\u6743\u9650\u6587\u4EF6\u683C\u5F0F\u3002\u671F\u671B { allow: [], deny: [] }" : "Invalid permissions file format. Expected { allow: [], deny: [] }");
|
|
384
192
|
}
|
|
385
|
-
|
|
193
|
+
const merge = options.merge ?? false;
|
|
194
|
+
permissionManager.importPermissions(config, merge);
|
|
386
195
|
const totalCount = (config.allow?.length || 0) + (config.deny?.length || 0);
|
|
387
|
-
console.log(
|
|
196
|
+
console.log(ansis.green(`\u2713 Imported ${totalCount} permission(s) successfully!`));
|
|
388
197
|
} catch (error) {
|
|
389
|
-
console.error(
|
|
198
|
+
console.error(ansis.red(`${isZh ? "\u5BFC\u5165\u6743\u9650\u65F6\u51FA\u9519" : "Error importing permissions"}:`), error);
|
|
390
199
|
process__default.exit(1);
|
|
391
200
|
}
|
|
392
|
-
console.log();
|
|
201
|
+
console.log("");
|
|
393
202
|
}
|
|
394
203
|
function permissionsHelp(_options) {
|
|
395
|
-
|
|
396
|
-
console.log(
|
|
204
|
+
const isZh = i18n.language === "zh-CN";
|
|
205
|
+
console.log("");
|
|
206
|
+
console.log(ansis.bold.cyan(`\u{1F4CB} ${isZh ? "CCJK \u6743\u9650\u7BA1\u7406" : "CCJK Permissions Management"}
|
|
207
|
+
`));
|
|
208
|
+
console.log(ansis.bold(isZh ? "\u7528\u6CD5\uFF1A" : "Usage:"));
|
|
397
209
|
console.log(" ccjk permissions [action] [...args]\n");
|
|
398
|
-
console.log(
|
|
399
|
-
console.log(
|
|
400
|
-
console.log(
|
|
401
|
-
console.log(
|
|
402
|
-
console.log(
|
|
403
|
-
console.log(
|
|
404
|
-
console.log(
|
|
405
|
-
console.log(
|
|
406
|
-
console.log(
|
|
407
|
-
console.log(
|
|
408
|
-
console.log(
|
|
409
|
-
console.log(
|
|
410
|
-
|
|
210
|
+
console.log(ansis.bold(isZh ? "\u64CD\u4F5C\uFF1A" : "Actions:"));
|
|
211
|
+
console.log(` list ${isZh ? "\u5217\u51FA\u6240\u6709\u6743\u9650" : "List all permissions"}`);
|
|
212
|
+
console.log(` search [query] ${isZh ? "\u4EA4\u4E92\u5F0F\u641C\u7D22\u6743\u9650" : "Interactive permission search"}`);
|
|
213
|
+
console.log(` check <resource> ${isZh ? "\u68C0\u67E5\u8D44\u6E90\u6743\u9650" : "Check permission for a resource"}`);
|
|
214
|
+
console.log(` grant <pattern> ${isZh ? "\u6388\u4E88\u6743\u9650" : "Grant permission for a pattern"}`);
|
|
215
|
+
console.log(` revoke <pattern> ${isZh ? "\u64A4\u9500\u6743\u9650" : "Revoke permission for a pattern"}`);
|
|
216
|
+
console.log(` reset ${isZh ? "\u91CD\u7F6E\u6240\u6709\u6743\u9650" : "Reset all permissions"}`);
|
|
217
|
+
console.log(` test <pattern> ${isZh ? "\u6D4B\u8BD5\u6A21\u5F0F\u5339\u914D" : "Test pattern matching"}`);
|
|
218
|
+
console.log(` diagnose [pattern] ${isZh ? "\u663E\u793A\u89C4\u5219\u8BCA\u65AD" : "Show rule diagnostics"}`);
|
|
219
|
+
console.log(` examples ${isZh ? "\u663E\u793A\u6A21\u5F0F\u793A\u4F8B" : "Show pattern examples"}`);
|
|
220
|
+
console.log(` export [file] ${isZh ? "\u5BFC\u51FA\u6743\u9650\u5230\u6587\u4EF6" : "Export permissions to a file"}`);
|
|
221
|
+
console.log(` import <file> ${isZh ? "\u4ECE\u6587\u4EF6\u5BFC\u5165\u6743\u9650" : "Import permissions from a file"}
|
|
222
|
+
`);
|
|
223
|
+
console.log(ansis.bold(isZh ? "\u9009\u9879\uFF1A" : "Options:"));
|
|
224
|
+
console.log(` --format, -f ${isZh ? "\u8F93\u51FA\u683C\u5F0F (table|json|list)" : "Output format (table|json|list)"}`);
|
|
225
|
+
console.log(` --verbose, -v ${isZh ? "\u8BE6\u7EC6\u8F93\u51FA" : "Verbose output"}`);
|
|
226
|
+
console.log(` --type, -t ${isZh ? "\u8FC7\u6EE4\u7C7B\u578B (allow|deny)" : "Filter by type (allow|deny)"}`);
|
|
227
|
+
console.log(` --category, -c ${isZh ? "\u8FC7\u6EE4\u5206\u7C7B" : "Filter by category"}`);
|
|
228
|
+
console.log(` --action, -a ${isZh ? "\u68C0\u67E5\u7684\u64CD\u4F5C" : "Action to check"}`);
|
|
229
|
+
console.log(` --description, -d ${isZh ? "\u89C4\u5219\u63CF\u8FF0" : "Rule description"}`);
|
|
230
|
+
console.log(` --merge ${isZh ? "\u5408\u5E76\u5BFC\u5165\uFF08\u800C\u4E0D\u662F\u66FF\u6362\uFF09" : "Merge on import (not replace)"}
|
|
231
|
+
`);
|
|
232
|
+
console.log(ansis.bold(isZh ? "\u793A\u4F8B\uFF1A" : "Examples:"));
|
|
411
233
|
console.log(" ccjk permissions list");
|
|
412
|
-
console.log(
|
|
413
|
-
console.log(' ccjk permissions
|
|
414
|
-
console.log(
|
|
415
|
-
console.log(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
234
|
+
console.log(" ccjk permissions search");
|
|
235
|
+
console.log(' ccjk permissions check "Bash(npm install)"');
|
|
236
|
+
console.log(' ccjk permissions grant "Bash(npm *)"');
|
|
237
|
+
console.log(' ccjk permissions test "mcp__server__*"');
|
|
238
|
+
console.log(" ccjk permissions diagnose");
|
|
239
|
+
console.log(" ccjk permissions examples\n");
|
|
240
|
+
console.log(ansis.bold(isZh ? "\u6A21\u5F0F\u683C\u5F0F\uFF1A" : "Pattern Formats:"));
|
|
241
|
+
console.log(` Bash(npm install) ${isZh ? "\u7CBE\u786E\u5339\u914D Bash \u547D\u4EE4" : "Exact Bash command match"}`);
|
|
242
|
+
console.log(` Bash(npm *) ${isZh ? "\u5339\u914D\u6240\u6709 npm \u547D\u4EE4" : "Match all npm commands"}`);
|
|
243
|
+
console.log(` Bash(* install) ${isZh ? '\u5339\u914D\u4EFB\u610F "* install" \u547D\u4EE4' : 'Match any "* install" command'}`);
|
|
244
|
+
console.log(` mcp__server__* ${isZh ? "\u5339\u914D MCP \u670D\u52A1\u5668\u5DE5\u5177" : "Match MCP server tools"}`);
|
|
245
|
+
console.log(` /home/user/* ${isZh ? "\u5339\u914D\u8DEF\u5F84\u6A21\u5F0F" : "Match path patterns"}`);
|
|
246
|
+
console.log(` https://api.* ${isZh ? "\u5339\u914D URL \u6A21\u5F0F" : "Match URL patterns"}
|
|
247
|
+
`);
|
|
426
248
|
}
|
|
427
249
|
|
|
428
250
|
export { checkPermission, exportPermissions, grantPermission, importPermissions, listPermissions, permissionsHelp, resetPermissions, revokePermission };
|