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
package/README.fr.md
CHANGED
|
@@ -22,9 +22,9 @@ Tout tourne sur votre machine et lit via `git` et `gh`. Il ne parle qu'à GitHub
|
|
|
22
22
|
|
|
23
23
|
- **Globe des projets.** Vos projets tournent sur des orbites selon l'activité : actif (7 jours au plus), récent (7 à 30 jours), en veille (plus de 30 jours). Les plus récents pulsent. Repli sur des orbites SVG sans WebGL.
|
|
24
24
|
- **Reprendre, Échéances, À traiter.** Le dernier projet travaillé, les jalons ouverts, et ce qui vous attend : PR à relire, fichiers non commités, journal manquant.
|
|
25
|
-
- **Page projet.**
|
|
25
|
+
- **Page projet.** Un fil « Où j’en suis » qui mêle vos dernières conversations Claude Code, les dernières sessions du journal et les commits récents (avec des pastilles « non poussé »), une carte « À traiter » (PR ouvertes avec leur titre, commits non poussés, fichiers modifiés, bugs ouverts) et une carte sprint compacte.
|
|
26
26
|
- **Carte des idées.** Une matrice impact/effort de vos idées.
|
|
27
|
-
- **Un clic pour reprendre.**
|
|
27
|
+
- **Un clic pour reprendre.** « Continuer » rouvre la dernière conversation exacte avec `claude --resume`, et ignore celle qui semble ouverte dans un autre terminal (écrite il y a moins de 2 minutes, affichée « en cours », avec confirmation). Un menu « Nouvelle session » propose la dernière conversation, une nouvelle avec la skill de reprise, ou toutes les skills. « + Nouvelle skill » ouvre Claude avec une consigne intégrée pour suggérer et créer des skills pour le projet.
|
|
28
28
|
- **Skills du plugin.** `/holohq:catch-up`, `/holohq:wrap-up` et `/holohq:kickoff` gardent le journal et le plan dans GitHub.
|
|
29
29
|
- **Thèmes.** Holo, Mars, Terminal, Nebula, Day, ou le vôtre, avec un réglage d'effets complets ou discrets.
|
|
30
30
|
- **Anglais et français.**
|
|
@@ -33,6 +33,13 @@ Tout tourne sur votre machine et lit via `git` et `gh`. Il ne parle qu'à GitHub
|
|
|
33
33
|

|
|
34
34
|

