@1a35e1/sonar-cli 0.4.0 → 0.4.1

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.
@@ -6,10 +6,11 @@ import { writeSkillTo } from '../../lib/skill.js';
6
6
  export const options = zod.object({
7
7
  install: zod.boolean().default(false).describe('Install to ~/.claude/skills/sonar/SKILL.md'),
8
8
  dest: zod.string().optional().describe('Write to a custom path'),
9
+ force: zod.boolean().default(false).describe('Overwrite even if file was modified'),
9
10
  });
10
11
  export default function Skill({ options: flags }) {
11
12
  useEffect(() => {
12
- writeSkillTo(flags.dest, flags.install);
13
+ writeSkillTo(flags.dest, flags.install, flags.force);
13
14
  }, []);
14
15
  return _jsx(Text, { dimColor: true, children: "Generating SKILL.md..." });
15
16
  }
package/dist/lib/skill.js CHANGED
@@ -1,4 +1,5 @@
1
- import { writeFileSync, mkdirSync } from 'node:fs';
1
+ import { writeFileSync, readFileSync, existsSync, mkdirSync } from 'node:fs';
2
+ import { createHash } from 'node:crypto';
2
3
  import { join, dirname } from 'node:path';
3
4
  import { homedir } from 'node:os';
4
5
  const SKILL_CONTENT = `---
@@ -109,18 +110,33 @@ sonar config nuke --confirm
109
110
  | \`ANTHROPIC_API_KEY\` | Required when vendor is \`anthropic\` |
110
111
  `;
111
112
  const DEFAULT_INSTALL_PATH = join(homedir(), '.claude', 'skills', 'sonar', 'SKILL.md');
112
- export function writeSkillTo(dest, install) {
113
+ function sha256(content) {
114
+ return createHash('sha256').update(content).digest('hex');
115
+ }
116
+ function safeWrite(target, content, force) {
117
+ if (existsSync(target) && !force) {
118
+ const existing = readFileSync(target, 'utf8');
119
+ if (existing === content) {
120
+ process.stdout.write(`SKILL.md is already up to date: ${target}\n`);
121
+ process.exit(0);
122
+ }
123
+ // File exists and differs — user may have customized it
124
+ process.stderr.write(`SKILL.md has been modified: ${target}\n` +
125
+ `Use --force to overwrite, or manually merge.\n` +
126
+ `New version hash: ${sha256(content).slice(0, 8)}\n`);
127
+ process.exit(1);
128
+ }
129
+ mkdirSync(dirname(target), { recursive: true });
130
+ writeFileSync(target, content, 'utf8');
131
+ process.stdout.write(`SKILL.md written to ${target}\n`);
132
+ }
133
+ export function writeSkillTo(dest, install, force) {
113
134
  if (install || dest === '--install') {
114
- const target = DEFAULT_INSTALL_PATH;
115
- mkdirSync(dirname(target), { recursive: true });
116
- writeFileSync(target, SKILL_CONTENT, 'utf8');
117
- process.stdout.write(`SKILL.md written to ${target}\n`);
135
+ safeWrite(DEFAULT_INSTALL_PATH, SKILL_CONTENT, force ?? false);
118
136
  process.exit(0);
119
137
  }
120
138
  if (dest) {
121
- mkdirSync(dirname(dest), { recursive: true });
122
- writeFileSync(dest, SKILL_CONTENT, 'utf8');
123
- process.stdout.write(`SKILL.md written to ${dest}\n`);
139
+ safeWrite(dest, SKILL_CONTENT, force ?? false);
124
140
  process.exit(0);
125
141
  }
126
142
  // Default: print to stdout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1a35e1/sonar-cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "X social graph CLI for signal filtering and curation",
5
5
  "type": "module",
6
6
  "bin": {