speckeeper 0.19.4 → 0.19.6

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/cli-contract.yaml CHANGED
@@ -3,7 +3,7 @@ cli_contracts: 0.1.0
3
3
 
4
4
  info:
5
5
  title: speckeeper CLI
6
- version: 0.19.4
6
+ version: 0.19.6
7
7
  description: >-
8
8
  TypeScript-first specification validation framework — validate design
9
9
  consistency, external SSOT integrity, and traceability with type-safe
package/dist/dsl/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { readFileSync } from 'fs';
3
- import { join, isAbsolute } from 'path';
4
- import { glob } from 'glob';
2
+ import { readFileSync, readdirSync, lstatSync, statSync } from 'fs';
3
+ import { join, isAbsolute, resolve, posix } from 'path';
5
4
  import { parse } from 'yaml';
6
5
 
7
6
  var __create = Object.create;
@@ -45014,13 +45013,256 @@ function markdownExporter(config) {
45014
45013
  }
45015
45014
  return exporter;
45016
45015
  }
45017
-
45018
- // src/core/paths.ts
45019
- function toPosixPath(filePath) {
45020
- return filePath.replace(/\\/g, "/");
45016
+ function globSync(pattern, options = {}) {
45017
+ const cwd = resolve(options.cwd ?? process.cwd());
45018
+ const ignore = (options.ignore ?? []).flatMap(expandBraces).map(compileIgnore);
45019
+ const found = /* @__PURE__ */ new Set();
45020
+ for (const expanded of expandBraces(pattern)) {
45021
+ const { root, segments, dirOnly } = splitPattern(expanded);
45022
+ if (segments.length === 0) continue;
45023
+ new Walker(segments, dirOnly, ignore, root !== "" || options.absolute === true, cwd, found).start(root === "" ? cwd : root, root);
45024
+ }
45025
+ return [...found].sort();
45026
+ }
45027
+ var NOCASE = process.platform === "darwin" || process.platform === "win32";
45028
+ function unsupported(pattern, what) {
45029
+ throw new Error(`Unsupported glob syntax in "${pattern}": ${what}`);
45030
+ }
45031
+ function expandBraces(pattern) {
45032
+ if (pattern.includes("\\")) unsupported(pattern, '"\\" escapes');
45033
+ if (/[@!+?*]\(/.test(pattern)) unsupported(pattern, "extended glob");
45034
+ for (let open = pattern.indexOf("{"); open !== -1; open = pattern.indexOf("{", open + 1)) {
45035
+ let depth = 0;
45036
+ const commas = [];
45037
+ let close = -1;
45038
+ for (let i = open; i < pattern.length; i++) {
45039
+ const c2 = pattern[i];
45040
+ if (c2 === "{") depth++;
45041
+ else if (c2 === "}" && --depth === 0) {
45042
+ close = i;
45043
+ break;
45044
+ } else if (c2 === "," && depth === 1) commas.push(i);
45045
+ }
45046
+ if (close === -1) return [pattern];
45047
+ const body = pattern.slice(open + 1, close);
45048
+ if (commas.length === 0) {
45049
+ if (/^(-?\d+|[A-Za-z])\.\.(-?\d+|[A-Za-z])(\.\.-?\d+)?$/.test(body)) {
45050
+ unsupported(pattern, `brace range "{${body}}"`);
45051
+ }
45052
+ continue;
45053
+ }
45054
+ const head = pattern.slice(0, open);
45055
+ const tail = pattern.slice(close + 1);
45056
+ const bounds = [open, ...commas, close];
45057
+ const alternatives = [];
45058
+ for (let k = 0; k < bounds.length - 1; k++) {
45059
+ alternatives.push(pattern.slice(bounds[k] + 1, bounds[k + 1]));
45060
+ }
45061
+ return alternatives.flatMap((alt) => expandBraces(head + alt + tail));
45062
+ }
45063
+ return [pattern];
45064
+ }
45065
+ function splitPattern(pattern) {
45066
+ const absolute = isAbsolute(pattern);
45067
+ const parts = pattern.split("/");
45068
+ let root = "";
45069
+ if (absolute) {
45070
+ root = parts[0] === "" ? "/" : `${parts[0]}/`;
45071
+ parts.shift();
45072
+ }
45073
+ while (parts.length > 1 && parts[0] === ".") parts.shift();
45074
+ const dirOnly = parts.length > 1 && parts[parts.length - 1] === "";
45075
+ const segments = parts.filter((p, i) => p !== "" || i === 0).filter((p) => p !== "");
45076
+ const collapsed = segments.filter((s, i) => !(s === "**" && segments[i - 1] === "**"));
45077
+ return { root, segments: collapsed, dirOnly };
45078
+ }
45079
+ var MAGIC = /[*?[]/;
45080
+ var segmentCache = /* @__PURE__ */ new Map();
45081
+ function matchSegment(name2, segment, dot) {
45082
+ if (!MAGIC.test(segment)) return NOCASE ? name2.toLowerCase() === segment.toLowerCase() : name2 === segment;
45083
+ if (name2 === "." || name2 === "..") return false;
45084
+ if (!dot && name2.startsWith(".") && !segment.startsWith(".")) return false;
45085
+ let re = segmentCache.get(segment);
45086
+ if (!re) {
45087
+ re = new RegExp(`^${segmentSource(segment)}$`, NOCASE ? "i" : "");
45088
+ segmentCache.set(segment, re);
45089
+ }
45090
+ return re.test(name2);
45021
45091
  }
45022
- function toPosixPaths(filePaths) {
45023
- return filePaths.map(toPosixPath);
45092
+ function segmentSource(segment) {
45093
+ let out = "";
45094
+ for (let i = 0; i < segment.length; i++) {
45095
+ const c2 = segment[i];
45096
+ if (c2 === "*") {
45097
+ out += "[^/]*";
45098
+ } else if (c2 === "?") {
45099
+ out += "[^/]";
45100
+ } else if (c2 === "[") {
45101
+ const end = segment.indexOf("]", i + 2);
45102
+ if (end === -1) {
45103
+ out += "\\[";
45104
+ continue;
45105
+ }
45106
+ let set = segment.slice(i + 1, end);
45107
+ const negate = set.startsWith("!") || set.startsWith("^");
45108
+ if (negate) set = set.slice(1);
45109
+ out += `[${negate ? "^" : ""}${set.replace(/[\]\\^]/g, (m) => `\\${m}`)}]`;
45110
+ i = end;
45111
+ } else {
45112
+ out += c2.replace(/[.+^${}()|\]\\]/g, (m) => `\\${m}`);
45113
+ }
45114
+ }
45115
+ return out;
45116
+ }
45117
+ function matchPath(segments, path, dot) {
45118
+ const memo = /* @__PURE__ */ new Map();
45119
+ const go = (s, p) => {
45120
+ const key = `${s}:${p}`;
45121
+ const hit = memo.get(key);
45122
+ if (hit !== void 0) return hit;
45123
+ let result;
45124
+ if (s === segments.length) {
45125
+ result = p === path.length;
45126
+ } else if (segments[s] === "**") {
45127
+ result = go(s + 1, p) || p < path.length && path[p] !== "." && path[p] !== ".." && (dot) && go(s, p + 1);
45128
+ } else {
45129
+ result = p < path.length && matchSegment(path[p], segments[s], dot) && go(s + 1, p + 1);
45130
+ }
45131
+ memo.set(key, result);
45132
+ return result;
45133
+ };
45134
+ return go(0, 0);
45135
+ }
45136
+ function compileIgnore(pattern) {
45137
+ const { root, segments } = splitPattern(pattern);
45138
+ const rootSegments = root === "" || root === "/" ? [] : [root.replace(/\/$/, "")];
45139
+ return {
45140
+ absolute: root !== "",
45141
+ segments: [...rootSegments, ...segments],
45142
+ children: segments[segments.length - 1] === "**"
45143
+ };
45144
+ }
45145
+ function toPosix(p) {
45146
+ return p.replace(/\\/g, "/");
45147
+ }
45148
+ function joinPath(prefix, name2) {
45149
+ if (prefix === "") return name2;
45150
+ return prefix.endsWith("/") ? prefix + name2 : `${prefix}/${name2}`;
45151
+ }
45152
+ var Walker = class {
45153
+ constructor(segments, dirOnly, ignore, absoluteResults, cwd, found) {
45154
+ this.segments = segments;
45155
+ this.dirOnly = dirOnly;
45156
+ this.ignore = ignore;
45157
+ this.absoluteResults = absoluteResults;
45158
+ this.found = found;
45159
+ this.cwdPosix = toPosix(cwd);
45160
+ const firstMagic = segments.findIndex((s) => s === "**" || MAGIC.test(s));
45161
+ this.prefixLength = firstMagic === -1 ? segments.length : firstMagic;
45162
+ }
45163
+ segments;
45164
+ dirOnly;
45165
+ ignore;
45166
+ absoluteResults;
45167
+ found;
45168
+ cwdPosix;
45169
+ /** Number of leading literal segments: the part of the pattern that names a fixed path. */
45170
+ prefixLength;
45171
+ /** Positions `**` lets the path also stand at: a `**` may match no directory. */
45172
+ close(positions) {
45173
+ const closed = /* @__PURE__ */ new Set();
45174
+ for (let i of positions) {
45175
+ closed.add(i);
45176
+ while (this.segments[i] === "**") closed.add(++i);
45177
+ }
45178
+ return [...closed];
45179
+ }
45180
+ /** Expands the pattern from its root (`output` is '' for a relative pattern). */
45181
+ start(root, output) {
45182
+ if (this.close([0]).includes(this.segments.length)) {
45183
+ this.add(output === "" ? "." : output);
45184
+ }
45185
+ this.walk(root, output, [0]);
45186
+ }
45187
+ add(output) {
45188
+ const absolute = posix.resolve(this.cwdPosix, output);
45189
+ this.found.add(this.absoluteResults ? absolute : posix.relative(this.cwdPosix, absolute) || ".");
45190
+ }
45191
+ /**
45192
+ * `dir` is the directory on disk, `output` the path it is reported as, and
45193
+ * `positions` the pattern segments that path stands before.
45194
+ */
45195
+ walk(dir, output, positions) {
45196
+ const end = this.segments.length;
45197
+ const pending = this.close(positions).filter((p) => p < end);
45198
+ if (pending.length === 0) return;
45199
+ const literalOnly = pending.every((p) => !MAGIC.test(this.segments[p]) && this.segments[p] !== "**");
45200
+ const entries = literalOnly ? this.literalEntries(dir, pending) : this.listEntries(dir);
45201
+ for (const entry of entries) {
45202
+ const viaSegment = [];
45203
+ const viaGlobstar = [];
45204
+ for (const p of pending) {
45205
+ const segment = this.segments[p];
45206
+ if (segment === "**") {
45207
+ if (!entry.name.startsWith(".")) viaGlobstar.push(p);
45208
+ } else if (matchSegment(entry.name, segment, false)) {
45209
+ viaSegment.push(p);
45210
+ }
45211
+ }
45212
+ if (viaSegment.length === 0 && viaGlobstar.length === 0) continue;
45213
+ const childDir = joinPath(dir, entry.name);
45214
+ const childOutput = joinPath(output, entry.name);
45215
+ const absolute = posix.resolve(this.cwdPosix, childOutput);
45216
+ const rel = (posix.relative(this.cwdPosix, absolute) || ".").split("/");
45217
+ const abs = absolute.split("/").filter(Boolean);
45218
+ const hits = this.ignore.filter((ig) => matchPath(ig.segments, ig.absolute ? abs : rel, true));
45219
+ const onTheWay = viaGlobstar.length === 0 && viaSegment.every((p) => p < this.prefixLength - 1);
45220
+ const byName = !this.dirOnly || entry.isDir || entry.isLink;
45221
+ const completes = viaSegment.some((p) => p + 1 === end && byName) || viaSegment.some((p) => p + 1 < end && this.close([p + 1]).includes(end) && byName && (entry.isDir || entry.isLink || p < this.prefixLength)) || viaGlobstar.some((p) => this.close([p]).includes(end) && (!this.dirOnly || entry.isDir && !entry.isLink));
45222
+ if (completes && hits.length === 0) this.add(childOutput);
45223
+ if (!entry.isDir || !onTheWay && hits.some((ig) => ig.children)) continue;
45224
+ const descend = entry.isLink ? [...viaSegment.map((p) => p + 1), ...viaGlobstar.filter((p) => p > 0).map((p) => p + 1)] : [...viaSegment.map((p) => p + 1), ...viaGlobstar];
45225
+ if (descend.length > 0) this.walk(childDir, childOutput, descend);
45226
+ }
45227
+ }
45228
+ listEntries(dir) {
45229
+ let dirents;
45230
+ try {
45231
+ dirents = readdirSync(dir, { withFileTypes: true });
45232
+ } catch {
45233
+ return [];
45234
+ }
45235
+ return dirents.map((d) => ({
45236
+ name: d.name,
45237
+ isLink: d.isSymbolicLink(),
45238
+ isDir: d.isSymbolicLink() ? isDirectory(joinPath(dir, d.name)) : d.isDirectory()
45239
+ }));
45240
+ }
45241
+ literalEntries(dir, pending) {
45242
+ const entries = [];
45243
+ for (const name2 of new Set(pending.map((p) => this.segments[p]))) {
45244
+ const path = joinPath(dir, name2);
45245
+ let link;
45246
+ try {
45247
+ link = lstatSync(path);
45248
+ } catch {
45249
+ continue;
45250
+ }
45251
+ entries.push({
45252
+ name: name2,
45253
+ isLink: link.isSymbolicLink(),
45254
+ isDir: link.isSymbolicLink() ? isDirectory(path) : link.isDirectory()
45255
+ });
45256
+ }
45257
+ return entries;
45258
+ }
45259
+ };
45260
+ function isDirectory(path) {
45261
+ try {
45262
+ return statSync(path).isDirectory();
45263
+ } catch {
45264
+ return false;
45265
+ }
45024
45266
  }
45025
45267
 
45026
45268
  // src/core/dsl/checkers.ts
@@ -45063,10 +45305,10 @@ function annotationCoverage(config) {
45063
45305
  }
45064
45306
  const allFiles = /* @__PURE__ */ new Set();
45065
45307
  for (const pattern of artifactConfig.globs) {
45066
- const found = toPosixPaths(glob.sync(pattern, {
45308
+ const found = globSync(pattern, {
45067
45309
  cwd: basePath,
45068
45310
  ignore: artifactConfig.exclude ?? []
45069
- }));
45311
+ });
45070
45312
  for (const f of found) {
45071
45313
  allFiles.add(f);
45072
45314
  }
@@ -45155,7 +45397,7 @@ function relationCoverage(config) {
45155
45397
  };
45156
45398
  }
45157
45399
  function findTestFiles(path, basePath) {
45158
- return toPosixPaths(glob.sync(path, { cwd: basePath })).sort();
45400
+ return globSync(path, { cwd: basePath });
45159
45401
  }
45160
45402
  function specIdsNamedIn(content, specIds) {
45161
45403
  const named = /* @__PURE__ */ new Set();
@@ -45587,10 +45829,10 @@ function runGlobalScan(sources, specIds, basePath, lookupKeyMap) {
45587
45829
  const keysToSearch = Array.from(keyToSpecId.keys());
45588
45830
  const allFiles = /* @__PURE__ */ new Set();
45589
45831
  for (const pattern of source.paths) {
45590
- const found = toPosixPaths(glob.sync(pattern, {
45832
+ const found = globSync(pattern, {
45591
45833
  cwd,
45592
45834
  ignore: source.exclude ?? []
45593
- }));
45835
+ });
45594
45836
  if (found.length === 0) {
45595
45837
  diagnostics.push({
45596
45838
  severity: "error",
package/dist/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { readFileSync, readdirSync, statSync, existsSync, mkdirSync, writeFileSync } from 'fs';
3
- import { extname, join, dirname, resolve } from 'path';
2
+ import { readFileSync, readdirSync, statSync, existsSync, mkdirSync, writeFileSync, lstatSync } from 'fs';
3
+ import { extname, join, dirname, resolve, isAbsolute, posix } from 'path';
4
4
  import YAML, { parse } from 'yaml';
5
5
  import { pathToFileURL } from 'url';
6
6
  import { createHash } from 'crypto';
7
- import { glob } from 'glob';
8
7
 
9
8
  // src/types/common.ts
10
9
  var PhaseSchema = z.enum(["REQ", "HLD", "LLD", "IMPL", "OPS", "CI"]);
@@ -1153,6 +1152,259 @@ async function loadConfig(configPath, cwd = process.cwd()) {
1153
1152
  `Unsupported config file extension: ${resolvedPath}. Supported extensions: ${CONFIG_FILES.map((file) => file.split(".").pop()).join(", ")}`
1154
1153
  );
1155
1154
  }
1155
+ function globSync(pattern, options = {}) {
1156
+ const cwd = resolve(options.cwd ?? process.cwd());
1157
+ const ignore = (options.ignore ?? []).flatMap(expandBraces).map(compileIgnore);
1158
+ const found = /* @__PURE__ */ new Set();
1159
+ for (const expanded of expandBraces(pattern)) {
1160
+ const { root, segments, dirOnly } = splitPattern(expanded);
1161
+ if (segments.length === 0) continue;
1162
+ new Walker(segments, dirOnly, ignore, root !== "" || options.absolute === true, cwd, found).start(root === "" ? cwd : root, root);
1163
+ }
1164
+ return [...found].sort();
1165
+ }
1166
+ var NOCASE = process.platform === "darwin" || process.platform === "win32";
1167
+ function unsupported(pattern, what) {
1168
+ throw new Error(`Unsupported glob syntax in "${pattern}": ${what}`);
1169
+ }
1170
+ function expandBraces(pattern) {
1171
+ if (pattern.includes("\\")) unsupported(pattern, '"\\" escapes');
1172
+ if (/[@!+?*]\(/.test(pattern)) unsupported(pattern, "extended glob");
1173
+ for (let open = pattern.indexOf("{"); open !== -1; open = pattern.indexOf("{", open + 1)) {
1174
+ let depth = 0;
1175
+ const commas = [];
1176
+ let close = -1;
1177
+ for (let i = open; i < pattern.length; i++) {
1178
+ const c = pattern[i];
1179
+ if (c === "{") depth++;
1180
+ else if (c === "}" && --depth === 0) {
1181
+ close = i;
1182
+ break;
1183
+ } else if (c === "," && depth === 1) commas.push(i);
1184
+ }
1185
+ if (close === -1) return [pattern];
1186
+ const body = pattern.slice(open + 1, close);
1187
+ if (commas.length === 0) {
1188
+ if (/^(-?\d+|[A-Za-z])\.\.(-?\d+|[A-Za-z])(\.\.-?\d+)?$/.test(body)) {
1189
+ unsupported(pattern, `brace range "{${body}}"`);
1190
+ }
1191
+ continue;
1192
+ }
1193
+ const head = pattern.slice(0, open);
1194
+ const tail = pattern.slice(close + 1);
1195
+ const bounds = [open, ...commas, close];
1196
+ const alternatives = [];
1197
+ for (let k = 0; k < bounds.length - 1; k++) {
1198
+ alternatives.push(pattern.slice(bounds[k] + 1, bounds[k + 1]));
1199
+ }
1200
+ return alternatives.flatMap((alt) => expandBraces(head + alt + tail));
1201
+ }
1202
+ return [pattern];
1203
+ }
1204
+ function splitPattern(pattern) {
1205
+ const absolute = isAbsolute(pattern);
1206
+ const parts = pattern.split("/");
1207
+ let root = "";
1208
+ if (absolute) {
1209
+ root = parts[0] === "" ? "/" : `${parts[0]}/`;
1210
+ parts.shift();
1211
+ }
1212
+ while (parts.length > 1 && parts[0] === ".") parts.shift();
1213
+ const dirOnly = parts.length > 1 && parts[parts.length - 1] === "";
1214
+ const segments = parts.filter((p, i) => p !== "" || i === 0).filter((p) => p !== "");
1215
+ const collapsed = segments.filter((s, i) => !(s === "**" && segments[i - 1] === "**"));
1216
+ return { root, segments: collapsed, dirOnly };
1217
+ }
1218
+ var MAGIC = /[*?[]/;
1219
+ var segmentCache = /* @__PURE__ */ new Map();
1220
+ function matchSegment(name, segment, dot) {
1221
+ if (!MAGIC.test(segment)) return NOCASE ? name.toLowerCase() === segment.toLowerCase() : name === segment;
1222
+ if (name === "." || name === "..") return false;
1223
+ if (!dot && name.startsWith(".") && !segment.startsWith(".")) return false;
1224
+ let re = segmentCache.get(segment);
1225
+ if (!re) {
1226
+ re = new RegExp(`^${segmentSource(segment)}$`, NOCASE ? "i" : "");
1227
+ segmentCache.set(segment, re);
1228
+ }
1229
+ return re.test(name);
1230
+ }
1231
+ function segmentSource(segment) {
1232
+ let out = "";
1233
+ for (let i = 0; i < segment.length; i++) {
1234
+ const c = segment[i];
1235
+ if (c === "*") {
1236
+ out += "[^/]*";
1237
+ } else if (c === "?") {
1238
+ out += "[^/]";
1239
+ } else if (c === "[") {
1240
+ const end = segment.indexOf("]", i + 2);
1241
+ if (end === -1) {
1242
+ out += "\\[";
1243
+ continue;
1244
+ }
1245
+ let set = segment.slice(i + 1, end);
1246
+ const negate = set.startsWith("!") || set.startsWith("^");
1247
+ if (negate) set = set.slice(1);
1248
+ out += `[${negate ? "^" : ""}${set.replace(/[\]\\^]/g, (m) => `\\${m}`)}]`;
1249
+ i = end;
1250
+ } else {
1251
+ out += c.replace(/[.+^${}()|\]\\]/g, (m) => `\\${m}`);
1252
+ }
1253
+ }
1254
+ return out;
1255
+ }
1256
+ function matchPath(segments, path, dot) {
1257
+ const memo = /* @__PURE__ */ new Map();
1258
+ const go = (s, p) => {
1259
+ const key = `${s}:${p}`;
1260
+ const hit = memo.get(key);
1261
+ if (hit !== void 0) return hit;
1262
+ let result;
1263
+ if (s === segments.length) {
1264
+ result = p === path.length;
1265
+ } else if (segments[s] === "**") {
1266
+ result = go(s + 1, p) || p < path.length && path[p] !== "." && path[p] !== ".." && (dot) && go(s, p + 1);
1267
+ } else {
1268
+ result = p < path.length && matchSegment(path[p], segments[s], dot) && go(s + 1, p + 1);
1269
+ }
1270
+ memo.set(key, result);
1271
+ return result;
1272
+ };
1273
+ return go(0, 0);
1274
+ }
1275
+ function compileIgnore(pattern) {
1276
+ const { root, segments } = splitPattern(pattern);
1277
+ const rootSegments = root === "" || root === "/" ? [] : [root.replace(/\/$/, "")];
1278
+ return {
1279
+ absolute: root !== "",
1280
+ segments: [...rootSegments, ...segments],
1281
+ children: segments[segments.length - 1] === "**"
1282
+ };
1283
+ }
1284
+ function toPosix(p) {
1285
+ return p.replace(/\\/g, "/");
1286
+ }
1287
+ function joinPath(prefix, name) {
1288
+ if (prefix === "") return name;
1289
+ return prefix.endsWith("/") ? prefix + name : `${prefix}/${name}`;
1290
+ }
1291
+ var Walker = class {
1292
+ constructor(segments, dirOnly, ignore, absoluteResults, cwd, found) {
1293
+ this.segments = segments;
1294
+ this.dirOnly = dirOnly;
1295
+ this.ignore = ignore;
1296
+ this.absoluteResults = absoluteResults;
1297
+ this.found = found;
1298
+ this.cwdPosix = toPosix(cwd);
1299
+ const firstMagic = segments.findIndex((s) => s === "**" || MAGIC.test(s));
1300
+ this.prefixLength = firstMagic === -1 ? segments.length : firstMagic;
1301
+ }
1302
+ segments;
1303
+ dirOnly;
1304
+ ignore;
1305
+ absoluteResults;
1306
+ found;
1307
+ cwdPosix;
1308
+ /** Number of leading literal segments: the part of the pattern that names a fixed path. */
1309
+ prefixLength;
1310
+ /** Positions `**` lets the path also stand at: a `**` may match no directory. */
1311
+ close(positions) {
1312
+ const closed = /* @__PURE__ */ new Set();
1313
+ for (let i of positions) {
1314
+ closed.add(i);
1315
+ while (this.segments[i] === "**") closed.add(++i);
1316
+ }
1317
+ return [...closed];
1318
+ }
1319
+ /** Expands the pattern from its root (`output` is '' for a relative pattern). */
1320
+ start(root, output) {
1321
+ if (this.close([0]).includes(this.segments.length)) {
1322
+ this.add(output === "" ? "." : output);
1323
+ }
1324
+ this.walk(root, output, [0]);
1325
+ }
1326
+ add(output) {
1327
+ const absolute = posix.resolve(this.cwdPosix, output);
1328
+ this.found.add(this.absoluteResults ? absolute : posix.relative(this.cwdPosix, absolute) || ".");
1329
+ }
1330
+ /**
1331
+ * `dir` is the directory on disk, `output` the path it is reported as, and
1332
+ * `positions` the pattern segments that path stands before.
1333
+ */
1334
+ walk(dir, output, positions) {
1335
+ const end = this.segments.length;
1336
+ const pending = this.close(positions).filter((p) => p < end);
1337
+ if (pending.length === 0) return;
1338
+ const literalOnly = pending.every((p) => !MAGIC.test(this.segments[p]) && this.segments[p] !== "**");
1339
+ const entries = literalOnly ? this.literalEntries(dir, pending) : this.listEntries(dir);
1340
+ for (const entry of entries) {
1341
+ const viaSegment = [];
1342
+ const viaGlobstar = [];
1343
+ for (const p of pending) {
1344
+ const segment = this.segments[p];
1345
+ if (segment === "**") {
1346
+ if (!entry.name.startsWith(".")) viaGlobstar.push(p);
1347
+ } else if (matchSegment(entry.name, segment, false)) {
1348
+ viaSegment.push(p);
1349
+ }
1350
+ }
1351
+ if (viaSegment.length === 0 && viaGlobstar.length === 0) continue;
1352
+ const childDir = joinPath(dir, entry.name);
1353
+ const childOutput = joinPath(output, entry.name);
1354
+ const absolute = posix.resolve(this.cwdPosix, childOutput);
1355
+ const rel = (posix.relative(this.cwdPosix, absolute) || ".").split("/");
1356
+ const abs = absolute.split("/").filter(Boolean);
1357
+ const hits = this.ignore.filter((ig) => matchPath(ig.segments, ig.absolute ? abs : rel, true));
1358
+ const onTheWay = viaGlobstar.length === 0 && viaSegment.every((p) => p < this.prefixLength - 1);
1359
+ const byName = !this.dirOnly || entry.isDir || entry.isLink;
1360
+ const completes = viaSegment.some((p) => p + 1 === end && byName) || viaSegment.some((p) => p + 1 < end && this.close([p + 1]).includes(end) && byName && (entry.isDir || entry.isLink || p < this.prefixLength)) || viaGlobstar.some((p) => this.close([p]).includes(end) && (!this.dirOnly || entry.isDir && !entry.isLink));
1361
+ if (completes && hits.length === 0) this.add(childOutput);
1362
+ if (!entry.isDir || !onTheWay && hits.some((ig) => ig.children)) continue;
1363
+ const descend = entry.isLink ? [...viaSegment.map((p) => p + 1), ...viaGlobstar.filter((p) => p > 0).map((p) => p + 1)] : [...viaSegment.map((p) => p + 1), ...viaGlobstar];
1364
+ if (descend.length > 0) this.walk(childDir, childOutput, descend);
1365
+ }
1366
+ }
1367
+ listEntries(dir) {
1368
+ let dirents;
1369
+ try {
1370
+ dirents = readdirSync(dir, { withFileTypes: true });
1371
+ } catch {
1372
+ return [];
1373
+ }
1374
+ return dirents.map((d) => ({
1375
+ name: d.name,
1376
+ isLink: d.isSymbolicLink(),
1377
+ isDir: d.isSymbolicLink() ? isDirectory(joinPath(dir, d.name)) : d.isDirectory()
1378
+ }));
1379
+ }
1380
+ literalEntries(dir, pending) {
1381
+ const entries = [];
1382
+ for (const name of new Set(pending.map((p) => this.segments[p]))) {
1383
+ const path = joinPath(dir, name);
1384
+ let link;
1385
+ try {
1386
+ link = lstatSync(path);
1387
+ } catch {
1388
+ continue;
1389
+ }
1390
+ entries.push({
1391
+ name,
1392
+ isLink: link.isSymbolicLink(),
1393
+ isDir: link.isSymbolicLink() ? isDirectory(path) : link.isDirectory()
1394
+ });
1395
+ }
1396
+ return entries;
1397
+ }
1398
+ };
1399
+ function isDirectory(path) {
1400
+ try {
1401
+ return statSync(path).isDirectory();
1402
+ } catch {
1403
+ return false;
1404
+ }
1405
+ }
1406
+
1407
+ // src/utils/file-writer.ts
1156
1408
  function ensureDir(dirPath) {
1157
1409
  if (!existsSync(dirPath)) {
1158
1410
  mkdirSync(dirPath, { recursive: true });
@@ -1220,14 +1472,14 @@ function checkBatchDrift(files) {
1220
1472
  return files.map(({ path, content }) => checkFileDrift(path, content));
1221
1473
  }
1222
1474
  async function findFiles(pattern, cwd = process.cwd()) {
1223
- return glob(pattern, { cwd, absolute: true });
1475
+ return globSync(pattern, { cwd, absolute: true });
1224
1476
  }
1225
1477
  async function findTypeScriptFiles(srcDir) {
1226
1478
  return findFiles("**/*.ts", srcDir);
1227
1479
  }
1228
1480
  async function findDefinitionFiles(srcDir, subDir) {
1229
1481
  const pattern = join(srcDir, subDir, "**/*.ts");
1230
- return glob(pattern, { absolute: true, ignore: ["**/*.d.ts", "**/index.ts"] });
1482
+ return globSync(pattern, { absolute: true, ignore: ["**/*.d.ts", "**/index.ts"] });
1231
1483
  }
1232
1484
  function generateDocsPath(baseDir, category, filename) {
1233
1485
  return join(baseDir, category, filename);