|
|
35
35
|
|
|
36
|
+
## L'étage : vos agents au travail
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
Cliquez sur **Étage** dans la barre latérale (ou ajoutez `?view=floor` à l'URL) pour voir en direct chaque session et sous-agent Claude Code, par projet. Choisissez le rendu dans Réglages → « Rendu de l'étage » : **Planètes** (par défaut), **Immeuble** ou **Open-space**. Un agent est en fonction (animé, avec une bulle de sa dernière action), attend votre réponse (un « ! » qui pulse) ou est au repos (« z »), et les sous-agents se tiennent à côté de leur session avec une courte étiquette « rôle · modèle ».
|
|
41
|
+
Il lit seulement les transcriptions locales de Claude Code : rien à installer, rien ne quitte votre machine. Limites connues : une demande de permission en attente ressemble à « en fonction », et un terminal fermé peut encore afficher « attend ta réponse » pendant un moment.
|
|
42
|
+
|
|
36
43
|
## Installation
|
|
37
44
|
|
|
38
45
|
Prérequis : Node 22 ou plus, `git`, et le [GitHub CLI](https://cli.github.com) connecté. [Claude Code](https://claude.com/claude-code) (`claude`) est facultatif : seuls les boutons « Ouvrir dans Claude » en ont besoin.
|
|
@@ -114,6 +121,7 @@ Le démarrage automatique (`holohq autostart on`) utilise une tâche planifiée
|
|
|
114
121
|
|
|
115
122
|
- Un serveur local lié à `127.0.0.1` uniquement, avec contrôle des en-têtes Host et Origin.
|
|
116
123
|
- Il lit via `git` et `gh`. Il ne parle qu'à GitHub, avec votre propre connexion `gh`, et n'a aucune télémétrie.
|
|
124
|
+
- L'historique des conversations est lu en local dans les fichiers de Claude Code (`~/.claude/projects`, ou `$CLAUDE_CONFIG_DIR/projects`) et n'est envoyé nulle part.
|
|
117
125
|
- Il n'écrit sur GitHub que sur action explicite.
|
|
118
126
|
- Les skills du plugin n'ont besoin que de `git` et `gh` ; ils demandent avant de créer quoi que ce soit.
|
|
119
127
|
|
package/README.md
CHANGED
|
@@ -22,9 +22,9 @@ It runs on your machine and reads through `git` and `gh`. It talks only to GitHu
|
|
|
22
22
|
|
|
23
23
|
- **Project globe.** Your projects orbit by activity: active (7 days or less), recent (7 to 30 days), dormant (over 30 days). The most recent ones pulse. Falls back to SVG orbits without WebGL.
|
|
24
24
|
- **Resume, Deadlines, To do.** The last project you worked on, open milestones, and what needs you: PRs to review, uncommitted files, missing journal.
|
|
25
|
-
- **Project page.**
|
|
25
|
+
- **Project page.** A "Where I am" thread mixing your latest Claude Code conversations, the last journal sessions and recent commits (with "unpushed" badges), a "To handle" card (open PRs with titles, unpushed commits, modified files, open bugs) and a compact sprint card.
|
|
26
26
|
- **Ideas map.** An impact/effort matrix of your ideas.
|
|
27
|
-
- **One click to resume.** "
|
|
27
|
+
- **One click to resume.** "Continue" reopens the exact last conversation with `claude --resume`, and skips one that looks open in another terminal (written in the last 2 minutes, shown as "in progress", with a confirmation). A "New session" menu offers the last conversation, a new one with the resume skill, or any skill. "+ New skill" opens Claude with a built-in prompt to suggest and create skills for the project.
|
|
28
28
|
- **Plugin skills.** `/holohq:catch-up`, `/holohq:wrap-up` and `/holohq:kickoff` keep the journal and plan in GitHub.
|
|
29
29
|
- **Themes.** Holo, Mars, Terminal, Nebula, Day, or your own, with a full/subtle effects switch.
|
|
30
30
|
- **English and French.**
|
|
@@ -33,6 +33,13 @@ It runs on your machine and reads through `git` and `gh`. It talks only to GitHu
|
|
|
33
33
|

|
|
34
34
|

|
|
35
35
|
|
|
36
|
+
## The floor: your agents at work
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
Click **Floor** in the sidebar (or add `?view=floor` to the URL) to see every Claude Code session and subagent, grouped by project, live. Pick the rendering in Settings → "Floor view": **Planets** (default), **Tower** or **Open space**. Agents are working (animated, with a bubble of their last action), waiting for you (a pulsing "!") or resting ("z"), and subagents sit next to their session with a short "role · model" tag.
|
|
41
|
+
It only reads Claude Code's local transcript files: nothing to install, nothing leaves your machine. Known limitations: a pending permission prompt looks like "working", and a closed terminal can still show "waiting for you" for a while.
|
|
42
|
+
|
|
36
43
|
## Install
|
|
37
44
|
|
|
38
45
|
Requirements: Node 22 or later, `git`, and the [GitHub CLI](https://cli.github.com) logged in. [Claude Code](https://claude.com/claude-code) (`claude`) is optional: only the "Open in Claude" buttons need it.
|
|
@@ -114,6 +121,7 @@ Autostart (`holohq autostart on`) uses a scheduled task on Windows, a LaunchAgen
|
|
|
114
121
|
|
|
115
122
|
- A local server bound to `127.0.0.1` only, with Host and Origin checks.
|
|
116
123
|
- It reads through `git` and `gh`. It talks only to GitHub, through your own `gh` login, and has no telemetry.
|
|
124
|
+
- Conversation history is read locally from Claude Code's own files (`~/.claude/projects`, or `$CLAUDE_CONFIG_DIR/projects`) and never sent anywhere.
|
|
117
125
|
- It writes to GitHub only on an explicit action.
|
|
118
126
|
- The plugin skills need only `git` and `gh`; they ask before creating anything.
|
|
119
127
|
|
|
@@ -4,6 +4,8 @@ import { clearCaches } from './cache.js';
|
|
|
4
4
|
import { guard } from './guard.js';
|
|
5
5
|
import { register as registerActions } from './routes/actions.js';
|
|
6
6
|
import { register as registerAutostart } from './routes/autostart.js';
|
|
7
|
+
import { register as registerConversations } from './routes/conversations.js';
|
|
8
|
+
import { register as registerFloor } from './routes/floor.js';
|
|
7
9
|
import { register as registerDetail } from './routes/detail.js';
|
|
8
10
|
import { register as registerLaunch } from './routes/launch.js';
|
|
9
11
|
import { register as registerHome } from './routes/home.js';
|
|
@@ -35,6 +37,8 @@ export function createApp(deps) {
|
|
|
35
37
|
registerDetail(app, deps);
|
|
36
38
|
registerRemotes(app, deps);
|
|
37
39
|
registerHome(app, deps);
|
|
40
|
+
registerConversations(app, deps);
|
|
41
|
+
registerFloor(app, deps);
|
|
38
42
|
registerLaunch(app, deps);
|
|
39
43
|
registerWrite(app, deps);
|
|
40
44
|
registerActions(app, deps);
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { evidenceOf } from '../floor/evidence.js';
|
|
4
|
+
import { cleanText, oneLine, readRange } from './history.js';
|
|
5
|
+
export const WORKING_MS = 10 * 60_000;
|
|
6
|
+
export const WAITING_MS = 15 * 60_000;
|
|
7
|
+
export const VISIBLE_MS = 60 * 60_000;
|
|
8
|
+
export const TAIL_BYTES = 262_144;
|
|
9
|
+
/** Plafond d'une lecture élargie, quand une fin de fichier jamais lue ne contient aucun enregistrement significatif. */
|
|
10
|
+
export const WIDE_BYTES = 2 * 1024 * 1024;
|
|
11
|
+
/** `finished` ne compte plus si le sous-agent a écrit au moins ce temps après sa fiche : sa session l'a repris. */
|
|
12
|
+
export const RESUMED_MS = 10_000;
|
|
13
|
+
/** Un sous-agent terminé ou trop ancien n'est revérifié qu'à cet intervalle. */
|
|
14
|
+
export const COLD_MS = 15_000;
|
|
15
|
+
export const ACTION_MAX = 40;
|
|
16
|
+
const PATHS_MAX = 20;
|
|
17
|
+
/** Outils qui attendent une réponse de l'utilisateur tant que leur résultat n'est pas écrit. */
|
|
18
|
+
const ASKING_TOOLS = new Set(['AskUserQuestion', 'ExitPlanMode']);
|
|
19
|
+
function blocksOf(rec) {
|
|
20
|
+
const content = rec.message?.content;
|
|
21
|
+
return Array.isArray(content) ? content.filter((b) => !!b && typeof b === 'object') : [];
|
|
22
|
+
}
|
|
23
|
+
/** Texte brut d'un message `user` (chaîne ou blocs `text`). */
|
|
24
|
+
function rawText(rec) {
|
|
25
|
+
const content = rec.message?.content;
|
|
26
|
+
if (typeof content === 'string')
|
|
27
|
+
return content;
|
|
28
|
+
return blocksOf(rec).map(b => (b.type === 'text' && typeof b.text === 'string' ? b.text : '')).join(' ');
|
|
29
|
+
}
|
|
30
|
+
/** Résume la fin d'une transcription. `cutAtStart` : le texte commence au milieu d'une ligne, la première est ignorée. */
|
|
31
|
+
export function parseTail(text, opts) {
|
|
32
|
+
const lines = text.split('\n');
|
|
33
|
+
if (opts.cutAtStart)
|
|
34
|
+
lines.shift();
|
|
35
|
+
let turn = null;
|
|
36
|
+
let action = null;
|
|
37
|
+
const asked = new Map();
|
|
38
|
+
let customTitle = null;
|
|
39
|
+
let aiTitle = null;
|
|
40
|
+
let promptTitle = null;
|
|
41
|
+
let entrypoint = null;
|
|
42
|
+
let cwd = null;
|
|
43
|
+
const paths = [];
|
|
44
|
+
/** Un enregistrement du tour en cours, ou le début d'un nouveau (début inconnu s'il précède le texte lu). */
|
|
45
|
+
const open = (at) => { turn = { open: true, startedAt: turn ? (turn.open ? turn.startedAt : at) : null, at }; };
|
|
46
|
+
const close = (at) => {
|
|
47
|
+
turn = { open: false, startedAt: turn?.startedAt ?? null, at };
|
|
48
|
+
action = null;
|
|
49
|
+
asked.clear();
|
|
50
|
+
};
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
if (!line.trim())
|
|
53
|
+
continue;
|
|
54
|
+
let rec;
|
|
55
|
+
try {
|
|
56
|
+
const v = JSON.parse(line);
|
|
57
|
+
if (!v || typeof v !== 'object')
|
|
58
|
+
continue;
|
|
59
|
+
rec = v;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const type = rec.type;
|
|
65
|
+
if (typeof rec.entrypoint === 'string')
|
|
66
|
+
entrypoint = rec.entrypoint;
|
|
67
|
+
if (typeof rec.cwd === 'string')
|
|
68
|
+
cwd = rec.cwd;
|
|
69
|
+
if (type === 'custom-title' && typeof rec.customTitle === 'string')
|
|
70
|
+
customTitle = oneLine(rec.customTitle) || customTitle;
|
|
71
|
+
else if (type === 'ai-title' && typeof rec.aiTitle === 'string')
|
|
72
|
+
aiTitle = oneLine(rec.aiTitle) || aiTitle;
|
|
73
|
+
else if (type === 'last-prompt' && typeof rec.lastPrompt === 'string')
|
|
74
|
+
promptTitle = cleanText(rec.lastPrompt) ?? promptTitle;
|
|
75
|
+
const at = rec.timestamp;
|
|
76
|
+
if (typeof at !== 'string')
|
|
77
|
+
continue;
|
|
78
|
+
if (type === 'user') {
|
|
79
|
+
if (rec.isMeta)
|
|
80
|
+
continue;
|
|
81
|
+
const results = blocksOf(rec).filter(b => b.type === 'tool_result');
|
|
82
|
+
const text = rawText(rec);
|
|
83
|
+
if (results.length) {
|
|
84
|
+
for (const b of results)
|
|
85
|
+
asked.delete(b.tool_use_id);
|
|
86
|
+
open(at);
|
|
87
|
+
}
|
|
88
|
+
else if (text.trimStart().startsWith('[Request interrupted by user')) {
|
|
89
|
+
close(at);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Demande tapée : elle ouvre un tour, ou s'ajoute au tour en cours ; une notification de Claude Code n'est pas une réponse.
|
|
93
|
+
if (!turn?.open)
|
|
94
|
+
action = null;
|
|
95
|
+
if (cleanText(text))
|
|
96
|
+
asked.clear();
|
|
97
|
+
turn = { open: true, startedAt: turn?.open ? turn.startedAt : at, at };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (type === 'assistant') {
|
|
101
|
+
const msg = rec.message;
|
|
102
|
+
// Une réponse fabriquée par Claude Code (erreur d'API) clôt le tour : plus rien ne travaille.
|
|
103
|
+
const closed = msg?.stop_reason === 'end_turn' || rec.isApiErrorMessage === true || msg?.model === '<synthetic>';
|
|
104
|
+
for (const b of blocksOf(rec)) {
|
|
105
|
+
if (b.type !== 'tool_use' || typeof b.name !== 'string')
|
|
106
|
+
continue;
|
|
107
|
+
const input = b.input && typeof b.input === 'object' ? b.input : {};
|
|
108
|
+
action = actionOf({ name: b.name, input });
|
|
109
|
+
if (ASKING_TOOLS.has(b.name))
|
|
110
|
+
asked.set(b.id, at);
|
|
111
|
+
const cited = evidenceOf(b.name, input);
|
|
112
|
+
if (cited.length)
|
|
113
|
+
paths.push(cited);
|
|
114
|
+
}
|
|
115
|
+
if (closed)
|
|
116
|
+
close(at);
|
|
117
|
+
else
|
|
118
|
+
open(at);
|
|
119
|
+
}
|
|
120
|
+
else if (type === 'system' && rec.subtype === 'turn_duration') {
|
|
121
|
+
close(at);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
turn, action, asking: [...asked.values()].pop() ?? null, title: customTitle ?? aiTitle ?? promptTitle, entrypoint, cwd,
|
|
126
|
+
paths: paths.slice(-PATHS_MAX).reverse(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const basename = (p) => p.split(/[\\/]/).filter(Boolean).pop() ?? p;
|
|
130
|
+
const str = (v) => (typeof v === 'string' && v ? v : null);
|
|
131
|
+
const clip = (s) => {
|
|
132
|
+
if (s === null)
|
|
133
|
+
return null;
|
|
134
|
+
const chars = [...s.replace(/\s+/g, ' ').trim()];
|
|
135
|
+
return chars.length > ACTION_MAX ? chars.slice(0, ACTION_MAX - 1).join('') + '…' : chars.join('');
|
|
136
|
+
};
|
|
137
|
+
function hostOf(url) {
|
|
138
|
+
if (typeof url !== 'string')
|
|
139
|
+
return null;
|
|
140
|
+
try {
|
|
141
|
+
return new URL(url).hostname || null;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Libellé court de ce que fait un outil : un verbe et une cible d'au plus `ACTION_MAX` caractères. */
|
|
148
|
+
export function actionOf(tool) {
|
|
149
|
+
const { name, input } = tool;
|
|
150
|
+
const make = (verb, target) => ({ verb, target: clip(target) });
|
|
151
|
+
switch (name) {
|
|
152
|
+
case 'Edit':
|
|
153
|
+
case 'Write':
|
|
154
|
+
case 'MultiEdit':
|
|
155
|
+
case 'NotebookEdit': {
|
|
156
|
+
const p = str(input.file_path) ?? str(input.notebook_path);
|
|
157
|
+
return make('edit', p && basename(p));
|
|
158
|
+
}
|
|
159
|
+
case 'Read': {
|
|
160
|
+
const p = str(input.file_path);
|
|
161
|
+
return make('read', p && basename(p));
|
|
162
|
+
}
|
|
163
|
+
case 'Bash':
|
|
164
|
+
case 'PowerShell': return make('run', str(input.description));
|
|
165
|
+
case 'Grep':
|
|
166
|
+
case 'Glob': return make('search', str(input.pattern));
|
|
167
|
+
case 'Agent':
|
|
168
|
+
case 'Task': return make('delegate', str(input.description));
|
|
169
|
+
case 'WebFetch': return make('web', hostOf(input.url));
|
|
170
|
+
case 'WebSearch': return make('web', str(input.query));
|
|
171
|
+
default: return make('other', name.split('__').filter(Boolean).pop() ?? name);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** Faux seulement pour les sessions pilotées par un SDK (`sdk-cli`, `sdk-ts`…). */
|
|
175
|
+
export function isInteractive(entrypoint) {
|
|
176
|
+
return !(entrypoint ?? '').startsWith('sdk-');
|
|
177
|
+
}
|
|
178
|
+
/** État d'une session d'après son dernier tour ; null : ne plus l'afficher. */
|
|
179
|
+
export function sessionState(s, now, o) {
|
|
180
|
+
if (!s.turn)
|
|
181
|
+
return null;
|
|
182
|
+
const age = now.getTime() - Date.parse(s.turn.at);
|
|
183
|
+
if (s.asking && o.interactive)
|
|
184
|
+
return age < VISIBLE_MS ? { state: 'waiting', since: s.asking } : null;
|
|
185
|
+
if (s.turn.open && age < WORKING_MS)
|
|
186
|
+
return { state: 'working', since: s.turn.startedAt ?? s.turn.at };
|
|
187
|
+
if (!s.turn.open && o.interactive && age < WAITING_MS)
|
|
188
|
+
return { state: 'waiting', since: s.turn.at };
|
|
189
|
+
if (age < VISIBLE_MS)
|
|
190
|
+
return { state: 'resting', since: s.turn.at };
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
194
|
+
const SUBAGENT_FILE = /^agent-(.+)\.jsonl$/;
|
|
195
|
+
/**
|
|
196
|
+
* Lecteur de l'étage : sessions et sous-agents Claude Code récents, lus dans le dossier des projets.
|
|
197
|
+
* Au mieux : ne lève jamais. Un fichier inchangé (chemin, taille, date) n'est pas relu. Les caches ne gardent que ce que
|
|
198
|
+
* le dernier passage a utilisé.
|
|
199
|
+
*/
|
|
200
|
+
export function createFloorReader(opts) {
|
|
201
|
+
const read = opts.read ?? readRange;
|
|
202
|
+
const statOf = opts.stat ?? stat;
|
|
203
|
+
const tails = new Map();
|
|
204
|
+
const metas = new Map();
|
|
205
|
+
/** Sous-agents terminés ou trop anciens : date de leur dernière vérification. */
|
|
206
|
+
const cold = new Map();
|
|
207
|
+
/** Chemins utilisés par le passage en cours. */
|
|
208
|
+
const used = new Set();
|
|
209
|
+
/** Sessions dont un sous-agent travaillait au dernier passage : à regarder même si plus rien n'est récent chez elles. */
|
|
210
|
+
let busy = new Set();
|
|
211
|
+
/** Dernier passage qui a regardé les sous-agents de toutes les sessions (au premier, puis tous les `WORKING_MS`). */
|
|
212
|
+
let deepAt = -Infinity;
|
|
213
|
+
/**
|
|
214
|
+
* Résumé de la fin d'un fichier. Sans enregistrement significatif dans cette fin : le résumé précédent reste vrai si tout
|
|
215
|
+
* l'ajout a été lu ; sinon, une seule lecture plus large. `birth` : début connu de l'agent, faute de voir celui du tour.
|
|
216
|
+
*/
|
|
217
|
+
async function tailOf(path, { size, mtimeMs }, birth) {
|
|
218
|
+
used.add(path);
|
|
219
|
+
const prev = tails.get(path);
|
|
220
|
+
if (prev && prev.size === size && prev.mtimeMs === mtimeMs)
|
|
221
|
+
return prev.value;
|
|
222
|
+
const summary = async (bytes) => {
|
|
223
|
+
const start = Math.max(0, size - bytes);
|
|
224
|
+
return { start, value: parseTail((await read(path, start, size)).toString('utf8'), { cutAtStart: start > 0 }) };
|
|
225
|
+
};
|
|
226
|
+
try {
|
|
227
|
+
let { start, value } = await summary(TAIL_BYTES);
|
|
228
|
+
const known = prev && prev.size <= size && start <= prev.size ? prev.value : null;
|
|
229
|
+
if (!value.turn && !known && start > 0)
|
|
230
|
+
({ value } = await summary(WIDE_BYTES));
|
|
231
|
+
if (known) {
|
|
232
|
+
value = { ...value, title: value.title ?? known.title, entrypoint: value.entrypoint ?? known.entrypoint, cwd: value.cwd ?? known.cwd };
|
|
233
|
+
if (!value.turn)
|
|
234
|
+
value = { ...value, turn: known.turn, action: known.action, asking: known.asking, paths: known.paths };
|
|
235
|
+
}
|
|
236
|
+
if (value.turn && value.turn.startedAt === null) {
|
|
237
|
+
// Début hors de la fin lue : celui du tour déjà suivi, sinon la naissance de l'agent, sinon maintenant. Il ne bouge plus ensuite.
|
|
238
|
+
const { at } = value.turn;
|
|
239
|
+
const last = prev?.value.turn;
|
|
240
|
+
const same = last?.open && Date.parse(at) - Date.parse(last.at) < WORKING_MS;
|
|
241
|
+
value = { ...value, turn: { ...value.turn, startedAt: (same ? last.startedAt : null) ?? (birth && birth <= at ? birth : at) } };
|
|
242
|
+
}
|
|
243
|
+
tails.set(path, { size, mtimeMs, value });
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function metaOf(path) {
|
|
251
|
+
used.add(path);
|
|
252
|
+
try {
|
|
253
|
+
const s = await statOf(path);
|
|
254
|
+
const hit = metas.get(path);
|
|
255
|
+
if (hit && hit.size === s.size && hit.mtimeMs === s.mtimeMs)
|
|
256
|
+
return hit.value;
|
|
257
|
+
let value = null;
|
|
258
|
+
try {
|
|
259
|
+
const m = JSON.parse(await readFile(path, 'utf8'));
|
|
260
|
+
if (m && typeof m === 'object') {
|
|
261
|
+
value = { role: str(m.agentType), task: str(m.description), model: str(m.model), finished: m.finished === true, at: s.mtimeMs };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch { /* fiche illisible : comme absente */ }
|
|
265
|
+
metas.set(path, { size: s.size, mtimeMs: s.mtimeMs, value });
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function scan() {
|
|
273
|
+
const now = opts.now();
|
|
274
|
+
let dirs;
|
|
275
|
+
try {
|
|
276
|
+
dirs = await readdir(opts.root, { withFileTypes: true });
|
|
277
|
+
}
|
|
278
|
+
catch (e) {
|
|
279
|
+
return e.code === 'ENOENT' ? { readable: true, agents: [] } : { readable: false };
|
|
280
|
+
}
|
|
281
|
+
used.clear();
|
|
282
|
+
const deep = now.getTime() - deepAt >= WORKING_MS;
|
|
283
|
+
if (deep)
|
|
284
|
+
deepAt = now.getTime();
|
|
285
|
+
const agents = [];
|
|
286
|
+
const nowBusy = new Set();
|
|
287
|
+
for (const d of dirs) {
|
|
288
|
+
if (!d.isDirectory())
|
|
289
|
+
continue;
|
|
290
|
+
const folder = join(opts.root, d.name);
|
|
291
|
+
let entries;
|
|
292
|
+
try {
|
|
293
|
+
entries = await readdir(folder, { withFileTypes: true });
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
// Par session : sa transcription et son dossier, s'ils existent (aucun `stat` perdu d'avance).
|
|
299
|
+
const found = new Map();
|
|
300
|
+
for (const ent of entries) {
|
|
301
|
+
const file = ent.isFile() && ent.name.endsWith('.jsonl');
|
|
302
|
+
const id = file ? ent.name.slice(0, -6) : ent.name;
|
|
303
|
+
if (!UUID.test(id) || (!file && !ent.isDirectory()))
|
|
304
|
+
continue;
|
|
305
|
+
const f = found.get(id) ?? { file: false, dir: false };
|
|
306
|
+
found.set(id, file ? { ...f, file } : { ...f, dir: true });
|
|
307
|
+
}
|
|
308
|
+
for (const [id, has] of found) {
|
|
309
|
+
const out = await scanSession(folder, id, has, now, deep);
|
|
310
|
+
if (out.some(a => a.kind === 'subagent' && a.state === 'working'))
|
|
311
|
+
nowBusy.add(id);
|
|
312
|
+
agents.push(...out);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
busy = nowBusy;
|
|
316
|
+
for (const cache of [tails, metas, cold])
|
|
317
|
+
for (const path of cache.keys())
|
|
318
|
+
if (!used.has(path))
|
|
319
|
+
cache.delete(path);
|
|
320
|
+
return { readable: true, agents };
|
|
321
|
+
}
|
|
322
|
+
async function scanSession(folder, id, has, now, deep) {
|
|
323
|
+
const fresh = (s) => s !== null && now.getTime() - s.mtimeMs < VISIBLE_MS;
|
|
324
|
+
const look = async (path) => { try {
|
|
325
|
+
return await statOf(path);
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
return null;
|
|
329
|
+
} };
|
|
330
|
+
const file = join(folder, `${id}.jsonl`);
|
|
331
|
+
const subDir = join(folder, id, 'subagents');
|
|
332
|
+
const own = has.file ? await look(file) : null;
|
|
333
|
+
if (!fresh(own) && !busy.has(id) && !(has.dir && (deep || fresh(await look(subDir)))))
|
|
334
|
+
return [];
|
|
335
|
+
const children = [];
|
|
336
|
+
let names = [];
|
|
337
|
+
if (has.dir)
|
|
338
|
+
try {
|
|
339
|
+
names = await readdir(subDir);
|
|
340
|
+
}
|
|
341
|
+
catch { /* pas de sous-agents */ }
|
|
342
|
+
for (const name of names) {
|
|
343
|
+
const m = SUBAGENT_FILE.exec(name);
|
|
344
|
+
if (!m)
|
|
345
|
+
continue;
|
|
346
|
+
const path = join(subDir, name);
|
|
347
|
+
const metaPath = join(subDir, `agent-${m[1]}.meta.json`);
|
|
348
|
+
if (now.getTime() - (cold.get(path) ?? -Infinity) < COLD_MS) {
|
|
349
|
+
used.add(path).add(metaPath);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
cold.delete(path);
|
|
353
|
+
const rest = () => { cold.set(path, now.getTime()); used.add(path); };
|
|
354
|
+
const s = await look(path);
|
|
355
|
+
if (!fresh(s)) {
|
|
356
|
+
rest();
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
const meta = await metaOf(metaPath);
|
|
360
|
+
const over = (at) => meta?.finished === true && at <= meta.at + RESUMED_MS;
|
|
361
|
+
if (over(s.mtimeMs)) {
|
|
362
|
+
rest();
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const tail = await tailOf(path, s, s.birthtimeMs > 0 ? new Date(s.birthtimeMs).toISOString() : null);
|
|
366
|
+
if (!tail?.turn || over(Date.parse(tail.turn.at)))
|
|
367
|
+
continue;
|
|
368
|
+
const st = sessionState(tail, now, { interactive: false });
|
|
369
|
+
if (!st)
|
|
370
|
+
continue;
|
|
371
|
+
children.push({
|
|
372
|
+
id: `agent-${m[1]}`, kind: 'subagent', parentId: id, state: st.state, title: null,
|
|
373
|
+
role: meta?.role ?? null, model: meta?.model ?? null, task: meta?.task ?? null,
|
|
374
|
+
action: st.state === 'working' ? tail.action : null,
|
|
375
|
+
since: st.since, updatedAt: tail.turn.at, cwd: tail.cwd, paths: tail.paths,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
// Une vieille session sans sous-agent vivant n'est pas lue.
|
|
379
|
+
if (!own || (!fresh(own) && !children.length))
|
|
380
|
+
return [];
|
|
381
|
+
const summary = await tailOf(file, own, null);
|
|
382
|
+
for (const c of children)
|
|
383
|
+
c.cwd ??= summary?.cwd ?? null;
|
|
384
|
+
const working = children.filter(c => c.state === 'working').sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt));
|
|
385
|
+
const state = summary ? sessionState(summary, now, { interactive: isInteractive(summary.entrypoint) }) : null;
|
|
386
|
+
// Un sous-agent n'est listé que si sa session l'est.
|
|
387
|
+
if (!summary || (!state && !working.length))
|
|
388
|
+
return [];
|
|
389
|
+
// Elle délègue : elle travaille, sauf si elle attend la réponse à une question.
|
|
390
|
+
const delegates = working.length > 0 && !(summary.asking && state?.state === 'waiting');
|
|
391
|
+
const parent = {
|
|
392
|
+
id, kind: 'session', parentId: null, title: summary.title, role: null, model: null, task: null,
|
|
393
|
+
state: delegates ? 'working' : state.state,
|
|
394
|
+
action: delegates
|
|
395
|
+
? (working[0].task ? actionOf({ name: 'Agent', input: { description: working[0].task } }) : { verb: 'delegate', target: null })
|
|
396
|
+
: state.state === 'working' ? summary.action : null,
|
|
397
|
+
since: delegates ? summary.turn?.startedAt ?? working[0].since : state.since,
|
|
398
|
+
updatedAt: summary.turn?.at ?? working[0].updatedAt, cwd: summary.cwd, paths: summary.paths,
|
|
399
|
+
};
|
|
400
|
+
return [parent, ...children];
|
|
401
|
+
}
|
|
402
|
+
// Une seule lecture à la fois : les appels simultanés partagent la même promesse.
|
|
403
|
+
let inflight = null;
|
|
404
|
+
return () => {
|
|
405
|
+
inflight ??= scan().catch(() => ({ readable: false })).finally(() => { inflight = null; });
|
|
406
|
+
return inflight;
|
|
407
|
+
};
|
|
408
|
+
}
|