@open-tomato/rafa 0.15.0 → 0.16.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,396 +1,33 @@
1
1
  // @bun
2
- // src/pr/types.ts
3
- var MERGE_METHODS = Object.freeze([
4
- "squash",
5
- "merge",
6
- "rebase"
7
- ]);
8
- function isMergeMethod(value) {
9
- return typeof value === "string" && MERGE_METHODS.includes(value);
10
- }
11
-
12
- // src/utils/declaration.ts
13
- var DECLARATION_KEYS = [
14
- "agent",
15
- "model",
16
- "effort",
17
- "budget",
18
- "tools",
19
- "skills"
20
- ];
21
- var GRANULAR_KEYS = ["model", "effort", "tools"];
22
- var AGENT_OWNED_KEYS = ["model", "tools"];
23
- var MODEL_ALIASES = ["opus", "sonnet", "haiku", "fable"];
24
- var EFFORT_LEVELS = [
25
- "low",
26
- "medium",
27
- "high",
28
- "xhigh",
29
- "max"
30
- ];
31
- var DECLARATION_BLOCK = /\{([^{}]*)\}$/;
32
- var ENTRY_TOKEN = /^([A-Za-z_][A-Za-z0-9_-]*)=(.*)$/;
33
- var FULL_MODEL_NAME = /^claude-[a-z0-9][a-z0-9.-]*$/;
34
- var AGENT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
35
- function isAgentName(value) {
36
- return AGENT_NAME.test(value);
37
- }
38
- var TOOL_NAME = /^[A-Za-z][A-Za-z0-9_-]*$/;
39
- var SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
40
- var BUDGET_FLAG = "--max-budget-usd";
41
- var BUDGET_VALUE = /^(?:0|[1-9]\d{0,5})(?:\.\d{1,6})?$/;
42
- function parseBudgetUsd(value) {
43
- if (!BUDGET_VALUE.test(value))
44
- return null;
45
- const usd = Number(value);
46
- return usd > 0 ? usd : null;
47
- }
48
- function isEffortLevel(value) {
49
- return EFFORT_LEVELS.includes(value);
50
- }
51
- function isModelValue(value) {
52
- if (MODEL_ALIASES.includes(value))
53
- return true;
54
- return FULL_MODEL_NAME.test(value);
55
- }
56
- function parseToolList(value) {
57
- const parts = value.split(",");
58
- if (parts.length === 0)
59
- return null;
60
- const tools = [];
61
- for (const part of parts) {
62
- if (!TOOL_NAME.test(part))
63
- return null;
64
- if (!tools.includes(part))
65
- tools.push(part);
66
- }
67
- return tools;
68
- }
69
- function parseSkillList(value) {
70
- const parts = value.split(",");
71
- if (parts.length === 0)
72
- return null;
73
- const skills = [];
74
- for (const part of parts) {
75
- if (!SKILL_NAME.test(part))
76
- return null;
77
- if (!skills.includes(part))
78
- skills.push(part);
79
- }
80
- return skills;
81
- }
82
- function unusableValue(key, token) {
83
- return { reason: "unusable-value", key, text: token };
84
- }
85
- function isDeclarationKey(key) {
86
- return DECLARATION_KEYS.includes(key);
87
- }
88
- function tokenise(body) {
89
- const trimmed = body.trim();
90
- if (trimmed.length === 0)
91
- return [];
92
- return trimmed.split(/\s+/);
93
- }
94
- function readBlock(raw, body) {
95
- const entries = [];
96
- const extras = [];
97
- const issues = [];
98
- const seen = new Set;
99
- let agent = null;
100
- let model = null;
101
- let effort = null;
102
- let budget = null;
103
- let tools = null;
104
- let skills = null;
105
- for (const token of tokenise(body)) {
106
- const match = token.match(ENTRY_TOKEN);
107
- const key = match?.[1];
108
- const value = match?.[2];
109
- if (key === undefined || value === undefined) {
110
- issues.push({ reason: "stray-token", key: "", text: token });
111
- continue;
112
- }
113
- const entry = { key, value };
114
- entries.push(entry);
115
- if (!isDeclarationKey(key)) {
116
- extras.push(entry);
117
- continue;
118
- }
119
- if (seen.has(key)) {
120
- issues.push({ reason: "duplicate-key", key, text: token });
121
- continue;
122
- }
123
- seen.add(key);
124
- if (key === "agent") {
125
- if (AGENT_NAME.test(value))
126
- agent = value;
127
- else
128
- issues.push(unusableValue(key, token));
129
- continue;
130
- }
131
- if (key === "model") {
132
- if (isModelValue(value))
133
- model = value;
134
- else
135
- issues.push(unusableValue(key, token));
136
- continue;
137
- }
138
- if (key === "effort") {
139
- if (isEffortLevel(value))
140
- effort = value;
141
- else
142
- issues.push(unusableValue(key, token));
143
- continue;
144
- }
145
- if (key === "budget") {
146
- const usd = parseBudgetUsd(value);
147
- if (usd === null)
148
- issues.push(unusableValue(key, token));
149
- else
150
- budget = usd;
151
- continue;
152
- }
153
- if (key === "tools") {
154
- const parsed = parseToolList(value);
155
- if (parsed === null)
156
- issues.push(unusableValue(key, token));
157
- else
158
- tools = parsed;
159
- continue;
160
- }
161
- const named = parseSkillList(value);
162
- if (named === null)
163
- issues.push(unusableValue(key, token));
164
- else
165
- skills = named;
166
- }
167
- if (seen.size === 0)
168
- return null;
169
- return {
170
- raw,
171
- entries,
172
- extras,
173
- issues,
174
- agent,
175
- model,
176
- effort,
177
- budget,
178
- tools,
179
- skills
180
- };
181
- }
182
- function parseTaskDeclaration(taskText) {
183
- const trimmed = taskText.trimEnd();
184
- const match = trimmed.match(DECLARATION_BLOCK);
185
- const raw = match?.[0];
186
- const body = match?.[1];
187
- if (raw === undefined || body === undefined) {
188
- return { text: taskText, declaration: null };
189
- }
190
- const before = trimmed.slice(0, trimmed.length - raw.length).trimEnd();
191
- if (before.length === 0)
192
- return { text: taskText, declaration: null };
193
- const declaration = readBlock(raw, body);
194
- if (declaration === null)
195
- return { text: taskText, declaration: null };
196
- return { text: before, declaration };
197
- }
198
- function stripTaskDeclaration(taskText) {
199
- return parseTaskDeclaration(taskText).text;
200
- }
201
- function budgetArgs(budget) {
202
- return budget === null ? [] : [BUDGET_FLAG, String(budget)];
203
- }
204
- function resolveDeclarationFlags(declaration, agentDeclaresEffort) {
205
- if (declaration === null)
206
- return { args: [], suppressed: [] };
207
- const { agent, effort } = declaration;
208
- const isPresent = (key) => declaration[key] !== null;
209
- const budget = budgetArgs(declaration.budget);
210
- if (agent !== null) {
211
- if (effort === null || agentDeclaresEffort(agent)) {
212
- return { args: ["--agent", agent, ...budget], suppressed: GRANULAR_KEYS.filter(isPresent) };
213
- }
214
- return {
215
- args: ["--agent", agent, "--effort", effort, ...budget],
216
- suppressed: AGENT_OWNED_KEYS.filter(isPresent)
217
- };
218
- }
219
- const args = [];
220
- if (declaration.model !== null)
221
- args.push("--model", declaration.model);
222
- if (declaration.effort !== null)
223
- args.push("--effort", declaration.effort);
224
- args.push(...budget);
225
- if (declaration.tools !== null) {
226
- args.push("--tools", declaration.tools.join(","));
227
- }
228
- return { args, suppressed: [] };
229
- }
230
-
231
- // src/config-sections.ts
232
- function isMapping(value) {
233
- return typeof value === "object" && value !== null && !Array.isArray(value);
234
- }
235
- function describeValue(value) {
236
- if (typeof value === "string")
237
- return JSON.stringify(value);
238
- if (value === null)
239
- return "null";
240
- if (Array.isArray(value))
241
- return "a list";
242
- if (typeof value === "object")
243
- return "a mapping";
244
- return String(value);
245
- }
246
- function messageOf(error) {
247
- return error instanceof Error ? error.message : String(error);
248
- }
249
- var CONFIG_VERSIONS = [1];
250
- var STORE_BACKENDS = ["sqlite", "ndjson"];
251
- var INJECT_MODES = ["full", "stage", "task"];
252
- var OUTPUT_MODES = ["text", "json"];
253
- var CLAUDE_SETTING_SOURCES = ["user", "project", "local"];
254
- var PR_PROVIDERS = ["gh", "none"];
255
- var RELEASE_AUTO = "auto";
256
- function accepted(value) {
257
- return { value, problems: [], extras: [] };
258
- }
259
- function refused(at, raw, expected) {
260
- const problem = `${at.label} is ${describeValue(raw)}, expected ${expected}`;
261
- return { value: undefined, problems: [problem], extras: [] };
262
- }
263
- function refusedWith(problems) {
264
- return { value: undefined, problems, extras: [] };
265
- }
266
- function mapReading(reading, map) {
267
- return reading.value === undefined ? { ...reading, value: undefined } : { ...reading, value: map(reading.value) };
268
- }
269
- function below(at, step) {
270
- return { label: `${at.label}${step}`, key: `${at.key}${step}` };
271
- }
272
- function oneOf(values) {
273
- const expected = `one of: ${values.join(", ")}`;
274
- return (raw, at) => {
275
- const hit = values.find((value) => value === raw);
276
- return hit === undefined ? refused(at, raw, expected) : accepted(hit);
277
- };
278
- }
279
- function text(expected) {
280
- return (raw, at) => typeof raw === "string" && raw.trim() !== "" ? accepted(raw) : refused(at, raw, expected);
281
- }
282
- var flag = (raw, at) => typeof raw === "boolean" ? accepted(raw) : refused(at, raw, "true or false");
283
- var mergeMethod = oneOf(MERGE_METHODS);
284
- var usdAmount = (raw, at) => {
285
- const usd = typeof raw === "number" ? parseBudgetUsd(String(raw)) : null;
286
- return usd === null ? refused(at, raw, "a number of US dollars above zero, at most six digits either side of the point") : accepted(usd);
287
- };
288
- var issueNumber = (raw, at) => typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0 ? accepted(raw) : refused(at, raw, "an issue number, a whole number above zero");
289
- var dayCount = (raw, at) => typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0 ? accepted(raw) : refused(at, raw, "a number of days, a whole number above zero");
290
- var releaseEnabled = (raw, at) => typeof raw === "boolean" || raw === RELEASE_AUTO ? accepted(raw) : refused(at, raw, `true, false or ${RELEASE_AUTO}`);
291
- var GITHUB_LOGIN = /^[A-Za-z0-9][A-Za-z0-9-]*(?:\[bot\])?$/;
292
- function isGitHubLogin(value) {
293
- return typeof value === "string" && GITHUB_LOGIN.test(value);
294
- }
295
- var githubLogin = (raw, at) => isGitHubLogin(raw) ? accepted(raw) : refused(at, raw, "a GitHub login");
296
- function listOf(item, expected) {
297
- return (raw, at) => {
298
- if (!Array.isArray(raw))
299
- return refused(at, raw, `a list of ${expected}`);
300
- const readings = raw.map((entry, index) => item(entry, below(at, `[${index}]`)));
301
- const problems = readings.flatMap((reading) => reading.problems);
302
- const extras = readings.flatMap((reading) => reading.extras);
303
- if (problems.length > 0)
304
- return { value: undefined, problems, extras };
305
- const values = readings.flatMap((reading) => reading.value === undefined ? [] : [reading.value]);
306
- return { value: Object.freeze(values), problems, extras };
307
- };
308
- }
309
- function subsetOf(values) {
310
- const expected = `a comma-separated subset of: ${values.join(", ")}`;
311
- return (raw, at) => {
312
- if (typeof raw !== "string")
313
- return refused(at, raw, expected);
314
- const named = [];
315
- for (const entry of raw.split(",")) {
316
- const hit = values.find((value) => value === entry.trim());
317
- if (hit === undefined || named.includes(hit))
318
- return refused(at, raw, expected);
319
- named.push(hit);
320
- }
321
- return accepted(Object.freeze(named));
322
- };
323
- }
324
- var itemText = text("a non-empty string");
325
- function readKeyedItem(shape, raw, at) {
326
- const choices = shape.kinds.join(", ");
327
- if (!isMapping(raw))
328
- return refused(at, raw, `a mapping naming one of: ${choices}`);
329
- const entries = Object.entries(raw);
330
- const kinds = shape.kinds.filter((kind2) => entries.some(([name]) => name === kind2));
331
- const [kind] = kinds;
332
- if (kind === undefined)
333
- return refusedWith([`${at.label} names none of: ${choices}`]);
334
- if (kinds.length > 1) {
335
- const named2 = kinds.join(" and ");
336
- return refusedWith([`${at.label} names ${named2}, expected exactly one of: ${choices}`]);
337
- }
338
- const optionalKeys = shape.optionalFor(kind);
339
- const problems = [];
340
- const extras = [];
341
- const optional = new Map;
342
- let named;
343
- for (const [name, value] of entries) {
344
- if (name !== kind && !optionalKeys.includes(name)) {
345
- extras.push({ key: `${at.key}.${name}`, value });
346
- continue;
347
- }
348
- if (name !== kind && value === null)
349
- continue;
350
- const reading = itemText(value, below(at, `.${name}`));
351
- problems.push(...reading.problems);
352
- if (reading.value === undefined)
353
- continue;
354
- if (name === kind)
355
- named = reading.value;
356
- else
357
- optional.set(name, reading.value);
358
- }
359
- return problems.length > 0 || named === undefined ? { value: undefined, problems, extras } : { value: { kind, named, optional }, problems, extras };
360
- }
361
- var PREREQUISITE_KINDS = ["tool", "env", "service", "lsp"];
362
- var REQUIRED_ITEM_KEYS = [...PREREQUISITE_KINDS, "probe"];
363
- var OPTIONAL_ITEM_KEYS = [...REQUIRED_ITEM_KEYS, "reason"];
364
- var requiredPrerequisite = (raw, at) => {
365
- const shape = { kinds: PREREQUISITE_KINDS, optionalFor: () => ["probe"] };
366
- return mapReading(readKeyedItem(shape, raw, at), (item) => Object.freeze({
367
- kind: item.kind,
368
- name: item.named,
369
- probe: item.optional.get("probe") ?? null
370
- }));
371
- };
372
- var optionalPrerequisite = (raw, at) => {
373
- const shape = { kinds: PREREQUISITE_KINDS, optionalFor: () => ["probe", "reason"] };
374
- return mapReading(readKeyedItem(shape, raw, at), (item) => Object.freeze({
375
- kind: item.kind,
376
- name: item.named,
377
- probe: item.optional.get("probe") ?? null,
378
- reason: item.optional.get("reason") ?? null
379
- }));
380
- };
381
- var MODULE_SOURCE_KINDS = ["npm", "github", "path"];
382
- var MODULE_SOURCE_KEYS = [...MODULE_SOURCE_KINDS, "ref"];
383
- var moduleSource = (raw, at) => {
384
- const shape = {
385
- kinds: MODULE_SOURCE_KINDS,
386
- optionalFor: (kind) => kind === "github" ? ["ref"] : []
387
- };
388
- return mapReading(readKeyedItem(shape, raw, at), (item) => Object.freeze({
389
- kind: item.kind,
390
- location: item.named,
391
- ref: item.optional.get("ref") ?? null
392
- }));
393
- };
2
+ import {
3
+ CLAUDE_SETTING_SOURCES,
4
+ CONFIG_VERSIONS,
5
+ INJECT_MODES,
6
+ MODULE_SOURCE_KEYS,
7
+ OPTIONAL_ITEM_KEYS,
8
+ OUTPUT_MODES,
9
+ PR_PROVIDERS,
10
+ RELEASE_AUTO,
11
+ REQUIRED_ITEM_KEYS,
12
+ STORE_BACKENDS,
13
+ dayCount,
14
+ describeValue,
15
+ flag,
16
+ githubLogin,
17
+ isMapping,
18
+ issueNumber,
19
+ listOf,
20
+ mergeMethod,
21
+ messageOf,
22
+ moduleSource,
23
+ oneOf,
24
+ optionalPrerequisite,
25
+ releaseEnabled,
26
+ requiredPrerequisite,
27
+ subsetOf,
28
+ text,
29
+ usdAmount
30
+ } from "./index-n3rw8rhr.js";
394
31
 
