@oxide/skepsis 0.5.1 → 0.6.0

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/README.md CHANGED
@@ -142,6 +142,18 @@ a revset ending in `@` for jj, or an open-ended range ending at the working
142
142
  tree for git), since that's where the inserted lines land. The default diff
143
143
  in both modes ends at the working copy, so comments are enabled by default.
144
144
 
145
+ A comment goes in right after the line it's on. A comment on several lines goes
146
+ after the last of them, and its open tag says how many it covers, counting up
147
+ from the tag:
148
+
149
+ ```ts
150
+ const start = Number(match[1])
151
+ const end = Number(match[2])
152
+ // <review covers="2 lines above">
153
+ // What about NaN?
154
+ // </review>
155
+ ```
156
+
145
157
  ### Marking files viewed
146
158
 
147
159
  Viewed state is stored per file in `~/.local/share/skepsis/` using the file's
package/dist/cli.js CHANGED
@@ -18666,13 +18666,28 @@ const REVIEW_COMMENT_SYNTAXES = [
18666
18666
  ];
18667
18667
  const REVIEW_OPEN_TAG = "<review>";
18668
18668
  const REVIEW_CLOSE_TAG = "</review>";
18669
+ /** A comment on several lines goes after the last of them, and its open tag
18670
+ * says how many lines it covers, counting up from the tag:
18671
+ * `<review covers="6 lines above">`. A count rather than line numbers, so it
18672
+ * stays right when lines above it are added or removed, including by other
18673
+ * comments. The value is in words because agents read it: in testing,
18674
+ * Sonnet and Haiku sometimes took `above="6"` or `span="6"` to mean line 6,
18675
+ * and never misread this. A plain `<review>` covers the line just above. */
18676
+ function reviewOpenTag(lines) {
18677
+ return lines > 1 ? `<review covers="${lines} lines above">` : REVIEW_OPEN_TAG;
18678
+ }
18679
+ const OPEN_TAG_SOURCE = "<review(?:\\s+[\\w-]+=\"[^\"]*\")*\\s*>";
18680
+ new RegExp(OPEN_TAG_SOURCE);
18669
18681
  function escapeRegex$1(text) {
18670
18682
  return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
18671
18683
  }
18684
+ function tagSource(tag) {
18685
+ return tag === "<review>" ? OPEN_TAG_SOURCE : escapeRegex$1(tag);
18686
+ }
18672
18687
  function reviewTagSource(syntax, tag) {
18673
18688
  const prefix = escapeRegex$1(syntax.prefix);
18674
18689
  const suffix = syntax.suffix ? `(?:\\s*${escapeRegex$1(syntax.suffix)})?` : "";
18675
- return `${prefix}\\s*${escapeRegex$1(tag)}${suffix}`;
18690
+ return `${prefix}\\s*${tagSource(tag)}${suffix}`;
18676
18691
  }
18677
18692
  function reviewTagRegex(syntax, tag) {
18678
18693
  return new RegExp(`^\\s*${reviewTagSource(syntax, tag)}\\s*$`);
@@ -18871,7 +18886,7 @@ async function getCommentSyntaxes(cwd, files) {
18871
18886
  async function assertNotSymlink(cwd, file) {
18872
18887
  if ((await lstat(join(cwd, file)).catch(() => null))?.isSymbolicLink()) throw new Error(`Cannot comment on symlink: ${file}`);
18873
18888
  }
18874
- async function insertComment(cwd, file, afterLine, lineText, text) {
18889
+ async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1) {
18875
18890
  await assertNotSymlink(cwd, file);
18876
18891
  const filePath = join(cwd, file);
18877
18892
  const lines = (await readFile(filePath, "utf-8")).split("\n");
@@ -18886,7 +18901,7 @@ async function insertComment(cwd, file, afterLine, lineText, text) {
18886
18901
  suffix
18887
18902
  ].filter(Boolean).join(" ");
18888
18903
  const commentLines = [
18889
- wrap(REVIEW_OPEN_TAG),
18904
+ wrap(reviewOpenTag(Math.min(lineCount, afterLine))),
18890
18905
  ...text.split("\n").map((line) => wrap(line)),
18891
18906
  wrap(REVIEW_CLOSE_TAG)
18892
18907
  ];
@@ -24246,7 +24261,9 @@ const commentRequestSchema = object({
24246
24261
  /** What the page shows at afterLine, so a file that changed since the diff
24247
24262
  * loaded can't take the comment on the wrong line. */
24248
24263
  lineText: string(),
24249
- text: string()
24264
+ text: string(),
24265
+ /** How many lines the comment covers, ending at afterLine. */
24266
+ lineCount: number().int().min(1).optional()
24250
24267
  });
24251
24268
  /** A comment for the --send command. Only `text` is required by the
24252
24269
  * contract; the page always anchors it to lines. */
@@ -24522,8 +24539,8 @@ async function startServer(opts) {
24522
24539
  return c.json({ ok: true });
24523
24540
  });
24524
24541
  app.post("/api/comment", zValidator("json", commentRequestSchema), async (c) => {
24525
- const { file, afterLine, lineText, text } = c.req.valid("json");
24526
- await insertComment(cwd, file, afterLine, lineText, text);
24542
+ const { file, afterLine, lineText, text, lineCount } = c.req.valid("json");
24543
+ await insertComment(cwd, file, afterLine, lineText, text, lineCount);
24527
24544
  hashInFlight = null;
24528
24545
  return c.json({ ok: true });
24529
24546
  });