holohq 0.0.0-stage → 0.2.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 (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.fr.md +145 -0
  3. package/README.md +144 -2
  4. package/bin/holohq.js +12 -0
  5. package/dist/server/server/actions/clone.js +36 -0
  6. package/dist/server/server/actions/newProject.js +40 -0
  7. package/dist/server/server/actions/publish.js +22 -0
  8. package/dist/server/server/app.js +46 -0
  9. package/dist/server/server/autostart.js +127 -0
  10. package/dist/server/server/autostartRun.js +96 -0
  11. package/dist/server/server/browser.js +24 -0
  12. package/dist/server/server/cache.js +24 -0
  13. package/dist/server/server/claude/floor.js +408 -0
  14. package/dist/server/server/claude/history.js +268 -0
  15. package/dist/server/server/claude/prompt.js +8 -0
  16. package/dist/server/server/cli/autostart.js +21 -0
  17. package/dist/server/server/cli/config.js +45 -0
  18. package/dist/server/server/cli/convention.js +51 -0
  19. package/dist/server/server/cli/io.js +1 -0
  20. package/dist/server/server/cli/main.js +129 -0
  21. package/dist/server/server/config.js +311 -0
  22. package/dist/server/server/demo/config.js +19 -0
  23. package/dist/server/server/demo/data.js +317 -0
  24. package/dist/server/server/demo/deps.js +36 -0
  25. package/dist/server/server/demo/floor.js +45 -0
  26. package/dist/server/server/demo/run.js +315 -0
  27. package/dist/server/server/demo/scan.js +21 -0
  28. package/dist/server/server/domain/home.js +85 -0
  29. package/dist/server/server/domain/journal.js +33 -0
  30. package/dist/server/server/domain/sprint.js +9 -0
  31. package/dist/server/server/exec.js +12 -0
  32. package/dist/server/server/floor/attribute.js +74 -0
  33. package/dist/server/server/floor/evidence.js +39 -0
  34. package/dist/server/server/git/status.js +45 -0
  35. package/dist/server/server/github/gh.js +27 -0
  36. package/dist/server/server/github/labels.js +65 -0
  37. package/dist/server/server/github/project.js +58 -0
  38. package/dist/server/server/github/repos.js +17 -0
  39. package/dist/server/server/github/write.js +91 -0
  40. package/dist/server/server/guard.js +18 -0
  41. package/dist/server/server/index.js +9 -0
  42. package/dist/server/server/launch.js +168 -0
  43. package/dist/server/server/paths.js +26 -0
  44. package/dist/server/server/preload.js +30 -0
  45. package/dist/server/server/projects/remote.js +13 -0
  46. package/dist/server/server/projects/scan.js +79 -0
  47. package/dist/server/server/routes/actions.js +89 -0
  48. package/dist/server/server/routes/autostart.js +21 -0
  49. package/dist/server/server/routes/conversations.js +21 -0
  50. package/dist/server/server/routes/detail.js +24 -0
  51. package/dist/server/server/routes/floor.js +77 -0
  52. package/dist/server/server/routes/home.js +64 -0
  53. package/dist/server/server/routes/launch.js +79 -0
  54. package/dist/server/server/routes/projects.js +75 -0
  55. package/dist/server/server/routes/remotes.js +30 -0
  56. package/dist/server/server/routes/setup.js +114 -0
  57. package/dist/server/server/routes/write.js +129 -0
  58. package/dist/server/server/setup/tools.js +37 -0
  59. package/dist/server/server/skills.js +69 -0
  60. package/dist/server/server/start.js +166 -0
  61. package/dist/server/server/static.js +49 -0
  62. package/dist/server/shared/color.js +59 -0
  63. package/dist/server/shared/errors.js +88 -0
  64. package/dist/server/shared/ideas.js +36 -0
  65. package/dist/server/shared/labels.js +36 -0
  66. package/dist/server/shared/repoName.js +13 -0
  67. package/dist/server/shared/themes.js +120 -0
  68. package/dist/server/shared/tiers.js +15 -0
  69. package/dist/server/shared/types.js +1 -0
  70. package/dist/web/assets/Globe-ighOFp2V.js +4273 -0
  71. package/dist/web/assets/index-ByHbMQJl.js +11 -0
  72. package/dist/web/assets/index-DgR2KpYV.css +1 -0
  73. package/dist/web/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  74. package/dist/web/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
  75. package/dist/web/assets/jetbrains-mono-cyrillic-600-normal-8K4wrrwR.woff +0 -0
  76. package/dist/web/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  77. package/dist/web/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
  78. package/dist/web/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  79. package/dist/web/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  80. package/dist/web/assets/jetbrains-mono-greek-600-normal-mc2nkWzM.woff +0 -0
  81. package/dist/web/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  82. package/dist/web/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  83. package/dist/web/assets/jetbrains-mono-latin-600-normal-BfsvjouI.woff +0 -0
  84. package/dist/web/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  85. package/dist/web/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  86. package/dist/web/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
  87. package/dist/web/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  88. package/dist/web/assets/jetbrains-mono-latin-ext-600-normal-DObL3zCW.woff +0 -0
  89. package/dist/web/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
  90. package/dist/web/assets/jetbrains-mono-vietnamese-600-normal-OWROknRo.woff +0 -0
  91. package/dist/web/assets/rajdhani-devanagari-500-normal-BPH8g_s8.woff +0 -0
  92. package/dist/web/assets/rajdhani-devanagari-500-normal-B_DH_jja.woff2 +0 -0
  93. package/dist/web/assets/rajdhani-devanagari-600-normal-BtY48IV_.woff +0 -0
  94. package/dist/web/assets/rajdhani-devanagari-600-normal-DhS7ScYx.woff2 +0 -0
  95. package/dist/web/assets/rajdhani-devanagari-700-normal-BQQOj9BB.woff2 +0 -0
  96. package/dist/web/assets/rajdhani-devanagari-700-normal-DBRwWuxA.woff +0 -0
  97. package/dist/web/assets/rajdhani-latin-500-normal-ByNUCHrt.woff2 +0 -0
  98. package/dist/web/assets/rajdhani-latin-500-normal-DfvNI-Td.woff +0 -0
  99. package/dist/web/assets/rajdhani-latin-600-normal-CXCVEoA9.woff2 +0 -0
  100. package/dist/web/assets/rajdhani-latin-600-normal-Dx02qI2_.woff +0 -0
  101. package/dist/web/assets/rajdhani-latin-700-normal-BPDUZo87.woff2 +0 -0
  102. package/dist/web/assets/rajdhani-latin-700-normal-e0Uj8ZlN.woff +0 -0
  103. package/dist/web/assets/rajdhani-latin-ext-500-normal-CyRWJZ5B.woff +0 -0
  104. package/dist/web/assets/rajdhani-latin-ext-500-normal-DiyUS11w.woff2 +0 -0
  105. package/dist/web/assets/rajdhani-latin-ext-600-normal-BleIgkPp.woff +0 -0
  106. package/dist/web/assets/rajdhani-latin-ext-600-normal-C9ZjJQAt.woff2 +0 -0
  107. package/dist/web/assets/rajdhani-latin-ext-700-normal-BPaQ7tlD.woff +0 -0
  108. package/dist/web/assets/rajdhani-latin-ext-700-normal-S6aYESQK.woff2 +0 -0
  109. package/dist/web/index.html +13 -0
  110. package/package.json +74 -4
  111. package/scripts/autostart.ps1 +28 -0
  112. package/scripts/start-hidden.vbs +12 -0
  113. package/templates/en/CLAUDE.md +18 -0
  114. package/templates/en/README.md +3 -0
  115. package/templates/fr/CLAUDE.md +18 -0
  116. package/templates/fr/README.md +3 -0
@@ -0,0 +1,268 @@
1
+ import { open, readdir, stat } from 'node:fs/promises';
2
+ import { join, posix, win32 } from 'node:path';
3
+ export const ACTIVE_MS = 120_000;
4
+ export const MAX_ITEMS = 5;
5
+ export const MAX_SCANNED = 30;
6
+ export const TEXT_MAX = 140;
7
+ /** Taille des morceaux lus pour confirmer le `cwd` d'un fichier ; un fichier rejeté n'est jamais lu au-delà. */
8
+ const HEAD_BYTES = 65_536;
9
+ /**
10
+ * Plafond de la tête : la première ligne qui porte `cwd` peut dépasser 64 Kio (capture d'écran ou long collage
11
+ * dans la première demande) ; on lit alors par morceaux jusqu'à sa fin, mais jamais plus loin que ce plafond.
12
+ */
13
+ const HEAD_MAX = 16 * 1024 * 1024;
14
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
15
+ const RECOGNISED = new Set(['user', 'assistant', 'ai-title', 'custom-title', 'last-prompt']);
16
+ /** Lecture par défaut : les octets `[start, end)` du fichier. */
17
+ export const readRange = async (file, start, end) => {
18
+ const fh = await open(file, 'r');
19
+ try {
20
+ const buf = Buffer.alloc(Math.max(0, end - start));
21
+ const { bytesRead } = await fh.read(buf, 0, buf.length, start);
22
+ return buf.subarray(0, bytesRead);
23
+ }
24
+ finally {
25
+ await fh.close();
26
+ }
27
+ };
28
+ export function claudeProjectsRoot(env, home) {
29
+ return env.CLAUDE_CONFIG_DIR ? join(env.CLAUDE_CONFIG_DIR, 'projects') : join(home, '.claude', 'projects');
30
+ }
31
+ /** Encodage de Claude Code : chaque caractère non alphanumérique devient `-` (perte d'information assumée). */
32
+ export function encodeProjectDir(projectPath) {
33
+ return projectPath.replace(/[^A-Za-z0-9]/g, '-');
34
+ }
35
+ /** Chemin comparable : normalisé pour l'OS ciblé ; sous Windows sans casse, `/` ramené à `\`, sans séparateur final. */
36
+ export function comparable(p, platform) {
37
+ if (platform === 'win32')
38
+ return win32.normalize(p.replace(/\//g, '\\')).replace(/\\+$/, '').toLowerCase();
39
+ return posix.normalize(p).replace(/\/+$/, '');
40
+ }
41
+ export function oneLine(s) {
42
+ return [...s.replace(/\s+/g, ' ').trim()].slice(0, TEXT_MAX).join('');
43
+ }
44
+ /** Balises que Claude Code injecte dans les messages `user` ; tout autre `<…>` est du texte de l'utilisateur. */
45
+ const CLAUDE_TAGS = [
46
+ 'command-name', 'command-message', 'command-args', 'local-command-stdout', 'local-command-stderr', 'local-command-caveat',
47
+ 'bash-input', 'bash-stdout', 'bash-stderr', 'system-reminder', 'user-prompt-submit-hook', 'task-notification',
48
+ ].join('|');
49
+ const CLAUDE_BLOCK = new RegExp(`<(${CLAUDE_TAGS})(?:\\s[^>]*)?>[\\s\\S]*?</\\1>`, 'gi');
50
+ const CLAUDE_LONE_TAG = new RegExp(`</?(?:${CLAUDE_TAGS})(?:\\s[^>]*)?>`, 'gi');
51
+ /** Texte d'une demande : le nom d'une commande slash, sinon le texte sans les blocs balisés par Claude Code. */
52
+ export function cleanText(raw) {
53
+ const cmd = /<command-name>([\s\S]*?)<\/command-name>/.exec(raw);
54
+ if (cmd)
55
+ return oneLine(cmd[1]) || null;
56
+ const stripped = raw.replace(CLAUDE_BLOCK, ' ').replace(CLAUDE_LONE_TAG, ' ');
57
+ return oneLine(stripped) || null;
58
+ }
59
+ /** Texte tapé d'une ligne `user` ; null pour meta, sous-agent, tool_result seul ou contenu vide. */
60
+ function typedText(rec) {
61
+ if (rec.isMeta || rec.isSidechain)
62
+ return null;
63
+ const content = rec.message?.content;
64
+ if (typeof content === 'string')
65
+ return cleanText(content);
66
+ if (!Array.isArray(content))
67
+ return null;
68
+ const parts = content.flatMap(p => (p && p.type === 'text' && typeof p.text === 'string' ? [p.text] : []));
69
+ return parts.length ? cleanText(parts.join(' ')) : null;
70
+ }
71
+ const emptySummary = () => ({
72
+ cwd: null, recognised: false, customTitle: null, aiTitle: null, firstPrompt: null, lastTyped: null, lastPromptField: null, branch: null,
73
+ });
74
+ const freshState = () => ({ size: -1, mtimeMs: 0, offset: 0, rest: Buffer.alloc(0), summary: emptySummary() });
75
+ function applyLine(s, line) {
76
+ let rec;
77
+ try {
78
+ const v = JSON.parse(line);
79
+ if (!v || typeof v !== 'object')
80
+ return;
81
+ rec = v;
82
+ }
83
+ catch {
84
+ return;
85
+ }
86
+ const type = rec.type;
87
+ if (typeof type !== 'string')
88
+ return;
89
+ if (RECOGNISED.has(type))
90
+ s.recognised = true;
91
+ if (s.cwd === null && typeof rec.cwd === 'string')
92
+ s.cwd = rec.cwd;
93
+ if (typeof rec.gitBranch === 'string' && rec.gitBranch)
94
+ s.branch = rec.gitBranch;
95
+ if (type === 'custom-title' && typeof rec.customTitle === 'string')
96
+ s.customTitle = oneLine(rec.customTitle) || s.customTitle;
97
+ else if (type === 'ai-title' && typeof rec.aiTitle === 'string')
98
+ s.aiTitle = oneLine(rec.aiTitle) || s.aiTitle;
99
+ else if (type === 'last-prompt' && typeof rec.lastPrompt === 'string')
100
+ s.lastPromptField = cleanText(rec.lastPrompt) ?? s.lastPromptField;
101
+ else if (type === 'user') {
102
+ const t = typedText(rec);
103
+ if (t) {
104
+ s.firstPrompt ??= t;
105
+ s.lastTyped = t;
106
+ }
107
+ }
108
+ }
109
+ /** Ajoute des octets lus au résumé ; la dernière ligne sans saut de ligne reste dans `rest`. */
110
+ function ingest(st, chunk, start) {
111
+ const buf = Buffer.concat([st.rest, chunk]);
112
+ let from = 0;
113
+ for (let nl = buf.indexOf(10, from); nl !== -1; nl = buf.indexOf(10, from)) {
114
+ const line = buf.toString('utf8', from, nl).trim();
115
+ if (line)
116
+ applyLine(st.summary, line);
117
+ from = nl + 1;
118
+ }
119
+ st.rest = Buffer.from(buf.subarray(from));
120
+ st.offset = start + chunk.length;
121
+ }
122
+ /**
123
+ * Lecteur de l'historique Claude Code local. Ne lève jamais : `{ readable: false }` seulement pour une
124
+ * racine illisible ou des fichiers examinés sans aucune ligne reconnue. L'état incrémental (un fichier
125
+ * en ajout seul n'est lu qu'à partir de ce qui a été ajouté) vit dans la fermeture.
126
+ */
127
+ export function createHistoryReader(opts) {
128
+ const read = opts.read ?? readRange;
129
+ const cache = new Map();
130
+ /**
131
+ * Tête : par morceaux de 64 Kio, jusqu'à la première ligne complète qui porte `cwd` (16 Mio au plus).
132
+ * Un morceau sans fin de ligne est mis de côté au lieu d'être recollé à chaque tour.
133
+ */
134
+ async function readHead(file, size, st) {
135
+ let pending = [];
136
+ // Début des octets en attente : on n'ingère que s'il est toujours `st.offset` (sinon, octets déjà vus).
137
+ let from = st.offset;
138
+ let at = from;
139
+ while (st.summary.cwd === null && at < size && at < HEAD_MAX) {
140
+ const chunk = await read(file, at, Math.min(size, at + HEAD_BYTES, HEAD_MAX));
141
+ if (st.offset !== from)
142
+ return;
143
+ if (chunk.length === 0)
144
+ break;
145
+ at += chunk.length;
146
+ pending.push(chunk);
147
+ if (chunk.includes(10)) {
148
+ ingest(st, Buffer.concat(pending), from);
149
+ pending = [];
150
+ from = st.offset;
151
+ }
152
+ }
153
+ if (pending.length)
154
+ ingest(st, Buffer.concat(pending), from);
155
+ // Plafond atteint sans `cwd` : le fichier est abandonné, inutile de garder sa ligne incomplète.
156
+ if (st.summary.cwd === null && st.offset >= HEAD_MAX)
157
+ st.rest = Buffer.alloc(0);
158
+ }
159
+ /** Met à jour l'état d'un fichier : tête pour confirmer le `cwd`, puis seulement les octets ajoutés. */
160
+ async function refresh(file, size, mtimeMs, target) {
161
+ let st = cache.get(file);
162
+ // Rétréci, ou réécrit à taille égale : on repart de zéro.
163
+ if (st && (size < st.size || (size === st.size && mtimeMs !== st.mtimeMs)))
164
+ st = undefined;
165
+ if (!st) {
166
+ st = freshState();
167
+ cache.set(file, st);
168
+ }
169
+ await readHead(file, size, st);
170
+ // Le reste du fichier n'est lu que s'il appartient à ce projet ; le résumé de la tête reste valable pour un autre.
171
+ const cwd = st.summary.cwd;
172
+ if (cwd !== null && comparable(cwd, opts.platform) === target && st.offset < size) {
173
+ const from = st.offset;
174
+ const tail = await read(file, from, size);
175
+ if (st.offset === from)
176
+ ingest(st, tail, from);
177
+ }
178
+ st.size = size;
179
+ st.mtimeMs = mtimeMs;
180
+ return st;
181
+ }
182
+ function toItem(id, st, now) {
183
+ const s = st.summary;
184
+ return {
185
+ id,
186
+ title: s.customTitle ?? s.aiTitle ?? s.firstPrompt,
187
+ updatedAt: new Date(st.mtimeMs).toISOString(),
188
+ branch: s.branch,
189
+ lastPrompt: s.lastPromptField ?? s.lastTyped,
190
+ active: now - st.mtimeMs < ACTIVE_MS,
191
+ };
192
+ }
193
+ // Un appel à la fois : deux lectures simultanées (focus et visibilitychange, relecture au clic pendant
194
+ // la relecture périodique) partageraient l'état incrémental des fichiers et sauteraient des octets.
195
+ let queue = Promise.resolve();
196
+ return projectPath => {
197
+ const next = queue.then(() => readProject(projectPath));
198
+ queue = next.catch(() => { });
199
+ return next;
200
+ };
201
+ async function readProject(projectPath) {
202
+ try {
203
+ const wanted = encodeProjectDir(projectPath).toLowerCase();
204
+ const target = comparable(projectPath, opts.platform);
205
+ let names;
206
+ try {
207
+ names = await readdir(opts.root);
208
+ }
209
+ catch (e) {
210
+ return e.code === 'ENOENT' ? { readable: true, items: [] } : { readable: false };
211
+ }
212
+ // `C--Users-x` et `c--Users-x` peuvent coexister : on réunit les fichiers de tous les dossiers candidats.
213
+ const files = [];
214
+ for (const name of names.filter(n => n.toLowerCase() === wanted)) {
215
+ const folder = join(opts.root, name);
216
+ let entries;
217
+ try {
218
+ entries = await readdir(folder, { withFileTypes: true });
219
+ }
220
+ catch (e) {
221
+ if (e.code === 'ENOENT')
222
+ continue;
223
+ return { readable: false };
224
+ }
225
+ for (const ent of entries) {
226
+ const id = ent.name.slice(0, -'.jsonl'.length);
227
+ if (!ent.isFile() || !ent.name.endsWith('.jsonl') || !UUID.test(id))
228
+ continue;
229
+ const path = join(folder, ent.name);
230
+ try {
231
+ const s = await stat(path);
232
+ files.push({ id, path, size: s.size, mtimeMs: s.mtimeMs });
233
+ }
234
+ catch { /* fichier disparu entre-temps */ }
235
+ }
236
+ }
237
+ files.sort((a, b) => b.mtimeMs - a.mtimeMs);
238
+ const now = opts.now().getTime();
239
+ const items = [];
240
+ let scanned = 0;
241
+ let recognised = false;
242
+ for (const f of files) {
243
+ if (items.length >= MAX_ITEMS || scanned >= MAX_SCANNED)
244
+ break;
245
+ let st;
246
+ try {
247
+ st = await refresh(f.path, f.size, f.mtimeMs, target);
248
+ }
249
+ catch {
250
+ continue;
251
+ }
252
+ scanned++;
253
+ if (st.summary.recognised)
254
+ recognised = true;
255
+ const cwd = st.summary.cwd;
256
+ if (cwd !== null && comparable(cwd, opts.platform) === target && st.summary.firstPrompt !== null) {
257
+ items.push(toItem(f.id, st, now));
258
+ }
259
+ }
260
+ if (scanned > 0 && !recognised)
261
+ return { readable: false };
262
+ return { readable: true, items };
263
+ }
264
+ catch {
265
+ return { readable: false };
266
+ }
267
+ }
268
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Consigne du « + Nouvelle skill » : constante du code, jamais une donnée utilisateur. Sans aucun caractère
3
+ * interprété par cmd.exe (`& | < > ^ % ! "`), ni `;`, `\` ou retour à la ligne ; l'apostrophe droite est permise.
4
+ */
5
+ export const NEW_SKILL_PROMPT = {
6
+ fr: "Regarde ce projet et les skills Claude Code qu'il a déjà, dans .claude/skills du projet et dans mes skills globales. Propose-moi 3 à 5 nouvelles skills qui m'aideraient vraiment ici : pour chacune, son nom, son rôle et quand la lancer. Demande-moi aussi mes propres idées. Pour chaque skill qu'on garde, demande-moi si elle va dans le projet ou dans mes skills globales, puis crée-la et teste-la. Si une skill d'écriture de skills est disponible, utilise-la.",
7
+ en: "Look at this project and the Claude Code skills it already has, in the project's .claude/skills and in my global skills. Suggest 3 to 5 new skills that would really help here: for each one, its name, what it does and when to run it. Ask me for my own ideas too. For each skill we keep, ask me whether it goes in the project or in my global skills, then create it and test it. If a skill-writing skill is available, use it.",
8
+ };
@@ -0,0 +1,21 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ import { realAutostartDeps, runAutostart } from '../autostartRun.js';
3
+ export async function autostartCommand(args, io) {
4
+ const mode = args[0];
5
+ if (mode !== 'on' && mode !== 'off') {
6
+ io.err('Usage: holohq autostart on|off');
7
+ return 1;
8
+ }
9
+ const r = await runAutostart(mode, await realAutostartDeps());
10
+ for (const s of r.steps)
11
+ io.out(s);
12
+ if (!r.ok) {
13
+ io.err(r.detail);
14
+ return 1;
15
+ }
16
+ return 0;
17
+ }
18
+ // Enveloppe `npm run autostart` (exécution directe uniquement).
19
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
20
+ process.exit(await autostartCommand(process.argv.slice(2), { out: console.log, err: console.error }));
21
+ }
@@ -0,0 +1,45 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { configPath, defaultConfig, saveConfig, storedPort, validateConfigInput } from '../config.js';
5
+ const USAGE = 'Usage: holohq config path | import <file.json>';
6
+ export async function configCommand(args, io) {
7
+ const [mode, input] = args;
8
+ const file = configPath(process.env, process.platform, homedir());
9
+ if (mode === 'path') {
10
+ io.out(file);
11
+ return 0;
12
+ }
13
+ if (mode === 'import' && input) {
14
+ let body;
15
+ try {
16
+ body = JSON.parse(readFileSync(input, 'utf8'));
17
+ }
18
+ catch (e) {
19
+ io.err(`${input}: ${e instanceof Error ? e.message : String(e)}`);
20
+ return 1;
21
+ }
22
+ const checked = validateConfigInput(body);
23
+ if (!checked.ok) {
24
+ io.err(`${input}: ${checked.error}`);
25
+ return 1;
26
+ }
27
+ const defaults = defaultConfig(homedir(), existsSync, Intl.DateTimeFormat().resolvedOptions().locale);
28
+ const cfg = {
29
+ ...defaults,
30
+ ...checked.value,
31
+ port: storedPort(file),
32
+ skills: { ...defaults.skills, ...(checked.value.skills ?? {}) },
33
+ };
34
+ // L'ancien fichier, s'il existe, est conservé en .bak.
35
+ await saveConfig(file, cfg, true);
36
+ io.out(`Config imported to ${file}`);
37
+ return 0;
38
+ }
39
+ io.err(USAGE);
40
+ return 1;
41
+ }
42
+ // Enveloppe `npm run config` (exécution directe uniquement).
43
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
44
+ process.exit(await configCommand(process.argv.slice(2), { out: console.log, err: console.error }));
45
+ }
@@ -0,0 +1,51 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { configPath, loadConfig } from '../config.js';
5
+ import { run } from '../exec.js';
6
+ import { repoLabelSet } from '../github/labels.js';
7
+ import { ensureConvention } from '../github/write.js';
8
+ const USAGE = 'Usage: holohq convention <owner>/<repo> [--lang en|fr]';
9
+ export async function conventionCommand(args, io) {
10
+ let lang = null;
11
+ const rest = [];
12
+ for (let i = 0; i < args.length; i++) {
13
+ if (args[i] === '--lang') {
14
+ const v = args[++i];
15
+ if (v !== 'en' && v !== 'fr') {
16
+ io.err(USAGE);
17
+ return 1;
18
+ }
19
+ lang = v;
20
+ }
21
+ else
22
+ rest.push(args[i]);
23
+ }
24
+ const arg = rest[0] ?? '';
25
+ const m = rest.length === 1 ? arg.match(/^([A-Za-z0-9][A-Za-z0-9-]*)\/([A-Za-z0-9._-]+)$/) : null;
26
+ if (!m) {
27
+ io.err(USAGE);
28
+ return 1;
29
+ }
30
+ try {
31
+ const repo = { owner: m[1], name: m[2] };
32
+ const fallback = lang ?? loadConfig(configPath(process.env, process.platform, homedir()), {
33
+ home: homedir(),
34
+ exists: existsSync,
35
+ locale: Intl.DateTimeFormat().resolvedOptions().locale,
36
+ }).config.labelSet;
37
+ // Le jeu déjà présent dans le dépôt prime (jamais de second jeu) ; --lang ou la config ne servent que de repli.
38
+ const set = await repoLabelSet(run, repo, fallback);
39
+ const r = await ensureConvention(run, repo, set);
40
+ io.out(`Convention in place on ${arg} (labels ${set.lang})${r.journalCreated ? ' (journal created and pinned)' : ' (journal already present)'}.`);
41
+ return 0;
42
+ }
43
+ catch (e) {
44
+ io.err(e instanceof Error ? e.message : String(e));
45
+ return 1;
46
+ }
47
+ }
48
+ // Enveloppe `npm run convention` (exécution directe uniquement).
49
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
50
+ process.exit(await conventionCommand(process.argv.slice(2), { out: console.log, err: console.error }));
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,129 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { pkgPath } from '../paths.js';
3
+ import { startServer } from '../start.js';
4
+ import { autostartCommand } from './autostart.js';
5
+ import { configCommand } from './config.js';
6
+ import { conventionCommand } from './convention.js';
7
+ export const HELP = `HoloHQ - a holographic HUD cockpit for your GitHub projects.
8
+
9
+ Usage:
10
+ holohq [start] [--demo] [--no-open] [--port <n>] [--lang en|fr]
11
+ holohq autostart on|off
12
+ holohq convention <owner>/<repo> [--lang en|fr]
13
+ holohq config path | import <file.json>
14
+ holohq --version | -v
15
+ holohq --help | -h
16
+
17
+ Commands:
18
+ start Start HoloHQ and open it in your browser (default)
19
+ autostart Start HoloHQ automatically at login (on) or stop doing so (off)
20
+ convention Set up the label convention and journal issue on a repository
21
+ config Print the config file path, or import a config file
22
+
23
+ Options:
24
+ --demo Run on built-in sample data (default port 4243, nothing is read or written)
25
+ --no-open Do not open the browser
26
+ --port <n> Listen on this port (default: the configured port)
27
+ --lang en|fr Language of the demo data
28
+ --version Print the version
29
+ --help Print this help
30
+ `;
31
+ export function parseArgs(argv) {
32
+ const [first, ...tail] = argv;
33
+ switch (first) {
34
+ case '--version':
35
+ case '-v':
36
+ return { kind: 'version' };
37
+ case '--help':
38
+ case '-h':
39
+ return { kind: 'help' };
40
+ case 'autostart':
41
+ return tail.length === 1 && (tail[0] === 'on' || tail[0] === 'off')
42
+ ? { kind: 'autostart', mode: tail[0] }
43
+ : { kind: 'error', message: 'Usage: holohq autostart on|off' };
44
+ case 'convention':
45
+ return { kind: 'convention', args: tail };
46
+ case 'config':
47
+ return { kind: 'config', args: tail };
48
+ }
49
+ const rest = first === 'start' ? tail : argv;
50
+ const cmd = { kind: 'start', demo: false, open: true, port: null, lang: null };
51
+ for (let i = 0; i < rest.length; i++) {
52
+ const a = rest[i];
53
+ if (a === '--demo')
54
+ cmd.demo = true;
55
+ else if (a === '--no-open')
56
+ cmd.open = false;
57
+ else if (a === '--port') {
58
+ const v = rest[++i];
59
+ const n = Number(v);
60
+ if (v === undefined || !/^\d+$/.test(v) || n < 1 || n > 65535) {
61
+ return { kind: 'error', message: `Invalid port: ${v ?? '(missing)'}. Expected a number from 1 to 65535.` };
62
+ }
63
+ cmd.port = n;
64
+ }
65
+ else if (a === '--lang') {
66
+ const v = rest[++i];
67
+ if (v !== 'en' && v !== 'fr')
68
+ return { kind: 'error', message: `Invalid language: ${v ?? '(missing)'}. Expected en or fr.` };
69
+ cmd.lang = v;
70
+ }
71
+ else if (a === '--version' || a === '-v')
72
+ return { kind: 'version' };
73
+ else if (a === '--help' || a === '-h')
74
+ return { kind: 'help' };
75
+ else
76
+ return { kind: 'error', message: `Unknown command or option: ${a}` };
77
+ }
78
+ if (cmd.lang !== null && !cmd.demo)
79
+ return { kind: 'error', message: '--lang only applies to --demo' };
80
+ return cmd;
81
+ }
82
+ export async function main(argv, io) {
83
+ const cmd = parseArgs(argv);
84
+ try {
85
+ switch (cmd.kind) {
86
+ case 'version':
87
+ io.out(io.version());
88
+ return 0;
89
+ case 'help':
90
+ io.out(HELP);
91
+ return 0;
92
+ case 'autostart':
93
+ return await io.autostart([cmd.mode]);
94
+ case 'convention':
95
+ return await io.convention(cmd.args);
96
+ case 'config':
97
+ return await io.config(cmd.args);
98
+ case 'error':
99
+ io.err(cmd.message);
100
+ io.err('Run "holohq --help" for usage.'); // erreurs d'usage seulement
101
+ return 1;
102
+ case 'start':
103
+ await io.start({ demo: cmd.demo, open: cmd.open, port: cmd.port, lang: cmd.lang, dev: false });
104
+ return await new Promise(() => { }); // le serveur tourne jusqu'à Ctrl+C
105
+ }
106
+ }
107
+ catch (e) {
108
+ io.err(e instanceof Error ? e.message : String(e));
109
+ return 1;
110
+ }
111
+ }
112
+ export function realIo() {
113
+ const base = { out: (s) => console.log(s), err: (s) => console.error(s) };
114
+ return {
115
+ ...base,
116
+ start: async (opts) => {
117
+ const r = await startServer(opts);
118
+ if (r.reused) {
119
+ base.out(`HoloHQ is already running at ${r.url}`);
120
+ process.exit(0);
121
+ }
122
+ base.out(`HoloHQ is running at ${r.url} (Ctrl+C to stop)`);
123
+ },
124
+ version: () => JSON.parse(readFileSync(pkgPath('package.json'), 'utf8')).version,
125
+ autostart: (a) => autostartCommand(a, base),
126
+ convention: (a) => conventionCommand(a, base),
127
+ config: (a) => configCommand(a, base),
128
+ };
129
+ }