@odarino/haren 1.2.3 → 1.3.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/dist/index.js CHANGED
@@ -406,10 +406,148 @@ var init_manifest = __esm(() => {
406
406
  YAML_SPECIAL_FLOAT = /^[-+]?\.(inf|nan)$/i;
407
407
  });
408
408
 
409
- // src/workspace/root-files.ts
409
+ // src/plugins/manifest.ts
410
410
  import { existsSync as existsSync2 } from "fs";
411
- import { mkdir as mkdir2, readdir, readFile, writeFile as writeFile2 } from "fs/promises";
412
- import { dirname, join as join3, relative, sep } from "path";
411
+ import { readFile } from "fs/promises";
412
+ import { isAbsolute, join as join3 } from "path";
413
+ function stringList(value, field) {
414
+ if (value === undefined)
415
+ return [];
416
+ if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
417
+ throw new Error(`Plugin manifest: ${field} must be a list of strings`);
418
+ }
419
+ return value;
420
+ }
421
+ function relativePathList(value, field) {
422
+ const list = stringList(value, field);
423
+ for (const p of list) {
424
+ if (isAbsolute(p) || p.startsWith("/") || /^[A-Za-z]:/.test(p) || p.split(/[\\/]/).includes("..")) {
425
+ throw new Error(`Plugin manifest: ${field} path must stay inside the plugin: ${p}`);
426
+ }
427
+ }
428
+ return list;
429
+ }
430
+ function validateManifest(raw, packageVersion) {
431
+ if (!raw || typeof raw !== "object")
432
+ throw new Error("Plugin manifest must be a JSON object");
433
+ const m = raw;
434
+ if (typeof m.name !== "string" || !m.name)
435
+ throw new Error("Plugin manifest: name is required");
436
+ if (!NAME.test(m.name))
437
+ throw new Error(`Plugin manifest: name must be kebab-case: ${m.name}`);
438
+ if (m.harenApi !== HAREN_API) {
439
+ throw new Error(`Plugin manifest: this haren supports harenApi "${HAREN_API}", got ${JSON.stringify(m.harenApi)}`);
440
+ }
441
+ let version;
442
+ if (packageVersion !== undefined) {
443
+ if (m.version !== undefined && m.version !== packageVersion) {
444
+ throw new Error(`Plugin manifest: version ${m.version} differs from package.json ${packageVersion}`);
445
+ }
446
+ version = packageVersion;
447
+ } else {
448
+ if (typeof m.version !== "string" || !m.version)
449
+ throw new Error("Plugin manifest: version is required");
450
+ version = m.version;
451
+ }
452
+ const hooks = {};
453
+ if (m.hooks !== undefined) {
454
+ if (!m.hooks || typeof m.hooks !== "object")
455
+ throw new Error("Plugin manifest: hooks must be an object");
456
+ for (const [name, command] of Object.entries(m.hooks)) {
457
+ if (!HOOK_NAMES.includes(name))
458
+ throw new Error(`Plugin manifest: Unknown hook: ${name}`);
459
+ if (typeof command !== "string" || !command)
460
+ throw new Error(`Plugin manifest: hook ${name} needs a command`);
461
+ hooks[name] = command;
462
+ }
463
+ }
464
+ const requires = [];
465
+ if (m.requires !== undefined) {
466
+ if (!Array.isArray(m.requires))
467
+ throw new Error("Plugin manifest: requires must be a list");
468
+ for (const r of m.requires) {
469
+ if (!r || typeof r.bin !== "string" || !r.bin)
470
+ throw new Error("Plugin manifest: each requirement needs a bin");
471
+ if (r.version !== undefined && typeof r.version !== "string") {
472
+ throw new Error(`Plugin manifest: requirement ${r.bin} version must be a string`);
473
+ }
474
+ if (r.install !== undefined && typeof r.install !== "string") {
475
+ throw new Error(`Plugin manifest: requirement ${r.bin} install must be a string`);
476
+ }
477
+ requires.push({
478
+ bin: r.bin,
479
+ version: r.version,
480
+ install: r.install
481
+ });
482
+ }
483
+ }
484
+ const config = m.config ?? {};
485
+ if (typeof config !== "object" || Array.isArray(config))
486
+ throw new Error("Plugin manifest: config must be an object");
487
+ return {
488
+ name: m.name,
489
+ version,
490
+ harenApi: HAREN_API,
491
+ description: typeof m.description === "string" ? m.description : undefined,
492
+ requires,
493
+ setup: stringList(m.setup, "setup"),
494
+ hooks,
495
+ config,
496
+ skills: relativePathList(m.skills, "skills"),
497
+ agents: relativePathList(m.agents, "agents")
498
+ };
499
+ }
500
+ async function readInstalledManifest(dir) {
501
+ const raw = JSON.parse(await readFile(join3(dir, "haren-plugin.json"), "utf-8"));
502
+ let packageVersion;
503
+ const hasVersion = raw && typeof raw === "object" && raw.version !== undefined;
504
+ const pkgPath = join3(dir, "package.json");
505
+ if (!hasVersion && existsSync2(pkgPath)) {
506
+ try {
507
+ const v = JSON.parse(await readFile(pkgPath, "utf-8"))?.version;
508
+ if (typeof v === "string")
509
+ packageVersion = v;
510
+ } catch {}
511
+ }
512
+ return validateManifest(raw, packageVersion);
513
+ }
514
+ var HAREN_API = "1", HOOK_NAMES, NAME;
515
+ var init_manifest2 = __esm(() => {
516
+ HOOK_NAMES = ["session-start", "after-plan", "on-task-status"];
517
+ NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
518
+ });
519
+
520
+ // src/plugins/state.ts
521
+ import { existsSync as existsSync3 } from "fs";
522
+ import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
523
+ import { join as join4 } from "path";
524
+ function pluginsPath(harenDir) {
525
+ return join4(harenDir, "plugins.json");
526
+ }
527
+ function pluginDir(harenDir, name) {
528
+ return join4(harenDir, ".plugins", name);
529
+ }
530
+ function pluginDataDir(harenDir, name) {
531
+ return join4(harenDir, ".plugin-data", name);
532
+ }
533
+ async function readPlugins(harenDir) {
534
+ const path = pluginsPath(harenDir);
535
+ if (!existsSync3(path))
536
+ return { version: 1, plugins: {} };
537
+ const data = JSON.parse(await readFile2(path, "utf-8"));
538
+ return { version: 1, plugins: data.plugins ?? {} };
539
+ }
540
+ async function writePlugins(harenDir, data) {
541
+ await mkdir2(harenDir, { recursive: true });
542
+ await writeFile2(pluginsPath(harenDir), `${JSON.stringify(data, null, 2)}
543
+ `);
544
+ }
545
+ var init_state = () => {};
546
+
547
+ // src/workspace/root-files.ts
548
+ import { existsSync as existsSync4 } from "fs";
549
+ import { mkdir as mkdir3, readdir, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
550
+ import { basename as basename2, dirname, join as join5, relative, resolve as resolve2, sep } from "path";
413
551
  function legacyRange(existing) {
414
552
  const start = existing.indexOf(LEGACY_HEADING);
415
553
  if (start === -1 || !existing.includes("haren/skill.md"))
@@ -508,7 +646,7 @@ function mergeCursorHooks(existing, command) {
508
646
  `;
509
647
  }
510
648
  async function readOrNull(path) {
511
- return existsSync2(path) ? readFile(path, "utf-8") : null;
649
+ return existsSync4(path) ? readFile3(path, "utf-8") : null;
512
650
  }
513
651
  function harenName(name) {
514
652
  return name.startsWith("haren-") ? name : `haren-${name}`;
@@ -529,7 +667,7 @@ async function listFiles(dir, prefix = "") {
529
667
  for (const entry of await readdir(dir, { withFileTypes: true })) {
530
668
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
531
669
  if (entry.isDirectory())
532
- out.push(...await listFiles(join3(dir, entry.name), rel));
670
+ out.push(...await listFiles(join5(dir, entry.name), rel));
533
671
  else if (entry.isFile())
534
672
  out.push(rel);
535
673
  }
@@ -537,7 +675,7 @@ async function listFiles(dir, prefix = "") {
537
675
  }
538
676
  async function frameworkFiles(harenDir, contentDir) {
539
677
  let source = harenDir;
540
- if (!existsSync2(join3(harenDir, "skills")) && !existsSync2(join3(harenDir, "agents"))) {
678
+ if (!existsSync4(join5(harenDir, "skills")) && !existsSync4(join5(harenDir, "agents"))) {
541
679
  try {
542
680
  source = contentDir ?? resolveContentDir();
543
681
  } catch {
@@ -545,18 +683,18 @@ async function frameworkFiles(harenDir, contentDir) {
545
683
  }
546
684
  }
547
685
  const files = [];
548
- const skillsDir = join3(source, "skills");
549
- if (existsSync2(skillsDir)) {
686
+ const skillsDir = join5(source, "skills");
687
+ if (existsSync4(skillsDir)) {
550
688
  for (const entry of await readdir(skillsDir, { withFileTypes: true })) {
551
689
  if (!entry.isDirectory())
552
690
  continue;
553
- const dir = join3(skillsDir, entry.name);
554
- const main = await readOrNull(join3(dir, "SKILL.md"));
691
+ const dir = join5(skillsDir, entry.name);
692
+ const main = await readOrNull(join5(dir, "SKILL.md"));
555
693
  if (main === null)
556
694
  continue;
557
695
  const name = harenName(frontmatterName(main) ?? entry.name);
558
696
  for (const rel of await listFiles(dir)) {
559
- const text = await readFile(join3(dir, rel), "utf-8");
697
+ const text = await readFile3(join5(dir, rel), "utf-8");
560
698
  files.push({
561
699
  path: `skills/${name}/${rel}`,
562
700
  content: rel === "SKILL.md" ? withFrontmatterName(text, name) : text,
@@ -565,10 +703,10 @@ async function frameworkFiles(harenDir, contentDir) {
565
703
  }
566
704
  }
567
705
  }
568
- const agentsDir = join3(source, "agents");
569
- if (existsSync2(agentsDir)) {
706
+ const agentsDir = join5(source, "agents");
707
+ if (existsSync4(agentsDir)) {
570
708
  for (const file of (await readdir(agentsDir)).filter((f) => f.endsWith(".md")).sort()) {
571
- const text = await readFile(join3(agentsDir, file), "utf-8");
709
+ const text = await readFile3(join5(agentsDir, file), "utf-8");
572
710
  const name = harenName(frontmatterName(text) ?? file.slice(0, -3));
573
711
  files.push({
574
712
  path: `agents/${name}.md`,
@@ -577,6 +715,55 @@ async function frameworkFiles(harenDir, contentDir) {
577
715
  });
578
716
  }
579
717
  }
718
+ files.push(...await pluginFiles(harenDir));
719
+ return files.sort((x, y) => x.path.localeCompare(y.path));
720
+ }
721
+ async function pluginFiles(harenDir, only) {
722
+ const files = [];
723
+ const state = await readPlugins(harenDir);
724
+ for (const [plugin, entry] of Object.entries(state.plugins)) {
725
+ if (only !== undefined ? plugin !== only : !entry.enabled)
726
+ continue;
727
+ const dir = pluginDir(harenDir, plugin);
728
+ let manifest;
729
+ try {
730
+ manifest = await readInstalledManifest(dir);
731
+ } catch {
732
+ continue;
733
+ }
734
+ const prefixed = (n) => n.startsWith(`${plugin}-`) ? n : `${plugin}-${n}`;
735
+ const safeName = (n) => /^[A-Za-z0-9._-]+$/.test(n) && !n.includes("..");
736
+ for (const skill of manifest.skills) {
737
+ const skillDir = join5(dir, skill);
738
+ const main = await readOrNull(join5(skillDir, "SKILL.md"));
739
+ if (main === null)
740
+ continue;
741
+ const name = prefixed(frontmatterName(main) ?? basename2(skillDir));
742
+ if (!safeName(name))
743
+ continue;
744
+ for (const rel of await listFiles(skillDir)) {
745
+ const text = await readFile3(join5(skillDir, rel), "utf-8");
746
+ files.push({
747
+ path: `skills/${name}/${rel}`,
748
+ content: rel === "SKILL.md" ? withFrontmatterName(text, name) : text,
749
+ group: "skills"
750
+ });
751
+ }
752
+ }
753
+ for (const agent of manifest.agents) {
754
+ const text = await readOrNull(join5(dir, agent));
755
+ if (text === null)
756
+ continue;
757
+ const name = prefixed(frontmatterName(text) ?? basename2(agent, ".md"));
758
+ if (!safeName(name))
759
+ continue;
760
+ files.push({
761
+ path: `agents/${name}.md`,
762
+ content: withFrontmatterName(text, name),
763
+ group: "agents"
764
+ });
765
+ }
766
+ }
580
767
  return files.sort((x, y) => x.path.localeCompare(y.path));
581
768
  }
582
769
  async function computeRootFiles(o) {
@@ -620,7 +807,7 @@ async function computeRootFiles(o) {
620
807
  }
621
808
  const files = [];
622
809
  for (const spec of specs) {
623
- const old = await readOrNull(join3(o.workspaceDir, spec.path));
810
+ const old = await readOrNull(join5(o.workspaceDir, spec.path));
624
811
  const content = spec.make(old);
625
812
  files.push({
626
813
  path: spec.path,
@@ -654,20 +841,31 @@ function summarizeRootFiles(files) {
654
841
  }
655
842
  return out;
656
843
  }
844
+ function isSafeRootPath(workspaceDir, path) {
845
+ const abs = resolve2(workspaceDir, path);
846
+ const root = resolve2(workspaceDir);
847
+ if (abs === join5(root, "CLAUDE.md") || abs === join5(root, ".cursorrules"))
848
+ return true;
849
+ return [".claude", ".cursor"].some((d) => abs.startsWith(join5(root, d) + sep));
850
+ }
657
851
  async function writeRootFiles(o) {
658
852
  const files = await computeRootFiles(o);
659
853
  for (const file of files) {
660
854
  if (!file.changed)
661
855
  continue;
662
- const abs = join3(o.workspaceDir, file.path);
663
- await mkdir2(dirname(abs), { recursive: true });
664
- await writeFile2(abs, file.content);
856
+ if (!isSafeRootPath(o.workspaceDir, file.path)) {
857
+ console.warn(` skipped unsafe path: ${file.path}`);
858
+ continue;
859
+ }
860
+ const abs = join5(o.workspaceDir, file.path);
861
+ await mkdir3(dirname(abs), { recursive: true });
862
+ await writeFile3(abs, file.content);
665
863
  }
666
864
  return files;
667
865
  }
668
866
  function detectEditor(workspaceDir) {
669
- const claude = existsSync2(join3(workspaceDir, "CLAUDE.md")) || existsSync2(join3(workspaceDir, ".claude", "settings.json"));
670
- const cursor = existsSync2(join3(workspaceDir, ".cursorrules")) || existsSync2(join3(workspaceDir, ".cursor"));
867
+ const claude = existsSync4(join5(workspaceDir, "CLAUDE.md")) || existsSync4(join5(workspaceDir, ".claude", "settings.json"));
868
+ const cursor = existsSync4(join5(workspaceDir, ".cursorrules")) || existsSync4(join5(workspaceDir, ".cursor"));
671
869
  if (claude && cursor)
672
870
  return "both";
673
871
  if (claude)
@@ -679,14 +877,16 @@ function detectEditor(workspaceDir) {
679
877
  var BLOCK_BEGIN = "<!-- haren:begin -->", BLOCK_END = "<!-- haren:end -->", LEGACY_HEADING = "## Haren Framework", GATE_SCRIPT = "brainstorm-gate.ts", LEGACY_LAST_LINE = "Design specs are written to Haren artifact folders, NOT to docs/superpowers/specs/.", LEGACY_HEADINGS;
680
878
  var init_root_files = __esm(() => {
681
879
  init_content_dir();
880
+ init_manifest2();
881
+ init_state();
682
882
  init_templates();
683
883
  LEGACY_HEADINGS = new Set([LEGACY_HEADING, "## Brainstorming Gate"]);
684
884
  });
685
885
 
686
886
  // src/workspace/git.ts
687
- import { existsSync as existsSync3 } from "fs";
688
- import { mkdir as mkdir3, readdir as readdir2 } from "fs/promises";
689
- import { dirname as dirname2, join as join4, resolve as resolve2 } from "path";
887
+ import { existsSync as existsSync5 } from "fs";
888
+ import { mkdir as mkdir4, readdir as readdir2 } from "fs/promises";
889
+ import { dirname as dirname2, join as join6, resolve as resolve3 } from "path";
690
890
  function gitEnv(interactive = process.stdin.isTTY === true, base = process.env) {
691
891
  if (interactive)
692
892
  return { ...base };
@@ -715,7 +915,7 @@ async function runGit(args, cwd) {
715
915
  }
716
916
  }
717
917
  function hasGitDir(dir) {
718
- return existsSync3(join4(dir, ".git"));
918
+ return existsSync5(join6(dir, ".git"));
719
919
  }
720
920
  async function isInsideWorkTree(dir) {
721
921
  const result = await runGit(["rev-parse", "--is-inside-work-tree"], dir);
@@ -726,9 +926,9 @@ async function getRemoteUrl(dir) {
726
926
  return result.ok && result.stdout ? result.stdout : null;
727
927
  }
728
928
  async function cloneRepo(remote, dest) {
729
- const abs = resolve2(dest);
929
+ const abs = resolve3(dest);
730
930
  try {
731
- await mkdir3(dirname2(abs), { recursive: true });
931
+ await mkdir4(dirname2(abs), { recursive: true });
732
932
  } catch (err) {
733
933
  return { ok: false, stdout: "", stderr: String(err) };
734
934
  }
@@ -743,7 +943,7 @@ async function listChildRepos(dir) {
743
943
  for (const entry of entries) {
744
944
  if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
745
945
  continue;
746
- const path = join4(dir, entry.name);
946
+ const path = join6(dir, entry.name);
747
947
  if (!hasGitDir(path))
748
948
  continue;
749
949
  repos.push({ name: entry.name, path, remote: await getRemoteUrl(path) });
@@ -753,14 +953,14 @@ async function listChildRepos(dir) {
753
953
  var init_git = () => {};
754
954
 
755
955
  // src/workspace/resolve.ts
756
- import { existsSync as existsSync4 } from "fs";
757
- import { readdir as readdir3, readFile as readFile2, stat } from "fs/promises";
758
- import { dirname as dirname3, join as join5, resolve as resolve3 } from "path";
956
+ import { existsSync as existsSync6 } from "fs";
957
+ import { readdir as readdir3, readFile as readFile4, stat } from "fs/promises";
958
+ import { dirname as dirname3, join as join7, resolve as resolve4 } from "path";
759
959
  async function hasMarkedManifest(dir) {
760
- const path = join5(dir, "manifest.yaml");
761
- if (!existsSync4(path))
960
+ const path = join7(dir, "manifest.yaml");
961
+ if (!existsSync6(path))
762
962
  return false;
763
- const text = await readFile2(path, "utf-8").catch(() => null);
963
+ const text = await readFile4(path, "utf-8").catch(() => null);
764
964
  if (text === null)
765
965
  return false;
766
966
  try {
@@ -773,7 +973,7 @@ async function hasMarkedManifest(dir) {
773
973
  }
774
974
  }
775
975
  function isLegacyHarenDir(dir) {
776
- return existsSync4(join5(dir, "manifest.yaml")) && existsSync4(join5(dir, "skill.md"));
976
+ return existsSync6(join7(dir, "manifest.yaml")) && existsSync6(join7(dir, "skill.md"));
777
977
  }
778
978
  function location(harenDir, legacy) {
779
979
  return { harenDir, workspaceDir: dirname3(harenDir), legacy };
@@ -791,8 +991,8 @@ function harenDirFlag(args) {
791
991
  async function resolveHarenDir(cwd, opts = {}) {
792
992
  const explicit = opts.harenDir || opts.env?.HAREN_DIR;
793
993
  if (explicit) {
794
- const dir = resolve3(cwd, explicit);
795
- if (!existsSync4(join5(dir, "manifest.yaml"))) {
994
+ const dir = resolve4(cwd, explicit);
995
+ if (!existsSync6(join7(dir, "manifest.yaml"))) {
796
996
  throw new Error(`No manifest.yaml in ${dir}`);
797
997
  }
798
998
  return location(dir, !await hasMarkedManifest(dir));
@@ -804,7 +1004,7 @@ async function resolveHarenDir(cwd, opts = {}) {
804
1004
  for (const entry of entries) {
805
1005
  if (entry.name.startsWith(".") || entry.name === "node_modules")
806
1006
  continue;
807
- const dir = join5(cwd, entry.name);
1007
+ const dir = join7(cwd, entry.name);
808
1008
  const isDir = entry.isSymbolicLink() ? await stat(dir).then((st) => st.isDirectory(), () => false) : entry.isDirectory();
809
1009
  if (!isDir)
810
1010
  continue;
@@ -816,7 +1016,7 @@ async function resolveHarenDir(cwd, opts = {}) {
816
1016
  throw new MultipleHarenDirsError(matches);
817
1017
  if (matches.length === 1)
818
1018
  return location(matches[0], false);
819
- const legacyChild = join5(cwd, "haren");
1019
+ const legacyChild = join7(cwd, "haren");
820
1020
  if (isLegacyHarenDir(legacyChild))
821
1021
  return location(legacyChild, true);
822
1022
  if (isLegacyHarenDir(cwd))
@@ -840,7 +1040,7 @@ Pass --haren-dir <path> to choose one.`);
840
1040
  });
