@odarino/haren 1.2.1 → 1.2.3

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.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/dist/index.js +193 -54
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -366,6 +366,12 @@ root.
366
366
  - **Cursor** → `.cursorrules` + `.cursor/rules/haren.mdc` + `.cursor/hooks.json`
367
367
  (registers the gate via `beforeFileEdit`/`preToolUse`).
368
368
 
369
+ Both editors also get every haren skill and agent in their native folders:
370
+ `.claude/skills/haren-<skill>/`, `.claude/agents/haren-<agent>.md`, and the same
371
+ under `.cursor/`. The `haren-` prefix keeps them apart from your own skills and
372
+ agents (for example `/haren-plan`, agent `haren-developer`). `haren upgrade`
373
+ refreshes these copies from the haren folder.
374
+
369
375
  These files go in the workspace root (the parent of the haren folder). Existing
370
376
  config files are kept: haren writes only inside its marked block.
371
377
 
package/dist/index.js CHANGED
@@ -408,7 +408,7 @@ var init_manifest = __esm(() => {
408
408
 
409
409
  // src/workspace/root-files.ts
410
410
  import { existsSync as existsSync2 } from "fs";
411
- import { mkdir as mkdir2, readFile, writeFile as writeFile2 } from "fs/promises";
411
+ import { mkdir as mkdir2, readdir, readFile, writeFile as writeFile2 } from "fs/promises";
412
412
  import { dirname, join as join3, relative, sep } from "path";
413
413
  function legacyRange(existing) {
414
414
  const start = existing.indexOf(LEGACY_HEADING);
@@ -510,14 +510,74 @@ function mergeCursorHooks(existing, command) {
510
510
  async function readOrNull(path) {
511
511
  return existsSync2(path) ? readFile(path, "utf-8") : null;
512
512
  }
513
- async function readPackagedOnboard(contentDir) {
514
- let dir;
515
- try {
516
- dir = contentDir ?? resolveContentDir();
517
- } catch {
518
- return null;
513
+ function harenName(name) {
514
+ return name.startsWith("haren-") ? name : `haren-${name}`;
515
+ }
516
+ function withFrontmatterName(text, name) {
517
+ const fm = /^---\r?\n[\s\S]*?\r?\n---/.exec(text);
518
+ if (!fm)
519
+ return text;
520
+ const head = fm[0].replace(/^name:.*$/m, `name: ${name}`);
521
+ return head + text.slice(fm[0].length);
522
+ }
523
+ function frontmatterName(text) {
524
+ const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
525
+ return fm?.[1]?.match(/^name:\s*(.+?)\s*$/m)?.[1]?.replace(/^["']|["']$/g, "");
526
+ }
527
+ async function listFiles(dir, prefix = "") {
528
+ const out = [];
529
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
530
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
531
+ if (entry.isDirectory())
532
+ out.push(...await listFiles(join3(dir, entry.name), rel));
533
+ else if (entry.isFile())
534
+ out.push(rel);
535
+ }
536
+ return out.sort();
537
+ }
538
+ async function frameworkFiles(harenDir, contentDir) {
539
+ let source = harenDir;
540
+ if (!existsSync2(join3(harenDir, "skills")) && !existsSync2(join3(harenDir, "agents"))) {
541
+ try {
542
+ source = contentDir ?? resolveContentDir();
543
+ } catch {
544
+ return [];
545
+ }
546
+ }
547
+ const files = [];
548
+ const skillsDir = join3(source, "skills");
549
+ if (existsSync2(skillsDir)) {
550
+ for (const entry of await readdir(skillsDir, { withFileTypes: true })) {
551
+ if (!entry.isDirectory())
552
+ continue;
553
+ const dir = join3(skillsDir, entry.name);
554
+ const main = await readOrNull(join3(dir, "SKILL.md"));
555
+ if (main === null)
556
+ continue;
557
+ const name = harenName(frontmatterName(main) ?? entry.name);
558
+ for (const rel of await listFiles(dir)) {
559
+ const text = await readFile(join3(dir, rel), "utf-8");
560
+ files.push({
561
+ path: `skills/${name}/${rel}`,
562
+ content: rel === "SKILL.md" ? withFrontmatterName(text, name) : text,
563
+ group: "skills"
564
+ });
565
+ }
566
+ }
567
+ }
568
+ const agentsDir = join3(source, "agents");
569
+ if (existsSync2(agentsDir)) {
570
+ for (const file of (await readdir(agentsDir)).filter((f) => f.endsWith(".md")).sort()) {
571
+ const text = await readFile(join3(agentsDir, file), "utf-8");
572
+ const name = harenName(frontmatterName(text) ?? file.slice(0, -3));
573
+ files.push({
574
+ path: `agents/${name}.md`,
575
+ content: withFrontmatterName(text, name),
576
+ group: "agents"
577
+ });
578
+ }
519
579
  }
520
- return readOrNull(join3(dir, "skills", "onboard", "SKILL.md"));
580
+ return files.sort((x, y) => x.path.localeCompare(y.path));
521
581
  }
522
582
  async function computeRootFiles(o) {
523
583
  const name = relative(o.workspaceDir, o.harenDir).split(sep).join("/");
@@ -525,8 +585,17 @@ async function computeRootFiles(o) {
525
585
  const useCursor = o.editor !== "claude-code";
526
586
  const command = gateCommand(name);
527
587
  const config = renderTemplate(editorConfigTemplate, name);
528
- const onboard = await readOrNull(join3(o.harenDir, "skills", "onboard", "SKILL.md")) ?? await readPackagedOnboard(o.contentDir);
588
+ const framework = await frameworkFiles(o.harenDir, o.contentDir);
529
589
  const specs = [];
590
+ const addFramework = (editorDir) => {
591
+ for (const f of framework) {
592
+ specs.push({
593
+ path: `${editorDir}/${f.path}`,
594
+ make: () => f.content,
595
+ group: `${editorDir}/${f.group}/`
596
+ });
597
+ }
598
+ };
530
599
  if (useClaude) {
531
600
  specs.push({
532
601
  path: "CLAUDE.md",
@@ -534,8 +603,7 @@ async function computeRootFiles(o) {
534
603
  markdown: true
535
604
  });
536
605
  specs.push({ path: ".claude/settings.json", make: (old) => mergeClaudeSettings(old, command) });
537
- if (onboard !== null)
538
- specs.push({ path: ".claude/skills/haren-onboard/SKILL.md", make: () => onboard });
606
+ addFramework(".claude");
539
607
  }
540
608
  if (useCursor) {
541
609
  specs.push({
@@ -548,8 +616,7 @@ async function computeRootFiles(o) {
548
616
  make: () => renderTemplate(cursorRuleTemplate, name)
549
617
  });
550
618
  specs.push({ path: ".cursor/hooks.json", make: (old) => mergeCursorHooks(old, command) });
551
- if (onboard !== null)
552
- specs.push({ path: ".cursor/skills/haren-onboard/SKILL.md", make: () => onboard });
619
+ addFramework(".cursor");
553
620
  }
554
621
  const files = [];
555
622
  for (const spec of specs) {
@@ -560,11 +627,33 @@ async function computeRootFiles(o) {
560
627
  content,
561
628
  existed: old !== null,
562
629
  changed: old !== content,
563
- userContent: spec.markdown ? hasUserContent(old) : false
630
+ userContent: spec.markdown ? hasUserContent(old) : false,
631
+ ...spec.group ? { group: spec.group } : {}
564
632
  });
565
633
  }
566
634
  return files;
567
635
  }
636
+ function summarizeRootFiles(files) {
637
+ const out = [];
638
+ const groups = new Map;
639
+ for (const file of files) {
640
+ if (!file.group) {
641
+ out.push(file);
642
+ continue;
643
+ }
644
+ const g = groups.get(file.group);
645
+ if (!g) {
646
+ const entry = { ...file, path: file.group, content: "", count: 1 };
647
+ groups.set(file.group, entry);
648
+ out.push(entry);
649
+ } else {
650
+ g.count += 1;
651
+ g.existed ||= file.existed;
652
+ g.changed ||= file.changed;
653
+ }
654
+ }
655
+ return out;
656
+ }
568
657
  async function writeRootFiles(o) {
569
658
  const files = await computeRootFiles(o);
570
659
  for (const file of files) {
@@ -596,7 +685,7 @@ var init_root_files = __esm(() => {
596
685
 
597
686
  // src/workspace/git.ts
598
687
  import { existsSync as existsSync3 } from "fs";
599
- import { mkdir as mkdir3, readdir } from "fs/promises";
688
+ import { mkdir as mkdir3, readdir as readdir2 } from "fs/promises";
600
689
  import { dirname as dirname2, join as join4, resolve as resolve2 } from "path";
601
690
  function gitEnv(interactive = process.stdin.isTTY === true, base = process.env) {
602
691
  if (interactive)
@@ -649,7 +738,7 @@ async function gitInit(dir) {
649
738
  return runGit(["init"], dir);
650
739
  }
651
740
  async function listChildRepos(dir) {
652
- const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
741
+ const entries = await readdir2(dir, { withFileTypes: true }).catch(() => []);
653
742
  const repos = [];
654
743
  for (const entry of entries) {
655
744
  if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
@@ -665,7 +754,7 @@ var init_git = () => {};
665
754
 
666
755
  // src/workspace/resolve.ts
667
756
  import { existsSync as existsSync4 } from "fs";
668
- import { readdir as readdir2, readFile as readFile2, stat } from "fs/promises";
757
+ import { readdir as readdir3, readFile as readFile2, stat } from "fs/promises";
669
758
  import { dirname as dirname3, join as join5, resolve as resolve3 } from "path";
670
759
  async function hasMarkedManifest(dir) {
671
760
  const path = join5(dir, "manifest.yaml");
@@ -710,7 +799,7 @@ async function resolveHarenDir(cwd, opts = {}) {
710
799
  }
711
800
  if (await hasMarkedManifest(cwd))
712
801
  return location(cwd, false);
713
- const entries = await readdir2(cwd, { withFileTypes: true }).catch(() => []);
802
+ const entries = await readdir3(cwd, { withFileTypes: true }).catch(() => []);
714
803
  const matches = [];
715
804
  for (const entry of entries) {
716
805
  if (entry.name.startsWith(".") || entry.name === "node_modules")
@@ -788,21 +877,24 @@ import { basename as basename2, relative as relative2, resolve as resolve4, sep
788
877
  async function buildPlan(input) {
789
878
  const items = [];
790
879
  const generatedNote = input.layout === "workspace" ? "(generated, not versioned)" : undefined;
791
- for (const file of await computeRootFiles({
880
+ const rootFiles = await computeRootFiles({
792
881
  workspaceDir: input.rootDir,
793
882
  harenDir: input.harenDir,
794
883
  editor: input.editor
795
- })) {
884
+ });
885
+ for (const file of summarizeRootFiles(rootFiles)) {
886
+ const count = file.count ? `(${file.count} files)` : undefined;
887
+ const join = (...notes) => notes.filter(Boolean).join(" ") || undefined;
796
888
  if (!file.existed)
797
- items.push({ path: file.path, action: "create", note: generatedNote });
889
+ items.push({ path: file.path, action: "create", note: join(count, generatedNote) });
798
890
  else if (file.changed)
799
891
  items.push({
800
892
  path: file.path,
801
893
  action: "modify",
802
- note: file.userContent ? "(haren block only)" : undefined
894
+ note: file.userContent ? "(haren block only)" : count
803
895
  });
804
896
  else
805
- items.push({ path: file.path, action: "keep" });
897
+ items.push({ path: file.path, action: "keep", note: count });
806
898
  }
807
899
  for (const [key, repo] of Object.entries(input.repos)) {
808
900
  const abs = resolve4(input.harenDir, repo.path);
@@ -936,7 +1028,7 @@ var init_version = __esm(() => {
936
1028
  });
937
1029
 
938
1030
  // src/commands/init.ts
939
- import { mkdir as mkdir4, writeFile as writeFile3, readdir as readdir3, copyFile, readFile as readFile3 } from "fs/promises";
1031
+ import { mkdir as mkdir4, writeFile as writeFile3, readdir as readdir4, copyFile, readFile as readFile3 } from "fs/promises";
940
1032
  import { existsSync as existsSync8, realpathSync } from "fs";
941
1033
  import { homedir } from "os";
942
1034
  import { basename as basename3, join as join6, resolve as resolve6 } from "path";
@@ -959,29 +1051,75 @@ async function prompt(question, defaultValue) {
959
1051
  const value = await readLine();
960
1052
  return value || defaultValue || "";
961
1053
  }
962
- async function promptSelect(question, options, descriptions, defaultValue) {
963
- console.log(` \x1B[36m?\x1B[0m ${question}`);
964
- for (const opt of options) {
965
- const marker = opt === defaultValue ? "\x1B[36m>\x1B[0m" : " ";
966
- const label = opt === defaultValue ? `\x1B[1m${opt}\x1B[0m` : opt;
967
- console.log(` ${marker} ${label} \x1B[2m\u2014 ${descriptions[opt]}\x1B[0m`);
968
- }
969
- process.stdout.write(` \x1B[2m enter choice:\x1B[0m `);
970
- while (true) {
971
- const choice = parseSelectChoice(await readLine(), options, defaultValue);
972
- if (choice)
973
- return choice;
974
- process.stdout.write(` \x1B[31m!\x1B[0m Invalid. Choose: ${options.join(", ")} (or 1-${options.length}) `);
975
- }
1054
+ function parseSelectKeys(data) {
1055
+ const keys = [];
1056
+ for (const [token] of data.matchAll(/\x1b\[[A-D]|\x1bO[A-D]|\r\n|[\s\S]/g)) {
1057
+ if (token === "\x1B[A" || token === "\x1BOA")
1058
+ keys.push("up");
1059
+ else if (token === "\x1B[B" || token === "\x1BOB")
1060
+ keys.push("down");
1061
+ else if (token === "\r" || token === `
1062
+ ` || token === `\r
1063
+ `)
1064
+ keys.push("enter");
1065
+ else if (token === "\x03")
1066
+ keys.push("abort");
1067
+ }
1068
+ return keys;
1069
+ }
1070
+ function moveSelection(index, key, count) {
1071
+ return key === "up" ? (index - 1 + count) % count : (index + 1) % count;
1072
+ }
1073
+ function listRows(lines, columns) {
1074
+ const width = columns && columns > 0 ? columns : Infinity;
1075
+ return lines.reduce((rows, l) => {
1076
+ const visible = l.replace(/\x1b\[[0-9;?]*[A-Za-z]|\r/g, "").length;
1077
+ return rows + Math.max(1, Math.ceil(visible / width));
1078
+ }, 0);
976
1079
  }
977
- function parseSelectChoice(value, options, defaultValue) {
978
- const answer = value.trim().toLowerCase();
979
- if (!answer)
980
- return defaultValue;
981
- if (options.includes(answer))
982
- return answer;
983
- const n = Number(answer);
984
- return Number.isInteger(n) && n >= 1 && n <= options.length ? options[n - 1] : null;
1080
+ async function promptSelect(question, options, descriptions, defaultValue) {
1081
+ const out = process.stdout;
1082
+ const stdin = process.stdin;
1083
+ let index = Math.max(0, options.indexOf(defaultValue));
1084
+ const line = (i) => {
1085
+ const opt = options[i];
1086
+ const marker = i === index ? "\x1B[36m>\x1B[0m" : " ";
1087
+ const label = i === index ? `\x1B[1m${opt}\x1B[0m` : opt;
1088
+ return `\r\x1B[2K ${marker} ${label} \x1B[2m\u2014 ${descriptions[opt]}\x1B[0m`;
1089
+ };
1090
+ const draw = () => out.write(options.map((_, i) => line(i)).join(`
1091
+ `));
1092
+ out.write(` \x1B[36m?\x1B[0m ${question} \x1B[2m(\u2191/\u2193, Enter)\x1B[0m
1093
+ \x1B[?25l`);
1094
+ draw();
1095
+ return new Promise((resolve) => {
1096
+ const finish = (abort) => {
1097
+ stdin.removeListener("data", onData);
1098
+ stdin.setRawMode(false);
1099
+ stdin.pause();
1100
+ out.write(`\x1B[?25h
1101
+ `);
1102
+ if (abort)
1103
+ process.exit(130);
1104
+ resolve(options[index]);
1105
+ };
1106
+ const onData = (data) => {
1107
+ for (const key of parseSelectKeys(data.toString())) {
1108
+ if (key === "abort")
1109
+ return finish(true);
1110
+ if (key === "enter")
1111
+ return finish(false);
1112
+ index = moveSelection(index, key, options.length);
1113
+ const up = listRows(options.map((_, i) => line(i)), out.columns) - 1;
1114
+ if (up > 0)
1115
+ out.write(`\x1B[${up}A`);
1116
+ draw();
1117
+ }
1118
+ };
1119
+ stdin.setRawMode(true);
1120
+ stdin.resume();
1121
+ stdin.on("data", onData);
1122
+ });
985
1123
  }
986
1124
  function parseRepoSelection(value, count, defaults) {
987
1125
  const answer = value.trim().toLowerCase();
@@ -1058,7 +1196,7 @@ function getDirectories(iterations) {
1058
1196
  return dirs;
1059
1197
  }
1060
1198
  async function copyRecursive(src, dest) {
1061
- const entries = await readdir3(src, { withFileTypes: true });
1199
+ const entries = await readdir4(src, { withFileTypes: true });
1062
1200
  await mkdir4(dest, { recursive: true });
1063
1201
  for (const entry of entries) {
1064
1202
  const srcPath = join6(src, entry.name);
@@ -1581,7 +1719,7 @@ var init_init = __esm(() => {
1581
1719
  });
1582
1720
 
1583
1721
  // src/commands/upgrade.ts
1584
- import { mkdir as mkdir5, readdir as readdir4, copyFile as copyFile2, readFile as readFile4, stat as stat2, writeFile as writeFile4 } from "fs/promises";
1722
+ import { mkdir as mkdir5, readdir as readdir5, copyFile as copyFile2, readFile as readFile4, stat as stat2, writeFile as writeFile4 } from "fs/promises";
1585
1723
  import { join as join7, resolve as resolve7 } from "path";
1586
1724
  import { existsSync as existsSync9 } from "fs";
1587
1725
  async function moduleRepoKey(harenDir, moduleName) {
@@ -1652,8 +1790,9 @@ async function planMigration(location) {
1652
1790
  steps.push(`.gitignore: add ${AGENT_FILES.join(", ")}`);
1653
1791
  const editor = detectEditor(workspaceDir) ?? "claude-code";
1654
1792
  const rootFiles = await computeRootFiles({ workspaceDir, harenDir, editor });
1655
- for (const file of rootFiles.filter((f) => f.changed)) {
1656
- steps.push(`${file.path}: ${file.existed ? "update" : "create"}`);
1793
+ for (const file of summarizeRootFiles(rootFiles).filter((f) => f.changed)) {
1794
+ const count = file.count ? ` (${file.count} files)` : "";
1795
+ steps.push(`${file.path}: ${file.existed ? "update" : "create"}${count}`);
1657
1796
  }
1658
1797
  return {
1659
1798
  manifest: { before: manifestBefore, after: manifestAfter },
@@ -1680,7 +1819,7 @@ async function planGitignore(harenDir) {
1680
1819
  return `${base}${missing.join(eol)}${eol}`;
1681
1820
  }
1682
1821
  async function copyRecursive2(src, dest) {
1683
- const entries = await readdir4(src, { withFileTypes: true });
1822
+ const entries = await readdir5(src, { withFileTypes: true });
1684
1823
  await mkdir5(dest, { recursive: true });
1685
1824
  for (const entry of entries) {
1686
1825
  const srcPath = join7(src, entry.name);
@@ -1694,7 +1833,7 @@ async function copyRecursive2(src, dest) {
1694
1833
  }
1695
1834
  async function countFiles(dir) {
1696
1835
  let count = 0;
1697
- const entries = await readdir4(dir, { withFileTypes: true });
1836
+ const entries = await readdir5(dir, { withFileTypes: true });
1698
1837
  for (const entry of entries) {
1699
1838
  if (entry.isDirectory()) {
1700
1839
  count += await countFiles(join7(dir, entry.name));
@@ -1834,7 +1973,7 @@ var init_cli_detector = __esm(() => {
1834
1973
 
1835
1974
  // src/agent/artifact-reader.ts
1836
1975
  import { join as join9 } from "path";
1837
- import { readdir as readdir5 } from "fs/promises";
1976
+ import { readdir as readdir6 } from "fs/promises";
1838
1977
  async function readProgress(harenDir) {
1839
1978
  const file = Bun.file(join9(harenDir, "progress.json"));
1840
1979
  if (!await file.exists())
@@ -1850,7 +1989,7 @@ async function readArtifactTree(harenDir) {
1850
1989
  }
1851
1990
  }
1852
1991
  async function buildTree(dirPath, relativePath) {
1853
- const entries = await readdir5(dirPath, { withFileTypes: true });
1992
+ const entries = await readdir6(dirPath, { withFileTypes: true });
1854
1993
  const nodes = [];
1855
1994
  for (const entry of entries) {
1856
1995
  const entryPath = join9(relativePath, entry.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odarino/haren",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Minimal skill-based agentic SDLC framework",
5
5
  "type": "module",
6
6
  "license": "MIT",