@caiqueoak/flow 0.5.0 → 0.5.2

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/README.md CHANGED
@@ -38,7 +38,7 @@ PRD, engineering and plans use YAML frontmatter with `schema_version: 1`, `statu
38
38
  - `gates.yaml`: schema 1, command/builtin checks only; qualitative judgment remains review instructions.
39
39
  - `docs/graph.md`: deterministic derived projection; regenerate rather than hand-edit.
40
40
 
41
- Persist only pending, in_progress and completed. Ready/Blocked are derived from dependency edges and explicit blockers. Blockers use `{id, type: external_action|consequential_decision, description, status: unresolved|resolved}`. Only one mutating work item/task may be active across the project. Read-only analysis may be parallel; automatic concurrent worktrees are out of scope.
41
+ Persist only pending, in_progress and completed. Ready/Blocked are derived exclusively from work-item dependency edges. Blockers use `{id, type: external_action|consequential_decision, description, status: unresolved|resolved}` as context for the agent to address within the work item; they do not change execution status. Only one mutating work item/task may be active across the project. Read-only analysis may be parallel; automatic concurrent worktrees are out of scope.
42
42
 
43
43
  ## CLI
44
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caiqueoak/flow",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Readability-first, agent-agnostic software development workflow for coding agents.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -120,13 +120,8 @@ export function validateAcyclic(items) {
120
120
  export function deriveExecutionStatus(item, byId) {
121
121
  if (item.state === 'completed') return { status: 'completed', reasons: [] };
122
122
  const incompleteDependencies = item.depends_on.filter((id) => byId.get(id)?.state !== 'completed');
123
- const explicitBlockers = (item.blockers ?? []).filter((blocker) => blocker.status !== 'resolved');
124
- if (incompleteDependencies.length || explicitBlockers.length) {
125
- return {
126
- status: 'blocked',
127
- reasons: [...incompleteDependencies.map((id) => ({ type: 'dependency', ref: id })), ...explicitBlockers]
128
- };
129
- }
123
+ if (incompleteDependencies.length)
124
+ return { status: 'blocked', reasons: incompleteDependencies.map((id) => ({ type: 'dependency', ref: id })) };
130
125
  return { status: item.state === 'in_progress' ? 'in_progress' : 'ready', reasons: [] };
131
126
  }
132
127
 
@@ -22,6 +22,13 @@ const CLASSES = [
22
22
  ' classDef blocked fill:#fee2e2,stroke:#dc2626,color:#7f1d1d;'
23
23
  ];
24
24
 
25
+ const LINK_STYLES = {
26
+ completed: 'stroke:#16a34a,stroke-width:2px',
27
+ in_progress: 'stroke:#2563eb,stroke-width:3px',
28
+ ready: 'stroke:#d97706,stroke-width:2px,stroke-dasharray:6 4',
29
+ blocked: 'stroke:#dc2626,stroke-width:2px,stroke-dasharray:2 3'
30
+ };
31
+
25
32
  export function generateGraphMarkdown(backlogText) {
26
33
  const { work_items: items } = parseBacklog(backlogText);
27
34
  const ordered = topologicalOrder(items);
@@ -39,10 +46,10 @@ export function generateGraphMarkdown(backlogText) {
39
46
  '',
40
47
  '## Status',
41
48
  '',
42
- '- **Completed** — accepted work.',
43
- '- **In Progress** — currently executing.',
44
- '- **Ready** — pending work with all dependencies satisfied.',
45
- '- **Blocked** — pending work with at least one incomplete dependency or explicit external blocker.',
49
+ '- 🟩 **Completed** — accepted work.',
50
+ '- 🟦 **In Progress** — currently executing.',
51
+ '- 🟨 **Ready** — pending work with all dependencies satisfied.',
52
+ '- 🟥 **Blocked** — pending work with at least one incomplete work-item dependency.',
46
53
  '',
47
54
  '```mermaid',
48
55
  "%%{init: {'flowchart': {'curve': 'linear', 'nodeSpacing': 32, 'rankSpacing': 54}} }%%",
