@open-tomato/rafa 0.34.0 → 0.35.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.
@@ -1,13 +1,11 @@
1
1
  // @bun
2
2
  import {
3
- activeOutput,
4
- isStampableStub,
5
- readRafaBlocks
6
- } from "./index-vp0xghk2.js";
7
- import {
3
+ parseTaskDeclaration,
8
4
  messageOf,
9
- parseTaskDeclaration
10
- } from "./index-fzhd3d4y.js";
5
+ isStampableStub,
6
+ activeOutput,
7
+ readRafaBlocks2
8
+ } from "./index-2tjmxwvp.js";
11
9
  // src/preflight/prerequisites-md.ts
12
10
  import { basename, dirname, join } from "path";
13
11
  var SECTION_AUTO_RE = /\[auto\]/i;
@@ -89,7 +87,7 @@ function readItem(lines, lineIndex, inherited) {
89
87
  const probe = isProbedTag(tag) ? extractProbe(description) : null;
90
88
  return Object.freeze({ raw, description, tag, lineIndex, probe });
91
89
  }
92
- function parsePrerequisites(content) {
90
+ function parsePrerequisites2(content) {
93
91
  const lines = content.split(`
94
92
  `);
95
93
  const items = [];
@@ -132,8 +130,8 @@ function namedItemOf(item) {
132
130
  function isMalformed(item) {
133
131
  return isProbedTag(item.tag) && item.probe === null;
134
132
  }
135
- function planPrerequisites(content) {
136
- const items = parsePrerequisites(content);
133
+ function planPrerequisites2(content) {
134
+ const items = parsePrerequisites2(content);
137
135
  return Object.freeze({
138
136
  required: requiredItemsTagged(items, "auto"),
139
137
  startRequired: requiredItemsTagged(items, "start"),
@@ -149,8 +147,8 @@ function malformedPrerequisiteLines(file, malformed) {
149
147
  `Write each as ${PROBE_ITEM_EXAMPLE}, its one backticked span a complete command run as written;` + " prove a tool is there with `<tool> --version`, `<tool> --help` or `which <tool>`."
150
148
  ];
151
149
  }
152
- function mergePlanPrerequisites(settings, content) {
153
- const plan = planPrerequisites(content ?? "");
150
+ function mergePlanPrerequisites2(settings, content) {
151
+ const plan = planPrerequisites2(content ?? "");
154
152
  return Object.freeze({
155
153
  required: Object.freeze([...settings.prerequisitesRequired, ...plan.required]),
156
154
  startRequired: plan.startRequired,
@@ -159,7 +157,7 @@ function mergePlanPrerequisites(settings, content) {
159
157
  malformed: plan.malformed
160
158
  });
161
159
  }
162
- function prerequisitesPathForPlan(planPath) {
160
+ function prerequisitesPathForPlan2(planPath) {
163
161
  const stub = PLAN_FILE_RE.exec(basename(planPath))?.[1];
164
162
  if (stub === undefined)
165
163
  return null;
@@ -175,13 +173,13 @@ async function readIfPresent(path) {
175
173
  throw new Error(`${path}: cannot be read (${messageOf(error)})`, { cause: error });
176
174
  }
177
175
  }
178
- async function loadPlanPrerequisites(planPath, settings) {
179
- const path = prerequisitesPathForPlan(planPath);
176
+ async function loadPlanPrerequisites2(planPath, settings) {
177
+ const path = prerequisitesPathForPlan2(planPath);
180
178
  const content = path === null ? null : await readIfPresent(path);
181
- return mergePlanPrerequisites(settings, content);
179
+ return mergePlanPrerequisites2(settings, content);
182
180
  }
183
181
  // src/preflight/run.ts
184
- var PROBE_TIMEOUT_MS = 30000;
182
+ var PROBE_TIMEOUT_MS2 = 30000;
185
183
  var SHELL = "/bin/sh";
186
184
  var PASS = Object.freeze({ outcome: "pass", failure: null });
187
185
  function spawnShell(probe, options) {
@@ -223,13 +221,13 @@ function collect(stream) {
223
221
  };
224
222
  return { text: read(), stop };
225
223
  }
226
- async function runShellProbe(probe, options) {
224
+ async function runShellProbe2(probe, options) {
227
225
  let proc;
228
226
  try {
229
227
  proc = spawnShell(probe, options);
230
228
  } catch (error) {
231
- const stderr2 = `could not run ${SHELL} in ${options.cwd}: ${messageOf(error)}`;
232
- return Object.freeze({ exitCode: null, stderr: stderr2, timedOut: false });
229
+ const stderr = `could not run ${SHELL} in ${options.cwd}: ${messageOf(error)}`;
230
+ return Object.freeze({ exitCode: null, stderr, timedOut: false });
233
231
  }
234
232
  const stderr = collect(proc.stderr);
235
233
  let timedOut = false;
@@ -348,14 +346,14 @@ function contextOf(options) {
348
346
  return {
349
347
  cwd: options.cwd,
350
348
  env: options.env ?? process.env,
351
- timeoutMs: options.timeoutMs ?? PROBE_TIMEOUT_MS,
352
- runProbe: options.runProbe ?? runShellProbe,
349
+ timeoutMs: options.timeoutMs ?? PROBE_TIMEOUT_MS2,
350
+ runProbe: options.runProbe ?? runShellProbe2,
353
351
  request: options.request ?? ((url, init) => fetch(url, init)),
354
352
  warn: options.warn ?? warnThroughActiveOutput,
355
353
  now: options.now ?? (() => performance.now())
356
354
  };
357
355
  }
358
- async function runPreflight(items, options) {
356
+ async function runPreflight2(items, options) {
359
357
  const context = contextOf(options);
360
358
  const checks = [];
361
359
  const knownMissing = [];
@@ -452,7 +450,7 @@ function withoutBlockerComment(line) {
452
450
  }
453
451
  function closedBlockLines(trackerContent) {
454
452
  const inside = new Set;
455
- for (const block of readRafaBlocks(trackerContent)) {
453
+ for (const block of readRafaBlocks2(trackerContent)) {
456
454
  if (!block.closed)
457
455
  continue;
458
456
  for (let line = block.span.first;line <= block.span.last; line += 1) {
@@ -519,13 +517,51 @@ function writeTrackerBlocker(trackerPath, lineNum, blocker) {
519
517
  `), "utf8");
520
518
  return true;
521
519
  }
520
+ var ANY_TASK_PREFIX = /^- \[(?: |x|BLOCKED)\] /;
521
+ var LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
522
+ function assertInsertable(entry) {
523
+ if (entry.task.trim().length === 0 || LINE_TERMINATOR.test(entry.task)) {
524
+ throw new Error("insertTrackerTask: the task text must be one line and not blank");
525
+ }
526
+ if (entry.declaration.trim().length === 0 || /[{}]/.test(entry.declaration) || LINE_TERMINATOR.test(entry.declaration)) {
527
+ throw new Error("insertTrackerTask: the declaration must be one line of entries holding no brace");
528
+ }
529
+ }
530
+ function endOfChecklist(lines, inBlock) {
531
+ for (let i = lines.length - 1;i >= 0; i -= 1) {
532
+ if (!inBlock.has(i) && ANY_TASK_PREFIX.test(lines[i]))
533
+ return i + 1;
534
+ }
535
+ const last = lines.length - 1;
536
+ return lines[last] === "" ? last : lines.length;
537
+ }
538
+ function insertTrackerTask(trackerPath, entry, beforeLine) {
539
+ assertInsertable(entry);
540
+ const content = fs.readFileSync(trackerPath, "utf8");
541
+ const lines = content.split(`
542
+ `);
543
+ const inBlock = closedBlockLines(content);
544
+ if (beforeLine !== null) {
545
+ const target = lines[beforeLine];
546
+ if (target === undefined || inBlock.has(beforeLine) || !ANY_TASK_PREFIX.test(target)) {
547
+ throw new Error(`insertTrackerTask: line ${beforeLine} is no task line`);
548
+ }
549
+ }
550
+ const at = beforeLine ?? endOfChecklist(lines, inBlock);
551
+ const { cr } = splitCarriageReturn(lines[0] ?? "");
552
+ const line = `- [BLOCKED] ${entry.task.trim()}${BLOCKER_GAP}{${entry.declaration.trim()}}` + `${BLOCKER_GAP}${blockerComment(entry.blocker)}${cr}`;
553
+ const written = [...lines.slice(0, at), line, ...lines.slice(at)];
554
+ fs.writeFileSync(trackerPath, written.join(`
555
+ `), "utf8");
556
+ return at;
557
+ }
522
558
  function trackerPathFor(planPath) {
523
559
  return planPath.replace(/PLAN(-[^/]*)?\.md$/, (_m, stub) => `PLAN_TRACKER${stub ?? ""}.md`);
524
560
  }
525
561
 
526
562
  // src/plan/parse.ts
527
- var PLAN_BLOCK_KINDS = ["plan", "context", "stage-context"];
528
- var PLAN_HEADER_FIELDS = ["stub", "issue", "spec", "release"];
563
+ var PLAN_BLOCK_KINDS2 = ["plan", "context", "stage-context"];
564
+ var PLAN_HEADER_FIELDS2 = ["stub", "issue", "spec", "release"];
529
565
  var PLAN_RELEASE_LEVELS = ["patch", "minor", "major", "none"];
530
566
  var TASK_LINES = [
531
567
  ["unchecked", /^- \[ \] (.+)/],
@@ -534,10 +570,10 @@ var TASK_LINES = [
534
570
  ];
535
571
  var STAGE_HEADING = /^# Stage: (.+)/;
536
572
  function isPlanBlockKind(kind) {
537
- return PLAN_BLOCK_KINDS.includes(kind);
573
+ return PLAN_BLOCK_KINDS2.includes(kind);
538
574
  }
539
575
  function isHeaderField(key) {
540
- return PLAN_HEADER_FIELDS.includes(key);
576
+ return PLAN_HEADER_FIELDS2.includes(key);
541
577
  }
542
578
  function isReleaseLevel(value) {
543
579
  return PLAN_RELEASE_LEVELS.includes(value);
@@ -746,8 +782,8 @@ function readHeader(block) {
746
782
  }
747
783
  return readFields(document, line);
748
784
  }
749
- function parsePlan(markdown) {
750
- const blocks = readRafaBlocks(markdown);
785
+ function parsePlan2(markdown) {
786
+ const blocks = readRafaBlocks2(markdown);
751
787
  const checklist = readChecklist(markdown, blocks);
752
788
  const bound = bindBlocks(blocks, checklist.headings);
753
789
  const reading = readHeader(bound.header);
@@ -860,15 +896,15 @@ var RENDERERS = {
860
896
  stage: renderStage,
861
897
  task: renderTask
862
898
  };
863
- function renderInjection(request) {
899
+ function renderInjection2(request) {
864
900
  const { mode, plan, task } = request;
865
901
  if (mode === "full")
866
902
  return { requested: mode, mode, text: plan, fallback: null };
867
- const model = parsePlan(plan);
903
+ const model = parsePlan2(plan);
868
904
  const location = locate(model, task);
869
905
  if (!location.found) {
870
906
  return { requested: mode, mode: "full", text: plan, fallback: location.fallback };
871
907
  }
872
908
  return { requested: mode, mode, text: RENDERERS[mode](model, location.task), fallback: null };
873
909
  }
874
- export { escapeBlockerText, splitBlockerComment, findNextTask, updateTrackerLine, writeTrackerBlocker, trackerPathFor, PLAN_BLOCK_KINDS, PLAN_HEADER_FIELDS, PLAN_RELEASE_LEVELS, parsePlan, parsePrerequisites, planPrerequisites, malformedPrerequisiteLines, mergePlanPrerequisites, prerequisitesPathForPlan, loadPlanPrerequisites, PROBE_TIMEOUT_MS, runShellProbe, runPreflight, renderInjection };
910
+ export { escapeBlockerText, splitBlockerComment, findNextTask, updateTrackerLine, writeTrackerBlocker, insertTrackerTask, trackerPathFor, PLAN_BLOCK_KINDS2, PLAN_HEADER_FIELDS2, PLAN_RELEASE_LEVELS, parsePlan2, parsePrerequisites2, planPrerequisites2, malformedPrerequisiteLines, mergePlanPrerequisites2, prerequisitesPathForPlan2, loadPlanPrerequisites2, PROBE_TIMEOUT_MS2, runShellProbe2, runPreflight2, renderInjection2 };