@axn-dev/cmd-c4model 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 astropiano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ export type RenderFormat = "single" | "multi";
2
+ export interface RenderResult {
3
+ format: RenderFormat;
4
+ output: string;
5
+ levels: string[];
6
+ }
7
+ export declare function render(dir: string, format: RenderFormat, out: string): RenderResult;
8
+ export declare function defaultWorkdir(slug: string): string;
9
+ export declare function slugify(title: string): string;
10
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/c4model-lib/render.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAyGD,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAQnF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO7C"}
@@ -0,0 +1,107 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, copyFileSync } from "node:fs";
2
+ import { join, basename, resolve } from "node:path";
3
+ import { parseYaml } from "@axn-dev/core";
4
+ const LEVEL_ORDER = ["context", "containers", "components", "code"];
5
+ function levelLabel(file) {
6
+ const m = basename(file, ".md").match(/^\d+-(.+)$/);
7
+ return m ? m[1] : basename(file, ".md");
8
+ }
9
+ function loadWorkdir(dir) {
10
+ const abs = resolve(dir);
11
+ if (!existsSync(abs))
12
+ throw new Error(`Working directory not found: ${abs}`);
13
+ let title = basename(abs);
14
+ let date = "";
15
+ const metaPath = join(abs, "meta.yaml");
16
+ if (existsSync(metaPath)) {
17
+ const meta = parseYaml(readFileSync(metaPath, "utf-8"));
18
+ if (typeof meta["title"] === "string")
19
+ title = meta["title"];
20
+ if (typeof meta["date"] === "string")
21
+ date = meta["date"];
22
+ }
23
+ const levelsDir = join(abs, "levels");
24
+ const isEmpty = (p) => readFileSync(p, "utf-8").replace(/<!--[\s\S]*?-->/g, "").trim() === "";
25
+ const levelFiles = existsSync(levelsDir)
26
+ ? readdirSync(levelsDir)
27
+ .filter((f) => f.endsWith(".md") && !isEmpty(join(levelsDir, f)))
28
+ .sort((a, b) => {
29
+ const rank = (f) => {
30
+ const idx = LEVEL_ORDER.indexOf(levelLabel(f));
31
+ return idx === -1 ? LEVEL_ORDER.length : idx;
32
+ };
33
+ return rank(a) - rank(b) || a.localeCompare(b);
34
+ })
35
+ .map((f) => join(levelsDir, f))
36
+ : [];
37
+ if (levelFiles.length === 0) {
38
+ throw new Error(`No level files found in ${levelsDir}. Expected files like 01-context.md.`);
39
+ }
40
+ return { dir: abs, title, date, levelFiles };
41
+ }
42
+ function headingFor(file) {
43
+ const label = levelLabel(file);
44
+ const num = basename(file, ".md").match(/^(\d+)/)?.[1];
45
+ const nice = label.charAt(0).toUpperCase() + label.slice(1);
46
+ return num ? `Level ${parseInt(num, 10)} — ${nice}` : nice;
47
+ }
48
+ function renderSingle(work, out) {
49
+ const parts = [`# C4 Decomposition — ${work.title}\n`];
50
+ if (work.date)
51
+ parts.push(`_Generated: ${work.date}_\n`);
52
+ parts.push(`## Contents\n`);
53
+ for (const f of work.levelFiles) {
54
+ const anchor = headingFor(f).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
55
+ parts.push(`- [${headingFor(f)}](#${anchor})`);
56
+ }
57
+ parts.push("");
58
+ for (const f of work.levelFiles) {
59
+ parts.push(`## ${headingFor(f)}\n`);
60
+ parts.push(readFileSync(f, "utf-8").trim() + "\n");
61
+ }
62
+ const outPath = resolve(out);
63
+ mkdirSync(dirnameOf(outPath), { recursive: true });
64
+ writeFileSync(outPath, parts.join("\n"), "utf-8");
65
+ return { format: "single", output: outPath, levels: work.levelFiles.map((f) => basename(f)) };
66
+ }
67
+ function renderMulti(work, out) {
68
+ const outDir = resolve(out);
69
+ mkdirSync(outDir, { recursive: true });
70
+ const lines = [`# C4 Decomposition — ${work.title}\n`];
71
+ if (work.date)
72
+ lines.push(`_Generated: ${work.date}_\n`);
73
+ lines.push(`## Levels\n`);
74
+ for (const f of work.levelFiles) {
75
+ const name = basename(f);
76
+ copyFileSync(f, join(outDir, name));
77
+ lines.push(`- [${headingFor(f)}](./${name})`);
78
+ }
79
+ lines.push("");
80
+ const indexPath = join(outDir, "index.md");
81
+ writeFileSync(indexPath, lines.join("\n"), "utf-8");
82
+ return { format: "multi", output: outDir, levels: work.levelFiles.map((f) => basename(f)) };
83
+ }
84
+ function dirnameOf(p) {
85
+ const idx = p.lastIndexOf("/");
86
+ return idx === -1 ? "." : p.slice(0, idx) || "/";
87
+ }
88
+ export function render(dir, format, out) {
89
+ const work = loadWorkdir(dir);
90
+ const defaultOut = format === "single"
91
+ ? join(work.dir, "c4-decomposition.md")
92
+ : join(work.dir, "c4");
93
+ const target = out || defaultOut;
94
+ return format === "single" ? renderSingle(work, target) : renderMulti(work, target);
95
+ }
96
+ export function defaultWorkdir(slug) {
97
+ return resolve(process.cwd(), ".axn-dev", "c4model", slug);
98
+ }
99
+ export function slugify(title) {
100
+ const slug = title
101
+ .toLowerCase()
102
+ .replace(/[^a-z0-9]+/g, "-")
103
+ .replace(/^-|-$/g, "")
104
+ .slice(0, 60);
105
+ return slug || `c4-${Date.now()}`;
106
+ }
107
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/c4model-lib/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACxG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAiB1C,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AAEpE,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACpD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC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RepoScan {
2
+ root: string;
3
+ name: string;
4
+ git?: {
5
+ branch: string;
6
+ remote?: string;
7
+ };
8
+ readme?: {
9
+ path: string;
10
+ excerpt: string;
11
+ };
12
+ manifests: ManifestInfo[];
13
+ tree: string[];
14
+ sources: Record<string, number>;
15
+ notables: string[];
16
+ }
17
+ interface ManifestInfo {
18
+ file: string;
19
+ kind: string;
20
+ summary?: string;
21
+ }
22
+ export declare function scanRepo(startPath: string): RepoScan;
23
+ export {};
24
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/c4model-lib/scan.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAwJD,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAiCpD"}
@@ -0,0 +1,193 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { join, basename, dirname, relative } from "node:path";
3
+ import { execSync } from "node:child_process";
4
+ const MANIFEST_FILES = {
5
+ "package.json": "node",
6
+ "pnpm-workspace.yaml": "node-workspace",
7
+ "tsconfig.json": "typescript",
8
+ "go.mod": "go",
9
+ "Cargo.toml": "rust",
10
+ "pyproject.toml": "python",
11
+ "requirements.txt": "python",
12
+ "pom.xml": "java",
13
+ "build.gradle": "java",
14
+ "build.gradle.kts": "java",
15
+ "composer.json": "php",
16
+ "Gemfile": "ruby",
17
+ };
18
+ const NOTABLE_FILES = [
19
+ "Dockerfile",
20
+ "docker-compose.yml",
21
+ "docker-compose.yaml",
22
+ "compose.yml",
23
+ "compose.yaml",
24
+ "Makefile",
25
+ ".gitlab-ci.yml",
26
+ "Jenkinsfile",
27
+ "helm",
28
+ "charts",
29
+ "k8s",
30
+ "terraform",
31
+ "ansible",
32
+ ];
33
+ const IGNORED_DIRS = new Set([
34
+ "node_modules",
35
+ "dist",
36
+ "build",
37
+ "out",
38
+ "target",
39
+ "vendor",
40
+ ".git",
41
+ ".idea",
42
+ ".vscode",
43
+ "__pycache__",
44
+ ".next",
45
+ "coverage",
46
+ ]);
47
+ const SOURCE_EXT_RE = /\.(ts|tsx|js|jsx|py|go|rs|java|kt|cs|cpp|c|h|hpp|rb|php|swift|scala|sh)$/;
48
+ /** Walk up from `start` until a .git entry (dir or file for worktrees) is found. */
49
+ function findGitRoot(start) {
50
+ let dir = start;
51
+ for (;;) {
52
+ if (existsSync(join(dir, ".git")))
53
+ return dir;
54
+ const parent = dirname(dir);
55
+ if (parent === dir)
56
+ return null;
57
+ dir = parent;
58
+ }
59
+ }
60
+ function gitExec(root, args) {
61
+ try {
62
+ return execSync(`git -C "${root}" ${args}`, { stdio: ["ignore", "pipe", "ignore"] })
63
+ .toString()
64
+ .trim();
65
+ }
66
+ catch {
67
+ return undefined;
68
+ }
69
+ }
70
+ function readExcerpt(path, maxLines = 60) {
71
+ return readFileSync(path, "utf-8").split("\n").slice(0, maxLines).join("\n");
72
+ }
73
+ function summarizeManifest(root, file, kind) {
74
+ const info = { file, kind };
75
+ try {
76
+ const raw = readFileSync(join(root, file), "utf-8");
77
+ if (file === "package.json") {
78
+ const pkg = JSON.parse(raw);
79
+ const deps = Object.keys(pkg.dependencies ?? {});
80
+ const devDeps = Object.keys(pkg.devDependencies ?? {});
81
+ info.summary = `${pkg.name ?? "?"} — deps: ${deps.join(", ") || "none"}; devDeps: ${devDeps.join(", ") || "none"}`;
82
+ }
83
+ else if (file === "go.mod") {
84
+ info.summary = raw.split("\n").find((l) => l.startsWith("module "))?.trim();
85
+ }
86
+ else if (file === "Cargo.toml") {
87
+ info.summary = raw.match(/^\s*name\s*=\s*"([^"]+)"/m)?.[0]?.trim();
88
+ }
89
+ else {
90
+ info.summary = raw.split("\n").filter((l) => l.trim()).slice(0, 5).join(" | ");
91
+ }
92
+ }
93
+ catch {
94
+ /* unreadable manifest — keep file+kind only */
95
+ }
96
+ return info;
97
+ }
98
+ /** Shallow directory listing: top-level entries plus one level into directories. */
99
+ function shallowTree(root, maxEntries = 120) {
100
+ const out = [];
101
+ const walk = (dir, depth) => {
102
+ if (out.length >= maxEntries || depth > 1)
103
+ return;
104
+ let entries;
105
+ try {
106
+ entries = readdirSync(dir, { withFileTypes: true });
107
+ }
108
+ catch {
109
+ return;
110
+ }
111
+ for (const e of entries) {
112
+ if (out.length >= maxEntries)
113
+ return;
114
+ if (e.name.startsWith(".") && depth > 0)
115
+ continue;
116
+ if (e.isDirectory() && IGNORED_DIRS.has(e.name))
117
+ continue;
118
+ const rel = relative(root, join(dir, e.name)) || e.name;
119
+ out.push(e.isDirectory() ? `${rel}/` : rel);
120
+ if (e.isDirectory() && depth === 0)
121
+ walk(join(dir, e.name), depth + 1);
122
+ }
123
+ };
124
+ walk(root, 0);
125
+ return out;
126
+ }
127
+ /** Count source files by extension across the repo (bounded walk). */
128
+ function countSources(root, maxFiles = 5000) {
129
+ const counts = {};
130
+ let seen = 0;
131
+ const walk = (dir, depth) => {
132
+ if (seen >= maxFiles || depth > 6)
133
+ return;
134
+ let entries;
135
+ try {
136
+ entries = readdirSync(dir, { withFileTypes: true });
137
+ }
138
+ catch {
139
+ return;
140
+ }
141
+ for (const e of entries) {
142
+ if (seen >= maxFiles)
143
+ return;
144
+ if (e.isDirectory()) {
145
+ if (IGNORED_DIRS.has(e.name) || e.name.startsWith("."))
146
+ continue;
147
+ walk(join(dir, e.name), depth + 1);
148
+ }
149
+ else {
150
+ const m = e.name.match(SOURCE_EXT_RE);
151
+ if (m) {
152
+ seen++;
153
+ const ext = m[1];
154
+ counts[ext] = (counts[ext] ?? 0) + 1;
155
+ }
156
+ }
157
+ }
158
+ };
159
+ walk(root, 0);
160
+ return counts;
161
+ }
162
+ export function scanRepo(startPath) {
163
+ const root = findGitRoot(startPath) ?? startPath;
164
+ const scan = {
165
+ root,
166
+ name: basename(root),
167
+ manifests: [],
168
+ tree: shallowTree(root),
169
+ sources: countSources(root),
170
+ notables: NOTABLE_FILES.filter((f) => existsSync(join(root, f))),
171
+ };
172
+ const branch = gitExec(root, "rev-parse --abbrev-ref HEAD");
173
+ if (branch) {
174
+ scan.git = { branch };
175
+ const remote = gitExec(root, "config --get remote.origin.url");
176
+ if (remote)
177
+ scan.git.remote = remote;
178
+ }
179
+ for (const readmeName of ["README.md", "README.adoc", "README.rst", "README"]) {
180
+ const p = join(root, readmeName);
181
+ if (existsSync(p) && statSync(p).isFile()) {
182
+ scan.readme = { path: readmeName, excerpt: readExcerpt(p) };
183
+ break;
184
+ }
185
+ }
186
+ for (const [file, kind] of Object.entries(MANIFEST_FILES)) {
187
+ if (existsSync(join(root, file))) {
188
+ scan.manifests.push(summarizeManifest(root, file, kind));
189
+ }
190
+ }
191
+ return scan;
192
+ }
193
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/c4model-lib/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE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AC,CAAC,CAAC;KACjE,CAAC;IAEF,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;IAC5D,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,gCAAgC,CAAC,CAAC;QAC/D,IAAI,MAAM;YAAE,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACvC,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,CAAC,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9E,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjC,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5D,MAAM;QACR,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC1D,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Command } from "@axn-dev/core";
2
+ export declare class C4ModelCommand implements Command {
3
+ readonly name = "c4model";
4
+ readonly description = "C4 decomposition helpers for AI agents (scan, init, render)";
5
+ private static readonly SUBS;
6
+ private static readonly FLAGS;
7
+ complete(words: string[]): string[];
8
+ help(): string;
9
+ execute(args: string[]): Promise<void>;
10
+ private scan;
11
+ private init;
12
+ private renderCmd;
13
+ private readStdin;
14
+ }
15
+ //# sourceMappingURL=c4model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4model.d.ts","sourceRoot":"","sources":["../src/c4model.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA2B7C,qBAAa,cAAe,YAAW,OAAO;IAC5C,QAAQ,CAAC,IAAI,aAAa;IAC1B,QAAQ,CAAC,WAAW,iEAAiE;IAErF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAA8B;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAkF;IAE/G,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAQnC,IAAI,IAAI,MAAM;IAqCR,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAe5C,OAAO,CAAC,IAAI;YAYE,IAAI;IA6ClB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,SAAS;CASlB"}
@@ -0,0 +1,188 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { scanRepo } from "./c4model-lib/scan.js";
4
+ import { render, defaultWorkdir, slugify } from "./c4model-lib/render.js";
5
+ const LEVEL_STUBS = {
6
+ "01-context.md": `<!-- Level 1 — System Context.
7
+ Audience: everyone, including non-technical stakeholders.
8
+ Answer: What is this? Who uses it? Why does it exist? Which external systems does it touch?
9
+ Keep it to ~1 page of prose plus ONE Mermaid diagram (C4Context / flowchart). -->
10
+ `,
11
+ "02-containers.md": `<!-- Level 2 — Containers.
12
+ Audience: PMs with technical interest, architects.
13
+ Answer: Which applications, services, databases, and queues make up the solution?
14
+ Prose plus ONE Mermaid diagram (C4Container / flowchart). -->
15
+ `,
16
+ "03-components.md": `<!-- Level 3 — Components.
17
+ Audience: developers.
18
+ Answer: Which major modules, classes, or services live inside each container, and what are their responsibilities and interactions?
19
+ Prose plus ONE Mermaid diagram per container that matters. -->
20
+ `,
21
+ "04-code.md": `<!-- Level 4 — Code (optional, deepest zoom).
22
+ Audience: developers implementing or reviewing.
23
+ Answer: Key interfaces, data structures, and call paths. Reference real files with paths.
24
+ Small Mermaid class/sequence diagrams allowed. -->
25
+ `,
26
+ };
27
+ export class C4ModelCommand {
28
+ name = "c4model";
29
+ description = "C4 decomposition helpers for AI agents (scan, init, render)";
30
+ static SUBS = ["scan", "init", "render"];
31
+ static FLAGS = ["--repo", "--title", "--input", "--dir", "--format", "--out", "--help", "-h"];
32
+ complete(words) {
33
+ const cur = words[words.length - 1] ?? "";
34
+ if (words.length === 3) {
35
+ return C4ModelCommand.SUBS.filter((s) => s.startsWith(cur) && s !== cur);
36
+ }
37
+ return C4ModelCommand.FLAGS.filter((f) => f.startsWith(cur) && f !== cur);
38
+ }
39
+ help() {
40
+ return `
41
+ axn-dev c4model <subcommand> [options]
42
+
43
+ Deterministic helpers for the c4-decomposition skill. The skill (AI agent)
44
+ does the analysis; this command provides repo grounding and output rendering.
45
+
46
+ Subcommands:
47
+ scan Print JSON context about a repository (tree, manifests,
48
+ readme excerpt, source stats) for grounding diagrams
49
+ init Create a working directory with meta.yaml, input.md and
50
+ level stubs to fill in
51
+ render Assemble level files into final output (single file or
52
+ multi-file folder)
53
+
54
+ Options:
55
+ scan:
56
+ --repo <path> Repo path to scan (default: current directory)
57
+ init:
58
+ --title <text> Title of the requirement (required)
59
+ --input <file|-> Requirement text from a file, or '-' for stdin
60
+ --dir <path> Working directory (default: .axn-dev/c4model/<slug>)
61
+ render:
62
+ --dir <path> Working directory created by init (required)
63
+ --format <single|multi> Output format (default: single)
64
+ --out <path> Output file (single) or directory (multi).
65
+ Defaults to <dir>/c4-decomposition.md or <dir>/c4/
66
+ -h, --help Show this help
67
+
68
+ Examples:
69
+ axn-dev c4model scan --repo /path/to/repo
70
+ axn-dev c4model init --title "SSO login" --input ticket.md
71
+ axn-dev c4model init --title "SSO login" --input - < ticket.md
72
+ axn-dev c4model render --dir .axn-dev/c4model/sso-login --format multi --out docs/c4
73
+ `;
74
+ }
75
+ async execute(args) {
76
+ const [sub, ...rest] = args;
77
+ if (!sub || sub === "--help" || sub === "-h") {
78
+ console.log(this.help());
79
+ return;
80
+ }
81
+ switch (sub) {
82
+ case "scan": return this.scan(rest);
83
+ case "init": return this.init(rest);
84
+ case "render": return this.renderCmd(rest);
85
+ default:
86
+ throw new Error(`Unknown c4model subcommand: '${sub}'\nRun 'axn-dev c4model --help' for usage.`);
87
+ }
88
+ }
89
+ scan(args) {
90
+ let repo = process.cwd();
91
+ for (let i = 0; i < args.length; i++) {
92
+ const a = args[i];
93
+ if (a === "--repo")
94
+ repo = resolve(args[++i]);
95
+ else if (a === "--help" || a === "-h") {
96
+ console.log(this.help());
97
+ return;
98
+ }
99
+ else
100
+ throw new Error(`Unknown option: ${a}. Run 'axn-dev c4model --help'.`);
101
+ }
102
+ if (!existsSync(repo))
103
+ throw new Error(`Repo path does not exist: ${repo}`);
104
+ console.log(JSON.stringify(scanRepo(repo), null, 2));
105
+ }
106
+ async init(args) {
107
+ let title = null;
108
+ let input = null;
109
+ let dir = null;
110
+ for (let i = 0; i < args.length; i++) {
111
+ const a = args[i];
112
+ if (a === "--title")
113
+ title = args[++i];
114
+ else if (a === "--input")
115
+ input = args[++i];
116
+ else if (a === "--dir")
117
+ dir = resolve(args[++i]);
118
+ else if (a === "--help" || a === "-h") {
119
+ console.log(this.help());
120
+ return;
121
+ }
122
+ else
123
+ throw new Error(`Unknown option: ${a}. Run 'axn-dev c4model --help'.`);
124
+ }
125
+ if (!title)
126
+ throw new Error("Missing --title. Run 'axn-dev c4model --help'.");
127
+ const workdir = dir ?? defaultWorkdir(slugify(title));
128
+ mkdirSync(join(workdir, "levels"), { recursive: true });
129
+ writeFileSync(join(workdir, "meta.yaml"), `title: "${title.replace(/"/g, '\\"')}"\ndate: ${new Date().toISOString().slice(0, 10)}\n`, "utf-8");
130
+ if (input) {
131
+ const text = input === "-" ? await this.readStdin() : readFileSync(resolve(input), "utf-8");
132
+ writeFileSync(join(workdir, "input.md"), text, "utf-8");
133
+ }
134
+ else {
135
+ writeFileSync(join(workdir, "input.md"), `<!-- Paste the requirement / ticket text here. -->\n`, "utf-8");
136
+ }
137
+ for (const [file, stub] of Object.entries(LEVEL_STUBS)) {
138
+ const p = join(workdir, "levels", file);
139
+ if (!existsSync(p))
140
+ writeFileSync(p, stub, "utf-8");
141
+ }
142
+ console.log(`Working directory: ${workdir}`);
143
+ console.log(`\nNext steps:`);
144
+ console.log(` 1. Put the requirement text into ${join(workdir, "input.md")}`);
145
+ console.log(` 2. (Optional) run 'axn-dev c4model scan --repo <path>' to ground against a codebase`);
146
+ console.log(` 3. Fill in the level files in ${join(workdir, "levels")}/`);
147
+ console.log(` 4. Run 'axn-dev c4model render --dir ${workdir} --format single|multi [--out <path>]'`);
148
+ }
149
+ renderCmd(args) {
150
+ let dir = null;
151
+ let format = "single";
152
+ let out = "";
153
+ for (let i = 0; i < args.length; i++) {
154
+ const a = args[i];
155
+ if (a === "--dir")
156
+ dir = args[++i];
157
+ else if (a === "--format") {
158
+ const v = args[++i];
159
+ if (v !== "single" && v !== "multi")
160
+ throw new Error(`--format must be 'single' or 'multi', got '${v}'`);
161
+ format = v;
162
+ }
163
+ else if (a === "--out")
164
+ out = args[++i];
165
+ else if (a === "--help" || a === "-h") {
166
+ console.log(this.help());
167
+ return;
168
+ }
169
+ else
170
+ throw new Error(`Unknown option: ${a}. Run 'axn-dev c4model --help'.`);
171
+ }
172
+ if (!dir)
173
+ throw new Error("Missing --dir. Run 'axn-dev c4model --help'.");
174
+ const result = render(dir, format, out);
175
+ console.log(`Rendered ${result.format} output: ${result.output}`);
176
+ console.log(`Levels: ${result.levels.join(", ")}`);
177
+ }
178
+ readStdin() {
179
+ return new Promise((resolvePromise, reject) => {
180
+ let data = "";
181
+ process.stdin.setEncoding("utf-8");
182
+ process.stdin.on("data", (chunk) => (data += chunk));
183
+ process.stdin.on("end", () => resolvePromise(data));
184
+ process.stdin.on("error", reject);
185
+ });
186
+ }
187
+ }
188
+ //# sourceMappingURL=c4model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4model.js","sourceRoot":"","sources":["../src/c4model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAqB,MAAM,yBAAyB,CAAC;AAE7F,MAAM,WAAW,GAA2B;IAC1C,eAAe,EAAE;;;;CAIlB;IACC,kBAAkB,EAAE;;;;CAIrB;IACC,kBAAkB,EAAE;;;;CAIrB;IACC,YAAY,EAAE;;;;CAIf;CACA,CAAC;AAEF,MAAM,OAAO,cAAc;IAChB,IAAI,GAAG,SAAS,CAAC;IACjB,WAAW,GAAG,6DAA6D,CAAC;IAE7E,MAAM,CAAU,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClD,MAAM,CAAU,KAAK,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAE/G,QAAQ,CAAC,KAAe;QACtB,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACv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CAAC,CAAC;IACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Command } from "@axn-dev/core";
2
+ import { C4ModelCommand } from "./c4model.js";
3
+ export { C4ModelCommand };
4
+ export declare const commands: Command[];
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,eAAO,MAAM,QAAQ,EAAE,OAAO,EAA2B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { C4ModelCommand } from "./c4model.js";
2
+ export { C4ModelCommand };
3
+ export const commands = [new C4ModelCommand()];
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAc,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@axn-dev/cmd-c4model",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.2",
4
+ "description": "axn-dev c4model command — C4 decomposition helpers for AI agents (scan, init, render)",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "development": "./src/index.ts",
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist",
18
+ "skills"
19
+ ],
20
+ "axn-dev": {
21
+ "commands": [
22
+ {
23
+ "name": "c4model",
24
+ "description": "C4 decomposition helpers for AI agents (scan, init, render)",
25
+ "flags": [
26
+ "scan",
27
+ "init",
28
+ "render",
29
+ "--repo",
30
+ "--title",
31
+ "--input",
32
+ "--dir",
33
+ "--format",
34
+ "--out",
35
+ "--help",
36
+ "-h"
37
+ ]
38
+ }
39
+ ]
40
+ },
41
+ "license": "MIT",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "peerDependencies": {
46
+ "@axn-dev/core": "*"
47
+ },
48
+ "devDependencies": {
49
+ "@axn-dev/core": "0.1.2"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/astropiano/axn-dev.git",
54
+ "directory": "packages/cmd-c4model"
55
+ },
56
+ "homepage": "https://github.com/astropiano/axn-dev/tree/main/packages/cmd-c4model#readme",
57
+ "bugs": "https://github.com/astropiano/axn-dev/issues",
58
+ "scripts": {
59
+ "build": "tsc -b"
60
+ }
6
61
  }
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: c4-decomposition
3
+ description: Decompose a high-level requirement (freeform text, ticket, user story) into a C4 model — Mermaid diagrams plus prose at four zoom levels (Context → Containers → Components → Code). Produces either one Markdown document or a folder of per-level files, readable by both non-technical PMs and developers.
4
+ ---
5
+
6
+ # c4-decomposition Skill
7
+
8
+ Decompose a problem (*analysis* in the original Greek sense: breaking a whole into its parts) into a C4 model. The result is a set of Mermaid diagrams plus textual descriptions at four zoom levels — from "what is this and why" down to "which classes and call paths implement it". The zoom-in / zoom-out structure lets a non-technical PM and a developer read the same artifact at the altitude they need.
9
+
10
+ ## When to use this skill
11
+
12
+ - A JIRA ticket, requirement, or problem statement needs to be broken down before implementation.
13
+ - A PM or stakeholder needs a visual, zoomable explanation of a feature or problem.
14
+ - You want architecture documentation grounded in the real codebase rather than invented.
15
+
16
+ ## Division of labour
17
+
18
+ | Role | Responsibility |
19
+ |---|---|
20
+ | `axn-dev c4model` | Deterministic "hands": repo scanning, working-directory scaffolding, final rendering. |
21
+ | The agent (you) | The "brain": reading the requirement, analysis, writing prose and Mermaid diagrams per level. |
22
+
23
+ Never hand-generate the final document layout — write the level files and let `axn-dev c4model render` assemble them. This keeps `--format` a pure output decision the user can change without regenerating content.
24
+
25
+ ## Workflow
26
+
27
+ ```bash
28
+ # 1. Scaffold the working directory
29
+ axn-dev c4model init --title "SSO login for admin portal" --input ticket.md
30
+ # or: cat ticket.md | axn-dev c4model init --title "..." --input -
31
+ # or: axn-dev c4model init --title "..." # write input.md yourself
32
+
33
+ # 2. (Optional but recommended) ground against a codebase
34
+ axn-dev c4model scan --repo /path/to/repo > /tmp/scan.json
35
+ # Prints JSON: git info, README excerpt, manifests + dependency lists,
36
+ # shallow file tree, source file counts, notable infra files.
37
+
38
+ # 3. Analyse the requirement and write the four level files:
39
+ # <workdir>/levels/01-context.md
40
+ # <workdir>/levels/02-containers.md
41
+ # <workdir>/levels/03-components.md
42
+ # <workdir>/levels/04-code.md (optional — deepest zoom)
43
+
44
+ # 4. Render the final artifact in the user's chosen format
45
+ axn-dev c4model render --dir <workdir> --format single --out c4-decomposition.md
46
+ axn-dev c4model render --dir <workdir> --format multi --out docs/c4/
47
+ ```
48
+
49
+ The working directory defaults to `.axn-dev/c4model/<slug>/` inside the current project. If the user did not specify a format or output path, ask — or default to `single` and tell them both formats are available.
50
+
51
+ ## The four levels
52
+
53
+ Each level file is Markdown: a short prose section followed by **one** Mermaid diagram (more only where genuinely needed, e.g. one per container at level 3).
54
+
55
+ ### Level 1 — Context (`01-context.md`)
56
+
57
+ - **Audience**: everyone, including non-technical PMs.
58
+ - **Content**: the problem in plain language. Who is affected, what changes, which external systems are involved, why it matters. No jargon.
59
+ - **Diagram**: `C4Context` (or a plain `flowchart` with people/systems). Show actors, the system under discussion, and external systems only.
60
+
61
+ ### Level 2 — Containers (`02-containers.md`)
62
+
63
+ - **Audience**: PMs with technical interest, architects, new team members.
64
+ - **Content**: the running parts — apps, services, databases, queues, frontends. One short paragraph per container: what it does and which technology it uses.
65
+ - **Diagram**: `C4Container` (or `flowchart`). Containers, their protocols, and the data flows between them.
66
+
67
+ ### Level 3 — Components (`03-components.md`)
68
+
69
+ - **Audience**: developers.
70
+ - **Content**: the major modules/classes inside each relevant container, their responsibilities and interactions. Where the codebase was scanned, name real modules and paths.
71
+ - **Diagram**: `C4Component` (or `flowchart`), one per container that matters.
72
+
73
+ ### Level 4 — Code (`04-code.md`, optional)
74
+
75
+ - **Audience**: developers implementing or reviewing.
76
+ - **Content**: key interfaces, data structures, and call paths. Reference real files (`src/foo/bar.ts`). Skip this level when the requirement has no meaningful code-level detail yet.
77
+ - **Diagram**: small Mermaid `classDiagram` or `sequenceDiagram` if helpful.
78
+
79
+ ## Mermaid guidelines
80
+
81
+ - Prefer `C4Context` / `C4Container` / `C4Component` / `C4Dynamic` diagram types where the renderer supports them; fall back to `flowchart`, `sequenceDiagram`, or `classDiagram` — they render everywhere.
82
+ - Keep diagrams small enough to read: ≤ ~10 nodes per diagram. Split rather than cram.
83
+ - Label every relationship edge (`-->|uses HTTPS|`). Unlabeled arrows are worthless to non-technical readers.
84
+ - Validate syntax mentally before writing — a broken Mermaid block fails silently in most renderers.
85
+
86
+ ## Output formats (user-controlled)
87
+
88
+ - **`--format single`** → one `c4-decomposition.md` with a generated table of contents and each level as a `##` section. Best for pasting into Confluence/GitLab/MR descriptions.
89
+ - **`--format multi`** → a folder with `index.md` linking to `01-context.md` … `04-code.md`. Best for committing to a repo's `docs/` folder.
90
+
91
+ ## Common tasks (cookbook)
92
+
93
+ **"Decompose this ticket for the PM":**
94
+ ```bash
95
+ axn-dev c4model init --title "…" --input ticket.txt
96
+ # write levels — focus on Level 1 + 2 quality, keep Level 3 light, skip Level 4
97
+ axn-dev c4model render --dir <workdir> --format single --out c4-decomposition.md
98
+ ```
99
+
100
+ **"Grounded decomposition against this repo":**
101
+ ```bash
102
+ axn-dev c4model init --title "…" --input -
103
+ axn-dev c4model scan --repo . > /tmp/scan.json
104
+ # read scan.json, then inspect the specific files it surfaced before writing levels 2–4
105
+ axn-dev c4model render --dir <workdir> --format multi --out docs/c4/<slug>
106
+ ```
107
+
108
+ ## Gotchas
109
+
110
+ - `init` only scaffolds — it never writes diagram content. All analysis is yours.
111
+ - `render` requires at least one `levels/*.md` file; `04-code.md` is optional.
112
+ - Level files are sorted by C4 order (context → code), not alphabetically; keep the `NN-` numeric prefix.
113
+ - If the requirement is ambiguous, note open questions inside the level files rather than inventing answers — flag them clearly for the PM.
114
+ - `.axn-dev/` is a working directory; the rendered output is the artifact to commit or share.
115
+
116
+ ## Source files
117
+
118
+ - `axn-dev-cli/packages/cmd-c4model/src/c4model.ts` — subcommand router (`scan`, `init`, `render`)
119
+ - `axn-dev-cli/packages/cmd-c4model/src/c4model-lib/scan.ts` — repo context scanner (JSON output)
120
+ - `axn-dev-cli/packages/cmd-c4model/src/c4model-lib/render.ts` — level-file assembly into single/multi output
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.