@@ -51,6 +58,8 @@ export function generateGraphMarkdown(backlogText) {
51
58
  for (const item of ordered) lines.push(` ${item.id}["${escapeMermaid(item.id)}<br/>${escapeMermaid(item.title)}"]`);
52
59
  lines.push('');
53
60
  for (const edge of edges) lines.push(` ${edge.source} --> ${edge.target}`);
61
+ lines.push('');
62
+ edges.forEach((edge, index) => lines.push(` linkStyle ${index} ${LINK_STYLES[statuses.get(edge.source)]};`));
54
63
  lines.push('', ...CLASSES);
55
64
  for (const status of ['completed', 'in_progress', 'ready', 'blocked']) {
56
65
  const ids = ordered.filter((item) => statuses.get(item.id) === status).map((item) => item.id);
@@ -27,9 +27,39 @@ function number(value) {
27
27
  if (!match) throw new Error(`Cannot normalize ID '${value}'.`);
28
28
  return match[0].padStart(3, '0');
29
29
  }
30
+ function temporarySibling(file) {
31
+ const directory = path.dirname(file);
32
+ const base = path.basename(file);
33
+ let attempt = 0;
34
+ let temporary;
35
+ do {
36
+ temporary = path.join(directory, `.${base}.flow-migration-${process.pid}-${Date.now()}-${attempt++}`);
37
+ } while (fs.existsSync(temporary));
38
+ return temporary;
39
+ }
40
+ function sameEntry(from, to) {
41
+ return fs.realpathSync.native(from) === fs.realpathSync.native(to);
42
+ }
30
43
  function move(from, to) {
31
44
  if (!fs.existsSync(from)) return;
32
- if (fs.existsSync(to)) throw new Error(`Migration destination already exists: ${to}`);
45
+ if (path.resolve(from) === path.resolve(to)) return;
46
+ if (fs.existsSync(to)) {
47
+ if (!sameEntry(from, to)) throw new Error(`Migration destination already exists: ${to}`);
48
+ const temporary = temporarySibling(from);
49
+ fs.renameSync(from, temporary);
50
+ try {
51
+ fs.renameSync(temporary, to);
52
+ } catch (error) {
53
+ try {
54
+ fs.renameSync(temporary, from);
55
+ } catch (recoveryError) {
56
+ error.preserveRecoveryData = true;
57
+ error.recovery = { from, to, temporary, recoveryError };
58
+ }
59
+ throw error;
60
+ }
61
+ return;
62
+ }
33
63
  fs.mkdirSync(path.dirname(to), { recursive: true });
34
64
  fs.renameSync(from, to);
35
65
  }
@@ -136,7 +166,7 @@ function migrateStaged(root) {
136
166
  ])
137
167
  move(path.join(flow, old), path.join(flow, 'docs', next));
138
168
  if (fs.existsSync(path.join(flow, 'GRAPH.md'))) fs.unlinkSync(path.join(flow, 'GRAPH.md'));
139
- if (oldFile.endsWith('BACKLOG.yaml')) fs.unlinkSync(oldFile);
169
+ if (oldFile.endsWith('BACKLOG.yaml')) move(oldFile, path.join(flow, 'backlog.yaml'));
140
170
  fs.writeFileSync(path.join(flow, 'backlog.yaml'), text);
141
171
  fs.writeFileSync(path.join(flow, 'docs', 'graph.md'), generateGraphMarkdown(text));
142
172
  const state = emptyState();
@@ -163,6 +193,7 @@ export function migrateProject(root) {
163
193
  const staging = fs.mkdtempSync(path.join(root, '.flow-migration-'));
164
194
  const backup = path.join(staging, 'backup');
165
195
  const staged = path.join(staging, '.flow');
196
+ let preserveStaging = false;
166
197
  try {
167
198
  fs.cpSync(flow, staged, { recursive: true });
168
199
  migrateStaged(staging);
@@ -174,9 +205,13 @@ export function migrateProject(root) {
174
205
  throw error;
175
206
  }
176
207
  return { unresolved: ['semantic reconciliation'], unchanged: false };
208
+ } catch (error) {
209
+ preserveStaging = Boolean(error?.preserveRecoveryData);
210
+ throw error;
177
211
  } finally {
178
212
  // Retain the original backup if even rollback failed; never delete the only copy.
179
- if (!fs.existsSync(backup) || fs.existsSync(flow)) fs.rmSync(staging, { recursive: true, force: true });
213
+ if (!preserveStaging && (!fs.existsSync(backup) || fs.existsSync(flow)))
214
+ fs.rmSync(staging, { recursive: true, force: true });
180
215
  }
181
216
  }
182
217
  export function runMigrate({ args }) {
@@ -79,7 +79,7 @@ export function routeProject(root) {
79
79
  if (active && deriveExecutionStatus(active, byId).status === 'blocked')
80
80
  return {
81
81
  action: 'stop',
82
- reason: 'external_action',
82
+ reason: 'dependency_blocked',
83
83
  work_item: active.id,
84
84
  details: deriveExecutionStatus(active, byId).reasons
85
85
  };
@@ -14,7 +14,11 @@ export function runStatus({ args }) {
14
14
  const groups = new Map(['in_progress', 'ready', 'blocked', 'completed'].map((status) => [status, []]));
15
15
  for (const item of backlog.work_items) {
16
16
  const derived = deriveExecutionStatus(item, byId);
17
- groups.get(derived.status).push({ ...item, reasons: derived.reasons });
17
+ groups.get(derived.status).push({
18
+ ...item,
19
+ reasons: derived.reasons,
20
+ blockers: item.blockers.filter((blocker) => blocker.status === 'unresolved')
21
+ });
18
22
  }
19
23
  const lines = [];
20
24
  for (const [status, items] of groups) {
@@ -23,8 +27,7 @@ export function runStatus({ args }) {
23
27
  for (const item of items) {
24
28
  const deps = item.reasons.filter((r) => r.type === 'dependency').map((r) => r.ref);
25
29
  lines.push(` ${item.id} — ${item.title}${deps.length ? ` ← ${deps.join(', ')}` : ''}`);
26
- for (const reason of item.reasons.filter((reason) => reason.type !== 'dependency'))
27
- lines.push(` ${reason.type}: ${reason.description} [${reason.id}]`);
30
+ for (const blocker of item.blockers) lines.push(` blocker: ${blocker.description} [${blocker.id}]`);
28
31
  }
29
32
  lines.push('');
30
33
  }
@@ -19,6 +19,7 @@ export function validateProject(root, { preCommitTask = null, skipTrace = false
19
19
  const error = (code, message) => findings.push({ level: 'error', code, message });
20
20
  const flow = path.join(root, '.flow');
21
21
  const exists = (relative) => fs.existsSync(path.join(flow, relative));
22
+ const hasExactRootEntry = (name) => fs.readdirSync(flow).includes(name);
22
23
  const read = (relative) => fs.readFileSync(path.join(flow, relative), 'utf8');
23
24
  let config;
24
25
  try {
@@ -36,7 +37,7 @@ export function validateProject(root, { preCommitTask = null, skipTrace = false
36
37
  )
37
38
  error('CONFIG', 'Invalid engineering bootstrap preferences.');
38
39
  for (const name of ['STATE.md', 'DECISIONS.md', 'SUMMARY.md', 'BACKLOG.yaml', 'PRD.md', 'ENGINEERING.md', 'GRAPH.md'])
39
- if (exists(name)) error('LEGACY', `${name} must be migrated.`);
40
+ if (hasExactRootEntry(name)) error('LEGACY', `${name} must be migrated.`);
40
41
  let state;
41
42
  try {
42
43
  state = exists('state.yaml') ? parseState(read('state.yaml')) : null;
@@ -4,7 +4,7 @@ const text = fs.readFileSync(
4
4
  new URL('../../skills/flow/engineering/profiles/readability-first.md', import.meta.url),
5
5
  'utf8'
6
6
  );
7
- export const READABILITY_FIRST_PROFILE = parse(text.match(/^---\n([\s\S]*?)\n---/)[1]);
7
+ export const READABILITY_FIRST_PROFILE = parse(text.match(/^---\r?\n([\s\S]*?)\r?\n---/)[1]);
8
8
  export const ENGINEERING_PROFILES = {
9
9
  'readability-first': READABILITY_FIRST_PROFILE,
10
10
  [READABILITY_FIRST_PROFILE.id]: READABILITY_FIRST_PROFILE