clikit-plugin 0.2.1 → 0.2.3

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 (2) hide show
  1. package/dist/cli.js +21 -7
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -44,15 +44,21 @@ function ensureConfigDir() {
44
44
  function parseConfig(configPath) {
45
45
  try {
46
46
  if (!fs.existsSync(configPath)) {
47
- return {};
47
+ return { config: {}, raw: "", parseError: null };
48
48
  }
49
49
  const content = fs.readFileSync(configPath, "utf-8");
50
- const cleaned = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
51
- const cleanedTrailing = cleaned.replace(/,\s*([}\]])/g, "$1");
52
- return JSON.parse(cleanedTrailing);
50
+ try {
51
+ const parsed = JSON.parse(content);
52
+ return { config: parsed, raw: content, parseError: null };
53
+ } catch {
54
+ const cleaned = content.replace(/\/\*[\s\S]*?\*\//g, "");
55
+ const cleanedTrailing = cleaned.replace(/,\s*([}\]])/g, "$1");
56
+ const parsed = JSON.parse(cleanedTrailing);
57
+ return { config: parsed, raw: content, parseError: null };
58
+ }
53
59
  } catch (err) {
54
- console.error(`Warning: Failed to parse config at ${configPath}: ${err}`);
55
- return {};
60
+ const raw = fs.existsSync(configPath) ? fs.readFileSync(configPath, "utf-8") : "";
61
+ return { config: {}, raw, parseError: String(err) };
56
62
  }
57
63
  }
58
64
  function backupConfig(configPath) {
@@ -93,7 +99,15 @@ async function install() {
93
99
  if (backupPath) {
94
100
  console.log(` Backup created: ${backupPath}`);
95
101
  }
96
- const config = parseConfig(configPath);
102
+ const result = parseConfig(configPath);
103
+ if (result.parseError && result.raw.trim()) {
104
+ console.error(`\u2717 Config file has syntax errors and cannot be safely modified.`);
105
+ console.error(` Error: ${result.parseError}`);
106
+ console.error(` Please fix the config file manually or restore from backup.`);
107
+ console.error(` Backup: ${backupPath}`);
108
+ return 1;
109
+ }
110
+ const config = result.config;
97
111
  const existingPlugins = Array.isArray(config.plugin) ? config.plugin : [];
98
112
  const preservedKeys = Object.keys(config).filter((k) => k !== "plugin");
99
113
  if (preservedKeys.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clikit-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "OpenCode plugin with 10 agents, 19 commands, 48 skills, 14 hooks",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",