@odarino/haren 1.3.3 → 1.4.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/dist/index.js CHANGED
@@ -53,17 +53,15 @@ This workspace uses the Haren agentic SDLC framework.
53
53
  3. Read \`{{harenDir}}/manifest.yaml\` and \`{{harenDir}}/progress.json\` before taking any action
54
54
 
55
55
  All project documentation, specs, plans, and artifacts are managed inside \`{{harenDir}}/\`.
56
- Write outside \`{{harenDir}}/\` only in the module's repos (see "Repos and Git" in \`{{harenDir}}/skill.md\`), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`, or when the user explicitly asks.
56
+ Write outside \`{{harenDir}}/\` only in the module's repos (see "Repos and Git" in \`{{harenDir}}/skill.md\`), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`. For a change the user explicitly asks for, use the gate override (see below).
57
57
 
58
58
  ## Brainstorming Gate
59
59
 
60
60
  Before writing ANY code outside \`{{harenDir}}/\`:
61
- 1. Read \`{{harenDir}}/progress.json\`
62
- 2. At least one module MUST have status \`planned\`, \`implementing\`, \`evaluating\`, or \`completed\`
63
- 3. If NO module is at \`planned\` or later \u2192 STOP. Do not write code.
64
- - \`discovered\`, \`specified\`, \`decomposed\` do NOT allow implementation
65
- - Discovery docs and specs are NOT sufficient \u2014 planning must be completed first
66
- 4. If blocked, tell the user to run the plan phase before implementation
61
+ 1. Read \`{{harenDir}}/progress.json\` and \`{{harenDir}}/manifest.yaml\`
62
+ 2. Write code only inside the repos of a module with status \`planned\`, \`implementing\`, \`evaluating\`, \`completed\`, or \`released\` (the module's \`repos\` keys in progress.json)
63
+ 3. \`discovered\` and \`decomposed\` do NOT allow code. If no module is at \`planned\` or later, STOP and tell the user to run the plan phase.
64
+ 4. Exception: the user explicitly asks for a change (for example a hotfix). Run \`haren track override on --reason "<what the user asked>"\`, make the change, then run \`haren track override off\`.
67
65
 
68
66
  Design specs are written to Haren artifact folders, NOT to docs/superpowers/specs/.
69
67
  `, cursorRuleTemplate = `---
@@ -100,20 +98,19 @@ This applies to ALL phases \u2014 planning, designing, implementing, everything.
100
98
 
101
99
  ---
102
100
 
103
- ## RULE #2: Code Gate \u2014 No code outside \`{{harenDir}}/\` without \`planned\` status
101
+ ## RULE #2: Code Gate \u2014 code only in the repos of a \`planned\` module
104
102
 
105
- **BEFORE writing ANY file outside \`{{harenDir}}/\`, check \`{{harenDir}}/progress.json\`:**
103
+ **BEFORE writing ANY file outside \`{{harenDir}}/\`, read \`{{harenDir}}/progress.json\` and \`{{harenDir}}/manifest.yaml\`:**
106
104
 
107
- 1. The relevant module MUST have status \`planned\`, \`implementing\`, \`evaluating\`, or \`completed\`
108
- 2. **If NO \u2192 STOP. DO NOT WRITE CODE.**
109
- 3. \`discovered\`, \`specified\`, \`decomposed\` do NOT allow code changes
110
- 4. Discovery docs and specs are NOT sufficient
105
+ 1. Write code only inside the repos of a module with status \`planned\`, \`implementing\`, \`evaluating\`, \`completed\`, or \`released\`
106
+ 2. \`discovered\` and \`decomposed\` do NOT allow code. Discovery docs and specs are NOT sufficient.
107
+ 3. **If no such module owns the file \u2192 STOP. DO NOT WRITE CODE.**
111
108
 
112
109
  **When blocked, respond ONLY with:**
113
110
  - No modules: "No modules found. Run the discover phase first."
114
111
  - No planned modules: "No module has reached 'planned' status yet. Run the plan phase first."
115
112
 
116
- No exceptions. No rationalizing. STOP means STOP.
113
+ **Only exception:** the user explicitly asks for the change (for example a hotfix). Run \`haren track override on --reason "<what the user asked>"\`, make the change, then run \`haren track override off\`.
117
114
 
118
115
  ---
119
116
 
@@ -124,34 +121,39 @@ No exceptions. No rationalizing. STOP means STOP.
124
121
  3. Read \`{{harenDir}}/manifest.yaml\` and \`{{harenDir}}/progress.json\` before taking any action
125
122
 
126
123
  All project documentation, specs, plans, and artifacts are managed inside \`{{harenDir}}/\`.
127
- Write outside \`{{harenDir}}/\` only in the module's repos (see "Repos and Git" in \`{{harenDir}}/skill.md\`), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`, or when the user explicitly asks.
124
+ Write outside \`{{harenDir}}/\` only in the module's repos (see "Repos and Git" in \`{{harenDir}}/skill.md\`), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`. For a change the user explicitly asks for, use the gate override (see below).
128
125
 
129
126
  ## Phase Progression (MANDATORY)
130
127
 
131
128
  Modules MUST progress through phases in order. You CANNOT skip phases.
132
129
 
