codechart 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. package/README.md +30 -28
  2. package/dist/cli.js +88 -29
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <p align="center">
9
9
  <a href="https://www.npmjs.com/package/codechart"><img alt="npm" src="https://img.shields.io/npm/v/codechart"></a>
10
10
  <a href="https://github.com/freeleex/codechart/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/freeleex/codechart/actions/workflows/ci.yml/badge.svg"></a>
11
- <img alt="Node >= 22.12" src="https://img.shields.io/badge/node-%3E%3D22.12-339933">
11
+ <img alt="Node 22.12+" src="https://img.shields.io/badge/node-%3E%3D22.12-339933">
12
12
  <a href="LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-blue"></a>
13
13
  </p>
14
14
 
@@ -63,6 +63,33 @@ New things are `+`, changed ones `~`, existing ones `·`, config `◆`. Layers a
63
63
 
64
64
  ![Full map: clicking the orders table shows its file and changed fields](docs/images/map.png)
65
65
 
66
+ Ask how something works and you get a **flow** instead. Every step points at the code that implements it:
67
+
68
+ ```text
69
+ Flow (key: + new ~ changed ? planned ◇ decision ⤷ shared step)
70
+
71
+ Accept a team invite
72
+ ────────────────────
73
+ +look up invite by token
74
+ ◇ +invite found?
75
+ ├─ no → +404 invite not found
76
+ └─ yes → ◇ +expired?
77
+ ├─ yes → +410 invite expired
78
+ └─ no → ◇ +already a member?
79
+ ├─ yes → +return already a member
80
+ └─ no → +save membership → +return joined
81
+
82
+ 9 steps · 9 new · 0 changed · 0 planned
83
+ gaps: did not check what happens when two requests accept the same invite at
84
+ once
85
+
86
+ Open full map
87
+ ```
88
+
89
+ Its full page shows the exact code behind each step. Click any step:
90
+
91
+ ![Full flow: clicking a decision shows its source lines](docs/images/flow.png)
92
+
66
93
  You don't need to ask for it. The skill fires when the agent summarizes changes, writes a plan, or explains how code behaves, and stays quiet for typo fixes.
67
94
 
68
95
  ## Install
@@ -91,32 +118,7 @@ Tables, columns, enums, models, endpoints, components, config and env vars, grou
91
118
 
92
119
  ### Flows: what the code actually does
93
120
 
94
- Decisions, edge cases and outcomes, each pointing at the source lines that implement it.
95
-
96
- ```text
97
- Flow (key: + new ~ changed ? planned ◇ decision ⤷ shared step)
98
-
99
- Accept a team invite
100
- ────────────────────
101
- +look up invite by token
102
- ◇ +invite found?
103
- ├─ no → +404 invite not found
104
- └─ yes → ◇ +expired?
105
- ├─ yes → +410 invite expired
106
- └─ no → ◇ +already a member?
107
- ├─ yes → +return already a member
108
- └─ no → +save membership → +return joined
109
-
110
- 9 steps · 9 new · 0 changed · 0 planned
111
- gaps: did not check what happens when two requests accept the same invite at
112
- once
113
-
114
- Open full map
115
- ```
116
-
117
- Its full page shows each step's exact code:
118
-
119
- ![Full flow: clicking a decision shows its source lines](docs/images/flow.png)
121
+ Decisions, edge cases and outcomes, each pointing at the source lines that implement it. Branches the agent didn't verify go under `gaps` instead of being drawn.
120
122
 
121
123
  ### Terminal first, page when it helps
122
124
 
@@ -212,7 +214,7 @@ Not because of codechart. It makes no network calls. The diagram is built from w
212
214
  `~/.cache/codechart`. It keeps the newest 20 per repo, plus anything under 7 days old.
213
215
 
214
216
  **I use VS Code, Cursor, Windsurf or Antigravity, and "Open full map" shows HTML source.**
215
- Those editors open file links as text. codechart detects them and opens new pages in your browser instead. Turn it off with `web.open: never` in `~/.config/codechart/config.yaml`.
217
+ Those editors open file links as text. codechart detects them and opens new pages in your browser instead. Where the editor doesn't allow that (Antigravity sandboxes agent commands), the reply includes the page's address to paste into your browser. Turn auto-open off with `web.open: never` in `~/.config/codechart/config.yaml`.
216
218
 
217
219
  ## License
218
220
 
package/dist/cli.js CHANGED
@@ -8,11 +8,27 @@ import path2 from "path";
8
8
  import { Command } from "commander";
9
9
 
10
10
  // src/config/load.ts
