@odarino/haren 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +68 -8
- package/content/skills/implement/SKILL.md +24 -0
- package/content/skills/plan/SKILL.md +5 -0
- package/content/templates/task-brief.md +40 -0
- package/content/templates/tasks.md +2 -0
- package/dist/index.js +1857 -435
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -49,8 +49,8 @@ import { join as join2 } from "path";
|
|
|
49
49
|
function renderTemplate(template, harenDirName) {
|
|
50
50
|
return template.replaceAll(HAREN_DIR_TOKEN, harenDirName);
|
|
51
51
|
}
|
|
52
|
-
function gateCommand(harenDirName) {
|
|
53
|
-
return `bun ${harenDirName}/hooks/brainstorm-gate.ts`;
|
|
52
|
+
function gateCommand(harenDirName, host) {
|
|
53
|
+
return `bun ${harenDirName}/hooks/brainstorm-gate.ts${host ? ` --host ${host}` : ""}`;
|
|
54
54
|
}
|
|
55
55
|
async function writeGateScript(harenDir) {
|
|
56
56
|
await mkdir(join2(harenDir, "hooks"), { recursive: true });
|
|
@@ -207,7 +207,15 @@ function inside(path: string, root: string): boolean {
|
|
|
207
207
|
return path === root || path.startsWith(root.endsWith(sep) ? root : root + sep);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
// apply_patch can touch several files: each target is checked, and allow()
|
|
211
|
+
// moves on to the next target until the last one.
|
|
212
|
+
class AllowNext extends Error {}
|
|
213
|
+
let deferAllow = false;
|
|
214
|
+
|
|
210
215
|
function allow(): never {
|
|
216
|
+
if (deferAllow) throw new AllowNext();
|
|
217
|
+
// Claude-protocol hosts named by --host parse stdout JSON against their own schema: print nothing.
|
|
218
|
+
if (quietHost) process.exit(0);
|
|
211
219
|
console.log(JSON.stringify({
|
|
212
220
|
allow: true, // Claude Code
|
|
213
221
|
permission: "allow", // Cursor
|
|
@@ -218,6 +226,39 @@ function allow(): never {
|
|
|
218
226
|
// Set by readInput(). "unknown" writes both the Claude and the Cursor denial.
|
|
219
227
|
let source: "claude" | "cursor" | "unknown" = "unknown";
|
|
220
228
|
|
|
229
|
+
// --host <id> in the hook command names the host exactly. Hosts with a
|
|
230
|
+
// Claude-style hook API (exit 2 + stderr) use the Claude output path.
|
|
231
|
+
const CLAUDE_STYLE_HOSTS = ["claude-code", "codex", "qwen-code"];
|
|
232
|
+
// codex and qwen-code: allow = exit 0 with no stdout, deny = exit 2 with stderr only.
|
|
233
|
+
const QUIET_HOSTS = ["codex", "qwen-code"];
|
|
234
|
+
const quietHost = (() => {
|
|
235
|
+
const i = process.argv.indexOf("--host");
|
|
236
|
+
return i >= 0 && QUIET_HOSTS.includes(process.argv[i + 1] ?? "");
|
|
237
|
+
})();
|
|
238
|
+
|
|
239
|
+
function hostArg(): typeof source | null {
|
|
240
|
+
const i = process.argv.indexOf("--host");
|
|
241
|
+
const id = i >= 0 ? process.argv[i + 1] : undefined;
|
|
242
|
+
if (!id) return null;
|
|
243
|
+
if (CLAUDE_STYLE_HOSTS.includes(id)) return "claude";
|
|
244
|
+
if (id === "cursor") return "cursor";
|
|
245
|
+
return null; // unknown value: fall back to the guess
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Qwen Code tool names: run_shell_command is a shell call; edit and write_file write a file.
|
|
249
|
+
const SHELL_TOOLS = ["Bash", "run_shell_command"];
|
|
250
|
+
|
|
251
|
+
// Codex apply_patch sends the patch text; its file headers (and Move to lines) name the targets.
|
|
252
|
+
// Unreadable patch text gives no target: the normal gate path runs (no silent allow).
|
|
253
|
+
function patchTargets(raw: unknown): string[] {
|
|
254
|
+
// The patch text can come as a string or as an argv array (["apply_patch", "<patch>"]).
|
|
255
|
+
const patch = Array.isArray(raw) ? raw.filter((x) => typeof x === "string").join("\\n") : raw;
|
|
256
|
+
if (typeof patch !== "string") return [];
|
|
257
|
+
const out: string[] = [];
|
|
258
|
+
for (const m of patch.matchAll(/^[ \\t]*\\*\\*\\* (?:(?:Add|Update|Delete) File|Move to): (.+?)\\r?$/gm)) out.push(m[1].trim());
|
|
259
|
+
return out;
|
|
260
|
+
}
|
|
261
|
+
|
|
221
262
|
// Claude Code sends hook_event_name "PreToolUse" with session_id and transcript_path.
|
|
222
263
|
// Cursor sends its own hook_event_name values (beforeShellExecution, preToolUse, ...).
|
|
223
264
|
function detectSource(input: any): typeof source {
|
|
@@ -461,15 +502,21 @@ function shellWritesTo(command: string, startCwd: string, roots: string[], exclu
|
|
|
461
502
|
}
|
|
462
503
|
|
|
463
504
|
// shell: the payload is a shell event (Claude Bash, Cursor beforeShellExecution).
|
|
464
|
-
interface HookInput { target: string; command: string | null; cwd: string; shell: boolean }
|
|
505
|
+
interface HookInput { target: string; targets?: string[]; command: string | null; cwd: string; shell: boolean }
|
|
465
506
|
|
|
466
507
|
async function readInput(): Promise<HookInput> {
|
|
467
508
|
try {
|
|
468
509
|
const stdin = await Bun.stdin.text();
|
|
469
510
|
if (!stdin) return { target: "", command: null, cwd: process.cwd(), shell: false };
|
|
470
511
|
const input = JSON.parse(stdin);
|
|
471
|
-
source = detectSource(input);
|
|
472
|
-
const
|
|
512
|
+
source = hostArg() ?? detectSource(input);
|
|
513
|
+
const cwd0 = typeof input?.cwd === "string" && input.cwd ? input.cwd : process.cwd();
|
|
514
|
+
if (input?.tool_name === "apply_patch") {
|
|
515
|
+
const paths = patchTargets(input?.tool_input?.command)
|
|
516
|
+
.map((p) => realTarget(resolve(cwd0, p)));
|
|
517
|
+
return { target: paths[0] ?? "", targets: paths, command: null, cwd: cwd0, shell: false };
|
|
518
|
+
}
|
|
519
|
+
const shell = SHELL_TOOLS.includes(input?.tool_name)
|
|
473
520
|
|| input?.hook_event_name === "beforeShellExecution"
|
|
474
521
|
|| (input !== null && typeof input === "object" && "command" in input);
|
|
475
522
|
const cwd = typeof input?.cwd === "string" && input.cwd ? input.cwd : process.cwd();
|
|
@@ -496,8 +543,8 @@ async function readInput(): Promise<HookInput> {
|
|
|
496
543
|
const READ_ONLY_MESSAGE =
|
|
497
544
|
"This repo is read-only (manifest readOnly: true). It is the legacy source of truth. The gate override does not lift this block.";
|
|
498
545
|
|
|
499
|
-
async function main() {
|
|
500
|
-
const { target, command, cwd, shell } =
|
|
546
|
+
async function main(input: HookInput) {
|
|
547
|
+
const { target, command, cwd, shell } = input;
|
|
501
548
|
|
|
502
549
|
// Shell commands: only the readOnly repo check applies. Everything else is allowed.
|
|
503
550
|
// A shell event without a usable command is allowed too (not the Edit/Write gate).
|
|
@@ -587,7 +634,21 @@ async function main() {
|
|
|
587
634
|
|
|
588
635
|
// Top-level await: on Windows, Bun exits early (code 0, no output) if main() is
|
|
589
636
|
// not awaited while it waits on stdin, which would allow every write.
|
|
590
|
-
|
|
637
|
+
async function run() {
|
|
638
|
+
const input = await readInput();
|
|
639
|
+
const targets = input.targets?.length ? input.targets : [input.target];
|
|
640
|
+
for (let i = 0; i < targets.length; i++) {
|
|
641
|
+
deferAllow = i < targets.length - 1;
|
|
642
|
+
try {
|
|
643
|
+
await main({ ...input, target: targets[i] });
|
|
644
|
+
} catch (err) {
|
|
645
|
+
if (err instanceof AllowNext) continue;
|
|
646
|
+
throw err;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
await run().catch((err) => {
|
|
591
652
|
console.error("brainstorm-gate hook error:", err);
|
|
592
653
|
process.exit(1);
|
|
593
654
|
});
|
|
@@ -843,6 +904,198 @@ var init_manifest = __esm(() => {
|
|
|
843
904
|
UI_MODES = ["ask", "ascii", "browser", "artifact"];
|
|
844
905
|
});
|
|
845
906
|
|
|
907
|
+
// src/workspace/experimental.ts
|
|
908
|
+
function stringList(value) {
|
|
909
|
+
if (!Array.isArray(value))
|
|
910
|
+
return;
|
|
911
|
+
return value.filter((v) => v !== null && v !== undefined).map((v) => String(v));
|
|
912
|
+
}
|
|
913
|
+
function readExperimental(m) {
|
|
914
|
+
const known = [];
|
|
915
|
+
const unknown = [];
|
|
916
|
+
for (const v of stringList(m.experimental) ?? []) {
|
|
917
|
+
if (EXPERIMENTAL_FEATURES.includes(v)) {
|
|
918
|
+
if (!known.includes(v))
|
|
919
|
+
known.push(v);
|
|
920
|
+
} else if (!unknown.includes(v)) {
|
|
921
|
+
unknown.push(v);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return { known, unknown };
|
|
925
|
+
}
|
|
926
|
+
function warnUnknownExperimental(m) {
|
|
927
|
+
for (const v of readExperimental(m).unknown) {
|
|
928
|
+
if (warned.has(v))
|
|
929
|
+
continue;
|
|
930
|
+
warned.add(v);
|
|
931
|
+
console.warn(` warning: unknown experimental feature "${v}" in manifest.yaml (known: ${EXPERIMENTAL_FEATURES.join(", ")}); ignored`);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function isExperimental(m, name) {
|
|
935
|
+
warnUnknownExperimental(m);
|
|
936
|
+
return readExperimental(m).known.includes(name);
|
|
937
|
+
}
|
|
938
|
+
function readHosts(m) {
|
|
939
|
+
return stringList(m.hosts);
|
|
940
|
+
}
|
|
941
|
+
function writeManifestList(text, key, values) {
|
|
942
|
+
return replaceTopLevelBlock(text, key, `${key}: [${values.join(", ")}]
|
|
943
|
+
`);
|
|
944
|
+
}
|
|
945
|
+
var EXPERIMENTAL_FEATURES, warned;
|
|
946
|
+
var init_experimental = __esm(() => {
|
|
947
|
+
init_manifest();
|
|
948
|
+
EXPERIMENTAL_FEATURES = ["multi-host", "multi-model"];
|
|
949
|
+
warned = new Set;
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
// src/workspace/resolve.ts
|
|
953
|
+
import { existsSync as existsSync2 } from "fs";
|
|
954
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
955
|
+
import { dirname, join as join3, resolve as resolve2 } from "path";
|
|
956
|
+
async function hasMarkedManifest(dir) {
|
|
957
|
+
const path = join3(dir, "manifest.yaml");
|
|
958
|
+
if (!existsSync2(path))
|
|
959
|
+
return false;
|
|
960
|
+
const text = await readFile(path, "utf-8").catch(() => null);
|
|
961
|
+
if (text === null)
|
|
962
|
+
return false;
|
|
963
|
+
try {
|
|
964
|
+
return hasMarker(parseManifest(text));
|
|
965
|
+
} catch (e) {
|
|
966
|
+
if (/^haren:/m.test(text)) {
|
|
967
|
+
throw new Error(`manifest.yaml in ${dir} is not valid YAML: ${e instanceof Error ? e.message : String(e)}. Fix the file or move it, then run again.`);
|
|
968
|
+
}
|
|
969
|
+
return false;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function isLegacyHarenDir(dir) {
|
|
973
|
+
return existsSync2(join3(dir, "manifest.yaml")) && existsSync2(join3(dir, "skill.md"));
|
|
974
|
+
}
|
|
975
|
+
function location(harenDir, legacy) {
|
|
976
|
+
return { harenDir, workspaceDir: dirname(harenDir), legacy };
|
|
977
|
+
}
|
|
978
|
+
function harenDirFlag(args) {
|
|
979
|
+
const i = args.indexOf("--haren-dir");
|
|
980
|
+
if (i === -1)
|
|
981
|
+
return;
|
|
982
|
+
const value = args[i + 1];
|
|
983
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
984
|
+
throw new Error("--haren-dir needs a path");
|
|
985
|
+
}
|
|
986
|
+
return value;
|
|
987
|
+
}
|
|
988
|
+
async function resolveHarenDir(cwd, opts = {}) {
|
|
989
|
+
const explicit = opts.harenDir || opts.env?.HAREN_DIR;
|
|
990
|
+
if (explicit) {
|
|
991
|
+
const dir = resolve2(cwd, explicit);
|
|
992
|
+
if (!existsSync2(join3(dir, "manifest.yaml"))) {
|
|
993
|
+
throw new Error(`No manifest.yaml in ${dir}`);
|
|
994
|
+
}
|
|
995
|
+
return location(dir, !await hasMarkedManifest(dir));
|
|
996
|
+
}
|
|
997
|
+
if (await hasMarkedManifest(cwd))
|
|
998
|
+
return location(cwd, false);
|
|
999
|
+
const entries = await readdir(cwd, { withFileTypes: true }).catch(() => []);
|
|
1000
|
+
const matches = [];
|
|
1001
|
+
for (const entry of entries) {
|
|
1002
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
1003
|
+
continue;
|
|
1004
|
+
const dir = join3(cwd, entry.name);
|
|
1005
|
+
const isDir = entry.isSymbolicLink() ? await stat(dir).then((st) => st.isDirectory(), () => false) : entry.isDirectory();
|
|
1006
|
+
if (!isDir)
|
|
1007
|
+
continue;
|
|
1008
|
+
if (await hasMarkedManifest(dir))
|
|
1009
|
+
matches.push(dir);
|
|
1010
|
+
}
|
|
1011
|
+
matches.sort();
|
|
1012
|
+
if (matches.length > 1)
|
|
1013
|
+
throw new MultipleHarenDirsError(matches);
|
|
1014
|
+
if (matches.length === 1)
|
|
1015
|
+
return location(matches[0], false);
|
|
1016
|
+
const legacyChild = join3(cwd, "haren");
|
|
1017
|
+
if (isLegacyHarenDir(legacyChild))
|
|
1018
|
+
return location(legacyChild, true);
|
|
1019
|
+
if (isLegacyHarenDir(cwd))
|
|
1020
|
+
return location(cwd, true);
|
|
1021
|
+
return null;
|
|
1022
|
+
}
|
|
1023
|
+
var MultipleHarenDirsError;
|
|
1024
|
+
var init_resolve = __esm(() => {
|
|
1025
|
+
init_manifest();
|
|
1026
|
+
MultipleHarenDirsError = class MultipleHarenDirsError extends Error {
|
|
1027
|
+
matches;
|
|
1028
|
+
constructor(matches) {
|
|
1029
|
+
super(`Found more than one haren folder:
|
|
1030
|
+
${matches.join(`
|
|
1031
|
+
`)}
|
|
1032
|
+
Pass --haren-dir <path> to choose one.`);
|
|
1033
|
+
this.matches = matches;
|
|
1034
|
+
this.name = "MultipleHarenDirsError";
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
// src/commands/experimental.ts
|
|
1040
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1041
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
1042
|
+
import { join as join4 } from "path";
|
|
1043
|
+
function checkFeature(name) {
|
|
1044
|
+
if (!name || !EXPERIMENTAL_FEATURES.includes(name)) {
|
|
1045
|
+
throw new Error(`Unknown experimental feature '${name ?? ""}'. Known: ${EXPERIMENTAL_FEATURES.join(", ")}`);
|
|
1046
|
+
}
|
|
1047
|
+
return name;
|
|
1048
|
+
}
|
|
1049
|
+
async function experimental(args, cwd = process.cwd()) {
|
|
1050
|
+
const positional = args.filter((a, i) => !a.startsWith("--") && args[i - 1] !== "--haren-dir");
|
|
1051
|
+
const [sub, name] = positional;
|
|
1052
|
+
if (!sub) {
|
|
1053
|
+
console.log(USAGE);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (sub !== "enable" && sub !== "disable" && sub !== "list") {
|
|
1057
|
+
throw new Error(`Unknown experimental command: ${sub}
|
|
1058
|
+
${USAGE}`);
|
|
1059
|
+
}
|
|
1060
|
+
const location = await resolveHarenDir(cwd, { harenDir: harenDirFlag(args), env: process.env });
|
|
1061
|
+
if (!location)
|
|
1062
|
+
throw new Error("No haren folder found. Run `haren init` first.");
|
|
1063
|
+
const path = join4(location.harenDir, "manifest.yaml");
|
|
1064
|
+
if (!existsSync3(path))
|
|
1065
|
+
throw new Error(`No manifest.yaml in ${location.harenDir}`);
|
|
1066
|
+
const text = await readFile2(path, "utf-8");
|
|
1067
|
+
const m = parseManifest(text);
|
|
1068
|
+
warnUnknownExperimental(m);
|
|
1069
|
+
const { known } = readExperimental(m);
|
|
1070
|
+
if (sub === "list") {
|
|
1071
|
+
for (const f of EXPERIMENTAL_FEATURES) {
|
|
1072
|
+
console.log(` ${f.padEnd(12)} ${known.includes(f) ? "on" : "off"}`);
|
|
1073
|
+
}
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
const feature = checkFeature(name);
|
|
1077
|
+
if (sub === "enable") {
|
|
1078
|
+
if (known.includes(feature))
|
|
1079
|
+
return;
|
|
1080
|
+
await writeFile2(path, writeManifestList(text, "experimental", [...known, feature]));
|
|
1081
|
+
console.log(` Enabled experimental feature: ${feature}`);
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
if (!known.includes(feature))
|
|
1085
|
+
return;
|
|
1086
|
+
await writeFile2(path, writeManifestList(text, "experimental", known.filter((f) => f !== feature)));
|
|
1087
|
+
console.log(` Disabled experimental feature: ${feature}`);
|
|
1088
|
+
}
|
|
1089
|
+
var USAGE;
|
|
1090
|
+
var init_experimental2 = __esm(() => {
|
|
1091
|
+
init_experimental();
|
|
1092
|
+
init_manifest();
|
|
1093
|
+
init_resolve();
|
|
1094
|
+
USAGE = `Usage: haren experimental enable <name> | disable <name> | list
|
|
1095
|
+
Known features: ${EXPERIMENTAL_FEATURES.join(", ")}
|
|
1096
|
+
Options: --haren-dir <path>`;
|
|
1097
|
+
});
|
|
1098
|
+
|
|
846
1099
|
// src/plugins/paths.ts
|
|
847
1100
|
import { isAbsolute } from "path";
|
|
848
1101
|
function assertInsidePlugin(p, field) {
|
|
@@ -912,10 +1165,10 @@ var init_adapter_spec = __esm(() => {
|
|
|
912
1165
|
});
|
|
913
1166
|
|
|
914
1167
|
// src/plugins/manifest.ts
|
|
915
|
-
import { existsSync as
|
|
916
|
-
import { readFile } from "fs/promises";
|
|
917
|
-
import { join as
|
|
918
|
-
function
|
|
1168
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1169
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1170
|
+
import { join as join5 } from "path";
|
|
1171
|
+
function stringList2(value, field) {
|
|
919
1172
|
if (value === undefined)
|
|
920
1173
|
return [];
|
|
921
1174
|
if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
|
|
@@ -924,7 +1177,7 @@ function stringList(value, field) {
|
|
|
924
1177
|
return value;
|
|
925
1178
|
}
|
|
926
1179
|
function relativePathList(value, field) {
|
|
927
|
-
const list =
|
|
1180
|
+
const list = stringList2(value, field);
|
|
928
1181
|
for (const p of list)
|
|
929
1182
|
assertInsidePlugin(p, field);
|
|
930
1183
|
return list;
|
|
@@ -995,7 +1248,7 @@ function validateManifest(raw, packageVersion) {
|
|
|
995
1248
|
harenApi: m.harenApi,
|
|
996
1249
|
description: typeof m.description === "string" ? m.description : undefined,
|
|
997
1250
|
requires,
|
|
998
|
-
setup:
|
|
1251
|
+
setup: stringList2(m.setup, "setup"),
|
|
999
1252
|
hooks,
|
|
1000
1253
|
config,
|
|
1001
1254
|
skills: relativePathList(m.skills, "skills"),
|
|
@@ -1004,13 +1257,13 @@ function validateManifest(raw, packageVersion) {
|
|
|
1004
1257
|
};
|
|
1005
1258
|
}
|
|
1006
1259
|
async function readInstalledManifest(dir) {
|
|
1007
|
-
const raw = JSON.parse(await
|
|
1260
|
+
const raw = JSON.parse(await readFile3(join5(dir, "haren-plugin.json"), "utf-8"));
|
|
1008
1261
|
let packageVersion;
|
|
1009
1262
|
const hasVersion = raw && typeof raw === "object" && raw.version !== undefined;
|
|
1010
|
-
const pkgPath =
|
|
1011
|
-
if (!hasVersion &&
|
|
1263
|
+
const pkgPath = join5(dir, "package.json");
|
|
1264
|
+
if (!hasVersion && existsSync4(pkgPath)) {
|
|
1012
1265
|
try {
|
|
1013
|
-
const v = JSON.parse(await
|
|
1266
|
+
const v = JSON.parse(await readFile3(pkgPath, "utf-8"))?.version;
|
|
1014
1267
|
if (typeof v === "string")
|
|
1015
1268
|
packageVersion = v;
|
|
1016
1269
|
} catch {}
|
|
@@ -1027,25 +1280,25 @@ var init_manifest2 = __esm(() => {
|
|
|
1027
1280
|
});
|
|
1028
1281
|
|
|
1029
1282
|
// src/plugins/state.ts
|
|
1030
|
-
import { existsSync as
|
|
1031
|
-
import { mkdir as mkdir2, readFile as
|
|
1032
|
-
import { join as
|
|
1283
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1284
|
+
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
|
|
1285
|
+
import { join as join6 } from "path";
|
|
1033
1286
|
function pluginsPath(harenDir) {
|
|
1034
|
-
return
|
|
1287
|
+
return join6(harenDir, "plugins.json");
|
|
1035
1288
|
}
|
|
1036
1289
|
function pluginDir(harenDir, name) {
|
|
1037
|
-
return
|
|
1290
|
+
return join6(harenDir, ".plugins", name);
|
|
1038
1291
|
}
|
|
1039
1292
|
function pluginDataDir(harenDir, name) {
|
|
1040
|
-
return
|
|
1293
|
+
return join6(harenDir, ".plugin-data", name);
|
|
1041
1294
|
}
|
|
1042
1295
|
async function readPlugins(harenDir) {
|
|
1043
1296
|
const path = pluginsPath(harenDir);
|
|
1044
|
-
if (!
|
|
1297
|
+
if (!existsSync5(path))
|
|
1045
1298
|
return { version: 1, plugins: {} };
|
|
1046
1299
|
let data;
|
|
1047
1300
|
try {
|
|
1048
|
-
data = JSON.parse(await
|
|
1301
|
+
data = JSON.parse(await readFile4(path, "utf-8"));
|
|
1049
1302
|
} catch (e) {
|
|
1050
1303
|
throw new Error(`plugins.json is not valid JSON: ${e instanceof Error ? e.message : String(e)}`);
|
|
1051
1304
|
}
|
|
@@ -1053,15 +1306,359 @@ async function readPlugins(harenDir) {
|
|
|
1053
1306
|
}
|
|
1054
1307
|
async function writePlugins(harenDir, data) {
|
|
1055
1308
|
await mkdir2(harenDir, { recursive: true });
|
|
1056
|
-
await
|
|
1309
|
+
await writeFile3(pluginsPath(harenDir), `${JSON.stringify(data, null, 2)}
|
|
1057
1310
|
`);
|
|
1058
1311
|
}
|
|
1059
1312
|
var init_state = () => {};
|
|
1060
1313
|
|
|
1314
|
+
// src/hosts/shared.ts
|
|
1315
|
+
function instructionBlock(file, ctx) {
|
|
1316
|
+
const config = renderTemplate(editorConfigTemplate, ctx.harenName);
|
|
1317
|
+
return { path: file, make: (old) => upsertBlock(old, config, file), markdown: true };
|
|
1318
|
+
}
|
|
1319
|
+
function frameworkCopies(dir, ctx) {
|
|
1320
|
+
return ctx.framework.map((f) => ({
|
|
1321
|
+
path: `${dir}/${f.path}`,
|
|
1322
|
+
make: () => f.content,
|
|
1323
|
+
group: `${dir}/${f.group}/`
|
|
1324
|
+
}));
|
|
1325
|
+
}
|
|
1326
|
+
function skillFiles(dir, ctx) {
|
|
1327
|
+
return frameworkCopies(dir, {
|
|
1328
|
+
...ctx,
|
|
1329
|
+
framework: ctx.framework.filter((f) => f.group === "skills" && CORE_SKILLS.has(f.path.split("/")[1] ?? ""))
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
function agentFiles(dir, ctx, convert = (c) => c, ext = "md") {
|
|
1333
|
+
return ctx.framework.filter((f) => f.group === "agents").map((f) => {
|
|
1334
|
+
const name = f.path.replace(/^agents\//, "").replace(/\.md$/, "");
|
|
1335
|
+
return {
|
|
1336
|
+
path: `${dir}/${name}.${ext}`,
|
|
1337
|
+
make: () => convert(f.content, name),
|
|
1338
|
+
group: `${dir}/`
|
|
1339
|
+
};
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
function claudeStyleHook(path, matcher, command) {
|
|
1343
|
+
return { path, make: (old) => mergeClaudeStyleHook(old, path, matcher, command) };
|
|
1344
|
+
}
|
|
1345
|
+
function splitFrontmatter(text) {
|
|
1346
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
|
|
1347
|
+
if (!fm)
|
|
1348
|
+
return { data: {}, body: text };
|
|
1349
|
+
let data;
|
|
1350
|
+
try {
|
|
1351
|
+
data = Bun.YAML.parse(fm[1] ?? "");
|
|
1352
|
+
} catch {
|
|
1353
|
+
data = {};
|
|
1354
|
+
}
|
|
1355
|
+
return {
|
|
1356
|
+
data: data && typeof data === "object" ? data : {},
|
|
1357
|
+
body: text.slice(fm[0].length)
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
function tomlString(value) {
|
|
1361
|
+
return JSON.stringify(value);
|
|
1362
|
+
}
|
|
1363
|
+
function tomlMultiline(value) {
|
|
1364
|
+
return `"""
|
|
1365
|
+
${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"""`;
|
|
1366
|
+
}
|
|
1367
|
+
function agentToToml(content, name) {
|
|
1368
|
+
const { data, body } = splitFrontmatter(content);
|
|
1369
|
+
const lines = [`name = ${tomlString(name)}`];
|
|
1370
|
+
const description = typeof data.description === "string" ? data.description : name;
|
|
1371
|
+
lines.push(`description = ${tomlString(description)}`);
|
|
1372
|
+
if (typeof data.model === "string" && data.model)
|
|
1373
|
+
lines.push(`model = ${tomlString(data.model)}`);
|
|
1374
|
+
lines.push(`developer_instructions = ${tomlMultiline(body)}`);
|
|
1375
|
+
return `${lines.join(`
|
|
1376
|
+
`)}
|
|
1377
|
+
`;
|
|
1378
|
+
}
|
|
1379
|
+
function withFrontmatter(content, pick, name) {
|
|
1380
|
+
const { data, body } = splitFrontmatter(content);
|
|
1381
|
+
const fields = Object.entries(pick(data, name)).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join(`
|
|
1382
|
+
`);
|
|
1383
|
+
return `---
|
|
1384
|
+
${fields}
|
|
1385
|
+
---
|
|
1386
|
+
${body}`;
|
|
1387
|
+
}
|
|
1388
|
+
var CORE_SKILLS, GATE_NOTE_NO_HOOK = "no workspace hook API; the brainstorming gate works only through the instructions in AGENTS.md.";
|
|
1389
|
+
var init_shared = __esm(() => {
|
|
1390
|
+
init_root_files();
|
|
1391
|
+
init_templates();
|
|
1392
|
+
CORE_SKILLS = new Set([
|
|
1393
|
+
"haren-ideate",
|
|
1394
|
+
"haren-discover",
|
|
1395
|
+
"haren-decompose",
|
|
1396
|
+
"haren-plan",
|
|
1397
|
+
"haren-implement",
|
|
1398
|
+
"haren-evaluate",
|
|
1399
|
+
"haren-extract",
|
|
1400
|
+
"haren-release",
|
|
1401
|
+
"haren-read-context",
|
|
1402
|
+
"haren-update-tracking",
|
|
1403
|
+
"haren-onboard"
|
|
1404
|
+
]);
|
|
1405
|
+
});
|
|
1406
|
+
|
|
1407
|
+
// src/hosts/agents-md.ts
|
|
1408
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1409
|
+
import { join as join7 } from "path";
|
|
1410
|
+
var GATE_NOTE_INSTRUCTIONS = "no hook API; the brainstorming gate works only through the instructions in AGENTS.md.", agentsMd;
|
|
1411
|
+
var init_agents_md = __esm(() => {
|
|
1412
|
+
init_shared();
|
|
1413
|
+
agentsMd = {
|
|
1414
|
+
id: "agents-md",
|
|
1415
|
+
label: "Any agent that reads AGENTS.md",
|
|
1416
|
+
experimental: true,
|
|
1417
|
+
level: 1,
|
|
1418
|
+
roots: ["AGENTS.md"],
|
|
1419
|
+
files: (ctx) => [instructionBlock("AGENTS.md", ctx)],
|
|
1420
|
+
detect: (ws) => existsSync6(join7(ws, "AGENTS.md")),
|
|
1421
|
+
gateNote: GATE_NOTE_INSTRUCTIONS
|
|
1422
|
+
};
|
|
1423
|
+
});
|
|
1424
|
+
|
|
1425
|
+
// src/hosts/claude-code.ts
|
|
1426
|
+
import { existsSync as existsSync7 } from "fs";
|
|
1427
|
+
import { join as join8 } from "path";
|
|
1428
|
+
var claudeCode;
|
|
1429
|
+
var init_claude_code = __esm(() => {
|
|
1430
|
+
init_root_files();
|
|
1431
|
+
init_templates();
|
|
1432
|
+
init_shared();
|
|
1433
|
+
claudeCode = {
|
|
1434
|
+
id: "claude-code",
|
|
1435
|
+
label: "Claude Code CLI / IDE extension",
|
|
1436
|
+
experimental: false,
|
|
1437
|
+
level: 3,
|
|
1438
|
+
roots: ["CLAUDE.md", ".claude/"],
|
|
1439
|
+
files(ctx) {
|
|
1440
|
+
const command = gateCommand(ctx.harenName);
|
|
1441
|
+
return [
|
|
1442
|
+
instructionBlock("CLAUDE.md", ctx),
|
|
1443
|
+
{ path: ".claude/settings.json", make: (old) => mergeClaudeSettings(old, command) },
|
|
1444
|
+
...frameworkCopies(".claude", ctx)
|
|
1445
|
+
];
|
|
1446
|
+
},
|
|
1447
|
+
exec: ({ prompt: prompt2, model }) => ["claude", "-p", prompt2, ...model ? ["--model", model] : []],
|
|
1448
|
+
detect: (ws) => existsSync7(join8(ws, "CLAUDE.md")) || existsSync7(join8(ws, ".claude", "settings.json"))
|
|
1449
|
+
};
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
// src/hosts/codex.ts
|
|
1453
|
+
import { existsSync as existsSync8 } from "fs";
|
|
1454
|
+
import { join as join9 } from "path";
|
|
1455
|
+
var codex;
|
|
1456
|
+
var init_codex = __esm(() => {
|
|
1457
|
+
init_templates();
|
|
1458
|
+
init_shared();
|
|
1459
|
+
codex = {
|
|
1460
|
+
id: "codex",
|
|
1461
|
+
label: "OpenAI Codex CLI",
|
|
1462
|
+
experimental: true,
|
|
1463
|
+
level: 3,
|
|
1464
|
+
roots: ["AGENTS.md", ".agents/", ".codex/"],
|
|
1465
|
+
files: (ctx) => [
|
|
1466
|
+
instructionBlock("AGENTS.md", ctx),
|
|
1467
|
+
...skillFiles(".agents", ctx),
|
|
1468
|
+
...agentFiles(".codex/agents", ctx, agentToToml, "toml"),
|
|
1469
|
+
claudeStyleHook(".codex/hooks.json", "Bash|apply_patch", gateCommand(ctx.harenName, "codex"))
|
|
1470
|
+
],
|
|
1471
|
+
gateNote: "Codex runs a new project hook only after you review it. Run codex here once, open /hooks and trust the haren gate. Until then the gate works only through the instructions.",
|
|
1472
|
+
detect: (ws) => existsSync8(join9(ws, ".codex")),
|
|
1473
|
+
exec: ({ prompt: prompt2, cwd, model }) => [
|
|
1474
|
+
"codex",
|
|
1475
|
+
"exec",
|
|
1476
|
+
...model ? ["-m", model] : [],
|
|
1477
|
+
"-C",
|
|
1478
|
+
cwd,
|
|
1479
|
+
"-s",
|
|
1480
|
+
"workspace-write",
|
|
1481
|
+
prompt2
|
|
1482
|
+
]
|
|
1483
|
+
};
|
|
1484
|
+
});
|
|
1485
|
+
|
|
1486
|
+
// src/hosts/cursor.ts
|
|
1487
|
+
import { existsSync as existsSync9 } from "fs";
|
|
1488
|
+
import { join as join10 } from "path";
|
|
1489
|
+
var cursor;
|
|
1490
|
+
var init_cursor = __esm(() => {
|
|
1491
|
+
init_root_files();
|
|
1492
|
+
init_templates();
|
|
1493
|
+
init_shared();
|
|
1494
|
+
cursor = {
|
|
1495
|
+
id: "cursor",
|
|
1496
|
+
label: "Cursor AI editor",
|
|
1497
|
+
experimental: false,
|
|
1498
|
+
level: 3,
|
|
1499
|
+
roots: [".cursorrules", ".cursor/"],
|
|
1500
|
+
files(ctx) {
|
|
1501
|
+
const command = gateCommand(ctx.harenName);
|
|
1502
|
+
return [
|
|
1503
|
+
instructionBlock(".cursorrules", ctx),
|
|
1504
|
+
{
|
|
1505
|
+
path: ".cursor/rules/haren.mdc",
|
|
1506
|
+
make: () => renderTemplate(cursorRuleTemplate, ctx.harenName)
|
|
1507
|
+
},
|
|
1508
|
+
{ path: ".cursor/hooks.json", make: (old) => mergeCursorHooks(old, command) },
|
|
1509
|
+
...frameworkCopies(".cursor", ctx)
|
|
1510
|
+
];
|
|
1511
|
+
},
|
|
1512
|
+
exec: ({ prompt: prompt2, model }) => [
|
|
1513
|
+
"agent",
|
|
1514
|
+
"--print",
|
|
1515
|
+
"--trust",
|
|
1516
|
+
...model ? ["--model", model] : [],
|
|
1517
|
+
prompt2
|
|
1518
|
+
],
|
|
1519
|
+
detect: (ws) => existsSync9(join10(ws, ".cursorrules")) || existsSync9(join10(ws, ".cursor"))
|
|
1520
|
+
};
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
// src/hosts/kimi-code.ts
|
|
1524
|
+
import { existsSync as existsSync10 } from "fs";
|
|
1525
|
+
import { join as join11 } from "path";
|
|
1526
|
+
var kimiCode;
|
|
1527
|
+
var init_kimi_code = __esm(() => {
|
|
1528
|
+
init_shared();
|
|
1529
|
+
kimiCode = {
|
|
1530
|
+
id: "kimi-code",
|
|
1531
|
+
label: "Kimi Code CLI",
|
|
1532
|
+
experimental: true,
|
|
1533
|
+
level: 2,
|
|
1534
|
+
roots: ["AGENTS.md", ".agents/"],
|
|
1535
|
+
files: (ctx) => [
|
|
1536
|
+
instructionBlock("AGENTS.md", ctx),
|
|
1537
|
+
...skillFiles(".agents", ctx),
|
|
1538
|
+
...agentFiles(".agents/agents", ctx)
|
|
1539
|
+
],
|
|
1540
|
+
detect: (ws) => existsSync10(join11(ws, ".agents", "agents")),
|
|
1541
|
+
exec: ({ prompt: prompt2, model }) => ["kimi", "-p", prompt2, ...model ? ["-m", model] : []],
|
|
1542
|
+
gateNote: GATE_NOTE_NO_HOOK
|
|
1543
|
+
};
|
|
1544
|
+
});
|
|
1545
|
+
|
|
1546
|
+
// src/hosts/opencode.ts
|
|
1547
|
+
import { existsSync as existsSync11 } from "fs";
|
|
1548
|
+
import { join as join12 } from "path";
|
|
1549
|
+
function toOpencodeAgent(content, name) {
|
|
1550
|
+
return withFrontmatter(content, (data) => ({
|
|
1551
|
+
description: typeof data.description === "string" ? data.description : name,
|
|
1552
|
+
mode: "subagent"
|
|
1553
|
+
}), name);
|
|
1554
|
+
}
|
|
1555
|
+
var opencode;
|
|
1556
|
+
var init_opencode = __esm(() => {
|
|
1557
|
+
init_shared();
|
|
1558
|
+
opencode = {
|
|
1559
|
+
id: "opencode",
|
|
1560
|
+
label: "OpenCode",
|
|
1561
|
+
experimental: true,
|
|
1562
|
+
level: 2,
|
|
1563
|
+
roots: ["AGENTS.md", ".agents/", ".opencode/"],
|
|
1564
|
+
files: (ctx) => [
|
|
1565
|
+
instructionBlock("AGENTS.md", ctx),
|
|
1566
|
+
...skillFiles(".agents", ctx),
|
|
1567
|
+
...agentFiles(".opencode/agents", ctx, toOpencodeAgent)
|
|
1568
|
+
],
|
|
1569
|
+
detect: (ws) => existsSync11(join12(ws, ".opencode")),
|
|
1570
|
+
exec: ({ prompt: prompt2, model }) => ["opencode", "run", ...model ? ["--model", model] : [], prompt2],
|
|
1571
|
+
gateNote: GATE_NOTE_NO_HOOK
|
|
1572
|
+
};
|
|
1573
|
+
});
|
|
1574
|
+
|
|
1575
|
+
// src/hosts/qwen-code.ts
|
|
1576
|
+
import { existsSync as existsSync12 } from "fs";
|
|
1577
|
+
import { join as join13 } from "path";
|
|
1578
|
+
var qwenCode;
|
|
1579
|
+
var init_qwen_code = __esm(() => {
|
|
1580
|
+
init_templates();
|
|
1581
|
+
init_shared();
|
|
1582
|
+
qwenCode = {
|
|
1583
|
+
id: "qwen-code",
|
|
1584
|
+
label: "Qwen Code CLI",
|
|
1585
|
+
experimental: true,
|
|
1586
|
+
level: 3,
|
|
1587
|
+
roots: ["AGENTS.md", ".agents/", ".qwen/"],
|
|
1588
|
+
files: (ctx) => [
|
|
1589
|
+
instructionBlock("AGENTS.md", ctx),
|
|
1590
|
+
...skillFiles(".agents", ctx),
|
|
1591
|
+
...agentFiles(".qwen/agents", ctx),
|
|
1592
|
+
claudeStyleHook(".qwen/settings.json", "run_shell_command|edit|write_file", gateCommand(ctx.harenName, "qwen-code"))
|
|
1593
|
+
],
|
|
1594
|
+
gateNote: "Qwen Code loads project hooks only in a trusted folder. Set security.folderTrust.enabled in ~/.qwen/settings.json and trust this folder, or run qwen here once and approve the hook. Until then the gate works only through the instructions.",
|
|
1595
|
+
detect: (ws) => existsSync12(join13(ws, ".qwen")),
|
|
1596
|
+
exec: ({ prompt: prompt2, model }) => [
|
|
1597
|
+
"qwen",
|
|
1598
|
+
"-p",
|
|
1599
|
+
prompt2,
|
|
1600
|
+
...model ? ["-m", model] : [],
|
|
1601
|
+
"--approval-mode",
|
|
1602
|
+
"auto-edit"
|
|
1603
|
+
]
|
|
1604
|
+
};
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
// src/hosts/registry.ts
|
|
1608
|
+
function getHost(id) {
|
|
1609
|
+
return HOSTS.find((h) => h.id === id);
|
|
1610
|
+
}
|
|
1611
|
+
function listHosts() {
|
|
1612
|
+
return [...HOSTS];
|
|
1613
|
+
}
|
|
1614
|
+
function resolveHosts(ids, multiHost, hosts = HOSTS) {
|
|
1615
|
+
const known = hosts.map((h) => h.id).join(", ");
|
|
1616
|
+
const unique = [...new Set(ids.map((i) => i.trim()).filter(Boolean))];
|
|
1617
|
+
if (unique.length === 0)
|
|
1618
|
+
throw new Error(`No hosts given. Known: ${known}`);
|
|
1619
|
+
for (const id of unique) {
|
|
1620
|
+
const host = hosts.find((h) => h.id === id);
|
|
1621
|
+
if (!host)
|
|
1622
|
+
throw new Error(`Unknown host: ${id}. Known: ${known}`);
|
|
1623
|
+
if (host.experimental && !multiHost) {
|
|
1624
|
+
throw new Error(`Host '${id}' is experimental. Enable it first: haren experimental enable multi-host (or haren init --experimental multi-host)`);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return unique;
|
|
1628
|
+
}
|
|
1629
|
+
function cliName(host) {
|
|
1630
|
+
return host.id === "claude-code" ? "claude" : host.id;
|
|
1631
|
+
}
|
|
1632
|
+
function hostForCli(cli) {
|
|
1633
|
+
return getHost(cli === "claude" ? "claude-code" : cli);
|
|
1634
|
+
}
|
|
1635
|
+
var HOSTS;
|
|
1636
|
+
var init_registry = __esm(() => {
|
|
1637
|
+
init_agents_md();
|
|
1638
|
+
init_claude_code();
|
|
1639
|
+
init_codex();
|
|
1640
|
+
init_cursor();
|
|
1641
|
+
init_kimi_code();
|
|
1642
|
+
init_opencode();
|
|
1643
|
+
init_qwen_code();
|
|
1644
|
+
HOSTS = [
|
|
1645
|
+
claudeCode,
|
|
1646
|
+
cursor,
|
|
1647
|
+
agentsMd,
|
|
1648
|
+
codex,
|
|
1649
|
+
qwenCode,
|
|
1650
|
+
opencode,
|
|
1651
|
+
kimiCode
|
|
1652
|
+
];
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1061
1655
|
// src/workspace/root-files.ts
|
|
1062
|
-
import { existsSync as
|
|
1063
|
-
import { mkdir as mkdir3, readdir, readFile as
|
|
1064
|
-
import { basename as basename2, dirname, join as
|
|
1656
|
+
import { existsSync as existsSync13 } from "fs";
|
|
1657
|
+
import { mkdir as mkdir3, readdir as readdir2, readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
|
|
1658
|
+
import { basename as basename2, dirname as dirname2, join as join14, relative, resolve as resolve3, sep } from "path";
|
|
1659
|
+
function editorHosts(editor) {
|
|
1660
|
+
return editor === "both" ? ["claude-code", "cursor"] : [editor];
|
|
1661
|
+
}
|
|
1065
1662
|
function legacyRange(existing) {
|
|
1066
1663
|
const start = existing.indexOf(LEGACY_HEADING);
|
|
1067
1664
|
if (start === -1 || !existing.includes("haren/skill.md"))
|
|
@@ -1134,16 +1731,19 @@ function parseJson(existing, path) {
|
|
|
1134
1731
|
function withoutGate(entries) {
|
|
1135
1732
|
return (Array.isArray(entries) ? entries : []).filter((entry) => !JSON.stringify(entry).includes(GATE_SCRIPT));
|
|
1136
1733
|
}
|
|
1137
|
-
function
|
|
1138
|
-
const data = parseJson(existing,
|
|
1734
|
+
function mergeClaudeStyleHook(existing, path, matcher, command) {
|
|
1735
|
+
const data = parseJson(existing, path);
|
|
1139
1736
|
data.hooks ??= {};
|
|
1140
1737
|
data.hooks.PreToolUse = [
|
|
1141
1738
|
...withoutGate(data.hooks.PreToolUse),
|
|
1142
|
-
{ matcher
|
|
1739
|
+
{ matcher, hooks: [{ type: "command", command }] }
|
|
1143
1740
|
];
|
|
1144
1741
|
return `${JSON.stringify(data, null, 2)}
|
|
1145
1742
|
`;
|
|
1146
1743
|
}
|
|
1744
|
+
function mergeClaudeSettings(existing, command) {
|
|
1745
|
+
return mergeClaudeStyleHook(existing, ".claude/settings.json", "Edit|Write|Bash", command);
|
|
1746
|
+
}
|
|
1147
1747
|
function mergeCursorHooks(existing, command) {
|
|
1148
1748
|
const data = parseJson(existing, ".cursor/hooks.json");
|
|
1149
1749
|
data.version ??= 1;
|
|
@@ -1164,7 +1764,7 @@ function mergeCursorHooks(existing, command) {
|
|
|
1164
1764
|
`;
|
|
1165
1765
|
}
|
|
1166
1766
|
async function readOrNull(path) {
|
|
1167
|
-
return
|
|
1767
|
+
return existsSync13(path) ? readFile5(path, "utf-8") : null;
|
|
1168
1768
|
}
|
|
1169
1769
|
function harenName(name) {
|
|
1170
1770
|
return name.startsWith("haren-") ? name : `haren-${name}`;
|
|
@@ -1182,10 +1782,10 @@ function frontmatterName(text) {
|
|
|
1182
1782
|
}
|
|
1183
1783
|
async function listFiles(dir, prefix = "") {
|
|
1184
1784
|
const out = [];
|
|
1185
|
-
for (const entry of await
|
|
1785
|
+
for (const entry of await readdir2(dir, { withFileTypes: true })) {
|
|
1186
1786
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1187
1787
|
if (entry.isDirectory())
|
|
1188
|
-
out.push(...await listFiles(
|
|
1788
|
+
out.push(...await listFiles(join14(dir, entry.name), rel));
|
|
1189
1789
|
else if (entry.isFile())
|
|
1190
1790
|
out.push(rel);
|
|
1191
1791
|
}
|
|
@@ -1193,7 +1793,7 @@ async function listFiles(dir, prefix = "") {
|
|
|
1193
1793
|
}
|
|
1194
1794
|
async function frameworkFiles(harenDir, contentDir) {
|
|
1195
1795
|
let source = harenDir;
|
|
1196
|
-
if (!
|
|
1796
|
+
if (!existsSync13(join14(harenDir, "skills")) && !existsSync13(join14(harenDir, "agents"))) {
|
|
1197
1797
|
try {
|
|
1198
1798
|
source = contentDir ?? resolveContentDir();
|
|
1199
1799
|
} catch {
|
|
@@ -1201,18 +1801,18 @@ async function frameworkFiles(harenDir, contentDir) {
|
|
|
1201
1801
|
}
|
|
1202
1802
|
}
|
|
1203
1803
|
const files = [];
|
|
1204
|
-
const skillsDir =
|
|
1205
|
-
if (
|
|
1206
|
-
for (const entry of await
|
|
1804
|
+
const skillsDir = join14(source, "skills");
|
|
1805
|
+
if (existsSync13(skillsDir)) {
|
|
1806
|
+
for (const entry of await readdir2(skillsDir, { withFileTypes: true })) {
|
|
1207
1807
|
if (!entry.isDirectory())
|
|
1208
1808
|
continue;
|
|
1209
|
-
const dir =
|
|
1210
|
-
const main = await readOrNull(
|
|
1809
|
+
const dir = join14(skillsDir, entry.name);
|
|
1810
|
+
const main = await readOrNull(join14(dir, "SKILL.md"));
|
|
1211
1811
|
if (main === null)
|
|
1212
1812
|
continue;
|
|
1213
1813
|
const name = harenName(frontmatterName(main) ?? entry.name);
|
|
1214
1814
|
for (const rel of await listFiles(dir)) {
|
|
1215
|
-
const text = await
|
|
1815
|
+
const text = await readFile5(join14(dir, rel), "utf-8");
|
|
1216
1816
|
files.push({
|
|
1217
1817
|
path: `skills/${name}/${rel}`,
|
|
1218
1818
|
content: rel === "SKILL.md" ? withFrontmatterName(text, name) : text,
|
|
@@ -1221,10 +1821,10 @@ async function frameworkFiles(harenDir, contentDir) {
|
|
|
1221
1821
|
}
|
|
1222
1822
|
}
|
|
1223
1823
|
}
|
|
1224
|
-
const agentsDir =
|
|
1225
|
-
if (
|
|
1226
|
-
for (const file of (await
|
|
1227
|
-
const text = await
|
|
1824
|
+
const agentsDir = join14(source, "agents");
|
|
1825
|
+
if (existsSync13(agentsDir)) {
|
|
1826
|
+
for (const file of (await readdir2(agentsDir)).filter((f) => f.endsWith(".md")).sort()) {
|
|
1827
|
+
const text = await readFile5(join14(agentsDir, file), "utf-8");
|
|
1228
1828
|
const name = harenName(frontmatterName(text) ?? file.slice(0, -3));
|
|
1229
1829
|
files.push({
|
|
1230
1830
|
path: `agents/${name}.md`,
|
|
@@ -1252,15 +1852,15 @@ async function pluginFiles(harenDir, only) {
|
|
|
1252
1852
|
const prefixed = (n) => n.startsWith(`${plugin}-`) ? n : `${plugin}-${n}`;
|
|
1253
1853
|
const safeName = (n) => /^[A-Za-z0-9._-]+$/.test(n) && !n.includes("..");
|
|
1254
1854
|
for (const skill of manifest.skills) {
|
|
1255
|
-
const skillDir =
|
|
1256
|
-
const main = await readOrNull(
|
|
1855
|
+
const skillDir = join14(dir, skill);
|
|
1856
|
+
const main = await readOrNull(join14(skillDir, "SKILL.md"));
|
|
1257
1857
|
if (main === null)
|
|
1258
1858
|
continue;
|
|
1259
1859
|
const name = prefixed(frontmatterName(main) ?? basename2(skillDir));
|
|
1260
1860
|
if (!safeName(name))
|
|
1261
1861
|
continue;
|
|
1262
1862
|
for (const rel of await listFiles(skillDir)) {
|
|
1263
|
-
const text = await
|
|
1863
|
+
const text = await readFile5(join14(skillDir, rel), "utf-8");
|
|
1264
1864
|
files.push({
|
|
1265
1865
|
path: `skills/${name}/${rel}`,
|
|
1266
1866
|
content: rel === "SKILL.md" ? withFrontmatterName(text, name) : text,
|
|
@@ -1269,7 +1869,7 @@ async function pluginFiles(harenDir, only) {
|
|
|
1269
1869
|
}
|
|
1270
1870
|
}
|
|
1271
1871
|
for (const agent of manifest.agents) {
|
|
1272
|
-
const text = await readOrNull(
|
|
1872
|
+
const text = await readOrNull(join14(dir, agent));
|
|
1273
1873
|
if (text === null)
|
|
1274
1874
|
continue;
|
|
1275
1875
|
const name = prefixed(frontmatterName(text) ?? basename2(agent, ".md"));
|
|
@@ -1284,48 +1884,32 @@ async function pluginFiles(harenDir, only) {
|
|
|
1284
1884
|
}
|
|
1285
1885
|
return files.sort((x, y) => x.path.localeCompare(y.path));
|
|
1286
1886
|
}
|
|
1887
|
+
function optionHosts(o) {
|
|
1888
|
+
return o.hosts ?? editorHosts(o.editor ?? "claude-code");
|
|
1889
|
+
}
|
|
1287
1890
|
async function computeRootFiles(o) {
|
|
1288
|
-
const
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1891
|
+
const ctx = {
|
|
1892
|
+
workspaceDir: o.workspaceDir,
|
|
1893
|
+
harenDir: o.harenDir,
|
|
1894
|
+
harenName: relative(o.workspaceDir, o.harenDir).split(sep).join("/"),
|
|
1895
|
+
framework: await frameworkFiles(o.harenDir, o.contentDir)
|
|
1896
|
+
};
|
|
1294
1897
|
const specs = [];
|
|
1295
|
-
const
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1898
|
+
const seen = new Set;
|
|
1899
|
+
for (const id of optionHosts(o)) {
|
|
1900
|
+
const host = getHost(id);
|
|
1901
|
+
if (!host)
|
|
1902
|
+
throw new Error(`Unknown host: ${id}`);
|
|
1903
|
+
for (const spec of host.files(ctx)) {
|
|
1904
|
+
if (seen.has(spec.path))
|
|
1905
|
+
continue;
|
|
1906
|
+
seen.add(spec.path);
|
|
1907
|
+
specs.push(spec);
|
|
1302
1908
|
}
|
|
1303
|
-
};
|
|
1304
|
-
if (useClaude) {
|
|
1305
|
-
specs.push({
|
|
1306
|
-
path: "CLAUDE.md",
|
|
1307
|
-
make: (old) => upsertBlock(old, config, "CLAUDE.md"),
|
|
1308
|
-
markdown: true
|
|
1309
|
-
});
|
|
1310
|
-
specs.push({ path: ".claude/settings.json", make: (old) => mergeClaudeSettings(old, command) });
|
|
1311
|
-
addFramework(".claude");
|
|
1312
|
-
}
|
|
1313
|
-
if (useCursor) {
|
|
1314
|
-
specs.push({
|
|
1315
|
-
path: ".cursorrules",
|
|
1316
|
-
make: (old) => upsertBlock(old, config, ".cursorrules"),
|
|
1317
|
-
markdown: true
|
|
1318
|
-
});
|
|
1319
|
-
specs.push({
|
|
1320
|
-
path: ".cursor/rules/haren.mdc",
|
|
1321
|
-
make: () => renderTemplate(cursorRuleTemplate, name)
|
|
1322
|
-
});
|
|
1323
|
-
specs.push({ path: ".cursor/hooks.json", make: (old) => mergeCursorHooks(old, command) });
|
|
1324
|
-
addFramework(".cursor");
|
|
1325
1909
|
}
|
|
1326
1910
|
const files = [];
|
|
1327
1911
|
for (const spec of specs) {
|
|
1328
|
-
const old = await readOrNull(
|
|
1912
|
+
const old = await readOrNull(join14(o.workspaceDir, spec.path));
|
|
1329
1913
|
const content = spec.make(old);
|
|
1330
1914
|
files.push({
|
|
1331
1915
|
path: spec.path,
|
|
@@ -1360,11 +1944,9 @@ function summarizeRootFiles(files) {
|
|
|
1360
1944
|
return out;
|
|
1361
1945
|
}
|
|
1362
1946
|
function isSafeRootPath(workspaceDir, path) {
|
|
1363
|
-
const abs =
|
|
1364
|
-
const root =
|
|
1365
|
-
|
|
1366
|
-
return true;
|
|
1367
|
-
return [".claude", ".cursor"].some((d) => abs.startsWith(join5(root, d) + sep));
|
|
1947
|
+
const abs = resolve3(workspaceDir, path);
|
|
1948
|
+
const root = resolve3(workspaceDir);
|
|
1949
|
+
return listHosts().flatMap((h) => h.roots).some((r) => r.endsWith("/") ? abs.startsWith(join14(root, r.slice(0, -1)) + sep) : abs === join14(root, r));
|
|
1368
1950
|
}
|
|
1369
1951
|
async function writeRootFiles(o) {
|
|
1370
1952
|
const files = await computeRootFiles(o);
|
|
@@ -1375,15 +1957,15 @@ async function writeRootFiles(o) {
|
|
|
1375
1957
|
console.warn(` skipped unsafe path: ${file.path}`);
|
|
1376
1958
|
continue;
|
|
1377
1959
|
}
|
|
1378
|
-
const abs =
|
|
1379
|
-
await mkdir3(
|
|
1380
|
-
await
|
|
1960
|
+
const abs = join14(o.workspaceDir, file.path);
|
|
1961
|
+
await mkdir3(dirname2(abs), { recursive: true });
|
|
1962
|
+
await writeFile4(abs, file.content);
|
|
1381
1963
|
}
|
|
1382
1964
|
return files;
|
|
1383
1965
|
}
|
|
1384
1966
|
function detectEditor(workspaceDir) {
|
|
1385
|
-
const claude =
|
|
1386
|
-
const cursor =
|
|
1967
|
+
const claude = existsSync13(join14(workspaceDir, "CLAUDE.md")) || existsSync13(join14(workspaceDir, ".claude", "settings.json"));
|
|
1968
|
+
const cursor = existsSync13(join14(workspaceDir, ".cursorrules")) || existsSync13(join14(workspaceDir, ".cursor"));
|
|
1387
1969
|
if (claude && cursor)
|
|
1388
1970
|
return "both";
|
|
1389
1971
|
if (claude)
|
|
@@ -1397,14 +1979,14 @@ var init_root_files = __esm(() => {
|
|
|
1397
1979
|
init_content_dir();
|
|
1398
1980
|
init_manifest2();
|
|
1399
1981
|
init_state();
|
|
1400
|
-
|
|
1982
|
+
init_registry();
|
|
1401
1983
|
LEGACY_HEADINGS = new Set([LEGACY_HEADING, "## Brainstorming Gate"]);
|
|
1402
1984
|
});
|
|
1403
1985
|
|
|
1404
1986
|
// src/workspace/git.ts
|
|
1405
|
-
import { existsSync as
|
|
1406
|
-
import { mkdir as mkdir4, readdir as
|
|
1407
|
-
import { dirname as
|
|
1987
|
+
import { existsSync as existsSync14 } from "fs";
|
|
1988
|
+
import { mkdir as mkdir4, readdir as readdir3 } from "fs/promises";
|
|
1989
|
+
import { dirname as dirname3, join as join15, resolve as resolve4 } from "path";
|
|
1408
1990
|
function gitEnv(interactive = process.stdin.isTTY === true, base = process.env) {
|
|
1409
1991
|
if (interactive)
|
|
1410
1992
|
return { ...base };
|
|
@@ -1433,7 +2015,7 @@ async function runGit(args, cwd) {
|
|
|
1433
2015
|
}
|
|
1434
2016
|
}
|
|
1435
2017
|
function hasGitDir(dir) {
|
|
1436
|
-
return
|
|
2018
|
+
return existsSync14(join15(dir, ".git"));
|
|
1437
2019
|
}
|
|
1438
2020
|
async function isInsideWorkTree(dir) {
|
|
1439
2021
|
const result = await runGit(["rev-parse", "--is-inside-work-tree"], dir);
|
|
@@ -1444,121 +2026,34 @@ async function getRemoteUrl(dir) {
|
|
|
1444
2026
|
return result.ok && result.stdout ? result.stdout : null;
|
|
1445
2027
|
}
|
|
1446
2028
|
async function cloneRepo(remote, dest) {
|
|
1447
|
-
const abs =
|
|
2029
|
+
const abs = resolve4(dest);
|
|
1448
2030
|
try {
|
|
1449
|
-
await mkdir4(
|
|
2031
|
+
await mkdir4(dirname3(abs), { recursive: true });
|
|
1450
2032
|
} catch (err) {
|
|
1451
2033
|
return { ok: false, stdout: "", stderr: String(err) };
|
|
1452
2034
|
}
|
|
1453
|
-
return runGit(["clone", remote, abs],
|
|
2035
|
+
return runGit(["clone", remote, abs], dirname3(abs));
|
|
1454
2036
|
}
|
|
1455
2037
|
async function gitInit(dir) {
|
|
1456
2038
|
return runGit(["init"], dir);
|
|
1457
2039
|
}
|
|
1458
2040
|
async function listChildRepos(dir) {
|
|
1459
|
-
const entries = await
|
|
1460
|
-
const repos = [];
|
|
1461
|
-
for (const entry of entries) {
|
|
1462
|
-
if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
|
|
1463
|
-
continue;
|
|
1464
|
-
const path = join6(dir, entry.name);
|
|
1465
|
-
if (!hasGitDir(path))
|
|
1466
|
-
continue;
|
|
1467
|
-
repos.push({ name: entry.name, path, remote: await getRemoteUrl(path) });
|
|
1468
|
-
}
|
|
1469
|
-
return repos.sort((a, b) => a.name.localeCompare(b.name));
|
|
1470
|
-
}
|
|
1471
|
-
var init_git = () => {};
|
|
1472
|
-
|
|
1473
|
-
// src/workspace/resolve.ts
|
|
1474
|
-
import { existsSync as existsSync6 } from "fs";
|
|
1475
|
-
import { readdir as readdir3, readFile as readFile4, stat } from "fs/promises";
|
|
1476
|
-
import { dirname as dirname3, join as join7, resolve as resolve4 } from "path";
|
|
1477
|
-
async function hasMarkedManifest(dir) {
|
|
1478
|
-
const path = join7(dir, "manifest.yaml");
|
|
1479
|
-
if (!existsSync6(path))
|
|
1480
|
-
return false;
|
|
1481
|
-
const text = await readFile4(path, "utf-8").catch(() => null);
|
|
1482
|
-
if (text === null)
|
|
1483
|
-
return false;
|
|
1484
|
-
try {
|
|
1485
|
-
return hasMarker(parseManifest(text));
|
|
1486
|
-
} catch (e) {
|
|
1487
|
-
if (/^haren:/m.test(text)) {
|
|
1488
|
-
throw new Error(`manifest.yaml in ${dir} is not valid YAML: ${e instanceof Error ? e.message : String(e)}. Fix the file or move it, then run again.`);
|
|
1489
|
-
}
|
|
1490
|
-
return false;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
function isLegacyHarenDir(dir) {
|
|
1494
|
-
return existsSync6(join7(dir, "manifest.yaml")) && existsSync6(join7(dir, "skill.md"));
|
|
1495
|
-
}
|
|
1496
|
-
function location(harenDir, legacy) {
|
|
1497
|
-
return { harenDir, workspaceDir: dirname3(harenDir), legacy };
|
|
1498
|
-
}
|
|
1499
|
-
function harenDirFlag(args) {
|
|
1500
|
-
const i = args.indexOf("--haren-dir");
|
|
1501
|
-
if (i === -1)
|
|
1502
|
-
return;
|
|
1503
|
-
const value = args[i + 1];
|
|
1504
|
-
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
1505
|
-
throw new Error("--haren-dir needs a path");
|
|
1506
|
-
}
|
|
1507
|
-
return value;
|
|
1508
|
-
}
|
|
1509
|
-
async function resolveHarenDir(cwd, opts = {}) {
|
|
1510
|
-
const explicit = opts.harenDir || opts.env?.HAREN_DIR;
|
|
1511
|
-
if (explicit) {
|
|
1512
|
-
const dir = resolve4(cwd, explicit);
|
|
1513
|
-
if (!existsSync6(join7(dir, "manifest.yaml"))) {
|
|
1514
|
-
throw new Error(`No manifest.yaml in ${dir}`);
|
|
1515
|
-
}
|
|
1516
|
-
return location(dir, !await hasMarkedManifest(dir));
|
|
1517
|
-
}
|
|
1518
|
-
if (await hasMarkedManifest(cwd))
|
|
1519
|
-
return location(cwd, false);
|
|
1520
|
-
const entries = await readdir3(cwd, { withFileTypes: true }).catch(() => []);
|
|
1521
|
-
const matches = [];
|
|
2041
|
+
const entries = await readdir3(dir, { withFileTypes: true }).catch(() => []);
|
|
2042
|
+
const repos = [];
|
|
1522
2043
|
for (const entry of entries) {
|
|
1523
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
2044
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
|
|
1524
2045
|
continue;
|
|
1525
|
-
const
|
|
1526
|
-
|
|
1527
|
-
if (!isDir)
|
|
2046
|
+
const path = join15(dir, entry.name);
|
|
2047
|
+
if (!hasGitDir(path))
|
|
1528
2048
|
continue;
|
|
1529
|
-
|
|
1530
|
-
matches.push(dir);
|
|
2049
|
+
repos.push({ name: entry.name, path, remote: await getRemoteUrl(path) });
|
|
1531
2050
|
}
|
|
1532
|
-
|
|
1533
|
-
if (matches.length > 1)
|
|
1534
|
-
throw new MultipleHarenDirsError(matches);
|
|
1535
|
-
if (matches.length === 1)
|
|
1536
|
-
return location(matches[0], false);
|
|
1537
|
-
const legacyChild = join7(cwd, "haren");
|
|
1538
|
-
if (isLegacyHarenDir(legacyChild))
|
|
1539
|
-
return location(legacyChild, true);
|
|
1540
|
-
if (isLegacyHarenDir(cwd))
|
|
1541
|
-
return location(cwd, true);
|
|
1542
|
-
return null;
|
|
2051
|
+
return repos.sort((a, b) => a.name.localeCompare(b.name));
|
|
1543
2052
|
}
|
|
1544
|
-
var
|
|
1545
|
-
var init_resolve = __esm(() => {
|
|
1546
|
-
init_manifest();
|
|
1547
|
-
MultipleHarenDirsError = class MultipleHarenDirsError extends Error {
|
|
1548
|
-
matches;
|
|
1549
|
-
constructor(matches) {
|
|
1550
|
-
super(`Found more than one haren folder:
|
|
1551
|
-
${matches.join(`
|
|
1552
|
-
`)}
|
|
1553
|
-
Pass --haren-dir <path> to choose one.`);
|
|
1554
|
-
this.matches = matches;
|
|
1555
|
-
this.name = "MultipleHarenDirsError";
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
});
|
|
2053
|
+
var init_git = () => {};
|
|
1559
2054
|
|
|
1560
2055
|
// src/workspace/detect.ts
|
|
1561
|
-
import { existsSync as
|
|
2056
|
+
import { existsSync as existsSync15 } from "fs";
|
|
1562
2057
|
import { dirname as dirname4 } from "path";
|
|
1563
2058
|
async function inferLayout(dir) {
|
|
1564
2059
|
if (hasGitDir(dir))
|
|
@@ -1567,7 +2062,7 @@ async function inferLayout(dir) {
|
|
|
1567
2062
|
if (childRepos.length > 0)
|
|
1568
2063
|
return { layout: "workspace", childRepos };
|
|
1569
2064
|
let probe = dir;
|
|
1570
|
-
while (!
|
|
2065
|
+
while (!existsSync15(probe) && dirname4(probe) !== probe)
|
|
1571
2066
|
probe = dirname4(probe);
|
|
1572
2067
|
if (await isInsideWorkTree(probe))
|
|
1573
2068
|
return { layout: "monorepo", childRepos: [] };
|
|
@@ -1590,7 +2085,7 @@ var init_detect = __esm(() => {
|
|
|
1590
2085
|
});
|
|
1591
2086
|
|
|
1592
2087
|
// src/workspace/plan.ts
|
|
1593
|
-
import { existsSync as
|
|
2088
|
+
import { existsSync as existsSync16 } from "fs";
|
|
1594
2089
|
import { basename as basename3, relative as relative2, resolve as resolve5, sep as sep2 } from "path";
|
|
1595
2090
|
async function buildPlan(input) {
|
|
1596
2091
|
const items = [];
|
|
@@ -1598,7 +2093,8 @@ async function buildPlan(input) {
|
|
|
1598
2093
|
const rootFiles = await computeRootFiles({
|
|
1599
2094
|
workspaceDir: input.rootDir,
|
|
1600
2095
|
harenDir: input.harenDir,
|
|
1601
|
-
editor: input.editor
|
|
2096
|
+
editor: input.editor,
|
|
2097
|
+
hosts: input.hosts
|
|
1602
2098
|
});
|
|
1603
2099
|
for (const file of summarizeRootFiles(rootFiles)) {
|
|
1604
2100
|
const count = file.count ? `(${file.count} files)` : undefined;
|
|
@@ -1617,7 +2113,7 @@ async function buildPlan(input) {
|
|
|
1617
2113
|
for (const [key, repo] of Object.entries(input.repos)) {
|
|
1618
2114
|
const abs = resolve5(input.harenDir, repo.path);
|
|
1619
2115
|
const path = relative2(input.rootDir, abs).split(sep2).join("/") || key;
|
|
1620
|
-
if (
|
|
2116
|
+
if (existsSync16(abs)) {
|
|
1621
2117
|
items.push(hasGitDir(abs) || input.layout === "monorepo" ? { path, action: "keep" } : { path, action: "warn", note: "! not a git repo" });
|
|
1622
2118
|
} else if (input.layout === "monorepo") {
|
|
1623
2119
|
items.push({ path, action: "warn", note: "! folder not found" });
|
|
@@ -1697,12 +2193,12 @@ var init_plan = __esm(() => {
|
|
|
1697
2193
|
});
|
|
1698
2194
|
|
|
1699
2195
|
// src/workspace/progress.ts
|
|
1700
|
-
import { readFile as
|
|
2196
|
+
import { readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
|
|
1701
2197
|
function phaseForStatus(status) {
|
|
1702
2198
|
return STATUS_TO_PHASE[status];
|
|
1703
2199
|
}
|
|
1704
2200
|
async function readProgress(path) {
|
|
1705
|
-
const raw = await
|
|
2201
|
+
const raw = await readFile6(path, "utf-8");
|
|
1706
2202
|
const progress = JSON.parse(raw);
|
|
1707
2203
|
progress.modules ??= {};
|
|
1708
2204
|
for (const mod of Object.values(progress.modules)) {
|
|
@@ -1721,7 +2217,7 @@ function isObject(value) {
|
|
|
1721
2217
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1722
2218
|
}
|
|
1723
2219
|
async function writeProgress(path, progress) {
|
|
1724
|
-
await
|
|
2220
|
+
await writeFile5(path, JSON.stringify(progress, null, 2));
|
|
1725
2221
|
}
|
|
1726
2222
|
function updateModuleStatus(progress, moduleName, newStatus) {
|
|
1727
2223
|
const mod = progress.modules[moduleName];
|
|
@@ -1923,7 +2419,7 @@ var init_progress = __esm(() => {
|
|
|
1923
2419
|
});
|
|
1924
2420
|
|
|
1925
2421
|
// src/lib/version.ts
|
|
1926
|
-
import { existsSync as
|
|
2422
|
+
import { existsSync as existsSync17, readFileSync } from "fs";
|
|
1927
2423
|
import { resolve as resolve6 } from "path";
|
|
1928
2424
|
function readHarenVersion(candidates) {
|
|
1929
2425
|
const probes = candidates ?? [
|
|
@@ -1931,7 +2427,7 @@ function readHarenVersion(candidates) {
|
|
|
1931
2427
|
resolve6(import.meta.dir, "..", "..", "package.json")
|
|
1932
2428
|
];
|
|
1933
2429
|
for (const path of probes) {
|
|
1934
|
-
if (!
|
|
2430
|
+
if (!existsSync17(path))
|
|
1935
2431
|
continue;
|
|
1936
2432
|
try {
|
|
1937
2433
|
const pkg = JSON.parse(readFileSync(path, "utf-8"));
|
|
@@ -1970,7 +2466,7 @@ function resolvePluginRef(ref) {
|
|
|
1970
2466
|
return { source: entry.source, official: true };
|
|
1971
2467
|
}
|
|
1972
2468
|
var REGISTRY;
|
|
1973
|
-
var
|
|
2469
|
+
var init_registry2 = __esm(() => {
|
|
1974
2470
|
REGISTRY = [
|
|
1975
2471
|
{
|
|
1976
2472
|
name: "backlog",
|
|
@@ -2004,10 +2500,10 @@ async function checkRequirement(req, env = process.env) {
|
|
|
2004
2500
|
}
|
|
2005
2501
|
|
|
2006
2502
|
// src/plugins/source.ts
|
|
2007
|
-
import { existsSync as
|
|
2008
|
-
import { cp, mkdir as mkdir5, mkdtemp, readFile as
|
|
2503
|
+
import { existsSync as existsSync18 } from "fs";
|
|
2504
|
+
import { cp, mkdir as mkdir5, mkdtemp, readFile as readFile7, rm } from "fs/promises";
|
|
2009
2505
|
import { tmpdir } from "os";
|
|
2010
|
-
import { isAbsolute as isAbsolute2, join as
|
|
2506
|
+
import { isAbsolute as isAbsolute2, join as join16, resolve as resolve7 } from "path";
|
|
2011
2507
|
function parseSource(text) {
|
|
2012
2508
|
const match = /^(npm|git|file):(.*)$/.exec(text);
|
|
2013
2509
|
if (!match)
|
|
@@ -2033,31 +2529,31 @@ async function run(cmd, cwd) {
|
|
|
2033
2529
|
}
|
|
2034
2530
|
async function fetchPlugin(source, destDir, cwd) {
|
|
2035
2531
|
const parsed = parseSource(source);
|
|
2036
|
-
const work = await mkdtemp(
|
|
2532
|
+
const work = await mkdtemp(join16(tmpdir(), "haren-plugin-"));
|
|
2037
2533
|
let root;
|
|
2038
2534
|
try {
|
|
2039
2535
|
if (parsed.kind === "file") {
|
|
2040
2536
|
root = isAbsolute2(parsed.path) ? parsed.path : resolve7(cwd, parsed.path);
|
|
2041
2537
|
} else if (parsed.kind === "git") {
|
|
2042
|
-
root =
|
|
2538
|
+
root = join16(work, "repo");
|
|
2043
2539
|
const ref = parsed.ref ? ["--branch", parsed.ref] : [];
|
|
2044
2540
|
await run(["git", "clone", "--depth", "1", "-q", ...ref, "--", parsed.url, root]);
|
|
2045
|
-
await rm(
|
|
2541
|
+
await rm(join16(root, ".git"), { recursive: true, force: true });
|
|
2046
2542
|
} else {
|
|
2047
2543
|
await run(["npm", "pack", "--silent", "--pack-destination", work, "--", parsed.spec], work);
|
|
2048
2544
|
const tgz = (await Array.fromAsync(new Bun.Glob("*.tgz").scan(work)))[0];
|
|
2049
2545
|
if (!tgz)
|
|
2050
2546
|
throw new Error(`npm pack ${parsed.spec} produced no archive`);
|
|
2051
2547
|
await run(["tar", "-xzf", tgz], work);
|
|
2052
|
-
root =
|
|
2548
|
+
root = join16(work, "package");
|
|
2053
2549
|
}
|
|
2054
|
-
const manifestPath =
|
|
2055
|
-
if (!
|
|
2550
|
+
const manifestPath = join16(root, "haren-plugin.json");
|
|
2551
|
+
if (!existsSync18(manifestPath))
|
|
2056
2552
|
throw new Error(`No haren-plugin.json in ${source}`);
|
|
2057
|
-
const raw = JSON.parse(await
|
|
2553
|
+
const raw = JSON.parse(await readFile7(manifestPath, "utf-8"));
|
|
2058
2554
|
let packageVersion;
|
|
2059
2555
|
if (parsed.kind === "npm") {
|
|
2060
|
-
packageVersion = JSON.parse(await
|
|
2556
|
+
packageVersion = JSON.parse(await readFile7(join16(root, "package.json"), "utf-8")).version;
|
|
2061
2557
|
}
|
|
2062
2558
|
const manifest = validateManifest(raw, packageVersion);
|
|
2063
2559
|
await rm(destDir, { recursive: true, force: true });
|
|
@@ -2073,9 +2569,9 @@ var init_source = __esm(() => {
|
|
|
2073
2569
|
});
|
|
2074
2570
|
|
|
2075
2571
|
// src/plugins/install.ts
|
|
2076
|
-
import { existsSync as
|
|
2077
|
-
import { readFile as
|
|
2078
|
-
import { join as
|
|
2572
|
+
import { existsSync as existsSync19 } from "fs";
|
|
2573
|
+
import { readFile as readFile8, rename, rm as rm2 } from "fs/promises";
|
|
2574
|
+
import { join as join17, relative as relative3, resolve as resolve8, sep as sep3 } from "path";
|
|
2079
2575
|
async function sh(command, cwd) {
|
|
2080
2576
|
const proc = Bun.spawn(["sh", "-c", command], { cwd, stdout: "inherit", stderr: "pipe" });
|
|
2081
2577
|
const [stderr, code] = await Promise.all([new Response(proc.stderr).text(), proc.exited]);
|
|
@@ -2084,11 +2580,11 @@ async function sh(command, cwd) {
|
|
|
2084
2580
|
`).pop() ?? `exit ${code}`}`);
|
|
2085
2581
|
}
|
|
2086
2582
|
async function harenLayout(harenDir) {
|
|
2087
|
-
const path =
|
|
2088
|
-
if (!
|
|
2583
|
+
const path = join17(harenDir, "manifest.yaml");
|
|
2584
|
+
if (!existsSync19(path))
|
|
2089
2585
|
return "workspace";
|
|
2090
2586
|
try {
|
|
2091
|
-
return parseManifest(await
|
|
2587
|
+
return parseManifest(await readFile8(path, "utf-8")).layout ?? "workspace";
|
|
2092
2588
|
} catch {
|
|
2093
2589
|
return "workspace";
|
|
2094
2590
|
}
|
|
@@ -2168,7 +2664,7 @@ async function removeEditorCopies(workspaceDir, files) {
|
|
|
2168
2664
|
}
|
|
2169
2665
|
async function missingPlugins(harenDir) {
|
|
2170
2666
|
const state = await readPlugins(harenDir);
|
|
2171
|
-
return Object.entries(state.plugins).filter(([name, e]) => e.enabled && !
|
|
2667
|
+
return Object.entries(state.plugins).filter(([name, e]) => e.enabled && !existsSync19(join17(pluginDir(harenDir, name), "haren-plugin.json"))).map(([name]) => name);
|
|
2172
2668
|
}
|
|
2173
2669
|
async function restorePlugins(ctx, report) {
|
|
2174
2670
|
const restored = [];
|
|
@@ -2218,17 +2714,17 @@ async function refreshPlugins(ctx, skip = []) {
|
|
|
2218
2714
|
}
|
|
2219
2715
|
var incomingDir = (ctx) => pluginDir(ctx.harenDir, ".incoming"), INSTALL_CANCELLED = "Plugin install cancelled";
|
|
2220
2716
|
var init_install = __esm(() => {
|
|
2221
|
-
|
|
2717
|
+
init_registry2();
|
|
2222
2718
|
init_source();
|
|
2223
2719
|
init_state();
|
|
2224
2720
|
init_manifest();
|
|
2225
2721
|
});
|
|
2226
2722
|
|
|
2227
2723
|
// src/commands/init.ts
|
|
2228
|
-
import { mkdir as mkdir6, writeFile as
|
|
2229
|
-
import { existsSync as
|
|
2724
|
+
import { mkdir as mkdir6, writeFile as writeFile6, readdir as readdir4, copyFile, readFile as readFile9 } from "fs/promises";
|
|
2725
|
+
import { existsSync as existsSync20, realpathSync } from "fs";
|
|
2230
2726
|
import { homedir } from "os";
|
|
2231
|
-
import { basename as basename4, join as
|
|
2727
|
+
import { basename as basename4, join as join18, resolve as resolve9 } from "path";
|
|
2232
2728
|
function readLine() {
|
|
2233
2729
|
return new Promise((resolve) => {
|
|
2234
2730
|
const stdin = process.stdin;
|
|
@@ -2399,8 +2895,8 @@ async function copyRecursive(src, dest) {
|
|
|
2399
2895
|
const entries = await readdir4(src, { withFileTypes: true });
|
|
2400
2896
|
await mkdir6(dest, { recursive: true });
|
|
2401
2897
|
for (const entry of entries) {
|
|
2402
|
-
const srcPath =
|
|
2403
|
-
const destPath =
|
|
2898
|
+
const srcPath = join18(src, entry.name);
|
|
2899
|
+
const destPath = join18(dest, entry.name);
|
|
2404
2900
|
if (entry.isDirectory()) {
|
|
2405
2901
|
await copyRecursive(srcPath, destPath);
|
|
2406
2902
|
} else {
|
|
@@ -2410,9 +2906,9 @@ async function copyRecursive(src, dest) {
|
|
|
2410
2906
|
}
|
|
2411
2907
|
async function scaffoldWorkspace(targetDir, options) {
|
|
2412
2908
|
for (const dir of getDirectories(!!options.iterations)) {
|
|
2413
|
-
await mkdir6(
|
|
2909
|
+
await mkdir6(join18(targetDir, dir), { recursive: true });
|
|
2414
2910
|
}
|
|
2415
|
-
|
|
2911
|
+
let manifestText = buildManifestText({
|
|
2416
2912
|
version: HAREN_VERSION,
|
|
2417
2913
|
layout: options.layout ?? "monorepo",
|
|
2418
2914
|
project: options.project,
|
|
@@ -2420,7 +2916,13 @@ async function scaffoldWorkspace(targetDir, options) {
|
|
|
2420
2916
|
language: options.language,
|
|
2421
2917
|
repos: options.repos ?? {},
|
|
2422
2918
|
iterations: options.iterations
|
|
2423
|
-
})
|
|
2919
|
+
});
|
|
2920
|
+
if (options.experimental?.length) {
|
|
2921
|
+
manifestText = writeManifestList(manifestText, "experimental", options.experimental);
|
|
2922
|
+
}
|
|
2923
|
+
const hosts = options.hosts ?? editorHosts(options.editor ?? "claude-code");
|
|
2924
|
+
manifestText = writeManifestList(manifestText, "hosts", hosts);
|
|
2925
|
+
await writeFile6(join18(targetDir, "manifest.yaml"), manifestText);
|
|
2424
2926
|
const progressData = {
|
|
2425
2927
|
project: options.project,
|
|
2426
2928
|
version: PROGRESS_VERSION,
|
|
@@ -2432,24 +2934,24 @@ async function scaffoldWorkspace(targetDir, options) {
|
|
|
2432
2934
|
if (options.iterations) {
|
|
2433
2935
|
progressData.currentIteration = 1;
|
|
2434
2936
|
}
|
|
2435
|
-
await
|
|
2436
|
-
await
|
|
2937
|
+
await writeFile6(join18(targetDir, "progress.json"), JSON.stringify(progressData, null, 2));
|
|
2938
|
+
await writeFile6(join18(targetDir, "FEEDBACK.md"), `# Haren Framework Feedback
|
|
2437
2939
|
|
|
2438
2940
|
Append-only log of framework improvement suggestions captured during usage.
|
|
2439
2941
|
|
|
2440
2942
|
---
|
|
2441
2943
|
`);
|
|
2442
|
-
await
|
|
2944
|
+
await writeFile6(join18(targetDir, "artifacts", "_registry", "artifact-index.md"), `# Artifact Index
|
|
2443
2945
|
|
|
2444
2946
|
Master registry of all artifacts in this Haren workspace.
|
|
2445
2947
|
|
|
2446
2948
|
| ID | Type | Module | Status | Path |
|
|
2447
2949
|
|----|------|--------|--------|------|
|
|
2448
2950
|
`);
|
|
2449
|
-
await
|
|
2450
|
-
const gitignore =
|
|
2451
|
-
if (!
|
|
2452
|
-
await
|
|
2951
|
+
await writeFile6(join18(targetDir, "events", "events.jsonl"), "");
|
|
2952
|
+
const gitignore = join18(targetDir, ".gitignore");
|
|
2953
|
+
if (!existsSync20(gitignore))
|
|
2954
|
+
await writeFile6(gitignore, `.agent.json
|
|
2453
2955
|
.agent.pid
|
|
2454
2956
|
.plugins/
|
|
2455
2957
|
.companion/
|
|
@@ -2457,18 +2959,46 @@ Master registry of all artifacts in this Haren workspace.
|
|
|
2457
2959
|
await writeGateScript(targetDir);
|
|
2458
2960
|
await scaffoldSkillMd(targetDir);
|
|
2459
2961
|
const contentDir = resolveContentDir();
|
|
2460
|
-
await copyRecursive(
|
|
2461
|
-
await copyRecursive(
|
|
2462
|
-
await copyRecursive(
|
|
2962
|
+
await copyRecursive(join18(contentDir, "agents"), join18(targetDir, "agents"));
|
|
2963
|
+
await copyRecursive(join18(contentDir, "skills"), join18(targetDir, "skills"));
|
|
2964
|
+
await copyRecursive(join18(contentDir, "templates"), join18(targetDir, "templates"));
|
|
2463
2965
|
await options.beforeRootFiles?.();
|
|
2464
2966
|
await writeRootFiles({
|
|
2465
2967
|
workspaceDir: resolve9(targetDir, ".."),
|
|
2466
2968
|
harenDir: targetDir,
|
|
2467
|
-
|
|
2969
|
+
hosts
|
|
2468
2970
|
});
|
|
2971
|
+
printGateNotes(hosts);
|
|
2972
|
+
}
|
|
2973
|
+
function gateNotes(hosts) {
|
|
2974
|
+
return hosts.flatMap((id) => {
|
|
2975
|
+
const host = getHost(id);
|
|
2976
|
+
return host?.gateNote ? [`${host.label}: ${host.gateNote}`] : [];
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
function printGateNotes(hosts) {
|
|
2980
|
+
for (const note of gateNotes(hosts))
|
|
2981
|
+
console.log(` \x1B[33m!\x1B[0m ${note}`);
|
|
2982
|
+
}
|
|
2983
|
+
function selectHosts(opts, multiHost) {
|
|
2984
|
+
if (opts.hosts)
|
|
2985
|
+
return resolveHosts(opts.hosts, multiHost);
|
|
2986
|
+
if (opts.editor)
|
|
2987
|
+
return editorHosts(opts.editor);
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
async function promptHosts(multiHost) {
|
|
2991
|
+
if (!multiHost) {
|
|
2992
|
+
const editor = await promptSelect("Which editors do you use?", EDITORS, EDITOR_DESCRIPTIONS, "claude-code");
|
|
2993
|
+
return editorHosts(editor);
|
|
2994
|
+
}
|
|
2995
|
+
const hosts = listHosts();
|
|
2996
|
+
const picked = await promptMultiSelect("Which coding agents do you use?", hosts.map((h) => `${h.id.padEnd(12)} ${h.label}${h.experimental ? " (experimental)" : ""}`), [0]);
|
|
2997
|
+
const ids = picked.map((i) => hosts[i].id);
|
|
2998
|
+
return ids.length > 0 ? ids : ["claude-code"];
|
|
2469
2999
|
}
|
|
2470
3000
|
async function scaffoldSkillMd(targetDir) {
|
|
2471
|
-
await
|
|
3001
|
+
await writeFile6(join18(targetDir, "skill.md"), `---
|
|
2472
3002
|
name: haren
|
|
2473
3003
|
description: Agentic SDLC framework \u2014 orchestrates AI agents through structured phases
|
|
2474
3004
|
---
|
|
@@ -2499,6 +3029,7 @@ You are operating within the Haren agentic SDLC framework.
|
|
|
2499
3029
|
6. Suggest next action based on current state
|
|
2500
3030
|
|
|
2501
3031
|
Visual questions follow the ui mode in manifest.yaml (\`ui.mockups\`: ask | ascii | browser | artifact). See the visual-companion skill.
|
|
3032
|
+
Experimental features are listed in manifest.yaml \`experimental:\` (\`multi-host\`, \`multi-model\`); the installed coding agents are in \`hosts:\`.
|
|
2502
3033
|
|
|
2503
3034
|
## Available Actions
|
|
2504
3035
|
|
|
@@ -2649,6 +3180,15 @@ function parseInitArgs(args) {
|
|
|
2649
3180
|
out.plugins.push(value);
|
|
2650
3181
|
i++;
|
|
2651
3182
|
break;
|
|
3183
|
+
case "--experimental": {
|
|
3184
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
3185
|
+
throw new Error("--experimental needs a comma list, for example multi-host");
|
|
3186
|
+
}
|
|
3187
|
+
const names = value.split(",").map((v) => v.trim()).filter(Boolean);
|
|
3188
|
+
out.experimental = [...new Set(names.map(checkFeature))];
|
|
3189
|
+
i++;
|
|
3190
|
+
break;
|
|
3191
|
+
}
|
|
2652
3192
|
case "--mode":
|
|
2653
3193
|
if (!MODES.includes(value)) {
|
|
2654
3194
|
throw new Error(`Invalid mode: ${value}. Must be blueprint, explore, inherit, migration, or undecided.`);
|
|
@@ -2656,6 +3196,17 @@ function parseInitArgs(args) {
|
|
|
2656
3196
|
out.mode = value;
|
|
2657
3197
|
i++;
|
|
2658
3198
|
break;
|
|
3199
|
+
case "--hosts":
|
|
3200
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
3201
|
+
throw new Error("--hosts needs a comma list, for example claude-code,codex");
|
|
3202
|
+
}
|
|
3203
|
+
out.hosts = value.split(",").map((v) => v.trim()).filter(Boolean);
|
|
3204
|
+
if (out.hosts.length === 0)
|
|
3205
|
+
throw new Error("--hosts needs at least one host");
|
|
3206
|
+
for (const id of out.hosts)
|
|
3207
|
+
resolveHosts([id], true);
|
|
3208
|
+
i++;
|
|
3209
|
+
break;
|
|
2659
3210
|
case "--editor":
|
|
2660
3211
|
if (value !== "claude-code" && value !== "cursor" && value !== "both") {
|
|
2661
3212
|
throw new Error(`Invalid editor: ${value}. Must be claude-code, cursor, or both.`);
|
|
@@ -2695,6 +3246,8 @@ function parseInitArgs(args) {
|
|
|
2695
3246
|
break;
|
|
2696
3247
|
}
|
|
2697
3248
|
}
|
|
3249
|
+
if (out.editor && out.hosts)
|
|
3250
|
+
throw new Error("Use --editor or --hosts, not both.");
|
|
2698
3251
|
return out;
|
|
2699
3252
|
}
|
|
2700
3253
|
async function applyClones(plan, rootDir) {
|
|
@@ -2703,7 +3256,7 @@ async function applyClones(plan, rootDir) {
|
|
|
2703
3256
|
if (item.action !== "clone" || !item.remote)
|
|
2704
3257
|
continue;
|
|
2705
3258
|
console.log(` \x1B[36m\u2193\x1B[0m Cloning ${item.path} ...`);
|
|
2706
|
-
const result = await cloneRepo(item.remote,
|
|
3259
|
+
const result = await cloneRepo(item.remote, join18(rootDir, item.path));
|
|
2707
3260
|
if (!result.ok) {
|
|
2708
3261
|
console.error(` \x1B[31m\u2717\x1B[0m ${item.path}: ${result.stderr.split(`
|
|
2709
3262
|
`).pop()}`);
|
|
@@ -2811,24 +3364,42 @@ async function runSetup(location, opts) {
|
|
|
2811
3364
|
console.log(" Run 'haren upgrade' to migrate it.");
|
|
2812
3365
|
return;
|
|
2813
3366
|
}
|
|
2814
|
-
const
|
|
3367
|
+
const manifestPath = join18(location.harenDir, "manifest.yaml");
|
|
3368
|
+
const manifestText = await readFile9(manifestPath, "utf-8");
|
|
3369
|
+
const manifest = parseManifest(manifestText);
|
|
2815
3370
|
const layout = manifest.layout ?? "workspace";
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
3371
|
+
const knownExp = readExperimental(manifest).known;
|
|
3372
|
+
const mergedExp = [...new Set([...knownExp, ...opts.experimental ?? []])];
|
|
3373
|
+
if (mergedExp.length !== knownExp.length)
|
|
3374
|
+
manifest.experimental = mergedExp;
|
|
3375
|
+
const multiHost = isExperimental(manifest, "multi-host");
|
|
3376
|
+
const saved = readHosts(manifest);
|
|
3377
|
+
const detected = detectEditor(location.workspaceDir);
|
|
3378
|
+
const hosts = selectHosts(opts, multiHost) ?? (saved ? resolveHosts(saved, multiHost) : undefined) ?? (detected ? editorHosts(detected) : undefined) ?? (canPrompt(opts) ? await promptHosts(multiHost) : ["claude-code"]);
|
|
3379
|
+
const saveManifest = async () => {
|
|
3380
|
+
let text = manifestText;
|
|
3381
|
+
if (mergedExp.length !== knownExp.length) {
|
|
3382
|
+
text = writeManifestList(text, "experimental", mergedExp);
|
|
3383
|
+
}
|
|
3384
|
+
if ((saved ?? []).join(",") !== hosts.join(","))
|
|
3385
|
+
text = writeManifestList(text, "hosts", hosts);
|
|
3386
|
+
if (text !== manifestText)
|
|
3387
|
+
await writeFile6(manifestPath, text);
|
|
3388
|
+
};
|
|
2820
3389
|
const plan = await buildPlan({
|
|
2821
3390
|
rootDir: location.workspaceDir,
|
|
2822
3391
|
harenDir: location.harenDir,
|
|
2823
3392
|
layout,
|
|
2824
3393
|
createHaren: false,
|
|
2825
3394
|
repos: normalizeRepos(manifest.repos),
|
|
2826
|
-
|
|
3395
|
+
hosts
|
|
2827
3396
|
});
|
|
2828
3397
|
console.log(` Found haren folder: ${location.harenDir}`);
|
|
2829
3398
|
const missing = await missingPlugins(location.harenDir);
|
|
2830
3399
|
if (isNoop(plan) && opts.plugins.length === 0) {
|
|
2831
3400
|
if (missing.length === 0) {
|
|
3401
|
+
if (!opts.dryRun)
|
|
3402
|
+
await saveManifest();
|
|
2832
3403
|
console.log(" Already set up. Run 'haren upgrade' to update framework files.");
|
|
2833
3404
|
return;
|
|
2834
3405
|
}
|
|
@@ -2836,11 +3407,12 @@ async function runSetup(location, opts) {
|
|
|
2836
3407
|
console.log(` Plugins to restore: ${missing.join(", ")}`);
|
|
2837
3408
|
return;
|
|
2838
3409
|
}
|
|
3410
|
+
await saveManifest();
|
|
2839
3411
|
await restoreMissing(opts, location, manifest.project ?? "");
|
|
2840
3412
|
await writeRootFiles({
|
|
2841
3413
|
workspaceDir: location.workspaceDir,
|
|
2842
3414
|
harenDir: location.harenDir,
|
|
2843
|
-
|
|
3415
|
+
hosts
|
|
2844
3416
|
});
|
|
2845
3417
|
return;
|
|
2846
3418
|
}
|
|
@@ -2851,14 +3423,16 @@ async function runSetup(location, opts) {
|
|
|
2851
3423
|
return;
|
|
2852
3424
|
if (await confirmOrExit(opts, false) === "no")
|
|
2853
3425
|
return;
|
|
3426
|
+
await saveManifest();
|
|
2854
3427
|
const failed = await applyClones(plan, location.workspaceDir);
|
|
2855
3428
|
await restoreMissing(opts, location, manifest.project ?? "");
|
|
2856
3429
|
await setupPlugins(opts, location.workspaceDir, location.harenDir, manifest.project ?? "");
|
|
2857
3430
|
await writeRootFiles({
|
|
2858
3431
|
workspaceDir: location.workspaceDir,
|
|
2859
3432
|
harenDir: location.harenDir,
|
|
2860
|
-
|
|
3433
|
+
hosts
|
|
2861
3434
|
});
|
|
3435
|
+
printGateNotes(hosts);
|
|
2862
3436
|
printNextSteps();
|
|
2863
3437
|
if (failed.length > 0) {
|
|
2864
3438
|
console.error(` ${failed.length} repo(s) failed to clone: ${failed.join(", ")}. Run 'haren init' again to retry.`);
|
|
@@ -2898,7 +3472,7 @@ async function init(args) {
|
|
|
2898
3472
|
process.exit(1);
|
|
2899
3473
|
}
|
|
2900
3474
|
printBanner();
|
|
2901
|
-
const explicitHarenDir = opts.harenDir &&
|
|
3475
|
+
const explicitHarenDir = opts.harenDir && existsSync20(join18(cwdRoot, opts.harenDir, "manifest.yaml")) ? opts.harenDir : undefined;
|
|
2902
3476
|
let detection;
|
|
2903
3477
|
try {
|
|
2904
3478
|
detection = await detectLayout(cwdRoot, { harenDir: explicitHarenDir, env: process.env });
|
|
@@ -2915,7 +3489,7 @@ async function init(args) {
|
|
|
2915
3489
|
let existingLayout;
|
|
2916
3490
|
if (detection.kind === "existing" && detection.location) {
|
|
2917
3491
|
const loc = detection.location;
|
|
2918
|
-
existingManifest = parseManifest(await
|
|
3492
|
+
existingManifest = parseManifest(await readFile9(join18(loc.harenDir, "manifest.yaml"), "utf-8"));
|
|
2919
3493
|
existingRepos = normalizeRepos(existingManifest.repos);
|
|
2920
3494
|
existingLayout = existingManifest.layout ?? (await inferLayout(loc.workspaceDir)).layout ?? "workspace";
|
|
2921
3495
|
}
|
|
@@ -2929,7 +3503,7 @@ async function init(args) {
|
|
|
2929
3503
|
console.log(` Layout detected: ${layout === "monorepo" ? "monorepo (inside a git repo)" : "multi-repo workspace (no .git at root)"}`);
|
|
2930
3504
|
console.log("");
|
|
2931
3505
|
const harenDirName = opts.harenDir ?? (existingLoc ? basename4(existingLoc.harenDir) : interactive ? await prompt2("haren folder name:", "haren") : "haren");
|
|
2932
|
-
const harenDir = existingLoc && !opts.harenDir ? existingLoc.harenDir :
|
|
3506
|
+
const harenDir = existingLoc && !opts.harenDir ? existingLoc.harenDir : join18(rootDir, harenDirName);
|
|
2933
3507
|
const children = (existingRepos ? [] : detection.childRepos).filter((r) => r.name !== harenDirName);
|
|
2934
3508
|
const defaults = children.flatMap((r, i) => r.remote ? [i] : []);
|
|
2935
3509
|
let selected = defaults;
|
|
@@ -2938,7 +3512,15 @@ async function init(args) {
|
|
|
2938
3512
|
const mode = opts.mode ?? existingMode ?? (interactive ? await promptSelect("Mode:", MODES, MODE_DESCRIPTIONS, "undecided") : "undecided");
|
|
2939
3513
|
const language = opts.language ?? existingManifest?.language ?? (interactive ? await prompt2("Preferred language:", "English") : "English");
|
|
2940
3514
|
const iterations = opts.iterations ?? (existingManifest ? manifestIterations(existingManifest) : interactive ? await promptIterations() : undefined);
|
|
2941
|
-
const
|
|
3515
|
+
const multiHost = (opts.experimental ?? []).includes("multi-host") || (existingManifest ? isExperimental(existingManifest, "multi-host") : false);
|
|
3516
|
+
let hosts;
|
|
3517
|
+
try {
|
|
3518
|
+
const saved = existingManifest ? readHosts(existingManifest) : undefined;
|
|
3519
|
+
hosts = selectHosts(opts, multiHost) ?? (saved ? resolveHosts(saved, multiHost) : undefined) ?? (existingLoc ? editorHosts(detectEditor(existingLoc.workspaceDir) ?? "claude-code") : undefined) ?? (interactive ? await promptHosts(multiHost) : ["claude-code"]);
|
|
3520
|
+
} catch (err) {
|
|
3521
|
+
console.error(` ${err.message}`);
|
|
3522
|
+
process.exit(1);
|
|
3523
|
+
}
|
|
2942
3524
|
while (true) {
|
|
2943
3525
|
if (layout === "workspace" && children.length > 0 && interactive) {
|
|
2944
3526
|
selected = await promptMultiSelect("Select code repos to track:", children.map((r) => `${r.name.padEnd(12)} ${r.remote ?? "(no remote)"}`), selected);
|
|
@@ -2954,7 +3536,7 @@ async function init(args) {
|
|
|
2954
3536
|
layout,
|
|
2955
3537
|
createHaren: true,
|
|
2956
3538
|
repos,
|
|
2957
|
-
|
|
3539
|
+
hosts,
|
|
2958
3540
|
manifestPreview: `layout: ${layout}
|
|
2959
3541
|
${renderReposBlock(repos)}`
|
|
2960
3542
|
});
|
|
@@ -2975,9 +3557,15 @@ ${renderReposBlock(repos)}`
|
|
|
2975
3557
|
mode,
|
|
2976
3558
|
language,
|
|
2977
3559
|
iterations,
|
|
2978
|
-
|
|
3560
|
+
hosts,
|
|
2979
3561
|
layout,
|
|
2980
3562
|
repos,
|
|
3563
|
+
experimental: [
|
|
3564
|
+
...new Set([
|
|
3565
|
+
...existingManifest ? readExperimental(existingManifest).known : [],
|
|
3566
|
+
...opts.experimental ?? []
|
|
3567
|
+
])
|
|
3568
|
+
],
|
|
2981
3569
|
beforeRootFiles: () => setupPlugins(opts, rootDir, harenDir, project)
|
|
2982
3570
|
});
|
|
2983
3571
|
if (layout === "workspace" && !hasGitDir(harenDir)) {
|
|
@@ -3001,14 +3589,17 @@ var init_init = __esm(() => {
|
|
|
3001
3589
|
init_content_dir();
|
|
3002
3590
|
init_templates();
|
|
3003
3591
|
init_manifest();
|
|
3592
|
+
init_experimental2();
|
|
3593
|
+
init_experimental();
|
|
3004
3594
|
init_root_files();
|
|
3595
|
+
init_registry();
|
|
3005
3596
|
init_detect();
|
|
3006
3597
|
init_plan();
|
|
3007
3598
|
init_git();
|
|
3008
3599
|
init_progress();
|
|
3009
3600
|
init_version();
|
|
3010
3601
|
init_install();
|
|
3011
|
-
|
|
3602
|
+
init_registry2();
|
|
3012
3603
|
MODES = ["blueprint", "explore", "inherit", "migration", "undecided"];
|
|
3013
3604
|
EDITORS = ["claude-code", "cursor", "both"];
|
|
3014
3605
|
EDITOR_DESCRIPTIONS = {
|
|
@@ -3026,7 +3617,7 @@ var init_init = __esm(() => {
|
|
|
3026
3617
|
});
|
|
3027
3618
|
|
|
3028
3619
|
// src/lib/changelog.ts
|
|
3029
|
-
import { existsSync as
|
|
3620
|
+
import { existsSync as existsSync21, readFileSync as readFileSync2 } from "fs";
|
|
3030
3621
|
import { resolve as resolve10 } from "path";
|
|
3031
3622
|
function readChangelog(candidates) {
|
|
3032
3623
|
const probes = candidates ?? [
|
|
@@ -3034,7 +3625,7 @@ function readChangelog(candidates) {
|
|
|
3034
3625
|
resolve10(import.meta.dir, "..", "..", "..", "..", "CHANGELOG.md")
|
|
3035
3626
|
];
|
|
3036
3627
|
for (const path of probes) {
|
|
3037
|
-
if (
|
|
3628
|
+
if (existsSync21(path))
|
|
3038
3629
|
return readFileSync2(path, "utf-8");
|
|
3039
3630
|
}
|
|
3040
3631
|
return null;
|
|
@@ -3072,20 +3663,33 @@ function whatsNew(text, from, to) {
|
|
|
3072
3663
|
var init_changelog = () => {};
|
|
3073
3664
|
|
|
3074
3665
|
// src/commands/upgrade.ts
|
|
3075
|
-
import { mkdir as mkdir7, readdir as readdir5, copyFile as copyFile2, readFile as
|
|
3076
|
-
import { join as
|
|
3077
|
-
import { existsSync as
|
|
3666
|
+
import { mkdir as mkdir7, readdir as readdir5, copyFile as copyFile2, readFile as readFile10, stat as stat2, writeFile as writeFile7 } from "fs/promises";
|
|
3667
|
+
import { join as join19, resolve as resolve11 } from "path";
|
|
3668
|
+
import { existsSync as existsSync22 } from "fs";
|
|
3078
3669
|
async function moduleRepoKey(harenDir, moduleName) {
|
|
3079
|
-
const path =
|
|
3080
|
-
if (!
|
|
3670
|
+
const path = join19(harenDir, "artifacts", "03-modules", moduleName, "module.md");
|
|
3671
|
+
if (!existsSync22(path))
|
|
3081
3672
|
return;
|
|
3082
|
-
const match = (await
|
|
3673
|
+
const match = (await readFile10(path, "utf-8")).match(/^repos:\s*\[([^\]]*)\]/m);
|
|
3083
3674
|
return match?.[1].split(",")[0]?.trim().replace(/^["']|["']$/g, "") || undefined;
|
|
3084
3675
|
}
|
|
3676
|
+
function usableHosts(saved, multiHost) {
|
|
3677
|
+
const out = [];
|
|
3678
|
+
for (const id of saved) {
|
|
3679
|
+
const host = getHost(id);
|
|
3680
|
+
if (!host)
|
|
3681
|
+
console.warn(` warning: unknown host '${id}' in manifest.yaml hosts:; skipped`);
|
|
3682
|
+
else if (host.experimental && !multiHost) {
|
|
3683
|
+
console.warn(` warning: host '${id}' is experimental and multi-host is off; skipped. Run: haren experimental enable multi-host`);
|
|
3684
|
+
} else if (!out.includes(id))
|
|
3685
|
+
out.push(id);
|
|
3686
|
+
}
|
|
3687
|
+
return out;
|
|
3688
|
+
}
|
|
3085
3689
|
async function planMigration(location) {
|
|
3086
3690
|
const { harenDir, workspaceDir } = location;
|
|
3087
3691
|
const steps = [];
|
|
3088
|
-
const manifestBefore = await
|
|
3692
|
+
const manifestBefore = await readFile10(join19(harenDir, "manifest.yaml"), "utf-8");
|
|
3089
3693
|
const manifest = parseManifest(manifestBefore);
|
|
3090
3694
|
const layout = manifest.layout ?? (await inferLayout(workspaceDir)).layout ?? "workspace";
|
|
3091
3695
|
if (!hasMarker(manifest))
|
|
@@ -3111,15 +3715,22 @@ async function planMigration(location) {
|
|
|
3111
3715
|
steps.push("manifest.yaml: convert repos to a map with remotes");
|
|
3112
3716
|
}
|
|
3113
3717
|
}
|
|
3114
|
-
|
|
3718
|
+
let manifestAfter = migrateManifestText(manifestBefore, {
|
|
3115
3719
|
version: HAREN_VERSION,
|
|
3116
3720
|
layout,
|
|
3117
3721
|
repos
|
|
3118
3722
|
});
|
|
3723
|
+
const detected = detectEditor(workspaceDir) ?? "claude-code";
|
|
3724
|
+
const saved = readHosts(manifest);
|
|
3725
|
+
const hosts = saved ? usableHosts(saved, isExperimental(manifest, "multi-host")) : editorHosts(detected);
|
|
3726
|
+
if (!saved) {
|
|
3727
|
+
manifestAfter = writeManifestList(manifestAfter, "hosts", hosts);
|
|
3728
|
+
steps.push(`manifest.yaml: add hosts: [${hosts.join(", ")}]`);
|
|
3729
|
+
}
|
|
3119
3730
|
let progress = null;
|
|
3120
|
-
const progressPath =
|
|
3121
|
-
if (
|
|
3122
|
-
const before = await
|
|
3731
|
+
const progressPath = join19(harenDir, "progress.json");
|
|
3732
|
+
if (existsSync22(progressPath)) {
|
|
3733
|
+
const before = await readFile10(progressPath, "utf-8");
|
|
3123
3734
|
let raw;
|
|
3124
3735
|
try {
|
|
3125
3736
|
raw = JSON.parse(before);
|
|
@@ -3141,8 +3752,8 @@ async function planMigration(location) {
|
|
|
3141
3752
|
const gitignore = await planGitignore(harenDir);
|
|
3142
3753
|
if (gitignore !== null)
|
|
3143
3754
|
steps.push(`.gitignore: add ${IGNORED.join(", ")}`);
|
|
3144
|
-
const editor =
|
|
3145
|
-
const rootFiles = await computeRootFiles({ workspaceDir, harenDir,
|
|
3755
|
+
const editor = detected;
|
|
3756
|
+
const rootFiles = await computeRootFiles({ workspaceDir, harenDir, hosts });
|
|
3146
3757
|
for (const file of summarizeRootFiles(rootFiles).filter((f) => f.changed)) {
|
|
3147
3758
|
const count = file.count ? ` (${file.count} files)` : "";
|
|
3148
3759
|
steps.push(`${file.path}: ${file.existed ? "update" : "create"}${count}`);
|
|
@@ -3153,13 +3764,14 @@ async function planMigration(location) {
|
|
|
3153
3764
|
gitignore,
|
|
3154
3765
|
layout,
|
|
3155
3766
|
editor,
|
|
3767
|
+
hosts,
|
|
3156
3768
|
steps,
|
|
3157
3769
|
fromVersion: hasMarker(manifest) ? String(manifest.haren?.version) : undefined
|
|
3158
3770
|
};
|
|
3159
3771
|
}
|
|
3160
3772
|
async function planGitignore(harenDir) {
|
|
3161
|
-
const path =
|
|
3162
|
-
const before =
|
|
3773
|
+
const path = join19(harenDir, ".gitignore");
|
|
3774
|
+
const before = existsSync22(path) ? await readFile10(path, "utf-8") : "";
|
|
3163
3775
|
const lines = new Set(before.split(/\r?\n/).map((l) => l.trim()));
|
|
3164
3776
|
const missing = IGNORED.filter((f) => !lines.has(f));
|
|
3165
3777
|
if (missing.length === 0)
|
|
@@ -3176,8 +3788,8 @@ async function copyRecursive2(src, dest) {
|
|
|
3176
3788
|
const entries = await readdir5(src, { withFileTypes: true });
|
|
3177
3789
|
await mkdir7(dest, { recursive: true });
|
|
3178
3790
|
for (const entry of entries) {
|
|
3179
|
-
const srcPath =
|
|
3180
|
-
const destPath =
|
|
3791
|
+
const srcPath = join19(src, entry.name);
|
|
3792
|
+
const destPath = join19(dest, entry.name);
|
|
3181
3793
|
if (entry.isDirectory()) {
|
|
3182
3794
|
await copyRecursive2(srcPath, destPath);
|
|
3183
3795
|
} else {
|
|
@@ -3190,7 +3802,7 @@ async function countFiles(dir) {
|
|
|
3190
3802
|
const entries = await readdir5(dir, { withFileTypes: true });
|
|
3191
3803
|
for (const entry of entries) {
|
|
3192
3804
|
if (entry.isDirectory()) {
|
|
3193
|
-
count += await countFiles(
|
|
3805
|
+
count += await countFiles(join19(dir, entry.name));
|
|
3194
3806
|
} else {
|
|
3195
3807
|
count++;
|
|
3196
3808
|
}
|
|
@@ -3234,8 +3846,8 @@ async function upgrade(args) {
|
|
|
3234
3846
|
console.log("\x1B[2m Upgrading framework files:\x1B[0m");
|
|
3235
3847
|
let totalFiles = 0;
|
|
3236
3848
|
for (const dir of FRAMEWORK_DIRS) {
|
|
3237
|
-
const srcDir =
|
|
3238
|
-
const destDir =
|
|
3849
|
+
const srcDir = join19(contentDir, dir);
|
|
3850
|
+
const destDir = join19(targetDir, dir);
|
|
3239
3851
|
const fileCount = await countFiles(srcDir);
|
|
3240
3852
|
totalFiles += fileCount;
|
|
3241
3853
|
console.log(` \x1B[36m\u2191\x1B[0m ${dir}/ \x1B[2m(${fileCount} files)\x1B[0m`);
|
|
@@ -3255,19 +3867,19 @@ async function upgrade(args) {
|
|
|
3255
3867
|
return;
|
|
3256
3868
|
}
|
|
3257
3869
|
for (const dir of FRAMEWORK_DIRS) {
|
|
3258
|
-
await copyRecursive2(
|
|
3870
|
+
await copyRecursive2(join19(contentDir, dir), join19(targetDir, dir));
|
|
3259
3871
|
}
|
|
3260
3872
|
await Promise.resolve().then(() => init_init());
|
|
3261
3873
|
await scaffoldSkillMd(targetDir);
|
|
3262
3874
|
await writeGateScript(targetDir);
|
|
3263
3875
|
if (migration.manifest.after !== migration.manifest.before) {
|
|
3264
|
-
await
|
|
3876
|
+
await writeFile7(join19(targetDir, "manifest.yaml"), migration.manifest.after);
|
|
3265
3877
|
}
|
|
3266
3878
|
if (migration.progress) {
|
|
3267
|
-
await
|
|
3879
|
+
await writeFile7(join19(targetDir, "progress.json"), migration.progress.after);
|
|
3268
3880
|
}
|
|
3269
3881
|
if (migration.gitignore !== null) {
|
|
3270
|
-
await
|
|
3882
|
+
await writeFile7(join19(targetDir, ".gitignore"), migration.gitignore);
|
|
3271
3883
|
}
|
|
3272
3884
|
const yes = args.includes("--yes") || args.includes("-y");
|
|
3273
3885
|
const pluginCtx = {
|
|
@@ -3286,7 +3898,7 @@ async function upgrade(args) {
|
|
|
3286
3898
|
await writeRootFiles({
|
|
3287
3899
|
workspaceDir: location.workspaceDir,
|
|
3288
3900
|
harenDir: targetDir,
|
|
3289
|
-
|
|
3901
|
+
hosts: migration.hosts
|
|
3290
3902
|
});
|
|
3291
3903
|
console.log(` \x1B[32m\u2713\x1B[0m Upgraded ${totalFiles + 2} framework files.`);
|
|
3292
3904
|
console.log(` \x1B[2mYour artifacts are untouched. Manifest and progress were migrated if needed.\x1B[0m`);
|
|
@@ -3322,6 +3934,8 @@ var init_upgrade = __esm(() => {
|
|
|
3322
3934
|
init_progress();
|
|
3323
3935
|
init_resolve();
|
|
3324
3936
|
init_root_files();
|
|
3937
|
+
init_registry();
|
|
3938
|
+
init_experimental();
|
|
3325
3939
|
init_install();
|
|
3326
3940
|
init_templates();
|
|
3327
3941
|
IGNORED = [".agent.json", ".agent.pid", ".plugins/", ".companion/"];
|
|
@@ -3330,15 +3944,15 @@ var init_upgrade = __esm(() => {
|
|
|
3330
3944
|
});
|
|
3331
3945
|
|
|
3332
3946
|
// src/agent/config.ts
|
|
3333
|
-
import { join as
|
|
3947
|
+
import { join as join20 } from "path";
|
|
3334
3948
|
async function readAgentConfig(harenDir) {
|
|
3335
|
-
const file = Bun.file(
|
|
3949
|
+
const file = Bun.file(join20(harenDir, CONFIG_FILE));
|
|
3336
3950
|
if (!await file.exists())
|
|
3337
3951
|
return null;
|
|
3338
3952
|
return file.json();
|
|
3339
3953
|
}
|
|
3340
3954
|
async function writeAgentConfig(harenDir, config) {
|
|
3341
|
-
const path =
|
|
3955
|
+
const path = join20(harenDir, CONFIG_FILE);
|
|
3342
3956
|
await Bun.write(path, JSON.stringify(config, null, 2));
|
|
3343
3957
|
}
|
|
3344
3958
|
var CONFIG_FILE = ".agent.json";
|
|
@@ -3348,29 +3962,31 @@ var init_config = () => {};
|
|
|
3348
3962
|
async function checkCLI(command) {
|
|
3349
3963
|
return Bun.which(command) !== null;
|
|
3350
3964
|
}
|
|
3965
|
+
function knownCLIs() {
|
|
3966
|
+
const hosts = listHosts().flatMap((h) => h.exec ? [{ name: cliName(h), binary: h.exec({ prompt: "", cwd: "." })[0] }] : []);
|
|
3967
|
+
return [...hosts, ...EXTRA_CLIS.map((c) => ({ name: c, binary: c }))];
|
|
3968
|
+
}
|
|
3351
3969
|
async function detectCLIs() {
|
|
3352
|
-
const results = await Promise.all(
|
|
3353
|
-
name: cli,
|
|
3354
|
-
available: await checkCLI(cli)
|
|
3355
|
-
})));
|
|
3970
|
+
const results = await Promise.all(knownCLIs().map(async (cli) => ({ name: cli.name, available: await checkCLI(cli.binary) })));
|
|
3356
3971
|
return results.filter((r) => r.available).map((r) => r.name);
|
|
3357
3972
|
}
|
|
3358
|
-
var
|
|
3973
|
+
var EXTRA_CLIS;
|
|
3359
3974
|
var init_cli_detector = __esm(() => {
|
|
3360
|
-
|
|
3975
|
+
init_registry();
|
|
3976
|
+
EXTRA_CLIS = ["github-copilot-cli"];
|
|
3361
3977
|
});
|
|
3362
3978
|
|
|
3363
3979
|
// src/agent/artifact-reader.ts
|
|
3364
|
-
import { join as
|
|
3980
|
+
import { join as join21 } from "path";
|
|
3365
3981
|
import { readdir as readdir6 } from "fs/promises";
|
|
3366
3982
|
async function readProgress2(harenDir) {
|
|
3367
|
-
const file = Bun.file(
|
|
3983
|
+
const file = Bun.file(join21(harenDir, "progress.json"));
|
|
3368
3984
|
if (!await file.exists())
|
|
3369
3985
|
return null;
|
|
3370
3986
|
return file.json();
|
|
3371
3987
|
}
|
|
3372
3988
|
async function readArtifactTree(harenDir) {
|
|
3373
|
-
const artifactsDir =
|
|
3989
|
+
const artifactsDir = join21(harenDir, "artifacts");
|
|
3374
3990
|
try {
|
|
3375
3991
|
return await buildTree(artifactsDir, "artifacts");
|
|
3376
3992
|
} catch {
|
|
@@ -3381,9 +3997,9 @@ async function buildTree(dirPath, relativePath) {
|
|
|
3381
3997
|
const entries = await readdir6(dirPath, { withFileTypes: true });
|
|
3382
3998
|
const nodes = [];
|
|
3383
3999
|
for (const entry of entries) {
|
|
3384
|
-
const entryPath =
|
|
4000
|
+
const entryPath = join21(relativePath, entry.name);
|
|
3385
4001
|
if (entry.isDirectory()) {
|
|
3386
|
-
const children = await buildTree(
|
|
4002
|
+
const children = await buildTree(join21(dirPath, entry.name), entryPath);
|
|
3387
4003
|
nodes.push({
|
|
3388
4004
|
name: entry.name,
|
|
3389
4005
|
type: "directory",
|
|
@@ -3397,7 +4013,7 @@ async function buildTree(dirPath, relativePath) {
|
|
|
3397
4013
|
return nodes.sort((a, b) => a.name.localeCompare(b.name));
|
|
3398
4014
|
}
|
|
3399
4015
|
async function readArtifact(harenDir, relativePath) {
|
|
3400
|
-
const file = Bun.file(
|
|
4016
|
+
const file = Bun.file(join21(harenDir, relativePath));
|
|
3401
4017
|
if (!await file.exists())
|
|
3402
4018
|
return null;
|
|
3403
4019
|
return file.text();
|
|
@@ -3459,20 +4075,22 @@ async function executeCLI(cli, prompt2, onOutput) {
|
|
|
3459
4075
|
}
|
|
3460
4076
|
}
|
|
3461
4077
|
function buildCLIArgs(cli, prompt2) {
|
|
4078
|
+
const host = hostForCli(cli);
|
|
4079
|
+
if (host?.exec)
|
|
4080
|
+
return host.exec({ prompt: prompt2, cwd: process.cwd() });
|
|
3462
4081
|
switch (cli) {
|
|
3463
|
-
case "claude":
|
|
3464
|
-
return ["claude", "--print", prompt2];
|
|
3465
|
-
case "cursor":
|
|
3466
|
-
return ["cursor", "--prompt", prompt2];
|
|
3467
4082
|
case "github-copilot-cli":
|
|
3468
4083
|
return ["github-copilot-cli", prompt2];
|
|
3469
4084
|
default:
|
|
3470
4085
|
return [cli, prompt2];
|
|
3471
4086
|
}
|
|
3472
4087
|
}
|
|
4088
|
+
var init_cli_executor = __esm(() => {
|
|
4089
|
+
init_registry();
|
|
4090
|
+
});
|
|
3473
4091
|
|
|
3474
4092
|
// src/workspace/events.ts
|
|
3475
|
-
import { appendFile, readFile as
|
|
4093
|
+
import { appendFile, readFile as readFile11 } from "fs/promises";
|
|
3476
4094
|
function isEventPhase(value) {
|
|
3477
4095
|
return typeof value === "string" && EVENT_PHASES.includes(value);
|
|
3478
4096
|
}
|
|
@@ -3549,10 +4167,11 @@ async function handleCommand(commandId, prompt2, cli, config, send) {
|
|
|
3549
4167
|
}
|
|
3550
4168
|
var init_request_handler = __esm(() => {
|
|
3551
4169
|
init_artifact_reader();
|
|
4170
|
+
init_cli_executor();
|
|
3552
4171
|
});
|
|
3553
4172
|
|
|
3554
4173
|
// src/agent/connection.ts
|
|
3555
|
-
import { join as
|
|
4174
|
+
import { join as join22 } from "path";
|
|
3556
4175
|
function buildWsUrl(portalUrl) {
|
|
3557
4176
|
return portalUrl.replace(/^https/, "wss").replace(/^http/, "ws") + "/ws/agent";
|
|
3558
4177
|
}
|
|
@@ -3566,7 +4185,7 @@ function buildAuthMessage(opts) {
|
|
|
3566
4185
|
};
|
|
3567
4186
|
}
|
|
3568
4187
|
async function connectToPortal(config) {
|
|
3569
|
-
await Bun.write(
|
|
4188
|
+
await Bun.write(join22(config.harenDir, ".agent.pid"), process.pid.toString());
|
|
3570
4189
|
setupCleanup(config.harenDir);
|
|
3571
4190
|
try {
|
|
3572
4191
|
await connectWebSocket(config);
|
|
@@ -3722,7 +4341,7 @@ async function connectPolling(config) {
|
|
|
3722
4341
|
}
|
|
3723
4342
|
}
|
|
3724
4343
|
function setupCleanup(harenDir) {
|
|
3725
|
-
const pidPath =
|
|
4344
|
+
const pidPath = join22(harenDir, ".agent.pid");
|
|
3726
4345
|
const cleanup = async () => {
|
|
3727
4346
|
console.log("Agent shutting down...");
|
|
3728
4347
|
const { unlink } = await import("fs/promises");
|
|
@@ -3735,7 +4354,7 @@ function setupCleanup(harenDir) {
|
|
|
3735
4354
|
var init_connection = () => {};
|
|
3736
4355
|
|
|
3737
4356
|
// src/commands/agent.ts
|
|
3738
|
-
import { join as
|
|
4357
|
+
import { join as join23 } from "path";
|
|
3739
4358
|
function readLine2(question) {
|
|
3740
4359
|
process.stdout.write(question);
|
|
3741
4360
|
return new Promise((resolve) => {
|
|
@@ -3829,7 +4448,7 @@ async function startAgent(harenDir) {
|
|
|
3829
4448
|
config = { portalUrl, teamCode, userId, userName };
|
|
3830
4449
|
await writeAgentConfig(harenDir, config);
|
|
3831
4450
|
console.log(`
|
|
3832
|
-
Config saved to ${
|
|
4451
|
+
Config saved to ${join23(harenDir, ".agent.json")}`);
|
|
3833
4452
|
}
|
|
3834
4453
|
const gitRemoteUrl = await getRemoteUrl(harenDir);
|
|
3835
4454
|
if (!gitRemoteUrl) {
|
|
@@ -3853,7 +4472,7 @@ Config saved to ${join15(harenDir, ".agent.json")}`);
|
|
|
3853
4472
|
});
|
|
3854
4473
|
}
|
|
3855
4474
|
async function stopAgent(harenDir) {
|
|
3856
|
-
const pidFile = Bun.file(
|
|
4475
|
+
const pidFile = Bun.file(join23(harenDir, ".agent.pid"));
|
|
3857
4476
|
if (!await pidFile.exists()) {
|
|
3858
4477
|
console.log("Agent is not running.");
|
|
3859
4478
|
return;
|
|
@@ -3866,7 +4485,7 @@ async function stopAgent(harenDir) {
|
|
|
3866
4485
|
console.log("Agent process not found. Cleaning up.");
|
|
3867
4486
|
}
|
|
3868
4487
|
const { unlink } = await import("fs/promises");
|
|
3869
|
-
await unlink(
|
|
4488
|
+
await unlink(join23(harenDir, ".agent.pid")).catch(() => {});
|
|
3870
4489
|
}
|
|
3871
4490
|
async function showStatus(harenDir) {
|
|
3872
4491
|
const config = await readAgentConfig(harenDir);
|
|
@@ -3874,7 +4493,7 @@ async function showStatus(harenDir) {
|
|
|
3874
4493
|
console.log("Agent is not configured. Run 'haren agent start' first.");
|
|
3875
4494
|
return;
|
|
3876
4495
|
}
|
|
3877
|
-
const pidFile = Bun.file(
|
|
4496
|
+
const pidFile = Bun.file(join23(harenDir, ".agent.pid"));
|
|
3878
4497
|
const isRunning = await pidFile.exists();
|
|
3879
4498
|
console.log(`Portal: ${config.portalUrl}`);
|
|
3880
4499
|
console.log(`Team: ${config.teamCode}`);
|
|
@@ -3991,21 +4610,21 @@ var init_updates = __esm(() => {
|
|
|
3991
4610
|
});
|
|
3992
4611
|
|
|
3993
4612
|
// src/plugins/runner.ts
|
|
3994
|
-
import { existsSync as
|
|
3995
|
-
import { appendFile as appendFile2, mkdir as mkdir8, readFile as
|
|
3996
|
-
import { isAbsolute as isAbsolute3, join as
|
|
4613
|
+
import { existsSync as existsSync23 } from "fs";
|
|
4614
|
+
import { appendFile as appendFile2, mkdir as mkdir8, readFile as readFile12 } from "fs/promises";
|
|
4615
|
+
import { isAbsolute as isAbsolute3, join as join24 } from "path";
|
|
3997
4616
|
function tasksPath(input, harenDir) {
|
|
3998
4617
|
if (typeof input.tasksFile !== "string")
|
|
3999
4618
|
return;
|
|
4000
|
-
return isAbsolute3(input.tasksFile) ? input.tasksFile :
|
|
4619
|
+
return isAbsolute3(input.tasksFile) ? input.tasksFile : join24(harenDir, input.tasksFile);
|
|
4001
4620
|
}
|
|
4002
4621
|
async function loadPlannedTasks(input, harenDir) {
|
|
4003
4622
|
const path = tasksPath(input, harenDir);
|
|
4004
|
-
if (!path || !
|
|
4623
|
+
if (!path || !existsSync23(path))
|
|
4005
4624
|
return [];
|
|
4006
|
-
const tasks = parseTasksFile(await
|
|
4007
|
-
const progressPath =
|
|
4008
|
-
if (typeof input.module !== "string" || !
|
|
4625
|
+
const tasks = parseTasksFile(await readFile12(path, "utf-8"));
|
|
4626
|
+
const progressPath = join24(harenDir, "progress.json");
|
|
4627
|
+
if (typeof input.module !== "string" || !existsSync23(progressPath))
|
|
4009
4628
|
return tasks;
|
|
4010
4629
|
try {
|
|
4011
4630
|
const mod = (await readProgress(progressPath)).modules[input.module];
|
|
@@ -4024,8 +4643,8 @@ async function buildPayload(hook, input, harenDir) {
|
|
|
4024
4643
|
return payload;
|
|
4025
4644
|
}
|
|
4026
4645
|
async function addPlannedFeatures(input, harenDir) {
|
|
4027
|
-
const progressPath =
|
|
4028
|
-
if (typeof input.module !== "string" || !
|
|
4646
|
+
const progressPath = join24(harenDir, "progress.json");
|
|
4647
|
+
if (typeof input.module !== "string" || !existsSync23(progressPath))
|
|
4029
4648
|
return;
|
|
4030
4649
|
const tasks = await loadPlannedTasks(input, harenDir);
|
|
4031
4650
|
const progress = await readProgress(progressPath);
|
|
@@ -4043,7 +4662,7 @@ async function addPlannedFeatures(input, harenDir) {
|
|
|
4043
4662
|
await writeProgress(progressPath, progress);
|
|
4044
4663
|
}
|
|
4045
4664
|
async function logError(dir, hook, error) {
|
|
4046
|
-
await appendFile2(
|
|
4665
|
+
await appendFile2(join24(dir, "errors.log"), `${new Date().toISOString()} ${hook}: ${error}
|
|
4047
4666
|
`).catch(() => {});
|
|
4048
4667
|
}
|
|
4049
4668
|
async function runHook(hook, input, o) {
|
|
@@ -4175,8 +4794,8 @@ async function runHookAndApply(hook, input, o) {
|
|
|
4175
4794
|
updates.push(...out.updates);
|
|
4176
4795
|
}
|
|
4177
4796
|
try {
|
|
4178
|
-
const progressPath =
|
|
4179
|
-
if (updates.length > 0 &&
|
|
4797
|
+
const progressPath = join24(o.harenDir, "progress.json");
|
|
4798
|
+
if (updates.length > 0 && existsSync23(progressPath)) {
|
|
4180
4799
|
const result = applyUpdates(await readProgress(progressPath), updates);
|
|
4181
4800
|
if (result.applied.length > 0)
|
|
4182
4801
|
await writeProgress(progressPath, result.progress);
|
|
@@ -4198,12 +4817,12 @@ var init_runner = __esm(() => {
|
|
|
4198
4817
|
});
|
|
4199
4818
|
|
|
4200
4819
|
// src/commands/plugin.ts
|
|
4201
|
-
import { readFile as
|
|
4202
|
-
import { join as
|
|
4820
|
+
import { readFile as readFile13 } from "fs/promises";
|
|
4821
|
+
import { join as join25 } from "path";
|
|
4203
4822
|
function parsePluginArgs(args) {
|
|
4204
4823
|
const sub = args[0];
|
|
4205
4824
|
if (!SUBS.includes(sub))
|
|
4206
|
-
throw new Error(
|
|
4825
|
+
throw new Error(USAGE2);
|
|
4207
4826
|
const yes = args.includes("--yes") || args.includes("-y");
|
|
4208
4827
|
const target = args[1] && !args[1].startsWith("-") ? args[1] : undefined;
|
|
4209
4828
|
if ((sub === "add" || sub === "remove") && !target)
|
|
@@ -4279,7 +4898,7 @@ async function plugin(args) {
|
|
|
4279
4898
|
process.exit(1);
|
|
4280
4899
|
}
|
|
4281
4900
|
const { workspaceDir, harenDir } = location;
|
|
4282
|
-
const manifest = parseManifest(await
|
|
4901
|
+
const manifest = parseManifest(await readFile13(join25(harenDir, "manifest.yaml"), "utf-8"));
|
|
4283
4902
|
const ctx = {
|
|
4284
4903
|
workspaceDir,
|
|
4285
4904
|
harenDir,
|
|
@@ -4334,7 +4953,7 @@ async function plugin(args) {
|
|
|
4334
4953
|
} catch (err) {
|
|
4335
4954
|
console.log(` ${name}: ${err.message}`);
|
|
4336
4955
|
}
|
|
4337
|
-
const log = Bun.file(
|
|
4956
|
+
const log = Bun.file(join25(dir, "errors.log"));
|
|
4338
4957
|
if (await log.exists()) {
|
|
4339
4958
|
const last = (await log.text()).trim().split(`
|
|
4340
4959
|
`).slice(-3);
|
|
@@ -4346,7 +4965,7 @@ async function plugin(args) {
|
|
|
4346
4965
|
}
|
|
4347
4966
|
}
|
|
4348
4967
|
}
|
|
4349
|
-
var SUBS,
|
|
4968
|
+
var SUBS, USAGE2 = "Usage: haren plugin add <name|source> | remove <name> | list | run <hook> [--payload <json>] | doctor";
|
|
4350
4969
|
var init_plugin = __esm(() => {
|
|
4351
4970
|
init_manifest2();
|
|
4352
4971
|
init_install();
|
|
@@ -4359,8 +4978,8 @@ var init_plugin = __esm(() => {
|
|
|
4359
4978
|
});
|
|
4360
4979
|
|
|
4361
4980
|
// src/plugins/adapter-read.ts
|
|
4362
|
-
import { existsSync as
|
|
4363
|
-
import { join as
|
|
4981
|
+
import { existsSync as existsSync24 } from "fs";
|
|
4982
|
+
import { join as join26 } from "path";
|
|
4364
4983
|
function adapterMissingMessage(name) {
|
|
4365
4984
|
return `Adapter '${name}' is named in manifest.yaml but not installed. Run \`haren plugin add <source>\`, or remove migration.adapter to work by hand.`;
|
|
4366
4985
|
}
|
|
@@ -4369,7 +4988,7 @@ async function readAdapter(harenDir, name) {
|
|
|
4369
4988
|
if (!plugins[name])
|
|
4370
4989
|
return null;
|
|
4371
4990
|
const dir = pluginDir(harenDir, name);
|
|
4372
|
-
if (!
|
|
4991
|
+
if (!existsSync24(join26(dir, "haren-plugin.json")))
|
|
4373
4992
|
return null;
|
|
4374
4993
|
try {
|
|
4375
4994
|
return (await readInstalledManifest(dir)).adapter ?? null;
|
|
@@ -4383,9 +5002,9 @@ var init_adapter_read = __esm(() => {
|
|
|
4383
5002
|
});
|
|
4384
5003
|
|
|
4385
5004
|
// src/commands/track.ts
|
|
4386
|
-
import { existsSync as
|
|
4387
|
-
import { mkdir as mkdir9, readdir as readdir7, readFile as
|
|
4388
|
-
import { dirname as dirname5, join as
|
|
5005
|
+
import { existsSync as existsSync25 } from "fs";
|
|
5006
|
+
import { mkdir as mkdir9, readdir as readdir7, readFile as readFile14, writeFile as writeFile8 } from "fs/promises";
|
|
5007
|
+
import { dirname as dirname5, join as join27, relative as relative4, sep as sep4 } from "path";
|
|
4389
5008
|
function parseTrackArgs(args) {
|
|
4390
5009
|
const positional = [];
|
|
4391
5010
|
const flags = {};
|
|
@@ -4413,9 +5032,9 @@ function parseTrackArgs(args) {
|
|
|
4413
5032
|
function pathsFor(harenDir) {
|
|
4414
5033
|
return {
|
|
4415
5034
|
harenDir,
|
|
4416
|
-
progress:
|
|
4417
|
-
events:
|
|
4418
|
-
registry:
|
|
5035
|
+
progress: join27(harenDir, "progress.json"),
|
|
5036
|
+
events: join27(harenDir, "events", "events.jsonl"),
|
|
5037
|
+
registry: join27(harenDir, "artifacts", "_registry", "artifact-index.md")
|
|
4419
5038
|
};
|
|
4420
5039
|
}
|
|
4421
5040
|
async function emit(paths, event) {
|
|
@@ -4435,7 +5054,7 @@ function requireModule(progress, name) {
|
|
|
4435
5054
|
}
|
|
4436
5055
|
}
|
|
4437
5056
|
async function loadProgress(paths) {
|
|
4438
|
-
if (!
|
|
5057
|
+
if (!existsSync25(paths.progress))
|
|
4439
5058
|
throw new Error(`No progress.json in ${paths.harenDir}`);
|
|
4440
5059
|
return readProgress(paths.progress);
|
|
4441
5060
|
}
|
|
@@ -4484,19 +5103,19 @@ async function trackUiMode(paths, rest) {
|
|
|
4484
5103
|
if (!UI_MODES.includes(mode)) {
|
|
4485
5104
|
throw new Error(`Invalid ui mode '${mode}'. Use ${UI_MODES.join(", ")}.`);
|
|
4486
5105
|
}
|
|
4487
|
-
const manifestPath =
|
|
4488
|
-
if (!
|
|
5106
|
+
const manifestPath = join27(paths.harenDir, "manifest.yaml");
|
|
5107
|
+
if (!existsSync25(manifestPath))
|
|
4489
5108
|
throw new Error(`No manifest.yaml in ${paths.harenDir}`);
|
|
4490
|
-
const text = await
|
|
4491
|
-
await
|
|
5109
|
+
const text = await readFile14(manifestPath, "utf-8");
|
|
5110
|
+
await writeFile8(manifestPath, setUiModeText(text, mode));
|
|
4492
5111
|
await emit(paths, { type: "ui-mode", mode });
|
|
4493
5112
|
console.log(` UI mockups mode: ${mode}.`);
|
|
4494
5113
|
}
|
|
4495
5114
|
async function loadMigration(paths) {
|
|
4496
|
-
const manifestPath =
|
|
4497
|
-
if (!
|
|
5115
|
+
const manifestPath = join27(paths.harenDir, "manifest.yaml");
|
|
5116
|
+
if (!existsSync25(manifestPath))
|
|
4498
5117
|
return null;
|
|
4499
|
-
return readMigrationConfig(parseManifest(await
|
|
5118
|
+
return readMigrationConfig(parseManifest(await readFile14(manifestPath, "utf-8")));
|
|
4500
5119
|
}
|
|
4501
5120
|
async function adapterCommands(paths, migration) {
|
|
4502
5121
|
if (!migration.adapter)
|
|
@@ -4552,8 +5171,8 @@ ${TRACK_USAGE}`);
|
|
|
4552
5171
|
return meta;
|
|
4553
5172
|
}
|
|
4554
5173
|
async function allowedRepoKeys(paths) {
|
|
4555
|
-
const manifestPath =
|
|
4556
|
-
const manifest =
|
|
5174
|
+
const manifestPath = join27(paths.harenDir, "manifest.yaml");
|
|
5175
|
+
const manifest = existsSync25(manifestPath) ? parseManifest(await readFile14(manifestPath, "utf-8")) : {};
|
|
4557
5176
|
const declared = Object.keys(normalizeRepos(manifest.repos));
|
|
4558
5177
|
return { allowed: declared.length ? declared : ["default"], empty: !declared.length };
|
|
4559
5178
|
}
|
|
@@ -4783,9 +5402,9 @@ async function trackArtifact(paths, rest, flags) {
|
|
|
4783
5402
|
const progress = await loadProgress(paths);
|
|
4784
5403
|
requireModule(progress, flags.module);
|
|
4785
5404
|
}
|
|
4786
|
-
const existing =
|
|
5405
|
+
const existing = existsSync25(paths.registry) ? await readFile14(paths.registry, "utf-8") : "";
|
|
4787
5406
|
await mkdir9(dirname5(paths.registry), { recursive: true });
|
|
4788
|
-
await
|
|
5407
|
+
await writeFile8(paths.registry, upsertArtifactRow(existing, [id, artifactType, module, status, path]));
|
|
4789
5408
|
await emit(paths, {
|
|
4790
5409
|
type: "artifact",
|
|
4791
5410
|
id,
|
|
@@ -4847,14 +5466,14 @@ async function trackOverride(paths, rest, flags) {
|
|
|
4847
5466
|
}
|
|
4848
5467
|
}
|
|
4849
5468
|
async function listArtifactFiles(artifactsDir) {
|
|
4850
|
-
if (!
|
|
5469
|
+
if (!existsSync25(artifactsDir))
|
|
4851
5470
|
return [];
|
|
4852
5471
|
const out = [];
|
|
4853
5472
|
const walk = async (dir) => {
|
|
4854
5473
|
for (const entry of await readdir7(dir, { withFileTypes: true })) {
|
|
4855
5474
|
if (entry.name.startsWith("."))
|
|
4856
5475
|
continue;
|
|
4857
|
-
const full =
|
|
5476
|
+
const full = join27(dir, entry.name);
|
|
4858
5477
|
if (entry.isDirectory()) {
|
|
4859
5478
|
if (dir === artifactsDir && UNTRACKED_DIRS.has(entry.name))
|
|
4860
5479
|
continue;
|
|
@@ -4888,8 +5507,8 @@ async function checkWorkspace(paths) {
|
|
|
4888
5507
|
const errors = [];
|
|
4889
5508
|
const warnings = [];
|
|
4890
5509
|
const progress = await loadProgress(paths);
|
|
4891
|
-
const manifestPath =
|
|
4892
|
-
const manifest =
|
|
5510
|
+
const manifestPath = join27(paths.harenDir, "manifest.yaml");
|
|
5511
|
+
const manifest = existsSync25(manifestPath) ? parseManifest(await readFile14(manifestPath, "utf-8")) : {};
|
|
4893
5512
|
const { allowed: allowedKeys, empty: noRepos } = await allowedRepoKeys(paths);
|
|
4894
5513
|
const declared = new Set(allowedKeys);
|
|
4895
5514
|
for (const [name, mod] of Object.entries(progress.modules)) {
|
|
@@ -4929,10 +5548,10 @@ async function checkWorkspace(paths) {
|
|
|
4929
5548
|
errors.push(`module '${name}' unit '${unit}' does not match migration.unitId`);
|
|
4930
5549
|
}
|
|
4931
5550
|
if (mig.adapter && unitAtLeast(status, "spec-approved")) {
|
|
4932
|
-
const gate =
|
|
5551
|
+
const gate = join27(paths.harenDir, "artifacts", "02-discovery", "units", unit, "gate.json");
|
|
4933
5552
|
let ok = false;
|
|
4934
5553
|
try {
|
|
4935
|
-
ok = JSON.parse(await
|
|
5554
|
+
ok = JSON.parse(await readFile14(gate, "utf-8")).pass === true;
|
|
4936
5555
|
} catch {
|
|
4937
5556
|
ok = false;
|
|
4938
5557
|
}
|
|
@@ -4943,10 +5562,10 @@ async function checkWorkspace(paths) {
|
|
|
4943
5562
|
}
|
|
4944
5563
|
}
|
|
4945
5564
|
}
|
|
4946
|
-
const registryText =
|
|
5565
|
+
const registryText = existsSync25(paths.registry) ? await readFile14(paths.registry, "utf-8") : "";
|
|
4947
5566
|
const rows = parseRegistryRows(registryText);
|
|
4948
5567
|
const indexed = new Set(rows.map((r) => normalizeArtifactPath(r.path)));
|
|
4949
|
-
const artifactsDir =
|
|
5568
|
+
const artifactsDir = join27(paths.harenDir, "artifacts");
|
|
4950
5569
|
for (const file of await listArtifactFiles(artifactsDir)) {
|
|
4951
5570
|
const rel = relative4(artifactsDir, file).split(sep4).join("/");
|
|
4952
5571
|
if (!indexed.has(rel)) {
|
|
@@ -4955,7 +5574,7 @@ async function checkWorkspace(paths) {
|
|
|
4955
5574
|
}
|
|
4956
5575
|
for (const row of rows) {
|
|
4957
5576
|
const rel = normalizeArtifactPath(row.path);
|
|
4958
|
-
if (!
|
|
5577
|
+
if (!existsSync25(join27(artifactsDir, rel))) {
|
|
4959
5578
|
errors.push(`index row ${row.id} points to missing file artifacts/${rel}`);
|
|
4960
5579
|
}
|
|
4961
5580
|
}
|
|
@@ -5080,9 +5699,9 @@ var init_adapter_run = __esm(() => {
|
|
|
5080
5699
|
});
|
|
5081
5700
|
|
|
5082
5701
|
// src/commands/migrate.ts
|
|
5083
|
-
import { existsSync as
|
|
5084
|
-
import { mkdir as mkdir10, readFile as
|
|
5085
|
-
import { dirname as dirname6, join as
|
|
5702
|
+
import { existsSync as existsSync26 } from "fs";
|
|
5703
|
+
import { mkdir as mkdir10, readFile as readFile15, writeFile as writeFile9 } from "fs/promises";
|
|
5704
|
+
import { dirname as dirname6, join as join28, resolve as resolve12 } from "path";
|
|
5086
5705
|
function parseMigrateArgs(args) {
|
|
5087
5706
|
const positional = [];
|
|
5088
5707
|
const flags = {};
|
|
@@ -5175,7 +5794,7 @@ async function loadContext(harenDir) {
|
|
|
5175
5794
|
const migration = await loadMigration(paths);
|
|
5176
5795
|
if (!migration)
|
|
5177
5796
|
throw new Error("haren migrate needs mode: migration in manifest.yaml");
|
|
5178
|
-
const manifest = parseManifest(await
|
|
5797
|
+
const manifest = parseManifest(await readFile15(join28(harenDir, "manifest.yaml"), "utf-8"));
|
|
5179
5798
|
const legacy = legacyRepo(manifest);
|
|
5180
5799
|
if (!legacy)
|
|
5181
5800
|
throw new Error("haren migrate needs a repo with role: legacy in manifest.yaml");
|
|
@@ -5224,8 +5843,8 @@ async function inventory(ctx, moduleFlag) {
|
|
|
5224
5843
|
const badIds = raw.units.filter((u) => !ctx.migration.unitId.test(u.id)).map((u) => u.id);
|
|
5225
5844
|
const out = { units: raw.units.filter((u) => ctx.migration.unitId.test(u.id)) };
|
|
5226
5845
|
const mapRel = "artifacts/02-discovery/unit-map.md";
|
|
5227
|
-
const mapPath =
|
|
5228
|
-
const previous =
|
|
5846
|
+
const mapPath = join28(ctx.paths.harenDir, mapRel);
|
|
5847
|
+
const previous = existsSync26(mapPath) ? await readFile15(mapPath, "utf-8") : "";
|
|
5229
5848
|
const known = parseUnitMap(previous);
|
|
5230
5849
|
const moduleOf = {};
|
|
5231
5850
|
const units = [];
|
|
@@ -5250,7 +5869,7 @@ async function inventory(ctx, moduleFlag) {
|
|
|
5250
5869
|
moduleOf[id] = row.module;
|
|
5251
5870
|
}
|
|
5252
5871
|
await mkdir10(dirname6(mapPath), { recursive: true });
|
|
5253
|
-
await
|
|
5872
|
+
await writeFile9(mapPath, renderUnitMap(units, moduleOf, previous));
|
|
5254
5873
|
const added = [];
|
|
5255
5874
|
const skipped = [];
|
|
5256
5875
|
for (const u of out.units) {
|
|
@@ -5269,10 +5888,10 @@ async function inventory(ctx, moduleFlag) {
|
|
|
5269
5888
|
for (const [module, unit] of added) {
|
|
5270
5889
|
await emit(ctx.paths, { type: "unit-status", module, unit, from: null, to: "inventoried" });
|
|
5271
5890
|
}
|
|
5272
|
-
const registry =
|
|
5891
|
+
const registry = existsSync26(ctx.paths.registry) ? await readFile15(ctx.paths.registry, "utf-8") : "";
|
|
5273
5892
|
if (!/^\|\s*UNITMAP-001\s*\|/m.test(registry)) {
|
|
5274
5893
|
await mkdir10(dirname6(ctx.paths.registry), { recursive: true });
|
|
5275
|
-
await
|
|
5894
|
+
await writeFile9(ctx.paths.registry, upsertArtifactRow(registry, ["UNITMAP-001", "unit-map", "-", "draft", mapRel]));
|
|
5276
5895
|
}
|
|
5277
5896
|
console.log(` inventory: ${fresh} new, ${out.units.length - fresh} known, ${gone.length} disappeared`);
|
|
5278
5897
|
if (gone.length)
|
|
@@ -5311,8 +5930,8 @@ async function gate(ctx, unit, approve) {
|
|
|
5311
5930
|
const progress = await readProgress(ctx.paths.progress);
|
|
5312
5931
|
const module = moduleOfUnit(progress, unit);
|
|
5313
5932
|
const unitDir = unitDirFor(ctx, unit);
|
|
5314
|
-
const specPath =
|
|
5315
|
-
if (!
|
|
5933
|
+
const specPath = join28(unitDir, "spec.md");
|
|
5934
|
+
if (!existsSync26(specPath))
|
|
5316
5935
|
throw new Error(`No spec at ${specPath}. Write the spec first.`);
|
|
5317
5936
|
const from = progress.modules[module].units[unit];
|
|
5318
5937
|
if (from !== "spec-draft" && from !== "spec-approved") {
|
|
@@ -5325,7 +5944,7 @@ async function gate(ctx, unit, approve) {
|
|
|
5325
5944
|
console.error(` adapter error: ${e instanceof Error ? e.message : String(e)}`);
|
|
5326
5945
|
throw e;
|
|
5327
5946
|
}
|
|
5328
|
-
await
|
|
5947
|
+
await writeFile9(join28(unitDir, "gate.json"), `${JSON.stringify({ ...out, ranAt: new Date().toISOString() }, null, 2)}
|
|
5329
5948
|
`);
|
|
5330
5949
|
if (!out.pass) {
|
|
5331
5950
|
for (const f of out.findings)
|
|
@@ -5363,7 +5982,7 @@ var MIGRATE_USAGE = `Usage:
|
|
|
5363
5982
|
haren migrate extract <unit>
|
|
5364
5983
|
haren migrate gate <unit> [--approve]
|
|
5365
5984
|
Options: --haren-dir <path>`, UNIT_MAP_HEADER = `| Unit | Parent | Family | Title | Module |
|
|
5366
|
-
|------|--------|--------|-------|--------|`, cell = (v) => v ? v.replaceAll("|", "\\|") : "-", unitDirFor = (ctx, unit) =>
|
|
5985
|
+
|------|--------|--------|-------|--------|`, cell = (v) => v ? v.replaceAll("|", "\\|") : "-", unitDirFor = (ctx, unit) => join28(ctx.paths.harenDir, "artifacts", "02-discovery", "units", unit);
|
|
5367
5986
|
var init_migrate = __esm(() => {
|
|
5368
5987
|
init_manifest();
|
|
5369
5988
|
init_progress();
|
|
@@ -5797,7 +6416,7 @@ import { randomBytes, timingSafeEqual } from "crypto";
|
|
|
5797
6416
|
import {
|
|
5798
6417
|
appendFileSync,
|
|
5799
6418
|
chmodSync,
|
|
5800
|
-
existsSync as
|
|
6419
|
+
existsSync as existsSync27,
|
|
5801
6420
|
lstatSync,
|
|
5802
6421
|
mkdirSync,
|
|
5803
6422
|
readdirSync,
|
|
@@ -5807,7 +6426,7 @@ import {
|
|
|
5807
6426
|
statSync,
|
|
5808
6427
|
writeFileSync
|
|
5809
6428
|
} from "fs";
|
|
5810
|
-
import { basename as basename5, extname, join as
|
|
6429
|
+
import { basename as basename5, extname, join as join29, sep as sep5 } from "path";
|
|
5811
6430
|
function makePrivateDir(dir) {
|
|
5812
6431
|
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
5813
6432
|
try {
|
|
@@ -5845,7 +6464,7 @@ function newestScreen(contentDir) {
|
|
|
5845
6464
|
for (const name of names) {
|
|
5846
6465
|
if (name.startsWith(".") || !name.endsWith(".html"))
|
|
5847
6466
|
continue;
|
|
5848
|
-
const fp =
|
|
6467
|
+
const fp = join29(contentDir, name);
|
|
5849
6468
|
if (!isRegularFileInside(contentDir, fp))
|
|
5850
6469
|
continue;
|
|
5851
6470
|
const mtime = statSync(fp).mtimeMs;
|
|
@@ -5885,14 +6504,14 @@ function urlHostForHttp(host) {
|
|
|
5885
6504
|
return host.includes(":") ? `[${host}]` : host;
|
|
5886
6505
|
}
|
|
5887
6506
|
async function startCompanion(opts) {
|
|
5888
|
-
const contentDir =
|
|
5889
|
-
const stateDir =
|
|
6507
|
+
const contentDir = join29(opts.sessionDir, "content");
|
|
6508
|
+
const stateDir = join29(opts.sessionDir, "state");
|
|
5890
6509
|
for (const dir of [opts.sessionDir, contentDir, stateDir])
|
|
5891
6510
|
makePrivateDir(dir);
|
|
5892
|
-
const stoppedFile =
|
|
5893
|
-
const eventsFile =
|
|
6511
|
+
const stoppedFile = join29(stateDir, "server-stopped");
|
|
6512
|
+
const eventsFile = join29(stateDir, "events");
|
|
5894
6513
|
rmSync(stoppedFile, { force: true });
|
|
5895
|
-
if (
|
|
6514
|
+
if (existsSync27(eventsFile))
|
|
5896
6515
|
chmodSync(eventsFile, 384);
|
|
5897
6516
|
const key = opts.key ?? randomBytes(16).toString("hex");
|
|
5898
6517
|
const idleTimeoutMs = opts.idleTimeoutMs ?? 240 * 60000;
|
|
@@ -5953,7 +6572,7 @@ async function startCompanion(opts) {
|
|
|
5953
6572
|
} catch {
|
|
5954
6573
|
return respond("Not found", "text/plain", 404, extra);
|
|
5955
6574
|
}
|
|
5956
|
-
const fp =
|
|
6575
|
+
const fp = join29(contentDir, name);
|
|
5957
6576
|
if (!name || name.startsWith(".") || !isRegularFileInside(contentDir, fp)) {
|
|
5958
6577
|
return respond("Not found", "text/plain", 404, extra);
|
|
5959
6578
|
}
|
|
@@ -6027,7 +6646,7 @@ async function startCompanion(opts) {
|
|
|
6027
6646
|
screen_dir: contentDir,
|
|
6028
6647
|
state_dir: stateDir
|
|
6029
6648
|
};
|
|
6030
|
-
writePrivateFile(
|
|
6649
|
+
writePrivateFile(join29(stateDir, "server-info"), `${JSON.stringify(info)}
|
|
6031
6650
|
`);
|
|
6032
6651
|
async function stop(reason = "stopped") {
|
|
6033
6652
|
if (stopped)
|
|
@@ -6036,7 +6655,7 @@ async function startCompanion(opts) {
|
|
|
6036
6655
|
if (idleTimer)
|
|
6037
6656
|
clearTimeout(idleTimer);
|
|
6038
6657
|
clearInterval(poll);
|
|
6039
|
-
if (
|
|
6658
|
+
if (existsSync27(stateDir)) {
|
|
6040
6659
|
writeFileSync(stoppedFile, `${JSON.stringify({ reason })}
|
|
6041
6660
|
`);
|
|
6042
6661
|
}
|
|
@@ -6079,7 +6698,7 @@ var init_server = __esm(() => {
|
|
|
6079
6698
|
// src/commands/companion.ts
|
|
6080
6699
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
6081
6700
|
import {
|
|
6082
|
-
existsSync as
|
|
6701
|
+
existsSync as existsSync28,
|
|
6083
6702
|
readdirSync as readdirSync2,
|
|
6084
6703
|
readFileSync as readFileSync4,
|
|
6085
6704
|
renameSync,
|
|
@@ -6088,7 +6707,7 @@ import {
|
|
|
6088
6707
|
writeFileSync as writeFileSync2
|
|
6089
6708
|
} from "fs";
|
|
6090
6709
|
import { spawnSync } from "child_process";
|
|
6091
|
-
import { join as
|
|
6710
|
+
import { join as join30, resolve as resolve13 } from "path";
|
|
6092
6711
|
function flag(args, name) {
|
|
6093
6712
|
const i = args.indexOf(name);
|
|
6094
6713
|
if (i === -1)
|
|
@@ -6119,21 +6738,21 @@ function pidAlive(pid) {
|
|
|
6119
6738
|
}
|
|
6120
6739
|
function readPid(dir) {
|
|
6121
6740
|
try {
|
|
6122
|
-
const n = Number.parseInt(readFileSync4(
|
|
6741
|
+
const n = Number.parseInt(readFileSync4(join30(dir, "state", "pid"), "utf-8").trim(), 10);
|
|
6123
6742
|
return Number.isFinite(n) && n > 0 ? n : null;
|
|
6124
6743
|
} catch {
|
|
6125
6744
|
return null;
|
|
6126
6745
|
}
|
|
6127
6746
|
}
|
|
6128
6747
|
function sessionOf(dir) {
|
|
6129
|
-
const stateDir =
|
|
6130
|
-
const info = readJson(
|
|
6748
|
+
const stateDir = join30(dir, "state");
|
|
6749
|
+
const info = readJson(join30(stateDir, "server-info")) ?? readJson(join30(stateDir, "server-info.prev"));
|
|
6131
6750
|
const pid = readPid(dir);
|
|
6132
|
-
const running = info !== null && !
|
|
6751
|
+
const running = info !== null && !existsSync28(join30(stateDir, "server-stopped")) && pid !== null && pidAlive(pid);
|
|
6133
6752
|
return { dir, info, running };
|
|
6134
6753
|
}
|
|
6135
6754
|
function latestSession(harenDir) {
|
|
6136
|
-
const base =
|
|
6755
|
+
const base = join30(harenDir, ".companion");
|
|
6137
6756
|
let best = null;
|
|
6138
6757
|
let names;
|
|
6139
6758
|
try {
|
|
@@ -6142,7 +6761,7 @@ function latestSession(harenDir) {
|
|
|
6142
6761
|
return null;
|
|
6143
6762
|
}
|
|
6144
6763
|
for (const name of names) {
|
|
6145
|
-
const dir =
|
|
6764
|
+
const dir = join30(base, name);
|
|
6146
6765
|
try {
|
|
6147
6766
|
const st = statSync2(dir);
|
|
6148
6767
|
if (!st.isDirectory())
|
|
@@ -6261,10 +6880,10 @@ async function serve(args) {
|
|
|
6261
6880
|
if (graceText !== undefined && !(Number(graceText) > 0))
|
|
6262
6881
|
badValue("--owner-grace-minutes must be a positive number");
|
|
6263
6882
|
const graceMs = Number(graceText ?? DEFAULT_OWNER_GRACE_MINUTES) * 60000;
|
|
6264
|
-
const stateDir =
|
|
6265
|
-
for (const d of [sessionDir,
|
|
6883
|
+
const stateDir = join30(sessionDir, "state");
|
|
6884
|
+
for (const d of [sessionDir, join30(sessionDir, "content"), stateDir])
|
|
6266
6885
|
makePrivateDir(d);
|
|
6267
|
-
const keyPath =
|
|
6886
|
+
const keyPath = join30(stateDir, "key");
|
|
6268
6887
|
const keyFile = flag(args, "--key-file");
|
|
6269
6888
|
let key = keyFile ? readKey(keyFile) : undefined;
|
|
6270
6889
|
if (keyFile && !key)
|
|
@@ -6289,10 +6908,10 @@ async function serve(args) {
|
|
|
6289
6908
|
throw e;
|
|
6290
6909
|
handle = await startCompanion({ ...opts, port: 0 });
|
|
6291
6910
|
}
|
|
6292
|
-
writePrivateFile(
|
|
6911
|
+
writePrivateFile(join30(stateDir, "pid"), `${process.pid}
|
|
6293
6912
|
`);
|
|
6294
6913
|
await new Promise((done) => {
|
|
6295
|
-
const stopFile =
|
|
6914
|
+
const stopFile = join30(handle.info.state_dir, "server-stopped");
|
|
6296
6915
|
let opened = !args.includes("--open");
|
|
6297
6916
|
let lastOwnerCheck = Date.now();
|
|
6298
6917
|
let ownerGoneAt = null;
|
|
@@ -6320,7 +6939,7 @@ async function serve(args) {
|
|
|
6320
6939
|
return;
|
|
6321
6940
|
}
|
|
6322
6941
|
}
|
|
6323
|
-
if (
|
|
6942
|
+
if (existsSync28(stopFile))
|
|
6324
6943
|
finish();
|
|
6325
6944
|
}, 100);
|
|
6326
6945
|
process.on("SIGTERM", onSignal);
|
|
@@ -6336,8 +6955,8 @@ function readKey(path) {
|
|
|
6336
6955
|
}
|
|
6337
6956
|
}
|
|
6338
6957
|
function restoreInfo(dir) {
|
|
6339
|
-
const infoPath =
|
|
6340
|
-
if (!
|
|
6958
|
+
const infoPath = join30(dir, "state", "server-info");
|
|
6959
|
+
if (!existsSync28(infoPath) && existsSync28(`${infoPath}.prev`))
|
|
6341
6960
|
renameSync(`${infoPath}.prev`, infoPath);
|
|
6342
6961
|
}
|
|
6343
6962
|
function keyOf(url) {
|
|
@@ -6388,7 +7007,7 @@ async function start(harenDir, args) {
|
|
|
6388
7007
|
}
|
|
6389
7008
|
const askedKey = flag(args, "--key");
|
|
6390
7009
|
const restart = current?.info && askedPort === undefined && askedKey === undefined ? current : null;
|
|
6391
|
-
const saved = restart ? readJson(
|
|
7010
|
+
const saved = restart ? readJson(join30(restart.dir, "state", "options.json")) : null;
|
|
6392
7011
|
const options = {
|
|
6393
7012
|
host: flag(args, "--host") ?? saved?.host ?? "127.0.0.1",
|
|
6394
7013
|
urlHost: flag(args, "--url-host") ?? saved?.urlHost,
|
|
@@ -6406,22 +7025,22 @@ async function start(harenDir, args) {
|
|
|
6406
7025
|
reused = true;
|
|
6407
7026
|
port = restart.info.port;
|
|
6408
7027
|
}
|
|
6409
|
-
const dir = restart ? restart.dir :
|
|
7028
|
+
const dir = restart ? restart.dir : join30(harenDir, ".companion", `${process.pid}-${Date.now()}`);
|
|
6410
7029
|
const fresh = !restart;
|
|
6411
|
-
const stateDir =
|
|
6412
|
-
for (const d of [dir,
|
|
7030
|
+
const stateDir = join30(dir, "state");
|
|
7031
|
+
for (const d of [dir, join30(dir, "content"), stateDir])
|
|
6413
7032
|
makePrivateDir(d);
|
|
6414
|
-
const keyPath =
|
|
7033
|
+
const keyPath = join30(stateDir, "key");
|
|
6415
7034
|
const oldKey = restart ? readKey(keyPath) ?? keyOf(restart.info.url) : undefined;
|
|
6416
7035
|
writePrivateFile(keyPath, `${askedKey ?? oldKey ?? randomBytes2(16).toString("hex")}
|
|
6417
7036
|
`);
|
|
6418
7037
|
if (restart) {
|
|
6419
|
-
const stoppedAt = mtimeOf(
|
|
6420
|
-
rmSync2(
|
|
6421
|
-
const infoPath =
|
|
6422
|
-
if (
|
|
7038
|
+
const stoppedAt = mtimeOf(join30(stateDir, "server-stopped"));
|
|
7039
|
+
rmSync2(join30(stateDir, "server-stopped"), { force: true });
|
|
7040
|
+
const infoPath = join30(stateDir, "server-info");
|
|
7041
|
+
if (existsSync28(infoPath))
|
|
6423
7042
|
renameSync(infoPath, `${infoPath}.prev`);
|
|
6424
|
-
archiveScreens(
|
|
7043
|
+
archiveScreens(join30(dir, "content"), stoppedAt);
|
|
6425
7044
|
}
|
|
6426
7045
|
const foreground = args.includes("--foreground");
|
|
6427
7046
|
const serveArgs = buildServeArgs(dir, {
|
|
@@ -6442,15 +7061,15 @@ async function start(harenDir, args) {
|
|
|
6442
7061
|
restoreInfo(dir);
|
|
6443
7062
|
};
|
|
6444
7063
|
const succeed = (info) => {
|
|
6445
|
-
rmSync2(
|
|
6446
|
-
writePrivateFile(
|
|
7064
|
+
rmSync2(join30(stateDir, "server-info.prev"), { force: true });
|
|
7065
|
+
writePrivateFile(join30(stateDir, "options.json"), `${JSON.stringify(options)}
|
|
6447
7066
|
`);
|
|
6448
7067
|
notePortChange(restart, info);
|
|
6449
7068
|
};
|
|
6450
7069
|
if (foreground) {
|
|
6451
|
-
const infoFile =
|
|
7070
|
+
const infoFile = join30(stateDir, "server-info");
|
|
6452
7071
|
const printer = setInterval(() => {
|
|
6453
|
-
if (
|
|
7072
|
+
if (existsSync28(infoFile)) {
|
|
6454
7073
|
const info = readJson(infoFile);
|
|
6455
7074
|
if (!info)
|
|
6456
7075
|
return;
|
|
@@ -6470,12 +7089,12 @@ async function start(harenDir, args) {
|
|
|
6470
7089
|
return;
|
|
6471
7090
|
}
|
|
6472
7091
|
const child = companionDeps.spawnServe(serveArgs);
|
|
6473
|
-
writePrivateFile(
|
|
7092
|
+
writePrivateFile(join30(stateDir, "pid"), `${child.pid}
|
|
6474
7093
|
`);
|
|
6475
7094
|
const deadline = Date.now() + companionDeps.startTimeoutMs;
|
|
6476
7095
|
while (Date.now() < deadline) {
|
|
6477
7096
|
const s = sessionOf(dir);
|
|
6478
|
-
if (s.info && s.running &&
|
|
7097
|
+
if (s.info && s.running && existsSync28(join30(stateDir, "server-info"))) {
|
|
6479
7098
|
succeed(s.info);
|
|
6480
7099
|
console.log(JSON.stringify(s.info));
|
|
6481
7100
|
return;
|
|
@@ -6501,7 +7120,7 @@ function archiveScreens(contentDir, stoppedAt) {
|
|
|
6501
7120
|
names = readdirSync2(contentDir).filter((n) => {
|
|
6502
7121
|
if (!n.endsWith(".html"))
|
|
6503
7122
|
return false;
|
|
6504
|
-
const st = statSync2(
|
|
7123
|
+
const st = statSync2(join30(contentDir, n));
|
|
6505
7124
|
return st.isFile() && st.mtimeMs < stoppedAt;
|
|
6506
7125
|
});
|
|
6507
7126
|
} catch {
|
|
@@ -6509,11 +7128,11 @@ function archiveScreens(contentDir, stoppedAt) {
|
|
|
6509
7128
|
}
|
|
6510
7129
|
if (names.length === 0)
|
|
6511
7130
|
return;
|
|
6512
|
-
const target =
|
|
6513
|
-
makePrivateDir(
|
|
7131
|
+
const target = join30(contentDir, "archive", String(Date.now()));
|
|
7132
|
+
makePrivateDir(join30(contentDir, "archive"));
|
|
6514
7133
|
makePrivateDir(target);
|
|
6515
7134
|
for (const n of names)
|
|
6516
|
-
renameSync(
|
|
7135
|
+
renameSync(join30(contentDir, n), join30(target, n));
|
|
6517
7136
|
}
|
|
6518
7137
|
function status(harenDir) {
|
|
6519
7138
|
const s = latestSession(harenDir);
|
|
@@ -6526,8 +7145,8 @@ screen_dir ${s.info.screen_dir}
|
|
|
6526
7145
|
state_dir ${s.info.state_dir}`);
|
|
6527
7146
|
}
|
|
6528
7147
|
function markStopped(dir) {
|
|
6529
|
-
const stopped =
|
|
6530
|
-
if (
|
|
7148
|
+
const stopped = join30(dir, "state", "server-stopped");
|
|
7149
|
+
if (existsSync28(join30(dir, "state")) && !existsSync28(stopped))
|
|
6531
7150
|
writeFileSync2(stopped, `${JSON.stringify({ reason: "stop" })}
|
|
6532
7151
|
`);
|
|
6533
7152
|
}
|
|
@@ -6549,7 +7168,7 @@ async function companion(args, cwd = process.cwd()) {
|
|
|
6549
7168
|
if (sub === "__serve")
|
|
6550
7169
|
return serve(rest);
|
|
6551
7170
|
if (!sub || !["start", "status", "stop"].includes(sub)) {
|
|
6552
|
-
console.log(
|
|
7171
|
+
console.log(USAGE3);
|
|
6553
7172
|
if (sub)
|
|
6554
7173
|
throw new ExitCode(1, `Unknown companion command: ${sub}`);
|
|
6555
7174
|
return;
|
|
@@ -6564,7 +7183,7 @@ async function companion(args, cwd = process.cwd()) {
|
|
|
6564
7183
|
return status(harenDir);
|
|
6565
7184
|
return stop(harenDir);
|
|
6566
7185
|
}
|
|
6567
|
-
var
|
|
7186
|
+
var USAGE3 = `Usage: haren companion <start|status|stop> [--haren-dir <path>]
|
|
6568
7187
|
start [--foreground] [--open] [--port <n>] [--host <h>] [--url-host <u>] [--idle-timeout-minutes <m>]
|
|
6569
7188
|
[--key <k>] [--no-owner-watch] [--owner-grace-minutes <m>]
|
|
6570
7189
|
status print the URL of the running server (exit 1 when stopped)
|
|
@@ -6599,6 +7218,792 @@ var init_companion = __esm(() => {
|
|
|
6599
7218
|
SHELLS = new Set(["sh", "bash", "zsh", "dash", "fish", "ksh", "tcsh", "csh", "env"]);
|
|
6600
7219
|
});
|
|
6601
7220
|
|
|
7221
|
+
// src/exec/brief.ts
|
|
7222
|
+
function line(body, name) {
|
|
7223
|
+
const l = body.split(/\r?\n/).find((x) => x.startsWith(`**${name}:**`));
|
|
7224
|
+
return l?.slice(name.length + 5).trim() || undefined;
|
|
7225
|
+
}
|
|
7226
|
+
function renderBrief(template, input) {
|
|
7227
|
+
const { task } = input;
|
|
7228
|
+
const missing = [];
|
|
7229
|
+
const description = line(task.body, "Description");
|
|
7230
|
+
if (!description)
|
|
7231
|
+
missing.push("**Description:**");
|
|
7232
|
+
if (task.files.length === 0)
|
|
7233
|
+
missing.push("**Files:**");
|
|
7234
|
+
if (!task.test)
|
|
7235
|
+
missing.push("**Test:**");
|
|
7236
|
+
if (task.stories.length === 0)
|
|
7237
|
+
missing.push("**Story:**");
|
|
7238
|
+
if (missing.length > 0) {
|
|
7239
|
+
throw new Error(`Task ${task.number} has no ${missing.join(", ")} line; add it to tasks.md`);
|
|
7240
|
+
}
|
|
7241
|
+
const feedback = input.feedback?.trim() ? `
|
|
7242
|
+
## Feedback from the last review
|
|
7243
|
+
|
|
7244
|
+
Fix these points first:
|
|
7245
|
+
|
|
7246
|
+
${input.feedback.trim()}
|
|
7247
|
+
` : "";
|
|
7248
|
+
const values = {
|
|
7249
|
+
number: String(task.number),
|
|
7250
|
+
title: task.title,
|
|
7251
|
+
description,
|
|
7252
|
+
stories: task.stories.join(", "),
|
|
7253
|
+
specPath: input.specPath,
|
|
7254
|
+
designPath: input.designPath,
|
|
7255
|
+
files: task.files.map((f) => `- \`${f}\``).join(`
|
|
7256
|
+
`),
|
|
7257
|
+
interfaces: line(task.body, "Interfaces") ?? "Follow the interfaces in the design and the spec.",
|
|
7258
|
+
test: task.test,
|
|
7259
|
+
harenDir: input.harenDir,
|
|
7260
|
+
feedback
|
|
7261
|
+
};
|
|
7262
|
+
return template.replace(/\{\{(\w+)\}\}/g, (m, k) => values[k] ?? m);
|
|
7263
|
+
}
|
|
7264
|
+
|
|
7265
|
+
// src/exec/config.ts
|
|
7266
|
+
function intInRange(value, def, min, max, field) {
|
|
7267
|
+
if (value === undefined || value === null)
|
|
7268
|
+
return def;
|
|
7269
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
|
|
7270
|
+
throw new Error(`manifest models.executor.${field} must be an integer in ${min}..${max}`);
|
|
7271
|
+
}
|
|
7272
|
+
return value;
|
|
7273
|
+
}
|
|
7274
|
+
function execRunners() {
|
|
7275
|
+
return listHosts().filter((h) => h.exec).map((h) => h.id);
|
|
7276
|
+
}
|
|
7277
|
+
function readExecutorConfig(m, lookup = getHost) {
|
|
7278
|
+
const models = m.models;
|
|
7279
|
+
const b = models && typeof models === "object" ? models.executor : undefined;
|
|
7280
|
+
if (!b || typeof b !== "object" || Array.isArray(b)) {
|
|
7281
|
+
throw new Error("manifest.yaml has no models.executor block; add models.executor with at least a runner");
|
|
7282
|
+
}
|
|
7283
|
+
const e = b;
|
|
7284
|
+
const runner = e.runner;
|
|
7285
|
+
const host = typeof runner === "string" ? lookup(runner) : undefined;
|
|
7286
|
+
if (!host?.exec) {
|
|
7287
|
+
throw new Error(`manifest models.executor.runner must be one of: ${execRunners().join(", ")}`);
|
|
7288
|
+
}
|
|
7289
|
+
if (e.model !== undefined && e.model !== null && typeof e.model !== "string") {
|
|
7290
|
+
throw new Error("manifest models.executor.model must be a string");
|
|
7291
|
+
}
|
|
7292
|
+
const env = {};
|
|
7293
|
+
if (e.env !== undefined && e.env !== null) {
|
|
7294
|
+
if (typeof e.env !== "object" || Array.isArray(e.env)) {
|
|
7295
|
+
throw new Error("manifest models.executor.env must be a map of string values");
|
|
7296
|
+
}
|
|
7297
|
+
for (const [k, v] of Object.entries(e.env)) {
|
|
7298
|
+
if (typeof v !== "string") {
|
|
7299
|
+
throw new Error(`manifest models.executor.env.${k} must be a string`);
|
|
7300
|
+
}
|
|
7301
|
+
if (SECRET_KEY.test(k) && !VAR_REF.test(v)) {
|
|
7302
|
+
throw new Error(`manifest models.executor.env.${k} looks like a secret; do not write it in manifest.yaml, use \${VAR} to read it from the environment`);
|
|
7303
|
+
}
|
|
7304
|
+
env[k] = v;
|
|
7305
|
+
}
|
|
7306
|
+
}
|
|
7307
|
+
return {
|
|
7308
|
+
runner: host.id,
|
|
7309
|
+
model: typeof e.model === "string" && e.model ? e.model : undefined,
|
|
7310
|
+
env,
|
|
7311
|
+
maxRetries: intInRange(e.maxRetries, 2, 0, 5, "maxRetries"),
|
|
7312
|
+
timeoutMinutes: intInRange(e.timeoutMinutes, 30, 1, 240, "timeoutMinutes")
|
|
7313
|
+
};
|
|
7314
|
+
}
|
|
7315
|
+
function resolveEnv(env, processEnv) {
|
|
7316
|
+
const missing = [];
|
|
7317
|
+
const out = {};
|
|
7318
|
+
for (const [k, v] of Object.entries(env)) {
|
|
7319
|
+
out[k] = v.replace(VAR_ANY, (_, name) => {
|
|
7320
|
+
const val = processEnv[name];
|
|
7321
|
+
if (val === undefined || val === "") {
|
|
7322
|
+
if (!missing.includes(name))
|
|
7323
|
+
missing.push(name);
|
|
7324
|
+
return "";
|
|
7325
|
+
}
|
|
7326
|
+
return val;
|
|
7327
|
+
});
|
|
7328
|
+
}
|
|
7329
|
+
if (missing.length > 0) {
|
|
7330
|
+
throw new Error(`missing environment variables for models.executor.env: ${missing.join(", ")}`);
|
|
7331
|
+
}
|
|
7332
|
+
return out;
|
|
7333
|
+
}
|
|
7334
|
+
function requireMultiModel(m) {
|
|
7335
|
+
const off = ["multi-host", "multi-model"].filter((f) => !isExperimental(m, f));
|
|
7336
|
+
if (off.length > 0) {
|
|
7337
|
+
throw new Error(`this command needs experimental features; run: ${off.map((f) => `haren experimental enable ${f}`).join(" && ")}`);
|
|
7338
|
+
}
|
|
7339
|
+
}
|
|
7340
|
+
function referencedVars(env) {
|
|
7341
|
+
const names = new Set;
|
|
7342
|
+
for (const v of Object.values(env))
|
|
7343
|
+
for (const m of v.matchAll(VAR_ANY))
|
|
7344
|
+
names.add(m[1] ?? "");
|
|
7345
|
+
return [...names].filter(Boolean);
|
|
7346
|
+
}
|
|
7347
|
+
var SECRET_KEY, VAR_REF, VAR_ANY;
|
|
7348
|
+
var init_config2 = __esm(() => {
|
|
7349
|
+
init_registry();
|
|
7350
|
+
init_experimental();
|
|
7351
|
+
SECRET_KEY = /KEY|TOKEN|SECRET/i;
|
|
7352
|
+
VAR_REF = /^\$\{[A-Za-z_][A-Za-z0-9_]*\}$/;
|
|
7353
|
+
VAR_ANY = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
7354
|
+
});
|
|
7355
|
+
|
|
7356
|
+
// src/exec/runs.ts
|
|
7357
|
+
import { mkdir as mkdir11, readdir as readdir8, writeFile as writeFile10 } from "fs/promises";
|
|
7358
|
+
import { join as join31 } from "path";
|
|
7359
|
+
function isPass(r) {
|
|
7360
|
+
return r.exitCode === 0 && !r.timedOut && r.tests.exitCode === 0 && r.violations.length === 0;
|
|
7361
|
+
}
|
|
7362
|
+
async function nextRun(dir) {
|
|
7363
|
+
let names;
|
|
7364
|
+
try {
|
|
7365
|
+
names = await readdir8(dir);
|
|
7366
|
+
} catch {
|
|
7367
|
+
return 1;
|
|
7368
|
+
}
|
|
7369
|
+
const used = names.map((n) => RUN_FILE_RE.exec(n)).filter((m) => m !== null);
|
|
7370
|
+
return 1 + Math.max(0, ...used.map((m) => Number(m[1])));
|
|
7371
|
+
}
|
|
7372
|
+
function checkRunAllowed(opts) {
|
|
7373
|
+
const { run, retry, maxRetries } = opts;
|
|
7374
|
+
if (!retry && run > 1) {
|
|
7375
|
+
throw new Error("Task already has a run. Use --retry --feedback <file> to run again, or --clean to start over.");
|
|
7376
|
+
}
|
|
7377
|
+
if (retry && run === 1)
|
|
7378
|
+
throw new Error("No earlier run to retry.");
|
|
7379
|
+
const limit = 1 + maxRetries;
|
|
7380
|
+
if (run > limit) {
|
|
7381
|
+
throw new Error(`Run ${run} is over the limit of ${limit} runs (maxRetries ${maxRetries})`);
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7384
|
+
async function writeResult(dir, result) {
|
|
7385
|
+
await mkdir11(dir, { recursive: true });
|
|
7386
|
+
const path = join31(dir, `result-${result.run}.json`);
|
|
7387
|
+
await writeFile10(path, `${JSON.stringify(result, null, 2)}
|
|
7388
|
+
`);
|
|
7389
|
+
return path;
|
|
7390
|
+
}
|
|
7391
|
+
var RUN_FILE_RE;
|
|
7392
|
+
var init_runs = __esm(() => {
|
|
7393
|
+
RUN_FILE_RE = /^(?:result|brief|run)-(\d+)\.(?:json|md|log)$/;
|
|
7394
|
+
});
|
|
7395
|
+
|
|
7396
|
+
// src/exec/spawn.ts
|
|
7397
|
+
import { spawn } from "child_process";
|
|
7398
|
+
import { createWriteStream, mkdirSync as mkdirSync2 } from "fs";
|
|
7399
|
+
import { dirname as dirname7 } from "path";
|
|
7400
|
+
function killGroup(pid, signal) {
|
|
7401
|
+
try {
|
|
7402
|
+
process.kill(-pid, signal);
|
|
7403
|
+
return true;
|
|
7404
|
+
} catch {
|
|
7405
|
+
return false;
|
|
7406
|
+
}
|
|
7407
|
+
}
|
|
7408
|
+
function runWithTimeout(argv, opts) {
|
|
7409
|
+
const killGraceMs = opts.killGraceMs ?? 5000;
|
|
7410
|
+
mkdirSync2(dirname7(opts.logPath), { recursive: true });
|
|
7411
|
+
const log = createWriteStream(opts.logPath, { flags: "a" });
|
|
7412
|
+
return new Promise((resolve) => {
|
|
7413
|
+
let timedOut = false;
|
|
7414
|
+
let error;
|
|
7415
|
+
let settled = false;
|
|
7416
|
+
let termTimer;
|
|
7417
|
+
let killTimer;
|
|
7418
|
+
let child;
|
|
7419
|
+
const finish = (exitCode) => {
|
|
7420
|
+
if (settled)
|
|
7421
|
+
return;
|
|
7422
|
+
settled = true;
|
|
7423
|
+
if (timedOut && child?.pid !== undefined)
|
|
7424
|
+
killGroup(child.pid, "SIGKILL");
|
|
7425
|
+
if (termTimer)
|
|
7426
|
+
clearTimeout(termTimer);
|
|
7427
|
+
if (killTimer)
|
|
7428
|
+
clearTimeout(killTimer);
|
|
7429
|
+
const result = { exitCode, timedOut };
|
|
7430
|
+
if (error !== undefined)
|
|
7431
|
+
result.error = error;
|
|
7432
|
+
log.end(() => resolve(result));
|
|
7433
|
+
};
|
|
7434
|
+
const [cmd, ...args] = argv;
|
|
7435
|
+
if (!cmd) {
|
|
7436
|
+
error = "empty argv";
|
|
7437
|
+
log.write(`[spawn error] ${error}
|
|
7438
|
+
`);
|
|
7439
|
+
finish(null);
|
|
7440
|
+
return;
|
|
7441
|
+
}
|
|
7442
|
+
const env = { ...process.env, ...opts.env };
|
|
7443
|
+
for (const name of opts.unsetEnv ?? [])
|
|
7444
|
+
delete env[name];
|
|
7445
|
+
child = spawn(cmd, args, {
|
|
7446
|
+
cwd: opts.cwd,
|
|
7447
|
+
env,
|
|
7448
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
7449
|
+
detached: true
|
|
7450
|
+
});
|
|
7451
|
+
child.stdout?.pipe(log, { end: false });
|
|
7452
|
+
child.stderr?.pipe(log, { end: false });
|
|
7453
|
+
child.on("error", (err) => {
|
|
7454
|
+
error = err.message;
|
|
7455
|
+
log.write(`[spawn error] ${err.message}
|
|
7456
|
+
`);
|
|
7457
|
+
if (child.pid === undefined)
|
|
7458
|
+
finish(null);
|
|
7459
|
+
});
|
|
7460
|
+
child.on("close", (code) => finish(code));
|
|
7461
|
+
termTimer = setTimeout(() => {
|
|
7462
|
+
const pid = child.pid;
|
|
7463
|
+
if (pid === undefined)
|
|
7464
|
+
return;
|
|
7465
|
+
timedOut = true;
|
|
7466
|
+
killGroup(pid, "SIGTERM");
|
|
7467
|
+
killTimer = setTimeout(() => {
|
|
7468
|
+
killGroup(pid, "SIGKILL");
|
|
7469
|
+
}, killGraceMs);
|
|
7470
|
+
}, opts.timeoutMs);
|
|
7471
|
+
});
|
|
7472
|
+
}
|
|
7473
|
+
var init_spawn = () => {};
|
|
7474
|
+
|
|
7475
|
+
// src/exec/task.ts
|
|
7476
|
+
function findTask(tasksText, n) {
|
|
7477
|
+
const lines = tasksText.split(/\r?\n/);
|
|
7478
|
+
const heading = new RegExp(`^## Task ${n}:\\s*(.*)$`);
|
|
7479
|
+
const start = lines.findIndex((l) => heading.test(l));
|
|
7480
|
+
if (start === -1)
|
|
7481
|
+
return;
|
|
7482
|
+
const title = (lines[start].match(heading)?.[1] ?? "").trim();
|
|
7483
|
+
const bodyLines = [];
|
|
7484
|
+
for (const line of lines.slice(start + 1)) {
|
|
7485
|
+
if (line.startsWith("## ") || /^---\s*$/.test(line))
|
|
7486
|
+
break;
|
|
7487
|
+
bodyLines.push(line);
|
|
7488
|
+
}
|
|
7489
|
+
const body = bodyLines.join(`
|
|
7490
|
+
`).trim();
|
|
7491
|
+
const field = (name) => bodyLines.find((l) => l.startsWith(`**${name}:**`))?.slice(name.length + 5).trim();
|
|
7492
|
+
const stories = field("Story")?.match(/STORY-\d+/g) ?? [];
|
|
7493
|
+
const repo = field("Repo") || undefined;
|
|
7494
|
+
const testRaw = field("Test");
|
|
7495
|
+
const test = testRaw ? testRaw.replace(/^`+|`+$/g, "").trim() : undefined;
|
|
7496
|
+
const files = [];
|
|
7497
|
+
const filesAt = bodyLines.findIndex((l) => l.startsWith("**Files:**"));
|
|
7498
|
+
if (filesAt !== -1) {
|
|
7499
|
+
for (const line of bodyLines.slice(filesAt + 1)) {
|
|
7500
|
+
if (!/^\s*-\s/.test(line))
|
|
7501
|
+
break;
|
|
7502
|
+
for (const m of line.matchAll(/`([^`]+)`/g)) {
|
|
7503
|
+
if (!files.includes(m[1]))
|
|
7504
|
+
files.push(m[1]);
|
|
7505
|
+
}
|
|
7506
|
+
}
|
|
7507
|
+
}
|
|
7508
|
+
return {
|
|
7509
|
+
number: n,
|
|
7510
|
+
title,
|
|
7511
|
+
stories,
|
|
7512
|
+
...repo ? { repo } : {},
|
|
7513
|
+
...test ? { test } : {},
|
|
7514
|
+
files,
|
|
7515
|
+
body
|
|
7516
|
+
};
|
|
7517
|
+
}
|
|
7518
|
+
function resolveTaskRepo(task, moduleRepos) {
|
|
7519
|
+
const repos = moduleRepos.length > 0 ? moduleRepos : ["default"];
|
|
7520
|
+
if (task.repo) {
|
|
7521
|
+
if (repos.includes(task.repo))
|
|
7522
|
+
return task.repo;
|
|
7523
|
+
throw new Error(`Task ${task.number}: repo "${task.repo}" is not a repo of this module. Valid keys: ${repos.join(", ")}`);
|
|
7524
|
+
}
|
|
7525
|
+
if (repos.length === 1)
|
|
7526
|
+
return repos[0];
|
|
7527
|
+
throw new Error(`Task ${task.number} needs a **Repo:** line because the module has several repos: ${repos.join(", ")}`);
|
|
7528
|
+
}
|
|
7529
|
+
|
|
7530
|
+
// src/exec/violations.ts
|
|
7531
|
+
function under(p, dir) {
|
|
7532
|
+
return p === dir || p.startsWith(`${dir}/`);
|
|
7533
|
+
}
|
|
7534
|
+
function findViolations(paths, opts) {
|
|
7535
|
+
const harenDir = opts.harenDirRel?.replace(/^(\.\/)+/, "").replace(/\/+$/, "") || null;
|
|
7536
|
+
const out = [];
|
|
7537
|
+
for (const path of paths) {
|
|
7538
|
+
const p = path.replace(/^(\.\/)+/, "");
|
|
7539
|
+
let reason;
|
|
7540
|
+
if (p.startsWith("/") || /^[A-Za-z]:[\\/]/.test(p))
|
|
7541
|
+
reason = "absolute path";
|
|
7542
|
+
else if (p.split(/[\\/]/).includes(".."))
|
|
7543
|
+
reason = "outside the repo";
|
|
7544
|
+
else if (harenDir && under(p, harenDir))
|
|
7545
|
+
reason = "haren folder";
|
|
7546
|
+
else if (under(p, ".haren-worktrees"))
|
|
7547
|
+
reason = "worktree folder";
|
|
7548
|
+
if (reason)
|
|
7549
|
+
out.push({ path, reason });
|
|
7550
|
+
}
|
|
7551
|
+
return out;
|
|
7552
|
+
}
|
|
7553
|
+
|
|
7554
|
+
// src/exec/worktree.ts
|
|
7555
|
+
import { existsSync as existsSync29, realpathSync as realpathSync3 } from "fs";
|
|
7556
|
+
import { appendFile as appendFile3, mkdir as mkdir12, readFile as readFile16 } from "fs/promises";
|
|
7557
|
+
import { join as join32, resolve as resolve14 } from "path";
|
|
7558
|
+
function worktreePath(repo, module, n) {
|
|
7559
|
+
return join32(repo, WORKTREE_DIR, `${module}-${n}`);
|
|
7560
|
+
}
|
|
7561
|
+
function execBranch(module, n) {
|
|
7562
|
+
return `exec/${module}/${n}`;
|
|
7563
|
+
}
|
|
7564
|
+
async function git(args, cwd) {
|
|
7565
|
+
const r = await runGit(args, cwd);
|
|
7566
|
+
if (!r.ok)
|
|
7567
|
+
throw new Error(r.stderr || `git ${args.join(" ")} failed`);
|
|
7568
|
+
return r.stdout;
|
|
7569
|
+
}
|
|
7570
|
+
async function baseBranch(repo) {
|
|
7571
|
+
const r = await runGit(["symbolic-ref", "--short", "-q", "HEAD"], repo);
|
|
7572
|
+
if (r.ok && r.stdout)
|
|
7573
|
+
return r.stdout;
|
|
7574
|
+
throw new Error(`${repo} is on a detached HEAD. Check out a branch first, then run again.`);
|
|
7575
|
+
}
|
|
7576
|
+
async function assertClean(repo, ignoreDir) {
|
|
7577
|
+
const spec = ignoreDir ? ["--", ".", `:(exclude)${ignoreDir}`] : [];
|
|
7578
|
+
const out = await git(["status", "--porcelain", "--untracked-files=no", ...spec], repo);
|
|
7579
|
+
if (!out)
|
|
7580
|
+
return;
|
|
7581
|
+
const files = out.split(`
|
|
7582
|
+
`).map((l) => l.trim().replace(/^\S+\s+/, "")).filter(Boolean);
|
|
7583
|
+
throw new Error(`${repo} has uncommitted changes to tracked files: ${files.join(", ")}. Commit or stash them first.`);
|
|
7584
|
+
}
|
|
7585
|
+
async function branchExists(repo, branch) {
|
|
7586
|
+
return (await runGit(["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], repo)).ok;
|
|
7587
|
+
}
|
|
7588
|
+
async function isRegisteredWorktree(repo, path) {
|
|
7589
|
+
const out = await git(["worktree", "list", "--porcelain"], repo);
|
|
7590
|
+
const want = resolve14(path);
|
|
7591
|
+
return out.split(`
|
|
7592
|
+
`).filter((l) => l.startsWith("worktree ")).some((l) => {
|
|
7593
|
+
const p = l.slice("worktree ".length);
|
|
7594
|
+
return resolve14(p) === want || resolveReal(p) === resolveReal(want);
|
|
7595
|
+
});
|
|
7596
|
+
}
|
|
7597
|
+
function resolveReal(p) {
|
|
7598
|
+
try {
|
|
7599
|
+
return realpathSync3(p);
|
|
7600
|
+
} catch {
|
|
7601
|
+
return resolve14(p);
|
|
7602
|
+
}
|
|
7603
|
+
}
|
|
7604
|
+
async function ensureExclude(repo) {
|
|
7605
|
+
const common = resolve14(repo, await git(["rev-parse", "--git-common-dir"], repo));
|
|
7606
|
+
const infoDir = join32(common, "info");
|
|
7607
|
+
const file = join32(infoDir, "exclude");
|
|
7608
|
+
const line = `${WORKTREE_DIR}/`;
|
|
7609
|
+
const current = existsSync29(file) ? await readFile16(file, "utf8") : "";
|
|
7610
|
+
if (current.split(`
|
|
7611
|
+
`).some((l) => l.trim() === line))
|
|
7612
|
+
return;
|
|
7613
|
+
await mkdir12(infoDir, { recursive: true });
|
|
7614
|
+
const prefix = current && !current.endsWith(`
|
|
7615
|
+
`) ? `
|
|
7616
|
+
` : "";
|
|
7617
|
+
await appendFile3(file, `${prefix}${line}
|
|
7618
|
+
`);
|
|
7619
|
+
}
|
|
7620
|
+
async function ensureWorktree(repo, module, n, base) {
|
|
7621
|
+
const path = worktreePath(repo, module, n);
|
|
7622
|
+
const branch = execBranch(module, n);
|
|
7623
|
+
await ensureExclude(repo);
|
|
7624
|
+
if (existsSync29(path) && await isRegisteredWorktree(repo, path)) {
|
|
7625
|
+
return { path, branch, created: false };
|
|
7626
|
+
}
|
|
7627
|
+
await git(["worktree", "prune"], repo);
|
|
7628
|
+
if (await branchExists(repo, branch)) {
|
|
7629
|
+
await git(["worktree", "add", path, branch], repo);
|
|
7630
|
+
} else {
|
|
7631
|
+
await git(["worktree", "add", "-b", branch, path, base], repo);
|
|
7632
|
+
}
|
|
7633
|
+
return { path, branch, created: true };
|
|
7634
|
+
}
|
|
7635
|
+
async function commitAll(wt, message) {
|
|
7636
|
+
await git(["add", "-A"], wt);
|
|
7637
|
+
const diff = await runGit(["diff", "--cached", "--quiet"], wt);
|
|
7638
|
+
if (diff.ok)
|
|
7639
|
+
return null;
|
|
7640
|
+
const email = await runGit(["config", "user.email"], wt);
|
|
7641
|
+
const identity = email.ok && email.stdout ? [] : ["-c", "user.name=haren-exec", "-c", "user.email=exec@haren.local"];
|
|
7642
|
+
await git([...identity, "commit", "--no-verify", "-m", message], wt);
|
|
7643
|
+
return git(["rev-parse", "HEAD"], wt);
|
|
7644
|
+
}
|
|
7645
|
+
async function diffInfo(repo, base, branch) {
|
|
7646
|
+
const range = `${base}...${branch}`;
|
|
7647
|
+
const names = await git(["diff", "--name-only", "--no-renames", range], repo);
|
|
7648
|
+
const stat = await git(["diff", "--shortstat", "--no-renames", range], repo);
|
|
7649
|
+
const num = (re) => Number(stat.match(re)?.[1] ?? 0);
|
|
7650
|
+
return {
|
|
7651
|
+
paths: names ? names.split(`
|
|
7652
|
+
`).filter(Boolean) : [],
|
|
7653
|
+
files: num(/(\d+) files? changed/),
|
|
7654
|
+
insertions: num(/(\d+) insertions?\(\+\)/),
|
|
7655
|
+
deletions: num(/(\d+) deletions?\(-\)/)
|
|
7656
|
+
};
|
|
7657
|
+
}
|
|
7658
|
+
async function removeWorktree(repo, module, n) {
|
|
7659
|
+
const path = worktreePath(repo, module, n);
|
|
7660
|
+
const branch = execBranch(module, n);
|
|
7661
|
+
if (existsSync29(path) || await isRegisteredWorktree(repo, path)) {
|
|
7662
|
+
await git(["worktree", "remove", "--force", path], repo);
|
|
7663
|
+
}
|
|
7664
|
+
await git(["worktree", "prune"], repo);
|
|
7665
|
+
if (await branchExists(repo, branch)) {
|
|
7666
|
+
await git(["branch", "-D", branch], repo);
|
|
7667
|
+
}
|
|
7668
|
+
}
|
|
7669
|
+
var WORKTREE_DIR = ".haren-worktrees";
|
|
7670
|
+
var init_worktree = __esm(() => {
|
|
7671
|
+
init_git();
|
|
7672
|
+
});
|
|
7673
|
+
|
|
7674
|
+
// src/exec/run.ts
|
|
7675
|
+
import { existsSync as existsSync30, realpathSync as realpathSync4 } from "fs";
|
|
7676
|
+
import { mkdir as mkdir13, readFile as readFile17, readdir as readdir9, rename as rename2, stat as stat3, writeFile as writeFile11 } from "fs/promises";
|
|
7677
|
+
import { isAbsolute as isAbsolute4, join as join33, relative as relative5, resolve as resolve15 } from "path";
|
|
7678
|
+
async function readManifest(harenDir) {
|
|
7679
|
+
const path = join33(harenDir, "manifest.yaml");
|
|
7680
|
+
if (!existsSync30(path))
|
|
7681
|
+
throw new Error(`No manifest.yaml in ${harenDir}`);
|
|
7682
|
+
return parseManifest(await readFile17(path, "utf-8"));
|
|
7683
|
+
}
|
|
7684
|
+
function checkModuleStatus(progress, module) {
|
|
7685
|
+
const status = progress.modules?.[module]?.status;
|
|
7686
|
+
if (!status)
|
|
7687
|
+
throw new Error(`Module "${module}" is not in progress.json`);
|
|
7688
|
+
if (!RUN_STATUSES.includes(status)) {
|
|
7689
|
+
throw new Error(`Module "${module}" has status "${status}"; haren exec needs ${RUN_STATUSES.join(" or ")}. Run the plan phase first.`);
|
|
7690
|
+
}
|
|
7691
|
+
}
|
|
7692
|
+
function activePlanDir(harenDir, manifest, progress, module) {
|
|
7693
|
+
const root = join33(harenDir, "artifacts", "04-plans", module);
|
|
7694
|
+
const it = manifest.iterations;
|
|
7695
|
+
const n = progress.currentIteration;
|
|
7696
|
+
if (it && it.enabled === true && (typeof n === "number" || typeof n === "string")) {
|
|
7697
|
+
const dir = join33(root, `iteration-${n}`);
|
|
7698
|
+
if (existsSync30(join33(dir, "tasks.md")))
|
|
7699
|
+
return dir;
|
|
7700
|
+
}
|
|
7701
|
+
return root;
|
|
7702
|
+
}
|
|
7703
|
+
async function frontMatterRepos(harenDir, module) {
|
|
7704
|
+
const path = join33(harenDir, "artifacts", "03-modules", module, "module.md");
|
|
7705
|
+
if (!existsSync30(path))
|
|
7706
|
+
return [];
|
|
7707
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(await readFile17(path, "utf-8"));
|
|
7708
|
+
if (!m)
|
|
7709
|
+
return [];
|
|
7710
|
+
const data = Bun.YAML.parse(m[1]);
|
|
7711
|
+
const repos = data?.repos;
|
|
7712
|
+
if (Array.isArray(repos))
|
|
7713
|
+
return repos.filter((r) => typeof r === "string");
|
|
7714
|
+
if (repos && typeof repos === "object")
|
|
7715
|
+
return Object.keys(repos);
|
|
7716
|
+
return [];
|
|
7717
|
+
}
|
|
7718
|
+
async function moduleRepoKeys(harenDir, progress, module) {
|
|
7719
|
+
const fromProgress = progress.modules?.[module]?.repos;
|
|
7720
|
+
if (fromProgress && fromProgress.length > 0)
|
|
7721
|
+
return fromProgress;
|
|
7722
|
+
return frontMatterRepos(harenDir, module);
|
|
7723
|
+
}
|
|
7724
|
+
async function repoPath(harenDir, manifest, key) {
|
|
7725
|
+
const repos = normalizeRepos(manifest.repos);
|
|
7726
|
+
const entry = repos[key];
|
|
7727
|
+
if (entry)
|
|
7728
|
+
return resolve15(harenDir, entry.path);
|
|
7729
|
+
if (key !== "default")
|
|
7730
|
+
throw new Error(`Repo "${key}" is not in manifest.yaml repos`);
|
|
7731
|
+
const r = await runGit(["rev-parse", "--show-toplevel"], harenDir);
|
|
7732
|
+
if (!r.ok || !r.stdout) {
|
|
7733
|
+
throw new Error(`${harenDir} is not inside a git repository; add the module's repo to repos`);
|
|
7734
|
+
}
|
|
7735
|
+
return r.stdout;
|
|
7736
|
+
}
|
|
7737
|
+
async function loadTask(t, manifest, progress) {
|
|
7738
|
+
const planDir = activePlanDir(t.harenDir, manifest, progress, t.module);
|
|
7739
|
+
const tasksPath = join33(planDir, "tasks.md");
|
|
7740
|
+
if (!existsSync30(tasksPath))
|
|
7741
|
+
throw new Error(`No tasks.md at ${tasksPath}`);
|
|
7742
|
+
const task = findTask(await readFile17(tasksPath, "utf-8"), t.task);
|
|
7743
|
+
if (!task)
|
|
7744
|
+
throw new Error(`Task ${t.task} not found in ${tasksPath}`);
|
|
7745
|
+
const key = resolveTaskRepo(task, await moduleRepoKeys(t.harenDir, progress, t.module));
|
|
7746
|
+
const repo = await repoPath(t.harenDir, manifest, key);
|
|
7747
|
+
return { planDir, task, repo };
|
|
7748
|
+
}
|
|
7749
|
+
async function loadContext2(t) {
|
|
7750
|
+
const manifest = await readManifest(t.harenDir);
|
|
7751
|
+
const progress = await readProgress(join33(t.harenDir, "progress.json"));
|
|
7752
|
+
return { manifest, progress, ...await loadTask(t, manifest, progress) };
|
|
7753
|
+
}
|
|
7754
|
+
function execDir(harenDir, module, n) {
|
|
7755
|
+
return join33(harenDir, "artifacts", "05-exec", module, String(n));
|
|
7756
|
+
}
|
|
7757
|
+
async function briefTemplate(harenDir) {
|
|
7758
|
+
const local = join33(harenDir, "templates", "task-brief.md");
|
|
7759
|
+
if (existsSync30(local))
|
|
7760
|
+
return readFile17(local, "utf-8");
|
|
7761
|
+
return readFile17(join33(resolveContentDir(), "templates", "task-brief.md"), "utf-8");
|
|
7762
|
+
}
|
|
7763
|
+
function real(p) {
|
|
7764
|
+
try {
|
|
7765
|
+
return realpathSync4(p);
|
|
7766
|
+
} catch {
|
|
7767
|
+
return resolve15(p);
|
|
7768
|
+
}
|
|
7769
|
+
}
|
|
7770
|
+
function harenDirInRepo(repo, harenDir) {
|
|
7771
|
+
const rel = relative5(real(repo), real(harenDir));
|
|
7772
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute4(rel))
|
|
7773
|
+
return null;
|
|
7774
|
+
return rel.split("\\").join("/");
|
|
7775
|
+
}
|
|
7776
|
+
async function writeBrief(opts, ctx, dir, run) {
|
|
7777
|
+
const feedback = opts.feedbackPath ? await readFile17(opts.feedbackPath, "utf-8") : undefined;
|
|
7778
|
+
const brief = renderBrief(await briefTemplate(opts.harenDir), {
|
|
7779
|
+
task: ctx.task,
|
|
7780
|
+
specPath: join33(opts.harenDir, "artifacts", "03-modules", opts.module, "spec.md"),
|
|
7781
|
+
designPath: join33(ctx.planDir, "design.md"),
|
|
7782
|
+
harenDir: harenDirInRepo(ctx.repo, opts.harenDir) ?? opts.harenDir,
|
|
7783
|
+
feedback
|
|
7784
|
+
});
|
|
7785
|
+
await mkdir13(dir, { recursive: true });
|
|
7786
|
+
await writeFile11(join33(dir, `brief-${run}.md`), brief);
|
|
7787
|
+
return brief;
|
|
7788
|
+
}
|
|
7789
|
+
async function emit2(opts, type, data) {
|
|
7790
|
+
const dir = join33(opts.harenDir, "events");
|
|
7791
|
+
await mkdir13(dir, { recursive: true });
|
|
7792
|
+
await appendEvent(join33(dir, "events.jsonl"), {
|
|
7793
|
+
type,
|
|
7794
|
+
module: opts.module,
|
|
7795
|
+
feature: String(opts.task),
|
|
7796
|
+
phase: "implement",
|
|
7797
|
+
timestamp: (opts.now ?? (() => new Date))().toISOString(),
|
|
7798
|
+
data
|
|
7799
|
+
});
|
|
7800
|
+
}
|
|
7801
|
+
function loadConfig(manifest, opts) {
|
|
7802
|
+
requireMultiModel(manifest);
|
|
7803
|
+
const lookup = opts.resolveHost ?? getHost;
|
|
7804
|
+
const config = readExecutorConfig(manifest, lookup);
|
|
7805
|
+
const host = lookup(config.runner);
|
|
7806
|
+
if (!host?.exec)
|
|
7807
|
+
throw new Error(`Runner ${config.runner} has no exec()`);
|
|
7808
|
+
return { config, host };
|
|
7809
|
+
}
|
|
7810
|
+
async function prepareRun(opts, ctx, config) {
|
|
7811
|
+
if (!ctx.task.test)
|
|
7812
|
+
throw new Error(`Task ${ctx.task.number} has no **Test:** line`);
|
|
7813
|
+
const base = await baseBranch(ctx.repo);
|
|
7814
|
+
const dir = execDir(opts.harenDir, opts.module, opts.task);
|
|
7815
|
+
const run = await nextRun(dir);
|
|
7816
|
+
checkRunAllowed({ run, retry: opts.retry === true, maxRetries: config.maxRetries });
|
|
7817
|
+
const exists = existsSync30(worktreePath(ctx.repo, opts.module, opts.task));
|
|
7818
|
+
if (run === 1 || !exists)
|
|
7819
|
+
await assertClean(ctx.repo, harenDirInRepo(ctx.repo, opts.harenDir));
|
|
7820
|
+
const wt = await ensureWorktree(ctx.repo, opts.module, opts.task, base);
|
|
7821
|
+
return { base, dir, run, wt };
|
|
7822
|
+
}
|
|
7823
|
+
async function runExec(opts) {
|
|
7824
|
+
const manifest = await readManifest(opts.harenDir);
|
|
7825
|
+
const { config, host } = loadConfig(manifest, opts);
|
|
7826
|
+
const progress = await readProgress(join33(opts.harenDir, "progress.json"));
|
|
7827
|
+
checkModuleStatus(progress, opts.module);
|
|
7828
|
+
const ctx = { manifest, ...await loadTask(opts, manifest, progress) };
|
|
7829
|
+
const env = resolveEnv(config.env, opts.processEnv ?? process.env);
|
|
7830
|
+
const { base, dir, run, wt } = await prepareRun(opts, ctx, config);
|
|
7831
|
+
const brief = await writeBrief(opts, ctx, dir, run);
|
|
7832
|
+
const argv = host.exec({ prompt: brief, cwd: wt.path, model: config.model, env });
|
|
7833
|
+
await emit2(opts, "exec.started", { run, runner: config.runner, model: config.model ?? null });
|
|
7834
|
+
const logPath = join33(dir, `run-${run}.log`);
|
|
7835
|
+
const timeoutMs = opts.timeoutMs ?? config.timeoutMinutes * 60000;
|
|
7836
|
+
const spawnOpts = { cwd: wt.path, env, timeoutMs, logPath, killGraceMs: opts.killGraceMs };
|
|
7837
|
+
const before = await harenSnapshot(opts.harenDir);
|
|
7838
|
+
const exec = await runWithTimeout(argv, spawnOpts);
|
|
7839
|
+
const harenChanged = diffSnapshot(before, await harenSnapshot(opts.harenDir));
|
|
7840
|
+
const commit = await commitAll(wt.path, `exec(${opts.module}): task ${opts.task} run ${run}`);
|
|
7841
|
+
const test = ctx.task.test ?? "";
|
|
7842
|
+
const unsetEnv = referencedVars(config.env);
|
|
7843
|
+
const tests = await runWithTimeout(["sh", "-c", test], { ...spawnOpts, env: {}, unsetEnv });
|
|
7844
|
+
const diff = await diffInfo(ctx.repo, base, wt.branch);
|
|
7845
|
+
const violations = [
|
|
7846
|
+
...findViolations(diff.paths, { harenDirRel: harenDirInRepo(ctx.repo, opts.harenDir) }),
|
|
7847
|
+
...harenChanged.map((path) => ({ path, reason: "haren folder changed during the run" }))
|
|
7848
|
+
];
|
|
7849
|
+
const partial = {
|
|
7850
|
+
run,
|
|
7851
|
+
runner: config.runner,
|
|
7852
|
+
...config.model ? { model: config.model } : {},
|
|
7853
|
+
exitCode: exec.exitCode,
|
|
7854
|
+
timedOut: exec.timedOut,
|
|
7855
|
+
tests: { command: test, exitCode: tests.exitCode },
|
|
7856
|
+
violations,
|
|
7857
|
+
diffStat: { files: diff.files, insertions: diff.insertions, deletions: diff.deletions },
|
|
7858
|
+
baseBranch: base,
|
|
7859
|
+
branch: wt.branch,
|
|
7860
|
+
worktree: relative5(ctx.repo, wt.path),
|
|
7861
|
+
commit,
|
|
7862
|
+
log: relative5(opts.harenDir, logPath),
|
|
7863
|
+
retriesLeft: Math.max(0, 1 + config.maxRetries - run)
|
|
7864
|
+
};
|
|
7865
|
+
const result = { ...partial, pass: isPass(partial) };
|
|
7866
|
+
const resultPath = await writeResult(dir, result);
|
|
7867
|
+
await emit2(opts, "exec.finished", {
|
|
7868
|
+
run,
|
|
7869
|
+
runner: config.runner,
|
|
7870
|
+
pass: result.pass,
|
|
7871
|
+
timedOut: result.timedOut
|
|
7872
|
+
});
|
|
7873
|
+
return { result, resultPath };
|
|
7874
|
+
}
|
|
7875
|
+
async function cleanExec(opts) {
|
|
7876
|
+
const { repo } = await loadContext2(opts);
|
|
7877
|
+
await removeWorktree(repo, opts.module, opts.task);
|
|
7878
|
+
const dir = execDir(opts.harenDir, opts.module, opts.task);
|
|
7879
|
+
const runFiles = existsSync30(dir) ? (await readdir9(dir)).filter((n) => /^(?:result|brief|run|feedback)-\d+\./.test(n)) : [];
|
|
7880
|
+
if (runFiles.length === 0)
|
|
7881
|
+
return;
|
|
7882
|
+
const stamp = (opts.now ?? (() => new Date))().toISOString().replace(/[:.]/g, "-");
|
|
7883
|
+
const archive = join33(dir, `cleaned-${stamp}`);
|
|
7884
|
+
await mkdir13(archive, { recursive: true });
|
|
7885
|
+
for (const n of runFiles)
|
|
7886
|
+
await rename2(join33(dir, n), join33(archive, n));
|
|
7887
|
+
}
|
|
7888
|
+
async function harenSnapshot(harenDir) {
|
|
7889
|
+
const out = new Map;
|
|
7890
|
+
const skip = [join33("artifacts", "05-exec"), "events"];
|
|
7891
|
+
const walk = async (rel) => {
|
|
7892
|
+
if (skip.includes(rel))
|
|
7893
|
+
return;
|
|
7894
|
+
let names;
|
|
7895
|
+
try {
|
|
7896
|
+
names = await readdir9(join33(harenDir, rel));
|
|
7897
|
+
} catch {
|
|
7898
|
+
return;
|
|
7899
|
+
}
|
|
7900
|
+
for (const n of names) {
|
|
7901
|
+
const r = rel ? join33(rel, n) : n;
|
|
7902
|
+
const st = await stat3(join33(harenDir, r)).catch(() => null);
|
|
7903
|
+
if (!st)
|
|
7904
|
+
continue;
|
|
7905
|
+
if (st.isDirectory())
|
|
7906
|
+
await walk(r);
|
|
7907
|
+
else
|
|
7908
|
+
out.set(r, `${st.size}:${st.mtimeMs}`);
|
|
7909
|
+
}
|
|
7910
|
+
};
|
|
7911
|
+
await walk("");
|
|
7912
|
+
return out;
|
|
7913
|
+
}
|
|
7914
|
+
function diffSnapshot(a, b) {
|
|
7915
|
+
const changed = new Set;
|
|
7916
|
+
for (const [k, v] of a)
|
|
7917
|
+
if (b.get(k) !== v)
|
|
7918
|
+
changed.add(k);
|
|
7919
|
+
for (const k of b.keys())
|
|
7920
|
+
if (!a.has(k))
|
|
7921
|
+
changed.add(k);
|
|
7922
|
+
return [...changed].sort();
|
|
7923
|
+
}
|
|
7924
|
+
var RUN_STATUSES;
|
|
7925
|
+
var init_run = __esm(() => {
|
|
7926
|
+
init_registry();
|
|
7927
|
+
init_content_dir();
|
|
7928
|
+
init_events();
|
|
7929
|
+
init_git();
|
|
7930
|
+
init_manifest();
|
|
7931
|
+
init_progress();
|
|
7932
|
+
init_config2();
|
|
7933
|
+
init_runs();
|
|
7934
|
+
init_spawn();
|
|
7935
|
+
init_worktree();
|
|
7936
|
+
RUN_STATUSES = ["planned", "implementing"];
|
|
7937
|
+
});
|
|
7938
|
+
|
|
7939
|
+
// src/commands/exec.ts
|
|
7940
|
+
import { relative as relative6, resolve as resolve16 } from "path";
|
|
7941
|
+
function value(args, flag) {
|
|
7942
|
+
const i = args.indexOf(flag);
|
|
7943
|
+
if (i === -1)
|
|
7944
|
+
return;
|
|
7945
|
+
const v = args[i + 1];
|
|
7946
|
+
if (v === undefined || v === "" || v.startsWith("--"))
|
|
7947
|
+
throw new Error(`${flag} needs a value`);
|
|
7948
|
+
return v;
|
|
7949
|
+
}
|
|
7950
|
+
function parseExecArgs(args) {
|
|
7951
|
+
const module = value(args, "--module");
|
|
7952
|
+
if (!module)
|
|
7953
|
+
throw new Error(`--module is required
|
|
7954
|
+
${EXEC_USAGE}`);
|
|
7955
|
+
const rawTask = value(args, "--task");
|
|
7956
|
+
if (!rawTask)
|
|
7957
|
+
throw new Error(`--task is required
|
|
7958
|
+
${EXEC_USAGE}`);
|
|
7959
|
+
if (!/^[1-9]\d*$/.test(rawTask))
|
|
7960
|
+
throw new Error("--task must be a positive integer");
|
|
7961
|
+
const retry = args.includes("--retry");
|
|
7962
|
+
const feedback = value(args, "--feedback");
|
|
7963
|
+
if (retry !== (feedback !== undefined)) {
|
|
7964
|
+
throw new Error("--retry and --feedback <file> go together");
|
|
7965
|
+
}
|
|
7966
|
+
return {
|
|
7967
|
+
module,
|
|
7968
|
+
task: Number(rawTask),
|
|
7969
|
+
retry,
|
|
7970
|
+
clean: args.includes("--clean"),
|
|
7971
|
+
feedback,
|
|
7972
|
+
harenDir: harenDirFlag(args)
|
|
7973
|
+
};
|
|
7974
|
+
}
|
|
7975
|
+
async function exec(args, deps = {}) {
|
|
7976
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
7977
|
+
const a = parseExecArgs(args);
|
|
7978
|
+
const location = await resolveHarenDir(cwd, { harenDir: a.harenDir, env: process.env });
|
|
7979
|
+
if (!location)
|
|
7980
|
+
throw new Error("No haren folder found. Run `haren init` first.");
|
|
7981
|
+
const target = {
|
|
7982
|
+
harenDir: location.harenDir,
|
|
7983
|
+
module: a.module,
|
|
7984
|
+
task: a.task,
|
|
7985
|
+
resolveHost: deps.resolveHost
|
|
7986
|
+
};
|
|
7987
|
+
if (a.clean) {
|
|
7988
|
+
await cleanExec(target);
|
|
7989
|
+
console.log(` Removed the worktree and branch of ${a.module} task ${a.task}; run files moved to cleaned-<time>/`);
|
|
7990
|
+
return;
|
|
7991
|
+
}
|
|
7992
|
+
const { result, resultPath } = await runExec({
|
|
7993
|
+
...target,
|
|
7994
|
+
retry: a.retry,
|
|
7995
|
+
feedbackPath: a.feedback ? resolve16(cwd, a.feedback) : undefined,
|
|
7996
|
+
processEnv: deps.processEnv
|
|
7997
|
+
});
|
|
7998
|
+
console.log(` ${relative6(cwd, resultPath)}`);
|
|
7999
|
+
console.log(` ${result.pass ? "PASS" : "FAIL"}`);
|
|
8000
|
+
}
|
|
8001
|
+
var EXEC_USAGE = "Usage: haren exec --module <m> --task <n> [--retry --feedback <file>] [--clean] [--haren-dir <dir>]";
|
|
8002
|
+
var init_exec = __esm(() => {
|
|
8003
|
+
init_run();
|
|
8004
|
+
init_resolve();
|
|
8005
|
+
});
|
|
8006
|
+
|
|
6602
8007
|
// src/index.ts
|
|
6603
8008
|
init_exit_code();
|
|
6604
8009
|
function parseArgs(args) {
|
|
@@ -6621,6 +8026,8 @@ function parseArgs(args) {
|
|
|
6621
8026
|
case "track":
|
|
6622
8027
|
case "migrate":
|
|
6623
8028
|
case "companion":
|
|
8029
|
+
case "experimental":
|
|
8030
|
+
case "exec":
|
|
6624
8031
|
return { command, args: rest };
|
|
6625
8032
|
default:
|
|
6626
8033
|
return { command: "unknown", args };
|
|
@@ -6665,6 +8072,16 @@ async function main() {
|
|
|
6665
8072
|
await companion(parsed.args);
|
|
6666
8073
|
break;
|
|
6667
8074
|
}
|
|
8075
|
+
case "experimental": {
|
|
8076
|
+
await Promise.resolve().then(() => init_experimental2());
|
|
8077
|
+
await experimental(parsed.args);
|
|
8078
|
+
break;
|
|
8079
|
+
}
|
|
8080
|
+
case "exec": {
|
|
8081
|
+
await Promise.resolve().then(() => init_exec());
|
|
8082
|
+
await exec(parsed.args);
|
|
8083
|
+
break;
|
|
8084
|
+
}
|
|
6668
8085
|
case "help":
|
|
6669
8086
|
console.log("Usage:");
|
|
6670
8087
|
console.log(" haren init Set up haren (detects monorepo or multi-repo workspace)");
|
|
@@ -6672,6 +8089,7 @@ async function main() {
|
|
|
6672
8089
|
console.log(" --mode <undecided|explore|blueprint|inherit|migration>");
|
|
6673
8090
|
console.log(" --yes|-y --dry-run --force");
|
|
6674
8091
|
console.log(" --plugin <name|source> (repeatable)");
|
|
8092
|
+
console.log(" --experimental <a,b> (experimental features to enable)");
|
|
6675
8093
|
console.log(" haren upgrade Upgrade framework files and migrate manifest/progress (--dry-run, --yes)");
|
|
6676
8094
|
console.log(" haren agent Manage local agent (start, stop, status)");
|
|
6677
8095
|
console.log(" haren plugin Manage plugins (add, remove, list, run, doctor)");
|
|
@@ -6688,11 +8106,15 @@ async function main() {
|
|
|
6688
8106
|
console.log(" haren migrate Run the migration adapter:");
|
|
6689
8107
|
console.log(" inventory [--module <m>] | extract <unit> | gate <unit> [--approve]");
|
|
6690
8108
|
console.log(" gate exit codes: 0 approved, 1 failed, 3 PASS but not approved yet");
|
|
8109
|
+
console.log(" haren experimental enable <name> | disable <name> | list (multi-host, multi-model)");
|
|
8110
|
+
console.log(" haren exec Run one planned task with the executor model (multi-model)");
|
|
8111
|
+
console.log(" --module <m> --task <n> [--retry --feedback <file>] [--clean] [--haren-dir <dir>]");
|
|
8112
|
+
console.log(" exit 0 when a result file is written (PASS or FAIL)");
|
|
6691
8113
|
console.log(" haren companion Visual companion server: start [--foreground] [--open] | status | stop");
|
|
6692
8114
|
break;
|
|
6693
8115
|
case "unknown":
|
|
6694
8116
|
console.error(`Unknown command: ${parsed.args[0]}`);
|
|
6695
|
-
console.log("Usage: haren init | upgrade | agent | plugin | track | migrate | companion (haren --help)");
|
|
8117
|
+
console.log("Usage: haren init | upgrade | agent | plugin | track | migrate | companion | experimental | exec (haren --help)");
|
|
6696
8118
|
process.exit(1);
|
|
6697
8119
|
}
|
|
6698
8120
|
}
|