henergyqueai 0.4.2 → 0.8.1

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/src/skills.js ADDED
@@ -0,0 +1,37 @@
1
+ import { readdir, readFile, realpath, stat } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+
5
+ const validName = (name) => /^[a-z0-9][a-z0-9_-]{0,63}$/i.test(name);
6
+
7
+ export async function listSkills(root) {
8
+ const projectRoot = await realpath(root);
9
+ const locations = [
10
+ { folder: path.join(homedir(), ".henergyqueai", "skills"), scope: "personnelle" },
11
+ { folder: path.join(root, ".henergyqueai", "skills"), scope: "projet" },
12
+ ];
13
+ const found = new Map();
14
+ for (const location of locations) {
15
+ const entries = await readdir(location.folder, { withFileTypes: true }).catch(() => []);
16
+ for (const entry of entries) {
17
+ if (!entry.isDirectory() || !validName(entry.name)) continue;
18
+ const file = path.join(location.folder, entry.name, "SKILL.md");
19
+ if (location.scope === "projet") {
20
+ const actual = await realpath(file).catch(() => "");
21
+ if (!actual.startsWith(projectRoot + path.sep)) continue;
22
+ }
23
+ const info = await stat(file).catch(() => null);
24
+ if (!info?.isFile() || info.size > 30_000) continue;
25
+ found.set(entry.name, { name: entry.name, scope: location.scope, file });
26
+ }
27
+ }
28
+ return [...found.values()].sort((a, b) => a.name.localeCompare(b.name, "fr"));
29
+ }
30
+
31
+ export async function readSkill(root, name) {
32
+ if (!validName(name)) return "Nom de compétence invalide.";
33
+ const skill = (await listSkills(root)).find((item) => item.name === name);
34
+ if (!skill) return `Compétence « ${name} » introuvable.`;
35
+ const content = await readFile(skill.file, "utf8");
36
+ return `Compétence ${skill.name} (${skill.scope}) :\n\n${content}`;
37
+ }
package/src/tasks.js ADDED
@@ -0,0 +1,71 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { readFile, writeFile, mkdir, rename } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import path from "node:path";
5
+
6
+ const fileFor = (root) =>
7
+ path.join(
8
+ homedir(),
9
+ ".henergyqueai",
10
+ "tasks",
11
+ `${createHash("sha256").update(path.resolve(root)).digest("hex").slice(0, 16)}.json`,
12
+ );
13
+
14
+ export async function listTasks(root) {
15
+ const raw = await readFile(fileFor(root), "utf8").catch(() => null);
16
+ if (!raw) return [];
17
+ try {
18
+ const tasks = JSON.parse(raw);
19
+ return Array.isArray(tasks)
20
+ ? tasks.filter(
21
+ (item) =>
22
+ typeof item.id === "string" &&
23
+ typeof item.title === "string" &&
24
+ ["à faire", "en cours", "terminée"].includes(item.status),
25
+ )
26
+ : [];
27
+ } catch {
28
+ return [];
29
+ }
30
+ }
31
+
32
+ async function saveTasks(root, tasks) {
33
+ const file = fileFor(root);
34
+ await mkdir(path.dirname(file), { recursive: true });
35
+ const temporary = `${file}.${randomUUID()}.tmp`;
36
+ await writeFile(temporary, JSON.stringify(tasks, null, 2), { mode: 0o600 });
37
+ await rename(temporary, file);
38
+ }
39
+
40
+ export async function manageTasks(root, { action, id, title, status } = {}) {
41
+ const tasks = await listTasks(root);
42
+ if (action === "lister")
43
+ return tasks.length
44
+ ? tasks.map((task) => `${task.id} · ${task.status} · ${task.title}`).join("\n")
45
+ : "Aucune tâche pour ce projet.";
46
+ if (action === "ajouter") {
47
+ const clean = String(title || "").trim();
48
+ if (!clean || clean.length > 180) return "Titre de tâche invalide (1 à 180 caractères).";
49
+ if (tasks.length >= 100) return "Limite de 100 tâches atteinte.";
50
+ const task = { id: randomUUID().slice(0, 8), title: clean, status: "à faire" };
51
+ tasks.push(task);
52
+ await saveTasks(root, tasks);
53
+ return `Tâche ${task.id} ajoutée : ${task.title}`;
54
+ }
55
+ if (action === "modifier") {
56
+ const task = tasks.find((item) => item.id === id);
57
+ if (!task) return "Tâche introuvable.";
58
+ if (!["à faire", "en cours", "terminée"].includes(status))
59
+ return "Statut invalide.";
60
+ task.status = status;
61
+ await saveTasks(root, tasks);
62
+ return `Tâche ${task.id} : ${task.status}.`;
63
+ }
64
+ if (action === "supprimer") {
65
+ const next = tasks.filter((item) => item.id !== id);
66
+ if (next.length === tasks.length) return "Tâche introuvable.";
67
+ await saveTasks(root, next);
68
+ return `Tâche ${id} supprimée.`;
69
+ }
70
+ return "Action de tâche inconnue.";
71
+ }