11
- import { existsSync, readFileSync, realpathSync, statSync } from "fs";
11
+ import { existsSync, realpathSync } from "fs";
12
12
  import { homedir } from "os";
13
13
  import { dirname, isAbsolute, join, relative, resolve, sep } from "path";
14
14
  import { parse } from "yaml";
15
15
 
16
+ // src/read-regular.ts
17
+ import { closeSync, constants, fstatSync, openSync, readSync } from "fs";
18
+ function readRegularFile(path3, accept) {
19
+ const fd = openSync(path3, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0) | (constants.O_NOFOLLOW ?? 0));
20
+ try {
21
+ const st = fstatSync(fd);
22
+ if (!accept(st)) return void 0;
23
+ const buf = Buffer.alloc(st.size);
24
+ let n = 0;
25
+ for (let r = 1; r > 0 && n < buf.length; n += r) r = readSync(fd, buf, n, buf.length - n, null);
26
+ return buf.toString("utf8", 0, n);
27
+ } finally {
28
+ closeSync(fd);
29
+ }
30
+ }
31
+
16
32
  // src/config/builtin-rules.ts
17
33
  var MAP_RULES = [
18
34
  {
@@ -185,18 +201,25 @@ function findRepoRoot(cwd) {
185
201
  }
186
202
  }
187
203
  function readConfigFile(file, root) {
188
- if (!existsSync(file)) return void 0;
189
- const real = realpathSync(file);
204
+ let real;
205
+ try {
206
+ real = realpathSync(file);
207
+ } catch (e) {
208
+ if (e.code === "ENOENT") return void 0;
209
+ throw e;
210
+ }
190
211
  if (root !== void 0) {
191
212
  const rel = relative(realpathSync(root), real);
192
213
  if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw new Error(`${file}: resolves outside the repo`);
193
214
  }
194
- const st = statSync(real);
195
- if (!st.isFile()) throw new Error(`${file}: not a regular file`);
196
- if (st.size > MAX_BYTES) throw new Error(`${file}: too large (over 1 MB)`);
215
+ const text = readRegularFile(real, (st) => {
216
+ if (!st.isFile()) throw new Error(`${file}: not a regular file`);
217
+ if (st.size > MAX_BYTES) throw new Error(`${file}: too large (over 1 MB)`);
218
+ return true;
219
+ });
197
220
  let raw;
198
221
  try {
199
- raw = parse(readFileSync(real, "utf8"));
222
+ raw = parse(text);
200
223
  } catch (e) {
201
224
  throw new Error(`${file}: ${e.message.split("\n")[0]}`);
202
225
  }
@@ -742,7 +765,7 @@ function packageFile(relative3) {
742
765
  }
743
766
 
744
767
  // src/commands/copy-file.ts
745
- import { constants, copyFileSync, existsSync as existsSync4, lstatSync, mkdirSync, unlinkSync } from "fs";
768
+ import { constants as constants2, copyFileSync, existsSync as existsSync4, lstatSync, mkdirSync, unlinkSync } from "fs";
746
769
  import { dirname as dirname3 } from "path";
747
770
  var isSymlink = (path3) => lstatSync(path3, { throwIfNoEntry: false })?.isSymbolicLink() === true;
748
771
  function copyFiles(pairs, force, opts) {
@@ -764,7 +787,7 @@ function copyFiles(pairs, force, opts) {
764
787
  for (const { source, target } of pairs) {
765
788
  mkdirSync(dirname3(target), { recursive: true });
766
789
  if (force && isSymlink(target)) unlinkSync(target);
767
- copyFileSync(source, target, force ? 0 : constants.COPYFILE_EXCL);
790
+ copyFileSync(source, target, force ? 0 : constants2.COPYFILE_EXCL);
768
791
  opts.stdout(`wrote ${target}
769
792
  `);
770
793
  }
@@ -965,12 +988,12 @@ function installSkillCommand(opts) {
965
988
  }
966
989
 
967
990
  // src/commands/render.ts
968
- import { chmodSync, constants as constants2, closeSync, fstatSync, lstatSync as lstatSync4, mkdirSync as mkdirSync2, openSync, readSync, writeFileSync } from "fs";
991
+ import { chmodSync, constants as constants3, closeSync as closeSync2, fstatSync as fstatSync2, lstatSync as lstatSync4, mkdirSync as mkdirSync2, openSync as openSync2, readSync as readSync2, writeFileSync } from "fs";
969
992
  import { basename as basename2, dirname as dirname4, resolve as resolve6 } from "path";
970
993
  import { Command as Command5, Option } from "commander";
971
994
 
972
995
  // src/render/flow/anchors.ts
973
- import { readFileSync as readFileSync2, realpathSync as realpathSync2, statSync as statSync2 } from "fs";
996
+ import { realpathSync as realpathSync2 } from "fs";
974
997
  import { isAbsolute as isAbsolute2, relative as relative2, resolve as resolve3, sep as sep2 } from "path";
975
998
  var SNIPPET_MAX_LINES = 15;
976
999
  var MAX_BYTES2 = 5 * 1024 * 1024;
@@ -1008,12 +1031,15 @@ function readLines(path3, root, realRoot, budget) {
1008
1031
  if (escapes(rel)) return { error: `${path3} is outside the repo` };
1009
1032
  if (inGit(rel)) return { error: `${path3} is inside .git` };
1010
1033
  try {
1011
- const st = statSync2(real);
1012
- if (!st.isFile()) return { error: `${path3} is not a regular file` };
1013
- if (st.size > MAX_BYTES2) return { error: `${path3} is too large (over 5 MB)` };
1014
- if (st.size > budget.left) return overBudget(path3);
1015
- budget.left -= st.size;
1016
- return toLines(readFileSync2(real, "utf8"));
1034
+ let refused;
1035
+ const text = readRegularFile(real, (st) => {
1036
+ if (!st.isFile()) refused = { error: `${path3} is not a regular file` };
1037
+ else if (st.size > MAX_BYTES2) refused = { error: `${path3} is too large (over 5 MB)` };
1038
+ else if (st.size > budget.left) refused = overBudget(path3);
1039
+ else budget.left -= st.size;
1040
+ return refused === void 0;
1041
+ });
1042
+ return refused ?? toLines(text);
1017
1043
  } catch (e) {
1018
1044
  return { error: `${path3} cannot be read (${e.code})` };
1019
1045
  }
@@ -1152,6 +1178,18 @@ ${fence}`);
1152
1178
  return `${lines.join("\n")}
1153
1179
  `;
1154
1180
  }
1181
+ function openBlockedNote(htmlPath, md) {
1182
+ const href = pathToFileURL(resolve4(htmlPath)).href;
1183
+ const say = "Your editor didn't let codechart open the page. Paste this into your browser's address bar:";
1184
+ return md ? `${say}
1185
+
1186
+ \`\`\`text
1187
+ ${href}
1188
+ \`\`\`
1189
+ ` : `${say}
1190
+ ${href}
1191
+ `;
1192
+ }
1155
1193
 
1156
1194
  // src/render/output-path.ts
1157
1195
  import { createHash } from "crypto";
@@ -2022,7 +2060,7 @@ function specJsonSchema() {
2022
2060
  }
2023
2061
 
2024
2062
  // src/commands/open.ts
2025
- import { spawn } from "child_process";
2063
+ import { spawn, spawnSync } from "child_process";
2026
2064
  import { win32 as win322 } from "path";
2027
2065
  function openArgv(platform, file, env = process.env) {
2028
2066
  if (platform === "darwin") return ["open", [file]];
@@ -2034,12 +2072,22 @@ function openArgv(platform, file, env = process.env) {
2034
2072
  function inCodeEditor(env) {
2035
2073
  return Boolean(env.VSCODE_PID) || env.TERM_PROGRAM === "vscode";
2036
2074
  }
2037
- function openInBrowser(file) {
2038
- const [cmd, args] = openArgv(process.platform, file);
2075
+ function openInBrowser(file, { platform = process.platform, run = spawnSync, detach = spawn } = {}) {
2076
+ const [cmd, args] = openArgv(platform, file);
2039
2077
  try {
2040
- spawn(cmd, args, { detached: true, stdio: "ignore" }).on("error", () => {
2041
- }).unref();
2042
- } catch {
2078
+ if (platform === "linux") {
2079
+ detach(cmd, args, { detached: true, stdio: "ignore" }).on("error", () => {
2080
+ }).unref();
2081
+ return void 0;
2082
+ }
2083
+ const r = run(cmd, args, { stdio: ["ignore", "ignore", "pipe"], timeout: 1e4, encoding: "utf8" });
2084
+ if (r.error?.code === "ETIMEDOUT") return void 0;
2085
+ if (r.error) return r.error.message;
2086
+ if (r.status === 0) return void 0;
2087
+ const why = (r.stderr ?? "").trim().split("\n")[0]?.slice(0, 200);
2088
+ return `${cmd} exited with ${r.status ?? r.signal}${why ? `: ${why}` : ""}`;
2089
+ } catch (e) {
2090
+ return e.message;
2043
2091
  }
2044
2092
  }
2045
2093
 
@@ -2486,16 +2534,16 @@ async function readStdin() {
2486
2534
  return Buffer.concat(chunks).toString("utf8");
2487
2535
  }
2488
2536
  function readSpecFile(file) {
2489
- const fd = openSync(file, constants2.O_RDONLY | (constants2.O_NONBLOCK ?? 0));
2537
+ const fd = openSync2(file, constants3.O_RDONLY | (constants3.O_NONBLOCK ?? 0));
2490
2538
  try {
2491
- if (!fstatSync(fd).isFile()) throw new Error("not a regular file");
2539
+ if (!fstatSync2(fd).isFile()) throw new Error("not a regular file");
2492
2540
  const buf = Buffer.alloc(MAX_SPEC_BYTES + 1);
2493
2541
  let n = 0;
2494
- for (let r = 1; r > 0 && n < buf.length; n += r) r = readSync(fd, buf, n, buf.length - n, null);
2542
+ for (let r = 1; r > 0 && n < buf.length; n += r) r = readSync2(fd, buf, n, buf.length - n, null);
2495
2543
  if (n > MAX_SPEC_BYTES) throw new Error(TOO_BIG);
2496
2544
  return buf.toString("utf8", 0, n);
2497
2545
  } finally {
2498
- closeSync(fd);
2546
+ closeSync2(fd);
2499
2547
  }
2500
2548
  }
2501
2549
  function specOutput(config, ruleNames, diagram) {
@@ -2563,6 +2611,8 @@ function renderCommand(opts) {
2563
2611
  const print = (text) => opts.stdout(o.md ? `${text}
2564
2612
  ` : text);
2565
2613
  const slug = fileSlug(spec.title, diagram);
2614
+ let blocked;
2615
+ const printBlocked = () => blocked && print(openBlockedNote(blocked, o.md === true));
2566
2616
  const writeHtml = async (build) => {
2567
2617
  const now = opts.now?.() ?? /* @__PURE__ */ new Date();
2568
2618
  const file = htmlOutputPath(config, repoFolder(root), slug, now);
@@ -2575,12 +2625,20 @@ function renderCommand(opts) {
2575
2625
  writeFileSync(file, html, { mode: 384 });
2576
2626
  pruneHtml(dirname4(file), { ...config.web, now, replaceSlug: slug });
2577
2627
  const mode = config.web.open;
2578
- if (o.open || mode === "always" || mode === "auto" && inCodeEditor(opts.env ?? process.env)) (opts.open ?? openInBrowser)(file);
2628
+ if (o.open || mode === "always" || mode === "auto" && inCodeEditor(opts.env ?? process.env)) {
2629
+ const failed = (opts.open ?? openInBrowser)(file);
2630
+ if (failed) {
2631
+ opts.stderr(`codechart: could not open the browser (${failed})
2632
+ `);
2633
+ blocked = file;
2634
+ }
2635
+ }
2579
2636
  return file;
2580
2637
  };
2581
2638
  if (spec.diagram === "flow") {
2582
2639
  const tree = { maxNodes, width, color, md: o.md };
2583
2640
  print(await renderFlow(spec, snippets, { output, minNodes: config.web.minNodes, tree, writeHtml }));
2641
+ printBlocked();
2584
2642
  return;
2585
2643
  }
2586
2644
  const { hidden } = selectTerminalNodes(spec, maxNodes);
@@ -2601,6 +2659,7 @@ function renderCommand(opts) {
2601
2659
  if (o.md) print(markdown(map, htmlPath));
2602
2660
  else print(map ?? `${fullMapLine(htmlPath)}
2603
2661
  `);
2662
+ printBlocked();
2604
2663
  } catch (e) {
2605
2664
  const message = e instanceof Error ? e.message : String(e);
2606
2665
  const lines = e instanceof InvalidSpec ? e.errors : message.split("\n").map((l) => `codechart: ${l}`);
@@ -2625,7 +2684,7 @@ function buildProgram(opts = {}) {
2625
2684
  const stdout = opts.stdout ?? ((s) => process.stdout.write(s));
2626
2685
  const rawStderr = opts.stderr ?? ((s) => process.stderr.write(s));
2627
2686
  const stderr = (s) => rawStderr(sanitizeText(s));
2628
- const program = new Command7().name("codechart").version("0.1.1");
2687
+ const program = new Command7().name("codechart").version("0.1.3");
2629
2688
  const cmdOpts = { ...opts, stdout, stderr };
2630
2689
  program.addCommand(checkCommand(cmdOpts));
2631
2690
  program.addCommand(renderCommand(cmdOpts));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codechart",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Agent skill + CLI: maps and flowcharts of code changes for AI coding agents, in terminal, chat and HTML",
5
5
  "keywords": [
6
6
  "agent-skills",