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.
Files changed (107) hide show
  1. package/README.md +103 -896
  2. package/dist/chunks/ccr.mjs +1 -0
  3. package/dist/chunks/doctor.mjs +58 -0
  4. package/dist/chunks/index.mjs +6 -0
  5. package/dist/chunks/package.mjs +1 -1
  6. package/dist/chunks/permissions.mjs +164 -342
  7. package/dist/chunks/thinking.mjs +615 -0
  8. package/dist/chunks/vim.mjs +891 -0
  9. package/dist/cli.mjs +49 -0
  10. package/dist/i18n/locales/en/configuration.json +97 -1
  11. package/dist/i18n/locales/en/lsp.json +78 -0
  12. package/dist/i18n/locales/en/mcp.json +11 -0
  13. package/dist/i18n/locales/en/permissions.json +53 -1
  14. package/dist/i18n/locales/en/thinking.json +65 -0
  15. package/dist/i18n/locales/en/vim.json +169 -0
  16. package/dist/i18n/locales/zh-CN/configuration.json +97 -1
  17. package/dist/i18n/locales/zh-CN/lsp.json +78 -0
  18. package/dist/i18n/locales/zh-CN/mcp.json +11 -0
  19. package/dist/i18n/locales/zh-CN/permissions.json +53 -1
  20. package/dist/i18n/locales/zh-CN/thinking.json +65 -0
  21. package/dist/i18n/locales/zh-CN/vim.json +169 -0
  22. package/dist/shared/ccjk.pi0nsyn3.mjs +1242 -0
  23. package/package.json +55 -55
  24. package/templates/claude-code/common/settings.json +63 -30
  25. package/templates/CLAUDE.md +0 -219
  26. package/templates/claude-code/CLAUDE.md +0 -250
  27. package/templates/claude-code/en/workflow/bmad/commands/bmad-init.md +0 -165
  28. package/templates/claude-code/en/workflow/common/agents/get-current-datetime.md +0 -29
  29. package/templates/claude-code/en/workflow/common/agents/init-architect.md +0 -114
  30. package/templates/claude-code/en/workflow/common/commands/init-project.md +0 -53
  31. package/templates/claude-code/en/workflow/essential/agents/get-current-datetime.md +0 -29
  32. package/templates/claude-code/en/workflow/essential/agents/init-architect.md +0 -114
  33. package/templates/claude-code/en/workflow/essential/agents/planner.md +0 -116
  34. package/templates/claude-code/en/workflow/essential/agents/ui-ux-designer.md +0 -91
  35. package/templates/claude-code/en/workflow/essential/commands/feat.md +0 -250
  36. package/templates/claude-code/en/workflow/essential/commands/init-project.md +0 -53
  37. package/templates/claude-code/en/workflow/plan/agents/planner.md +0 -116
  38. package/templates/claude-code/en/workflow/plan/agents/ui-ux-designer.md +0 -91
  39. package/templates/claude-code/en/workflow/plan/commands/feat.md +0 -105
  40. package/templates/claude-code/zh-CN/workflow/bmad/commands/bmad-init.md +0 -172
  41. package/templates/claude-code/zh-CN/workflow/common/agents/get-current-datetime.md +0 -29
  42. package/templates/claude-code/zh-CN/workflow/common/agents/init-architect.md +0 -114
  43. package/templates/claude-code/zh-CN/workflow/common/commands/init-project.md +0 -53
  44. package/templates/claude-code/zh-CN/workflow/essential/agents/get-current-datetime.md +0 -29
  45. package/templates/claude-code/zh-CN/workflow/essential/agents/init-architect.md +0 -114
  46. package/templates/claude-code/zh-CN/workflow/essential/agents/planner.md +0 -116
  47. package/templates/claude-code/zh-CN/workflow/essential/agents/ui-ux-designer.md +0 -91
  48. package/templates/claude-code/zh-CN/workflow/essential/commands/feat.md +0 -248
  49. package/templates/claude-code/zh-CN/workflow/essential/commands/init-project.md +0 -53
  50. package/templates/claude-code/zh-CN/workflow/plan/agents/planner.md +0 -116
  51. package/templates/claude-code/zh-CN/workflow/plan/agents/ui-ux-designer.md +0 -91
  52. package/templates/claude-code/zh-CN/workflow/plan/commands/feat.md +0 -105
  53. package/templates/codex/common/config.toml +0 -0
  54. package/templates/common/output-styles/en/casual-friendly.md +0 -97
  55. package/templates/common/output-styles/en/expert-concise.md +0 -93
  56. package/templates/common/output-styles/en/pair-programmer.md +0 -177
  57. package/templates/common/output-styles/en/senior-architect.md +0 -121
  58. package/templates/common/output-styles/en/speed-coder.md +0 -185
  59. package/templates/common/output-styles/en/teaching-mode.md +0 -102
  60. package/templates/common/output-styles/en/technical-precise.md +0 -101
  61. package/templates/common/output-styles/zh-CN/pair-programmer.md +0 -177
  62. package/templates/common/output-styles/zh-CN/senior-architect.md +0 -297
  63. package/templates/common/output-styles/zh-CN/speed-coder.md +0 -185
  64. package/templates/common/skills/code-review.md +0 -343
  65. package/templates/common/skills/en/agent-browser.md +0 -258
  66. package/templates/common/skills/en/brainstorming.md +0 -64
  67. package/templates/common/skills/en/code-review.md +0 -81
  68. package/templates/common/skills/en/documentation-gen.md +0 -808
  69. package/templates/common/skills/en/executing-plans.md +0 -75
  70. package/templates/common/skills/en/git-commit.md +0 -216
  71. package/templates/common/skills/en/interview.md +0 -223
  72. package/templates/common/skills/en/migration-assistant.md +0 -312
  73. package/templates/common/skills/en/performance-profiling.md +0 -576
  74. package/templates/common/skills/en/pr-review.md +0 -341
  75. package/templates/common/skills/en/refactoring.md +0 -384
  76. package/templates/common/skills/en/security-audit.md +0 -462
  77. package/templates/common/skills/en/systematic-debugging.md +0 -82
  78. package/templates/common/skills/en/tdd-workflow.md +0 -93
  79. package/templates/common/skills/en/verification.md +0 -81
  80. package/templates/common/skills/en/workflow.md +0 -370
  81. package/templates/common/skills/en/writing-plans.md +0 -78
  82. package/templates/common/skills/summarize.md +0 -312
  83. package/templates/common/skills/translate.md +0 -202
  84. package/templates/common/skills/zh-CN/agent-browser.md +0 -260
  85. package/templates/common/skills/zh-CN/documentation-gen.md +0 -807
  86. package/templates/common/skills/zh-CN/migration-assistant.md +0 -318
  87. package/templates/common/skills/zh-CN/performance-profiling.md +0 -746
  88. package/templates/common/skills/zh-CN/pr-review.md +0 -341
  89. package/templates/common/skills/zh-CN/refactoring.md +0 -384
  90. package/templates/common/skills/zh-CN/security-audit.md +0 -462
  91. package/templates/common/smart-guide/en/smart-guide.md +0 -72
  92. package/templates/common/smart-guide/zh-CN/smart-guide.md +0 -72
  93. package/templates/common/workflow/git/en/git-cleanBranches.md +0 -102
  94. package/templates/common/workflow/git/en/git-commit.md +0 -205
  95. package/templates/common/workflow/git/en/git-rollback.md +0 -90
  96. package/templates/common/workflow/git/en/git-worktree.md +0 -276
  97. package/templates/common/workflow/git/zh-CN/git-cleanBranches.md +0 -102
  98. package/templates/common/workflow/git/zh-CN/git-commit.md +0 -205
  99. package/templates/common/workflow/git/zh-CN/git-rollback.md +0 -90
  100. package/templates/common/workflow/git/zh-CN/git-worktree.md +0 -276
  101. package/templates/common/workflow/interview/en/interview.md +0 -212
  102. package/templates/common/workflow/interview/zh-CN/interview.md +0 -212
  103. package/templates/common/workflow/sixStep/en/workflow.md +0 -357
  104. package/templates/common/workflow/sixStep/zh-CN/workflow.md +0 -357
  105. package/templates/industry/devops/en/ci-cd-pipeline.md +0 -410
  106. package/templates/industry/web-dev/en/api-design.md +0 -299
  107. 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 chalk from 'chalk';