395
32
  // src/config-schema.ts
396
33
  import { join } from "path";
@@ -425,7 +62,8 @@ var CONFIG_DEFAULTS = Object.freeze({
425
62
  releaseHeading: "## {version} \u2014 {date}, {title}",
426
63
  cleanupStaleDays: 30,
427
64
  cleanupWorktreeIdleDays: 7,
428
- cleanupKeep: Object.freeze([])
65
+ cleanupKeep: Object.freeze([]),
66
+ dangerousAcceptStaleRefs: false
429
67
  });
430
68
  var directory = text("a directory path");
431
69
  var trackerKind = text("a tracker kind name");
@@ -511,6 +149,11 @@ var SETTINGS = {
511
149
  key: "cleanup.keep",
512
150
  read: listOf(text("a glob pattern"), "glob patterns"),
513
151
  cli: false
152
+ },
153
+ dangerousAcceptStaleRefs: {
154
+ key: "dangerous.acceptStaleRefs",
155
+ read: flag,
156
+ cli: false
514
157
  }
515
158
  };
516
159
  var SETTING_NAMES = Object.keys(SETTINGS);
@@ -608,7 +251,8 @@ function readLayer(rawOf, atOf) {
608
251
  releaseHeading: read("releaseHeading"),
609
252
  cleanupStaleDays: read("cleanupStaleDays"),
610
253
  cleanupWorktreeIdleDays: read("cleanupWorktreeIdleDays"),
611
- cleanupKeep: read("cleanupKeep")
254
+ cleanupKeep: read("cleanupKeep"),
255
+ dangerousAcceptStaleRefs: read("dangerousAcceptStaleRefs")
612
256
  };