133
130
  \`\`\`
134
- discovered \u2192 specified \u2192 planned \u2192 implementing \u2192 evaluating \u2192 completed
131
+ discovered \u2192 decomposed \u2192 planned \u2192 implementing \u2192 evaluating \u2192 completed \u2192 released
135
132
  \`\`\`
136
133
 
137
134
  **Before taking ANY action on a module, read \`{{harenDir}}/progress.json\` and check the module's current status. Then follow the dispatch rules in \`{{harenDir}}/skill.md\`.**
138
135
 
139
136
  Key dispatch rules:
140
- - Module at \`specified\` \u2192 user says "plan" \u2192 you MUST run the \`plan/\` skill first (read \`{{harenDir}}/skills/plan/SKILL.md\`)
137
+ - Module at \`decomposed\` \u2192 user says "plan" \u2192 you MUST run the \`plan/\` skill first (read \`{{harenDir}}/skills/plan/SKILL.md\`)
141
138
  - Module at \`discovered\` or no module \u2192 user says "plan" or "build" \u2192 you MUST run \`discover/\` skill first (brainstorming)
142
139
  - Module at \`planned\` \u2192 user says "implement" or "build" \u2192 proceed with implementation
143
- - **You CANNOT jump from \`specified\` directly to \`implementing\`**
140
+ - **You CANNOT jump from \`decomposed\` directly to \`implementing\`**
144
141
  - **You CANNOT skip brainstorming/discovery for new features**
145
142
 
146
143
  ## Rules
147
144
 
148
145
  - Always read progress.json before taking action
149
- - Write outside \`{{harenDir}}/\` only in the module's repos (see "Repos and Git" in \`{{harenDir}}/skill.md\`), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`, or when the user explicitly asks.
146
+ - Write outside \`{{harenDir}}/\` only in the module's repos (see "Repos and Git" in \`{{harenDir}}/skill.md\`), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`. For a change the user explicitly asks for, use the gate override (see below).
150
147
  - Update progress.json after every phase transition
151
148
  - Append to FEEDBACK.md when you encounter framework friction