841
1041
 
842
1042
  // src/workspace/detect.ts
843
- import { existsSync as existsSync5 } from "fs";
1043
+ import { existsSync as existsSync7 } from "fs";
844
1044
  import { dirname as dirname4 } from "path";
845
1045
  async function inferLayout(dir) {
846
1046
  if (hasGitDir(dir))
@@ -849,7 +1049,7 @@ async function inferLayout(dir) {
849
1049
  if (childRepos.length > 0)
850
1050
  return { layout: "workspace", childRepos };
851
1051
  let probe = dir;
852
- while (!existsSync5(probe) && dirname4(probe) !== probe)
1052
+ while (!existsSync7(probe) && dirname4(probe) !== probe)
853
1053
  probe = dirname4(probe);
854
1054
  if (await isInsideWorkTree(probe))
855
1055
  return { layout: "monorepo", childRepos: [] };
@@ -872,8 +1072,8 @@ var init_detect = __esm(() => {
872
1072
  });
873
1073
 
874
1074
  // src/workspace/plan.ts
875
- import { existsSync as existsSync6 } from "fs";
876
- import { basename as basename2, relative as relative2, resolve as resolve4, sep as sep2 } from "path";
1075
+ import { existsSync as existsSync8 } from "fs";
1076
+ import { basename as basename3, relative as relative2, resolve as resolve5, sep as sep2 } from "path";
877
1077
  async function buildPlan(input) {
878
1078
  const items = [];
879
1079
  const generatedNote = input.layout === "workspace" ? "(generated, not versioned)" : undefined;
@@ -897,9 +1097,9 @@ async function buildPlan(input) {
897
1097
  items.push({ path: file.path, action: "keep", note: count });
898
1098
  }
899
1099
  for (const [key, repo] of Object.entries(input.repos)) {
900
- const abs = resolve4(input.harenDir, repo.path);
1100
+ const abs = resolve5(input.harenDir, repo.path);
901
1101
  const path = relative2(input.rootDir, abs).split(sep2).join("/") || key;
902
- if (existsSync6(abs)) {
1102
+ if (existsSync8(abs)) {
903
1103
  items.push(hasGitDir(abs) || input.layout === "monorepo" ? { path, action: "keep" } : { path, action: "warn", note: "! not a git repo" });
904
1104
  } else if (input.layout === "monorepo") {
905
1105
  items.push({ path, action: "warn", note: "! folder not found" });
@@ -911,7 +1111,7 @@ async function buildPlan(input) {
911
1111
  }
912
1112
  return {
913
1113
  rootDir: input.rootDir,
914
- harenDirName: basename2(input.harenDir),
1114
+ harenDirName: basename3(input.harenDir),
915
1115
  layout: input.layout,
916
1116
  createHaren: input.createHaren,
917
1117
  items,
@@ -979,6 +1179,53 @@ var init_plan = __esm(() => {
979
1179
  });
980
1180
 
981
1181
  // src/workspace/progress.ts
1182
+ import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
1183
+ async function readProgress(path) {
1184
+ const raw = await readFile5(path, "utf-8");
1185
+ const progress = JSON.parse(raw);
1186
+ progress.modules ??= {};
1187
+ for (const mod of Object.values(progress.modules)) {
1188
+ if (!isObject(mod.features))
1189
+ mod.features = {};
1190
+ if (!isObject(mod.lastCommit))
1191
+ mod.lastCommit = {};
1192
+ }
1193
+ return progress;
1194
+ }
1195
+ function isObject(value) {
1196
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1197
+ }
1198
+ async function writeProgress(path, progress) {
1199
+ await writeFile4(path, JSON.stringify(progress, null, 2));
1200
+ }
1201
+ function updateFeatureStatus(progress, moduleName, featureName, newStatus) {
1202
+ const mod = progress.modules[moduleName];
1203
+ if (!mod) {
1204
+ throw new Error(`Module '${moduleName}' not found`);
1205
+ }
1206
+ const currentStatus = mod.features[featureName];
1207
+ if (currentStatus === undefined) {
1208
+ throw new Error(`Feature '${featureName}' not found in module '${moduleName}'`);
1209
+ }
1210
+ const allowed = VALID_FEATURE_TRANSITIONS[currentStatus];
1211
+ if (!allowed.includes(newStatus)) {
1212
+ throw new Error(`Invalid feature transition: ${currentStatus} \u2192 ${newStatus}. Allowed: ${allowed.join(", ")}`);
1213
+ }
1214
+ return {
1215
+ ...progress,
1216
+ modules: {
1217
+ ...progress.modules,
1218
+ [moduleName]: {
1219
+ ...mod,
1220
+ features: {
1221
+ ...mod.features,
1222
+ [featureName]: newStatus
1223
+ },
1224
+ lastUpdated: new Date().toISOString()
1225
+ }
1226
+ }
1227
+ };
1228
+ }
982
1229
  function migrateProgress(raw, repoKeyFor) {
983
1230
  if (!raw || typeof raw !== "object")
984
1231
  return { progress: raw, changed: false };
@@ -998,19 +1245,28 @@ function migrateProgress(raw, repoKeyFor) {
998
1245
  }
999
1246
  return { progress: { ...data, version: PROGRESS_VERSION, modules }, changed: true };
1000
1247
  }
1001
- var PROGRESS_VERSION = 2;
1002
- var init_progress = () => {};
1248
+ var VALID_FEATURE_TRANSITIONS, PROGRESS_VERSION = 2;
1249
+ var init_progress = __esm(() => {
1250
+ VALID_FEATURE_TRANSITIONS = {
1251
+ pending: ["in-progress"],
1252
+ "in-progress": ["evaluating"],
1253
+ evaluating: ["passing", "fixing", "blocked"],
1254
+ fixing: ["evaluating"],
1255
+ passing: [],
1256
+ blocked: ["in-progress"]
1257
+ };
1258
+ });
1003
1259
 
1004
1260
  // src/lib/version.ts
1005
- import { existsSync as existsSync7, readFileSync } from "fs";
1006
- import { resolve as resolve5 } from "path";
1261
+ import { existsSync as existsSync9, readFileSync } from "fs";
1262
+ import { resolve as resolve6 } from "path";
1007
1263
  function readHarenVersion(candidates) {
1008
1264
  const probes = candidates ?? [
1009
- resolve5(import.meta.dir, "..", "package.json"),
1010
- resolve5(import.meta.dir, "..", "..", "package.json")
1265
+ resolve6(import.meta.dir, "..", "package.json"),
1266
+ resolve6(import.meta.dir, "..", "..", "package.json")
1011
1267
  ];
1012
1268
  for (const path of probes) {
1013
- if (!existsSync7(path))
1269
+ if (!existsSync9(path))
1014
1270
  continue;
1015
1271
  try {
1016
1272
  const pkg = JSON.parse(readFileSync(path, "utf-8"));
@@ -1027,11 +1283,287 @@ var init_version = __esm(() => {
1027
1283
  HAREN_VERSION = readHarenVersion();
1028
1284
  });
1029
1285
 
1286
+ // src/plugins/registry.ts
1287
+ function npmPackageName(spec) {
1288
+ const at = spec.indexOf("@", spec.startsWith("@") ? 1 : 0);
1289
+ return at === -1 ? spec : spec.slice(0, at);
1290
+ }
1291
+ function isOfficialSource(source) {
1292
+ if (source.startsWith("npm:")) {
1293
+ const name = npmPackageName(source.slice(4));
1294
+ return REGISTRY.some((e) => e.source.startsWith("npm:") && npmPackageName(e.source.slice(4)) === name);
1295
+ }
1296
+ return REGISTRY.some((e) => e.source === source);
1297
+ }
1298
+ function resolvePluginRef(ref) {
1299
+ if (/^(npm|git|file):/.test(ref)) {
1300
+ return { source: ref, official: isOfficialSource(ref) };
1301
+ }
1302
+ const entry = REGISTRY.find((e) => e.name === ref);
1303
+ if (!entry)
1304
+ throw new Error(`Unknown plugin: ${ref}. Use a registry name or npm:/git:/file: source.`);
1305
+ return { source: entry.source, official: true };
1306
+ }
1307
+ var REGISTRY;
1308
+ var init_registry = __esm(() => {
1309
+ REGISTRY = [
1310
+ {
1311
+ name: "backlog",
1312
+ source: "npm:@odarino/backlog.md",
1313
+ description: "Two-way sync between haren tasks and a Backlog.md board"
1314
+ }
1315
+ ];
1316
+ });
1317
+
1318
+ // src/plugins/requires.ts
1319
+ function extractVersion(text) {
1320
+ return /(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/.exec(text)?.[1];
1321
+ }
1322
+ async function checkRequirement(req, env = process.env) {
1323
+ const path = Bun.which(req.bin, { PATH: env.PATH ?? "" });
1324
+ if (!path)
1325
+ return { ok: false, reason: "missing" };
1326
+ if (!req.version)
1327
+ return { ok: true };
1328
+ const proc = Bun.spawn([path, "--version"], {
1329
+ stdout: "pipe",
1330
+ stderr: "pipe",
1331
+ env
1332
+ });
1333
+ const [out] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
1334
+ const version = extractVersion(out);
1335
+ if (!version || !Bun.semver.satisfies(version, req.version)) {
1336
+ return { ok: false, reason: "outdated", version: version ?? "unknown" };
1337
+ }
1338
+ return { ok: true, version };
1339
+ }
1340
+
1341
+ // src/plugins/source.ts
1342
+ import { existsSync as existsSync10 } from "fs";
1343
+ import { cp, mkdir as mkdir5, mkdtemp, readFile as readFile6, rm } from "fs/promises";
1344
+ import { tmpdir } from "os";
1345
+ import { isAbsolute as isAbsolute2, join as join8, resolve as resolve7 } from "path";
1346
+ function parseSource(text) {
1347
+ const match = /^(npm|git|file):(.*)$/.exec(text);
1348
+ if (!match)
1349
+ throw new Error(`Plugin source must start with npm:, git:, or file: \u2014 got ${text}`);
1350
+ const [, kind, rest] = match;
1351
+ if (!rest)
1352
+ throw new Error(`Plugin source is empty: ${text}`);
1353
+ if (kind !== "file" && rest.startsWith("-"))
1354
+ throw new Error(`Plugin source must not start with "-": ${text}`);
1355
+ if (kind === "npm")
1356
+ return { kind, spec: rest };
1357
+ if (kind === "file")
1358
+ return { kind, path: rest };
1359
+ const hash = rest.lastIndexOf("#");
1360
+ return hash > 0 ? { kind, url: rest.slice(0, hash), ref: rest.slice(hash + 1) } : { kind, url: rest };
1361
+ }
1362
+ async function run(cmd, cwd) {
1363
+ const proc = Bun.spawn(cmd, { cwd, stdout: "pipe", stderr: "pipe" });
1364
+ const [stderr, code] = await Promise.all([new Response(proc.stderr).text(), proc.exited]);
1365
+ if (code !== 0)
1366
+ throw new Error(`${cmd.join(" ")} failed: ${stderr.trim().split(`
1367
+ `).pop()}`);
1368
+ }
1369
+ async function fetchPlugin(source, destDir, cwd) {
1370
+ const parsed = parseSource(source);
1371
+ const work = await mkdtemp(join8(tmpdir(), "haren-plugin-"));
1372
+ let root;
1373
+ try {
1374
+ if (parsed.kind === "file") {
1375
+ root = isAbsolute2(parsed.path) ? parsed.path : resolve7(cwd, parsed.path);
1376
+ } else if (parsed.kind === "git") {
1377
+ root = join8(work, "repo");
1378
+ const ref = parsed.ref ? ["--branch", parsed.ref] : [];
1379
+ await run(["git", "clone", "--depth", "1", "-q", ...ref, "--", parsed.url, root]);
1380
+ await rm(join8(root, ".git"), { recursive: true, force: true });
1381
+ } else {
1382
+ await run(["npm", "pack", "--silent", "--pack-destination", work, "--", parsed.spec], work);
1383
+ const tgz = (await Array.fromAsync(new Bun.Glob("*.tgz").scan(work)))[0];
1384
+ if (!tgz)
1385
+ throw new Error(`npm pack ${parsed.spec} produced no archive`);
1386
+ await run(["tar", "-xzf", tgz], work);
1387
+ root = join8(work, "package");
1388
+ }
1389
+ const manifestPath = join8(root, "haren-plugin.json");
1390
+ if (!existsSync10(manifestPath))
1391
+ throw new Error(`No haren-plugin.json in ${source}`);
1392
+ const raw = JSON.parse(await readFile6(manifestPath, "utf-8"));
1393
+ let packageVersion;
1394
+ if (parsed.kind === "npm") {
1395
+ packageVersion = JSON.parse(await readFile6(join8(root, "package.json"), "utf-8")).version;
1396
+ }
1397
+ const manifest = validateManifest(raw, packageVersion);
1398
+ await rm(destDir, { recursive: true, force: true });
1399
+ await mkdir5(destDir, { recursive: true });
1400
+ await cp(root, destDir, { recursive: true });
1401
+ return manifest;
1402
+ } finally {
1403
+ await rm(work, { recursive: true, force: true });
1404
+ }
1405
+ }
1406
+ var init_source = __esm(() => {
1407
+ init_manifest2();
1408
+ });
1409
+
1410
+ // src/plugins/install.ts
1411
+ import { existsSync as existsSync11 } from "fs";
1412
+ import { readFile as readFile7, rename, rm as rm2 } from "fs/promises";
1413
+ import { join as join9, relative as relative3, resolve as resolve8, sep as sep3 } from "path";
1414
+ async function sh(command, cwd) {
1415
+ const proc = Bun.spawn(["sh", "-c", command], { cwd, stdout: "inherit", stderr: "pipe" });
1416
+ const [stderr, code] = await Promise.all([new Response(proc.stderr).text(), proc.exited]);
1417
+ if (code !== 0)
1418
+ throw new Error(`"${command}" failed: ${stderr.trim().split(`
1419
+ `).pop() ?? `exit ${code}`}`);
1420
+ }
1421
+ async function harenLayout(harenDir) {
1422
+ const path = join9(harenDir, "manifest.yaml");
1423
+ if (!existsSync11(path))
1424
+ return "workspace";
1425
+ try {
1426
+ return parseManifest(await readFile7(path, "utf-8")).layout ?? "workspace";
1427
+ } catch {
1428
+ return "workspace";
1429
+ }
1430
+ }
1431
+ async function stage(source, ctx) {
1432
+ await rm2(incomingDir(ctx), { recursive: true, force: true });
1433
+ return fetchPlugin(source, incomingDir(ctx), ctx.workspaceDir);
1434
+ }
1435
+ async function commit(manifest, ctx) {
1436
+ const dest = pluginDir(ctx.harenDir, manifest.name);
1437
+ await rm2(dest, { recursive: true, force: true });
1438
+ await rename(incomingDir(ctx), dest);
1439
+ }
1440
+ async function installPlugin(ref, ctx) {
1441
+ const { source, official } = resolvePluginRef(ref);
1442
+ if (!official) {
1443
+ ctx.io.log("This plugin is not in the haren registry. Its hooks run as code with your user permissions.");
1444
+ if (!await ctx.io.confirm("Install it?"))
1445
+ throw new Error("Plugin install cancelled");
1446
+ }
1447
+ const manifest = await stage(source, ctx);
1448
+ try {
1449
+ for (const req of manifest.requires) {
1450
+ let status = await checkRequirement(req, ctx.env);
1451
+ if (!status.ok && req.install && await ctx.io.confirm(`Run "${req.install}"?`)) {
1452
+ await sh(req.install, ctx.workspaceDir);
1453
+ status = await checkRequirement(req, ctx.env);
1454
+ }
1455
+ if (!status.ok)
1456
+ throw new Error(`${req.bin} is required: ${status.reason}`);
1457
+ }
1458
+ const harenRel = relative3(ctx.workspaceDir, ctx.harenDir).split(sep3).join("/");
1459
+ const layout = await harenLayout(ctx.harenDir);
1460
+ for (const command of manifest.setup) {
1461
+ await sh(command.replaceAll("{{project}}", ctx.project).replaceAll("{{harenDir}}", harenRel).replaceAll("{{layout}}", layout), ctx.workspaceDir);
1462
+ }
1463
+ await commit(manifest, ctx);
1464
+ } finally {
1465
+ await rm2(incomingDir(ctx), { recursive: true, force: true });
1466
+ }
1467
+ const state = await readPlugins(ctx.harenDir);
1468
+ state.plugins[manifest.name] = {
1469
+ source,
1470
+ version: manifest.version,
1471
+ enabled: true,
1472
+ config: state.plugins[manifest.name]?.config ?? {}
1473
+ };
1474
+ await writePlugins(ctx.harenDir, state);
1475
+ ctx.io.log(`Installed plugin ${manifest.name} ${manifest.version}`);
1476
+ return manifest;
1477
+ }
1478
+ async function removePlugin(name, ctx) {
1479
+ const state = await readPlugins(ctx.harenDir);
1480
+ if (!state.plugins[name])
1481
+ throw new Error(`Plugin ${name} is not installed`);
1482
+ delete state.plugins[name];
1483
+ await writePlugins(ctx.harenDir, state);
1484
+ await rm2(pluginDir(ctx.harenDir, name), { recursive: true, force: true });
1485
+ }
1486
+ async function removeEditorCopies(workspaceDir, files) {
1487
+ const targets = new Set;
1488
+ for (const f of files) {
1489
+ const [group, name] = f.path.split("/");
1490
+ if (!name)
1491
+ continue;
1492
+ targets.add(`${group}/${group === "skills" ? name : f.path.slice(group.length + 1)}`);
1493
+ }
1494
+ for (const editor of [".claude", ".cursor"]) {
1495
+ for (const t of targets) {
1496
+ const group = t.split("/")[0];
1497
+ const abs = resolve8(workspaceDir, editor, t);
1498
+ if (!abs.startsWith(resolve8(workspaceDir, editor, group) + sep3))
1499
+ continue;
1500
+ await rm2(abs, { recursive: true, force: true });
1501
+ }
1502
+ }
1503
+ }
1504
+ async function missingPlugins(harenDir) {
1505
+ const state = await readPlugins(harenDir);
1506
+ return Object.entries(state.plugins).filter(([name, e]) => e.enabled && !existsSync11(join9(pluginDir(harenDir, name), "haren-plugin.json"))).map(([name]) => name);
1507
+ }
1508
+ async function restorePlugins(ctx, report) {
1509
+ const restored = [];
1510
+ const state = await readPlugins(ctx.harenDir);
1511
+ for (const name of await missingPlugins(ctx.harenDir)) {
1512
+ const source = state.plugins[name].source;
1513
+ ctx.io.log(`Restoring plugin ${name} from ${source}`);
1514
+ try {
1515
+ const manifest = await installPlugin(source, ctx);
1516
+ if (manifest.name !== name) {
1517
+ report.warn(`plugin ${name}: source now installs ${manifest.name}`);
1518
+ }
1519
+ restored.push(manifest.name);
1520
+ } catch (err) {
1521
+ const message = err.message;
1522
+ if (message === "Plugin install cancelled") {
1523
+ report.warn(`plugin ${name}: skipped, not confirmed. Run again with --yes to install it.`);
1524
+ } else {
1525
+ report.error(`plugin ${name}: ${message}`);
1526
+ }
1527
+ }
1528
+ }
1529
+ return restored;
1530
+ }
1531
+ async function refreshPlugins(ctx, skip = []) {
1532
+ const warnings = [];
1533
+ const state = await readPlugins(ctx.harenDir);
1534
+ for (const [name, entry] of Object.entries(state.plugins)) {
1535
+ if (!entry.enabled || skip.includes(name))
1536
+ continue;
1537
+ try {
1538
+ const manifest = await stage(entry.source, ctx);
1539
+ if (manifest.name !== name) {
1540
+ warnings.push(`plugin ${name}: kept ${entry.version}: manifest name changed to ${manifest.name}`);
1541
+ continue;
1542
+ }
1543
+ await commit(manifest, ctx);
1544
+ entry.version = manifest.version;
1545
+ } catch (err) {
1546
+ warnings.push(`plugin ${name}: kept ${entry.version}: ${err.message}`);
1547
+ } finally {
1548
+ await rm2(incomingDir(ctx), { recursive: true, force: true });
1549
+ }
1550
+ }
1551
+ await writePlugins(ctx.harenDir, state);
1552
+ return warnings;
1553
+ }
1554
+ var incomingDir = (ctx) => pluginDir(ctx.harenDir, ".incoming");
1555
+ var init_install = __esm(() => {
1556
+ init_registry();
1557
+ init_source();
1558
+ init_state();
1559
+ init_manifest();
1560
+ });
1561
+
1030
1562
  // src/commands/init.ts
1031
- import { mkdir as mkdir4, writeFile as writeFile3, readdir as readdir4, copyFile, readFile as readFile3 } from "fs/promises";
1032
- import { existsSync as existsSync8, realpathSync } from "fs";
1563
+ import { mkdir as mkdir6, writeFile as writeFile5, readdir as readdir4, copyFile, readFile as readFile8 } from "fs/promises";
1564
+ import { existsSync as existsSync12, realpathSync } from "fs";
1033
1565
  import { homedir } from "os";
1034
- import { basename as basename3, join as join6, resolve as resolve6 } from "path";
1566
+ import { basename as basename4, join as join10, resolve as resolve9 } from "path";
1035
1567
  function readLine() {
1036
1568
  return new Promise((resolve) => {
1037
1569
  const stdin = process.stdin;
@@ -1197,10 +1729,10 @@ function getDirectories(iterations) {
1197
1729
  }
1198
1730
  async function copyRecursive(src, dest) {
1199
1731
  const entries = await readdir4(src, { withFileTypes: true });
1200
- await mkdir4(dest, { recursive: true });
1732
+ await mkdir6(dest, { recursive: true });
1201
1733
  for (const entry of entries) {
1202
- const srcPath = join6(src, entry.name);
1203
- const destPath = join6(dest, entry.name);
1734
+ const srcPath = join10(src, entry.name);
1735
+ const destPath = join10(dest, entry.name);
1204
1736
  if (entry.isDirectory()) {
1205
1737
  await copyRecursive(srcPath, destPath);
1206
1738
  } else {
@@ -1210,9 +1742,9 @@ async function copyRecursive(src, dest) {
1210
1742
  }
1211
1743
  async function scaffoldWorkspace(targetDir, options) {
1212
1744
  for (const dir of getDirectories(!!options.iterations)) {
1213
- await mkdir4(join6(targetDir, dir), { recursive: true });
1745
+ await mkdir6(join10(targetDir, dir), { recursive: true });
1214
1746
  }
1215
- await writeFile3(join6(targetDir, "manifest.yaml"), buildManifestText({
1747
+ await writeFile5(join10(targetDir, "manifest.yaml"), buildManifestText({
1216
1748
  version: HAREN_VERSION,
1217
1749
  layout: options.layout ?? "monorepo",
1218
1750
  project: options.project,
@@ -1232,40 +1764,42 @@ async function scaffoldWorkspace(targetDir, options) {
1232
1764
  if (options.iterations) {
1233
1765
  progressData.currentIteration = 1;
1234
1766
  }
1235
- await writeFile3(join6(targetDir, "progress.json"), JSON.stringify(progressData, null, 2));
1236
- await writeFile3(join6(targetDir, "FEEDBACK.md"), `# Haren Framework Feedback
1767
+ await writeFile5(join10(targetDir, "progress.json"), JSON.stringify(progressData, null, 2));
1768
+ await writeFile5(join10(targetDir, "FEEDBACK.md"), `# Haren Framework Feedback
1237
1769
 
1238
1770
  Append-only log of framework improvement suggestions captured during usage.
1239
1771
 
1240
1772
  ---
1241
1773
  `);
1242
- await writeFile3(join6(targetDir, "artifacts", "_registry", "artifact-index.md"), `# Artifact Index
1774
+ await writeFile5(join10(targetDir, "artifacts", "_registry", "artifact-index.md"), `# Artifact Index
1243
1775
 
1244
1776
  Master registry of all artifacts in this Haren workspace.
1245
1777
 
1246
1778
  | ID | Type | Module | Status | Path |
1247
1779
  |----|------|--------|--------|------|
1248
1780
  `);
1249
- await writeFile3(join6(targetDir, "events", "events.jsonl"), "");
1250
- const gitignore = join6(targetDir, ".gitignore");
1251
- if (!existsSync8(gitignore))
1252
- await writeFile3(gitignore, `.agent.json
1781
+ await writeFile5(join10(targetDir, "events", "events.jsonl"), "");
1782
+ const gitignore = join10(targetDir, ".gitignore");
1783
+ if (!existsSync12(gitignore))
1784
+ await writeFile5(gitignore, `.agent.json
1253
1785
  .agent.pid
1786
+ .plugins/
1254
1787
  `);
1255
1788
  await writeGateScript(targetDir);
1256
1789
  await scaffoldSkillMd(targetDir);
1257
1790
  const contentDir = resolveContentDir();
1258
- await copyRecursive(join6(contentDir, "agents"), join6(targetDir, "agents"));
1259
- await copyRecursive(join6(contentDir, "skills"), join6(targetDir, "skills"));
1260
- await copyRecursive(join6(contentDir, "templates"), join6(targetDir, "templates"));
1791
+ await copyRecursive(join10(contentDir, "agents"), join10(targetDir, "agents"));
1792
+ await copyRecursive(join10(contentDir, "skills"), join10(targetDir, "skills"));
1793
+ await copyRecursive(join10(contentDir, "templates"), join10(targetDir, "templates"));
1794
+ await options.beforeRootFiles?.();
1261
1795
  await writeRootFiles({
1262
- workspaceDir: resolve6(targetDir, ".."),
1796
+ workspaceDir: resolve9(targetDir, ".."),
1263
1797
  harenDir: targetDir,
1264
1798
  editor: options.editor ?? "claude-code"
1265
1799
  });
1266
1800
  }
1267
1801
  async function scaffoldSkillMd(targetDir) {
1268
- await writeFile3(join6(targetDir, "skill.md"), `---
1802
+ await writeFile5(join10(targetDir, "skill.md"), `---
1269
1803
  name: haren
1270
1804
  description: Agentic SDLC framework \u2014 orchestrates AI agents through structured phases
1271
1805
  ---
@@ -1380,7 +1914,8 @@ function parseInitArgs(args) {
1380
1914
  const out = {
1381
1915
  force: args.includes("--force"),
1382
1916
  yes: args.includes("--yes") || args.includes("-y"),
1383
- dryRun: args.includes("--dry-run")
1917
+ dryRun: args.includes("--dry-run"),
1918
+ plugins: []
1384
1919
  };
1385
1920
  for (let i = 0;i < args.length; i++) {
1386
1921
  const value = args[i + 1];
@@ -1404,6 +1939,13 @@ function parseInitArgs(args) {
1404
1939
  out.harenDir = value;
1405
1940
  i++;
1406
1941
  break;
1942
+ case "--plugin":
1943
+ if (value === undefined || value === "" || value.startsWith("-")) {
1944
+ throw new Error("--plugin needs a name or source");
1945
+ }
1946
+ out.plugins.push(value);
1947
+ i++;
1948
+ break;
1407
1949
  case "--mode":
1408
1950
  if (!MODES.includes(value)) {
1409
1951
  throw new Error(`Invalid mode: ${value}. Must be blueprint, explore, inherit, or undecided.`);
@@ -1458,7 +2000,7 @@ async function applyClones(plan, rootDir) {
1458
2000
  if (item.action !== "clone" || !item.remote)
1459
2001
  continue;
1460
2002
  console.log(` \x1B[36m\u2193\x1B[0m Cloning ${item.path} ...`);
1461
- const result = await cloneRepo(item.remote, join6(rootDir, item.path));
2003
+ const result = await cloneRepo(item.remote, join10(rootDir, item.path));
1462
2004
  if (!result.ok) {
1463
2005
  console.error(` \x1B[31m\u2717\x1B[0m ${item.path}: ${result.stderr.split(`
1464
2006
  `).pop()}`);
@@ -1470,6 +2012,48 @@ async function applyClones(plan, rootDir) {
1470
2012
  function canPrompt(opts) {
1471
2013
  return !opts.yes && process.stdin.isTTY === true;
1472
2014
  }
2015
+ async function setupPlugins(opts, workspaceDir, harenDir, project) {
2016
+ let refs = opts.plugins;
2017
+ if (refs.length === 0 && canPrompt(opts) && REGISTRY.length > 0) {
2018
+ const picked = await promptMultiSelect("Install plugins?", REGISTRY.map((e) => `${e.name.padEnd(12)} ${e.description}`), []);
2019
+ refs = picked.map((i) => REGISTRY[i].name);
2020
+ }
2021
+ for (const ref of refs) {
2022
+ try {
2023
+ await installPlugin(ref, {
2024
+ workspaceDir,
2025
+ harenDir,
2026
+ project,
2027
+ io: {
2028
+ confirm: async (q) => {
2029
+ console.log(` ${q}`);
2030
+ return opts.yes || canPrompt(opts) && await promptConfirm(false) === "yes";
2031
+ },
2032
+ log: (l) => console.log(` ${l}`)
2033
+ }
2034
+ });
2035
+ } catch (err) {
2036
+ console.error(` \x1B[31m\u2717\x1B[0m plugin ${ref}: ${err.message}`);
2037
+ }
2038
+ }
2039
+ }
2040
+ async function restoreMissing(opts, location, project) {
2041
+ await restorePlugins({
2042
+ workspaceDir: location.workspaceDir,
2043
+ harenDir: location.harenDir,
2044
+ project,
2045
+ io: {
2046
+ confirm: async (q) => {
2047
+ console.log(` ${q}`);
2048
+ return opts.yes || canPrompt(opts) && await promptConfirm(false) === "yes";
2049
+ },
2050
+ log: (l) => console.log(` ${l}`)
2051
+ }
2052
+ }, {
2053
+ warn: (l) => console.warn(` \x1B[33m!\x1B[0m ${l}`),
2054
+ error: (l) => console.error(` \x1B[31m\u2717\x1B[0m ${l}`)
2055
+ });
2056
+ }
1473
2057
  async function confirmOrExit(opts, allowEdit) {
1474
2058
  if (opts.yes)
1475
2059
  return "yes";
@@ -1524,7 +2108,7 @@ async function runSetup(location, opts) {
1524
2108
  console.log(" Run 'haren upgrade' to migrate it.");
1525
2109
  return;
1526
2110
  }
1527
- const manifest = parseManifest(await readFile3(join6(location.harenDir, "manifest.yaml"), "utf-8"));
2111
+ const manifest = parseManifest(await readFile8(join10(location.harenDir, "manifest.yaml"), "utf-8"));
1528
2112
  const layout = manifest.layout ?? "workspace";
1529
2113
  let editor = opts.editor ?? detectEditor(location.workspaceDir);
1530
2114
  if (!editor) {
@@ -1539,8 +2123,22 @@ async function runSetup(location, opts) {
1539
2123
  editor
1540
2124
  });
1541
2125
  console.log(` Found haren folder: ${location.harenDir}`);
1542
- if (isNoop(plan)) {
1543
- console.log(" Already set up. Run 'haren upgrade' to update framework files.");
2126
+ const missing = await missingPlugins(location.harenDir);
2127
+ if (isNoop(plan) && opts.plugins.length === 0) {
2128
+ if (missing.length === 0) {
2129
+ console.log(" Already set up. Run 'haren upgrade' to update framework files.");
2130
+ return;
2131
+ }
2132
+ if (opts.dryRun) {
2133
+ console.log(` Plugins to restore: ${missing.join(", ")}`);
2134
+ return;
2135
+ }
2136
+ await restoreMissing(opts, location, manifest.project ?? "");
2137
+ await writeRootFiles({
2138
+ workspaceDir: location.workspaceDir,
2139
+ harenDir: location.harenDir,
2140
+ editor
2141
+ });
1544
2142
  return;
1545
2143
  }
1546
2144
  console.log("");
@@ -1551,6 +2149,8 @@ async function runSetup(location, opts) {
1551
2149
  if (await confirmOrExit(opts, false) === "no")
1552
2150
  return;
1553
2151
  const failed = await applyClones(plan, location.workspaceDir);
2152
+ await restoreMissing(opts, location, manifest.project ?? "");
2153
+ await setupPlugins(opts, location.workspaceDir, location.harenDir, manifest.project ?? "");
1554
2154
  await writeRootFiles({
1555
2155
  workspaceDir: location.workspaceDir,
1556
2156
  harenDir: location.harenDir,
@@ -1578,7 +2178,7 @@ function realPath(path) {
1578
2178
  try {
1579
2179
  return realpathSync(path);
1580
2180
  } catch {
1581
- return resolve6(path);
2181
+ return resolve9(path);
1582
2182
  }
1583
2183
  }
1584
2184
  async function init(args) {
@@ -1589,13 +2189,13 @@ async function init(args) {
1589
2189
  console.error(` ${err.message}`);
1590
2190
  process.exit(1);
1591
2191
  }
1592
- const cwdRoot = resolve6(opts.dir?.replace(/^~(?=$|\/)/, process.env.HOME ?? "~") ?? process.cwd());
2192
+ const cwdRoot = resolve9(opts.dir?.replace(/^~(?=$|\/)/, process.env.HOME ?? "~") ?? process.cwd());
1593
2193
  if (!opts.force && realPath(cwdRoot) === realPath(homedir())) {
1594
2194
  console.error(" Refusing to set up haren in your home folder. Choose a project folder, for example ~/my-project (or pass --force).");
1595
2195
  process.exit(1);
1596
2196
  }
1597
2197
  printBanner();
1598
- const explicitHarenDir = opts.harenDir && existsSync8(join6(cwdRoot, opts.harenDir, "manifest.yaml")) ? opts.harenDir : undefined;
2198
+ const explicitHarenDir = opts.harenDir && existsSync12(join10(cwdRoot, opts.harenDir, "manifest.yaml")) ? opts.harenDir : undefined;
1599
2199
  let detection;
1600
2200
  try {
1601
2201
  detection = await detectLayout(cwdRoot, { harenDir: explicitHarenDir, env: process.env });
@@ -1612,7 +2212,7 @@ async function init(args) {
1612
2212
  let existingLayout;
1613
2213
  if (detection.kind === "existing" && detection.location) {
1614
2214
  const loc = detection.location;
1615
- existingManifest = parseManifest(await readFile3(join6(loc.harenDir, "manifest.yaml"), "utf-8"));
2215
+ existingManifest = parseManifest(await readFile8(join10(loc.harenDir, "manifest.yaml"), "utf-8"));
1616
2216
  existingRepos = normalizeRepos(existingManifest.repos);
1617
2217
  existingLayout = existingManifest.layout ?? (await inferLayout(loc.workspaceDir)).layout ?? "workspace";
1618
2218
  }
@@ -1625,12 +2225,12 @@ async function init(args) {
1625
2225
  }, "workspace") : "workspace");
1626
2226
  console.log(` Layout detected: ${layout === "monorepo" ? "monorepo (inside a git repo)" : "multi-repo workspace (no .git at root)"}`);
1627
2227
  console.log("");
1628
- const harenDirName = opts.harenDir ?? (existingLoc ? basename3(existingLoc.harenDir) : interactive ? await prompt("haren folder name:", "haren") : "haren");
1629
- const harenDir = existingLoc && !opts.harenDir ? existingLoc.harenDir : join6(rootDir, harenDirName);
2228
+ const harenDirName = opts.harenDir ?? (existingLoc ? basename4(existingLoc.harenDir) : interactive ? await prompt("haren folder name:", "haren") : "haren");
2229
+ const harenDir = existingLoc && !opts.harenDir ? existingLoc.harenDir : join10(rootDir, harenDirName);
1630
2230
  const children = (existingRepos ? [] : detection.childRepos).filter((r) => r.name !== harenDirName);
1631
2231
  const defaults = children.flatMap((r, i) => r.remote ? [i] : []);
1632
2232
  let selected = defaults;
1633
- const project = opts.project ?? existingManifest?.project ?? (interactive ? await prompt("Project name:", basename3(rootDir)) : basename3(rootDir));
2233
+ const project = opts.project ?? existingManifest?.project ?? (interactive ? await prompt("Project name:", basename4(rootDir)) : basename4(rootDir));
1634
2234
  const existingMode = MODES.find((m) => m === existingManifest?.mode);
1635
2235
  const mode = opts.mode ?? existingMode ?? (interactive ? await promptSelect("Mode:", MODES, MODE_DESCRIPTIONS, "undecided") : "undecided");
1636
2236
  const language = opts.language ?? existingManifest?.language ?? (interactive ? await prompt("Preferred language:", "English") : "English");
@@ -1666,7 +2266,7 @@ ${renderReposBlock(repos)}`
1666
2266
  if (answer === "edit")
1667
2267
  continue;
1668
2268
  const failed = layout === "workspace" ? await applyClones(plan, rootDir) : [];
1669
- await mkdir4(harenDir, { recursive: true });
2269
+ await mkdir6(harenDir, { recursive: true });
1670
2270
  await scaffoldWorkspace(harenDir, {
1671
2271
  project,
1672
2272
  mode,
@@ -1674,7 +2274,8 @@ ${renderReposBlock(repos)}`
1674
2274
  iterations,
1675
2275
  editor,
1676
2276
  layout,
1677
- repos
2277
+ repos,
2278
+ beforeRootFiles: () => setupPlugins(opts, rootDir, harenDir, project)
1678
2279
  });
1679
2280
  if (layout === "workspace" && !hasGitDir(harenDir)) {
1680
2281
  const result = await gitInit(harenDir);
@@ -1703,6 +2304,8 @@ var init_init = __esm(() => {
1703
2304
  init_git();
1704
2305
  init_progress();
1705
2306
  init_version();
2307
+ init_install();
2308
+ init_registry();
1706
2309
  MODES = ["blueprint", "explore", "inherit", "undecided"];
1707
2310
  EDITORS = ["claude-code", "cursor", "both"];
1708
2311
  EDITOR_DESCRIPTIONS = {
@@ -1719,20 +2322,20 @@ var init_init = __esm(() => {
1719
2322
  });
1720
2323
 
1721
2324
  // src/commands/upgrade.ts
1722
- import { mkdir as mkdir5, readdir as readdir5, copyFile as copyFile2, readFile as readFile4, stat as stat2, writeFile as writeFile4 } from "fs/promises";
1723
- import { join as join7, resolve as resolve7 } from "path";
1724
- import { existsSync as existsSync9 } from "fs";
2325
+ import { mkdir as mkdir7, readdir as readdir5, copyFile as copyFile2, readFile as readFile9, stat as stat2, writeFile as writeFile6 } from "fs/promises";
2326
+ import { join as join11, resolve as resolve10 } from "path";
2327
+ import { existsSync as existsSync13 } from "fs";
1725
2328
  async function moduleRepoKey(harenDir, moduleName) {
1726
- const path = join7(harenDir, "artifacts", "03-modules", moduleName, "module.md");
1727
- if (!existsSync9(path))
2329
+ const path = join11(harenDir, "artifacts", "03-modules", moduleName, "module.md");
2330
+ if (!existsSync13(path))
1728
2331
  return;
1729
- const match = (await readFile4(path, "utf-8")).match(/^repos:\s*\[([^\]]*)\]/m);
2332
+ const match = (await readFile9(path, "utf-8")).match(/^repos:\s*\[([^\]]*)\]/m);
1730
2333
  return match?.[1].split(",")[0]?.trim().replace(/^["']|["']$/g, "") || undefined;
1731
2334
  }
1732
2335
  async function planMigration(location) {
1733
2336
  const { harenDir, workspaceDir } = location;
1734
2337
  const steps = [];
1735
- const manifestBefore = await readFile4(join7(harenDir, "manifest.yaml"), "utf-8");
2338
+ const manifestBefore = await readFile9(join11(harenDir, "manifest.yaml"), "utf-8");
1736
2339
  const manifest = parseManifest(manifestBefore);
1737
2340
  const layout = manifest.layout ?? (await inferLayout(workspaceDir)).layout ?? "workspace";
1738
2341
  if (!hasMarker(manifest))
@@ -1748,7 +2351,7 @@ async function planMigration(location) {
1748
2351
  const map = {};
1749
2352
  let foundRemote = false;
1750
2353
  for (const [key, entry] of Object.entries(current)) {
1751
- const remote = entry.remote ?? (layout === "workspace" ? await getRemoteUrl(resolve7(harenDir, entry.path)) : null);
2354
+ const remote = entry.remote ?? (layout === "workspace" ? await getRemoteUrl(resolve10(harenDir, entry.path)) : null);
1752
2355
  if (remote && !entry.remote)
1753
2356
  foundRemote = true;
1754
2357
  map[key] = remote ? { ...entry, remote } : entry;
@@ -1764,9 +2367,9 @@ async function planMigration(location) {
1764
2367
  repos
1765
2368
  });
1766
2369
  let progress = null;
1767
- const progressPath = join7(harenDir, "progress.json");
1768
- if (existsSync9(progressPath)) {
1769
- const before = await readFile4(progressPath, "utf-8");
2370
+ const progressPath = join11(harenDir, "progress.json");
2371
+ if (existsSync13(progressPath)) {
2372
+ const before = await readFile9(progressPath, "utf-8");
1770
2373
  let raw;
1771
2374
  try {
1772
2375
  raw = JSON.parse(before);
@@ -1787,7 +2390,7 @@ async function planMigration(location) {
1787
2390
  }
1788
2391
  const gitignore = await planGitignore(harenDir);
1789
2392
  if (gitignore !== null)
1790
- steps.push(`.gitignore: add ${AGENT_FILES.join(", ")}`);
2393
+ steps.push(`.gitignore: add ${IGNORED.join(", ")}`);
1791
2394
  const editor = detectEditor(workspaceDir) ?? "claude-code";
1792
2395
  const rootFiles = await computeRootFiles({ workspaceDir, harenDir, editor });
1793
2396
  for (const file of summarizeRootFiles(rootFiles).filter((f) => f.changed)) {
@@ -1804,10 +2407,10 @@ async function planMigration(location) {
1804
2407
  };
1805
2408
  }
1806
2409
  async function planGitignore(harenDir) {
1807
- const path = join7(harenDir, ".gitignore");
1808
- const before = existsSync9(path) ? await readFile4(path, "utf-8") : "";
2410
+ const path = join11(harenDir, ".gitignore");
2411
+ const before = existsSync13(path) ? await readFile9(path, "utf-8") : "";
1809
2412
  const lines = new Set(before.split(/\r?\n/).map((l) => l.trim()));
1810
- const missing = AGENT_FILES.filter((f) => !lines.has(f));
2413
+ const missing = IGNORED.filter((f) => !lines.has(f));
1811
2414
  if (missing.length === 0)
1812
2415
  return null;
1813
2416
  const eol = before.includes(`\r
@@ -1820,10 +2423,10 @@ async function planGitignore(harenDir) {
1820
2423
  }
1821
2424
  async function copyRecursive2(src, dest) {
1822
2425
  const entries = await readdir5(src, { withFileTypes: true });
1823
- await mkdir5(dest, { recursive: true });
2426
+ await mkdir7(dest, { recursive: true });
1824
2427
  for (const entry of entries) {
1825
- const srcPath = join7(src, entry.name);
1826
- const destPath = join7(dest, entry.name);
2428
+ const srcPath = join11(src, entry.name);
2429
+ const destPath = join11(dest, entry.name);
1827
2430
  if (entry.isDirectory()) {
1828
2431
  await copyRecursive2(srcPath, destPath);
1829
2432
  } else {
@@ -1836,7 +2439,7 @@ async function countFiles(dir) {
1836
2439
  const entries = await readdir5(dir, { withFileTypes: true });
1837
2440
  for (const entry of entries) {
1838
2441
  if (entry.isDirectory()) {
1839
- count += await countFiles(join7(dir, entry.name));
2442
+ count += await countFiles(join11(dir, entry.name));
1840
2443
  } else {
1841
2444
  count++;
1842
2445
  }
@@ -1880,8 +2483,8 @@ async function upgrade(args) {
1880
2483
  console.log("\x1B[2m Upgrading framework files:\x1B[0m");
1881
2484
  let totalFiles = 0;
1882
2485
  for (const dir of FRAMEWORK_DIRS) {
1883
- const srcDir = join7(contentDir, dir);
1884
- const destDir = join7(targetDir, dir);
2486
+ const srcDir = join11(contentDir, dir);
2487
+ const destDir = join11(targetDir, dir);
1885
2488
  const fileCount = await countFiles(srcDir);
1886
2489
  totalFiles += fileCount;
1887
2490
  console.log(` \x1B[36m\u2191\x1B[0m ${dir}/ \x1B[2m(${fileCount} files)\x1B[0m`);
@@ -1901,20 +2504,34 @@ async function upgrade(args) {
1901
2504
  return;
1902
2505
  }
1903
2506
  for (const dir of FRAMEWORK_DIRS) {
1904
- await copyRecursive2(join7(contentDir, dir), join7(targetDir, dir));
2507
+ await copyRecursive2(join11(contentDir, dir), join11(targetDir, dir));
1905
2508
  }
1906
2509
  await Promise.resolve().then(() => init_init());
1907
2510
  await scaffoldSkillMd(targetDir);
1908
2511
  await writeGateScript(targetDir);
1909
2512
  if (migration.manifest.after !== migration.manifest.before) {
1910
- await writeFile4(join7(targetDir, "manifest.yaml"), migration.manifest.after);
2513
+ await writeFile6(join11(targetDir, "manifest.yaml"), migration.manifest.after);
1911
2514
  }
1912
2515
  if (migration.progress) {
1913
- await writeFile4(join7(targetDir, "progress.json"), migration.progress.after);
2516
+ await writeFile6(join11(targetDir, "progress.json"), migration.progress.after);
1914
2517
  }
1915
2518
  if (migration.gitignore !== null) {
1916
- await writeFile4(join7(targetDir, ".gitignore"), migration.gitignore);
2519
+ await writeFile6(join11(targetDir, ".gitignore"), migration.gitignore);
1917
2520
  }
2521
+ const yes = args.includes("--yes") || args.includes("-y");
2522
+ const pluginCtx = {
2523
+ workspaceDir: location.workspaceDir,
2524
+ harenDir: targetDir,
2525
+ project: String(parseManifest(migration.manifest.after).project ?? ""),
2526
+ io: { confirm: async () => yes, log: (l) => console.log(` ${l}`) }
2527
+ };
2528
+ const restored = await restorePlugins(pluginCtx, {
2529
+ warn: (l) => console.warn(` \x1B[33m!\x1B[0m ${l}`),
2530
+ error: (l) => console.error(` \x1B[31m\u2717\x1B[0m ${l}`)
2531
+ });
2532
+ const pluginWarnings = await refreshPlugins({ ...pluginCtx, io: { ...pluginCtx.io, confirm: async () => false } }, restored);
2533
+ for (const w of pluginWarnings)
2534
+ console.warn(` \x1B[33m!\x1B[0m ${w}`);
1918
2535
  await writeRootFiles({
1919
2536
  workspaceDir: location.workspaceDir,
1920
2537
  harenDir: targetDir,
@@ -1924,7 +2541,7 @@ async function upgrade(args) {
1924
2541
  console.log(` \x1B[2mYour artifacts are untouched. Manifest and progress were migrated if needed.\x1B[0m`);
1925
2542
  console.log("");
1926
2543
  }
1927
- var AGENT_FILES, FRAMEWORK_DIRS, USER_FILES;
2544
+ var IGNORED, FRAMEWORK_DIRS, USER_FILES;
1928
2545
  var init_upgrade = __esm(() => {
1929
2546
  init_content_dir();
1930
2547
  init_version();
@@ -1934,22 +2551,23 @@ var init_upgrade = __esm(() => {
1934
2551
  init_progress();
1935
2552
  init_resolve();
1936
2553
  init_root_files();
2554
+ init_install();
1937
2555
  init_templates();
1938
- AGENT_FILES = [".agent.json", ".agent.pid"];
2556
+ IGNORED = [".agent.json", ".agent.pid", ".plugins/"];
1939
2557
  FRAMEWORK_DIRS = ["agents", "skills", "templates"];
1940
2558
  USER_FILES = ["FEEDBACK.md", "artifacts/", "events/"];
1941
2559
  });
1942
2560
 
1943
2561
  // src/agent/config.ts
1944
- import { join as join8 } from "path";
2562
+ import { join as join12 } from "path";
1945
2563
  async function readAgentConfig(harenDir) {
1946
- const file = Bun.file(join8(harenDir, CONFIG_FILE));
2564
+ const file = Bun.file(join12(harenDir, CONFIG_FILE));
1947
2565
  if (!await file.exists())
1948
2566
  return null;
1949
2567
  return file.json();
1950
2568
  }
1951
2569
  async function writeAgentConfig(harenDir, config) {
1952
- const path = join8(harenDir, CONFIG_FILE);
2570
+ const path = join12(harenDir, CONFIG_FILE);
1953
2571
  await Bun.write(path, JSON.stringify(config, null, 2));
1954
2572
  }
1955
2573
  var CONFIG_FILE = ".agent.json";
@@ -1972,16 +2590,16 @@ var init_cli_detector = __esm(() => {
1972
2590
  });
1973
2591
 
1974
2592
  // src/agent/artifact-reader.ts
1975
- import { join as join9 } from "path";
2593
+ import { join as join13 } from "path";
1976
2594
  import { readdir as readdir6 } from "fs/promises";
1977
- async function readProgress(harenDir) {
1978
- const file = Bun.file(join9(harenDir, "progress.json"));
2595
+ async function readProgress2(harenDir) {
2596
+ const file = Bun.file(join13(harenDir, "progress.json"));
1979
2597
  if (!await file.exists())
1980
2598
  return null;
1981
2599
  return file.json();
1982
2600
  }
1983
2601
  async function readArtifactTree(harenDir) {
1984
- const artifactsDir = join9(harenDir, "artifacts");
2602
+ const artifactsDir = join13(harenDir, "artifacts");
1985
2603
  try {
1986
2604
  return await buildTree(artifactsDir, "artifacts");
1987
2605
  } catch {
@@ -1992,9 +2610,9 @@ async function buildTree(dirPath, relativePath) {
1992
2610
  const entries = await readdir6(dirPath, { withFileTypes: true });
1993
2611
  const nodes = [];
1994
2612
  for (const entry of entries) {
1995
- const entryPath = join9(relativePath, entry.name);
2613
+ const entryPath = join13(relativePath, entry.name);
1996
2614
  if (entry.isDirectory()) {
1997
- const children = await buildTree(join9(dirPath, entry.name), entryPath);
2615
+ const children = await buildTree(join13(dirPath, entry.name), entryPath);
1998
2616
  nodes.push({
1999
2617
  name: entry.name,
2000
2618
  type: "directory",
@@ -2008,7 +2626,7 @@ async function buildTree(dirPath, relativePath) {
2008
2626
  return nodes.sort((a, b) => a.name.localeCompare(b.name));
2009
2627
  }
2010
2628
  async function readArtifact(harenDir, relativePath) {
2011
- const file = Bun.file(join9(harenDir, relativePath));
2629
+ const file = Bun.file(join13(harenDir, relativePath));
2012
2630
  if (!await file.exists())
2013
2631
  return null;
2014
2632
  return file.text();
@@ -2083,7 +2701,7 @@ function buildCLIArgs(cli, prompt) {
2083
2701
  }
2084
2702
 
2085
2703
  // src/workspace/events.ts
2086
- import { appendFile, readFile as readFile5 } from "fs/promises";
2704
+ import { appendFile, readFile as readFile10 } from "fs/promises";
2087
2705
  async function appendEvent(path, event) {
2088
2706
  const line = JSON.stringify(event) + `
2089
2707
  `;
@@ -2109,7 +2727,7 @@ async function handleDataRequest(requestId, path, harenDir, send) {
2109
2727
  let data;
2110
2728
  switch (path) {
2111
2729
  case "progress":
2112
- data = await readProgress(harenDir);
2730
+ data = await readProgress2(harenDir);
2113
2731
  break;
2114
2732
  case "artifacts":
2115
2733
  data = await readArtifactTree(harenDir);
@@ -2147,7 +2765,7 @@ var init_request_handler = __esm(() => {
2147
2765
  });
2148
2766
 
2149
2767
  // src/agent/connection.ts
2150
- import { join as join10 } from "path";
2768
+ import { join as join14 } from "path";
2151
2769
  function buildWsUrl(portalUrl) {
2152
2770
  return portalUrl.replace(/^https/, "wss").replace(/^http/, "ws") + "/ws/agent";
2153
2771
  }
@@ -2161,7 +2779,7 @@ function buildAuthMessage(opts) {
2161
2779
  };
2162
2780
  }
2163
2781
  async function connectToPortal(config) {
2164
- await Bun.write(join10(config.harenDir, ".agent.pid"), process.pid.toString());
2782
+ await Bun.write(join14(config.harenDir, ".agent.pid"), process.pid.toString());
2165
2783
  setupCleanup(config.harenDir);
2166
2784
  try {
2167
2785
  await connectWebSocket(config);
@@ -2317,7 +2935,7 @@ async function connectPolling(config) {
2317
2935
  }
2318
2936
  }
2319
2937
  function setupCleanup(harenDir) {
2320
- const pidPath = join10(harenDir, ".agent.pid");
2938
+ const pidPath = join14(harenDir, ".agent.pid");
2321
2939
  const cleanup = async () => {
2322
2940
  console.log("Agent shutting down...");
2323
2941
  const { unlink } = await import("fs/promises");
@@ -2330,7 +2948,7 @@ function setupCleanup(harenDir) {
2330
2948
  var init_connection = () => {};
2331
2949
 
2332
2950
  // src/commands/agent.ts
2333
- import { join as join11 } from "path";
2951
+ import { join as join15 } from "path";
2334
2952
  function readLine2(question) {
2335
2953
  process.stdout.write(question);
2336
2954
  return new Promise((resolve) => {
@@ -2424,7 +3042,7 @@ async function startAgent(harenDir) {
2424
3042
  config = { portalUrl, teamCode, userId, userName };
2425
3043
  await writeAgentConfig(harenDir, config);
2426
3044
  console.log(`
2427
- Config saved to ${join11(harenDir, ".agent.json")}`);
3045
+ Config saved to ${join15(harenDir, ".agent.json")}`);
2428
3046
  }
2429
3047
  const gitRemoteUrl = await getRemoteUrl(harenDir);
2430
3048
  if (!gitRemoteUrl) {
@@ -2448,7 +3066,7 @@ Config saved to ${join11(harenDir, ".agent.json")}`);
2448
3066
  });
2449
3067
  }
2450
3068
  async function stopAgent(harenDir) {
2451
- const pidFile = Bun.file(join11(harenDir, ".agent.pid"));
3069
+ const pidFile = Bun.file(join15(harenDir, ".agent.pid"));
2452
3070
  if (!await pidFile.exists()) {
2453
3071
  console.log("Agent is not running.");
2454
3072
  return;
@@ -2461,7 +3079,7 @@ async function stopAgent(harenDir) {
2461
3079
  console.log("Agent process not found. Cleaning up.");
2462
3080
  }
2463
3081
  const { unlink } = await import("fs/promises");
2464
- await unlink(join11(harenDir, ".agent.pid")).catch(() => {});
3082
+ await unlink(join15(harenDir, ".agent.pid")).catch(() => {});
2465
3083
  }
2466
3084
  async function showStatus(harenDir) {
2467
3085
  const config = await readAgentConfig(harenDir);
@@ -2469,7 +3087,7 @@ async function showStatus(harenDir) {
2469
3087
  console.log("Agent is not configured. Run 'haren agent start' first.");
2470
3088
  return;
2471
3089
  }
2472
- const pidFile = Bun.file(join11(harenDir, ".agent.pid"));
3090
+ const pidFile = Bun.file(join15(harenDir, ".agent.pid"));
2473
3091
  const isRunning = await pidFile.exists();
2474
3092
  console.log(`Portal: ${config.portalUrl}`);
2475
3093
  console.log(`Team: ${config.teamCode}`);
@@ -2487,6 +3105,471 @@ var init_agent = __esm(() => {
2487
3105
  init_git();
2488
3106
  });
2489
3107
 
3108
+ // src/plugins/tasks.ts
3109
+ function slugify(title) {
3110
+ return title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
3111
+ }
3112
+ function parseTasksFile(text) {
3113
+ const sections = text.split(/^## Task (\d+):[ \t]*(.+)$/m);
3114
+ const raw = [];
3115
+ for (let i = 1;i + 2 < sections.length; i += 3) {
3116
+ raw.push({
3117
+ number: Number(sections[i]),
3118
+ title: sections[i + 1].trim(),
3119
+ body: sections[i + 2] ?? ""
3120
+ });
3121
+ }
3122
+ const keyOf = new Map(raw.map((t) => [t.number, `task-${t.number}-${slugify(t.title)}`]));
3123
+ return raw.map((t) => {
3124
+ const field = (name) => new RegExp(`^\\*\\*${name}:\\*\\*[ \\t]*(.*)$`, "m").exec(t.body)?.[1]?.trim() ?? "";
3125
+ const deps = [...field("Dependencies").matchAll(/Task (\d+)/g)].map((m) => keyOf.get(Number(m[1]))).filter((k) => k !== undefined);
3126
+ return {
3127
+ key: keyOf.get(t.number),
3128
+ number: t.number,
3129
+ title: t.title,
3130
+ description: field("Description"),
3131
+ dependencies: deps
3132
+ };
3133
+ });
3134
+ }
3135
+ function alignTaskKeys(tasks, existing) {
3136
+ const aligned = new Map;
3137
+ for (const t of tasks) {
3138
+ const found = existing.find((k) => k.startsWith(`task-${t.number}-`));
3139
+ aligned.set(t.key, found ?? t.key);
3140
+ }
3141
+ return tasks.map((t) => ({
3142
+ ...t,
3143
+ key: aligned.get(t.key),
3144
+ dependencies: t.dependencies.map((d) => aligned.get(d) ?? d)
3145
+ }));
3146
+ }
3147
+
3148
+ // src/plugins/updates.ts
3149
+ function applyUpdates(progress, updates) {
3150
+ let current = progress;
3151
+ const applied = [];
3152
+ const skipped = [];
3153
+ for (const u of updates) {
3154
+ if (!u || typeof u !== "object") {
3155
+ skipped.push({ update: u, reason: "Update must be an object" });
3156
+ continue;
3157
+ }
3158
+ const extra = Object.keys(u).filter((k) => !KEYS.includes(k));
3159
+ if (extra.length > 0) {
3160
+ skipped.push({ update: u, reason: `Unknown field: ${extra.join(", ")}` });
3161
+ continue;
3162
+ }
3163
+ const { module, feature, status } = u;
3164
+ if (typeof module !== "string" || typeof feature !== "string") {
3165
+ skipped.push({ update: u, reason: "module and feature must be strings" });
3166
+ continue;
3167
+ }
3168
+ if (!STATUSES.includes(status)) {
3169
+ skipped.push({ update: u, reason: `Unknown status: ${String(status)}` });
3170
+ continue;
3171
+ }
3172
+ if (!Object.hasOwn(current.modules, module)) {
3173
+ skipped.push({ update: u, reason: `Unknown module: ${module}` });
3174
+ continue;
3175
+ }
3176
+ const mod = current.modules[module];
3177
+ if (!Object.hasOwn(mod.features, feature)) {
3178
+ skipped.push({ update: u, reason: `Unknown feature: ${module}/${feature}` });
3179
+ continue;
3180
+ }
3181
+ if (mod.features[feature] === status)
3182
+ continue;
3183
+ try {
3184
+ current = updateFeatureStatus(current, module, feature, status);
3185
+ applied.push({ module, feature, status });
3186
+ } catch (err) {
3187
+ skipped.push({ update: u, reason: err.message });
3188
+ }
3189
+ }
3190
+ return { progress: current, applied, skipped };
3191
+ }
3192
+ var STATUSES, KEYS;
3193
+ var init_updates = __esm(() => {
3194
+ init_progress();
3195
+ STATUSES = [
3196
+ "pending",
3197
+ "in-progress",
3198
+ "evaluating",
3199
+ "passing",
3200
+ "fixing",
3201
+ "blocked"
3202
+ ];
3203
+ KEYS = ["module", "feature", "status"];
3204
+ });
3205
+
3206
+ // src/plugins/runner.ts
3207
+ import { existsSync as existsSync14 } from "fs";
3208
+ import { appendFile as appendFile2, mkdir as mkdir8, readFile as readFile11 } from "fs/promises";
3209
+ import { isAbsolute as isAbsolute3, join as join16 } from "path";
3210
+ function tasksPath(input, harenDir) {
3211
+ if (typeof input.tasksFile !== "string")
3212
+ return;
3213
+ return isAbsolute3(input.tasksFile) ? input.tasksFile : join16(harenDir, input.tasksFile);
3214
+ }
3215
+ async function loadPlannedTasks(input, harenDir) {
3216
+ const path = tasksPath(input, harenDir);
3217
+ if (!path || !existsSync14(path))
3218
+ return [];
3219
+ const tasks = parseTasksFile(await readFile11(path, "utf-8"));
3220
+ const progressPath = join16(harenDir, "progress.json");
3221
+ if (typeof input.module !== "string" || !existsSync14(progressPath))
3222
+ return tasks;
3223
+ try {
3224
+ const mod = (await readProgress(progressPath)).modules[input.module];
3225
+ return mod ? alignTaskKeys(tasks, Object.keys(mod.features)) : tasks;
3226
+ } catch {
3227
+ return tasks;
3228
+ }
3229
+ }
3230
+ async function buildPayload(hook, input, harenDir) {
3231
+ const payload = { ...input, hook };
3232
+ const path = tasksPath(input, harenDir);
3233
+ if (hook === "after-plan" && path) {
3234
+ payload.tasksFile = path;
3235
+ payload.tasks = await loadPlannedTasks(input, harenDir);
3236
+ }
3237
+ return payload;
3238
+ }
3239
+ async function addPlannedFeatures(input, harenDir) {
3240
+ const progressPath = join16(harenDir, "progress.json");
3241
+ if (typeof input.module !== "string" || !existsSync14(progressPath))
3242
+ return;
3243
+ const tasks = await loadPlannedTasks(input, harenDir);
3244
+ const progress = await readProgress(progressPath);
3245
+ const mod = progress.modules[input.module];
3246
+ if (!mod)
3247
+ return;
3248
+ let changed = false;
3249
+ for (const t of tasks) {
3250
+ if (!(t.key in mod.features)) {
3251
+ mod.features[t.key] = "pending";
3252
+ changed = true;
3253
+ }
3254
+ }
3255
+ if (changed)
3256
+ await writeProgress(progressPath, progress);
3257
+ }
3258
+ async function logError(dir, hook, error) {
3259
+ await appendFile2(join16(dir, "errors.log"), `${new Date().toISOString()} ${hook}: ${error}
3260
+ `).catch(() => {});
3261
+ }
3262
+ async function runHook(hook, input, o) {
3263
+ const state = await readPlugins(o.harenDir);
3264
+ const payload = JSON.stringify(await buildPayload(hook, input, o.harenDir));
3265
+ const outcomes = [];
3266
+ for (const [name, entry] of Object.entries(state.plugins)) {
3267
+ if (!entry.enabled)
3268
+ continue;
3269
+ const dir = pluginDir(o.harenDir, name);
3270
+ const fail = async (error) => {
3271
+ outcomes.push({ plugin: name, ok: false, messages: [], updates: [], error });
3272
+ await logError(dir, hook, error);
3273
+ };
3274
+ let command;
3275
+ let config = {};
3276
+ try {
3277
+ const manifest = await readInstalledManifest(dir);
3278
+ command = manifest.hooks[hook];
3279
+ config = { ...manifest.config, ...entry.config };
3280
+ } catch (err) {
3281
+ await fail(`manifest unreadable: ${err.message}. Run 'haren plugin doctor'.`);
3282
+ continue;
3283
+ }
3284
+ if (!command)
3285
+ continue;
3286
+ const limit = o.timeoutMs ?? 30000;
3287
+ let timedOut = false;
3288
+ let timer;
3289
+ let stdout;
3290
+ let stderr;
3291
+ let code;
3292
+ try {
3293
+ const dataDir = pluginDataDir(o.harenDir, name);
3294
+ await mkdir8(dataDir, { recursive: true });
3295
+ const proc = Bun.spawn(["sh", "-c", command], {
3296
+ cwd: dir,
3297
+ stdin: new Blob([payload]),
3298
+ stdout: "pipe",
3299
+ stderr: "pipe",
3300
+ detached: true,
3301
+ env: {
3302
+ ...process.env,
3303
+ HAREN_ROOT: o.workspaceDir,
3304
+ HAREN_DIR: o.harenDir,
3305
+ HAREN_PLUGIN_DIR: dir,
3306
+ HAREN_PLUGIN_DATA: dataDir,
3307
+ HAREN_PLUGIN_CONFIG: JSON.stringify(config)
3308
+ }
3309
+ });
3310
+ const collected = Promise.all([
3311
+ new Response(proc.stdout).text(),
3312
+ new Response(proc.stderr).text(),
3313
+ proc.exited
3314
+ ]);
3315
+ collected.catch(() => {});
3316
+ const expired = new Promise((resolve) => {
3317
+ timer = setTimeout(() => {
3318
+ timedOut = true;
3319
+ try {
3320
+ process.kill(-proc.pid, "SIGKILL");
3321
+ } catch {
3322
+ try {
3323
+ proc.kill("SIGKILL");
3324
+ } catch {}
3325
+ }
3326
+ setTimeout(() => resolve(null), 500);
3327
+ }, limit);
3328
+ });
3329
+ const res = await Promise.race([collected, expired]);
3330
+ clearTimeout(timer);
3331
+ if (res === null) {
3332
+ await fail(`timed out after ${limit} ms`);
3333
+ continue;
3334
+ }
3335
+ [stdout, stderr, code] = res;
3336
+ } catch (err) {
3337
+ clearTimeout(timer);
3338
+ await fail(`could not start hook: ${err.message}`);
3339
+ continue;
3340
+ }
3341
+ if (timedOut) {
3342
+ await fail(`timed out after ${limit} ms`);
3343
+ continue;
3344
+ }
3345
+ if (code !== 0) {
3346
+ await fail(`exit ${code}: ${stderr.trim().split(`
3347
+ `).pop() ?? ""}`);
3348
+ continue;
3349
+ }
3350
+ let result;
3351
+ try {
3352
+ result = stdout.trim() ? JSON.parse(stdout) : {};
3353
+ } catch {
3354
+ await fail("invalid JSON on stdout");
3355
+ continue;
3356
+ }
3357
+ outcomes.push({
3358
+ plugin: name,
3359
+ ok: true,
3360
+ messages: Array.isArray(result.messages) ? result.messages.map(String) : [],
3361
+ updates: Array.isArray(result.updates) ? result.updates : []
3362
+ });
3363
+ }
3364
+ return outcomes;
3365
+ }
3366
+ async function runHookAndApply(hook, input, o) {
3367
+ const lines = [];
3368
+ let outcomes;
3369
+ if (hook === "after-plan") {
3370
+ try {
3371
+ await addPlannedFeatures(input, o.harenDir);
3372
+ } catch (err) {
3373
+ lines.push(`warning: could not add planned features: ${err.message}`);
3374
+ }
3375
+ }
3376
+ try {
3377
+ outcomes = await runHook(hook, input, o);
3378
+ } catch (err) {
3379
+ lines.push(`warning: could not run ${hook} hooks: ${err.message}`);
3380
+ return lines;
3381
+ }
3382
+ const updates = [];
3383
+ for (const out of outcomes) {
3384
+ for (const m of out.messages)
3385
+ lines.push(`[${out.plugin}] ${m}`);
3386
+ if (!out.ok)
3387
+ lines.push(`[${out.plugin}] warning: ${hook} failed: ${out.error}`);
3388
+ updates.push(...out.updates);
3389
+ }
3390
+ try {
3391
+ const progressPath = join16(o.harenDir, "progress.json");
3392
+ if (updates.length > 0 && existsSync14(progressPath)) {
3393
+ const result = applyUpdates(await readProgress(progressPath), updates);
3394
+ if (result.applied.length > 0)
3395
+ await writeProgress(progressPath, result.progress);
3396
+ for (const u of result.applied)
3397
+ lines.push(`updated ${u.module}/${u.feature} \u2192 ${u.status}`);
3398
+ for (const s of result.skipped)
3399
+ lines.push(`skipped update ${JSON.stringify(s.update)}: ${s.reason}`);
3400
+ }
3401
+ } catch (err) {
3402
+ lines.push(`warning: could not apply plugin updates: ${err.message}`);
3403
+ }
3404
+ return lines;
3405
+ }
3406
+ var init_runner = __esm(() => {
3407
+ init_progress();
3408
+ init_manifest2();
3409
+ init_state();
3410
+ init_updates();
3411
+ });
3412
+
3413
+ // src/commands/plugin.ts
3414
+ import { readFile as readFile12 } from "fs/promises";
3415
+ import { join as join17 } from "path";
3416
+ function parsePluginArgs(args) {
3417
+ const sub = args[0];
3418
+ if (!SUBS.includes(sub))
3419
+ throw new Error(USAGE);
3420
+ const yes = args.includes("--yes") || args.includes("-y");
3421
+ const target = args[1] && !args[1].startsWith("-") ? args[1] : undefined;
3422
+ if ((sub === "add" || sub === "remove") && !target)
3423
+ throw new Error(`haren plugin ${sub} needs a plugin`);
3424
+ if (sub === "run" && !HOOK_NAMES.includes(target ?? "")) {
3425
+ throw new Error(`Unknown hook: ${target ?? ""}. Hooks: ${HOOK_NAMES.join(", ")}`);
3426
+ }
3427
+ let payload = {};
3428
+ const i = args.indexOf("--payload");
3429
+ if (i >= 0) {
3430
+ try {
3431
+ payload = JSON.parse(args[i + 1] ?? "");
3432
+ } catch {
3433
+ throw new Error("--payload must be JSON");
3434
+ }
3435
+ }
3436
+ return { sub, target, payload, yes };
3437
+ }
3438
+ async function confirm(question, yes) {
3439
+ if (yes)
3440
+ return true;
3441
+ if (!process.stdin.isTTY)
3442
+ return false;
3443
+ process.stdout.write(` \x1B[36m?\x1B[0m ${question} (y/N) `);
3444
+ const answer = await new Promise((resolve) => {
3445
+ process.stdin.resume();
3446
+ process.stdin.once("data", (d) => {
3447
+ process.stdin.pause();
3448
+ resolve(d.toString().trim());
3449
+ });
3450
+ });
3451
+ return /^y(es)?$/i.test(answer);
3452
+ }
3453
+ async function plugin(args) {
3454
+ let opts;
3455
+ try {
3456
+ opts = parsePluginArgs(args);
3457
+ } catch (err) {
3458
+ console.error(` ${err.message}`);
3459
+ process.exit(1);
3460
+ }
3461
+ if (opts.sub === "run") {
3462
+ try {
3463
+ const loc = await resolveHarenDir(process.cwd(), {
3464
+ harenDir: harenDirFlag(args),
3465
+ env: process.env
3466
+ });
3467
+ if (!loc)
3468
+ throw new Error("No haren folder found");
3469
+ for (const line of await runHookAndApply(opts.target, opts.payload, {
3470
+ workspaceDir: loc.workspaceDir,
3471
+ harenDir: loc.harenDir
3472
+ })) {
3473
+ console.log(` ${line}`);
3474
+ }
3475
+ } catch (err) {
3476
+ console.log(` warning: plugin hook ${opts.target} skipped: ${err.message}`);
3477
+ }
3478
+ return;
3479
+ }
3480
+ let location;
3481
+ try {
3482
+ location = await resolveHarenDir(process.cwd(), {
3483
+ harenDir: harenDirFlag(args),
3484
+ env: process.env
3485
+ });
3486
+ } catch (err) {
3487
+ console.error(` ${err instanceof MultipleHarenDirsError ? err.message : String(err)}`);
3488
+ process.exit(1);
3489
+ }
3490
+ if (!location) {
3491
+ console.error(" No haren folder found. Run 'haren init' first.");
3492
+ process.exit(1);
3493
+ }
3494
+ const { workspaceDir, harenDir } = location;
3495
+ const manifest = parseManifest(await readFile12(join17(harenDir, "manifest.yaml"), "utf-8"));
3496
+ const ctx = {
3497
+ workspaceDir,
3498
+ harenDir,
3499
+ project: String(manifest.project ?? ""),
3500
+ io: { confirm: (q) => confirm(q, opts.yes), log: (l) => console.log(` ${l}`) }
3501
+ };
3502
+ const syncEditors = () => writeRootFiles({ workspaceDir, harenDir, editor: detectEditor(workspaceDir) ?? "claude-code" });
3503
+ switch (opts.sub) {
3504
+ case "add":
3505
+ try {
3506
+ await installPlugin(opts.target, ctx);
3507
+ } catch (err) {
3508
+ console.error(` ${err.message}`);
3509
+ process.exit(1);
3510
+ }
3511
+ await syncEditors();
3512
+ return;
3513
+ case "remove":
3514
+ try {
3515
+ const copies = await pluginFiles(harenDir, opts.target);
3516
+ await removePlugin(opts.target, ctx);
3517
+ await removeEditorCopies(workspaceDir, copies);
3518
+ } catch (err) {
3519
+ console.error(` ${err.message}`);
3520
+ process.exit(1);
3521
+ }
3522
+ await syncEditors();
3523
+ console.log(` Removed plugin ${opts.target}. Tool data in the project stays.`);
3524
+ return;
3525
+ case "list": {
3526
+ const state = await readPlugins(harenDir);
3527
+ const rows = Object.entries(state.plugins);
3528
+ if (rows.length === 0)
3529
+ console.log(" No plugins installed.");
3530
+ for (const [name, e] of rows) {
3531
+ console.log(` ${name} ${e.version} ${e.enabled ? "enabled" : "disabled"} ${e.source}`);
3532
+ }
3533
+ return;
3534
+ }
3535
+ case "doctor": {
3536
+ const state = await readPlugins(harenDir);
3537
+ for (const name of Object.keys(state.plugins)) {
3538
+ const dir = pluginDir(harenDir, name);
3539
+ try {
3540
+ const m = await readInstalledManifest(dir);
3541
+ console.log(` ${name}: manifest ok (${m.version})`);
3542
+ for (const req of m.requires) {
3543
+ const s = await checkRequirement(req);
3544
+ console.log(` ${req.bin}: ${s.ok ? `ok ${s.version ?? ""}` : s.reason}${!s.ok && req.install ? ` \u2014 run: ${req.install}` : ""}`);
3545
+ }
3546
+ } catch (err) {
3547
+ console.log(` ${name}: ${err.message}`);
3548
+ }
3549
+ const log = Bun.file(join17(dir, "errors.log"));
3550
+ if (await log.exists()) {
3551
+ const last = (await log.text()).trim().split(`
3552
+ `).slice(-3);
3553
+ for (const l of last)
3554
+ console.log(` last error: ${l}`);
3555
+ }
3556
+ }
3557
+ return;
3558
+ }
3559
+ }
3560
+ }
3561
+ var SUBS, USAGE = "Usage: haren plugin add <name|source> | remove <name> | list | run <hook> [--payload <json>] | doctor";
3562
+ var init_plugin = __esm(() => {
3563
+ init_manifest2();
3564
+ init_install();
3565
+ init_runner();
3566
+ init_state();
3567
+ init_manifest();
3568
+ init_root_files();
3569
+ init_resolve();
3570
+ SUBS = ["add", "remove", "list", "run", "doctor"];
3571
+ });
3572
+
2490
3573
  // src/index.ts
2491
3574
  function parseArgs(args) {
2492
3575
  if (args.length === 0) {
@@ -2504,6 +3587,7 @@ function parseArgs(args) {
2504
3587
  case "init":
2505
3588
  case "upgrade":
2506
3589
  case "agent":
3590
+ case "plugin":
2507
3591
  return { command, args: rest };
2508
3592
  default:
2509
3593
  return { command: "unknown", args };
@@ -2528,13 +3612,20 @@ async function main() {
2528
3612
  await agent(parsed.args);
2529
3613
  break;
2530
3614
  }
3615
+ case "plugin": {
3616
+ await Promise.resolve().then(() => init_plugin());
3617
+ await plugin(parsed.args);
3618
+ break;
3619
+ }
2531
3620
  case "help":
2532
3621
  console.log("Usage:");
2533
3622
  console.log(" haren init Set up haren (detects monorepo or multi-repo workspace)");
2534
3623
  console.log(" --dir <path> --layout monorepo|workspace --haren-dir <name>");
2535
3624
  console.log(" --yes|-y --dry-run --force");
2536
- console.log(" haren upgrade Upgrade framework files and migrate manifest/progress (--dry-run)");
3625
+ console.log(" --plugin <name|source> (repeatable)");
3626
+ console.log(" haren upgrade Upgrade framework files and migrate manifest/progress (--dry-run, --yes)");
2537
3627
  console.log(" haren agent Manage local agent (start, stop, status)");
3628
+ console.log(" haren plugin Manage plugins (add, remove, list, run, doctor)");
2538
3629
  break;
2539
3630
  case "unknown":
2540
3631
  console.error(`Unknown command: ${parsed.args[0]}`);