613
257
  return { layer, problems, extras };
614
258
  }
@@ -881,4 +525,4 @@ function activeOutputMode() {
881
525
  return activeMode;
882
526
  }
883
527
 
884
- export { MERGE_METHODS, isMergeMethod, isAgentName, BUDGET_FLAG, parseTaskDeclaration, stripTaskDeclaration, resolveDeclarationFlags, isMapping, describeValue, messageOf, CONFIG_VERSIONS, STORE_BACKENDS, INJECT_MODES, OUTPUT_MODES, CLAUDE_SETTING_SOURCES, PR_PROVIDERS, RELEASE_AUTO, isGitHubLogin, listOf, PREREQUISITE_KINDS, requiredPrerequisite, optionalPrerequisite, MODULE_SOURCE_KINDS, CONFIG_FILE, CONFIG_DEFAULTS, ConfigError, configFilePath, parseConfigText, resolveConfig, createTextOutput, activeOutput, activeOutputMode, RAFA_BLOCK_KINDS, isRafaBlockKind, readRafaBlocks };
528
+ export { CONFIG_FILE, CONFIG_DEFAULTS, SETTINGS, ConfigError, configFilePath, parseConfigText, resolveConfig, createTextOutput, activeOutput, activeOutputMode, RAFA_BLOCK_KINDS, isRafaBlockKind, readRafaBlocks };