@davidbyoung/software-factory 0.0.0-stage → 0.1.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/.claude-plugin/plugin.json +5 -0
- package/LICENSE +21 -0
- package/README.md +135 -2
- package/actions/factory-agent/action.yml +218 -0
- package/agents/factory-test-reviewer.md +129 -0
- package/agents/factory-ticket-readiness.md +107 -0
- package/agents/factory-ui-reviewer.md +160 -0
- package/bin/factory.js +45 -0
- package/bin/launch.js +67 -0
- package/dist/board.d.mts +128 -0
- package/dist/board.mjs +456 -0
- package/dist/build.d.mts +18 -0
- package/dist/build.mjs +60 -0
- package/dist/cli.d.mts +17 -0
- package/dist/cli.mjs +264 -0
- package/dist/code-host/github.d.mts +118 -0
- package/dist/code-host/github.mjs +419 -0
- package/dist/code-host/index.d.mts +9 -0
- package/dist/code-host/index.mjs +18 -0
- package/dist/code-host/types.d.mts +205 -0
- package/dist/code-host/types.mjs +12 -0
- package/dist/config.d.mts +166 -0
- package/dist/config.mjs +548 -0
- package/dist/deps.d.mts +32 -0
- package/dist/deps.mjs +126 -0
- package/dist/doctor.d.mts +34 -0
- package/dist/doctor.mjs +188 -0
- package/dist/guard-commit.d.mts +41 -0
- package/dist/guard-commit.mjs +205 -0
- package/dist/guard-permission.d.mts +15 -0
- package/dist/guard-permission.mjs +52 -0
- package/dist/guard-ticket-text.d.mts +27 -0
- package/dist/guard-ticket-text.mjs +288 -0
- package/dist/guard.d.mts +4 -0
- package/dist/guard.mjs +37 -0
- package/dist/init.d.mts +58 -0
- package/dist/init.mjs +556 -0
- package/dist/lib/clock.d.mts +14 -0
- package/dist/lib/clock.mjs +36 -0
- package/dist/lib/gh.d.mts +28 -0
- package/dist/lib/gh.mjs +92 -0
- package/dist/lib/glob.d.mts +2 -0
- package/dist/lib/glob.mjs +41 -0
- package/dist/lib/pricing.d.mts +25 -0
- package/dist/lib/pricing.mjs +77 -0
- package/dist/lib/usage.d.mts +34 -0
- package/dist/lib/usage.mjs +128 -0
- package/dist/lib/work-status.d.mts +251 -0
- package/dist/lib/work-status.mjs +510 -0
- package/dist/merge-policy.d.mts +66 -0
- package/dist/merge-policy.mjs +146 -0
- package/dist/parts.d.mts +39 -0
- package/dist/parts.mjs +138 -0
- package/dist/poller.d.mts +61 -0
- package/dist/poller.mjs +247 -0
- package/dist/pr-watch.d.mts +45 -0
- package/dist/pr-watch.mjs +244 -0
- package/dist/pr.d.mts +65 -0
- package/dist/pr.mjs +571 -0
- package/dist/review-cost.d.mts +18 -0
- package/dist/review-cost.mjs +95 -0
- package/dist/review-tools.d.mts +5 -0
- package/dist/review-tools.mjs +46 -0
- package/dist/review-verdict.d.mts +50 -0
- package/dist/review-verdict.mjs +171 -0
- package/dist/reviewers.d.mts +54 -0
- package/dist/reviewers.mjs +312 -0
- package/dist/runner/github-actions.d.mts +12 -0
- package/dist/runner/github-actions.mjs +97 -0
- package/dist/runner/index.d.mts +9 -0
- package/dist/runner/index.mjs +22 -0
- package/dist/runner/types.d.mts +60 -0
- package/dist/runner/types.mjs +7 -0
- package/dist/session-start.d.mts +20 -0
- package/dist/session-start.mjs +115 -0
- package/dist/site/capture.d.mts +44 -0
- package/dist/site/capture.mjs +114 -0
- package/dist/site/measure.d.mts +83 -0
- package/dist/site/measure.mjs +225 -0
- package/dist/site/pages.d.mts +10 -0
- package/dist/site/pages.mjs +71 -0
- package/dist/site/pixels.d.mts +47 -0
- package/dist/site/pixels.mjs +157 -0
- package/dist/site/servers.d.mts +47 -0
- package/dist/site/servers.mjs +141 -0
- package/dist/site.d.mts +60 -0
- package/dist/site.mjs +341 -0
- package/dist/status.d.mts +100 -0
- package/dist/status.mjs +514 -0
- package/dist/sync.d.mts +59 -0
- package/dist/sync.mjs +292 -0
- package/dist/ticket.d.mts +61 -0
- package/dist/ticket.mjs +562 -0
- package/dist/tickets/github.d.mts +128 -0
- package/dist/tickets/github.mjs +491 -0
- package/dist/tickets/index.d.mts +15 -0
- package/dist/tickets/index.mjs +27 -0
- package/dist/tickets/transport.d.mts +42 -0
- package/dist/tickets/transport.mjs +158 -0
- package/dist/tickets/types.d.mts +191 -0
- package/dist/tickets/types.mjs +76 -0
- package/docs/builds.md +227 -0
- package/docs/cli.md +221 -0
- package/docs/configuration.md +809 -0
- package/docs/design.md +106 -0
- package/docs/developing.md +400 -0
- package/docs/existing-repo.md +138 -0
- package/docs/github/reference.md +288 -0
- package/docs/github/setup.md +312 -0
- package/docs/glossary.md +106 -0
- package/docs/limitations.md +115 -0
- package/docs/plugins.md +192 -0
- package/docs/quick-start.md +222 -0
- package/docs/removing.md +76 -0
- package/docs/skills.md +270 -0
- package/docs/updating.md +108 -0
- package/docs/workflow.md +195 -0
- package/package.json +67 -4
- package/poller.Dockerfile +21 -0
- package/review.md +170 -0
- package/rules.md +313 -0
- package/settings.schema.json +411 -0
- package/skills/factory-address-review/SKILL.md +547 -0
- package/skills/factory-address-review/patch-coverage.py +68 -0
- package/skills/factory-build/SKILL.md +412 -0
- package/skills/factory-deps/SKILL.md +185 -0
- package/skills/factory-design/SKILL.md +159 -0
- package/skills/factory-diagnose/SKILL.md +93 -0
- package/skills/factory-mutate/SKILL.md +76 -0
- package/skills/factory-refine/SKILL.md +417 -0
- package/skills/factory-resolve-conflicts/SKILL.md +235 -0
- package/workflows/factory-board-sync.yml +91 -0
- package/workflows/factory-build.yml +72 -0
- package/workflows/factory-check.yml +37 -0
- package/workflows/factory-claude-review.yml +133 -0
- package/workflows/factory-conflicts.yml +69 -0
- package/workflows/factory-deps-auto-merge.yml +43 -0
- package/workflows/factory-deps.yml +59 -0
- package/workflows/factory-merge-policy.yml +121 -0
- package/workflows/factory-review-verdict.yml +54 -0
- package/workflows/factory-review.yml +75 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export type BareTag = {
|
|
3
|
+
tag: string;
|
|
4
|
+
line: string;
|
|
5
|
+
};
|
|
6
|
+
/** Each tag-like `<word>` outside code that GitHub would not render as
|
|
7
|
+
* meant, with the line it is on. */
|
|
8
|
+
export declare function bareTags(text: string): BareTag[];
|
|
9
|
+
/** The text each `gh issue create|edit|comment` in the command posts, from
|
|
10
|
+
* `--body`/`-b` or from the file `--body-file`/`-F` names, which `read`
|
|
11
|
+
* returns, or null when it cannot, and the `body` field each `gh api` call
|
|
12
|
+
* sends to an issue or an issue comment. */
|
|
13
|
+
export declare function issueBodies(command: string, read: (path: string) => string | null): string[];
|
|
14
|
+
export declare function refusal(tags: BareTag[]): string;
|
|
15
|
+
/** The refusal for this Bash call, or null to let it through. */
|
|
16
|
+
export declare function checkTicketText(input: {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
tool_input?: {
|
|
19
|
+
command?: string;
|
|
20
|
+
};
|
|
21
|
+
}): string | null;
|
|
22
|
+
/** Throws the refusal when a body a command is about to post has a bare
|
|
23
|
+
* tag, so `factory ticket` and `factory pr comment` post nothing. */
|
|
24
|
+
export declare function refuseBareTags(text: string): void;
|
|
25
|
+
/** The owner's pass of the review verdict for one commit, which no agent
|
|
26
|
+
* adds ("What merges without the owner" in rules.md). */
|
|
27
|
+
export declare function refuseOverride(label: string): void;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse hook for Bash, run as `factory guard ticket-text` or within
|
|
3
|
+
// `factory guard`. Refuses `gh issue create`,
|
|
4
|
+
// `gh issue edit`, and `gh issue comment` when the text they post holds a
|
|
5
|
+
// bare tag-like `<word>` outside code spans, code fences, and HTML
|
|
6
|
+
// comments. GitHub drops an unknown tag, so `/study/guides/<slug>/` shows as
|
|
7
|
+
// `/study/guides//`, and keeps a real one, so an unclosed `<code>` turns the
|
|
8
|
+
// rest of a list into code. Exit 2 blocks the call and shows stderr to
|
|
9
|
+
// Claude, which backticks the line and posts again.
|
|
10
|
+
//
|
|
11
|
+
// It also reads a `gh api` call to an issue or an issue comment
|
|
12
|
+
// (`repos/OWNER/REPO/issues`, `issues/N`, `issues/N/comments`, or
|
|
13
|
+
// `issues/comments/ID`) that sends a `body` field, through `-f body=TEXT`,
|
|
14
|
+
// `-F body=TEXT`, or `-F body=@FILE` and their `--raw-field` and `--field`
|
|
15
|
+
// forms, which is how a session posts without `gh issue`.
|
|
16
|
+
// GitHub serves a pull request's conversation comments, and its body, as
|
|
17
|
+
// an issue's, so those paths are read too; `gh pr` and `pulls/N` are not.
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
import { resolve } from "node:path";
|
|
20
|
+
/** The tags GitHub renders on purpose, which issue text may use bare. Not
|
|
21
|
+
* `code` or `pre`: written bare, they are usually a placeholder, and an
|
|
22
|
+
* unclosed one swallows what follows. */
|
|
23
|
+
const RENDERED = new Set([
|
|
24
|
+
"a",
|
|
25
|
+
"abbr",
|
|
26
|
+
"b",
|
|
27
|
+
"blockquote",
|
|
28
|
+
"br",
|
|
29
|
+
"dd",
|
|
30
|
+
"del",
|
|
31
|
+
"details",
|
|
32
|
+
"div",
|
|
33
|
+
"dl",
|
|
34
|
+
"dt",
|
|
35
|
+
"em",
|
|
36
|
+
"h1",
|
|
37
|
+
"h2",
|
|
38
|
+
"h3",
|
|
39
|
+
"h4",
|
|
40
|
+
"h5",
|
|
41
|
+
"h6",
|
|
42
|
+
"hr",
|
|
43
|
+
"i",
|
|
44
|
+
"img",
|
|
45
|
+
"ins",
|
|
46
|
+
"kbd",
|
|
47
|
+
"li",
|
|
48
|
+
"mark",
|
|
49
|
+
"ol",
|
|
50
|
+
"p",
|
|
51
|
+
"picture",
|
|
52
|
+
"q",
|
|
53
|
+
"rp",
|
|
54
|
+
"rt",
|
|
55
|
+
"ruby",
|
|
56
|
+
"s",
|
|
57
|
+
"samp",
|
|
58
|
+
"source",
|
|
59
|
+
"span",
|
|
60
|
+
"strong",
|
|
61
|
+
"sub",
|
|
62
|
+
"summary",
|
|
63
|
+
"sup",
|
|
64
|
+
"table",
|
|
65
|
+
"tbody",
|
|
66
|
+
"td",
|
|
67
|
+
"tfoot",
|
|
68
|
+
"th",
|
|
69
|
+
"thead",
|
|
70
|
+
"tr",
|
|
71
|
+
"tt",
|
|
72
|
+
"u",
|
|
73
|
+
"ul",
|
|
74
|
+
"var",
|
|
75
|
+
]);
|
|
76
|
+
/** Blanks code fences, code spans, and HTML comments, keeping line breaks so
|
|
77
|
+
* each remaining tag stays on its own line. */
|
|
78
|
+
function withoutCode(text) {
|
|
79
|
+
const blank = (s) => s.replace(/[^\n]/g, " ");
|
|
80
|
+
return text
|
|
81
|
+
.replace(/<!--[\s\S]*?-->/g, blank)
|
|
82
|
+
.replace(/^([ \t]*)(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:\n\1\2[^\n]*|$)/gm, blank)
|
|
83
|
+
.replace(/(`+)(?!`)[\s\S]*?[^`]\1(?!`)/g, blank);
|
|
84
|
+
}
|
|
85
|
+
/** Each tag-like `<word>` outside code that GitHub would not render as
|
|
86
|
+
* meant, with the line it is on. */
|
|
87
|
+
export function bareTags(text) {
|
|
88
|
+
const lines = text.split("\n");
|
|
89
|
+
const found = [];
|
|
90
|
+
withoutCode(text)
|
|
91
|
+
.split("\n")
|
|
92
|
+
.forEach((line, i) => {
|
|
93
|
+
for (const m of line.matchAll(/<\/?([A-Za-z][\w-]*)(?:\s[^<>]*)?\/?>/g))
|
|
94
|
+
if (!RENDERED.has(m[1].toLowerCase()))
|
|
95
|
+
found.push({ tag: m[0], line: lines[i] });
|
|
96
|
+
});
|
|
97
|
+
return found;
|
|
98
|
+
}
|
|
99
|
+
/** The command's words and separators, as a POSIX shell splits them, with
|
|
100
|
+
* each `$(cat <<'X' … X)` heredoc read as the text it passes. */
|
|
101
|
+
function tokens(command) {
|
|
102
|
+
const heredocs = [];
|
|
103
|
+
const src = command.replace(/\$\(\s*cat\s+<<-?\s*(['"]?)(\w+)\1[^\n]*\n([\s\S]*?\n)\2[ \t]*\n?\s*\)/g, (_, _q, _tag, body) => `\u0000${heredocs.push(body) - 1}\u0000`);
|
|
104
|
+
const out = [];
|
|
105
|
+
let word = null;
|
|
106
|
+
const end = () => {
|
|
107
|
+
if (word !== null)
|
|
108
|
+
out.push({ word });
|
|
109
|
+
word = null;
|
|
110
|
+
};
|
|
111
|
+
for (let i = 0; i < src.length; i++) {
|
|
112
|
+
const c = src[i];
|
|
113
|
+
if (c === "'") {
|
|
114
|
+
const close = src.indexOf("'", i + 1);
|
|
115
|
+
const stop = close === -1 ? src.length : close;
|
|
116
|
+
word = (word ?? "") + src.slice(i + 1, stop);
|
|
117
|
+
i = stop;
|
|
118
|
+
}
|
|
119
|
+
else if (c === '"') {
|
|
120
|
+
let text = "";
|
|
121
|
+
for (i++; i < src.length && src[i] !== '"'; i++) {
|
|
122
|
+
if (src[i] === "\\" && i + 1 < src.length)
|
|
123
|
+
text += src[++i];
|
|
124
|
+
else
|
|
125
|
+
text += src[i];
|
|
126
|
+
}
|
|
127
|
+
word = (word ?? "") + text;
|
|
128
|
+
}
|
|
129
|
+
else if (c === "\\" && i + 1 < src.length) {
|
|
130
|
+
word = (word ?? "") + src[++i];
|
|
131
|
+
}
|
|
132
|
+
else if (/\s/.test(c)) {
|
|
133
|
+
if (c === "\n") {
|
|
134
|
+
end();
|
|
135
|
+
out.push({ op: "\n" });
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
end();
|
|
139
|
+
}
|
|
140
|
+
else if (/[;&|()]/.test(c)) {
|
|
141
|
+
end();
|
|
142
|
+
out.push({ op: c });
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
word = (word ?? "") + c;
|
|
146
|
+
}
|
|
147
|
+
end();
|
|
148
|
+
return out.map((t) => "word" in t
|
|
149
|
+
? { word: t.word.replace(/\u0000(\d+)\u0000/g, (_, n) => heredocs[n]) }
|
|
150
|
+
: t);
|
|
151
|
+
}
|
|
152
|
+
/** The text each `gh issue create|edit|comment` in the command posts, from
|
|
153
|
+
* `--body`/`-b` or from the file `--body-file`/`-F` names, which `read`
|
|
154
|
+
* returns, or null when it cannot, and the `body` field each `gh api` call
|
|
155
|
+
* sends to an issue or an issue comment. */
|
|
156
|
+
export function issueBodies(command, read) {
|
|
157
|
+
const commands = [[]];
|
|
158
|
+
for (const t of tokens(command)) {
|
|
159
|
+
if ("op" in t)
|
|
160
|
+
commands.push([]);
|
|
161
|
+
else
|
|
162
|
+
commands[commands.length - 1].push(t.word);
|
|
163
|
+
}
|
|
164
|
+
const bodies = [];
|
|
165
|
+
for (const words of commands) {
|
|
166
|
+
if (words[0] === "gh" && words[1] === "api") {
|
|
167
|
+
const body = apiBody(words.slice(2), read);
|
|
168
|
+
if (body !== null)
|
|
169
|
+
bodies.push(body);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (words[0] !== "gh" ||
|
|
173
|
+
words[1] !== "issue" ||
|
|
174
|
+
!["create", "edit", "comment"].includes(words[2]))
|
|
175
|
+
continue;
|
|
176
|
+
for (let i = 3; i < words.length; i++) {
|
|
177
|
+
const w = words[i];
|
|
178
|
+
const fromFile = (path) => {
|
|
179
|
+
if (path === undefined || path === "-")
|
|
180
|
+
return;
|
|
181
|
+
const text = read(path);
|
|
182
|
+
if (text !== null)
|
|
183
|
+
bodies.push(text);
|
|
184
|
+
};
|
|
185
|
+
if (w === "--body" || w === "-b") {
|
|
186
|
+
if (words[i + 1] !== undefined)
|
|
187
|
+
bodies.push(words[++i]);
|
|
188
|
+
}
|
|
189
|
+
else if (w.startsWith("--body="))
|
|
190
|
+
bodies.push(w.slice(7));
|
|
191
|
+
else if (w === "--body-file" || w === "-F")
|
|
192
|
+
fromFile(words[++i]);
|
|
193
|
+
else if (w.startsWith("--body-file="))
|
|
194
|
+
fromFile(w.slice(12));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return bodies;
|
|
198
|
+
}
|
|
199
|
+
/** `gh api`'s options that take a value, so the value is not read as the
|
|
200
|
+
* path. */
|
|
201
|
+
const API_VALUE_OPTIONS = new Set([
|
|
202
|
+
"-X",
|
|
203
|
+
"--method",
|
|
204
|
+
"-H",
|
|
205
|
+
"--header",
|
|
206
|
+
"--input",
|
|
207
|
+
"-q",
|
|
208
|
+
"--jq",
|
|
209
|
+
"-t",
|
|
210
|
+
"--template",
|
|
211
|
+
"--cache",
|
|
212
|
+
"-p",
|
|
213
|
+
"--preview",
|
|
214
|
+
"--hostname",
|
|
215
|
+
]);
|
|
216
|
+
const ISSUE_PATH = /^\/?repos\/[^/]+\/[^/]+\/issues(?:\/\d+(?:\/comments)?|\/comments\/\d+)?\/?$/;
|
|
217
|
+
/** The `body` field a `gh api` call (its words after `gh api`) sends to an
|
|
218
|
+
* issue or an issue comment, or null when it sends none there. A `-F`
|
|
219
|
+
* value starting with `@` names a file, which `read` returns. */
|
|
220
|
+
function apiBody(words, read) {
|
|
221
|
+
let path;
|
|
222
|
+
let body = null;
|
|
223
|
+
for (let i = 0; i < words.length; i++) {
|
|
224
|
+
let w = words[i];
|
|
225
|
+
let raw;
|
|
226
|
+
if (w === "-f" || w === "--raw-field")
|
|
227
|
+
raw = true;
|
|
228
|
+
else if (w === "-F" || w === "--field")
|
|
229
|
+
raw = false;
|
|
230
|
+
else if (w.startsWith("--raw-field="))
|
|
231
|
+
[raw, w] = [true, w.slice(12)];
|
|
232
|
+
else if (w.startsWith("--field="))
|
|
233
|
+
[raw, w] = [false, w.slice(8)];
|
|
234
|
+
if (raw !== undefined) {
|
|
235
|
+
const field = w.startsWith("-") ? (words[++i] ?? "") : w;
|
|
236
|
+
if (!field.startsWith("body="))
|
|
237
|
+
continue;
|
|
238
|
+
const value = field.slice(5);
|
|
239
|
+
body =
|
|
240
|
+
!raw && value.startsWith("@")
|
|
241
|
+
? value === "@-"
|
|
242
|
+
? null
|
|
243
|
+
: read(value.slice(1))
|
|
244
|
+
: value;
|
|
245
|
+
}
|
|
246
|
+
else if (API_VALUE_OPTIONS.has(w))
|
|
247
|
+
i++;
|
|
248
|
+
else if (!w.startsWith("-") && path === undefined)
|
|
249
|
+
path = w;
|
|
250
|
+
}
|
|
251
|
+
return path !== undefined && ISSUE_PATH.test(path) ? body : null;
|
|
252
|
+
}
|
|
253
|
+
export function refusal(tags) {
|
|
254
|
+
const lines = tags.map((t) => ` ${t.tag} in: ${t.line.trim()}`);
|
|
255
|
+
return [
|
|
256
|
+
"Blocked by factory guard ticket-text: this ticket text has a bare tag-like",
|
|
257
|
+
"<word> that GitHub drops or renders as HTML. Put each placeholder or tag",
|
|
258
|
+
"name in backticks, then post again:",
|
|
259
|
+
...lines,
|
|
260
|
+
].join("\n");
|
|
261
|
+
}
|
|
262
|
+
/** The refusal for this Bash call, or null to let it through. */
|
|
263
|
+
export function checkTicketText(input) {
|
|
264
|
+
const cwd = input.cwd ?? ".";
|
|
265
|
+
const read = (path) => {
|
|
266
|
+
try {
|
|
267
|
+
return readFileSync(resolve(cwd, path), "utf8");
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const tags = issueBodies(input.tool_input?.command ?? "", read).flatMap(bareTags);
|
|
274
|
+
return tags.length === 0 ? null : refusal(tags);
|
|
275
|
+
}
|
|
276
|
+
/** Throws the refusal when a body a command is about to post has a bare
|
|
277
|
+
* tag, so `factory ticket` and `factory pr comment` post nothing. */
|
|
278
|
+
export function refuseBareTags(text) {
|
|
279
|
+
const tags = bareTags(text);
|
|
280
|
+
if (tags.length > 0)
|
|
281
|
+
throw new Error(refusal(tags));
|
|
282
|
+
}
|
|
283
|
+
/** The owner's pass of the review verdict for one commit, which no agent
|
|
284
|
+
* adds ("What merges without the owner" in rules.md). */
|
|
285
|
+
export function refuseOverride(label) {
|
|
286
|
+
if (label.trim().toLowerCase() === "verdict: override")
|
|
287
|
+
throw new Error("Refused: the verdict: override label is the owner's pass of the review verdict, which an agent never adds.");
|
|
288
|
+
}
|
package/dist/guard.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type HookInput } from "./guard-commit.mts";
|
|
2
|
+
export type Which = "all" | "commit" | "ticket-text";
|
|
3
|
+
export declare function guard(which: Which, input: HookInput, err: (text: string) => void): Promise<number>;
|
|
4
|
+
export declare function run(which: Which): Promise<number>;
|
package/dist/guard.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The PreToolUse hook for Bash: `factory guard` runs both guards on one
|
|
2
|
+
// reading of the hook's input, and `factory guard commit` or
|
|
3
|
+
// `factory guard ticket-text` runs one. A block exits 2 with the reason on
|
|
4
|
+
// standard error, which stops the call and shows the reason to Claude.
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { checkCommit } from "./guard-commit.mjs";
|
|
7
|
+
import { checkTicketText } from "./guard-ticket-text.mjs";
|
|
8
|
+
export async function guard(which, input, err) {
|
|
9
|
+
if (which !== "ticket-text") {
|
|
10
|
+
const block = await checkCommit(input, err);
|
|
11
|
+
if (block) {
|
|
12
|
+
err(`Blocked by factory guard commit: ${block}`);
|
|
13
|
+
return 2;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (which !== "commit") {
|
|
17
|
+
const refusal = checkTicketText(input);
|
|
18
|
+
if (refusal) {
|
|
19
|
+
err(refusal);
|
|
20
|
+
return 2;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
export async function run(which) {
|
|
26
|
+
let input = {};
|
|
27
|
+
try {
|
|
28
|
+
input = JSON.parse(readFileSync(0, "utf8") || "{}");
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// No input: nothing to check.
|
|
32
|
+
}
|
|
33
|
+
return guard(which, input, (text) => {
|
|
34
|
+
if (text)
|
|
35
|
+
process.stderr.write(`${text}\n`);
|
|
36
|
+
});
|
|
37
|
+
}
|
package/dist/init.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type CodeHost } from "./code-host/index.mts";
|
|
2
|
+
import { type Check } from "./doctor.mts";
|
|
3
|
+
import { type Runner } from "./runner/index.mts";
|
|
4
|
+
import type { Tickets } from "./tickets/types.mts";
|
|
5
|
+
/** The questions init asks. Each is answered at the terminal, and in tests
|
|
6
|
+
* from a script. */
|
|
7
|
+
export type Ask = {
|
|
8
|
+
checkbox(message: string, choices: {
|
|
9
|
+
name: string;
|
|
10
|
+
value: string;
|
|
11
|
+
checked: boolean;
|
|
12
|
+
/** Shown under the list while this choice is highlighted. */
|
|
13
|
+
description?: string;
|
|
14
|
+
}[]): Promise<string[]>;
|
|
15
|
+
select(message: string, choices: {
|
|
16
|
+
name: string;
|
|
17
|
+
value: string;
|
|
18
|
+
}[]): Promise<string>;
|
|
19
|
+
confirm(message: string, fallback: boolean): Promise<boolean>;
|
|
20
|
+
/** Read without echoing what is typed. */
|
|
21
|
+
secret(message: string): Promise<string>;
|
|
22
|
+
input(message: string, fallback: string): Promise<string>;
|
|
23
|
+
};
|
|
24
|
+
export type InitDeps = {
|
|
25
|
+
root: string;
|
|
26
|
+
ask: Ask;
|
|
27
|
+
out: (line: string) => void;
|
|
28
|
+
/** The `origin` remote's address, or null without one. */
|
|
29
|
+
remote: () => string | null;
|
|
30
|
+
open: (repository: string) => {
|
|
31
|
+
codeHost: CodeHost;
|
|
32
|
+
runner: Runner;
|
|
33
|
+
tickets: Tickets;
|
|
34
|
+
};
|
|
35
|
+
sync: () => Promise<number>;
|
|
36
|
+
/** The files a sync with these settings would write or delete. */
|
|
37
|
+
syncChanges: (settingsText: string) => string[];
|
|
38
|
+
/** Runs a command attached to the terminal, as `claude setup-token`. */
|
|
39
|
+
interactive: (argv: string[]) => Promise<number>;
|
|
40
|
+
hasCommand: (name: string) => boolean;
|
|
41
|
+
openPage: (url: string) => void;
|
|
42
|
+
/** A new signing key's two halves, its files already deleted. */
|
|
43
|
+
keygen: () => Promise<{
|
|
44
|
+
privateKey: string;
|
|
45
|
+
publicKey: string;
|
|
46
|
+
}>;
|
|
47
|
+
checks: () => Promise<Check[]>;
|
|
48
|
+
packageName: string;
|
|
49
|
+
packageVersion: string;
|
|
50
|
+
};
|
|
51
|
+
/** The repository and code host a remote's address names, or null for one
|
|
52
|
+
* on a code host the factory does not support. */
|
|
53
|
+
export declare function parseRemote(url: string): {
|
|
54
|
+
codeHost: "github";
|
|
55
|
+
repository: string;
|
|
56
|
+
} | null;
|
|
57
|
+
export declare function main(_argv: string[], d: InitDeps): Promise<number>;
|
|
58
|
+
export declare function run(argv: string[]): Promise<number>;
|