@neikyun/ciel 5.2.7 → 5.2.9

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/bin/ciel.js +125 -2
  2. package/package.json +1 -1
package/bin/ciel.js CHANGED
@@ -1,6 +1,129 @@
1
1
  #!/usr/bin/env node
2
2
  // Ciel CLI — bootstrap entry point
3
- // This file exists before build so npm can validate the bin path.
4
- // It loads the compiled CLI from dist/ at runtime.
3
+ // Vérifie si l'initialisation est nécessaire, sinon lance la CLI normalement.
4
+ // Solution de secours quand le postinstall npm ne s'exécute pas.
5
5
 
6
+ const { existsSync, mkdirSync, writeFileSync, readFileSync, copyFileSync, readdirSync, chmodSync, unlinkSync } = require("fs");
7
+ const { join, dirname } = require("path");
8
+ const { execSync } = require("child_process");
9
+
10
+ const PKG_DIR = join(__dirname, "..");
11
+ const PKG = JSON.parse(readFileSync(join(PKG_DIR, "package.json"), "utf-8"));
12
+ const CIEL_VERSION = PKG.version || "0.0.0";
13
+ const ASSETS = join(PKG_DIR, "assets");
14
+
15
+ // Vérifier si une (ré)initialisation est nécessaire
16
+ const targetDir = process.env.INIT_CWD || process.cwd();
17
+ const memPath = join(targetDir, ".ciel", "memory.json");
18
+ const storedVersion = (() => { try { return JSON.parse(readFileSync(memPath, "utf-8")).cielVersion; } catch { return null; } })();
19
+ const needsInit = !existsSync(memPath) || storedVersion !== CIEL_VERSION;
20
+
21
+ function copyDir(src, dest) {
22
+ if (!existsSync(src)) return 0;
23
+ let count = 0;
24
+ mkdirSync(dest, { recursive: true });
25
+ for (const entry of readdirSync(src, { withFileTypes: true })) {
26
+ const s = join(src, entry.name), d = join(dest, entry.name);
27
+ if (entry.isDirectory()) count += copyDir(s, d);
28
+ else { copyFileSync(s, d); if (s.endsWith(".sh")) try { chmodSync(d, 0o755); } catch {} count++; }
29
+ }
30
+ return count;
31
+ }
32
+
33
+ function patchConfig(targetDir, assets) {
34
+ const cfgPath = join(targetDir, "opencode.json");
35
+ if (!existsSync(cfgPath)) return false;
36
+ try {
37
+ const cfg = JSON.parse(readFileSync(cfgPath, "utf-8"));
38
+ if (!cfg.plugin) cfg.plugin = [];
39
+ cfg.plugin = cfg.plugin.filter(p => p !== "./.opencode/plugins/ciel.ts");
40
+ if (!cfg.plugin.includes("@neikyun/ciel")) cfg.plugin.push("@neikyun/ciel");
41
+ if (!cfg.instructions) cfg.instructions = [];
42
+ if (!cfg.instructions.includes("AGENTS.md")) cfg.instructions.push("AGENTS.md");
43
+ writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
44
+ return true;
45
+ } catch { return false; }
46
+ }
47
+
48
+ function runInit(targetDir, assets) {
49
+ let total = 0;
50
+
51
+ // .ciel/ state
52
+ mkdirSync(join(targetDir, ".ciel"), { recursive: true });
53
+ if (!existsSync(join(targetDir, ".ciel/map.json")))
54
+ writeFileSync(join(targetDir, ".ciel/map.json"), JSON.stringify({ modules: [], lastUpdated: "" }), "utf-8");
55
+ if (!existsSync(join(targetDir, ".ciel/parking.md")))
56
+ writeFileSync(join(targetDir, ".ciel/parking.md"), "# Ciel Parking Lot\n\n", "utf-8");
57
+
58
+ // OpenCode files
59
+ if (existsSync(join(targetDir, "opencode.json")) || existsSync(join(targetDir, ".opencode"))) {
60
+ // Clean old curl plugin
61
+ const old = join(targetDir, ".opencode/plugins/ciel.ts");
62
+ if (existsSync(old)) { try { unlinkSync(old); } catch {} }
63
+ // Copy agents
64
+ total += copyDir(join(assets, "platforms/opencode/.opencode/agents"), join(targetDir, ".opencode/agents"));
65
+ // Copy commands
66
+ total += copyDir(join(assets, "platforms/opencode/.opencode/commands"), join(targetDir, ".opencode/commands"));
67
+ // Copy AGENTS.md
68
+ if (existsSync(join(assets, "platforms/opencode/AGENTS.md"))) {
69
+ copyFileSync(join(assets, "platforms/opencode/AGENTS.md"), join(targetDir, "AGENTS.md"));
70
+ total++;
71
+ }
72
+ if (patchConfig(targetDir, assets)) total++;
73
+ console.error(` ${green("✓")} OpenCode: ${total} fichiers`);
74
+ }
75
+
76
+ // Claude Code files
77
+ if (existsSync(join(targetDir, ".claude/settings.json")) || existsSync(join(targetDir, ".claude"))) {
78
+ total += copyDir(join(assets, ".claude/agents"), join(targetDir, ".claude/agents"));
79
+ total += copyDir(join(assets, ".claude/hooks"), join(targetDir, ".claude/hooks"));
80
+ total += copyDir(join(assets, "commands"), join(targetDir, ".claude/commands"));
81
+ if (existsSync(join(assets, ".claude/settings.json"))) {
82
+ copyFileSync(join(assets, ".claude/settings.json"), join(targetDir, ".claude/settings.json"));
83
+ }
84
+ if (existsSync(join(assets, "CLAUDE.md"))) {
85
+ copyFileSync(join(assets, "CLAUDE.md"), join(targetDir, "CLAUDE.md"));
86
+ }
87
+ console.error(` ${green("✓")} Claude Code: ${total} fichiers`);
88
+ }
89
+
90
+ // Save version
91
+ writeFileSync(memPath, JSON.stringify({ cielVersion: CIEL_VERSION, lastUpdated: new Date().toISOString() }, null, 2), "utf-8");
92
+ return total;
93
+ }
94
+
95
+ const c = (code, s) => process.stderr.isTTY ? `\x1b[${code}m${s}\x1b[0m` : s;
96
+ const green = (s) => c(32, s);
97
+ const cyan = (s) => c(36, s);
98
+
99
+ if (needsInit) {
100
+ const args = process.argv.slice(2);
101
+ if (!args.includes("--help") && !args.includes("-h") && !args.includes("--version") && !args.includes("-v")) {
102
+ try {
103
+ const hasOC = existsSync(join(targetDir, "opencode.json")) || existsSync(join(targetDir, ".opencode"));
104
+ const hasClaude = existsSync(join(targetDir, ".claude/settings.json")) || existsSync(join(targetDir, ".claude"));
105
+ const hasOC_CLI = (() => { try { return execSync("opencode --version 2>&1", { stdio: "pipe", timeout: 3000 }).toString().length > 0; } catch { return false; } })();
106
+ const hasClaude_CLI = (() => { try { return execSync("claude --version 2>&1", { stdio: "pipe", timeout: 3000 }).toString().length > 0; } catch { return false; } })();
107
+
108
+ // Créer les configs si CLI détectée mais pas de fichier
109
+ if (hasOC_CLI && !hasOC) {
110
+ writeFileSync(join(targetDir, "opencode.json"), JSON.stringify({ $schema: "https://opencode.ai/config.json", plugin: ["@neikyun/ciel"] }, null, 2) + "\n", "utf-8");
111
+ }
112
+ if (hasClaude_CLI && !hasClaude) {
113
+ mkdirSync(join(targetDir, ".claude"), { recursive: true });
114
+ writeFileSync(join(targetDir, ".claude/settings.json"), "{}\n", "utf-8");
115
+ }
116
+
117
+ if (hasOC || hasClaude || hasOC_CLI || hasClaude_CLI) {
118
+ if (existsSync(ASSETS) && existsSync(join(ASSETS, "platforms/opencode/.opencode/agents/ciel.md"))) {
119
+ console.error(`\n ⚡ Ciel v${CIEL_VERSION} — Premier lancement, initialisation...`);
120
+ const n = runInit(targetDir, ASSETS);
121
+ console.error(` ${green("✓")} Ciel v${CIEL_VERSION} configuré (${n} fichiers)\n`);
122
+ }
123
+ }
124
+ } catch {}
125
+ }
126
+ }
127
+
128
+ // Lancer la CLI normalement
6
129
  require("../dist/cli/index.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neikyun/ciel",
3
- "version": "5.2.7",
3
+ "version": "5.2.9",
4
4
  "description": "Ciel — Deep-reasoning pipeline for LLM-assisted development. OpenCode plugin + multi-platform CLI (OpenCode, Claude Code, more).",
5
5
  "main": "./dist/plugin/index.js",
6
6
  "types": "./dist/plugin/index.d.ts",