@caiqueoak/flow 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caiqueoak/flow",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Readability-first, agent-agnostic software development workflow for coding agents.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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 }) {
@@ -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