poe-code 11.0.6 → 11.0.7

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.
@@ -39,12 +39,7 @@ export function extractBlock(markdown, startLine = 1) {
39
39
  const parts = [];
40
40
  let cursor = first.start;
41
41
  for (const block of blocks) {
42
- let gap = "";
43
- for (let offset = cursor; offset < block.start; offset++) {
44
- const character = markdown[offset];
45
- gap += character === "\n" || character === "\r" ? character : " ";
46
- }
47
- parts.push(gap, markdown.slice(block.start, block.end));
42
+ parts.push(maskSource(markdown.slice(cursor, block.start)), markdown.slice(block.start, block.end));
48
43
  cursor = block.end;
49
44
  }
50
45
  return {
@@ -55,6 +50,14 @@ export function extractBlock(markdown, startLine = 1) {
55
50
  ranges: blocks.map((block) => [block.start, block.end])
56
51
  };
57
52
  }
53
+ export function maskSource(source) {
54
+ let masked = "";
55
+ for (let offset = 0; offset < source.length; offset++) {
56
+ const character = source[offset];
57
+ masked += character === "\n" || character === "\r" ? character : " ";
58
+ }
59
+ return masked;
60
+ }
58
61
  function readOpeningFence(line) {
59
62
  const fenceStart = readFenceStart(line);
60
63
  if (fenceStart === undefined) {
@@ -3,7 +3,7 @@ import { extname } from "node:path";
3
3
  import { supportsSpawnMode } from "@poe-code/agent-spawn/configs";
4
4
  import { SPAWN_MODES } from "@poe-code/agent-spawn/types";
5
5
  import { hasOwnErrorCode } from "../error-codes.js";
6
- import { countLineBreaks, extractBlock } from "../loader/extract-block.js";
6
+ import { countLineBreaks, extractBlock, maskSource } from "../loader/extract-block.js";
7
7
  import { splitFrontmatter } from "../loader/frontmatter.js";
8
8
  import { lint } from "../lint.js";
9
9
  import { createLintModulesFromRuntimeRegistry } from "../lint/runtime-modules.js";
@@ -52,7 +52,7 @@ export class LintError extends Error {
52
52
  }
53
53
  }
54
54
  export async function runHarness(filepath, options) {
55
- const rawSource = stripByteOrderMark(await readHarnessFile(filepath));
55
+ const rawSource = await readHarnessFile(filepath);
56
56
  const { executableSource, frontmatter, isRawScript } = loadExecutableSource(filepath, rawSource);
57
57
  assertFrontmatterAgentModes(frontmatter);
58
58
  const meta = createHarnessMeta(filepath, frontmatter);
@@ -137,11 +137,12 @@ async function readHarnessFile(filepath) {
137
137
  }
138
138
  function loadExecutableSource(filepath, source) {
139
139
  if (isRawScriptPath(filepath)) {
140
- if (source.length === 0) {
140
+ const executableSource = stripByteOrderMark(source);
141
+ if (executableSource.length === 0) {
141
142
  throw new Error(`No code block found in empty harness file: ${filepath}`);
142
143
  }
143
144
  return {
144
- executableSource: source,
145
+ executableSource,
145
146
  frontmatter: {},
146
147
  isRawScript: true
147
148
  };
@@ -152,9 +153,8 @@ function loadExecutableSource(filepath, source) {
152
153
  }
153
154
  const bodyStartOffset = source.length - body.length;
154
155
  const { source: executableBlock, startOffset } = extractBlock(body, countLineBreaks(source, 0, bodyStartOffset) + 1);
155
- const absoluteLineOffset = countLineBreaks(source, 0, bodyStartOffset + startOffset);
156
156
  return {
157
- executableSource: createLineOffsetSource(stripHashbang(executableBlock), absoluteLineOffset),
157
+ executableSource: maskSource(source.slice(0, bodyStartOffset + startOffset)) + stripHashbang(executableBlock),
158
158
  frontmatter,
159
159
  isRawScript: false
160
160
  };
@@ -238,9 +238,6 @@ function stripHashbang(source) {
238
238
  end += 1;
239
239
  return `${" ".repeat(end)}${source.slice(end)}`;
240
240
  }
241
- function createLineOffsetSource(source, lineOffset) {
242
- return `${"\n".repeat(Math.max(lineOffset, 0))}${source}`;
243
- }
244
241
  function formatLintErrorMessage(diagnostics) {
245
242
  if (diagnostics.length === 0) {
246
243
  return "Script lint failed.";