@open-tomato/rafa 0.46.0 → 0.48.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 +70 -37
- package/dist/adapters/logger/settings.d.ts +2 -2
- package/dist/bugs/places.d.ts +1 -1
- package/dist/bugs/record.d.ts +1 -1
- package/dist/bundled/skills/dev-planner/SKILL.md +2 -2
- package/dist/cli.js +73457 -72996
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +6 -4
- package/dist/config/shape.d.ts +20 -15
- package/dist/config/templates.d.ts +64 -0
- package/dist/config-registry.d.ts +21 -12
- package/dist/config-schema-board-project.d.ts +3 -3
- package/dist/config-schema-bugs.d.ts +3 -3
- package/dist/config-schema-checks.d.ts +114 -0
- package/dist/config-schema-errors.d.ts +3 -3
- package/dist/config-schema-features.d.ts +4 -4
- package/dist/config-schema-hub.d.ts +6 -4
- package/dist/config-schema-issues.d.ts +2 -2
- package/dist/config-schema-logger.d.ts +3 -3
- package/dist/config-schema-loop-continue.d.ts +3 -3
- package/dist/config-schema-loop-retries.d.ts +4 -4
- package/dist/config-schema-release.d.ts +23 -24
- package/dist/config-schema-tests.d.ts +35 -27
- package/dist/config-schema-triage.d.ts +3 -3
- package/dist/config-schema-wrap-up.d.ts +4 -4
- package/dist/core/command/command.d.ts +1 -1
- package/dist/core/command/confirm.d.ts +11 -5
- package/dist/core/command/global-flags.d.ts +25 -0
- package/dist/core/command/index.d.ts +47 -23
- package/dist/core/command/registry-types.d.ts +4 -4
- package/dist/core/command/shared-flags.d.ts +40 -0
- package/dist/core/command/types.d.ts +3 -2
- package/dist/core/config/branch-template.d.ts +2 -0
- package/dist/core/config/config-items.d.ts +1 -1
- package/dist/core/config/config-load-module.d.ts +43 -0
- package/dist/core/config/config-load.d.ts +43 -12
- package/dist/core/config/config-origins.d.ts +31 -30
- package/dist/core/config/config-schema.d.ts +11 -0
- package/dist/core/config/config-sections.d.ts +15 -14
- package/dist/core/config/config.d.ts +90 -25
- package/dist/core/config/core-section.d.ts +1 -1
- package/dist/core/config/default-routing.d.ts +1 -1
- package/dist/core/config/index.d.ts +14 -10
- package/dist/core/config/merge-method.d.ts +40 -0
- package/dist/core/config/scope.d.ts +2 -2
- package/dist/core/config/section.d.ts +81 -1
- package/dist/core/config/sections.d.ts +17 -6
- package/dist/core/git/gh-runner.d.ts +1 -1
- package/dist/core/git/git.d.ts +34 -0
- package/dist/core/git/index.d.ts +13 -8
- package/dist/core/loop/claude.d.ts +11 -5
- package/dist/core/loop/hop-record.d.ts +6 -6
- package/dist/core/loop/index.d.ts +9 -8
- package/dist/core/loop/session-record-parse.d.ts +9 -2
- package/dist/core/loop/sessions.d.ts +23 -11
- package/dist/core/loop/suite-failure.d.ts +8 -6
- package/dist/core/output/active.d.ts +1 -1
- package/dist/core/plan/block-reader.d.ts +1 -1
- package/dist/core/runtime/identity.d.ts +13 -0
- package/dist/core/runtime/index.d.ts +12 -6
- package/dist/effort/store/check-rows.d.ts +1 -1
- package/dist/effort/store/commit-stats.d.ts +1 -1
- package/dist/effort/store/index.js +7 -8
- package/dist/effort/store/merge-commit-gaps.d.ts +1 -1
- package/dist/effort/store/plan-stubs.d.ts +1 -1
- package/dist/effort/store/session-row-types.d.ts +2 -2
- package/dist/errors/rafa-codes.d.ts +1 -1
- package/dist/index-2xzkzwm6.js +670 -0
- package/dist/index-ajv88fkm.js +448 -0
- package/dist/{index-ykggr043.js → index-fpgmdmww.js} +13 -5
- package/dist/index-g91ys6kw.js +249 -0
- package/dist/{index-cy98y87p.js → index-jx3x70xh.js} +1111 -638
- package/dist/{index-gvek4r8m.js → index-m672ptpg.js} +84 -26
- package/dist/{index-39kbcw68.js → index-w5qbpdtp.js} +415 -842
- package/dist/{index-gqz4jn6j.js → index-z4r20zwr.js} +8974 -11438
- package/dist/{index-j4k2vdz3.js → index-zsak0jy6.js} +124 -290
- package/dist/index.js +24940 -18766
- package/dist/learning/index.js +221 -12
- package/dist/plan/index.js +10 -9
- package/dist/ports/index.d.ts +7 -7
- package/dist/ports/learning.d.ts +5 -4
- package/dist/ports/spec-review.d.ts +1 -1
- package/dist/ready-gax3hhtt.js +241 -0
- package/dist/release-templates/release-bot-fragment.yml +6 -6
- package/dist/release-templates/release-publish.yml +8 -8
- package/dist/release-templates/release-settle.yml +8 -7
- package/dist/release-templates/release-tag.yml +8 -7
- package/package.json +53 -2
- package/dist/index-77ajfffn.js +0 -223
- package/dist/index-jh1r4kcn.js +0 -1067
- package/dist/index-z1w83f81.js +0 -4
- package/dist/pr/checks.d.ts +0 -133
- package/dist/pr/types.d.ts +0 -422
- package/dist/ready-4f8edezt.js +0 -2016
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
CORE_SECTION
|
|
4
|
+
} from "./index-m672ptpg.js";
|
|
5
|
+
import {
|
|
6
|
+
BUSY_TIMEOUT_MAX_MS,
|
|
7
|
+
BUSY_TIMEOUT_MIN_MS,
|
|
8
|
+
describeValue,
|
|
9
|
+
isBusyTimeoutMs,
|
|
10
|
+
messageOf
|
|
11
|
+
} from "./index-fpgmdmww.js";
|
|
12
|
+
|
|
13
|
+
// packages/rafa/src/core/adapters/registry.ts
|
|
14
|
+
var REFUSAL = "adapter registry";
|
|
15
|
+
var PORT_VERSIONS = Object.freeze({
|
|
16
|
+
tracker: 1,
|
|
17
|
+
store: 1,
|
|
18
|
+
learning: 1,
|
|
19
|
+
output: 1,
|
|
20
|
+
planner: 1,
|
|
21
|
+
sync: 1,
|
|
22
|
+
logger: 1
|
|
23
|
+
});
|
|
24
|
+
var SERVED_VERSIONS = new Map(Object.entries(PORT_VERSIONS));
|
|
25
|
+
var PORT_TYPE_LIST = [...SERVED_VERSIONS.keys()].join(", ");
|
|
26
|
+
function checkPortType(port) {
|
|
27
|
+
if (!SERVED_VERSIONS.has(port)) {
|
|
28
|
+
throw new TypeError(`${REFUSAL}: port is ${describeValue(port)}, expected one of: ${PORT_TYPE_LIST}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function accept(adapter, held) {
|
|
32
|
+
if (typeof adapter !== "object" || adapter === null) {
|
|
33
|
+
throw new TypeError(`${REFUSAL}: an adapter is ${describeValue(adapter)}, expected a mapping`);
|
|
34
|
+
}
|
|
35
|
+
const { port, kind, portVersion, create } = adapter;
|
|
36
|
+
checkPortType(port);
|
|
37
|
+
if (typeof kind !== "string" || kind === "") {
|
|
38
|
+
throw new TypeError(`${REFUSAL}: a ${port} adapter has kind ${describeValue(kind)}, expected a non-empty name`);
|
|
39
|
+
}
|
|
40
|
+
const key = `${port}/${kind}`;
|
|
41
|
+
if (typeof create !== "function") {
|
|
42
|
+
throw new TypeError(`${REFUSAL}: ${key} has create ${describeValue(create)}, expected a function`);
|
|
43
|
+
}
|
|
44
|
+
const served = SERVED_VERSIONS.get(port);
|
|
45
|
+
if (portVersion !== served) {
|
|
46
|
+
throw new Error(`${REFUSAL}: ${key} implements ${port} port version ${describeValue(portVersion)},` + ` and core serves ${port} port version ${served}`);
|
|
47
|
+
}
|
|
48
|
+
if (held.some((other) => other.port === port && other.kind === kind)) {
|
|
49
|
+
throw new Error(`${REFUSAL}: ${key} is already registered`);
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze({ port, kind, portVersion, create });
|
|
52
|
+
}
|
|
53
|
+
function indexByPort(adapters) {
|
|
54
|
+
const only = (port) => new Map(adapters.filter((adapter) => adapter.port === port).map((adapter) => [adapter.kind, adapter]));
|
|
55
|
+
return {
|
|
56
|
+
tracker: only("tracker"),
|
|
57
|
+
store: only("store"),
|
|
58
|
+
learning: only("learning"),
|
|
59
|
+
output: only("output"),
|
|
60
|
+
planner: only("planner"),
|
|
61
|
+
sync: only("sync"),
|
|
62
|
+
logger: only("logger")
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function createAdapterRegistry(adapters = []) {
|
|
66
|
+
const held = adapters.reduce((accepted, adapter) => [...accepted, accept(adapter, accepted)], []);
|
|
67
|
+
const byPort = indexByPort(held);
|
|
68
|
+
const registry = {
|
|
69
|
+
register: (adapter) => createAdapterRegistry([...held, adapter]),
|
|
70
|
+
find: (port, kind) => SERVED_VERSIONS.has(port) ? byPort[port].get(kind) : undefined,
|
|
71
|
+
resolve: (port, kind) => {
|
|
72
|
+
checkPortType(port);
|
|
73
|
+
const adapter = byPort[port].get(kind);
|
|
74
|
+
if (adapter !== undefined)
|
|
75
|
+
return adapter;
|
|
76
|
+
const registered = [...byPort[port].keys()];
|
|
77
|
+
const listed = registered.length === 0 ? "none" : registered.join(", ");
|
|
78
|
+
throw new Error(`${REFUSAL}: no ${port} adapter is registered as ${describeValue(kind)};` + ` registered: ${listed}`);
|
|
79
|
+
},
|
|
80
|
+
kinds: (port) => {
|
|
81
|
+
checkPortType(port);
|
|
82
|
+
return [...byPort[port].keys()];
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return Object.freeze(registry);
|
|
86
|
+
}
|
|
87
|
+
var EMPTY_ADAPTER_REGISTRY = createAdapterRegistry();
|
|
88
|
+
var COMPOSITION_ROOT = "src/adapter-registry.ts";
|
|
89
|
+
var active = EMPTY_ADAPTER_REGISTRY;
|
|
90
|
+
function holdsNone(registry) {
|
|
91
|
+
return [...SERVED_VERSIONS.keys()].every((port) => registry.kinds(port).length === 0);
|
|
92
|
+
}
|
|
93
|
+
function registerAdapters(adapters) {
|
|
94
|
+
const previous = active;
|
|
95
|
+
active = adapters.reduce((registry, adapter) => registry.register(adapter), previous);
|
|
96
|
+
return previous;
|
|
97
|
+
}
|
|
98
|
+
function restoreAdapters(registry) {
|
|
99
|
+
if (registry === CORE_ADAPTER_REGISTRY) {
|
|
100
|
+
throw new TypeError(`${REFUSAL}: CORE_ADAPTER_REGISTRY reads the active registry and cannot be made the active one;` + " restore what registerAdapters or activeAdapterRegistry answered");
|
|
101
|
+
}
|
|
102
|
+
active = registry;
|
|
103
|
+
}
|
|
104
|
+
function activeAdapterRegistry() {
|
|
105
|
+
return active;
|
|
106
|
+
}
|
|
107
|
+
function registered() {
|
|
108
|
+
if (holdsNone(active)) {
|
|
109
|
+
throw new Error(`${REFUSAL}: no adapter is registered: call registerCoreAdapters() from ${COMPOSITION_ROOT}` + " before reading CORE_ADAPTER_REGISTRY");
|
|
110
|
+
}
|
|
111
|
+
return active;
|
|
112
|
+
}
|
|
113
|
+
var CORE_ADAPTER_REGISTRY = Object.freeze({
|
|
114
|
+
register: (adapter) => registered().register(adapter),
|
|
115
|
+
find: (port, kind) => registered().find(port, kind),
|
|
116
|
+
resolve: (port, kind) => registered().resolve(port, kind),
|
|
117
|
+
kinds: (port) => registered().kinds(port)
|
|
118
|
+
});
|
|
119
|
+
// packages/rafa/src/core/command/command.ts
|
|
120
|
+
var MAX_EXIT_CODE = 255;
|
|
121
|
+
|
|
122
|
+
class CommandExit extends Error {
|
|
123
|
+
exitCode;
|
|
124
|
+
constructor(exitCode, message = "", options) {
|
|
125
|
+
super(message, options);
|
|
126
|
+
if (!Number.isInteger(exitCode) || exitCode < 0 || exitCode > MAX_EXIT_CODE) {
|
|
127
|
+
throw new TypeError(`CommandExit: exit code is ${describeValue(exitCode)}, expected a whole number from 0 to ${MAX_EXIT_CODE}`);
|
|
128
|
+
}
|
|
129
|
+
this.name = "CommandExit";
|
|
130
|
+
this.exitCode = exitCode;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function isTopLevel(command) {
|
|
134
|
+
return command.subject === command.action;
|
|
135
|
+
}
|
|
136
|
+
function commandSpelling(command) {
|
|
137
|
+
return isTopLevel(command) ? command.subject : `${command.subject} ${command.action}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// packages/rafa/src/core/command/confirm.ts
|
|
141
|
+
import { createInterface } from "readline";
|
|
142
|
+
var YES_ANSWERS = Object.freeze(["y", "yes"]);
|
|
143
|
+
function createLinePrompter(input, output) {
|
|
144
|
+
const buffered = [];
|
|
145
|
+
const waiting = [];
|
|
146
|
+
let ended = false;
|
|
147
|
+
const lines = createInterface({ input, terminal: false, crlfDelay: Infinity });
|
|
148
|
+
lines.on("line", (line) => {
|
|
149
|
+
const reader = waiting.shift();
|
|
150
|
+
if (reader === undefined)
|
|
151
|
+
buffered.push(line);
|
|
152
|
+
else
|
|
153
|
+
reader(line);
|
|
154
|
+
});
|
|
155
|
+
lines.on("close", () => {
|
|
156
|
+
ended = true;
|
|
157
|
+
for (const reader of waiting.splice(0))
|
|
158
|
+
reader(null);
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
say: (text) => {
|
|
162
|
+
output.write(`${text}
|
|
163
|
+
`);
|
|
164
|
+
},
|
|
165
|
+
ask: async (question) => {
|
|
166
|
+
output.write(question);
|
|
167
|
+
const next = buffered.shift();
|
|
168
|
+
if (next !== undefined)
|
|
169
|
+
return next;
|
|
170
|
+
if (ended)
|
|
171
|
+
return null;
|
|
172
|
+
return new Promise((settle) => {
|
|
173
|
+
waiting.push(settle);
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
close: () => {
|
|
177
|
+
lines.close();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function lazyPrompter(open) {
|
|
182
|
+
let prompter = null;
|
|
183
|
+
const askLine = async (question) => {
|
|
184
|
+
prompter ??= open();
|
|
185
|
+
return prompter.ask(question);
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
askLine,
|
|
189
|
+
ask: async (question) => {
|
|
190
|
+
const answer = await askLine(question);
|
|
191
|
+
return answer !== null && YES_ANSWERS.includes(answer.trim().toLowerCase());
|
|
192
|
+
},
|
|
193
|
+
close: () => {
|
|
194
|
+
prompter?.close();
|
|
195
|
+
prompter = null;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// packages/rafa/src/core/command/global-flags.ts
|
|
200
|
+
var GLOBAL_FLAGS = Object.freeze([
|
|
201
|
+
{ spelling: "--output=json", note: "NDJSON events instead of text (also RAFA_OUTPUT=json)" },
|
|
202
|
+
{ spelling: "--output=events", note: "one rafa\xB7 line per loop event (also RAFA_OUTPUT=events)" },
|
|
203
|
+
{ spelling: "-v, --verbose", note: "up to 3 times, or --verbose=N (also RAFA_VERBOSITY=N)" },
|
|
204
|
+
{ spelling: "--version", note: 'print "rafa <version>" and exit; typed alone, no short form' }
|
|
205
|
+
]);
|
|
206
|
+
// packages/rafa/src/core/command/running.ts
|
|
207
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
208
|
+
var scopes = new AsyncLocalStorage;
|
|
209
|
+
var running = null;
|
|
210
|
+
function runningCommand() {
|
|
211
|
+
return scopes.getStore() ?? running;
|
|
212
|
+
}
|
|
213
|
+
// packages/rafa/src/core/command/shared-flags.ts
|
|
214
|
+
var HINT_FLAG = "hint";
|
|
215
|
+
var HINT_FLAG_SPEC = Object.freeze({
|
|
216
|
+
name: HINT_FLAG,
|
|
217
|
+
description: "Ends by naming the one step that follows, asking it where there is a terminal to answer on;" + " `--no-hint` reads nothing and prints nothing.",
|
|
218
|
+
type: "boolean",
|
|
219
|
+
default: true
|
|
220
|
+
});
|
|
221
|
+
var DEFAULT_CI_TIMEOUT_MIN = 20;
|
|
222
|
+
// package.json
|
|
223
|
+
var version = "0.48.0";
|
|
224
|
+
|
|
225
|
+
// packages/rafa/src/core/command/version.ts
|
|
226
|
+
var RAFA_VERSION = version;
|
|
227
|
+
// packages/rafa/src/core/git/git.ts
|
|
228
|
+
import { spawnSync } from "child_process";
|
|
229
|
+
function createGitRunner(cwd) {
|
|
230
|
+
return (args) => {
|
|
231
|
+
const result = spawnSync("git", [...args], {
|
|
232
|
+
cwd,
|
|
233
|
+
encoding: "utf8",
|
|
234
|
+
env: { ...process.env, LC_ALL: "C" }
|
|
235
|
+
});
|
|
236
|
+
if (result.error !== undefined) {
|
|
237
|
+
return { ok: false, stdout: "", stderr: `could not run git in ${cwd}: ${messageOf(result.error)}` };
|
|
238
|
+
}
|
|
239
|
+
return { ok: result.status === 0, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function gitSaid(result) {
|
|
243
|
+
return [result.stderr, result.stdout].map((stream) => stream.trim()).filter((stream) => stream !== "").join(`
|
|
244
|
+
`);
|
|
245
|
+
}
|
|
246
|
+
var UNTRACKED_PREFIX = "?? ";
|
|
247
|
+
function parseWorkingTree(stdout) {
|
|
248
|
+
const entries = stdout.split(`
|
|
249
|
+
`).map((line) => line.replace(/\r$/, "")).filter((line) => line.trim() !== "");
|
|
250
|
+
const tracked = entries.filter((line) => !line.startsWith(UNTRACKED_PREFIX));
|
|
251
|
+
const untracked = entries.filter((line) => line.startsWith(UNTRACKED_PREFIX)).map((line) => unquoteGitPath(line.slice(UNTRACKED_PREFIX.length)));
|
|
252
|
+
return {
|
|
253
|
+
clean: entries.length === 0,
|
|
254
|
+
entries: Object.freeze(entries),
|
|
255
|
+
tracked: Object.freeze(tracked),
|
|
256
|
+
untracked: Object.freeze(untracked)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
var C_ESCAPES = {
|
|
260
|
+
a: 7,
|
|
261
|
+
b: 8,
|
|
262
|
+
f: 12,
|
|
263
|
+
n: 10,
|
|
264
|
+
r: 13,
|
|
265
|
+
t: 9,
|
|
266
|
+
v: 11,
|
|
267
|
+
"\\": 92,
|
|
268
|
+
'"': 34
|
|
269
|
+
};
|
|
270
|
+
var OCTAL_ESCAPE = /^[0-7]{3}$/;
|
|
271
|
+
function unquoteGitPath(raw) {
|
|
272
|
+
if (raw.length < 2 || !raw.startsWith('"') || !raw.endsWith('"'))
|
|
273
|
+
return raw;
|
|
274
|
+
const body = raw.slice(1, -1);
|
|
275
|
+
const bytes = [];
|
|
276
|
+
const encoder = new TextEncoder;
|
|
277
|
+
for (let at = 0;at < body.length; at += 1) {
|
|
278
|
+
const char = body.charAt(at);
|
|
279
|
+
if (char !== "\\") {
|
|
280
|
+
bytes.push(...encoder.encode(char));
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const octal = body.slice(at + 1, at + 4);
|
|
284
|
+
if (OCTAL_ESCAPE.test(octal)) {
|
|
285
|
+
bytes.push(Number.parseInt(octal, 8));
|
|
286
|
+
at += 3;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const escaped = C_ESCAPES[body.charAt(at + 1)];
|
|
290
|
+
if (escaped === undefined) {
|
|
291
|
+
bytes.push(...encoder.encode(char));
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
bytes.push(escaped);
|
|
295
|
+
at += 1;
|
|
296
|
+
}
|
|
297
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
298
|
+
}
|
|
299
|
+
// packages/rafa/src/core/git/commit.ts
|
|
300
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
301
|
+
var DEFAULT_COMMIT_TYPE = "chore";
|
|
302
|
+
var TEST_NOUN_WINDOW = 40;
|
|
303
|
+
var FIX_VERBS = ["fix", "repair", "correct", "resolve"];
|
|
304
|
+
var REFACTOR_VERBS = [
|
|
305
|
+
"remove",
|
|
306
|
+
"delete",
|
|
307
|
+
"drop",
|
|
308
|
+
"move",
|
|
309
|
+
"rename",
|
|
310
|
+
"relocate",
|
|
311
|
+
"extract",
|
|
312
|
+
"split",
|
|
313
|
+
"inline",
|
|
314
|
+
"collapse"
|
|
315
|
+
];
|
|
316
|
+
var FEAT_VERBS = [
|
|
317
|
+
"add",
|
|
318
|
+
"implement",
|
|
319
|
+
"introduce",
|
|
320
|
+
"register",
|
|
321
|
+
"extend",
|
|
322
|
+
"call",
|
|
323
|
+
"wire",
|
|
324
|
+
"expose",
|
|
325
|
+
"parse",
|
|
326
|
+
"strip",
|
|
327
|
+
"enforce",
|
|
328
|
+
"generate"
|
|
329
|
+
];
|
|
330
|
+
var CHORE_VERBS = [
|
|
331
|
+
"capture",
|
|
332
|
+
"measure",
|
|
333
|
+
"run",
|
|
334
|
+
"sweep",
|
|
335
|
+
"verify",
|
|
336
|
+
"ensure",
|
|
337
|
+
"regenerate",
|
|
338
|
+
"update",
|
|
339
|
+
"gitignore",
|
|
340
|
+
"take",
|
|
341
|
+
"bump",
|
|
342
|
+
"pin"
|
|
343
|
+
];
|
|
344
|
+
function openingVerbs(verbs) {
|
|
345
|
+
return new RegExp(`^(?:${verbs.join("|")})\\b`, "i");
|
|
346
|
+
}
|
|
347
|
+
var COMMIT_TYPE_RULES = [
|
|
348
|
+
{
|
|
349
|
+
type: "test",
|
|
350
|
+
pattern: new RegExp(`^.{0,${TEST_NOUN_WINDOW}}?\\btests?\\b`, "i")
|
|
351
|
+
},
|
|
352
|
+
{ type: "docs", pattern: /\.md\b/i },
|
|
353
|
+
{ type: "fix", pattern: openingVerbs(FIX_VERBS) },
|
|
354
|
+
{ type: "refactor", pattern: openingVerbs(REFACTOR_VERBS) },
|
|
355
|
+
{ type: "feat", pattern: openingVerbs(FEAT_VERBS) },
|
|
356
|
+
{ type: "chore", pattern: openingVerbs(CHORE_VERBS) }
|
|
357
|
+
];
|
|
358
|
+
var MAX_SUBJECT_LENGTH = 72;
|
|
359
|
+
var FALLBACK_DESCRIPTION = "complete the scoped task";
|
|
360
|
+
var MAX_MESSAGE_CHARS = 4000;
|
|
361
|
+
function normaliseTaskText(taskText) {
|
|
362
|
+
return taskText.replace(/\s+/g, " ").trim();
|
|
363
|
+
}
|
|
364
|
+
function inferCommitType(taskText) {
|
|
365
|
+
const text = normaliseTaskText(taskText);
|
|
366
|
+
for (const rule of COMMIT_TYPE_RULES) {
|
|
367
|
+
if (rule.pattern.test(text))
|
|
368
|
+
return rule.type;
|
|
369
|
+
}
|
|
370
|
+
return DEFAULT_COMMIT_TYPE;
|
|
371
|
+
}
|
|
372
|
+
function countBackticks(text) {
|
|
373
|
+
let count = 0;
|
|
374
|
+
for (const character of text) {
|
|
375
|
+
if (character === "`")
|
|
376
|
+
count += 1;
|
|
377
|
+
}
|
|
378
|
+
return count;
|
|
379
|
+
}
|
|
380
|
+
function balanceCodeSpans(text) {
|
|
381
|
+
let result = text;
|
|
382
|
+
while (countBackticks(result) % 2 === 1) {
|
|
383
|
+
const lastSpace = result.lastIndexOf(" ");
|
|
384
|
+
if (lastSpace <= 0)
|
|
385
|
+
return result.replace(/`/g, "");
|
|
386
|
+
result = result.slice(0, lastSpace).trimEnd();
|
|
387
|
+
}
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
function stripTrailingPeriod(text) {
|
|
391
|
+
if (!text.endsWith("."))
|
|
392
|
+
return text;
|
|
393
|
+
const withoutDot = text.slice(0, -1);
|
|
394
|
+
const lastToken = withoutDot.slice(withoutDot.lastIndexOf(" ") + 1);
|
|
395
|
+
if (lastToken.includes("."))
|
|
396
|
+
return text;
|
|
397
|
+
return withoutDot;
|
|
398
|
+
}
|
|
399
|
+
function lowerFirstWord(text) {
|
|
400
|
+
const match = text.match(/^[A-Za-z]+/);
|
|
401
|
+
const word = match?.[0];
|
|
402
|
+
if (word === undefined)
|
|
403
|
+
return text;
|
|
404
|
+
if (word.length > 1 && word === word.toUpperCase())
|
|
405
|
+
return text;
|
|
406
|
+
return text.slice(0, 1).toLowerCase() + text.slice(1);
|
|
407
|
+
}
|
|
408
|
+
var CLAUSE_ENDINGS = new Set([",", ":", "(", ")"]);
|
|
409
|
+
function backtickRunLength(text, start) {
|
|
410
|
+
let end = start;
|
|
411
|
+
while (text.charAt(end) === "`")
|
|
412
|
+
end += 1;
|
|
413
|
+
return end - start;
|
|
414
|
+
}
|
|
415
|
+
function codeSpanEnd(text, from, length) {
|
|
416
|
+
let index = text.indexOf("`", from);
|
|
417
|
+
while (index !== -1) {
|
|
418
|
+
const run = backtickRunLength(text, index);
|
|
419
|
+
if (run === length)
|
|
420
|
+
return index + run;
|
|
421
|
+
index = text.indexOf("`", index + run);
|
|
422
|
+
}
|
|
423
|
+
return -1;
|
|
424
|
+
}
|
|
425
|
+
function firstClause(text) {
|
|
426
|
+
let index = 0;
|
|
427
|
+
while (index < text.length) {
|
|
428
|
+
const character = text.charAt(index);
|
|
429
|
+
if (character === "`") {
|
|
430
|
+
const run = backtickRunLength(text, index);
|
|
431
|
+
const end = codeSpanEnd(text, index + run, run);
|
|
432
|
+
index = end === -1 ? index + run : end;
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (CLAUSE_ENDINGS.has(character))
|
|
436
|
+
return text.slice(0, index).trimEnd();
|
|
437
|
+
index += 1;
|
|
438
|
+
}
|
|
439
|
+
return text.trimEnd();
|
|
440
|
+
}
|
|
441
|
+
function truncateDescription(description, budget) {
|
|
442
|
+
if (budget <= 0)
|
|
443
|
+
return "";
|
|
444
|
+
if (description.length <= budget)
|
|
445
|
+
return description;
|
|
446
|
+
const window = description.slice(0, budget + 1);
|
|
447
|
+
const lastSpace = window.lastIndexOf(" ");
|
|
448
|
+
const cut = lastSpace > 0 ? window.slice(0, lastSpace) : window.slice(0, budget);
|
|
449
|
+
return balanceCodeSpans(cut.trimEnd()).replace(/[\s,;:-]+$/, "");
|
|
450
|
+
}
|
|
451
|
+
function subjectDescription(normalised) {
|
|
452
|
+
const clause = firstClause(normalised);
|
|
453
|
+
const description = clause.length === 0 ? normalised : clause;
|
|
454
|
+
return lowerFirstWord(stripTrailingPeriod(description));
|
|
455
|
+
}
|
|
456
|
+
function deriveCommitSubject(taskText, options = {}) {
|
|
457
|
+
const type = inferCommitType(taskText);
|
|
458
|
+
const scope = options.scope;
|
|
459
|
+
const prefix = scope === undefined || scope.length === 0 ? `${type}: ` : `${type}(${scope}): `;
|
|
460
|
+
const normalised = normaliseTaskText(taskText);
|
|
461
|
+
const uncut = normalised.length === 0 ? FALLBACK_DESCRIPTION : subjectDescription(normalised);
|
|
462
|
+
const maxLength = options.maxLength ?? MAX_SUBJECT_LENGTH;
|
|
463
|
+
const description = truncateDescription(uncut, maxLength - prefix.length);
|
|
464
|
+
const truncated = description !== uncut;
|
|
465
|
+
return {
|
|
466
|
+
subject: `${prefix}${description}`,
|
|
467
|
+
type,
|
|
468
|
+
truncated
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function buildCommitMessage(taskText, options = {}) {
|
|
472
|
+
const derived = deriveCommitSubject(taskText, options);
|
|
473
|
+
const body = normaliseTaskText(taskText);
|
|
474
|
+
return { ...derived, body };
|
|
475
|
+
}
|
|
476
|
+
function stageAllArgs() {
|
|
477
|
+
return ["add", "-A"];
|
|
478
|
+
}
|
|
479
|
+
function stagedChangesArgs() {
|
|
480
|
+
return ["diff", "--cached", "--quiet"];
|
|
481
|
+
}
|
|
482
|
+
function commitArgs(subject, body = "") {
|
|
483
|
+
const args = ["commit", "--cleanup=whitespace", "-m", subject];
|
|
484
|
+
if (body.length > 0)
|
|
485
|
+
args.push("-m", body);
|
|
486
|
+
return args;
|
|
487
|
+
}
|
|
488
|
+
function headShaArgs() {
|
|
489
|
+
return ["rev-parse", "HEAD"];
|
|
490
|
+
}
|
|
491
|
+
var MAX_GIT_BUFFER = 16 * 1024 * 1024;
|
|
492
|
+
function failureMessage(result) {
|
|
493
|
+
const combined = [result.stderr, result.stdout].map((stream) => stream.trim()).filter((stream) => stream.length > 0).join(`
|
|
494
|
+
`);
|
|
495
|
+
if (combined.length <= MAX_MESSAGE_CHARS)
|
|
496
|
+
return combined;
|
|
497
|
+
return `${combined.slice(0, MAX_MESSAGE_CHARS)}
|
|
498
|
+
[truncated]`;
|
|
499
|
+
}
|
|
500
|
+
function failed(step, subject, result) {
|
|
501
|
+
return {
|
|
502
|
+
outcome: "failed",
|
|
503
|
+
subject,
|
|
504
|
+
sha: null,
|
|
505
|
+
failedStep: step,
|
|
506
|
+
exitCode: result.status,
|
|
507
|
+
message: failureMessage(result)
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function spawnGit(cwd) {
|
|
511
|
+
return (args) => {
|
|
512
|
+
const result = spawnSync2("git", args, {
|
|
513
|
+
cwd,
|
|
514
|
+
encoding: "utf8",
|
|
515
|
+
maxBuffer: MAX_GIT_BUFFER
|
|
516
|
+
});
|
|
517
|
+
if (result.error !== undefined) {
|
|
518
|
+
return { status: null, stdout: "", stderr: result.error.message };
|
|
519
|
+
}
|
|
520
|
+
return {
|
|
521
|
+
status: result.status,
|
|
522
|
+
stdout: result.stdout ?? "",
|
|
523
|
+
stderr: result.stderr ?? ""
|
|
524
|
+
};
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function commitTaskWork(options) {
|
|
528
|
+
const run = options.runGit ?? spawnGit(options.cwd ?? process.cwd());
|
|
529
|
+
const message = buildCommitMessage(options.taskText, {
|
|
530
|
+
scope: options.scope,
|
|
531
|
+
maxLength: options.maxLength
|
|
532
|
+
});
|
|
533
|
+
const { subject } = message;
|
|
534
|
+
const staged = run(stageAllArgs());
|
|
535
|
+
if (staged.status !== 0)
|
|
536
|
+
return failed("stage", subject, staged);
|
|
537
|
+
const pending = run(stagedChangesArgs());
|
|
538
|
+
if (pending.status === 0) {
|
|
539
|
+
return {
|
|
540
|
+
outcome: "nothing-to-commit",
|
|
541
|
+
subject,
|
|
542
|
+
sha: null,
|
|
543
|
+
failedStep: null,
|
|
544
|
+
exitCode: 0,
|
|
545
|
+
message: ""
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
if (pending.status !== 1)
|
|
549
|
+
return failed("inspect", subject, pending);
|
|
550
|
+
const committed = run(commitArgs(subject, message.body));
|
|
551
|
+
if (committed.status !== 0)
|
|
552
|
+
return failed("commit", subject, committed);
|
|
553
|
+
const head = run(headShaArgs());
|
|
554
|
+
const sha = head.status === 0 ? head.stdout.trim() : null;
|
|
555
|
+
return {
|
|
556
|
+
outcome: "committed",
|
|
557
|
+
subject,
|
|
558
|
+
sha,
|
|
559
|
+
failedStep: null,
|
|
560
|
+
exitCode: 0,
|
|
561
|
+
message: ""
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
// packages/rafa/src/effort/store/trusted-permissions.ts
|
|
565
|
+
var TRUSTED_PERMISSIONS = ["admin", "maintain", "write"];
|
|
566
|
+
|
|
567
|
+
// packages/rafa/src/schema/project-id.ts
|
|
568
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
569
|
+
var PROJECT_ID_LENGTH = 12;
|
|
570
|
+
var PROJECT_ID_PATTERN = new RegExp(`^[0-9a-f]{${PROJECT_ID_LENGTH}}$`);
|
|
571
|
+
function hasColonAfterAt(url) {
|
|
572
|
+
const at = url.indexOf("@");
|
|
573
|
+
return at !== -1 && url.lastIndexOf(":") > at;
|
|
574
|
+
}
|
|
575
|
+
function normalizeRemote(url) {
|
|
576
|
+
const stripped = url.replace(/:\/\/[^@]+@/, "://");
|
|
577
|
+
const network = !stripped.startsWith("file://") && (stripped.includes("://") || hasColonAfterAt(stripped));
|
|
578
|
+
const trimmed = stripped.replace(/^[A-Za-z][A-Za-z0-9+.-]*:\/\//, "").replace(/^[^@/:]+@([^:/]+):/, "$1/").replace(/\.git\/?$/, "").replace(/\/+$/, "");
|
|
579
|
+
return network ? trimmed.toLowerCase() : trimmed;
|
|
580
|
+
}
|
|
581
|
+
function gitRemoteUrl(dir) {
|
|
582
|
+
const result = spawnSync3("git", ["remote", "get-url", "origin"], {
|
|
583
|
+
cwd: dir,
|
|
584
|
+
encoding: "utf8",
|
|
585
|
+
env: { ...process.env, LC_ALL: "C" }
|
|
586
|
+
});
|
|
587
|
+
if (result.error !== undefined || result.status !== 0)
|
|
588
|
+
return null;
|
|
589
|
+
const url = result.stdout.trim();
|
|
590
|
+
return url === "" ? null : url;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// packages/rafa/src/effort/store/settings.ts
|
|
594
|
+
var DEFAULT_STORE_SETTINGS = Object.freeze({
|
|
595
|
+
busyTimeoutMs: CORE_SECTION.defaults.effortBusyTimeoutMs
|
|
596
|
+
});
|
|
597
|
+
var active2 = DEFAULT_STORE_SETTINGS;
|
|
598
|
+
function setActiveStoreSettings(settings) {
|
|
599
|
+
if (settings === null) {
|
|
600
|
+
active2 = DEFAULT_STORE_SETTINGS;
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (!isBusyTimeoutMs(settings.busyTimeoutMs)) {
|
|
604
|
+
throw new RangeError(`effort store: busy timeout ${String(settings.busyTimeoutMs)} is not a whole number ` + `of milliseconds from ${String(BUSY_TIMEOUT_MIN_MS)} to ${String(BUSY_TIMEOUT_MAX_MS)}`);
|
|
605
|
+
}
|
|
606
|
+
active2 = Object.freeze({ busyTimeoutMs: settings.busyTimeoutMs });
|
|
607
|
+
}
|
|
608
|
+
function activeStoreSettings() {
|
|
609
|
+
return active2;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// packages/rafa/src/core/loop/hop-record.ts
|
|
613
|
+
var HOP_KINDS = ["blocker", "dry"];
|
|
614
|
+
var HOP_STATES = ["away", "waiting", "merged", "halted"];
|
|
615
|
+
function isRecord(value) {
|
|
616
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
617
|
+
}
|
|
618
|
+
function isIssueNumber(value) {
|
|
619
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
620
|
+
}
|
|
621
|
+
function asPlace(value) {
|
|
622
|
+
if (!isRecord(value) || !isIssueNumber(value.board))
|
|
623
|
+
return null;
|
|
624
|
+
if (value.epic !== null && !isIssueNumber(value.epic))
|
|
625
|
+
return null;
|
|
626
|
+
return { board: value.board, epic: value.epic };
|
|
627
|
+
}
|
|
628
|
+
function isIssueOrNull(value) {
|
|
629
|
+
return value === null || isIssueNumber(value);
|
|
630
|
+
}
|
|
631
|
+
function isTimestamp(value) {
|
|
632
|
+
return typeof value === "string" && !Number.isNaN(Date.parse(value));
|
|
633
|
+
}
|
|
634
|
+
function issuesMatchKind(kind, blocked, target) {
|
|
635
|
+
return kind === "blocker" ? blocked !== null && target !== null : blocked === null && target === null;
|
|
636
|
+
}
|
|
637
|
+
function asHopRecord(value) {
|
|
638
|
+
if (!isRecord(value))
|
|
639
|
+
return null;
|
|
640
|
+
const { kind, blocked, target, targetEpic, targetBoard, state, pullRequest, startedAt } = value;
|
|
641
|
+
const home = asPlace(value.home);
|
|
642
|
+
const from = asPlace(value.from);
|
|
643
|
+
if (typeof kind !== "string" || !HOP_KINDS.includes(kind))
|
|
644
|
+
return null;
|
|
645
|
+
if (typeof state !== "string" || !HOP_STATES.includes(state))
|
|
646
|
+
return null;
|
|
647
|
+
if (home === null || from === null)
|
|
648
|
+
return null;
|
|
649
|
+
if (!isIssueOrNull(blocked) || !isIssueOrNull(target) || !isIssueOrNull(pullRequest))
|
|
650
|
+
return null;
|
|
651
|
+
if (!isIssueNumber(targetEpic) || !isIssueNumber(targetBoard) || !isTimestamp(startedAt))
|
|
652
|
+
return null;
|
|
653
|
+
const hopKind = kind;
|
|
654
|
+
if (!issuesMatchKind(hopKind, blocked, target))
|
|
655
|
+
return null;
|
|
656
|
+
return {
|
|
657
|
+
kind: hopKind,
|
|
658
|
+
home,
|
|
659
|
+
from,
|
|
660
|
+
blocked,
|
|
661
|
+
target,
|
|
662
|
+
targetEpic,
|
|
663
|
+
targetBoard,
|
|
664
|
+
state,
|
|
665
|
+
pullRequest,
|
|
666
|
+
startedAt
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export { PORT_VERSIONS, createAdapterRegistry, registerAdapters, restoreAdapters, activeAdapterRegistry, CORE_ADAPTER_REGISTRY, CommandExit, commandSpelling, createLinePrompter, lazyPrompter, GLOBAL_FLAGS, runningCommand, HINT_FLAG, HINT_FLAG_SPEC, DEFAULT_CI_TIMEOUT_MIN, RAFA_VERSION, createGitRunner, gitSaid, parseWorkingTree, commitTaskWork, TRUSTED_PERMISSIONS, isRecord, asPlace, asHopRecord, PROJECT_ID_LENGTH, PROJECT_ID_PATTERN, normalizeRemote, gitRemoteUrl, setActiveStoreSettings, activeStoreSettings };
|