stego-cli 0.3.1 → 0.3.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/dist/comments/add-comment.js +12 -7
- package/dist/stego-cli.js +15 -5
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { CommentsCommandError } from "./errors.js";
|
|
4
|
-
const
|
|
4
|
+
const COMMENT_DELIMITER_REGEX = /^<!--\s*comment:\s*(CMT-(\d{4,}))\s*-->\s*$/i;
|
|
5
|
+
const LEGACY_COMMENT_HEADING_REGEX = /^###\s+(CMT-(\d{4,}))\s*$/i;
|
|
5
6
|
const START_SENTINEL = "<!-- stego-comments:start -->";
|
|
6
7
|
const END_SENTINEL = "<!-- stego-comments:end -->";
|
|
7
8
|
/** Adds one stego comment entry to a manuscript and writes the updated file. */
|
|
@@ -18,7 +19,7 @@ export function addCommentToManuscript(request) {
|
|
|
18
19
|
if (!sentinelState.hasSentinels && !hasYamlFrontmatter) {
|
|
19
20
|
throw new CommentsCommandError("NOT_STEGO_MANUSCRIPT", 3, "File is not recognized as a Stego manuscript (missing frontmatter and comments sentinels).");
|
|
20
21
|
}
|
|
21
|
-
const commentId = getNextCommentId(lines);
|
|
22
|
+
const commentId = getNextCommentId(lines, sentinelState);
|
|
22
23
|
const createdAt = new Date().toISOString();
|
|
23
24
|
const meta = buildMetaPayload(request.range, request.sourceMeta);
|
|
24
25
|
const meta64 = Buffer.from(JSON.stringify(meta), "utf8").toString("base64url");
|
|
@@ -75,7 +76,7 @@ function buildCommentEntryLines(commentId, timestamp, author, message, meta64) {
|
|
|
75
76
|
.split("\n")
|
|
76
77
|
.map((line) => line.trimEnd());
|
|
77
78
|
return [
|
|
78
|
-
|
|
79
|
+
`<!-- comment: ${commentId} -->`,
|
|
79
80
|
`<!-- meta64: ${meta64} -->`,
|
|
80
81
|
`> _${timestamp} | ${safeAuthor}_`,
|
|
81
82
|
">",
|
|
@@ -142,11 +143,15 @@ function findTrimmedLineIndexes(lines, target) {
|
|
|
142
143
|
}
|
|
143
144
|
return indexes;
|
|
144
145
|
}
|
|
145
|
-
function getNextCommentId(lines) {
|
|
146
|
+
function getNextCommentId(lines, sentinelState) {
|
|
147
|
+
const candidateLines = sentinelState.hasSentinels
|
|
148
|
+
? lines.slice(sentinelState.startIndex + 1, sentinelState.endIndex)
|
|
149
|
+
: lines;
|
|
146
150
|
let maxId = 0;
|
|
147
|
-
for (const line of
|
|
148
|
-
const
|
|
149
|
-
|
|
151
|
+
for (const line of candidateLines) {
|
|
152
|
+
const trimmed = line.trim();
|
|
153
|
+
const match = trimmed.match(COMMENT_DELIMITER_REGEX) ?? trimmed.match(LEGACY_COMMENT_HEADING_REGEX);
|
|
154
|
+
if (!match || !match[2]) {
|
|
150
155
|
continue;
|
|
151
156
|
}
|
|
152
157
|
const numeric = Number.parseInt(match[2], 10);
|
package/dist/stego-cli.js
CHANGED
|
@@ -1425,19 +1425,18 @@ function parseStegoCommentThreads(lines, relativePath, baseLine, issues) {
|
|
|
1425
1425
|
index += 1;
|
|
1426
1426
|
continue;
|
|
1427
1427
|
}
|
|
1428
|
-
const
|
|
1429
|
-
if (!
|
|
1430
|
-
issues.push(makeIssue("error", "comments", "Invalid comments appendix line. Expected
|
|
1428
|
+
const id = parseCommentThreadDelimiter(trimmed);
|
|
1429
|
+
if (!id) {
|
|
1430
|
+
issues.push(makeIssue("error", "comments", "Invalid comments appendix line. Expected comment delimiter '<!-- comment: CMT-0001 -->'.", relativePath, baseLine + index));
|
|
1431
1431
|
index += 1;
|
|
1432
1432
|
continue;
|
|
1433
1433
|
}
|
|
1434
|
-
const id = headingMatch[1];
|
|
1435
1434
|
index += 1;
|
|
1436
1435
|
const rowLines = [];
|
|
1437
1436
|
const rowLineNumbers = [];
|
|
1438
1437
|
while (index < lines.length) {
|
|
1439
1438
|
const nextTrimmed = lines[index].trim();
|
|
1440
|
-
if (
|
|
1439
|
+
if (parseCommentThreadDelimiter(nextTrimmed)) {
|
|
1441
1440
|
break;
|
|
1442
1441
|
}
|
|
1443
1442
|
rowLines.push(lines[index]);
|
|
@@ -1549,6 +1548,17 @@ function parseStegoCommentThreads(lines, relativePath, baseLine, issues) {
|
|
|
1549
1548
|
}
|
|
1550
1549
|
return comments;
|
|
1551
1550
|
}
|
|
1551
|
+
function parseCommentThreadDelimiter(line) {
|
|
1552
|
+
const markerMatch = line.match(/^<!--\s*comment:\s*(CMT-\d{4,})\s*-->\s*$/i);
|
|
1553
|
+
if (markerMatch?.[1]) {
|
|
1554
|
+
return markerMatch[1].toUpperCase();
|
|
1555
|
+
}
|
|
1556
|
+
const legacyHeadingMatch = line.match(/^###\s+(CMT-\d{4,})\s*$/i);
|
|
1557
|
+
if (legacyHeadingMatch?.[1]) {
|
|
1558
|
+
return legacyHeadingMatch[1].toUpperCase();
|
|
1559
|
+
}
|
|
1560
|
+
return undefined;
|
|
1561
|
+
}
|
|
1552
1562
|
function decodeCommentMeta64(encoded, commentId, relativePath, lineNumber, issues) {
|
|
1553
1563
|
let rawJson = "";
|
|
1554
1564
|
try {
|