@open-tomato/rafa 0.35.0 → 0.36.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.
@@ -0,0 +1,129 @@
1
+ // @bun
2
+ import {
3
+ describeValue
4
+ } from "./index-fzhd3d4y.js";
5
+
6
+ // src/cli/spends.ts
7
+ var SPENDS_GLYPH = "\uD83E\uDE99";
8
+ var SPENDS_WHEN = ["always", "with", "unless", "through"];
9
+ var FLAGGED = ["with", "unless"];
10
+ var FLAG_SPELLING = /^--[^\s-]\S*$/;
11
+ function flagProblem(when, flag) {
12
+ if (FLAGGED.includes(when)) {
13
+ return typeof flag === "string" && FLAG_SPELLING.test(flag) ? null : `spends.flag is ${describeValue(flag)}, expected a flag as typed, starting with --`;
14
+ }
15
+ return flag === undefined ? null : `spends.flag is ${describeValue(flag)}, expected absent when spends.when is "${when}"`;
16
+ }
17
+ function spendsProblem(value) {
18
+ if (value === undefined)
19
+ return null;
20
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
21
+ return `spends is ${describeValue(value)}, expected absent or a mapping`;
22
+ }
23
+ const { when, what, flag } = value;
24
+ if (!SPENDS_WHEN.includes(when)) {
25
+ return `spends.when is ${describeValue(when)}, expected one of ${SPENDS_WHEN.join(", ")}`;
26
+ }
27
+ if (typeof what !== "string") {
28
+ return `spends.what is ${describeValue(what)}, expected a string`;
29
+ }
30
+ return flagProblem(when, flag);
31
+ }
32
+
33
+ // src/cli/command.ts
34
+ var COMMAND_OUTPUTS = ["text", "json", "events", "tui"];
35
+ var MAX_EXIT_CODE = 255;
36
+
37
+ class CommandExit extends Error {
38
+ exitCode;
39
+ constructor(exitCode, message = "") {
40
+ super(message);
41
+ if (!Number.isInteger(exitCode) || exitCode < 0 || exitCode > MAX_EXIT_CODE) {
42
+ throw new TypeError(`CommandExit: exit code is ${describeValue(exitCode)}, expected a whole number from 0 to ${MAX_EXIT_CODE}`);
43
+ }
44
+ this.name = "CommandExit";
45
+ this.exitCode = exitCode;
46
+ }
47
+ }
48
+ function isListOf(value, check) {
49
+ return Array.isArray(value) && value.every(check);
50
+ }
51
+ function hasStrings(value, keys) {
52
+ if (typeof value !== "object" || value === null)
53
+ return false;
54
+ const record = value;
55
+ return keys.every((key) => typeof record[key] === "string");
56
+ }
57
+ function isRoutingWord(value) {
58
+ return typeof value === "string" && /^[^\s/-][^\s/]*$/.test(value);
59
+ }
60
+ function isFlag(item) {
61
+ if (!hasStrings(item, ["name"]))
62
+ return false;
63
+ const { deprecated } = item;
64
+ return deprecated === undefined || hasStrings(deprecated, ["use"]);
65
+ }
66
+ function fieldProblem(fields) {
67
+ const checks = [
68
+ ["subject", isRoutingWord(fields.subject), "a word with no space, no slash and no leading dash"],
69
+ ["action", isRoutingWord(fields.action), "a word with no space, no slash and no leading dash"],
70
+ ["name", typeof fields.name === "string", "a string"],
71
+ ["summary", typeof fields.summary === "string", "a string"],
72
+ ["description", typeof fields.description === "string", "a string"],
73
+ ["args", isListOf(fields.args, (item) => hasStrings(item, ["name"])), "a list of named arguments"],
74
+ ["flags", isListOf(fields.flags, isFlag), "a list of named flags, each deprecation naming its use"],
75
+ ["examples", isListOf(fields.examples, (item) => hasStrings(item, ["cmd", "note"])), "a list of examples"],
76
+ [
77
+ "outputs",
78
+ isListOf(fields.outputs, (item) => COMMAND_OUTPUTS.includes(item)),
79
+ `a list of ${COMMAND_OUTPUTS.join(", ")}`
80
+ ],
81
+ [
82
+ "aliases",
83
+ fields.aliases === undefined || isListOf(fields.aliases, (item) => typeof item === "string"),
84
+ "absent or a list of strings"
85
+ ],
86
+ [
87
+ "lastingAliases",
88
+ fields.lastingAliases === undefined || isListOf(fields.lastingAliases, (item) => typeof item === "string"),
89
+ "absent or a list of strings"
90
+ ],
91
+ [
92
+ "deprecated",
93
+ fields.deprecated === undefined || hasStrings(fields.deprecated, ["since", "use"]),
94
+ "absent or a mapping of since and use"
95
+ ],
96
+ ["hidden", fields.hidden === undefined || typeof fields.hidden === "boolean", "absent or a boolean"],
97
+ [
98
+ "needsProject",
99
+ fields.needsProject === undefined || typeof fields.needsProject === "boolean",
100
+ "absent or a boolean"
101
+ ],
102
+ ["exec", fields.exec === undefined || fields.exec === true, "absent or true"],
103
+ ["run", typeof fields.run === "function", "a function"]
104
+ ];
105
+ const failed = checks.find(([, passes]) => !passes);
106
+ if (failed === undefined)
107
+ return null;
108
+ const [key, , expected] = failed;
109
+ return `${key} is ${describeValue(fields[key])}, expected ${expected}`;
110
+ }
111
+ function commandProblem(value) {
112
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
113
+ return `a command is ${describeValue(value)}, expected a mapping`;
114
+ }
115
+ const fields = value;
116
+ const problem = fieldProblem(fields) ?? spendsProblem(fields.spends);
117
+ if (problem === null)
118
+ return null;
119
+ const named = isRoutingWord(fields.subject) && isRoutingWord(fields.action) ? `command "${commandSpelling(fields)}"` : "a command";
120
+ return `${named}: ${problem}`;
121
+ }
122
+ function isTopLevel(command) {
123
+ return command.subject === command.action;
124
+ }
125
+ function commandSpelling(command) {
126
+ return isTopLevel(command) ? command.subject : `${command.subject} ${command.action}`;
127
+ }
128
+
129
+ export { SPENDS_GLYPH, CommandExit, isRoutingWord, commandProblem, isTopLevel, commandSpelling };
@@ -1,11 +1,13 @@
1
1
  // @bun
