@moritakaaz/markflow 0.2.0 → 0.3.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/package.json CHANGED
@@ -19,5 +19,5 @@
19
19
  "test": "node --test"
20
20
  },
21
21
  "type": "module",
22
- "version": "0.2.0"
22
+ "version": "0.3.0"
23
23
  }
package/src/discover.js CHANGED
@@ -19,6 +19,86 @@ const MANIFESTS = {
19
19
  "Gemfile": "Ruby",
20
20
  };
21
21
 
22
+ // Discovery records dependency names as written.
23
+ // It does not map them to framework names.
24
+
25
+ function parsePackageDeps(text) {
26
+ try {
27
+ const pkg = JSON.parse(text);
28
+ return [
29
+ ...Object.keys(pkg.dependencies || {}),
30
+ ...Object.keys(pkg.devDependencies || {}),
31
+ ];
32
+ } catch {
33
+ return [];
34
+ }
35
+ }
36
+
37
+ function parseRequirements(text) {
38
+ const names = [];
39
+ for (const raw of text.split("\n")) {
40
+ let line = raw.split("#")[0].trim();
41
+ if (!line || line.startsWith("-")) {
42
+ continue;
43
+ }
44
+ line = line.split(";")[0].trim();
45
+ const name = line.split(/[\s=<>~!\[]/)[0].trim();
46
+ if (name) {
47
+ names.push(name);
48
+ }
49
+ }
50
+ return names;
51
+ }
52
+
53
+ function parseGoMod(text) {
54
+ const names = [];
55
+ for (const raw of text.split("\n")) {
56
+ const line = raw.trim();
57
+ if (!line || line === ")" || line.startsWith("//")) {
58
+ continue;
59
+ }
60
+ const parts = line.split(/\s+/);
61
+ let mod = null;
62
+ if (parts[0] === "require") {
63
+ mod = parts[1];
64
+ } else if (
65
+ !["module", "go", "require", "replace", "exclude", "retract"].includes(
66
+ parts[0]
67
+ ) &&
68
+ parts.length >= 2
69
+ ) {
70
+ mod = parts[0];
71
+ }
72
+ if (!mod || mod.startsWith("(")) {
73
+ continue;
74
+ }
75
+ const segments = mod.split("/");
76
+ let last = segments[segments.length - 1];
77
+ if (/^v\d+$/.test(last)) {
78
+ last = segments[segments.length - 2] || "";
79
+ }
80
+ if (last) {
81
+ names.push(last);
82
+ }
83
+ }
84
+ return names;
85
+ }
86
+
87
+ function parseComposerDeps(text) {
88
+ try {
89
+ const pkg = JSON.parse(text);
90
+ const names = [
91
+ ...Object.keys(pkg.require || {}),
92
+ ...Object.keys(pkg["require-dev"] || {}),
93
+ ];
94
+ return names.filter(
95
+ (n) => n !== "php" && !n.startsWith("ext-") && !n.startsWith("lib-")
96
+ );
97
+ } catch {
98
+ return [];
99
+ }
100
+ }
101
+
22
102
  const WORKSPACE_FILES = ["pnpm-workspace.yaml", "lerna.json"];
23
103
 
24
104
  const CONFIG_PATTERNS = [
@@ -63,7 +143,9 @@ export async function discover(root) {
63
143
  const configs = [];
64
144
  const workspaceEvidence = [];
65
145
  const memberDirs = new Set();
146
+ const dependencies = [];
66
147
  const seen = new Set();
148
+ const seenDeps = new Set();
67
149
  function addStack(name, evidence, confidence) {
68
150
  manifests.push(evidence);
69
151
  if (seen.has(name)) {
@@ -72,6 +154,37 @@ export async function discover(root) {
72
154
  seen.add(name);
73
155
  stacks.push({ name, evidence, confidence });
74
156
  }
157
+ function addDependency(name, evidence) {
158
+ const key = name + "@" + evidence;
159
+ if (seenDeps.has(key)) {
160
+ return;
161
+ }
162
+ seenDeps.add(key);
163
+ dependencies.push({ name, evidence, confidence: "detected" });
164
+ }
165
+ async function collectDeps(fileName, fullPath, evidence) {
166
+ let text;
167
+ try {
168
+ text = await readFile(fullPath, "utf8");
169
+ } catch {
170
+ return;
171
+ }
172
+ let names = [];
173
+ if (fileName === "package.json") {
174
+ names = parsePackageDeps(text);
175
+ } else if (fileName === "requirements.txt") {
176
+ names = parseRequirements(text);
177
+ } else if (fileName === "go.mod") {
178
+ names = parseGoMod(text);
179
+ } else if (fileName === "composer.json") {
180
+ names = parseComposerDeps(text);
181
+ } else {
182
+ return;
183
+ }
184
+ for (const dep of names) {
185
+ addDependency(dep, evidence);
186
+ }
187
+ }
75
188
  async function scanDir(dir, rel, confidence, depth) {
76
189
  let entries;
77
190
  try {
@@ -102,6 +215,7 @@ export async function discover(root) {
102
215
  if (rel) {
103
216
  memberDirs.add(rel.split("/").slice(0, 2).join("/"));
104
217
  }
218
+ await collectDeps(entry.name, join(dir, entry.name), childRel);
105
219
  }
106
220
  }
107
221
  }
@@ -177,6 +291,7 @@ export async function discover(root) {
177
291
  stacks,
178
292
  manifests,
179
293
  configs,
294
+ dependencies,
180
295
  workspace: {
181
296
  detected: workspaceEvidence.length > 0,
182
297
  evidence: workspaceEvidence,
package/src/doctor.js CHANGED
@@ -204,25 +204,32 @@ export async function runDoctor(options) {
204
204
  }
205
205
  }
206
206
  }
207
+ const stillTemplate = [];
207
208
  try {
208
209
  const templatesDir = await findTemplatesDir();
209
- const projectName =
210
- (marker && marker.project) || basename(root);
211
- const prdTemplate = (
212
- await readFile(join(templatesDir, "markflow/docs/PRD.md"), "utf8")
213
- )
214
- .split("{{project_name}}")
215
- .join(projectName);
216
- const prdText = await readFile(
217
- join(root, "markflow/docs/PRD.md"),
218
- "utf8"
219
- );
220
- if (prdText === prdTemplate) {
221
- console.log("Warning PRD is still the template markflow/docs/PRD.md");
222
- warnings.push("markflow/docs/PRD.md");
210
+ const projectName = (marker && marker.project) || basename(root);
211
+ for (const [rel, label] of [
212
+ ["markflow/docs/PRD.md", "PRD"],
213
+ ["markflow/docs/ARCHITECTURE.md", "ARCHITECTURE"],
214
+ ["markflow/TASKS.md", "TASKS"],
215
+ ]) {
216
+ const templateText = (
217
+ await readFile(join(templatesDir, rel), "utf8")
218
+ )
219
+ .split("{{project_name}}")
220
+ .join(projectName);
221
+ const text = await readFile(join(root, rel), "utf8");
222
+ if (text === templateText) {
223
+ console.log("Warning " + label + " is still the template " + rel);
224
+ warnings.push(rel);
225
+ stillTemplate.push(rel);
226
+ }
223
227
  }
224
228
  } catch {
225
- // Template or PRD is missing, so skip this check.
229
+ // Template or doc is missing, so skip this check.
230
+ }
231
+ if (stillTemplate.length > 0) {
232
+ console.log("Next. Fill " + stillTemplate[0] + ".");
226
233
  }
227
234
  let specTotal = 0;
228
235
  let specDraft = 0;
package/src/init.js CHANGED
@@ -85,7 +85,8 @@ export function fillArchitecture(text, context) {
85
85
  .replace("- Language. TBD", "- Language. " + names)
86
86
  .replace(
87
87
  "- Framework. TBD",
88
- "- Framework. TBD\n- Evidence. " +
88
+ "- Framework. TBD" +
89
+ "\n- Evidence. " +
89
90
  evidence +
90
91
  "\n- Monorepo. " +
91
92
  (context.monorepo ? "Yes" : "No")
@@ -136,8 +137,17 @@ export async function runInit(options) {
136
137
  const lines = context.stacks.map(
137
138
  (s) => "- " + s.name + " from " + s.evidence + ", confidence " + s.confidence
138
139
  );
139
- const filled =
140
+ let filled =
140
141
  stack + "\n## Detected stacks\n\nDiscovery found these stacks.\n\n" + lines.join("\n") + "\n";
142
+ if (context.dependencies.length > 0) {
143
+ const depLines = context.dependencies.map(
144
+ (d) => "- " + d.name + " from " + d.evidence + ", detected"
145
+ );
146
+ filled +=
147
+ "\n## Detected dependencies\n\nDiscovery found these dependencies.\n\n" +
148
+ depLines.join("\n") +
149
+ "\n";
150
+ }
141
151
  await writeFile(stackPath, filled);
142
152
  }
143
153
  }
@@ -206,6 +216,7 @@ export async function runInit(options) {
206
216
  stacks: context.stacks,
207
217
  manifests: context.manifests,
208
218
  monorepo: context.monorepo,
219
+ dependencies: context.dependencies,
209
220
  };
210
221
  // Record hashes only for files this run created.
211
222
  // A file the user wrote before init stays untracked,
package/src/versions.js CHANGED
@@ -2,5 +2,5 @@
2
2
  // Bump methodology when the docs in docs change.
3
3
  // Bump template when the files in templates change.
4
4
  // The CLI version comes from package.json.
5
- export const METHODOLOGY_VERSION = "0.2.0";
6
- export const TEMPLATE_VERSION = "0.2.0";
5
+ export const METHODOLOGY_VERSION = "0.3.0";
6
+ export const TEMPLATE_VERSION = "0.3.0";
@@ -6,6 +6,8 @@ This file is the router for AI agents in this project. Read it first.
6
6
 
7
7
  All project context lives in the `markflow` folder. Do not create new Markdown files in the root.
8
8
 
9
+ If the PRD is still the template, start with the onboarding workflow in `markflow/.agents/workflows/onboarding.md`. It interviews the user one question at a time and fills the first docs.
10
+
9
11
  Start with these files in order.
10
12
 
11
13
  1. Read `markflow/docs/PRD.md` to learn what this project is.
@@ -10,6 +10,8 @@ Draft means the spec is still being written. Approved means it is ready to build
10
10
 
11
11
  ## Specs
12
12
 
13
- | ID | Title | Status |
14
- |---|---|---|
15
- | 01 | TBD | Draft |
13
+ Add one row per spec. Write the file name in the File column. Doctor checks the file name, not the title.
14
+
15
+ | ID | File | Title | Status |
16
+ |---|---|---|---|
17
+ | 01 | TBD | TBD | Draft |
package/test/cli.test.js CHANGED
@@ -81,6 +81,49 @@ describe("discover", () => {
81
81
  assert.equal(result.workspace.detected, true);
82
82
  });
83
83
 
84
+ it("detects dependencies from package.json", async (t) => {
85
+ const dir = await tempDir(t);
86
+ await write(
87
+ dir,
88
+ "package.json",
89
+ JSON.stringify({
90
+ dependencies: { alpha: "^1.0.0", beta: "^2.0.0" },
91
+ devDependencies: { gamma: "^3.0.0" },
92
+ })
93
+ );
94
+ const result = await discover(dir);
95
+ assert.deepEqual(
96
+ result.dependencies.map((d) => d.name),
97
+ ["alpha", "beta", "gamma"]
98
+ );
99
+ assert.equal(result.dependencies[0].confidence, "detected");
100
+ assert.equal(result.dependencies[0].evidence, "package.json");
101
+ });
102
+
103
+ it("detects dependencies from requirements.txt", async (t) => {
104
+ const dir = await tempDir(t);
105
+ await write(dir, "requirements.txt", "alpha==1.0\nbeta>=2.0\n");
106
+ const result = await discover(dir);
107
+ assert.deepEqual(
108
+ result.dependencies.map((d) => d.name),
109
+ ["alpha", "beta"]
110
+ );
111
+ });
112
+
113
+ it("detects dependencies from go.mod", async (t) => {
114
+ const dir = await tempDir(t);
115
+ await write(
116
+ dir,
117
+ "go.mod",
118
+ "module example.com/demo\n\ngo 1.21\n\nrequire (\n\tgithub.com/example/alpha v1.0.0\n\tgithub.com/example/beta/v4 v4.0.0\n)\n"
119
+ );
120
+ const result = await discover(dir);
121
+ assert.deepEqual(
122
+ result.dependencies.map((d) => d.name),
123
+ ["alpha", "beta"]
124
+ );
125
+ });
126
+
84
127
  it("skips venv, target, and .next dirs", async (t) => {
85
128
  const dir = await tempDir(t);
86
129
  await write(dir, "package.json", "{}");
@@ -163,6 +206,35 @@ describe("init", () => {
163
206
  assert.ok(filled.includes("- Monorepo. No"));
164
207
  });
165
208
 
209
+ it("fillArchitecture leaves framework as TBD", () => {
210
+ const filled = fillArchitecture("- Language. TBD\n- Framework. TBD\n", {
211
+ stacks: [{ name: "JavaScript", evidence: "package.json", confidence: "high" }],
212
+ monorepo: false,
213
+ });
214
+ assert.ok(filled.includes("- Framework. TBD"));
215
+ });
216
+
217
+ it("writes detected dependencies into docs", async (t) => {
218
+ const dir = await tempDir(t);
219
+ await write(
220
+ dir,
221
+ "package.json",
222
+ JSON.stringify({ dependencies: { alpha: "^1.0.0" } })
223
+ );
224
+ await runInit({ target: dir });
225
+ const arch = await readFile(
226
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
227
+ "utf8"
228
+ );
229
+ assert.ok(arch.includes("- Framework. TBD"));
230
+ const stack = await readFile(
231
+ join(dir, "markflow/docs/STACK.md"),
232
+ "utf8"
233
+ );
234
+ assert.ok(stack.includes("## Detected dependencies"));
235
+ assert.ok(stack.includes("- alpha from package.json, detected"));
236
+ });
237
+
166
238
  it("fillArchitecture throws when template lines are missing", () => {
167
239
  assert.throws(
168
240
  () =>
@@ -214,6 +286,13 @@ describe("init", () => {
214
286
  assert.equal(marker.minimal, false);
215
287
  });
216
288
 
289
+ it("created AGENTS.md points to onboarding", async (t) => {
290
+ const dir = await tempDir(t);
291
+ await runInit({ target: dir });
292
+ const text = await readFile(join(dir, "AGENTS.md"), "utf8");
293
+ assert.ok(text.includes("markflow/.agents/workflows/onboarding.md"));
294
+ });
295
+
217
296
  it("init suggests onboarding on first run only", async (t) => {
218
297
  const dir = await tempDir(t);
219
298
  const first = await runInit({ target: dir });
@@ -258,6 +337,62 @@ describe("doctor", () => {
258
337
  assert.ok(result.warnings.some((w) => w.includes("99-new.md")));
259
338
  });
260
339
 
340
+ it("spec listed by file name in index passes", async (t) => {
341
+ const dir = await tempDir(t);
342
+ await runInit({ target: dir });
343
+ const index = await readFile(
344
+ join(dir, "markflow/specs/index.md"),
345
+ "utf8"
346
+ );
347
+ assert.ok(index.includes("| ID | File | Title | Status |"));
348
+ assert.ok(index.includes("Write the file name in the File column."));
349
+ await write(
350
+ dir,
351
+ "markflow/specs/01-record-a-sale.md",
352
+ "# Record a sale\n\n## Goal\n\nRecord one sale.\n\n## Acceptance\n\n- The sale is saved.\n\n## Status\n\nDraft\n"
353
+ );
354
+ await write(
355
+ dir,
356
+ "markflow/specs/index.md",
357
+ index.replace(
358
+ "| 01 | TBD | TBD | Draft |",
359
+ "| 01 | 01-record-a-sale.md | Record a sale | Draft |"
360
+ )
361
+ );
362
+ const result = await runDoctor({ target: dir });
363
+ assert.equal(result.ok, true);
364
+ assert.ok(
365
+ !result.warnings.some((w) => w.includes("01-record-a-sale.md"))
366
+ );
367
+ });
368
+
369
+ it("spec listed by title only still warns", async (t) => {
370
+ const dir = await tempDir(t);
371
+ await runInit({ target: dir });
372
+ const index = await readFile(
373
+ join(dir, "markflow/specs/index.md"),
374
+ "utf8"
375
+ );
376
+ await write(
377
+ dir,
378
+ "markflow/specs/01-record-a-sale.md",
379
+ "# Record a sale\n\n## Goal\n\nRecord one sale.\n\n## Acceptance\n\n- The sale is saved.\n\n## Status\n\nDraft\n"
380
+ );
381
+ await write(
382
+ dir,
383
+ "markflow/specs/index.md",
384
+ index.replace(
385
+ "| 01 | TBD | TBD | Draft |",
386
+ "| 01 | TBD | Record a sale | Draft |"
387
+ )
388
+ );
389
+ const result = await runDoctor({ target: dir });
390
+ assert.equal(result.ok, true);
391
+ assert.ok(
392
+ result.warnings.some((w) => w.includes("01-record-a-sale.md"))
393
+ );
394
+ });
395
+
261
396
  it("warns on empty acceptance in a spec", async (t) => {
262
397
  const dir = await tempDir(t);
263
398
  await runInit({ target: dir });
@@ -358,6 +493,28 @@ describe("doctor", () => {
358
493
  assert.equal(result.errors.length, 0);
359
494
  });
360
495
 
496
+ it("warns when ARCHITECTURE and TASKS are still the template", async (t) => {
497
+ const dir = await tempDir(t);
498
+ await runInit({ target: dir });
499
+ const result = await runDoctor({ target: dir });
500
+ assert.equal(result.ok, true);
501
+ assert.ok(result.warnings.includes("markflow/docs/ARCHITECTURE.md"));
502
+ assert.ok(result.warnings.includes("markflow/TASKS.md"));
503
+ });
504
+
505
+ it("no template warnings when all three are filled", async (t) => {
506
+ const dir = await tempDir(t);
507
+ await runInit({ target: dir });
508
+ await write(dir, "markflow/docs/PRD.md", "Our own product.\n");
509
+ await write(dir, "markflow/docs/ARCHITECTURE.md", "Our own stack.\n");
510
+ await write(dir, "markflow/TASKS.md", "Our own tasks.\n");
511
+ const result = await runDoctor({ target: dir });
512
+ assert.equal(result.ok, true);
513
+ assert.ok(!result.warnings.includes("markflow/docs/PRD.md"));
514
+ assert.ok(!result.warnings.includes("markflow/docs/ARCHITECTURE.md"));
515
+ assert.ok(!result.warnings.includes("markflow/TASKS.md"));
516
+ });
517
+
361
518
  it("no PRD warning when PRD is filled", async (t) => {
362
519
  const dir = await tempDir(t);
363
520
  await runInit({ target: dir });
@@ -552,7 +709,7 @@ describe("parser", () => {
552
709
  const dir = await tempDir(t);
553
710
  const result = runCli(["--version"], dir);
554
711
  assert.equal(result.status, 0);
555
- assert.equal(result.stdout.trim(), "0.2.0");
712
+ assert.equal(result.stdout.trim(), "0.3.0");
556
713
  });
557
714
  });
558
715