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.
- package/LICENSE +21 -0
- package/README.fr.md +145 -0
- package/README.md +144 -2
- package/bin/holohq.js +12 -0
- package/dist/server/server/actions/clone.js +36 -0
- package/dist/server/server/actions/newProject.js +40 -0
- package/dist/server/server/actions/publish.js +22 -0
- package/dist/server/server/app.js +46 -0
- package/dist/server/server/autostart.js +127 -0
- package/dist/server/server/autostartRun.js +96 -0
- package/dist/server/server/browser.js +24 -0
- package/dist/server/server/cache.js +24 -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/cli/autostart.js +21 -0
- package/dist/server/server/cli/config.js +45 -0
- package/dist/server/server/cli/convention.js +51 -0
- package/dist/server/server/cli/io.js +1 -0
- package/dist/server/server/cli/main.js +129 -0
- package/dist/server/server/config.js +311 -0
- package/dist/server/server/demo/config.js +19 -0
- package/dist/server/server/demo/data.js +317 -0
- package/dist/server/server/demo/deps.js +36 -0
- package/dist/server/server/demo/floor.js +45 -0
- package/dist/server/server/demo/run.js +315 -0
- package/dist/server/server/demo/scan.js +21 -0
- package/dist/server/server/domain/home.js +85 -0
- package/dist/server/server/domain/journal.js +33 -0
- package/dist/server/server/domain/sprint.js +9 -0
- package/dist/server/server/exec.js +12 -0
- package/dist/server/server/floor/attribute.js +74 -0
- package/dist/server/server/floor/evidence.js +39 -0
- package/dist/server/server/git/status.js +45 -0
- package/dist/server/server/github/gh.js +27 -0
- package/dist/server/server/github/labels.js +65 -0
- package/dist/server/server/github/project.js +58 -0
- package/dist/server/server/github/repos.js +17 -0
- package/dist/server/server/github/write.js +91 -0
- package/dist/server/server/guard.js +18 -0
- package/dist/server/server/index.js +9 -0
- package/dist/server/server/launch.js +168 -0
- package/dist/server/server/paths.js +26 -0
- package/dist/server/server/preload.js +30 -0
- package/dist/server/server/projects/remote.js +13 -0
- package/dist/server/server/projects/scan.js +79 -0
- package/dist/server/server/routes/actions.js +89 -0
- package/dist/server/server/routes/autostart.js +21 -0
- package/dist/server/server/routes/conversations.js +21 -0
- package/dist/server/server/routes/detail.js +24 -0
- package/dist/server/server/routes/floor.js +77 -0
- package/dist/server/server/routes/home.js +64 -0
- package/dist/server/server/routes/launch.js +79 -0
- package/dist/server/server/routes/projects.js +75 -0
- package/dist/server/server/routes/remotes.js +30 -0
- package/dist/server/server/routes/setup.js +114 -0
- package/dist/server/server/routes/write.js +129 -0
- package/dist/server/server/setup/tools.js +37 -0
- package/dist/server/server/skills.js +69 -0
- package/dist/server/server/start.js +166 -0
- package/dist/server/server/static.js +49 -0
- package/dist/server/shared/color.js +59 -0
- package/dist/server/shared/errors.js +88 -0
- package/dist/server/shared/ideas.js +36 -0
- package/dist/server/shared/labels.js +36 -0
- package/dist/server/shared/repoName.js +13 -0
- package/dist/server/shared/themes.js +120 -0
- package/dist/server/shared/tiers.js +15 -0
- package/dist/server/shared/types.js +1 -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/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-600-normal-8K4wrrwR.woff +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/dist/web/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-600-normal-mc2nkWzM.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-600-normal-BfsvjouI.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-600-normal-DObL3zCW.woff +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-600-normal-OWROknRo.woff +0 -0
- package/dist/web/assets/rajdhani-devanagari-500-normal-BPH8g_s8.woff +0 -0
- package/dist/web/assets/rajdhani-devanagari-500-normal-B_DH_jja.woff2 +0 -0
- package/dist/web/assets/rajdhani-devanagari-600-normal-BtY48IV_.woff +0 -0
- package/dist/web/assets/rajdhani-devanagari-600-normal-DhS7ScYx.woff2 +0 -0
- package/dist/web/assets/rajdhani-devanagari-700-normal-BQQOj9BB.woff2 +0 -0
- package/dist/web/assets/rajdhani-devanagari-700-normal-DBRwWuxA.woff +0 -0
- package/dist/web/assets/rajdhani-latin-500-normal-ByNUCHrt.woff2 +0 -0
- package/dist/web/assets/rajdhani-latin-500-normal-DfvNI-Td.woff +0 -0
- package/dist/web/assets/rajdhani-latin-600-normal-CXCVEoA9.woff2 +0 -0
- package/dist/web/assets/rajdhani-latin-600-normal-Dx02qI2_.woff +0 -0
- package/dist/web/assets/rajdhani-latin-700-normal-BPDUZo87.woff2 +0 -0
- package/dist/web/assets/rajdhani-latin-700-normal-e0Uj8ZlN.woff +0 -0
- package/dist/web/assets/rajdhani-latin-ext-500-normal-CyRWJZ5B.woff +0 -0
- package/dist/web/assets/rajdhani-latin-ext-500-normal-DiyUS11w.woff2 +0 -0
- package/dist/web/assets/rajdhani-latin-ext-600-normal-BleIgkPp.woff +0 -0
- package/dist/web/assets/rajdhani-latin-ext-600-normal-C9ZjJQAt.woff2 +0 -0
- package/dist/web/assets/rajdhani-latin-ext-700-normal-BPaQ7tlD.woff +0 -0
- package/dist/web/assets/rajdhani-latin-ext-700-normal-S6aYESQK.woff2 +0 -0
- package/dist/web/index.html +13 -0
- package/package.json +74 -4
- package/scripts/autostart.ps1 +28 -0
- package/scripts/start-hidden.vbs +12 -0
- package/templates/en/CLAUDE.md +18 -0
- package/templates/en/README.md +3 -0
- package/templates/fr/CLAUDE.md +18 -0
- package/templates/fr/README.md +3 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Faux `run` du mode démo : répond, à partir du jeu de données, à chaque forme de commande git/gh que le serveur
|
|
3
|
+
* émet (voir `grep -rn "run(" server`). Rien n'est jamais exécuté. Une commande non reconnue renvoie `code: 1`
|
|
4
|
+
* et est notée dans `misses` (journalisé à l'arrêt de la démo).
|
|
5
|
+
*/
|
|
6
|
+
import { LABEL_SETS } from '../../shared/labels.js';
|
|
7
|
+
import { DEMO_OWNER, DEMO_PROJECTS, DEMO_REMOTE_ONLY, daysAgoIso, demoPath } from './data.js';
|
|
8
|
+
const EN = LABEL_SETS.en;
|
|
9
|
+
/** Format des `git log` du serveur (git/status.ts, routes/projects.ts). */
|
|
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');
|
|
13
|
+
const FILES = ['src/index.ts', 'src/app.ts', 'README.md', 'src/styles.css', 'package.json'];
|
|
14
|
+
const ok = (stdout = '') => ({ stdout, stderr: '', code: 0 });
|
|
15
|
+
const fail = (stderr, code = 1) => ({ stdout: '', stderr, code });
|
|
16
|
+
const json = (v) => ok(JSON.stringify(v));
|
|
17
|
+
const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
18
|
+
/** Valeur qui suit `name` dans les arguments. */
|
|
19
|
+
const flag = (args, name) => {
|
|
20
|
+
const i = args.indexOf(name);
|
|
21
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
22
|
+
};
|
|
23
|
+
/** Empreinte stable (FNV-1a) : de faux hash de commit identiques d'un lancement à l'autre. */
|
|
24
|
+
function fakeHash(s) {
|
|
25
|
+
let h = 0x811c9dc5;
|
|
26
|
+
for (const ch of s)
|
|
27
|
+
h = Math.imul(h ^ ch.charCodeAt(0), 0x01000193) >>> 0;
|
|
28
|
+
return h.toString(16).padStart(8, '0').slice(0, 7);
|
|
29
|
+
}
|
|
30
|
+
const byPath = (path) => DEMO_PROJECTS.find((p) => demoPath(p.name) === path);
|
|
31
|
+
/** Projet de la démo publié sur GitHub, d'après `owner/name`. */
|
|
32
|
+
function bySlug(slug) {
|
|
33
|
+
const [owner, name] = (slug ?? '').split('/');
|
|
34
|
+
if (owner?.toLowerCase() !== DEMO_OWNER)
|
|
35
|
+
return undefined;
|
|
36
|
+
return DEMO_PROJECTS.find((p) => p.github && p.name.toLowerCase() === name?.toLowerCase());
|
|
37
|
+
}
|
|
38
|
+
const issueUrl = (p, n) => `https://github.com/${DEMO_OWNER}/${p.name}/issues/${n}`;
|
|
39
|
+
const ideaLabels = (i) => [
|
|
40
|
+
EN.idea,
|
|
41
|
+
...(i.theme ? [`${EN.themePrefix}${i.theme}`] : []),
|
|
42
|
+
...(i.effort ? [`effort:${i.effort}`] : []),
|
|
43
|
+
...(i.impact ? [EN.impact[i.impact]] : []),
|
|
44
|
+
];
|
|
45
|
+
/** Tickets d'un projet, numérotés : journal (#1), puis le jalon, puis les idées. */
|
|
46
|
+
function issuesOf(p) {
|
|
47
|
+
let n = 0;
|
|
48
|
+
const out = [];
|
|
49
|
+
if (p.journal)
|
|
50
|
+
out.push({ number: ++n, title: EN.journalTitle, state: 'OPEN', labels: ['journal'], milestone: null, kind: 'journal' });
|
|
51
|
+
for (const i of p.sprint?.issues ?? [])
|
|
52
|
+
out.push({ number: ++n, title: i.title, state: i.closed ? 'CLOSED' : 'OPEN', labels: i.labels ?? [], milestone: 1, kind: 'sprint' });
|
|
53
|
+
for (const i of p.ideas ?? [])
|
|
54
|
+
out.push({ number: ++n, title: i.title, state: 'OPEN', labels: ideaLabels(i), milestone: null, kind: 'idea' });
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
const rawIssue = (p, i) => ({
|
|
58
|
+
number: i.number,
|
|
59
|
+
title: i.title,
|
|
60
|
+
url: issueUrl(p, i.number),
|
|
61
|
+
state: i.state,
|
|
62
|
+
labels: { nodes: i.labels.map((name) => ({ name })) },
|
|
63
|
+
milestone: i.milestone === null ? null : { number: i.milestone },
|
|
64
|
+
});
|
|
65
|
+
/** Labels du dépôt : la convention complète (jeu anglais) quand le projet a un journal, sinon ceux de GitHub par défaut. */
|
|
66
|
+
function labelsOf(p) {
|
|
67
|
+
const base = ['bug', 'documentation', 'enhancement'];
|
|
68
|
+
if (!p.journal)
|
|
69
|
+
return base;
|
|
70
|
+
const themes = issuesOf(p).flatMap((i) => i.labels.filter((l) => l.startsWith(EN.themePrefix)));
|
|
71
|
+
return [...new Set([...base, EN.idea, 'effort:S', 'effort:M', 'effort:L', ...Object.values(EN.impact), 'journal', ...themes])];
|
|
72
|
+
}
|
|
73
|
+
function milestone(p, now) {
|
|
74
|
+
const s = p.sprint;
|
|
75
|
+
const issues = issuesOf(p).filter((i) => i.kind === 'sprint');
|
|
76
|
+
const closed = issues.filter((i) => i.state === 'CLOSED').length;
|
|
77
|
+
return {
|
|
78
|
+
number: 1,
|
|
79
|
+
title: s.title,
|
|
80
|
+
dueOn: s.dueInDays === null ? null : daysAgoIso(now, -s.dueInDays),
|
|
81
|
+
createdAt: daysAgoIso(now, s.createdDaysAgo),
|
|
82
|
+
open: issues.length - closed,
|
|
83
|
+
closed,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function journalBody(p, now) {
|
|
87
|
+
const j = p.journal;
|
|
88
|
+
return `## Session ${daysAgoIso(now, j.daysAgo).slice(0, 10)}\n**Done:** ${j.done}\n**Left:** ${j.left}\n**Next:** ${j.next}`;
|
|
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
|
+
}
|
|
110
|
+
// ---- git ----
|
|
111
|
+
function statusText(p) {
|
|
112
|
+
const upstream = p.ahead === null ? '' : `...origin/${p.branch}${p.ahead > 0 ? ` [ahead ${p.ahead}]` : ''}`;
|
|
113
|
+
const lines = [`## ${p.branch}${upstream}`];
|
|
114
|
+
for (let i = 0; i < p.modified; i++)
|
|
115
|
+
lines.push(` M ${FILES[i % FILES.length]}`);
|
|
116
|
+
for (let i = 0; i < p.untracked; i++)
|
|
117
|
+
lines.push(`?? notes-${i + 1}.md`);
|
|
118
|
+
return lines.join('\n') + '\n';
|
|
119
|
+
}
|
|
120
|
+
function logText(p, n, now) {
|
|
121
|
+
return p.commits
|
|
122
|
+
.slice(0, n)
|
|
123
|
+
.map(([daysAgo, subject], i) => `${fakeHash(`${p.name}:${i}`)}\x1f${daysAgoIso(now, daysAgo)}\x1f${subject}\n`)
|
|
124
|
+
.join('');
|
|
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
|
+
}
|
|
131
|
+
function git(args, now) {
|
|
132
|
+
if (same(args, ['--version']))
|
|
133
|
+
return ok('git version 2.47.0\n');
|
|
134
|
+
if (args[0] === '-C') {
|
|
135
|
+
const p = byPath(args[1]);
|
|
136
|
+
if (!p)
|
|
137
|
+
return null;
|
|
138
|
+
const rest = args.slice(2).filter((a) => a !== '--no-optional-locks');
|
|
139
|
+
if (same(rest, ['remote', 'get-url', 'origin']))
|
|
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));
|
|
151
|
+
if (same(rest, ['status', '--porcelain=v1', '--branch']))
|
|
152
|
+
return ok(statusText(p));
|
|
153
|
+
if (rest.length === 3 && rest[0] === 'log' && /^-\d+$/.test(rest[1]) && rest[2] === LOG_FORMAT)
|
|
154
|
+
return ok(logText(p, Number(rest[1].slice(1)), now));
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
// Nouveau projet (actions/newProject.ts), dans son dossier.
|
|
158
|
+
if (same(args, ['init', '-b', 'main']) || same(args, ['add', '.']) || (args.length === 3 && args[0] === 'commit' && args[1] === '-m'))
|
|
159
|
+
return ok();
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
// ---- gh ----
|
|
163
|
+
function graphql(rest, now) {
|
|
164
|
+
const vars = {};
|
|
165
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
166
|
+
const kv = rest[i + 1];
|
|
167
|
+
if ((rest[i] !== '-f' && rest[i] !== '-F') || kv === undefined || !kv.includes('='))
|
|
168
|
+
return null;
|
|
169
|
+
vars[kv.slice(0, kv.indexOf('='))] = kv.slice(kv.indexOf('=') + 1);
|
|
170
|
+
}
|
|
171
|
+
const q = vars.query ?? '';
|
|
172
|
+
const data = (d) => json({ data: d });
|
|
173
|
+
// Dépôts du compte (github/repos.ts).
|
|
174
|
+
if (q.includes('repositoryOwner(')) {
|
|
175
|
+
if (vars.owner?.toLowerCase() !== DEMO_OWNER)
|
|
176
|
+
return data({ repositoryOwner: null });
|
|
177
|
+
const pr = (n = 0) => ({ totalCount: n });
|
|
178
|
+
const nodes = [
|
|
179
|
+
...DEMO_PROJECTS.filter((p) => p.github).map((p) => ({ name: p.name, isPrivate: !!p.isPrivate, isFork: false, isArchived: false, pushedAt: daysAgoIso(now, p.commits[0][0]), pullRequests: pr(p.openPrs) })),
|
|
180
|
+
...DEMO_REMOTE_ONLY.map((r) => ({ name: r.name, isPrivate: r.isPrivate, isFork: r.isFork, isArchived: r.isArchived, pushedAt: daysAgoIso(now, r.pushedDaysAgo), pullRequests: pr() })),
|
|
181
|
+
]
|
|
182
|
+
.map((n) => ({ ...n, url: `https://github.com/${DEMO_OWNER}/${n.name}` }))
|
|
183
|
+
.sort((a, b) => Date.parse(b.pushedAt) - Date.parse(a.pushedAt));
|
|
184
|
+
return data({ repositoryOwner: { repositories: { nodes } } });
|
|
185
|
+
}
|
|
186
|
+
const p = bySlug(`${vars.owner}/${vars.name}`);
|
|
187
|
+
// Tickets du jalon courant (github/project.ts, SPRINT_QUERY).
|
|
188
|
+
if (q.includes('milestone(number:')) {
|
|
189
|
+
if (!p)
|
|
190
|
+
return data({ repository: null });
|
|
191
|
+
const ok1 = p.sprint && vars.number === '1';
|
|
192
|
+
return data({ repository: { milestone: ok1 ? { issues: { nodes: issuesOf(p).filter((i) => i.kind === 'sprint').map((i) => rawIssue(p, i)) } } : null } });
|
|
193
|
+
}
|
|
194
|
+
// Détail d'un projet (github/project.ts, QUERY).
|
|
195
|
+
if (q.includes('milestones(states: OPEN')) {
|
|
196
|
+
if (!p)
|
|
197
|
+
return data({ repository: null });
|
|
198
|
+
const issues = issuesOf(p);
|
|
199
|
+
const journal = issues.find((i) => i.kind === 'journal');
|
|
200
|
+
const m = p.sprint ? milestone(p, now) : null;
|
|
201
|
+
return data({
|
|
202
|
+
repository: {
|
|
203
|
+
milestones: { nodes: m ? [{ ...m, open: { totalCount: m.open }, closed: { totalCount: m.closed } }] : [] },
|
|
204
|
+
ideas: { nodes: issues.filter((i) => i.kind === 'idea').map((i) => rawIssue(p, i)) },
|
|
205
|
+
bugs: { totalCount: p.bugs ?? 0 },
|
|
206
|
+
pullRequests: { totalCount: p.openPrs ?? 0, nodes: demoPrs(p, now) },
|
|
207
|
+
journal: {
|
|
208
|
+
nodes: journal
|
|
209
|
+
? [{ number: journal.number, url: issueUrl(p, journal.number), comments: { nodes: journalComments(p, journal.number, now) } }]
|
|
210
|
+
: [],
|
|
211
|
+
},
|
|
212
|
+
label: p.journal ? { name: 'journal' } : null,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
// Épinglage du journal (github/write.ts).
|
|
217
|
+
if (q.includes('pinIssue('))
|
|
218
|
+
return data({ pinIssue: { issue: { number: 1 } } });
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
function gh(args, now) {
|
|
222
|
+
if (same(args, ['--version']))
|
|
223
|
+
return ok('gh version 2.63.0\n');
|
|
224
|
+
if (same(args, ['auth', 'status']))
|
|
225
|
+
return ok(`github.com\n Logged in to github.com account ${DEMO_OWNER}\n`);
|
|
226
|
+
if (same(args, ['api', 'user', '-q', '.login']))
|
|
227
|
+
return ok(`${DEMO_OWNER}\n`);
|
|
228
|
+
if (args[0] === 'api' && args[1] === 'graphql')
|
|
229
|
+
return graphql(args.slice(2), now);
|
|
230
|
+
// Jalons en REST (github/write.ts) : liste des ouverts, ou création.
|
|
231
|
+
if (args[0] === 'api') {
|
|
232
|
+
const m = /^repos\/([^/]+\/[^/?]+)\/milestones(\?state=open&per_page=50)?$/.exec(args[1] ?? '');
|
|
233
|
+
const p = bySlug(m?.[1]);
|
|
234
|
+
if (!m || !p)
|
|
235
|
+
return null;
|
|
236
|
+
const raw = (x) => ({ number: x.number, title: x.title, due_on: x.dueOn, created_at: x.createdAt, open_issues: x.open, closed_issues: x.closed });
|
|
237
|
+
if (m[2])
|
|
238
|
+
return args.length === 2 ? json(p.sprint ? [raw(milestone(p, now))] : []) : null;
|
|
239
|
+
const title = args.slice(2).find((a) => a.startsWith('title='))?.slice('title='.length);
|
|
240
|
+
if (!title)
|
|
241
|
+
return null;
|
|
242
|
+
const due = args.slice(2).find((a) => a.startsWith('due_on='))?.slice('due_on='.length) ?? null;
|
|
243
|
+
return json({ number: p.sprint ? 2 : 1, title, due_on: due, created_at: now.toISOString(), open_issues: 0, closed_issues: 0 });
|
|
244
|
+
}
|
|
245
|
+
if (args[0] === 'label') {
|
|
246
|
+
const p = bySlug(flag(args, '-R'));
|
|
247
|
+
if (!p)
|
|
248
|
+
return null;
|
|
249
|
+
if (args[1] === 'list')
|
|
250
|
+
return json(labelsOf(p).map((name) => ({ name })));
|
|
251
|
+
if (args[1] === 'create')
|
|
252
|
+
return ok();
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
if (args[0] === 'issue') {
|
|
256
|
+
const p = bySlug(flag(args, '-R'));
|
|
257
|
+
if (!p)
|
|
258
|
+
return null;
|
|
259
|
+
const issues = issuesOf(p);
|
|
260
|
+
if (args[1] === 'create')
|
|
261
|
+
return ok(`${issueUrl(p, issues.length + 1)}\n`);
|
|
262
|
+
if (args[1] === 'edit')
|
|
263
|
+
return ok();
|
|
264
|
+
if (args[1] === 'list' && flag(args, '--label') === 'journal') {
|
|
265
|
+
const j = issues.find((i) => i.kind === 'journal');
|
|
266
|
+
return json(j ? [{ number: j.number, url: issueUrl(p, j.number) }] : []);
|
|
267
|
+
}
|
|
268
|
+
if (args[1] === 'view') {
|
|
269
|
+
const n = Number(args[2]);
|
|
270
|
+
const field = flag(args, '--json');
|
|
271
|
+
if (field === 'id')
|
|
272
|
+
return json({ id: `I_demo_${n}` });
|
|
273
|
+
if (field === 'labels')
|
|
274
|
+
return json({ labels: (issues.find((i) => i.number === n)?.labels ?? []).map((name) => ({ name })) });
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
if (args[0] === 'repo') {
|
|
279
|
+
// Existence d'un dépôt avant création (actions/newProject.ts).
|
|
280
|
+
if (args[1] === 'view') {
|
|
281
|
+
const [owner, name] = (args[2] ?? '').split('/');
|
|
282
|
+
const known = owner?.toLowerCase() === DEMO_OWNER && [...DEMO_PROJECTS.filter((p) => p.github), ...DEMO_REMOTE_ONLY].some((r) => r.name === name);
|
|
283
|
+
return known ? json({ name }) : fail(`GraphQL: Could not resolve to a Repository with the name '${args[2]}'.`);
|
|
284
|
+
}
|
|
285
|
+
if (args[1] === 'clone' || args[1] === 'create')
|
|
286
|
+
return ok();
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
function answer(cmd, args, now) {
|
|
292
|
+
switch (cmd) {
|
|
293
|
+
case 'git':
|
|
294
|
+
return git(args, now);
|
|
295
|
+
case 'gh':
|
|
296
|
+
return gh(args, now);
|
|
297
|
+
// Détection des outils (setup/tools.ts) : `claude --version`, ou `where claude` sous Windows.
|
|
298
|
+
case 'claude':
|
|
299
|
+
return same(args, ['--version']) ? ok('1.0.0 (demo)\n') : null;
|
|
300
|
+
case 'where':
|
|
301
|
+
return same(args, ['claude']) ? ok('claude.cmd\n') : null;
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
export function demoRun(now) {
|
|
306
|
+
const misses = [];
|
|
307
|
+
const run = async (cmd, args) => {
|
|
308
|
+
const out = answer(cmd, args, now());
|
|
309
|
+
if (out)
|
|
310
|
+
return out;
|
|
311
|
+
misses.push([cmd, ...args].join(' '));
|
|
312
|
+
return fail(`Demo mode: no answer for "${cmd}"`);
|
|
313
|
+
};
|
|
314
|
+
return Object.assign(run, { misses });
|
|
315
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { projectId } from '../projects/scan.js';
|
|
2
|
+
import { DEMO_OWNER, DEMO_PROJECTS, demoPath } from './data.js';
|
|
3
|
+
export async function demoScan() {
|
|
4
|
+
return DEMO_PROJECTS.map((p) => {
|
|
5
|
+
const path = demoPath(p.name);
|
|
6
|
+
return { id: projectId(path), name: p.name, path, repo: p.github ? { owner: DEMO_OWNER, name: p.name } : null, duplicates: [] };
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Remplace `listSkills` : les skills fictifs du projet, puis ceux de la config (skills de plugin, sans fichier à lire).
|
|
11
|
+
* Un skill de config sans « : » (dossier global) n'est pas lu : la démo ne touche pas au disque.
|
|
12
|
+
*/
|
|
13
|
+
export async function demoSkills(projectPath, cfg) {
|
|
14
|
+
const own = DEMO_PROJECTS.find((p) => demoPath(p.name) === projectPath)?.skills ?? [];
|
|
15
|
+
const out = own.map((s) => ({ ...s, scope: 'projet' }));
|
|
16
|
+
for (const name of Object.values(cfg.skills)) {
|
|
17
|
+
if (name.includes(':') && !out.some((s) => s.name === name))
|
|
18
|
+
out.push({ name, description: '', scope: 'plugin' });
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { tierOf } from '../../shared/tiers.js';
|
|
2
|
+
const MAX_DETAILS = 8;
|
|
3
|
+
const isHot = (p) => p.tier === 'actif' || p.tier === 'recent';
|
|
4
|
+
export function toHomeProjects(projects, now) {
|
|
5
|
+
const home = projects.map((p) => {
|
|
6
|
+
const git = 'error' in p.git ? null : p.git;
|
|
7
|
+
const lastActivity = git?.lastCommit?.date ?? null;
|
|
8
|
+
return {
|
|
9
|
+
id: p.id,
|
|
10
|
+
name: p.name,
|
|
11
|
+
tier: tierOf(lastActivity, now),
|
|
12
|
+
lastActivity,
|
|
13
|
+
branch: git?.branch ?? null,
|
|
14
|
+
dirty: git ? git.modified + git.untracked : 0,
|
|
15
|
+
lastSubject: git?.lastCommit?.subject ?? null,
|
|
16
|
+
openPrs: 0,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
return home.sort((a, b) => {
|
|
20
|
+
if (a.lastActivity === b.lastActivity)
|
|
21
|
+
return 0;
|
|
22
|
+
if (a.lastActivity === null)
|
|
23
|
+
return 1;
|
|
24
|
+
if (b.lastActivity === null)
|
|
25
|
+
return -1;
|
|
26
|
+
return Date.parse(b.lastActivity) - Date.parse(a.lastActivity);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function detailTargets(home, hasRepo) {
|
|
30
|
+
const hot = home.filter(p => isHot(p) && hasRepo(p.id)).slice(0, MAX_DETAILS).map(p => p.id);
|
|
31
|
+
if (hot.length > 0)
|
|
32
|
+
return hot;
|
|
33
|
+
const first = home.find(p => hasRepo(p.id));
|
|
34
|
+
return first ? [first.id] : [];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* PR ouvertes de chaque projet, tirées de la même carte que les badges de la barre latérale
|
|
38
|
+
* (dépôts de config.owner, hors forks et archivés). Absent de la carte, ou carte en échec : 0,
|
|
39
|
+
* sans repli sur le détail, pour que l'accueil ne contredise jamais les badges.
|
|
40
|
+
*/
|
|
41
|
+
export function applyPrs(home, repoKey, remotePrs) {
|
|
42
|
+
return home.map(p => {
|
|
43
|
+
const key = repoKey(p.id);
|
|
44
|
+
return { ...p, openPrs: (key !== null && remotePrs?.get(key)) || 0 };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function pickResume(home, details) {
|
|
48
|
+
for (const p of home) {
|
|
49
|
+
const detail = details.get(p.id);
|
|
50
|
+
if (!detail)
|
|
51
|
+
continue;
|
|
52
|
+
const last = detail.journal?.sessions[0] ?? null;
|
|
53
|
+
return { projectId: p.id, name: p.name, fait: last?.fait ?? null, prochaine: last?.prochaine ?? null, lastSubject: p.lastSubject, hasJournal: last != null };
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
export function buildDeadlines(home, details) {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const p of home) {
|
|
60
|
+
if (!isHot(p))
|
|
61
|
+
continue;
|
|
62
|
+
const sprint = details.get(p.id)?.sprint;
|
|
63
|
+
if (!sprint)
|
|
64
|
+
continue;
|
|
65
|
+
out.push({ projectId: p.id, name: p.name, title: sprint.title, dueOn: sprint.dueOn, closed: sprint.closed, total: sprint.open + sprint.closed });
|
|
66
|
+
}
|
|
67
|
+
return out.sort((a, b) => {
|
|
68
|
+
if (a.dueOn !== b.dueOn) {
|
|
69
|
+
if (a.dueOn === null)
|
|
70
|
+
return 1;
|
|
71
|
+
if (b.dueOn === null)
|
|
72
|
+
return -1;
|
|
73
|
+
return a.dueOn < b.dueOn ? -1 : 1;
|
|
74
|
+
}
|
|
75
|
+
return a.name.localeCompare(b.name);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export function buildTodo(home, details) {
|
|
79
|
+
const todo = (p, kind, count) => ({ projectId: p.id, name: p.name, kind, count });
|
|
80
|
+
return [
|
|
81
|
+
...home.filter(p => isHot(p) && p.openPrs > 0).map(p => todo(p, 'prs', p.openPrs)),
|
|
82
|
+
...home.filter(p => p.dirty > 0).map(p => todo(p, 'dirty', p.dirty)),
|
|
83
|
+
...home.filter(p => p.tier === 'actif' && details.get(p.id)?.journal === null).map(p => todo(p, 'journal', 1)),
|
|
84
|
+
];
|
|
85
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function field(body, label) {
|
|
2
|
+
const re = new RegExp(String.raw `\*\*(?:${label})\s*:\*\*[ \t]*([\s\S]*?)(?=\n\s*\*\*[^*\n]+:\*\*|$)`, 'i');
|
|
3
|
+
return body.match(re)?.[1].trim() ?? '';
|
|
4
|
+
}
|
|
5
|
+
/** Lit un commentaire de session ; hors format → texte brut dans `fait`. */
|
|
6
|
+
export function parseJournalComment(body, url, createdAt) {
|
|
7
|
+
const text = body.replace(/\r\n/g, '\n');
|
|
8
|
+
const date = text.match(/^##\s*Session(?: du)? (\d{4}-\d{2}-\d{2})/m)?.[1] ?? '';
|
|
9
|
+
const fait = field(text, 'Fait|Done');
|
|
10
|
+
const reste = field(text, 'Reste|Left');
|
|
11
|
+
const prochaine = field(text, 'Prochaine étape|Next');
|
|
12
|
+
if (!date && !fait && !reste && !prochaine)
|
|
13
|
+
return { date: '', fait: text.trim(), reste: '', prochaine: '', url, createdAt };
|
|
14
|
+
return { date, fait, reste, prochaine, url, createdAt };
|
|
15
|
+
}
|
|
16
|
+
const TEMPLATES = {
|
|
17
|
+
fr: `Journal des sessions de travail. Chaque session ajoute un commentaire de ce format :
|
|
18
|
+
|
|
19
|
+
## Session du AAAA-MM-JJ
|
|
20
|
+
**Fait :** ce qui a été fait
|
|
21
|
+
**Reste :** ce qui reste à faire
|
|
22
|
+
**Prochaine étape :** par où reprendre
|
|
23
|
+
`,
|
|
24
|
+
en: `Work session log. Each session adds a comment in this format:
|
|
25
|
+
|
|
26
|
+
## Session YYYY-MM-DD
|
|
27
|
+
**Done:** what was done
|
|
28
|
+
**Left:** what remains
|
|
29
|
+
**Next:** where to pick up
|
|
30
|
+
`,
|
|
31
|
+
};
|
|
32
|
+
/** Corps de l'issue journal, décrivant le format de commentaire de la langue. */
|
|
33
|
+
export const journalTemplate = (lang) => TEMPLATES[lang];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Jalon courant : échéance la plus proche ; sinon le plus récemment créé. */
|
|
2
|
+
export function pickCurrentSprint(milestones) {
|
|
3
|
+
if (milestones.length === 0)
|
|
4
|
+
return null;
|
|
5
|
+
const dated = milestones.filter((m) => m.dueOn);
|
|
6
|
+
if (dated.length > 0)
|
|
7
|
+
return [...dated].sort((a, b) => Date.parse(a.dueOn) - Date.parse(b.dueOn))[0];
|
|
8
|
+
return [...milestones].sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))[0];
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
export const run = (cmd, args, opts = {}) => new Promise((resolve) => {
|
|
3
|
+
const child = execFile(cmd, args, { cwd: opts.cwd, windowsHide: true, maxBuffer: 20 * 1024 * 1024, encoding: 'utf8' }, (err, stdout, stderr) => {
|
|
4
|
+
if (!err)
|
|
5
|
+
return resolve({ stdout, stderr, code: 0 });
|
|
6
|
+
const e = err;
|
|
7
|
+
const code = typeof e.code === 'number' ? e.code : 1;
|
|
8
|
+
resolve({ stdout: stdout ?? '', stderr: stderr || e.message, code });
|
|
9
|
+
});
|
|
10
|
+
if (opts.input !== undefined)
|
|
11
|
+
child.stdin?.end(opts.input);
|
|
12
|
+
});
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Champs d'un outil qui portent un chemin. */
|
|
2
|
+
const PATH_KEYS = ['file_path', 'path', 'notebook_path', 'cwd'];
|
|
3
|
+
/** Outils dont un texte peut citer des chemins, et les champs de ce texte. */
|
|
4
|
+
const TEXT_KEYS = {
|
|
5
|
+
Bash: ['command'], PowerShell: ['command'], Agent: ['prompt'], Task: ['prompt'], SendMessage: ['message', 'content', 'prompt'],
|
|
6
|
+
};
|
|
7
|
+
/** Texte lu au plus, et chemins retenus au plus, par outil. */
|
|
8
|
+
const TEXT_CHARS = 16_384;
|
|
9
|
+
const TOKENS_MAX = 40;
|
|
10
|
+
/** Chemin absolu entre guillemets : il peut contenir des espaces. */
|
|
11
|
+
const QUOTED = /(["'`])((?:[A-Za-z]:[\\/]|\/)[^"'`\r\n]*)\1/g;
|
|
12
|
+
/** Chemin absolu nu : `C:\…`, `C:/…` (aussi dans `--out=C:/…` et `file:///C:/…`) ou `/…` (ni une URL, ni un chemin relatif). */
|
|
13
|
+
const BARE = /(?<![A-Za-z0-9])[A-Za-z]:[\\/][^\s"'`|<>;&(),]*|(?<![\w.~:/\\$}*-])\/(?:\\ |[^\s"'`|<>;&(),\\])+/g;
|
|
14
|
+
/** Ponctuation finale d'une phrase ou d'un Markdown : retirée par la fin, en temps linéaire (une regex `…+$` serait quadratique). */
|
|
15
|
+
function trimEnd(token) {
|
|
16
|
+
let end = token.length;
|
|
17
|
+
while (end > 0 && '.,:!?*]}'.includes(token[end - 1]))
|
|
18
|
+
end--;
|
|
19
|
+
return token.slice(0, end);
|
|
20
|
+
}
|
|
21
|
+
/** Chemins absolus cités dans une commande ou une consigne, sans doublon. */
|
|
22
|
+
export function pathTokens(text) {
|
|
23
|
+
const out = new Set();
|
|
24
|
+
const rest = text.slice(0, TEXT_CHARS).replace(QUOTED, (_all, _quote, path) => {
|
|
25
|
+
out.add(path);
|
|
26
|
+
return ' ';
|
|
27
|
+
});
|
|
28
|
+
for (const [token] of rest.matchAll(BARE))
|
|
29
|
+
out.add(trimEnd(token.replace(/\\ /g, ' ')));
|
|
30
|
+
return [...out].slice(0, TOKENS_MAX);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Chemins qu'un tool_use désigne : ses champs de chemin, et les chemins absolus de sa commande ou de sa consigne.
|
|
34
|
+
* Ils servent seulement à trouver le projet d'un agent : ils ne quittent jamais le serveur.
|
|
35
|
+
*/
|
|
36
|
+
export function evidenceOf(name, input) {
|
|
37
|
+
const strings = (keys) => keys.map((k) => input[k]).filter((v) => typeof v === 'string' && v !== '');
|
|
38
|
+
return [...strings(PATH_KEYS), ...strings(Object.hasOwn(TEXT_KEYS, name) ? TEXT_KEYS[name] : []).flatMap(pathTokens)];
|
|
39
|
+
}
|