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
|
+
function parseHeader(line) {
|
|
2
|
+
const h = line.replace(/^##\s*/, '');
|
|
3
|
+
const empty = /^No commits yet on (.+)$/.exec(h);
|
|
4
|
+
if (empty)
|
|
5
|
+
return { branch: empty[1].split('...')[0], ahead: null };
|
|
6
|
+
const m = /^(.+?)(?:\.\.\.(\S+))?(?: \[(.*)\])?$/.exec(h);
|
|
7
|
+
if (!m)
|
|
8
|
+
return { branch: h, ahead: null };
|
|
9
|
+
const [, branch, upstream, info] = m;
|
|
10
|
+
if (!upstream)
|
|
11
|
+
return { branch, ahead: null };
|
|
12
|
+
if (info?.includes('gone'))
|
|
13
|
+
return { branch, ahead: null };
|
|
14
|
+
const a = /ahead (\d+)/.exec(info ?? '');
|
|
15
|
+
return { branch, ahead: a ? Number(a[1]) : 0 };
|
|
16
|
+
}
|
|
17
|
+
export async function gitStatus(path, run) {
|
|
18
|
+
const [st, log] = await Promise.all([
|
|
19
|
+
run('git', ['-C', path, 'status', '--porcelain=v1', '--branch']),
|
|
20
|
+
run('git', ['-C', path, 'log', '-1', '--format=%h%x1f%cI%x1f%s']),
|
|
21
|
+
]);
|
|
22
|
+
if (st.code !== 0)
|
|
23
|
+
throw new Error(st.stderr.trim() || 'git status failed');
|
|
24
|
+
let branch = '';
|
|
25
|
+
let ahead = null;
|
|
26
|
+
let modified = 0;
|
|
27
|
+
let untracked = 0;
|
|
28
|
+
for (const line of st.stdout.split(/\r?\n/)) {
|
|
29
|
+
if (!line)
|
|
30
|
+
continue;
|
|
31
|
+
if (line.startsWith('##'))
|
|
32
|
+
({ branch, ahead } = parseHeader(line));
|
|
33
|
+
else if (line.startsWith('??'))
|
|
34
|
+
untracked++;
|
|
35
|
+
else if (!line.startsWith('!!'))
|
|
36
|
+
modified++;
|
|
37
|
+
}
|
|
38
|
+
let lastCommit = null;
|
|
39
|
+
if (log.code === 0) {
|
|
40
|
+
const [hash, date, subject] = log.stdout.replace(/\r?\n$/, '').split('\x1f');
|
|
41
|
+
if (hash && date)
|
|
42
|
+
lastCommit = { hash, date, subject: subject ?? '' };
|
|
43
|
+
}
|
|
44
|
+
return { branch, modified, untracked, ahead, lastCommit };
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class GhError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(message, code) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = 'GhError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Requête GraphQL via `gh` : le jeton ne quitte jamais gh. */
|
|
10
|
+
export async function ghGraphql(run, query, vars) {
|
|
11
|
+
const args = ['api', 'graphql', '-f', `query=${query}`];
|
|
12
|
+
for (const [k, v] of Object.entries(vars))
|
|
13
|
+
args.push(typeof v === 'number' ? '-F' : '-f', `${k}=${v}`);
|
|
14
|
+
const r = await run('gh', args);
|
|
15
|
+
if (r.code !== 0)
|
|
16
|
+
throw new GhError(r.stderr.trim() || `gh failed (code ${r.code})`, r.code);
|
|
17
|
+
const body = JSON.parse(r.stdout);
|
|
18
|
+
if (body.errors?.length && !body.data)
|
|
19
|
+
throw new GhError(body.errors.map((e) => e.message).join('; '), 0);
|
|
20
|
+
return body.data;
|
|
21
|
+
}
|
|
22
|
+
export async function ghJson(run, args) {
|
|
23
|
+
const r = await run('gh', args);
|
|
24
|
+
if (r.code !== 0)
|
|
25
|
+
throw new GhError(r.stderr.trim() || `gh failed (code ${r.code})`, r.code);
|
|
26
|
+
return JSON.parse(r.stdout);
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { LABEL_SETS, detectLabelSet } from '../../shared/labels.js';
|
|
2
|
+
import { cached, forgetCached } from '../cache.js';
|
|
3
|
+
import { GhError } from './gh.js';
|
|
4
|
+
/** Même limite pour détecter le jeu et pour lister avant création : les deux voient les mêmes labels. */
|
|
5
|
+
export const LABEL_LIST_LIMIT = 1000;
|
|
6
|
+
export const THEME_COLOR = '64748b';
|
|
7
|
+
const slug = (r) => `${r.owner}/${r.name}`;
|
|
8
|
+
const setKey = (r) => `labelset:${slug(r)}`.toLowerCase();
|
|
9
|
+
const DESCRIPTIONS = {
|
|
10
|
+
fr: { idea: 'Idée à trier', bug: 'Quelque chose ne marche pas', effort: ['Effort : petit', 'Effort : moyen', 'Effort : gros'], impact: ['Impact fort', 'Impact moyen', 'Impact faible'], journal: 'Journal des sessions', theme: 'Thème' },
|
|
11
|
+
en: { idea: 'Idea to triage', bug: "Something isn't working", effort: ['Effort: small', 'Effort: medium', 'Effort: large'], impact: ['High impact', 'Medium impact', 'Low impact'], journal: 'Session log', theme: 'Theme' },
|
|
12
|
+
};
|
|
13
|
+
export function standardLabels(set) {
|
|
14
|
+
const d = DESCRIPTIONS[set.lang];
|
|
15
|
+
return [
|
|
16
|
+
{ name: set.idea, color: 'a78bfa', description: d.idea },
|
|
17
|
+
{ name: 'bug', color: 'd73a4a', description: d.bug },
|
|
18
|
+
{ name: 'effort:S', color: '22c55e', description: d.effort[0] },
|
|
19
|
+
{ name: 'effort:M', color: 'eab308', description: d.effort[1] },
|
|
20
|
+
{ name: 'effort:L', color: 'ef4444', description: d.effort[2] },
|
|
21
|
+
{ name: set.impact.high, color: '7c3aed', description: d.impact[0] },
|
|
22
|
+
{ name: set.impact.medium, color: 'a855f7', description: d.impact[1] },
|
|
23
|
+
{ name: set.impact.low, color: 'c4b5fd', description: d.impact[2] },
|
|
24
|
+
{ name: 'journal', color: '0ea5e9', description: d.journal },
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function defFor(set, name) {
|
|
28
|
+
const std = standardLabels(set).find((l) => l.name === name);
|
|
29
|
+
if (std)
|
|
30
|
+
return std;
|
|
31
|
+
if (name.startsWith(set.themePrefix))
|
|
32
|
+
return { name, color: THEME_COLOR, description: DESCRIPTIONS[set.lang].theme };
|
|
33
|
+
return { name, color: THEME_COLOR, description: '' };
|
|
34
|
+
}
|
|
35
|
+
async function listLabelNames(run, repo) {
|
|
36
|
+
const list = await run('gh', ['label', 'list', '-R', slug(repo), '--json', 'name', '--limit', String(LABEL_LIST_LIMIT)]);
|
|
37
|
+
if (list.code !== 0)
|
|
38
|
+
throw new GhError(list.stderr.trim() || 'gh label list failed', list.code);
|
|
39
|
+
return JSON.parse(list.stdout).map((l) => l.name);
|
|
40
|
+
}
|
|
41
|
+
/** Jeu de labels du dépôt (français prioritaire si les deux), sinon `fallback`. Mis en cache 60 s. */
|
|
42
|
+
export function repoLabelSet(run, repo, fallback) {
|
|
43
|
+
return cached(setKey(repo), 60_000, () => new Date(), async () => LABEL_SETS[detectLabelSet(await listLabelNames(run, repo)) ?? fallback]);
|
|
44
|
+
}
|
|
45
|
+
/** Crée les labels manquants ; ne modifie ni ne supprime jamais un label existant. */
|
|
46
|
+
export async function ensureLabels(run, repo, set, names) {
|
|
47
|
+
const existing = new Set((await listLabelNames(run, repo)).map((n) => n.toLowerCase()));
|
|
48
|
+
let created = false;
|
|
49
|
+
try {
|
|
50
|
+
for (const name of [...new Set(names)]) {
|
|
51
|
+
if (existing.has(name.toLowerCase()))
|
|
52
|
+
continue;
|
|
53
|
+
const d = defFor(set, name);
|
|
54
|
+
const r = await run('gh', ['label', 'create', d.name, '-R', slug(repo), '--color', d.color, '--description', d.description]);
|
|
55
|
+
if (r.code !== 0)
|
|
56
|
+
throw new GhError(r.stderr.trim() || `creating label ${name} failed`, r.code);
|
|
57
|
+
created = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
// Le dépôt a maintenant des labels : le jeu détecté avant (ou son repli) n'est plus valable.
|
|
62
|
+
if (created)
|
|
63
|
+
forgetCached(setKey(repo));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { classifyIdea } from '../../shared/ideas.js';
|
|
2
|
+
import { pickCurrentSprint } from '../domain/sprint.js';
|
|
3
|
+
import { parseJournalComment } from '../domain/journal.js';
|
|
4
|
+
import { ghGraphql } from './gh.js';
|
|
5
|
+
const ISSUE = 'number title url state labels(first: 20) { nodes { name } } milestone { number }';
|
|
6
|
+
const QUERY = `query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) {
|
|
7
|
+
milestones(states: OPEN, first: 20) { nodes { number title dueOn createdAt open: issues(states: OPEN) { totalCount } closed: issues(states: CLOSED) { totalCount } } }
|
|
8
|
+
ideas: issues(states: OPEN, labels: ["idée", "idea"], first: 100) { nodes { ${ISSUE} } }
|
|
9
|
+
bugs: issues(states: OPEN, labels: ["bug"]) { totalCount }
|
|
10
|
+
pullRequests(states: OPEN, first: 5, orderBy: {field: CREATED_AT, direction: DESC}) { totalCount nodes { number title url isDraft author { login } } }
|
|
11
|
+
journal: issues(states: OPEN, labels: ["journal"], first: 1) { nodes { number url comments(last: 3) { nodes { body url createdAt } } } }
|
|
12
|
+
label(name: "journal") { name }
|
|
13
|
+
} }`;
|
|
14
|
+
const SPRINT_QUERY = `query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) {
|
|
15
|
+
milestone(number: $number) { issues(first: 50, orderBy: {field: CREATED_AT, direction: ASC}) { nodes { ${ISSUE} } } }
|
|
16
|
+
} }`;
|
|
17
|
+
const toIssue = (n) => ({
|
|
18
|
+
number: n.number,
|
|
19
|
+
title: n.title,
|
|
20
|
+
url: n.url,
|
|
21
|
+
state: n.state,
|
|
22
|
+
labels: n.labels.nodes.map((l) => l.name),
|
|
23
|
+
milestone: n.milestone?.number ?? null,
|
|
24
|
+
});
|
|
25
|
+
export async function fetchProjectDetail(run, repo) {
|
|
26
|
+
const vars = { owner: repo.owner, name: repo.name };
|
|
27
|
+
const data = await ghGraphql(run, QUERY, vars);
|
|
28
|
+
const r = data.repository;
|
|
29
|
+
if (!r)
|
|
30
|
+
return { sprint: null, ideas: [], openBugs: 0, openPrs: 0, prs: [], journal: null, hasConvention: false };
|
|
31
|
+
const milestones = r.milestones.nodes.map((m) => ({
|
|
32
|
+
number: m.number,
|
|
33
|
+
title: m.title,
|
|
34
|
+
dueOn: m.dueOn,
|
|
35
|
+
createdAt: m.createdAt,
|
|
36
|
+
open: m.open.totalCount,
|
|
37
|
+
closed: m.closed.totalCount,
|
|
38
|
+
}));
|
|
39
|
+
const picked = pickCurrentSprint(milestones);
|
|
40
|
+
let sprint = null;
|
|
41
|
+
if (picked) {
|
|
42
|
+
const s = await ghGraphql(run, SPRINT_QUERY, { ...vars, number: picked.number });
|
|
43
|
+
sprint = { ...picked, issues: (s.repository?.milestone?.issues.nodes ?? []).map(toIssue) };
|
|
44
|
+
}
|
|
45
|
+
const ideas = r.ideas.nodes.map((n) => classifyIdea(toIssue(n)));
|
|
46
|
+
const j = r.journal.nodes[0];
|
|
47
|
+
// GitHub renvoie les commentaires du plus ancien au plus récent : on inverse.
|
|
48
|
+
const sessions = (j?.comments.nodes ?? []).map((c) => parseJournalComment(c.body, c.url, c.createdAt)).reverse();
|
|
49
|
+
return {
|
|
50
|
+
sprint,
|
|
51
|
+
ideas,
|
|
52
|
+
openBugs: r.bugs.totalCount,
|
|
53
|
+
openPrs: r.pullRequests.totalCount,
|
|
54
|
+
prs: r.pullRequests.nodes.map((n) => ({ number: n.number, title: n.title, url: n.url, isDraft: n.isDraft, author: n.author?.login ?? null })),
|
|
55
|
+
journal: j ? { number: j.number, url: j.url, sessions } : null,
|
|
56
|
+
hasConvention: r.label !== null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ghGraphql } from './gh.js';
|
|
2
|
+
const QUERY = 'query($owner: String!) { repositoryOwner(login: $owner) { repositories(first: 100, orderBy: {field: PUSHED_AT, direction: DESC}) { nodes { name url isPrivate isFork isArchived pushedAt pullRequests(states: OPEN) { totalCount } } } } }';
|
|
3
|
+
export async function listRemoteRepos(run, owner) {
|
|
4
|
+
const data = await ghGraphql(run, QUERY, { owner });
|
|
5
|
+
const nodes = data.repositoryOwner?.repositories.nodes ?? [];
|
|
6
|
+
return nodes.map((n) => ({
|
|
7
|
+
owner,
|
|
8
|
+
name: n.name,
|
|
9
|
+
url: n.url,
|
|
10
|
+
isPrivate: n.isPrivate,
|
|
11
|
+
isFork: n.isFork,
|
|
12
|
+
isArchived: n.isArchived,
|
|
13
|
+
pushedAt: n.pushedAt,
|
|
14
|
+
openPrs: n.pullRequests.totalCount,
|
|
15
|
+
localPath: null,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { parseImpact } from '../../shared/labels.js';
|
|
2
|
+
import { journalTemplate } from '../domain/journal.js';
|
|
3
|
+
import { GhError, ghGraphql, ghJson } from './gh.js';
|
|
4
|
+
import { ensureLabels, standardLabels } from './labels.js';
|
|
5
|
+
const slug = (r) => `${r.owner}/${r.name}`;
|
|
6
|
+
const labelsOf = (set, l) => [
|
|
7
|
+
...(l.theme ? [`${set.themePrefix}${l.theme}`] : []),
|
|
8
|
+
...(l.effort ? [`effort:${l.effort}`] : []),
|
|
9
|
+
...(l.impact ? [set.impact[l.impact]] : []),
|
|
10
|
+
];
|
|
11
|
+
/** Préfixes de thème des deux jeux et tous les impacts : retirés à la réécriture pour ne jamais en laisser deux. */
|
|
12
|
+
const THEME_PREFIXES = ['thème:', 'theme:'];
|
|
13
|
+
const startsWithAny = (name, prefixes) => prefixes.some((p) => name.toLowerCase().startsWith(p));
|
|
14
|
+
async function gh(run, args) {
|
|
15
|
+
const r = await run('gh', args);
|
|
16
|
+
if (r.code !== 0)
|
|
17
|
+
throw new GhError(r.stderr.trim() || `gh failed (code ${r.code})`, r.code);
|
|
18
|
+
return r.stdout;
|
|
19
|
+
}
|
|
20
|
+
function parseIssueUrl(out) {
|
|
21
|
+
const url = out.trim().split(/\s+/).pop() ?? '';
|
|
22
|
+
const n = Number(url.match(/\/issues\/(\d+)$/)?.[1]);
|
|
23
|
+
if (!Number.isInteger(n))
|
|
24
|
+
throw new GhError(`Unexpected gh output: ${out.trim()}`, 0);
|
|
25
|
+
return { number: n, url };
|
|
26
|
+
}
|
|
27
|
+
export async function createIdea(run, repo, set, a) {
|
|
28
|
+
const labels = [set.idea, ...labelsOf(set, a)];
|
|
29
|
+
await ensureLabels(run, repo, set, labels);
|
|
30
|
+
const out = await gh(run, ['issue', 'create', '-R', slug(repo), '--title', a.title, '--body', '', '--label', labels.join(',')]);
|
|
31
|
+
const { number, url } = parseIssueUrl(out);
|
|
32
|
+
return { number, title: a.title, url, state: 'OPEN', labels, milestone: null };
|
|
33
|
+
}
|
|
34
|
+
export async function setIdeaLabels(run, repo, set, number, l) {
|
|
35
|
+
const add = labelsOf(set, l);
|
|
36
|
+
if (add.length === 0)
|
|
37
|
+
return;
|
|
38
|
+
await ensureLabels(run, repo, set, add);
|
|
39
|
+
const cur = await ghJson(run, ['issue', 'view', String(number), '-R', slug(repo), '--json', 'labels']);
|
|
40
|
+
const prefixes = [...(l.theme ? THEME_PREFIXES : []), ...(l.effort ? ['effort:'] : [])];
|
|
41
|
+
// Impact : seulement les six valeurs connues, jamais un `impact:*` libre de l'utilisateur.
|
|
42
|
+
const isOldImpact = (n) => !!l.impact && parseImpact(n) !== null;
|
|
43
|
+
const keep = new Set(add.map((n) => n.toLowerCase()));
|
|
44
|
+
const remove = cur.labels.map((x) => x.name).filter((n) => (startsWithAny(n, prefixes) || isOldImpact(n)) && !keep.has(n.toLowerCase()));
|
|
45
|
+
const args = ['issue', 'edit', String(number), '-R', slug(repo)];
|
|
46
|
+
for (const n of remove)
|
|
47
|
+
args.push('--remove-label', n);
|
|
48
|
+
for (const n of add)
|
|
49
|
+
args.push('--add-label', n);
|
|
50
|
+
await gh(run, args);
|
|
51
|
+
}
|
|
52
|
+
export async function addToSprint(run, repo, number, milestoneTitle) {
|
|
53
|
+
await gh(run, ['issue', 'edit', String(number), '-R', slug(repo), '--milestone', milestoneTitle]);
|
|
54
|
+
}
|
|
55
|
+
const toMilestone = (m) => ({ number: m.number, title: m.title, dueOn: m.due_on, createdAt: m.created_at, open: m.open_issues, closed: m.closed_issues });
|
|
56
|
+
export async function listOpenMilestones(run, repo) {
|
|
57
|
+
const raw = await ghJson(run, ['api', `repos/${slug(repo)}/milestones?state=open&per_page=50`]);
|
|
58
|
+
return raw.map(toMilestone);
|
|
59
|
+
}
|
|
60
|
+
export async function createSprint(run, repo, a) {
|
|
61
|
+
const args = ['api', `repos/${slug(repo)}/milestones`, '-f', `title=${a.title}`];
|
|
62
|
+
if (a.dueOn)
|
|
63
|
+
args.push('-f', `due_on=${a.dueOn}T23:59:59Z`);
|
|
64
|
+
return toMilestone(await ghJson(run, args));
|
|
65
|
+
}
|
|
66
|
+
export async function createJournal(run, repo, set) {
|
|
67
|
+
await ensureLabels(run, repo, set, ['journal']);
|
|
68
|
+
const out = await gh(run, ['issue', 'create', '-R', slug(repo), '--title', set.journalTitle, '--body', journalTemplate(set.lang), '--label', 'journal']);
|
|
69
|
+
const { number, url } = parseIssueUrl(out);
|
|
70
|
+
let pinned = false;
|
|
71
|
+
try {
|
|
72
|
+
const { id } = await ghJson(run, ['issue', 'view', String(number), '-R', slug(repo), '--json', 'id']);
|
|
73
|
+
await ghGraphql(run, 'mutation($id: ID!) { pinIssue(input: {issueId: $id}) { issue { number } } }', { id });
|
|
74
|
+
pinned = true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Épinglage impossible (ex. 3 tickets déjà épinglés) : le journal existe quand même.
|
|
78
|
+
}
|
|
79
|
+
return { number, url, pinned };
|
|
80
|
+
}
|
|
81
|
+
export async function findJournal(run, repo) {
|
|
82
|
+
const l = await ghJson(run, ['issue', 'list', '-R', slug(repo), '--label', 'journal', '--state', 'open', '--json', 'number,url', '--limit', '1']);
|
|
83
|
+
return l[0] ?? null;
|
|
84
|
+
}
|
|
85
|
+
export async function ensureConvention(run, repo, set) {
|
|
86
|
+
await ensureLabels(run, repo, set, standardLabels(set).map((l) => l.name));
|
|
87
|
+
if (await findJournal(run, repo))
|
|
88
|
+
return { journalCreated: false };
|
|
89
|
+
await createJournal(run, repo, set);
|
|
90
|
+
return { journalCreated: true };
|
|
91
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { errorBody } from '../shared/errors.js';
|
|
2
|
+
export function guard(config) {
|
|
3
|
+
const hosts = new Set([`localhost:${config.port}`, `127.0.0.1:${config.port}`]);
|
|
4
|
+
const origins = new Set(config.allowedOrigins);
|
|
5
|
+
return async (c, next) => {
|
|
6
|
+
const host = c.req.header('host');
|
|
7
|
+
if (!host || !hosts.has(host))
|
|
8
|
+
return c.json(errorBody('hostRefused'), 403);
|
|
9
|
+
if (c.req.method !== 'GET' && c.req.method !== 'HEAD') {
|
|
10
|
+
if (c.req.header('x-holohq') !== '1')
|
|
11
|
+
return c.json(errorBody('missingHeader'), 403);
|
|
12
|
+
const origin = c.req.header('origin');
|
|
13
|
+
if (!origin || !origins.has(origin))
|
|
14
|
+
return c.json(errorBody('originRefused'), 403);
|
|
15
|
+
}
|
|
16
|
+
await next();
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { log, startServer } from './start.js';
|
|
2
|
+
// Point d'entrée `npm start` / démarrage automatique : pas de navigateur.
|
|
3
|
+
try {
|
|
4
|
+
await startServer({ demo: false, open: false, port: null, lang: null, dev: process.argv.includes('--dev') });
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
log(`Startup failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { lstatSync } from 'node:fs';
|
|
2
|
+
import { posix, win32 } from 'node:path';
|
|
3
|
+
import { errorBody } from '../shared/errors.js';
|
|
4
|
+
import { SKILL_NAME } from './skills.js';
|
|
5
|
+
const CONTROL = /[\0-\x1f\x7f]/;
|
|
6
|
+
/** Caractères que cmd.exe interprète même dans un argument (`&`, `|`, redirections, `^`, `%VAR%`, `!VAR!`, guillemet). */
|
|
7
|
+
const CMD_META = /[&|<>^%!"]/;
|
|
8
|
+
/** Refus communs à tous les lancements : un chemin pris pour une option, ou contenant un caractère de contrôle. */
|
|
9
|
+
function checkPath(path) {
|
|
10
|
+
if (path.startsWith('-'))
|
|
11
|
+
return errorBody('pathRefused');
|
|
12
|
+
if (CONTROL.test(path))
|
|
13
|
+
return errorBody('pathControlChar');
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function checkCmdPath(path) {
|
|
17
|
+
return CMD_META.test(path) ? errorBody('pathCmdMeta') : null;
|
|
18
|
+
}
|
|
19
|
+
/** UUID strict d'une conversation Claude Code : jamais pris pour une option, ni un chemin. */
|
|
20
|
+
export const SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21
|
+
/** Caractères refusés dans une consigne : métacaractères de cmd.exe, `;` (séparateur de Windows Terminal), `\`, retours à la ligne. */
|
|
22
|
+
const PROMPT_META = /[&|<>^%!";\\\r\n]/;
|
|
23
|
+
/** Lance `claude` dans un nouveau terminal, dans le dossier du projet. Arguments séparés, jamais de chaîne shell (sauf l'AppleScript, échappé). */
|
|
24
|
+
export function claudeLaunch(projectPath, what, ctx) {
|
|
25
|
+
let claudeArgs;
|
|
26
|
+
if ('skill' in what) {
|
|
27
|
+
if (!SKILL_NAME.test(what.skill))
|
|
28
|
+
return errorBody('skillInvalid');
|
|
29
|
+
claudeArgs = ['/' + what.skill];
|
|
30
|
+
}
|
|
31
|
+
else if ('resume' in what) {
|
|
32
|
+
if (!SESSION_ID.test(what.resume))
|
|
33
|
+
return errorBody('sessionIdInvalid');
|
|
34
|
+
claudeArgs = ['--resume', what.resume];
|
|
35
|
+
}
|
|
36
|
+
else if ('continue' in what) {
|
|
37
|
+
claudeArgs = ['--continue'];
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (PROMPT_META.test(what.prompt))
|
|
41
|
+
return errorBody('promptInvalid');
|
|
42
|
+
claudeArgs = [what.prompt];
|
|
43
|
+
}
|
|
44
|
+
const bad = checkPath(projectPath);
|
|
45
|
+
if (bad)
|
|
46
|
+
return bad;
|
|
47
|
+
if (ctx.platform === 'win32')
|
|
48
|
+
return windows(projectPath, claudeArgs, ctx);
|
|
49
|
+
if (ctx.platform === 'darwin')
|
|
50
|
+
return mac(projectPath, claudeArgs, ctx);
|
|
51
|
+
return linux(projectPath, claudeArgs, ctx);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* cmd.exe cherche une commande dans le dossier courant (ici le projet) avant le PATH : un `claude.cmd` posé
|
|
55
|
+
* à la racine d'un dépôt passerait avant le vrai claude. Cette variable coupe cette recherche ; texte fixe,
|
|
56
|
+
* sans valeur injectée (le `&&` collé évite une espace finale dans la valeur).
|
|
57
|
+
*/
|
|
58
|
+
const NO_CWD_SEARCH = ['set', 'NoDefaultCurrentDirectoryInExePath=1&&'];
|
|
59
|
+
function windows(path, claudeArgs, ctx) {
|
|
60
|
+
if (path.includes(';'))
|
|
61
|
+
return errorBody('pathSemicolon');
|
|
62
|
+
// wt.exe ne transmet pas l'environnement du serveur : la variable est posée dans la console elle-même.
|
|
63
|
+
if (ctx.terminal === 'wt' || ctx.has('wt.exe'))
|
|
64
|
+
return { cmd: 'wt.exe', args: ['-d', path, 'cmd.exe', '/k', ...NO_CWD_SEARCH, 'claude', ...claudeArgs] };
|
|
65
|
+
// Repli : `start` ouvre une nouvelle console ; ici le chemin est relu par cmd.exe. La variable est posée
|
|
66
|
+
// avant `start` (sinon le `&&` serait lu par ce premier cmd) et héritée par la nouvelle console.
|
|
67
|
+
const bad = checkCmdPath(path);
|
|
68
|
+
if (bad)
|
|
69
|
+
return bad;
|
|
70
|
+
return { cmd: 'cmd.exe', args: ['/c', ...NO_CWD_SEARCH, 'start', '""', '/D', path, 'cmd.exe', '/k', 'claude', ...claudeArgs] };
|
|
71
|
+
}
|
|
72
|
+
/** Protège pour sh : entre apostrophes, chaque `'` devient `'\''`. */
|
|
73
|
+
const shellQuote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
74
|
+
/** Protège pour une chaîne AppleScript : `\` puis `"`. */
|
|
75
|
+
const appleQuote = (s) => `"${s.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
76
|
+
/** Argument sans caractère spécial pour sh : laissé tel quel (`--resume`, `/skill`) ; sinon protégé par `shellQuote`. */
|
|
77
|
+
const shellArg = (s) => (/^[A-Za-z0-9_.\/:=-]+$/.test(s) ? s : shellQuote(s));
|
|
78
|
+
function mac(path, claudeArgs, ctx) {
|
|
79
|
+
// La commande est tapée dans le shell de l'utilisateur ; sous fish, \' et \\ restent des échappements
|
|
80
|
+
// entre apostrophes : une barre oblique inverse pourrait faire sortir le chemin de ses apostrophes.
|
|
81
|
+
if (path.includes('\\'))
|
|
82
|
+
return errorBody('pathBackslash');
|
|
83
|
+
const command = appleQuote(`cd ${shellQuote(path)} && claude ${claudeArgs.map(shellArg).join(' ')}`);
|
|
84
|
+
const script = ctx.terminal?.toLowerCase() === 'iterm'
|
|
85
|
+
? [
|
|
86
|
+
'tell application "iTerm"',
|
|
87
|
+
'activate',
|
|
88
|
+
'set w to (create window with default profile)',
|
|
89
|
+
`tell current session of w to write text ${command}`,
|
|
90
|
+
'end tell',
|
|
91
|
+
].join('\n')
|
|
92
|
+
: ['tell application "Terminal"', 'activate', `do script ${command}`, 'end tell'].join('\n');
|
|
93
|
+
return { cmd: 'osascript', args: ['-e', script] };
|
|
94
|
+
}
|
|
95
|
+
const LINUX_TERMINALS = ['x-terminal-emulator', 'gnome-terminal', 'konsole', 'xfce4-terminal', 'kitty', 'alacritty'];
|
|
96
|
+
function linux(path, claudeArgs, ctx) {
|
|
97
|
+
// Terminal choisi dans les réglages mais absent : on le dit au lieu d'un lancement qui échoue sans bruit.
|
|
98
|
+
if (ctx.terminal && !ctx.has(ctx.terminal))
|
|
99
|
+
return errorBody('terminalNotFound', { terminal: ctx.terminal });
|
|
100
|
+
const term = ctx.terminal || ctx.env.TERMINAL || LINUX_TERMINALS.find((t) => ctx.has(t));
|
|
101
|
+
if (!term)
|
|
102
|
+
return errorBody('noTerminal');
|
|
103
|
+
switch (posix.basename(term)) {
|
|
104
|
+
case 'gnome-terminal':
|
|
105
|
+
return { cmd: term, args: ['--working-directory', path, '--', 'claude', ...claudeArgs] };
|
|
106
|
+
case 'konsole':
|
|
107
|
+
return { cmd: term, args: ['--workdir', path, '-e', 'claude', ...claudeArgs] };
|
|
108
|
+
case 'xfce4-terminal':
|
|
109
|
+
return { cmd: term, args: ['--working-directory', path, '-x', 'claude', ...claudeArgs] };
|
|
110
|
+
case 'kitty':
|
|
111
|
+
return { cmd: term, args: ['--directory', path, 'claude', ...claudeArgs] };
|
|
112
|
+
case 'alacritty':
|
|
113
|
+
return { cmd: term, args: ['--working-directory', path, '-e', 'claude', ...claudeArgs] };
|
|
114
|
+
default:
|
|
115
|
+
// Le chemin est un argument positionnel ($1), jamais interpolé dans la chaîne -c.
|
|
116
|
+
return { cmd: term, args: ['-e', 'sh', '-c', 'cd "$1" && shift && exec claude "$@"', 'sh', path, ...claudeArgs] };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Ouvre le projet dans l'éditeur. Sous Windows, une commande sans extension (ou .cmd/.bat) est un shim
|
|
121
|
+
* (`code.cmd`) que seul cmd.exe sait lancer : on passe par `cmd.exe /c`, le chemin restant un argument séparé.
|
|
122
|
+
*/
|
|
123
|
+
export function editorLaunch(projectPath, editorCommand, platform) {
|
|
124
|
+
const bad = checkPath(projectPath);
|
|
125
|
+
if (bad)
|
|
126
|
+
return bad;
|
|
127
|
+
if (platform === 'win32' && ['', '.cmd', '.bat'].includes(win32.extname(editorCommand).toLowerCase())) {
|
|
128
|
+
const badCmd = checkCmdPath(projectPath);
|
|
129
|
+
if (badCmd)
|
|
130
|
+
return badCmd;
|
|
131
|
+
return { cmd: 'cmd.exe', args: ['/c', editorCommand, projectPath] };
|
|
132
|
+
}
|
|
133
|
+
return { cmd: editorCommand, args: [projectPath] };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* `has()` : cherche l'exécutable dans le PATH (et avec les extensions de PATHEXT sous Windows), de façon synchrone.
|
|
137
|
+
* Un chemin (avec / ou \) est vérifié tel quel, sans passer par le PATH.
|
|
138
|
+
*/
|
|
139
|
+
export function pathLookup(env, platform) {
|
|
140
|
+
const win = platform === 'win32';
|
|
141
|
+
const p = win ? win32 : posix;
|
|
142
|
+
// Sous Windows, le nom de la variable varie (`Path`, `PATH`) : recherche sans casse.
|
|
143
|
+
const get = (name) => {
|
|
144
|
+
const key = win ? Object.keys(env).find((k) => k.toUpperCase() === name) : name;
|
|
145
|
+
return (key && env[key]) || '';
|
|
146
|
+
};
|
|
147
|
+
const dirs = get('PATH').split(p.delimiter).filter(Boolean);
|
|
148
|
+
// Sous Windows, chaque extension est aussi essayée en minuscules : un FS sensible à la casse (Linux) ne trouve pas `Code.EXE`.
|
|
149
|
+
const exts = win ? ['', ...new Set(get('PATHEXT').split(';').filter(Boolean).flatMap((e) => [e, e.toLowerCase()]))] : [''];
|
|
150
|
+
// lstat et non stat : les alias d'exécution de Windows (WindowsApps\wt.exe) refusent stat (EACCES).
|
|
151
|
+
const isFile = (f) => {
|
|
152
|
+
try {
|
|
153
|
+
const s = lstatSync(f, { throwIfNoEntry: false });
|
|
154
|
+
return s !== undefined && !s.isDirectory();
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
// Un répertoire sans `\` (ex. /usr/bin) se joint en POSIX : win32.join le rendrait introuvable hors Windows.
|
|
161
|
+
const joinDir = (d, f) => (win && !d.includes('\\') ? posix : p).join(d, f);
|
|
162
|
+
return (exe) => (/[\\/]/.test(exe) ? exts.some((x) => isFile(exe + x)) : dirs.some((d) => exts.some((x) => isFile(joinDir(d, exe + x)))));
|
|
163
|
+
}
|
|
164
|
+
/** Contexte de lancement : la machine (injectée, sinon la vraie) et le terminal des réglages, relu à chaque appel. */
|
|
165
|
+
export function launchCtx(deps) {
|
|
166
|
+
const host = deps.launchHost ?? { platform: process.platform, env: process.env, has: pathLookup(process.env, process.platform) };
|
|
167
|
+
return { ...host, terminal: deps.config.terminal };
|
|
168
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, posix, win32 } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** Racine du paquet : remonte depuis ce fichier jusqu'au package.json (tsx ou dist/server/server). */
|
|
5
|
+
export function pkgRoot() {
|
|
6
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
for (;;) {
|
|
8
|
+
if (existsSync(join(dir, 'package.json')))
|
|
9
|
+
return dir;
|
|
10
|
+
const parent = dirname(dir);
|
|
11
|
+
if (parent === dir)
|
|
12
|
+
throw new Error('package.json not found');
|
|
13
|
+
dir = parent;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function pkgPath(...parts) {
|
|
17
|
+
return join(pkgRoot(), ...parts);
|
|
18
|
+
}
|
|
19
|
+
/** Dossier des journaux du serveur, selon l'OS. */
|
|
20
|
+
export function dataDir(env, platform, home) {
|
|
21
|
+
if (platform === 'win32')
|
|
22
|
+
return win32.join(env.LOCALAPPDATA || win32.join(home, 'AppData', 'Local'), 'holohq');
|
|
23
|
+
if (platform === 'darwin')
|
|
24
|
+
return posix.join(home, 'Library', 'Logs', 'holohq');
|
|
25
|
+
return posix.join(env.XDG_STATE_HOME || posix.join(home, '.local', 'state'), 'holohq');
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cached } from './cache.js';
|
|
2
|
+
import { listRemoteRepos } from './github/repos.js';
|
|
3
|
+
import { fetchProjectDetail } from './github/project.js';
|
|
4
|
+
import { scanProjects } from './projects/scan.js';
|
|
5
|
+
/** Réchauffe le cache GitHub au démarrage ; les erreurs sont seulement loguées. */
|
|
6
|
+
export async function preloadAll(deps, log = () => { }) {
|
|
7
|
+
try {
|
|
8
|
+
const owner = deps.config.owner;
|
|
9
|
+
// Sans compte détecté : pas de liste de dépôts, seuls les détails des projets locaux sont préchargés.
|
|
10
|
+
if (owner)
|
|
11
|
+
await cached(`remotes:${owner}`, 60_000, deps.now, () => listRemoteRepos(deps.run, owner));
|
|
12
|
+
const projects = (await scanProjects(deps)).filter((p) => p.repo);
|
|
13
|
+
const queue = [...projects];
|
|
14
|
+
const worker = async () => {
|
|
15
|
+
for (let p = queue.shift(); p; p = queue.shift()) {
|
|
16
|
+
const repo = p.repo;
|
|
17
|
+
try {
|
|
18
|
+
await cached(`detail:${repo.owner}/${repo.name}`.toLowerCase(), 60_000, deps.now, () => fetchProjectDetail(deps.run, repo));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
log(`Preload failed (${repo.name}): ${e instanceof Error ? e.message : String(e)}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
await Promise.all(Array.from({ length: Math.min(4, queue.length) }, worker));
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
log(`Preload failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const PATTERNS = [
|
|
2
|
+
/^https?:\/\/(?:[^@/]+@)?github\.com\/([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i,
|
|
3
|
+
/^(?:ssh:\/\/)?git@github\.com[:/]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i,
|
|
4
|
+
];
|
|
5
|
+
export function parseGithubRemote(url) {
|
|
6
|
+
const u = url.trim();
|
|
7
|
+
for (const re of PATTERNS) {
|
|
8
|
+
const m = re.exec(u);
|
|
9
|
+
if (m)
|
|
10
|
+
return { owner: m[1], name: m[2] };
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { parseGithubRemote } from './remote.js';
|
|
5
|
+
const norm = (p) => resolve(p).toLowerCase();
|
|
6
|
+
export function projectId(path) {
|
|
7
|
+
return createHash('sha1').update(norm(path)).digest('hex').slice(0, 10);
|
|
8
|
+
}
|
|
9
|
+
async function mtime(p) {
|
|
10
|
+
try {
|
|
11
|
+
return (await stat(p)).mtimeMs;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function hasGit(dir) {
|
|
18
|
+
try {
|
|
19
|
+
await stat(join(dir, '.git'));
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function recency(dir) {
|
|
27
|
+
const g = join(dir, '.git');
|
|
28
|
+
return Math.max(await mtime(g), await mtime(join(g, 'HEAD')), await mtime(join(g, 'index')));
|
|
29
|
+
}
|
|
30
|
+
export async function scanLocalProjects(roots, exclude, run) {
|
|
31
|
+
const excluded = new Set(exclude.map(norm));
|
|
32
|
+
const excludedNames = new Set(exclude.map((e) => e.toLowerCase()));
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
const dirs = [];
|
|
35
|
+
for (const root of roots) {
|
|
36
|
+
let entries;
|
|
37
|
+
try {
|
|
38
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
for (const e of entries) {
|
|
44
|
+
if (!e.isDirectory())
|
|
45
|
+
continue;
|
|
46
|
+
const p = join(root, e.name);
|
|
47
|
+
const key = norm(p);
|
|
48
|
+
if (seen.has(key) || excluded.has(key) || excludedNames.has(e.name.toLowerCase()))
|
|
49
|
+
continue;
|
|
50
|
+
seen.add(key);
|
|
51
|
+
if (await hasGit(p))
|
|
52
|
+
dirs.push(p);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const cands = await Promise.all(dirs.map(async (path) => {
|
|
56
|
+
const r = await run('git', ['-C', path, 'remote', 'get-url', 'origin']);
|
|
57
|
+
return { path, mtime: await recency(path), repo: r.code === 0 ? parseGithubRemote(r.stdout) : null };
|
|
58
|
+
}));
|
|
59
|
+
const groups = new Map();
|
|
60
|
+
for (const c of cands) {
|
|
61
|
+
const key = c.repo ? `repo:${c.repo.owner}/${c.repo.name}`.toLowerCase() : `path:${norm(c.path)}`;
|
|
62
|
+
groups.set(key, [...(groups.get(key) ?? []), c]);
|
|
63
|
+
}
|
|
64
|
+
return [...groups.values()].map((g) => {
|
|
65
|
+
const sorted = [...g].sort((a, b) => b.mtime - a.mtime || a.path.localeCompare(b.path));
|
|
66
|
+
const [best, ...rest] = sorted;
|
|
67
|
+
return {
|
|
68
|
+
id: projectId(best.path),
|
|
69
|
+
name: best.repo ? best.repo.name : basename(best.path),
|
|
70
|
+
path: best.path,
|
|
71
|
+
repo: best.repo,
|
|
72
|
+
duplicates: rest.map((c) => c.path),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** Projets locaux par le scanner des dépendances : le fictif en démo, le vrai sinon. */
|
|
77
|
+
export function scanProjects(deps) {
|
|
78
|
+
return (deps.scan ?? scanLocalProjects)(deps.config.roots, deps.config.exclude, deps.run);
|
|
79
|
+
}
|