152
149
  `, GATE_SCRIPT_PATH = "hooks/brainstorm-gate.ts", brainstormGateScript = `/**
153
150
  * Brainstorm Gate Hook
154
- * Blocks Edit/Write tool use if no module has reached 'planned' status.
151
+ * Blocks Edit/Write tool use outside the haren folder unless a module that
152
+ * owns the target repo has reached 'planned' status (or later).
153
+ *
154
+ * Override (for a fix the user asked for): HAREN_GATE=off, or
155
+ * progress.json "gateOverride": { "reason": "...", "until": "<ISO>" }
156
+ * (set it with: haren track override on --reason "...").
155
157
  *
156
158
  * Works with both Claude Code and Cursor:
157
159
  * - Exit 0 = allow
@@ -165,6 +167,11 @@ import { basename, dirname, join, resolve, sep } from "path";
165
167
  // The hook lives in <harenDir>/hooks/, so the haren folder is one level up.
166
168
  // This works for any folder name. Use the real path so symlinks compare equal.
167
169
  const harenDir = realpathSync(resolve(import.meta.dir, ".."));
170
+ const workspaceDir = dirname(harenDir);
171
+
172
+ const IMPLEMENTABLE = ["planned", "implementing", "evaluating", "completed", "released"];
173
+ const OVERRIDE_HINT =
174
+ "If the user explicitly asked for this change, run \`haren track override on --reason \\"...\\"\` (or set HAREN_GATE=off) and try again.";
168
175
 
169
176
  // Editors send logical paths that can go through symlinks. Resolve the nearest
170
177
  // existing ancestor to its real path, then add back the missing segments.
@@ -182,7 +189,11 @@ function realTarget(abs: string): string {
182
189
  }
183
190
  }
184
191
 
185
- function allow() {
192
+ function inside(path: string, root: string): boolean {
193
+ return path === root || path.startsWith(root.endsWith(sep) ? root : root + sep);
194
+ }
195
+
196
+ function allow(): never {
186
197
  console.log(JSON.stringify({
187
198
  allow: true, // Claude Code
188
199
  permission: "allow", // Cursor
@@ -190,7 +201,7 @@ function allow() {
190
201
  process.exit(0);
191
202
  }
192
203
 
193
- function deny(message: string) {
204
+ function deny(message: string): never {
194
205
  console.log(JSON.stringify({
195
206
  error: message, // Claude Code
196
207
  permission: "deny", // Cursor
@@ -200,54 +211,121 @@ function deny(message: string) {
200
211
  process.exit(2);
201
212
  }
202
213
 
203
- async function main() {
204
- // Allow writes inside the haren folder \u2014 planning/discovery phases write artifacts there
205
- try {
206
- const stdin = await Bun.stdin.text();
207
- if (stdin) {
208
- const input = JSON.parse(stdin);
209
- const filePath = input?.tool_input?.file_path
210
- || input?.tool_input?.path
211
- || input?.file_path
212
- || input?.path
213
- || "";
214
- if (filePath) {
215
- const real = realTarget(resolve(process.cwd(), filePath));
216
- if (real === harenDir || real.startsWith(harenDir + sep)) {
217
- allow();
218
- }
214
+ interface Repo { path: string; role?: string }
215
+
216
+ // Same rules as the CLI: repos is a map key -> {path} | key -> string, or an array.
217
+ function normalizeRepos(repos: unknown): Record<string, Repo> {
218
+ const out: Record<string, Repo> = {};
219
+ if (Array.isArray(repos)) {
220
+ for (const item of repos) {
221
+ const path = typeof item === "string" ? item : item?.path;
222
+ if (typeof path === "string" && path) out[basename(path)] = { path, role: item?.role };
223
+ }
224
+ } else if (repos && typeof repos === "object") {
225
+ for (const [key, value] of Object.entries(repos as Record<string, any>)) {
226
+ if (typeof value === "string") out[key] = { path: value };
227
+ else if (value && typeof value === "object" && typeof value.path === "string") {
228
+ out[key] = { path: value.path, role: value.role };
219
229
  }
220
230
  }
231
+ }
232
+ return out;
233
+ }
234
+
235
+ async function readRepos(): Promise<Record<string, Repo>> {
236
+ try {
237
+ const file = Bun.file(join(harenDir, "manifest.yaml"));
238
+ if (!(await file.exists())) return {};
239
+ const data: any = Bun.YAML.parse(await file.text());
240
+ return normalizeRepos(data?.repos);
221
241
  } catch {
222
- // stdin parse failed \u2014 continue with gate check
242
+ return {}; // fail-open: malformed manifest means no repo info
223
243
  }
244
+ }
224
245
 
225
- const progressPath = resolve(harenDir, "progress.json");
226
- const progressFile = Bun.file(progressPath);
246
+ function realRoot(path: string): string {
247
+ return realTarget(resolve(harenDir, path));
248
+ }
227
249
 
228
- if (!(await progressFile.exists())) {
229
- allow();
250
+ function overrideActive(progress: any): boolean {
251
+ if (process.env.HAREN_GATE === "off") return true;
252
+ const o = progress?.gateOverride;
253
+ if (!o || typeof o !== "object" || typeof o.reason !== "string") return false;
254
+ if (o.until === undefined || o.until === null || o.until === "") return true;
255
+ const until = Date.parse(o.until);
256
+ return !Number.isNaN(until) && until > Date.now();
257
+ }
258
+
259
+ async function readTarget(): Promise<string> {
260
+ try {
261
+ const stdin = await Bun.stdin.text();
262
+ if (!stdin) return "";
263
+ const input = JSON.parse(stdin);
264
+ const filePath = input?.tool_input?.file_path
265
+ || input?.tool_input?.path
266
+ || input?.file_path
267
+ || input?.path
268
+ || "";
269
+ return filePath ? realTarget(resolve(process.cwd(), filePath)) : "";
270
+ } catch {
271
+ return ""; // stdin parse failed \u2014 continue with gate check
230
272
  }
273
+ }
274
+
275
+ async function main() {
276
+ const target = await readTarget();
277
+
278
+ // Allow writes inside the haren folder \u2014 planning/discovery phases write artifacts there
279
+ if (target && inside(target, harenDir)) allow();
280
+
281
+ if (process.env.HAREN_GATE === "off") allow();
282
+
283
+ const progressFile = Bun.file(resolve(harenDir, "progress.json"));
284
+ if (!(await progressFile.exists())) allow();
231
285
 
232
286
  const progress = await progressFile.json();
233
- const modules = progress.modules || {};
234
- const hasModules = Object.keys(modules).length > 0;
287
+ if (overrideActive(progress)) allow();
235
288
 
236
- const implementablePhases = ["planned", "implementing", "evaluating", "completed"];
237
- const hasImplementableModule = Object.values(modules).some(
238
- (m: any) => implementablePhases.includes(m.status || m.currentPhase)
289
+ const modules: Record<string, any> = progress.modules || {};
290
+ const hasModules = Object.keys(modules).length > 0;
291
+ const active = Object.entries(modules).filter(([, m]) =>
292
+ IMPLEMENTABLE.includes(m?.status || m?.currentPhase),
239
293
  );
240
294
 
241
- if (hasImplementableModule) {
242
- allow();
295
+ if (active.length === 0) {
296
+ const message = !hasModules
297
+ ? "No modules or discovery found. Run the discover phase first. Say \\"let's build X\\" or \\"start discovery\\" to begin. " + OVERRIDE_HINT
298
+ : "No module has reached 'planned' status yet. Run the plan phase on a module before writing code. " + OVERRIDE_HINT;
299
+ deny(message);
300
+ }
301
+
302
+ // No file path, or a file outside the workspace (temp files): legacy rule.
303
+ if (!target || !inside(target, workspaceDir)) allow();
304
+
305
+ const repos = await readRepos();
306
+ const roots: string[] = [];
307
+ const described: string[] = [];
308
+ for (const [name, m] of active) {
309
+ const keys: unknown = m?.repos;
310
+ if (!Array.isArray(keys) || keys.length === 0) allow(); // no repo info: allow all
311
+ const paths: string[] = [];
312
+ for (const key of keys) {
313
+ if (key === "default" || typeof key !== "string" || !repos[key]) allow();
314
+ paths.push(repos[key].path);
315
+ roots.push(realRoot(repos[key].path));
316
+ }
317
+ described.push(name + " (" + paths.join(", ") + ")");
318
+ }
319
+ for (const repo of Object.values(repos)) {
320
+ if (repo.role === "e2e") roots.push(realRoot(repo.path));
243
321
  }
244
322
 
245
- // No module is ready for implementation \u2014 block unconditionally
246
- const message = !hasModules
247
- ? "No modules or discovery found. Run the discover phase first. Say \\"let's build X\\" or \\"start discovery\\" to begin."
248
- : "No module has reached 'planned' status yet. Run the plan phase on a module before writing code.";
323
+ if (roots.some((root) => inside(target, root))) allow();
249
324
 
250
- deny(message);
325
+ deny(
326
+ "This file is outside the repos of the modules at 'planned' or later. Active modules: " +
327
+ described.join("; ") + ". " + OVERRIDE_HINT,
328
+ );
251
329
  }
252
330
 
253
331
  // Top-level await: on Windows, Bun exits early (code 0, no output) if main() is
@@ -1180,6 +1258,9 @@ var init_plan = __esm(() => {
1180
1258
 
1181
1259
  // src/workspace/progress.ts
1182
1260
  import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
1261
+ function phaseForStatus(status) {
1262
+ return STATUS_TO_PHASE[status];
1263
+ }
1183
1264
  async function readProgress(path) {
1184
1265
  const raw = await readFile5(path, "utf-8");
1185
1266
  const progress = JSON.parse(raw);
@@ -1198,6 +1279,28 @@ function isObject(value) {
1198
1279
  async function writeProgress(path, progress) {
1199
1280
  await writeFile4(path, JSON.stringify(progress, null, 2));
1200
1281
  }
1282
+ function updateModuleStatus(progress, moduleName, newStatus) {
1283
+ const mod = progress.modules[moduleName];
1284
+ if (!mod) {
1285
+ throw new Error(`Module '${moduleName}' not found in progress`);
1286
+ }
1287
+ const allowed = VALID_MODULE_TRANSITIONS[mod.status];
1288
+ if (!allowed.includes(newStatus)) {
1289
+ throw new Error(`Invalid module transition: ${mod.status} \u2192 ${newStatus}. Allowed: ${allowed.join(", ")}`);
1290
+ }
1291
+ return {
1292
+ ...progress,
1293
+ modules: {
1294
+ ...progress.modules,
1295
+ [moduleName]: {
1296
+ ...mod,
1297
+ status: newStatus,
1298
+ currentPhase: STATUS_TO_PHASE[newStatus],
1299
+ lastUpdated: new Date().toISOString()
1300
+ }
1301
+ }
1302
+ };
1303
+ }
1201
1304
  function updateFeatureStatus(progress, moduleName, featureName, newStatus) {
1202
1305
  const mod = progress.modules[moduleName];
1203
1306
  if (!mod) {
@@ -1245,8 +1348,46 @@ function migrateProgress(raw, repoKeyFor) {
1245
1348
  }
1246
1349
  return { progress: { ...data, version: PROGRESS_VERSION, modules }, changed: true };
1247
1350
  }
1248
- var VALID_FEATURE_TRANSITIONS, PROGRESS_VERSION = 2;
1351
+ var MODULE_STATUSES, FEATURE_STATUSES, VALID_MODULE_TRANSITIONS, STATUS_TO_PHASE, VALID_FEATURE_TRANSITIONS, PROGRESS_VERSION = 2;
1249
1352
  var init_progress = __esm(() => {
1353
+ MODULE_STATUSES = [
1354
+ "discovered",
1355
+ "decomposed",
1356
+ "planned",
1357
+ "implementing",
1358
+ "evaluating",
1359
+ "completed",
1360
+ "released",
1361
+ "blocked"
1362
+ ];
1363
+ FEATURE_STATUSES = [
1364
+ "pending",
1365
+ "in-progress",
1366
+ "evaluating",
1367
+ "passing",
1368
+ "fixing",
1369
+ "blocked"
1370
+ ];
1371
+ VALID_MODULE_TRANSITIONS = {
1372
+ discovered: ["decomposed"],
1373
+ decomposed: ["planned"],
1374
+ planned: ["implementing"],
1375
+ implementing: ["evaluating", "blocked"],
1376
+ evaluating: ["implementing", "completed", "blocked"],
1377
+ completed: ["released"],
1378
+ released: [],
1379
+ blocked: ["implementing", "planned"]
1380
+ };
1381
+ STATUS_TO_PHASE = {
1382
+ discovered: "discover",
1383
+ decomposed: "decompose",
1384
+ planned: "plan",
1385
+ implementing: "implement",
1386
+ evaluating: "evaluate",
1387
+ completed: "evaluate",
1388
+ released: "release",
1389
+ blocked: "blocked"
1390
+ };
1250
1391
  VALID_FEATURE_TRANSITIONS = {
1251
1392
  pending: ["in-progress"],
1252
1393
  "in-progress": ["evaluating"],
@@ -1841,7 +1982,9 @@ You are operating within the Haren agentic SDLC framework.
1841
1982
  | Evaluate a module | evaluate/ | Reviewer |
1842
1983
  | Check project status | read-context/ | \u2014 |
1843
1984
  | Search artifacts | search-artifact/ | \u2014 |
1844
- | Draw a UI wireframe | generate-mockup/ | \u2014 |
1985
+ | Release completed modules | release/ | Architect |
1986
+ | Draw a UI wireframe or compare screen options | generate-mockup/ | \u2014 |
1987
+ | Update status, artifacts, events | update-tracking/ (\`haren track\`) | \u2014 |
1845
1988
  | Onboard to the project / check the workspace | onboard/ (\`/haren-onboard\`) | \u2014 |
1846
1989
 
1847
1990
  ## How to dispatch
@@ -1854,8 +1997,19 @@ You are operating within the Haren agentic SDLC framework.
1854
1997
  - User says "status" or "where are we?" \u2192 read-context/ skill
1855
1998
  - User says "start" or "init" \u2192 discover/ skill
1856
1999
  - User asks about an artifact \u2192 search-artifact/ skill
2000
+ - User says "release", "deploy" or "ship {module}" \u2192 release/ skill (plans the order; never deploys by itself)
1857
2001
  - User runs \`/haren-onboard\`, is new to the project, or asks "is my workspace set up?" \u2192 onboard/ skill
1858
2002
 
2003
+ ## Phases
2004
+
2005
+ \`ideate\` \u2192 \`discover\` \u2192 \`research\` \u2192 \`decompose\` \u2192 \`plan\` \u2192 \`implement\` \u2192 \`evaluate\` \u2192 \`release\`. A module that is stuck is in \`blocked\`. These are also the allowed \`phase\` values in \`events/events.jsonl\`.
2006
+
2007
+ Module status: \`discovered \u2192 decomposed \u2192 planned \u2192 implementing \u2192 evaluating \u2192 completed \u2192 released\`.
2008
+
2009
+ ## Tracking
2010
+
2011
+ Change \`progress.json\`, \`events/events.jsonl\` and \`artifacts/_registry/artifact-index.md\` only with \`haren track\` (see update-tracking/ skill). Never edit them by hand, with sed or with jq.
2012
+
1859
2013
  ## Artifact Ownership
1860
2014
 
1861
2015
  | Artifact | Owner | Location |
@@ -1901,11 +2055,21 @@ When a skill says "read the master plan" or needs full module context, it means
1901
2055
  - **lastCommit:** \`modules.<module>.lastCommit\` maps a repo key to the last commit SHA that haren recorded, for example \`{ "backend": "abc1234" }\`. It is never a plain string. The key \`default\` comes from an old progress file. In the monorepo layout, it means the repo that holds this haren folder. In the workspace layout, it means the module's first repo.
1902
2056
  - Never push. Never create pull requests unless the user asks. Never clone repos \u2014 tell the user to run \`haren init\`.
1903
2057
 
2058
+ ### Dependent modules
2059
+
2060
+ The decompose skill records module dependencies in \`progress.json\` \`dependencies\` (for example \`"web": ["api"]\`). If module B depends on module A:
2061
+
2062
+ - **A is merged:** create \`feat/<B>\` from the default branch as usual.
2063
+ - **A is not merged yet:** create \`feat/<B>\` from \`feat/<A>\`. Record the base in the session log, for example "baseBranch: feat/<A>". Merge A into the default branch first. Then rebase or merge B onto the default branch, and only then merge B.
2064
+ - **Monorepo layout:** both modules share one repository. When possible, merge A before you start B, so that B starts from the default branch.
2065
+ - Never merge B before A.
2066
+
1904
2067
  ## Rules
1905
2068
 
1906
2069
  - Always read progress.json before taking action
1907
- - Write outside this haren folder only in the module's repos (see "Repos and Git"), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`, or when the user explicitly asks
1908
- - Update progress.json after every phase transition
2070
+ - Write outside this haren folder only in the module's repos (see "Repos and Git"), only from the \`planned\` status on (implement phase) or when qa-engineer writes tests in \`$E2E\`, or when the user explicitly asks. For a user request outside the module flow (for example a hotfix), first run \`haren track override on --reason "<what the user asked>"\`, and run \`haren track override off\` when the change is done
2071
+ - The code gate allows code only inside the repos of modules at \`planned\` or later. Do not edit other repos without the override
2072
+ - Update progress.json after every phase transition with \`haren track status\`
1909
2073
  - Append to FEEDBACK.md when you encounter framework friction
1910
2074
  - Validate artifacts before phase transitions (validate-artifact/ skill)
1911
2075
  `);
@@ -2702,12 +2866,28 @@ function buildCLIArgs(cli, prompt) {
2702
2866
 
2703
2867
  // src/workspace/events.ts
2704
2868
  import { appendFile, readFile as readFile10 } from "fs/promises";
2869
+ function isEventPhase(value) {
2870
+ return typeof value === "string" && EVENT_PHASES.includes(value);
2871
+ }
2705
2872
  async function appendEvent(path, event) {
2706
2873
  const line = JSON.stringify(event) + `
2707
2874
  `;
2708
2875
  await appendFile(path, line);
2709
2876
  }
2710
- var init_events = () => {};
2877
+ var EVENT_PHASES;
2878
+ var init_events = __esm(() => {
2879
+ EVENT_PHASES = [
2880
+ "ideate",
2881
+ "discover",
2882
+ "research",
2883
+ "decompose",
2884
+ "plan",
2885
+ "implement",
2886
+ "evaluate",
2887
+ "release",
2888
+ "blocked"
2889
+ ];
2890
+ });
2711
2891
 
2712
2892
  // src/agent/request-handler.ts
2713
2893
  function handleServerMessage(msg, config, send) {
@@ -3570,6 +3750,316 @@ var init_plugin = __esm(() => {
3570
3750
  SUBS = ["add", "remove", "list", "run", "doctor"];
3571
3751
  });
3572
3752
 
3753
+ // src/commands/track.ts
3754
+ import { existsSync as existsSync15 } from "fs";
3755
+ import { mkdir as mkdir9, readFile as readFile13, writeFile as writeFile7 } from "fs/promises";
3756
+ import { dirname as dirname5, join as join18 } from "path";
3757
+ function parseTrackArgs(args) {
3758
+ const positional = [];
3759
+ const flags = {};
3760
+ for (let i = 0;i < args.length; i++) {
3761
+ const arg = args[i];
3762
+ if (arg.startsWith("--")) {
3763
+ const eq = arg.indexOf("=");
3764
+ const name = eq === -1 ? arg : arg.slice(0, eq);
3765
+ if (!VALUE_FLAGS.includes(name))
3766
+ throw new Error(`Unknown option: ${name}`);
3767
+ const value = eq === -1 ? args[++i] : arg.slice(eq + 1);
3768
+ if (value === undefined)
3769
+ throw new Error(`${name} needs a value`);
3770
+ flags[name.slice(2)] = value;
3771
+ } else {
3772
+ positional.push(arg);
3773
+ }
3774
+ }
3775
+ return { positional, flags };
3776
+ }
3777
+ function pathsFor(harenDir) {
3778
+ return {
3779
+ harenDir,
3780
+ progress: join18(harenDir, "progress.json"),
3781
+ events: join18(harenDir, "events", "events.jsonl"),
3782
+ registry: join18(harenDir, "artifacts", "_registry", "artifact-index.md")
3783
+ };
3784
+ }
3785
+ async function emit(paths, event) {
3786
+ await mkdir9(dirname5(paths.events), { recursive: true });
3787
+ await appendEvent(paths.events, { ...event, timestamp: new Date().toISOString() });
3788
+ }
3789
+ function need(value, what) {
3790
+ if (value === undefined || value === "")
3791
+ throw new Error(`Missing ${what}.
3792
+ ${TRACK_USAGE}`);
3793
+ return value;
3794
+ }
3795
+ function requireModule(progress, name) {
3796
+ if (!progress.modules[name]) {
3797
+ const known = Object.keys(progress.modules);
3798
+ throw new Error(`Unknown module '${name}'. Known modules: ${known.length ? known.join(", ") : "(none)"}`);
3799
+ }
3800
+ }
3801
+ async function loadProgress(paths) {
3802
+ if (!existsSync15(paths.progress))
3803
+ throw new Error(`No progress.json in ${paths.harenDir}`);
3804
+ return readProgress(paths.progress);
3805
+ }
3806
+ async function track(args, cwd = process.cwd()) {
3807
+ const { positional, flags } = parseTrackArgs(args);
3808
+ const [sub, ...rest] = positional;
3809
+ if (!sub) {
3810
+ console.log(TRACK_USAGE);
3811
+ return;
3812
+ }
3813
+ const location = await resolveHarenDir(cwd, {
3814
+ harenDir: harenDirFlag(args),
3815
+ env: process.env
3816
+ });
3817
+ if (!location)
3818
+ throw new Error("No haren folder found. Run `haren init` first.");
3819
+ const paths = pathsFor(location.harenDir);
3820
+ switch (sub) {
3821
+ case "status":
3822
+ return trackStatus(paths, rest);
3823
+ case "feature":
3824
+ return trackFeature(paths, rest);
3825
+ case "commit":
3826
+ return trackCommit(paths, rest);
3827
+ case "artifact":
3828
+ return trackArtifact(paths, rest, flags);
3829
+ case "event":
3830
+ return trackEvent(paths, rest, flags);
3831
+ case "override":
3832
+ return trackOverride(paths, rest, flags);
3833
+ default:
3834
+ throw new Error(`Unknown track command: ${sub}
3835
+ ${TRACK_USAGE}`);
3836
+ }
3837
+ }
3838
+ async function trackStatus(paths, rest) {
3839
+ const module = need(rest[0], "<module>");
3840
+ const to = need(rest[1], "<status>");
3841
+ if (!MODULE_STATUSES.includes(to)) {
3842
+ throw new Error(`Invalid module status '${to}'. Allowed: ${MODULE_STATUSES.join(", ")}`);
3843
+ }
3844
+ const progress = await loadProgress(paths);
3845
+ let next;
3846
+ let from = null;
3847
+ if (!progress.modules[module]) {
3848
+ if (to !== "discovered" && to !== "decomposed") {
3849
+ throw new Error(`Unknown module '${module}'. A new module can start only at 'discovered' or 'decomposed'.`);
3850
+ }
3851
+ next = {
3852
+ ...progress,
3853
+ modules: {
3854
+ ...progress.modules,
3855
+ [module]: {
3856
+ status: to,
3857
+ currentPhase: phaseForStatus(to),
3858
+ features: {},
3859
+ lastCommit: {},
3860
+ lastUpdated: new Date().toISOString()
3861
+ }
3862
+ }
3863
+ };
3864
+ } else {
3865
+ from = progress.modules[module].status;
3866
+ next = updateModuleStatus(progress, module, to);
3867
+ }
3868
+ await writeProgress(paths.progress, next);
3869
+ await emit(paths, { type: "module-status", module, from, to, phase: phaseForStatus(to) });
3870
+ console.log(` ${module}: ${from ?? "(new)"} \u2192 ${to}`);
3871
+ }
3872
+ async function trackFeature(paths, rest) {
3873
+ const module = need(rest[0], "<module>");
3874
+ const feature = need(rest[1], "<feature>");
3875
+ const to = rest[2];
3876
+ const progress = await loadProgress(paths);
3877
+ requireModule(progress, module);
3878
+ const mod = progress.modules[module];
3879
+ let next;
3880
+ let from = null;
3881
+ if (to === undefined) {
3882
+ if (mod.features[feature] !== undefined) {
3883
+ throw new Error(`Feature '${feature}' already exists in module '${module}'`);
3884
+ }
3885
+ next = {
3886
+ ...progress,
3887
+ modules: {
3888
+ ...progress.modules,
3889
+ [module]: {
3890
+ ...mod,
3891
+ features: { ...mod.features, [feature]: "pending" },
3892
+ lastUpdated: new Date().toISOString()
3893
+ }
3894
+ }
3895
+ };
3896
+ } else {
3897
+ if (!FEATURE_STATUSES.includes(to)) {
3898
+ throw new Error(`Invalid feature status '${to}'. Allowed: ${FEATURE_STATUSES.join(", ")}`);
3899
+ }
3900
+ from = mod.features[feature] ?? null;
3901
+ next = updateFeatureStatus(progress, module, feature, to);
3902
+ }
3903
+ const status = to ?? "pending";
3904
+ await writeProgress(paths.progress, next);
3905
+ await emit(paths, { type: "feature-status", module, feature, from, to: status });
3906
+ console.log(` ${module}/${feature}: ${from ?? "(new)"} \u2192 ${status}`);
3907
+ }
3908
+ async function trackCommit(paths, rest) {
3909
+ const module = need(rest[0], "<module>");
3910
+ const repo = need(rest[1], "<repoKey>");
3911
+ const sha = need(rest[2], "<sha>");
3912
+ const progress = await loadProgress(paths);
3913
+ requireModule(progress, module);
3914
+ const mod = progress.modules[module];
3915
+ const repos = Array.isArray(mod.repos) ? mod.repos : [];
3916
+ const next = {
3917
+ ...progress,
3918
+ modules: {
3919
+ ...progress.modules,
3920
+ [module]: {
3921
+ ...mod,
3922
+ lastCommit: { ...mod.lastCommit, [repo]: sha },
3923
+ branch: mod.branch || `feat/${module}`,
3924
+ repos: repos.includes(repo) ? repos : [...repos, repo],
3925
+ lastUpdated: new Date().toISOString()
3926
+ }
3927
+ }
3928
+ };
3929
+ await writeProgress(paths.progress, next);
3930
+ await emit(paths, { type: "commit", module, repo, sha });
3931
+ console.log(` ${module}: lastCommit.${repo} = ${sha}`);
3932
+ }
3933
+ function upsertArtifactRow(text, cells) {
3934
+ const row = `| ${cells.map((c) => c.replaceAll("|", "\\|")).join(" | ")} |`;
3935
+ const lines = text.split(`
3936
+ `);
3937
+ let lastRow = -1;
3938
+ for (let i = 0;i < lines.length; i++) {
3939
+ const line = lines[i].trim();
3940
+ if (!line.startsWith("|"))
3941
+ continue;
3942
+ lastRow = i;
3943
+ const id = line.slice(1).split("|")[0].trim();
3944
+ if (id === cells[0]) {
3945
+ lines[i] = row;
3946
+ return lines.join(`
3947
+ `);
3948
+ }
3949
+ }
3950
+ if (lastRow === -1) {
3951
+ const base = text.trimEnd();
3952
+ return `${base ? base + `
3953
+
3954
+ ` : ""}${REGISTRY_HEADER}
3955
+ ${row}
3956
+ `;
3957
+ }
3958
+ lines.splice(lastRow + 1, 0, row);
3959
+ return lines.join(`
3960
+ `);
3961
+ }
3962
+ async function trackArtifact(paths, rest, flags) {
3963
+ const id = need(rest[0], "<id>");
3964
+ const artifactType = need(flags.type, "--type <type>");
3965
+ const path = need(flags.path, "--path <path>");
3966
+ const module = flags.module ?? "-";
3967
+ const status = flags.status ?? "draft";
3968
+ if (flags.module) {
3969
+ const progress = await loadProgress(paths);
3970
+ requireModule(progress, flags.module);
3971
+ }
3972
+ const existing = existsSync15(paths.registry) ? await readFile13(paths.registry, "utf-8") : "";
3973
+ await mkdir9(dirname5(paths.registry), { recursive: true });
3974
+ await writeFile7(paths.registry, upsertArtifactRow(existing, [id, artifactType, module, status, path]));
3975
+ await emit(paths, {
3976
+ type: "artifact",
3977
+ id,
3978
+ artifactType,
3979
+ path,
3980
+ status,
3981
+ ...flags.module ? { module: flags.module } : {}
3982
+ });
3983
+ console.log(` artifact ${id} \u2192 ${path}`);
3984
+ }
3985
+ async function trackEvent(paths, rest, flags) {
3986
+ const type = need(rest[0], "<type>");
3987
+ if (flags.phase !== undefined && !isEventPhase(flags.phase)) {
3988
+ throw new Error(`Invalid phase '${flags.phase}'. Allowed: ${EVENT_PHASES.join(", ")}`);
3989
+ }
3990
+ let data = {};
3991
+ if (flags.data !== undefined) {
3992
+ let parsed;
3993
+ try {
3994
+ parsed = JSON.parse(flags.data);
3995
+ } catch {
3996
+ throw new Error("--data must be a JSON object");
3997
+ }
3998
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
3999
+ throw new Error("--data must be a JSON object");
4000
+ }
4001
+ data = parsed;
4002
+ }
4003
+ const event = { ...data, type };
4004
+ if (flags.module)
4005
+ event.module = flags.module;
4006
+ if (flags.phase)
4007
+ event.phase = flags.phase;
4008
+ if (flags.feature)
4009
+ event.feature = flags.feature;
4010
+ await emit(paths, event);
4011
+ console.log(` event ${type}`);
4012
+ }
4013
+ async function trackOverride(paths, rest, flags) {
4014
+ const action = need(rest[0], "on|off");
4015
+ const progress = await loadProgress(paths);
4016
+ if (action === "on") {
4017
+ const reason = need(flags.reason, '--reason "<text>"');
4018
+ const hours = flags.hours === undefined ? 2 : Number(flags.hours);
4019
+ if (!Number.isFinite(hours) || hours <= 0) {
4020
+ throw new Error("--hours must be a positive number");
4021
+ }
4022
+ const until = new Date(Date.now() + hours * 3600000).toISOString();
4023
+ await writeProgress(paths.progress, { ...progress, gateOverride: { reason, until } });
4024
+ await emit(paths, { type: "gate-override", action: "on", reason, until });
4025
+ console.log(` Gate override on until ${until}. Run \`haren track override off\` when done.`);
4026
+ } else if (action === "off") {
4027
+ const { gateOverride: _removed, ...next } = progress;
4028
+ await writeProgress(paths.progress, next);
4029
+ await emit(paths, { type: "gate-override", action: "off" });
4030
+ console.log(" Gate override off.");
4031
+ } else {
4032
+ throw new Error(`Unknown override action '${action}'. Use on or off.`);
4033
+ }
4034
+ }
4035
+ var TRACK_USAGE = `Usage:
4036
+ haren track status <module> <status>
4037
+ haren track feature <module> <feature> [status]
4038
+ haren track commit <module> <repoKey> <sha>
4039
+ haren track artifact <id> --type <type> --path <path> [--module <m>] [--status <s>]
4040
+ haren track event <type> [--module m] [--phase p] [--feature f] [--data '<json object>']
4041
+ haren track override on --reason "<text>" [--hours <n>]
4042
+ haren track override off
4043
+ Options: --haren-dir <path>`, VALUE_FLAGS, REGISTRY_HEADER = `| ID | Type | Module | Status | Path |
4044
+ |----|------|--------|--------|------|`;
4045
+ var init_track = __esm(() => {
4046
+ init_events();
4047
+ init_progress();
4048
+ init_resolve();
4049
+ VALUE_FLAGS = [
4050
+ "--haren-dir",
4051
+ "--type",
4052
+ "--path",
4053
+ "--module",
4054
+ "--status",
4055
+ "--phase",
4056
+ "--feature",
4057
+ "--data",
4058
+ "--reason",
4059
+ "--hours"
4060
+ ];
4061
+ });
4062
+
3573
4063
  // src/index.ts
3574
4064
  function parseArgs(args) {
3575
4065
  if (args.length === 0) {
@@ -3588,6 +4078,7 @@ function parseArgs(args) {
3588
4078
  case "upgrade":
3589
4079
  case "agent":
3590
4080
  case "plugin":
4081
+ case "track":
3591
4082
  return { command, args: rest };
3592
4083
  default:
3593
4084
  return { command: "unknown", args };
@@ -3617,6 +4108,11 @@ async function main() {
3617
4108
  await plugin(parsed.args);
3618
4109
  break;
3619
4110
  }
4111
+ case "track": {
4112
+ await Promise.resolve().then(() => init_track());
4113
+ await track(parsed.args);
4114
+ break;
4115
+ }
3620
4116
  case "help":
3621
4117
  console.log("Usage:");
3622
4118
  console.log(" haren init Set up haren (detects monorepo or multi-repo workspace)");
@@ -3626,10 +4122,17 @@ async function main() {
3626
4122
  console.log(" haren upgrade Upgrade framework files and migrate manifest/progress (--dry-run, --yes)");
3627
4123
  console.log(" haren agent Manage local agent (start, stop, status)");
3628
4124
  console.log(" haren plugin Manage plugins (add, remove, list, run, doctor)");
4125
+ console.log(" haren track Record progress and events:");
4126
+ console.log(" status <module> <status>");
4127
+ console.log(" feature <module> <feature> [status]");
4128
+ console.log(" commit <module> <repoKey> <sha>");
4129
+ console.log(" artifact <id> --type <type> --path <path> [--module <m>] [--status <s>]");
4130
+ console.log(" event <type> [--module m] [--phase p] [--feature f] [--data '<json>']");
4131
+ console.log(' override on --reason "<text>" [--hours <n>] | override off');
3629
4132
  break;
3630
4133
  case "unknown":
3631
4134
  console.error(`Unknown command: ${parsed.args[0]}`);
3632
- console.log("Usage: haren init | haren upgrade");
4135
+ console.log("Usage: haren init | upgrade | agent | plugin | track (haren --help)");
3633
4136
  process.exit(1);
3634
4137
  }
3635
4138
  }