3
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
4
- import { homedir } from 'node:os';
5
- import { join } from 'pathe';
6
-
7
- class PermissionManager {
8
- permissions = [];
9
- configPath;
10
- constructor(configPath) {
11
- this.configPath = configPath || join(homedir(), ".ccjk", "config.json");
12
- this.loadPermissions();
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 permissions = permissionManager.listPermissions();
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(permissions, null, 2));
28
+ console.log(JSON.stringify(rules, null, 2));
244
29
  return;
245
30
  }
246
- console.log(chalk.bold("\n\u{1F4CB} CCJK Permissions\n"));
247
- if (permissions.length === 0) {
248
- console.log(chalk.yellow("No permissions configured."));
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 perm of permissions) {
253
- const typeColor = getTypeColor(perm.type);
254
- console.log(`${chalk.cyan(perm.pattern)}: ${typeColor(perm.type)}`);
255
- if (verbose && perm.description) {
256
- console.log(chalk.gray(` Description: ${perm.description}`));
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(chalk.bold("Pattern".padEnd(40)) + chalk.bold("Type".padEnd(15)) + chalk.bold("Scope"));
261
- console.log("\u2500".repeat(70));
262
- for (const perm of permissions) {
263
- const typeColor = getTypeColor(perm.type);
264
- const pattern = perm.pattern.padEnd(40);
265
- const type = typeColor(perm.type.padEnd(15));
266
- const scope = perm.scope;
267
- console.log(`${pattern}${type}${scope}`);
268
- if (verbose && perm.description) {
269
- console.log(chalk.gray(` Description: ${perm.description}`));
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(chalk.red("Error: Resource is required"));
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 || "read";
80
+ const action = options.action || "execute";
282
81
  const verbose = options.verbose || false;
283
- console.log(chalk.bold(`
284
- \u{1F50D} Checking permission for: ${chalk.cyan(resource)}
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(chalk.green("\u2713 Permission granted"));
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(chalk.red("\u2717 Permission denied"));
296
- console.log(` Reason: ${result.reason}`);
297
- console.log(chalk.yellow(' Use "ccjk permissions grant" to grant permission'));
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, _options) {
101
+ async function grantPermission(resource, options) {
102
+ const isZh = i18n.language === "zh-CN";
302
103
  if (!resource) {
303
- console.error(chalk.red("Error: Resource is required"));
304
- console.log("Usage: ccjk permissions grant <resource>");
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(chalk.bold(`
308
- \u2713 Granting permission for: ${chalk.cyan(resource)}
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(chalk.green("Permission granted successfully!"));
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(chalk.red("Error: Resource is required"));
323
- console.log("Usage: ccjk permissions revoke <resource>");
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(chalk.bold(`
327
- \u2717 Revoking permission for: ${chalk.cyan(resource)}
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 > 0) {
331
- console.log(chalk.green(`Permission revoked successfully! (${removed} rule(s) removed)`));
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(chalk.yellow("No matching permission found."));
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
- console.log(chalk.bold("\n\u26A0\uFE0F Resetting all permissions\n"));
339
- const readline = await import('node:readline');
340
- const rl = readline.createInterface({
341
- input: process__default.stdin,
342
- output: process__default.stdout
343
- });
344
- const answer = await new Promise((resolve) => {
345
- rl.question(chalk.yellow("Are you sure you want to reset all permissions? (yes/no): "), resolve);
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
- rl.close();
348
- if (answer.toLowerCase() !== "yes") {
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(chalk.green("All permissions have been reset!"));
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(chalk.bold(`
361
- \u{1F4E4} Exporting permissions to: ${chalk.cyan(outputPath)}
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.length + permissions.deny.length;
366
- console.log(chalk.green(`Exported ${totalCount} permissions successfully!`));
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, _options) {
176
+ async function importPermissions(filePath, options) {
177
+ const isZh = i18n.language === "zh-CN";
370
178
  if (!filePath) {
371
- console.error(chalk.red("Error: File path is required"));
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(chalk.bold(`
377
- \u{1F4E5} Importing permissions from: ${chalk.cyan(filePath)}
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
- permissionManager.importPermissions(config, false);
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(chalk.green(`Imported ${totalCount} permissions successfully!`));
196
+ console.log(ansis.green(`\u2713 Imported ${totalCount} permission(s) successfully!`));
388
197
  } catch (error) {
389
- console.error(chalk.red("Error importing permissions:"), 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
- console.log(chalk.bold("\n\u{1F4CB} CCJK Permissions Management\n"));
396
- console.log(chalk.bold("Usage:"));
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(chalk.bold("Actions:"));
399
- console.log(" list List all permissions");
400
- console.log(" check <resource> Check permission for a resource");
401
- console.log(" grant <resource> Grant permission for a resource");
402
- console.log(" revoke <resource> Revoke permission for a resource");
403
- console.log(" reset Reset all permissions");
404
- console.log(" export [file] Export permissions to a file");
405
- console.log(" import <file> Import permissions from a file\n");
406
- console.log(chalk.bold("Options:"));
407
- console.log(" --format, -f Output format (table|json|list)");
408
- console.log(" --verbose, -v Verbose output");
409
- console.log(" --action, -a Action to check (read|write|admin)\n");
410
- console.log(chalk.bold("Examples:"));
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(' ccjk permissions check "Provider(302ai):*"');
413
- console.log(' ccjk permissions grant "Provider(302ai):*"');
414
- console.log(" ccjk permissions export permissions.json");
415
- console.log(" ccjk permissions import permissions.json\n");
416
- }
417
- function getTypeColor(type) {
418
- switch (type) {
419
- case "allow":
420
- return chalk.green;
421
- case "deny":
422
- return chalk.red;
423
- default:
424
- return chalk.gray;
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 };