codechart 0.1.2 → 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 (2) hide show
  1. package/dist/cli.js +48 -22
  2. package/package.json +1 -1
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
  }
@@ -2508,16 +2534,16 @@ async function readStdin() {
2508
2534
  return Buffer.concat(chunks).toString("utf8");
2509
2535
  }
2510
2536
  function readSpecFile(file) {
2511
- const fd = openSync(file, constants2.O_RDONLY | (constants2.O_NONBLOCK ?? 0));
2537
+ const fd = openSync2(file, constants3.O_RDONLY | (constants3.O_NONBLOCK ?? 0));
2512
2538
  try {
2513
- if (!fstatSync(fd).isFile()) throw new Error("not a regular file");
2539
+ if (!fstatSync2(fd).isFile()) throw new Error("not a regular file");
2514
2540
  const buf = Buffer.alloc(MAX_SPEC_BYTES + 1);
2515
2541
  let n = 0;
2516
- 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);
2517
2543
  if (n > MAX_SPEC_BYTES) throw new Error(TOO_BIG);
2518
2544
  return buf.toString("utf8", 0, n);
2519
2545
  } finally {
2520
- closeSync(fd);
2546
+ closeSync2(fd);
2521
2547
  }
2522
2548
  }
2523
2549
  function specOutput(config, ruleNames, diagram) {
@@ -2658,7 +2684,7 @@ function buildProgram(opts = {}) {
2658
2684
  const stdout = opts.stdout ?? ((s) => process.stdout.write(s));
2659
2685
  const rawStderr = opts.stderr ?? ((s) => process.stderr.write(s));
2660
2686
  const stderr = (s) => rawStderr(sanitizeText(s));
2661
- const program = new Command7().name("codechart").version("0.1.2");
2687
+ const program = new Command7().name("codechart").version("0.1.3");
2662
2688
  const cmdOpts = { ...opts, stdout, stderr };
2663
2689
  program.addCommand(checkCommand(cmdOpts));
2664
2690
  program.addCommand(renderCommand(cmdOpts));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codechart",
3
- "version": "0.1.2",
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",