co-maintainer 0.4.0 → 0.4.2
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 +2 -0
- package/dist/package.json +1 -1
- package/dist/src/cli/args.js +1 -0
- package/dist/src/cli/commands/serve.d.ts +3 -3
- package/dist/src/cli/commands/serve.js +5 -18
- package/dist/src/cli/main.js +5 -0
- package/dist/src/knowledge/facts.js +6 -3
- package/dist/src/knowledge/validate.d.ts +2 -1
- package/dist/src/knowledge/validate.js +6 -4
- package/dist/src/server/app.d.ts +1 -7
- package/dist/src/server/app.js +19 -4
- package/dist/src/services/setup.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# co-maintainer
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/co-maintainer)
|
|
4
|
+
|
|
3
5
|
`co-maintainer` analyzes a GitHub repository and writes repository-specific
|
|
4
6
|
`SKILL.md` guidance that helps developers contribute changes more reliably.
|
|
5
7
|
|
package/dist/package.json
CHANGED
package/dist/src/cli/args.js
CHANGED
|
@@ -46,6 +46,7 @@ export async function parseArgs(args) {
|
|
|
46
46
|
console.log(" co-maintainer review owner/repo PR_NUMBER [options]");
|
|
47
47
|
console.log(" co-maintainer set --token=... --ai=... --low-model=... --high-model=... --auth=...");
|
|
48
48
|
console.log(" co-maintainer serve --port=N");
|
|
49
|
+
console.log(" co-maintainer -v | --version");
|
|
49
50
|
console.log(" --webhook-url=https://host/github/webhook [or CM_WEBHOOK_URL]");
|
|
50
51
|
console.log(" --env=PATH --debug --log-time --gh-concurrent=N --ai-concurrent=N");
|
|
51
52
|
console.log("Options: --include-codebase --include-pull-requests --include-pull-request-changes");
|
|
@@ -11,8 +11,8 @@ export declare function resolveAuthMethods(args: string[], config: Pick<UserConf
|
|
|
11
11
|
export declare function resolveWebhookUrl(args: string[], port: number, configured?: string): string;
|
|
12
12
|
/** `co-maintainer serve --port=N [--password=...] [--disable-auth=password]
|
|
13
13
|
* [--enable-auth=github] [--inject-500]`. HMAC-verified `POST /github/webhook`
|
|
14
|
-
* plus a dashboard gated by password and/or GitHub sign-in.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* plus a dashboard gated by password and/or GitHub sign-in. The GitHub App
|
|
15
|
+
* is optional at startup and can be added later from the dashboard settings
|
|
16
|
+
* or `co-maintainer set`. GitHub sign-in needs
|
|
17
17
|
* `--github-oauth-client-id`/`-client-secret`/`-allowed-user` set. */
|
|
18
18
|
export declare function runServe(args: string[]): Promise<void>;
|
|
@@ -83,9 +83,9 @@ export function resolveWebhookUrl(args, port, configured) {
|
|
|
83
83
|
}
|
|
84
84
|
/** `co-maintainer serve --port=N [--password=...] [--disable-auth=password]
|
|
85
85
|
* [--enable-auth=github] [--inject-500]`. HMAC-verified `POST /github/webhook`
|
|
86
|
-
* plus a dashboard gated by password and/or GitHub sign-in.
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* plus a dashboard gated by password and/or GitHub sign-in. The GitHub App
|
|
87
|
+
* is optional at startup and can be added later from the dashboard settings
|
|
88
|
+
* or `co-maintainer set`. GitHub sign-in needs
|
|
89
89
|
* `--github-oauth-client-id`/`-client-secret`/`-allowed-user` set. */
|
|
90
90
|
export async function runServe(args) {
|
|
91
91
|
const portArg = args
|
|
@@ -99,14 +99,8 @@ export async function runServe(args) {
|
|
|
99
99
|
}
|
|
100
100
|
const config = readConfig();
|
|
101
101
|
const webhookUrl = resolveWebhookUrl(args, port, config.webhookUrl);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
!config.githubAppPrivateKey &&
|
|
105
|
-
"--github-app-private-key=... (or --github-app-private-key-file=path)",
|
|
106
|
-
].filter(Boolean);
|
|
107
|
-
if (missing.length > 0) {
|
|
108
|
-
die(`serve requires the GitHub App to be configured first; run:\n` +
|
|
109
|
-
` co-maintainer set ${missing.join(" ")}`);
|
|
102
|
+
if (!config.githubAppId || !config.githubAppPrivateKey) {
|
|
103
|
+
console.log("[serve] GitHub App is not configured yet. Add it in the dashboard settings or with co-maintainer set.");
|
|
110
104
|
}
|
|
111
105
|
const auth = resolveAuthMethods(args, config);
|
|
112
106
|
let githubOAuth;
|
|
@@ -157,13 +151,6 @@ export async function runServe(args) {
|
|
|
157
151
|
}
|
|
158
152
|
const app = createApp({
|
|
159
153
|
password,
|
|
160
|
-
githubApp: config.githubAppId && config.githubAppPrivateKey
|
|
161
|
-
? {
|
|
162
|
-
appId: config.githubAppId,
|
|
163
|
-
privateKeyPem: config.githubAppPrivateKey,
|
|
164
|
-
}
|
|
165
|
-
: undefined,
|
|
166
|
-
webhookSecret: config.githubWebhookSecret,
|
|
167
154
|
webhookUrl,
|
|
168
155
|
inject500,
|
|
169
156
|
auth,
|
package/dist/src/cli/main.js
CHANGED
|
@@ -6,7 +6,12 @@ import { runSet } from "./commands/set.js";
|
|
|
6
6
|
import { runProbe } from "./commands/probe.js";
|
|
7
7
|
import { runReviewFromCli } from "./commands/review.js";
|
|
8
8
|
import { runInitOrRemake } from "../services/setup.js";
|
|
9
|
+
import { VERSION } from "../version.js";
|
|
9
10
|
export async function run(args) {
|
|
11
|
+
if (args[0] === "-v" || args[0] === "--version") {
|
|
12
|
+
console.log(VERSION);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
10
15
|
if (args[0] === "set") {
|
|
11
16
|
await runSet(args.slice(1));
|
|
12
17
|
return;
|
|
@@ -314,9 +314,12 @@ export function extractFacts(source, options) {
|
|
|
314
314
|
.join("; ")}.`, "commit history", 2));
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
const currentPaths = new Set(source.tree);
|
|
318
|
+
const changedFiles = source.pullRequests
|
|
319
|
+
.flatMap((pr) => pr.changedFiles)
|
|
320
|
+
.filter((path) => currentPaths.has(path));
|
|
321
|
+
if (options.includePullRequestChanges && changedFiles.length) {
|
|
322
|
+
const files = counts(changedFiles).slice(0, 10);
|
|
320
323
|
add(facts, fact("review-bar", `Frequently changed files include ${files
|
|
321
324
|
.map(([path]) => `\`${path}\``)
|
|
322
325
|
.join(", ")}; check nearby tests and workflows before editing.`, "pull request files", 2));
|
|
@@ -2,5 +2,6 @@ import type { Source } from "./types.ts";
|
|
|
2
2
|
export type ValidationResult = {
|
|
3
3
|
valid: boolean;
|
|
4
4
|
errors: string[];
|
|
5
|
+
warnings: string[];
|
|
5
6
|
};
|
|
6
|
-
export declare function validateSkill(markdown: string, outputDirectory: string, source?: Source): Promise<ValidationResult>;
|
|
7
|
+
export declare function validateSkill(markdown: string, outputDirectory: string, source?: Source, referenceIssues?: "error" | "warning"): Promise<ValidationResult>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { stat } from "../util/runtime.js";
|
|
2
|
-
export async function validateSkill(markdown, outputDirectory, source) {
|
|
2
|
+
export async function validateSkill(markdown, outputDirectory, source, referenceIssues = "error") {
|
|
3
3
|
const errors = [];
|
|
4
|
+
const warnings = [];
|
|
5
|
+
const referenceProblems = referenceIssues === "error" ? errors : warnings;
|
|
4
6
|
if (!markdown.startsWith("---\n"))
|
|
5
7
|
errors.push("missing YAML frontmatter");
|
|
6
8
|
if (!/^name:\s+\S+/m.test(markdown))
|
|
@@ -104,14 +106,14 @@ export async function validateSkill(markdown, outputDirectory, source) {
|
|
|
104
106
|
![...paths].some((path) => wildcardPattern
|
|
105
107
|
? wildcardPattern.test(path)
|
|
106
108
|
: path.startsWith(`${normalized}/`))) {
|
|
107
|
-
|
|
109
|
+
referenceProblems.push(`referenced path is absent from source: ${reference}`);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
if (/^(?:npm|pnpm|yarn|bun|deno|cargo|make|go|python|node|git)\s/.test(reference) &&
|
|
111
113
|
![...commands].some((command) => reference === command ||
|
|
112
114
|
reference.startsWith(`${command} `) ||
|
|
113
115
|
command.startsWith(`${reference} `))) {
|
|
114
|
-
|
|
116
|
+
referenceProblems.push(`referenced command is absent from source: ${reference}`);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
}
|
|
@@ -130,5 +132,5 @@ export async function validateSkill(markdown, outputDirectory, source) {
|
|
|
130
132
|
errors.push(`linked file does not exist: ${link}`);
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
|
-
return { valid: errors.length === 0, errors };
|
|
135
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
134
136
|
}
|
package/dist/src/server/app.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import type { AuthMethods } from "./auth.ts";
|
|
2
2
|
/** `password` is the dashboard password `serve` generates or takes via
|
|
3
|
-
* `--password`.
|
|
4
|
-
* the App ID and private key. */
|
|
3
|
+
* `--password`. */
|
|
5
4
|
export type AppDeps = {
|
|
6
5
|
password: string;
|
|
7
|
-
githubApp?: {
|
|
8
|
-
appId: string;
|
|
9
|
-
privateKeyPem: string;
|
|
10
|
-
};
|
|
11
|
-
webhookSecret?: string;
|
|
12
6
|
webhookUrl?: string;
|
|
13
7
|
secureCookie?: boolean;
|
|
14
8
|
inject500?: boolean;
|
package/dist/src/server/app.js
CHANGED
|
@@ -78,18 +78,33 @@ function health() {
|
|
|
78
78
|
db,
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
/** Read per request so credentials saved from the dashboard take effect
|
|
82
|
+
* without restarting `serve`. */
|
|
83
|
+
function liveGithubConfig() {
|
|
84
|
+
const config = readConfig();
|
|
85
|
+
return {
|
|
86
|
+
githubApp: config.githubAppId && config.githubAppPrivateKey
|
|
87
|
+
? {
|
|
88
|
+
appId: config.githubAppId,
|
|
89
|
+
privateKeyPem: config.githubAppPrivateKey,
|
|
90
|
+
}
|
|
91
|
+
: undefined,
|
|
92
|
+
webhookSecret: config.githubWebhookSecret,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
81
95
|
export function createApp(deps) {
|
|
82
96
|
return {
|
|
83
97
|
async fetch(request, remoteAddr = "unknown") {
|
|
84
98
|
const url = new URL(request.url);
|
|
99
|
+
const { githubApp, webhookSecret } = liveGithubConfig();
|
|
85
100
|
const mutating = ["POST", "PATCH", "PUT", "DELETE"].includes(request.method);
|
|
86
101
|
if (url.pathname === "/api/health" && request.method === "GET") {
|
|
87
102
|
return health();
|
|
88
103
|
}
|
|
89
104
|
if (url.pathname === "/github/webhook" && request.method === "POST") {
|
|
90
|
-
return await handleWebhookRequest(request,
|
|
105
|
+
return await handleWebhookRequest(request, webhookSecret);
|
|
91
106
|
}
|
|
92
|
-
const page = await handlePageRequest(request, deps, remoteAddr);
|
|
107
|
+
const page = await handlePageRequest(request, { ...deps, githubApp }, remoteAddr);
|
|
93
108
|
if (page)
|
|
94
109
|
return page;
|
|
95
110
|
if (url.pathname.startsWith("/api/remote/")) {
|
|
@@ -122,10 +137,10 @@ export function createApp(deps) {
|
|
|
122
137
|
return handleJobsRoute(request, url);
|
|
123
138
|
}
|
|
124
139
|
if (url.pathname.startsWith("/api/repos")) {
|
|
125
|
-
return await handleReposRoute(request, url,
|
|
140
|
+
return await handleReposRoute(request, url, githubApp);
|
|
126
141
|
}
|
|
127
142
|
if (url.pathname === "/api/installations") {
|
|
128
|
-
return await handleInstallationsRoute(request,
|
|
143
|
+
return await handleInstallationsRoute(request, githubApp);
|
|
129
144
|
}
|
|
130
145
|
if (url.pathname.startsWith("/api/settings")) {
|
|
131
146
|
return await handleSettingsRoute(request, url, deps.webhookUrl ?? "");
|
|
@@ -211,7 +211,10 @@ export async function runInitOrRemake(options) {
|
|
|
211
211
|
result = await timed("reassemble valid skill", options.logTime, () => assembleSkill(options.repo, facts, previousMarkdown, previous?.sectionHashes ?? {}, overrides));
|
|
212
212
|
result.markdown = addReviewLink(result.markdown, reviewDocuments);
|
|
213
213
|
}
|
|
214
|
-
const finalValidation = await timed("final skill validation", options.logTime, () => validateSkill(result.markdown, `${reposDir()}/${options.repo}`, source));
|
|
214
|
+
const finalValidation = await timed("final skill validation", options.logTime, () => validateSkill(result.markdown, `${reposDir()}/${options.repo}`, source, "warning"));
|
|
215
|
+
if (finalValidation.warnings.length) {
|
|
216
|
+
log("validate", `stale references kept: ${finalValidation.warnings.join(", ")}`);
|
|
217
|
+
}
|
|
215
218
|
if (!finalValidation.valid) {
|
|
216
219
|
throw new Error(`generated skill is invalid: ${finalValidation.errors.join("; ")}`);
|
|
217
220
|
}
|