2
2
  import {
3
- parseTaskDeclaration,
4
- messageOf,
5
- isStampableStub,
6
3
  activeOutput,
7
- readRafaBlocks2
8
- } from "./index-2tjmxwvp.js";
4
+ isStampableStub,
5
+ readRafaBlocks
6
+ } from "./index-jfas157k.js";
7
+ import {
8
+ messageOf,
9
+ parseTaskDeclaration
10
+ } from "./index-fzhd3d4y.js";
9
11
  // src/preflight/prerequisites-md.ts
10
12
  import { basename, dirname, join } from "path";
11
13
  var SECTION_AUTO_RE = /\[auto\]/i;
@@ -87,7 +89,7 @@ function readItem(lines, lineIndex, inherited) {
87
89
  const probe = isProbedTag(tag) ? extractProbe(description) : null;
88
90
  return Object.freeze({ raw, description, tag, lineIndex, probe });
89
91
  }
90
- function parsePrerequisites2(content) {
92
+ function parsePrerequisites(content) {
91
93
  const lines = content.split(`
92
94
  `);
93
95
  const items = [];
@@ -130,8 +132,8 @@ function namedItemOf(item) {
130
132
  function isMalformed(item) {
131
133
  return isProbedTag(item.tag) && item.probe === null;
132
134
  }
133
- function planPrerequisites2(content) {
134
- const items = parsePrerequisites2(content);
135
+ function planPrerequisites(content) {
136
+ const items = parsePrerequisites(content);
135
137
  return Object.freeze({
136
138
  required: requiredItemsTagged(items, "auto"),
137
139
  startRequired: requiredItemsTagged(items, "start"),
@@ -147,8 +149,8 @@ function malformedPrerequisiteLines(file, malformed) {
147
149
  `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>`."
148
150
  ];
149
151
  }
150
- function mergePlanPrerequisites2(settings, content) {
151
- const plan = planPrerequisites2(content ?? "");
152
+ function mergePlanPrerequisites(settings, content) {
153
+ const plan = planPrerequisites(content ?? "");
152
154
  return Object.freeze({
153
155
  required: Object.freeze([...settings.prerequisitesRequired, ...plan.required]),
154
156
  startRequired: plan.startRequired,
@@ -157,7 +159,7 @@ function mergePlanPrerequisites2(settings, content) {
157
159
  malformed: plan.malformed
158
160
  });
159
161
  }
160
- function prerequisitesPathForPlan2(planPath) {
162
+ function prerequisitesPathForPlan(planPath) {
161
163
  const stub = PLAN_FILE_RE.exec(basename(planPath))?.[1];
162
164
  if (stub === undefined)
163
165
  return null;
@@ -173,13 +175,13 @@ async function readIfPresent(path) {
173
175
  throw new Error(`${path}: cannot be read (${messageOf(error)})`, { cause: error });
174
176
  }
175
177
  }
176
- async function loadPlanPrerequisites2(planPath, settings) {
177
- const path = prerequisitesPathForPlan2(planPath);
178
+ async function loadPlanPrerequisites(planPath, settings) {
179
+ const path = prerequisitesPathForPlan(planPath);
178
180
  const content = path === null ? null : await readIfPresent(path);
179
- return mergePlanPrerequisites2(settings, content);
181
+ return mergePlanPrerequisites(settings, content);
180
182
  }
181
183
  // src/preflight/run.ts
182
- var PROBE_TIMEOUT_MS2 = 30000;
184
+ var PROBE_TIMEOUT_MS = 30000;
183
185
  var SHELL = "/bin/sh";
184
186
  var PASS = Object.freeze({ outcome: "pass", failure: null });
185
187
  function spawnShell(probe, options) {
@@ -221,13 +223,13 @@ function collect(stream) {
221
223
  };
222
224
  return { text: read(), stop };
223
225
  }
224
- async function runShellProbe2(probe, options) {
226
+ async function runShellProbe(probe, options) {
225
227
  let proc;
226
228
  try {
227
229
  proc = spawnShell(probe, options);
228
230
  } catch (error) {
229
- const stderr = `could not run ${SHELL} in ${options.cwd}: ${messageOf(error)}`;
230
- return Object.freeze({ exitCode: null, stderr, timedOut: false });
231
+ const stderr2 = `could not run ${SHELL} in ${options.cwd}: ${messageOf(error)}`;
232
+ return Object.freeze({ exitCode: null, stderr: stderr2, timedOut: false });
231
233
  }
232
234
  const stderr = collect(proc.stderr);
233
235
  let timedOut = false;
@@ -346,14 +348,14 @@ function contextOf(options) {
346
348
  return {
347
349
  cwd: options.cwd,
348
350
  env: options.env ?? process.env,
349
- timeoutMs: options.timeoutMs ?? PROBE_TIMEOUT_MS2,
350
- runProbe: options.runProbe ?? runShellProbe2,
351
+ timeoutMs: options.timeoutMs ?? PROBE_TIMEOUT_MS,
352
+ runProbe: options.runProbe ?? runShellProbe,
351
353
  request: options.request ?? ((url, init) => fetch(url, init)),
352
354
  warn: options.warn ?? warnThroughActiveOutput,
353
355
  now: options.now ?? (() => performance.now())
354
356
  };
355
357
  }
356
- async function runPreflight2(items, options) {
358
+ async function runPreflight(items, options) {
357
359
  const context = contextOf(options);
358
360
  const checks = [];
359
361
  const knownMissing = [];
@@ -450,7 +452,7 @@ function withoutBlockerComment(line) {
450
452
  }
451
453
  function closedBlockLines(trackerContent) {
452
454
  const inside = new Set;
453
- for (const block of readRafaBlocks2(trackerContent)) {
455
+ for (const block of readRafaBlocks(trackerContent)) {
454
456
  if (!block.closed)
455
457
  continue;
456
458
  for (let line = block.span.first;line <= block.span.last; line += 1) {
@@ -560,8 +562,8 @@ function trackerPathFor(planPath) {
560
562
  }
561
563
 
562
564
  // src/plan/parse.ts
563
- var PLAN_BLOCK_KINDS2 = ["plan", "context", "stage-context"];
564
- var PLAN_HEADER_FIELDS2 = ["stub", "issue", "spec", "release"];
565
+ var PLAN_BLOCK_KINDS = ["plan", "context", "stage-context"];
566
+ var PLAN_HEADER_FIELDS = ["stub", "issue", "spec", "release"];
565
567
  var PLAN_RELEASE_LEVELS = ["patch", "minor", "major", "none"];
566
568
  var TASK_LINES = [
567
569
  ["unchecked", /^- \[ \] (.+)/],
@@ -570,10 +572,10 @@ var TASK_LINES = [
570
572
  ];
571
573
  var STAGE_HEADING = /^# Stage: (.+)/;
572
574
  function isPlanBlockKind(kind) {
573
- return PLAN_BLOCK_KINDS2.includes(kind);
575
+ return PLAN_BLOCK_KINDS.includes(kind);
574
576
  }
575
577
  function isHeaderField(key) {
576
- return PLAN_HEADER_FIELDS2.includes(key);
578
+ return PLAN_HEADER_FIELDS.includes(key);
577
579
  }
578
580
  function isReleaseLevel(value) {
579
581
  return PLAN_RELEASE_LEVELS.includes(value);
@@ -782,8 +784,8 @@ function readHeader(block) {
782
784
  }
783
785
  return readFields(document, line);
784
786
  }
785
- function parsePlan2(markdown) {
786
- const blocks = readRafaBlocks2(markdown);
787
+ function parsePlan(markdown) {
788
+ const blocks = readRafaBlocks(markdown);
787
789
  const checklist = readChecklist(markdown, blocks);
788
790
  const bound = bindBlocks(blocks, checklist.headings);
789
791
  const reading = readHeader(bound.header);
@@ -896,15 +898,15 @@ var RENDERERS = {
896
898
  stage: renderStage,
897
899
  task: renderTask
898
900
  };
899
- function renderInjection2(request) {
901
+ function renderInjection(request) {
900
902
  const { mode, plan, task } = request;
901
903
  if (mode === "full")
902
904
  return { requested: mode, mode, text: plan, fallback: null };
903
- const model = parsePlan2(plan);
905
+ const model = parsePlan(plan);
904
906
  const location = locate(model, task);
905
907
  if (!location.found) {
906
908
  return { requested: mode, mode: "full", text: plan, fallback: location.fallback };
907
909
  }
908
910
  return { requested: mode, mode, text: RENDERERS[mode](model, location.task), fallback: null };
909
911
  }
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 };
912
+ export { escapeBlockerText, splitBlockerComment, findNextTask, updateTrackerLine, writeTrackerBlocker, insertTrackerTask, trackerPathFor, PLAN_BLOCK_KINDS, PLAN_HEADER_FIELDS, PLAN_RELEASE_LEVELS, parsePlan, parsePrerequisites, planPrerequisites, malformedPrerequisiteLines, mergePlanPrerequisites, prerequisitesPathForPlan, loadPlanPrerequisites, PROBE_TIMEOUT_MS, runShellProbe, runPreflight, renderInjection };
@@ -1,11 +1,11 @@
1
1
  // @bun
2
2
  import {
3
- GAP2,
4
- SOURCE_STEP2,
5
- CONFIDENCE_MIN2,
6
- CONFIDENCE_MAX2,
7
- triggerKey2
8
- } from "./index-21jcfatr.js";
3
+ CONFIDENCE_MAX,
4
+ CONFIDENCE_MIN,
5
+ GAP,
6
+ SOURCE_STEP,
7
+ triggerKey
8
+ } from "./index-wp8c28fd.js";
9
9
 
10
10
  // src/learning/bless.ts
11
11
  import { createHash } from "crypto";
@@ -32,19 +32,19 @@ function blessedRecords(held, minConfidence) {
32
32
  function versionOf(instincts) {
33
33
  return createHash("sha256").update(JSON.stringify(instincts)).digest("hex");
34
34
  }
35
- function bless2(held, options) {
35
+ function bless(held, options) {
36
36
  const instincts = blessedRecords(held, options.minConfidence);
37
37
  return { version: versionOf(instincts), instincts };
38
38
  }
39
- function promotable2(held, options) {
39
+ function promotable(held, options) {
40
40
  return blessedRecords(held, options.minConfidence).filter((each) => each.usage_count >= options.after);
41
41
  }
42
42
  // src/learning/merge.ts
43
43
  var HUNDREDTHS2 = 100;
44
- var GAP_H = Math.round(GAP2 * HUNDREDTHS2);
45
- var STEP_H = Math.round(SOURCE_STEP2 * HUNDREDTHS2);
46
- var MIN_H = Math.round(CONFIDENCE_MIN2 * HUNDREDTHS2);
47
- var MAX_H = Math.round(CONFIDENCE_MAX2 * HUNDREDTHS2);
44
+ var GAP_H = Math.round(GAP * HUNDREDTHS2);
45
+ var STEP_H = Math.round(SOURCE_STEP * HUNDREDTHS2);
46
+ var MIN_H = Math.round(CONFIDENCE_MIN * HUNDREDTHS2);
47
+ var MAX_H = Math.round(CONFIDENCE_MAX * HUNDREDTHS2);
48
48
  function hundredths2(confidence) {
49
49
  return Math.round(confidence * HUNDREDTHS2);
50
50
  }
@@ -194,16 +194,16 @@ function settleTrigger(held, incoming, now) {
194
194
  }
195
195
  return settleMany(collapsed, held, now);
196
196
  }
197
- function merge2(held, payload, now) {
197
+ function merge(held, payload, now) {
198
198
  const incoming = payload.instincts.map((record) => withSource(record, payload.source_id));
199
- const keys = [...new Set(incoming.map((record) => triggerKey2(record.trigger)))];
199
+ const keys = [...new Set(incoming.map((record) => triggerKey(record.trigger)))];
200
200
  const outcomes = new Map;
201
201
  for (const key of keys) {
202
- const onKey = (record) => triggerKey2(record.trigger) === key;
202
+ const onKey = (record) => triggerKey(record.trigger) === key;
203
203
  outcomes.set(key, settleTrigger(held.filter(onKey), incoming.filter(onKey), now));
204
204
  }
205
205
  const decisions = payload.instincts.map((record) => {
206
- const outcome = outcomes.get(triggerKey2(record.trigger));
206
+ const outcome = outcomes.get(triggerKey(record.trigger));
207
207
  return {
208
208
  incoming: record,
209
209
  rule: outcome.rules.get(record.action_hash),
@@ -215,4 +215,4 @@ function merge2(held, payload, now) {
215
215
  discarded: keys.flatMap((key) => outcomes.get(key).discarded)
216
216
  };
217
217
  }
218
- export { bless2, promotable2, merge2 };
218
+ export { bless, promotable, merge };