lean-spec 0.2.5-dev.20251119025751 → 0.2.5-dev.20251119062438
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.
|
@@ -16,7 +16,6 @@ import { execSync, spawn } from 'child_process';
|
|
|
16
16
|
import ora from 'ora';
|
|
17
17
|
import stripAnsi from 'strip-ansi';
|
|
18
18
|
import { select } from '@inquirer/prompts';
|
|
19
|
-
import { encoding_for_model } from 'tiktoken';
|
|
20
19
|
import dayjs3 from 'dayjs';
|
|
21
20
|
import { marked } from 'marked';
|
|
22
21
|
import { markedTerminal } from 'marked-terminal';
|
|
@@ -1050,10 +1049,10 @@ function updateCommand() {
|
|
|
1050
1049
|
await updateSpec(specPath, updates);
|
|
1051
1050
|
});
|
|
1052
1051
|
}
|
|
1053
|
-
async function updateSpec(specPath, updates) {
|
|
1052
|
+
async function updateSpec(specPath, updates, options = {}) {
|
|
1054
1053
|
await autoCheckIfEnabled();
|
|
1055
|
-
const
|
|
1056
|
-
const
|
|
1054
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1055
|
+
const config = await loadConfig(cwd);
|
|
1057
1056
|
const specsDir = path4.join(cwd, config.specsDir);
|
|
1058
1057
|
const resolvedPath = await resolveSpecPath(specPath, cwd, specsDir);
|
|
1059
1058
|
if (!resolvedPath) {
|
|
@@ -2449,21 +2448,28 @@ function analyzeMarkdownStructure(content) {
|
|
|
2449
2448
|
};
|
|
2450
2449
|
}
|
|
2451
2450
|
var TokenCounter = class {
|
|
2452
|
-
encoding;
|
|
2453
|
-
|
|
2454
|
-
this.encoding
|
|
2451
|
+
encoding = null;
|
|
2452
|
+
async getEncoding() {
|
|
2453
|
+
if (!this.encoding) {
|
|
2454
|
+
const { encoding_for_model } = await import('tiktoken');
|
|
2455
|
+
this.encoding = encoding_for_model("gpt-4");
|
|
2456
|
+
}
|
|
2457
|
+
return this.encoding;
|
|
2455
2458
|
}
|
|
2456
2459
|
/**
|
|
2457
2460
|
* Clean up resources (important to prevent memory leaks)
|
|
2458
2461
|
*/
|
|
2459
2462
|
dispose() {
|
|
2460
|
-
this.encoding
|
|
2463
|
+
if (this.encoding) {
|
|
2464
|
+
this.encoding.free();
|
|
2465
|
+
}
|
|
2461
2466
|
}
|
|
2462
2467
|
/**
|
|
2463
2468
|
* Count tokens in a string
|
|
2464
2469
|
*/
|
|
2465
|
-
countString(text) {
|
|
2466
|
-
const
|
|
2470
|
+
async countString(text) {
|
|
2471
|
+
const encoding = await this.getEncoding();
|
|
2472
|
+
const tokens = encoding.encode(text);
|
|
2467
2473
|
return tokens.length;
|
|
2468
2474
|
}
|
|
2469
2475
|
/**
|
|
@@ -2478,7 +2484,7 @@ var TokenCounter = class {
|
|
|
2478
2484
|
*/
|
|
2479
2485
|
async countFile(filePath, options = {}) {
|
|
2480
2486
|
const content = await fs9.readFile(filePath, "utf-8");
|
|
2481
|
-
const tokens = this.countString(content);
|
|
2487
|
+
const tokens = await this.countString(content);
|
|
2482
2488
|
const lines = content.split("\n").length;
|
|
2483
2489
|
const result = {
|
|
2484
2490
|
total: tokens,
|
|
@@ -2528,7 +2534,7 @@ var TokenCounter = class {
|
|
|
2528
2534
|
for (const file of filesToCount) {
|
|
2529
2535
|
const filePath = path4.join(specPath, file);
|
|
2530
2536
|
const content = await fs9.readFile(filePath, "utf-8");
|
|
2531
|
-
const tokens = this.countString(content);
|
|
2537
|
+
const tokens = await this.countString(content);
|
|
2532
2538
|
const lines = content.split("\n").length;
|
|
2533
2539
|
fileCounts.push({
|
|
2534
2540
|
path: file,
|
|
@@ -2566,7 +2572,7 @@ var TokenCounter = class {
|
|
|
2566
2572
|
const parsed = matter2(content);
|
|
2567
2573
|
body = parsed.content;
|
|
2568
2574
|
frontmatterContent = parsed.matter;
|
|
2569
|
-
breakdown.frontmatter = this.countString(frontmatterContent);
|
|
2575
|
+
breakdown.frontmatter = await this.countString(frontmatterContent);
|
|
2570
2576
|
} catch {
|
|
2571
2577
|
}
|
|
2572
2578
|
let inCodeBlock = false;
|
|
@@ -2577,23 +2583,23 @@ var TokenCounter = class {
|
|
|
2577
2583
|
const trimmed = line.trim();
|
|
2578
2584
|
if (trimmed.startsWith("```")) {
|
|
2579
2585
|
inCodeBlock = !inCodeBlock;
|
|
2580
|
-
breakdown.code += this.countString(line + "\n");
|
|
2586
|
+
breakdown.code += await this.countString(line + "\n");
|
|
2581
2587
|
continue;
|
|
2582
2588
|
}
|
|
2583
2589
|
if (inCodeBlock) {
|
|
2584
|
-
breakdown.code += this.countString(line + "\n");
|
|
2590
|
+
breakdown.code += await this.countString(line + "\n");
|
|
2585
2591
|
continue;
|
|
2586
2592
|
}
|
|
2587
2593
|
const isTableSeparator = trimmed.includes("|") && /[-:]{3,}/.test(trimmed);
|
|
2588
2594
|
const isTableRow = trimmed.includes("|") && trimmed.startsWith("|");
|
|
2589
2595
|
if (isTableSeparator || inTable && isTableRow) {
|
|
2590
2596
|
inTable = true;
|
|
2591
|
-
breakdown.tables += this.countString(line + "\n");
|
|
2597
|
+
breakdown.tables += await this.countString(line + "\n");
|
|
2592
2598
|
continue;
|
|
2593
2599
|
} else if (inTable && !isTableRow) {
|
|
2594
2600
|
inTable = false;
|
|
2595
2601
|
}
|
|
2596
|
-
breakdown.prose += this.countString(line + "\n");
|
|
2602
|
+
breakdown.prose += await this.countString(line + "\n");
|
|
2597
2603
|
}
|
|
2598
2604
|
return breakdown;
|
|
2599
2605
|
}
|
|
@@ -2674,12 +2680,12 @@ async function countTokens(input, options) {
|
|
|
2674
2680
|
try {
|
|
2675
2681
|
if (typeof input === "string") {
|
|
2676
2682
|
return {
|
|
2677
|
-
total: counter.countString(input),
|
|
2683
|
+
total: await counter.countString(input),
|
|
2678
2684
|
files: []
|
|
2679
2685
|
};
|
|
2680
2686
|
} else if ("content" in input) {
|
|
2681
2687
|
return {
|
|
2682
|
-
total: counter.countString(input.content),
|
|
2688
|
+
total: await counter.countString(input.content),
|
|
2683
2689
|
files: []
|
|
2684
2690
|
};
|
|
2685
2691
|
} else if ("filePath" in input) {
|
|
@@ -2857,7 +2863,7 @@ var ComplexityValidator = class {
|
|
|
2857
2863
|
const listItemCount = lines.filter((line) => line.match(/^[\s]*[-*]\s/) || line.match(/^[\s]*\d+\.\s/)).length;
|
|
2858
2864
|
const tableCount = lines.filter((line) => line.includes("|") && line.match(/[-:]{3,}/)).length;
|
|
2859
2865
|
const counter = new TokenCounter();
|
|
2860
|
-
const tokenCount = counter.countString(content);
|
|
2866
|
+
const tokenCount = await counter.countString(content);
|
|
2861
2867
|
counter.dispose();
|
|
2862
2868
|
let hasSubSpecs = false;
|
|
2863
2869
|
let subSpecCount = 0;
|
|
@@ -8459,5 +8465,5 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|
|
8459
8465
|
}
|
|
8460
8466
|
|
|
8461
8467
|
export { analyzeCommand, archiveCommand, backfillCommand, boardCommand, checkCommand, compactCommand, createCommand, createMcpServer, depsCommand, filesCommand, ganttCommand, initCommand, linkCommand, listCommand, mcpCommand, migrateCommand, openCommand, searchCommand, splitCommand, statsCommand, templatesCommand, timelineCommand, tokensCommand, uiCommand, unlinkCommand, updateCommand, validateCommand, viewCommand };
|
|
8462
|
-
//# sourceMappingURL=chunk-
|
|
8463
|
-
//# sourceMappingURL=chunk-
|
|
8468
|
+
//# sourceMappingURL=chunk-D5HD2K67.js.map
|
|
8469
|
+
//# sourceMappingURL=chunk-D5HD2K67.js.map
|