holohq 0.1.0 → 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.
- package/README.fr.md +10 -2
- package/README.md +10 -2
- package/dist/server/server/app.js +4 -0
- package/dist/server/server/claude/floor.js +408 -0
- package/dist/server/server/claude/history.js +268 -0
- package/dist/server/server/claude/prompt.js +8 -0
- package/dist/server/server/config.js +10 -4
- package/dist/server/server/demo/data.js +12 -1
- package/dist/server/server/demo/deps.js +14 -0
- package/dist/server/server/demo/floor.js +45 -0
- package/dist/server/server/demo/run.js +40 -3
- package/dist/server/server/domain/home.js +1 -1
- package/dist/server/server/domain/journal.js +3 -3
- package/dist/server/server/floor/attribute.js +74 -0
- package/dist/server/server/floor/evidence.js +39 -0
- package/dist/server/server/github/project.js +7 -5
- package/dist/server/server/launch.js +42 -20
- package/dist/server/server/routes/actions.js +1 -1
- package/dist/server/server/routes/conversations.js +21 -0
- package/dist/server/server/routes/floor.js +77 -0
- package/dist/server/server/routes/launch.js +42 -7
- package/dist/server/server/routes/projects.js +14 -2
- package/dist/server/server/start.js +7 -1
- package/dist/server/shared/errors.js +5 -1
- package/dist/server/shared/themes.js +2 -0
- package/dist/web/assets/Globe-ighOFp2V.js +4273 -0
- package/dist/web/assets/index-ByHbMQJl.js +11 -0
- package/dist/web/assets/index-DgR2KpYV.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/Globe-BQOGOJCc.js +0 -4273
- package/dist/web/assets/index-BBiWQTd5.js +0 -11
- package/dist/web/assets/index-CoHzgpbC.css +0 -1
|
@@ -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
|
+
};
|
|
@@ -3,7 +3,7 @@ import { copyFile, mkdir, writeFile } from 'node:fs/promises';
|
|
|
3
3
|
import { dirname, posix, win32 } from 'node:path';
|
|
4
4
|
import { errorBody } from '../shared/errors.js';
|
|
5
5
|
import { parseHex } from '../shared/color.js';
|
|
6
|
-
import { DEFAULT_APPEARANCE, THEME_IDS } from '../shared/themes.js';
|
|
6
|
+
import { DEFAULT_APPEARANCE, THEME_IDS, FLOOR_VIEWS } from '../shared/themes.js';
|
|
7
7
|
import { SKILL_NAME } from './skills.js';
|
|
8
8
|
/** Chemin du fichier de config de l'utilisateur, selon l'OS. */
|
|
9
9
|
export function configPath(env, platform, home) {
|
|
@@ -41,6 +41,7 @@ export function defaultConfig(home, exists, locale) {
|
|
|
41
41
|
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
42
42
|
const isThemeId = (v) => typeof v === 'string' && THEME_IDS.includes(v);
|
|
43
43
|
const isEffects = (v) => v === 'full' || v === 'subtle';
|
|
44
|
+
const isFloor = (v) => FLOOR_VIEWS.includes(v);
|
|
44
45
|
/** Couleur `#rrggbb` normalisée en minuscules ; null sinon. */
|
|
45
46
|
const hexColor = (v) => (typeof v === 'string' && parseHex(v) ? v.toLowerCase() : null);
|
|
46
47
|
function customColors(v) {
|
|
@@ -51,16 +52,19 @@ function customColors(v) {
|
|
|
51
52
|
return accent && accent2 && (v.mode === 'dark' || v.mode === 'light') ? { accent, accent2, mode: v.mode } : null;
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
|
-
* Apparence saisie : thème connu, couleurs `#rrggbb`, effets full/subtle ; null si un champ est invalide.
|
|
55
|
+
* Apparence saisie : thème connu, couleurs `#rrggbb`, effets full/subtle, rendu de l'étage connu s'il est donné ; null si un champ est invalide.
|
|
55
56
|
* Perso exige ses deux couleurs (sinon l'interface afficherait Holo en croyant Perso choisi).
|
|
56
57
|
*/
|
|
57
58
|
function appearanceInput(v) {
|
|
58
59
|
if (!isObj(v) || !isThemeId(v.theme) || !isEffects(v.effects))
|
|
59
60
|
return null;
|
|
61
|
+
if (v.floor !== undefined && !isFloor(v.floor))
|
|
62
|
+
return null;
|
|
63
|
+
const floor = v.floor === undefined ? {} : { floor: v.floor };
|
|
60
64
|
if (v.custom === undefined)
|
|
61
|
-
return v.theme === 'custom' ? null : { theme: v.theme, effects: v.effects };
|
|
65
|
+
return v.theme === 'custom' ? null : { theme: v.theme, effects: v.effects, ...floor };
|
|
62
66
|
const custom = customColors(v.custom);
|
|
63
|
-
return custom ? { theme: v.theme, custom, effects: v.effects } : null;
|
|
67
|
+
return custom ? { theme: v.theme, custom, effects: v.effects, ...floor } : null;
|
|
64
68
|
}
|
|
65
69
|
/** Apparence lue dans le fichier : chaque champ invalide revient au défaut (Perso invalide écarté, Perso sans couleurs → Holo). */
|
|
66
70
|
function appearanceFromFile(v) {
|
|
@@ -70,6 +74,8 @@ function appearanceFromFile(v) {
|
|
|
70
74
|
const out = { theme, effects: isEffects(a.effects) ? a.effects : DEFAULT_APPEARANCE.effects };
|
|
71
75
|
if (custom)
|
|
72
76
|
out.custom = custom;
|
|
77
|
+
if (isFloor(a.floor))
|
|
78
|
+
out.floor = a.floor;
|
|
73
79
|
return out;
|
|
74
80
|
}
|
|
75
81
|
const OWNER_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/;
|
|
@@ -13,6 +13,10 @@ export const DEMO_PROJECTS = [
|
|
|
13
13
|
modified: 2,
|
|
14
14
|
untracked: 1,
|
|
15
15
|
ahead: 1,
|
|
16
|
+
conversations: [
|
|
17
|
+
{ id: '3f1c9a52-7d4e-4b8a-9c21-5e6d0a1b7f30', title: 'Sync queue design', daysAgo: 2.5, branch: 'feat/offline-sync', lastPrompt: 'How should the queue replay failed writes?' },
|
|
18
|
+
{ id: 'b7e4d608-12a9-4c35-8f7b-0d93a6c2e514', title: 'Fix note ordering', daysAgo: 6, branch: 'main', lastPrompt: 'Notes jump around after a sync, why?' },
|
|
19
|
+
],
|
|
16
20
|
commits: [
|
|
17
21
|
[0.08, 'feat: persist the offline queue in IndexedDB'],
|
|
18
22
|
[0.9, 'feat: conflict banner on reconnect'],
|
|
@@ -59,7 +63,13 @@ export const DEMO_PROJECTS = [
|
|
|
59
63
|
branch: 'main',
|
|
60
64
|
modified: 0,
|
|
61
65
|
untracked: 0,
|
|
62
|
-
|
|
66
|
+
// Projet de la capture `docs/assets/project.png` : conversations, un commit non poussé et des PR ouvertes.
|
|
67
|
+
ahead: 1,
|
|
68
|
+
conversations: [
|
|
69
|
+
{ id: '8a2d5c17-4e9b-4f06-b3a1-6c7e9d0f2b48', title: 'GIF export pipeline', daysAgo: 0.4, branch: 'main', lastPrompt: 'Can the GIF encoder reuse the sprite sheet palette?' },
|
|
70
|
+
{ id: 'c94e1f03-5b2a-4d78-8e6c-1a0b3d7f9e25', title: 'Crash on empty frames', daysAgo: 1.6, branch: 'main', lastPrompt: 'Export fails when a frame has no pixels, find why' },
|
|
71
|
+
{ id: '5d7b0e29-a1c4-4f83-9d52-e8f61b3c0a97', title: 'Onion skin opacity', daysAgo: 3.1, branch: 'main', lastPrompt: 'Make the previous frame fade to 30 percent' },
|
|
72
|
+
],
|
|
63
73
|
commits: [
|
|
64
74
|
[1.5, 'feat: export sprites as a sheet'],
|
|
65
75
|
[2.2, 'feat: onion skin for the previous frame'],
|
|
@@ -67,6 +77,7 @@ export const DEMO_PROJECTS = [
|
|
|
67
77
|
[5.3, 'chore: bump the canvas library'],
|
|
68
78
|
[8.0, 'feat: frame timeline'],
|
|
69
79
|
],
|
|
80
|
+
openPrs: 2,
|
|
70
81
|
bugs: 2,
|
|
71
82
|
sprint: {
|
|
72
83
|
title: 'v0.9: Export',
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { demoConfig, DEMO_PORT } from './config.js';
|
|
2
|
+
import { DEMO_PROJECTS, daysAgoIso, demoPath } from './data.js';
|
|
3
|
+
import { demoFloor } from './floor.js';
|
|
2
4
|
import { demoRun } from './run.js';
|
|
3
5
|
import { demoScan, demoSkills } from './scan.js';
|
|
4
6
|
/** Repère affiché à la place du chemin du fichier de config : la démo n'en a pas. */
|
|
@@ -16,6 +18,18 @@ export function demoDeps(opts) {
|
|
|
16
18
|
now,
|
|
17
19
|
scan: demoScan,
|
|
18
20
|
listSkills: demoSkills,
|
|
21
|
+
conversations: async (path) => ({
|
|
22
|
+
readable: true,
|
|
23
|
+
items: (DEMO_PROJECTS.find((p) => demoPath(p.name) === path)?.conversations ?? []).map((c) => ({
|
|
24
|
+
id: c.id,
|
|
25
|
+
title: c.title,
|
|
26
|
+
updatedAt: daysAgoIso(now(), c.daysAgo),
|
|
27
|
+
branch: c.branch,
|
|
28
|
+
lastPrompt: c.lastPrompt,
|
|
29
|
+
active: false,
|
|
30
|
+
})),
|
|
31
|
+
}),
|
|
32
|
+
floor: async () => ({ readable: true, agents: demoFloor(now()) }),
|
|
19
33
|
// Jamais atteint : toute écriture (lancement, éditeur, nouveau projet) est refusée avant (middleware demoMode).
|
|
20
34
|
spawnDetached: () => { },
|
|
21
35
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { demoPath } from './data.js';
|
|
2
|
+
const CYCLE_MS = 8000;
|
|
3
|
+
const MIN = 60_000;
|
|
4
|
+
const SESSIONS = [
|
|
5
|
+
{ id: 'demo-s1', project: 'orbit-notes', title: 'Offline sync for notes', state: 'working', ago: 4, model: 'opus',
|
|
6
|
+
actions: [{ verb: 'edit', target: 'sync.ts' }, { verb: 'read', target: 'store.ts' }, { verb: 'run', target: 'npm test' }, { verb: 'search', target: 'queue' }] },
|
|
7
|
+
{ id: 'demo-s2', project: 'orbit-notes', title: 'Review the migration plan', state: 'waiting', ago: 9, model: 'sonnet', actions: [] },
|
|
8
|
+
{ id: 'demo-s3', project: 'pixel-forge', title: 'GIF export pipeline', state: 'working', ago: 2, model: 'opus',
|
|
9
|
+
actions: [{ verb: 'read', target: 'palette.ts' }, { verb: 'edit', target: 'encoder.ts' }, { verb: 'web', target: 'gif spec' }, { verb: 'run', target: 'npm run build' }] },
|
|
10
|
+
{ id: 'demo-s4', project: 'pixel-forge', title: 'Fix crash on empty frames', state: 'resting', ago: 40, model: 'sonnet', actions: [] },
|
|
11
|
+
{ id: 'demo-s5', project: 'tide-planner', title: 'Tide table parser', state: 'working', ago: 6, model: 'sonnet',
|
|
12
|
+
actions: [{ verb: 'search', target: 'parseTide' }, { verb: 'edit', target: 'parser.ts' }, { verb: 'read', target: 'tides.json' }, { verb: 'run', target: 'npx vitest' }] },
|
|
13
|
+
{ id: 'demo-s6', project: 'tide-planner', title: 'Plan the sprint board', state: 'waiting', ago: 12, model: 'opus', actions: [] },
|
|
14
|
+
{ id: 'demo-s7', project: null, title: 'Scratch experiments', state: 'resting', ago: 55, model: 'haiku', actions: [] },
|
|
15
|
+
];
|
|
16
|
+
const SUBAGENTS = [
|
|
17
|
+
{ id: 'demo-a1', parent: 'demo-s1', phases: [0, 1, 2], role: 'general-purpose', task: 'Map every call site of the sync queue', model: 'sonnet',
|
|
18
|
+
actions: [{ verb: 'search', target: 'enqueue' }, { verb: 'read', target: 'queue.ts' }, { verb: 'read', target: 'worker.ts' }, { verb: 'search', target: 'flush' }] },
|
|
19
|
+
{ id: 'demo-a2', parent: 'demo-s3', phases: [1, 2, 3], role: 'code-reviewer', task: 'Review the encoder changes', model: 'opus',
|
|
20
|
+
actions: [{ verb: 'read', target: 'encoder.ts' }, { verb: 'run', target: 'git diff' }, { verb: 'read', target: 'palette.ts' }, { verb: 'edit', target: 'notes.md' }] },
|
|
21
|
+
];
|
|
22
|
+
/** Agents fictifs de l'étage, déterministes d'après `now` : deux sous-agents vont et viennent, les actions tournent. */
|
|
23
|
+
export function demoFloor(now) {
|
|
24
|
+
const t = now.getTime();
|
|
25
|
+
const step = Math.floor(t / CYCLE_MS);
|
|
26
|
+
const phase = step % 4;
|
|
27
|
+
const iso = (agoMs) => new Date(t - agoMs).toISOString();
|
|
28
|
+
const out = [];
|
|
29
|
+
SESSIONS.forEach((s, i) => {
|
|
30
|
+
out.push({
|
|
31
|
+
id: s.id, kind: 'session', parentId: null, state: s.state, title: s.title, role: null, model: s.model, task: null,
|
|
32
|
+
action: s.state === 'working' ? s.actions[(step + i) % s.actions.length] : null,
|
|
33
|
+
since: iso(s.ago * MIN), updatedAt: iso(s.state === 'working' ? (i + 1) * 3000 : s.ago * MIN),
|
|
34
|
+
cwd: s.project ? demoPath(s.project) : '/demo/scratch', paths: [],
|
|
35
|
+
});
|
|
36
|
+
for (const a of SUBAGENTS.filter((x) => x.parent === s.id && x.phases.includes(phase))) {
|
|
37
|
+
out.push({
|
|
38
|
+
id: a.id, kind: 'subagent', parentId: s.id, state: 'working', title: null, role: a.role, model: a.model, task: a.task,
|
|
39
|
+
action: a.actions[step % a.actions.length], since: iso(MIN), updatedAt: iso(2000),
|
|
40
|
+
cwd: s.project ? demoPath(s.project) : '/demo/scratch', paths: [],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
@@ -8,6 +8,8 @@ import { DEMO_OWNER, DEMO_PROJECTS, DEMO_REMOTE_ONLY, daysAgoIso, demoPath } fro
|
|
|
8
8
|
const EN = LABEL_SETS.en;
|
|
9
9
|
/** Format des `git log` du serveur (git/status.ts, routes/projects.ts). */
|
|
10
10
|
const LOG_FORMAT = '--format=%h%x1f%cI%x1f%s';
|
|
11
|
+
/** Hash complet (40 caractères) d'un faux commit : le court en préfixe, comme dans un vrai dépôt. */
|
|
12
|
+
const fullHash = (p, i) => fakeHash(`${p.name}:${i}`).padEnd(40, '0');
|
|
11
13
|
const FILES = ['src/index.ts', 'src/app.ts', 'README.md', 'src/styles.css', 'package.json'];
|
|
12
14
|
const ok = (stdout = '') => ({ stdout, stderr: '', code: 0 });
|
|
13
15
|
const fail = (stderr, code = 1) => ({ stdout: '', stderr, code });
|
|
@@ -85,6 +87,26 @@ function journalBody(p, now) {
|
|
|
85
87
|
const j = p.journal;
|
|
86
88
|
return `## Session ${daysAgoIso(now, j.daysAgo).slice(0, 10)}\n**Done:** ${j.done}\n**Left:** ${j.left}\n**Next:** ${j.next}`;
|
|
87
89
|
}
|
|
90
|
+
const PR_TITLES = ['Add dark theme toggle', 'Fix crash on empty save file', 'Refactor input handling', 'Update dependencies', 'Improve onboarding copy'];
|
|
91
|
+
/** PR ouvertes fictives, de la plus récente à la plus ancienne (un brouillon, un auteur absent). */
|
|
92
|
+
const demoPrs = (p, now) => Array.from({ length: Math.min(p.openPrs ?? 0, 5) }, (_, i) => ({
|
|
93
|
+
number: 40 - i,
|
|
94
|
+
title: PR_TITLES[i % PR_TITLES.length],
|
|
95
|
+
url: `https://github.com/${DEMO_OWNER}/${p.name}/pull/${40 - i}`,
|
|
96
|
+
isDraft: i === 1,
|
|
97
|
+
author: i === 2 ? null : { login: i % 2 === 0 ? 'demo-dev' : 'demo-helper' },
|
|
98
|
+
createdAt: daysAgoIso(now, i + 1),
|
|
99
|
+
}));
|
|
100
|
+
/** Commentaires du journal, du plus ancien au plus récent (ordre de GitHub) : deux sessions antérieures fictives, puis la dernière. */
|
|
101
|
+
function journalComments(p, n, now) {
|
|
102
|
+
const j = p.journal;
|
|
103
|
+
const older = [j.daysAgo + 14, j.daysAgo + 7].map((d, i) => ({
|
|
104
|
+
body: `## Session ${daysAgoIso(now, d).slice(0, 10)}\n**Done:** early groundwork\n**Left:** most of the polish\n**Next:** pick the next small step`,
|
|
105
|
+
url: `${issueUrl(p, n)}#issuecomment-${n}000${i + 2}`,
|
|
106
|
+
createdAt: daysAgoIso(now, d),
|
|
107
|
+
}));
|
|
108
|
+
return [...older, { body: journalBody(p, now), url: `${issueUrl(p, n)}#issuecomment-${n}0001`, createdAt: daysAgoIso(now, j.daysAgo) }];
|
|
109
|
+
}
|
|
88
110
|
// ---- git ----
|
|
89
111
|
function statusText(p) {
|
|
90
112
|
const upstream = p.ahead === null ? '' : `...origin/${p.branch}${p.ahead > 0 ? ` [ahead ${p.ahead}]` : ''}`;
|
|
@@ -101,6 +123,11 @@ function logText(p, n, now) {
|
|
|
101
123
|
.map(([daysAgo, subject], i) => `${fakeHash(`${p.name}:${i}`)}\x1f${daysAgoIso(now, daysAgo)}\x1f${subject}\n`)
|
|
102
124
|
.join('');
|
|
103
125
|
}
|
|
126
|
+
/** `git rev-list --max-count=8 HEAD --not --remotes` : les commits d'avance ; sans amont (ahead null), tous ceux d'un projet publié. */
|
|
127
|
+
function unpushedText(p) {
|
|
128
|
+
const n = p.ahead ?? p.commits.length;
|
|
129
|
+
return p.commits.slice(0, Math.min(n, 8)).map((_, i) => `${fullHash(p, i)}\n`).join('');
|
|
130
|
+
}
|
|
104
131
|
function git(args, now) {
|
|
105
132
|
if (same(args, ['--version']))
|
|
106
133
|
return ok('git version 2.47.0\n');
|
|
@@ -108,9 +135,19 @@ function git(args, now) {
|
|
|
108
135
|
const p = byPath(args[1]);
|
|
109
136
|
if (!p)
|
|
110
137
|
return null;
|
|
111
|
-
const rest = args.slice(2);
|
|
138
|
+
const rest = args.slice(2).filter((a) => a !== '--no-optional-locks');
|
|
112
139
|
if (same(rest, ['remote', 'get-url', 'origin']))
|
|
113
140
|
return p.github ? ok(`https://github.com/${DEMO_OWNER}/${p.name}.git\n`) : fail("error: No such remote 'origin'", 2);
|
|
141
|
+
// L'étage (routes/floor.ts) : worktrees et date du dernier commit.
|
|
142
|
+
if (same(rest, ['worktree', 'list', '--porcelain']))
|
|
143
|
+
return ok(`worktree ${demoPath(p.name)}\n`);
|
|
144
|
+
if (same(rest, ['log', '-1', '--format=%cI']))
|
|
145
|
+
return ok(p.commits.length ? `${daysAgoIso(now, p.commits[0][0])}\n` : '');
|
|
146
|
+
// Remotes du dépôt (routes/projects.ts) : `origin` seulement pour un projet publié.
|
|
147
|
+
if (same(rest, ['remote']))
|
|
148
|
+
return ok(p.github ? 'origin\n' : '');
|
|
149
|
+
if (same(rest, ['rev-list', '--max-count=8', 'HEAD', '--not', '--remotes']))
|
|
150
|
+
return ok(unpushedText(p));
|
|
114
151
|
if (same(rest, ['status', '--porcelain=v1', '--branch']))
|
|
115
152
|
return ok(statusText(p));
|
|
116
153
|
if (rest.length === 3 && rest[0] === 'log' && /^-\d+$/.test(rest[1]) && rest[2] === LOG_FORMAT)
|
|
@@ -166,10 +203,10 @@ function graphql(rest, now) {
|
|
|
166
203
|
milestones: { nodes: m ? [{ ...m, open: { totalCount: m.open }, closed: { totalCount: m.closed } }] : [] },
|
|
167
204
|
ideas: { nodes: issues.filter((i) => i.kind === 'idea').map((i) => rawIssue(p, i)) },
|
|
168
205
|
bugs: { totalCount: p.bugs ?? 0 },
|
|
169
|
-
pullRequests: { totalCount: p.openPrs ?? 0 },
|
|
206
|
+
pullRequests: { totalCount: p.openPrs ?? 0, nodes: demoPrs(p, now) },
|
|
170
207
|
journal: {
|
|
171
208
|
nodes: journal
|
|
172
|
-
? [{ number: journal.number, url: issueUrl(p, journal.number), comments: { nodes:
|
|
209
|
+
? [{ number: journal.number, url: issueUrl(p, journal.number), comments: { nodes: journalComments(p, journal.number, now) } }]
|
|
173
210
|
: [],
|
|
174
211
|
},
|
|
175
212
|
label: p.journal ? { name: 'journal' } : null,
|
|
@@ -49,7 +49,7 @@ export function pickResume(home, details) {
|
|
|
49
49
|
const detail = details.get(p.id);
|
|
50
50
|
if (!detail)
|
|
51
51
|
continue;
|
|
52
|
-
const last = detail.journal?.
|
|
52
|
+
const last = detail.journal?.sessions[0] ?? null;
|
|
53
53
|
return { projectId: p.id, name: p.name, fait: last?.fait ?? null, prochaine: last?.prochaine ?? null, lastSubject: p.lastSubject, hasJournal: last != null };
|
|
54
54
|
}
|
|
55
55
|
return null;
|
|
@@ -3,15 +3,15 @@ function field(body, label) {
|
|
|
3
3
|
return body.match(re)?.[1].trim() ?? '';
|
|
4
4
|
}
|
|
5
5
|
/** Lit un commentaire de session ; hors format → texte brut dans `fait`. */
|
|
6
|
-
export function parseJournalComment(body, url) {
|
|
6
|
+
export function parseJournalComment(body, url, createdAt) {
|
|
7
7
|
const text = body.replace(/\r\n/g, '\n');
|
|
8
8
|
const date = text.match(/^##\s*Session(?: du)? (\d{4}-\d{2}-\d{2})/m)?.[1] ?? '';
|
|
9
9
|
const fait = field(text, 'Fait|Done');
|
|
10
10
|
const reste = field(text, 'Reste|Left');
|
|
11
11
|
const prochaine = field(text, 'Prochaine étape|Next');
|
|
12
12
|
if (!date && !fait && !reste && !prochaine)
|
|
13
|
-
return { date: '', fait: text.trim(), reste: '', prochaine: '', url };
|
|
14
|
-
return { date, fait, reste, prochaine, url };
|
|
13
|
+
return { date: '', fait: text.trim(), reste: '', prochaine: '', url, createdAt };
|
|
14
|
+
return { date, fait, reste, prochaine, url, createdAt };
|
|
15
15
|
}
|
|
16
16
|
const TEMPLATES = {
|
|
17
17
|
fr: `Journal des sessions de travail. Chaque session ajoute un commentaire de ce format :
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { comparable } from '../claude/history.js';
|
|
2
|
+
/** Racine la plus longue qui est `p` ou un de ses parents (séparateur ajouté : `proj` n'englobe pas `proj-2`). */
|
|
3
|
+
function owner(p, roots, platform) {
|
|
4
|
+
// Git Bash écrit `/c/dossier` pour `C:\dossier`.
|
|
5
|
+
const key = comparable(platform === 'win32' ? p.replace(/^\/([A-Za-z])(?=\/|$)/, '$1:') : p, platform);
|
|
6
|
+
let best = null;
|
|
7
|
+
for (const r of roots) {
|
|
8
|
+
const hit = key === r.key || key.startsWith(r.key.endsWith('/') || r.key.endsWith('\\') ? r.key : r.key + (platform === 'win32' ? '\\' : '/'));
|
|
9
|
+
if (hit && (!best || r.key.length > best.key.length))
|
|
10
|
+
best = r;
|
|
11
|
+
}
|
|
12
|
+
return best?.projectId ?? null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Projet d'un agent d'après ses propres preuves : son dossier de travail, sinon le vote de ses outils récents (`paths`, du
|
|
16
|
+
* plus récent au plus ancien : l'égalité va au plus récent). Un outil vote une fois par projet qu'il cite ; un chemin hors
|
|
17
|
+
* de tout projet ne compte pas. Aucune preuve : null.
|
|
18
|
+
*/
|
|
19
|
+
export function attribute(agent, roots, platform) {
|
|
20
|
+
const prepared = roots.map((r) => ({ projectId: r.projectId, key: comparable(r.path, platform) }));
|
|
21
|
+
if (agent.cwd) {
|
|
22
|
+
const hit = owner(agent.cwd, prepared, platform);
|
|
23
|
+
if (hit)
|
|
24
|
+
return hit;
|
|
25
|
+
}
|
|
26
|
+
return majority(agent.paths.flatMap((cited) => [...new Set(cited.map((p) => owner(p, prepared, platform)))]));
|
|
27
|
+
}
|
|
28
|
+
/** Valeur la plus fréquente (les null ne comptent pas) ; à égalité, la première rencontrée. */
|
|
29
|
+
function majority(votes) {
|
|
30
|
+
const count = new Map();
|
|
31
|
+
for (const v of votes)
|
|
32
|
+
if (v)
|
|
33
|
+
count.set(v, (count.get(v) ?? 0) + 1);
|
|
34
|
+
let best = null;
|
|
35
|
+
for (const [id, n] of count)
|
|
36
|
+
if (best === null || n > count.get(best))
|
|
37
|
+
best = id;
|
|
38
|
+
return best;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Projet de chaque agent, dans cet ordre : ses propres preuves ; le dernier projet qu'elles ont donné ; pour une session, le
|
|
42
|
+
* projet majoritaire de ses sous-agents (d'après leurs preuves à eux) ; pour un sous-agent, le projet de sa session.
|
|
43
|
+
* `memory` est mise à jour et ne garde que les agents présents : un agent ne change de projet que sur une nouvelle preuve.
|
|
44
|
+
*/
|
|
45
|
+
export function attributeAll(agents, roots, platform, memory) {
|
|
46
|
+
const present = new Set(agents.map((a) => a.id));
|
|
47
|
+
for (const id of memory.keys())
|
|
48
|
+
if (!present.has(id))
|
|
49
|
+
memory.delete(id);
|
|
50
|
+
for (const a of agents) {
|
|
51
|
+
const projectId = attribute(a, roots, platform);
|
|
52
|
+
if (projectId)
|
|
53
|
+
memory.set(a.id, { projectId, own: true });
|
|
54
|
+
}
|
|
55
|
+
const proven = (id) => (memory.get(id)?.own ? memory.get(id).projectId : null);
|
|
56
|
+
for (const a of agents) {
|
|
57
|
+
if (a.parentId !== null || proven(a.id))
|
|
58
|
+
continue;
|
|
59
|
+
const children = agents.filter((c) => c.parentId === a.id).sort((x, y) => Date.parse(y.updatedAt) - Date.parse(x.updatedAt));
|
|
60
|
+
const projectId = majority(children.map((c) => proven(c.id)));
|
|
61
|
+
if (projectId)
|
|
62
|
+
memory.set(a.id, { projectId, own: false });
|
|
63
|
+
}
|
|
64
|
+
const known = (id) => (id === null ? null : (memory.get(id)?.projectId ?? null));
|
|
65
|
+
return new Map(agents.map((a) => [a.id, known(a.id) ?? known(a.parentId)]));
|
|
66
|
+
}
|
|
67
|
+
/** Chemins des lignes `worktree <path>` de `git worktree list --porcelain`. */
|
|
68
|
+
export function parseWorktrees(porcelain) {
|
|
69
|
+
return porcelain
|
|
70
|
+
.split(/\r?\n/)
|
|
71
|
+
.filter((l) => l.startsWith('worktree '))
|
|
72
|
+
.map((l) => l.slice('worktree '.length).trim())
|
|
73
|
+
.filter(Boolean);
|
|
74
|
+
}
|