@technomoron/agent-brain 0.1.3 → 0.1.6
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/CHANGES.md +15 -0
- package/README.md +141 -136
- package/dist/brain/cli.js +12 -43
- package/dist/brain/config.js +1 -0
- package/dist/brain/github-client.js +78 -0
- package/dist/brain/github-issues.js +332 -0
- package/dist/brain/issue-configuration-tools.js +29 -0
- package/dist/brain/issue-configuration.js +398 -0
- package/dist/brain/issue-tools.js +61 -0
- package/dist/brain/remote-policy.js +7 -6
- package/dist/brain/remote-server.js +108 -19
- package/dist/brain/repository-discovery.js +36 -2
- package/dist/brain/server.js +11 -63
- package/dist/brain/skills.js +18 -5
- package/dist/brain/todos.js +3 -99
- package/ops/config-deploy-entry.sh +1 -1
- package/ops/config-deploy-root.cjs +8 -6
- package/ops/config-deploy.cjs +7 -6
- package/ops/config-policy.cjs +23 -1
- package/ops/layout.cjs +13 -0
- package/package.json +9 -6
- package/skills/brain-memory/SKILL.md +5 -5
- package/skills/changelog/SKILL.md +25 -0
- package/skills/code-review/README.md +2 -2
- package/skills/code-review/SKILL.md +48 -12
- package/skills/git-workflow/SKILL.md +12 -2
- package/skills/github-issue-cleanup/SKILL.md +20 -0
- package/skills/github-release/SKILL.md +14 -0
- package/skills/package-integrity-check/SKILL.md +3 -2
- package/skills/todo-manager/README.md +2 -2
- package/skills/todo-manager/SKILL.md +11 -5
- package/skills/unslop/SKILL.md +4 -1
- package/dist/brain/connectors.js +0 -65
- package/dist/brain/github-reviews.js +0 -187
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GithubReviews = exports.reviewInput = void 0;
|
|
4
|
-
exports.githubReviews = githubReviews;
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const node_crypto_1 = require("node:crypto");
|
|
7
|
-
const jsonc_parser_1 = require("jsonc-parser");
|
|
8
|
-
const zod_1 = require("zod");
|
|
9
|
-
const repositories_1 = require("./repositories");
|
|
10
|
-
const config_1 = require("./config");
|
|
11
|
-
const store_1 = require("./store");
|
|
12
|
-
const configSchema = zod_1.z.object({ backend: zod_1.z.literal('github'), repository: repositories_1.repositoryId.optional(),
|
|
13
|
-
tokenEnv: zod_1.z.string().regex(/^[A-Z_][A-Z0-9_]*$/).default('GITHUB_TOKEN'), writesEnabled: zod_1.z.boolean().default(false) }).strict();
|
|
14
|
-
exports.reviewInput = zod_1.z.object({ key: zod_1.z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*$/).max(200),
|
|
15
|
-
title: zod_1.z.string().trim().min(1).max(250), content: zod_1.z.string().trim().min(1).max(40000), severity: store_1.severitySchema,
|
|
16
|
-
applies_to: zod_1.z.array(zod_1.z.string().max(500)).max(100).default([]), confirmed: zod_1.z.literal(true) }).strict();
|
|
17
|
-
const metadata = zod_1.z.object({ key: zod_1.z.string(), severity: store_1.severitySchema, applies_to: zod_1.z.array(zod_1.z.string()) });
|
|
18
|
-
const issueSchema = zod_1.z.object({ number: zod_1.z.number().int().positive(), title: zod_1.z.string(), body: zod_1.z.string().nullable(),
|
|
19
|
-
state: zod_1.z.enum(['open', 'closed']), state_reason: zod_1.z.string().nullable().optional(), html_url: zod_1.z.string().url(),
|
|
20
|
-
updated_at: zod_1.z.string(), pull_request: zod_1.z.unknown().optional() });
|
|
21
|
-
// Hash review content for revisions and repository-specific retry files.
|
|
22
|
-
const hash = (value) => (0, node_crypto_1.createHash)('sha256').update(value).digest('hex');
|
|
23
|
-
const start = '<!-- agent-mcp-review:start -->';
|
|
24
|
-
const end = '<!-- agent-mcp-review:end -->';
|
|
25
|
-
class GithubReviews {
|
|
26
|
-
// Bind the review backend to its store, configuration and GitHub repository.
|
|
27
|
-
constructor(store, config, repository) {
|
|
28
|
-
this.store = store;
|
|
29
|
-
this.config = config;
|
|
30
|
-
this.repository = repository;
|
|
31
|
-
}
|
|
32
|
-
// Send an authenticated GitHub issue request with time and size limits.
|
|
33
|
-
async request(route, method = 'GET', body) {
|
|
34
|
-
const token = process.env[this.config.tokenEnv];
|
|
35
|
-
if (!token)
|
|
36
|
-
throw new Error('Set ' + this.config.tokenEnv + ' for GitHub reviews');
|
|
37
|
-
const response = await fetch('https://api.github.com/repos/' + this.repository + '/issues' + route, {
|
|
38
|
-
method, redirect: 'error', signal: AbortSignal.timeout(30000), headers: { accept: 'application/vnd.github+json',
|
|
39
|
-
'content-type': 'application/json', 'user-agent': 'agent-brain', authorization: 'Bearer ' + token,
|
|
40
|
-
'X-GitHub-Api-Version': '2026-03-10' }, ...(body ? { body: JSON.stringify(body) } : {})
|
|
41
|
-
});
|
|
42
|
-
if (!response.ok)
|
|
43
|
-
throw new Error('GitHub review request failed with HTTP ' + response.status);
|
|
44
|
-
const text = await response.text();
|
|
45
|
-
if (text.length > 4 * 1024 * 1024)
|
|
46
|
-
throw new Error('GitHub response exceeds 4 MiB');
|
|
47
|
-
return JSON.parse(text);
|
|
48
|
-
}
|
|
49
|
-
// Extract managed review metadata from an ordinary GitHub issue.
|
|
50
|
-
data(issue) {
|
|
51
|
-
if (issue.pull_request)
|
|
52
|
-
return null;
|
|
53
|
-
const body = issue.body ?? '';
|
|
54
|
-
const match = /<!-- agent-mcp-meta:([A-Za-z0-9_-]+) -->/.exec(body);
|
|
55
|
-
if (!match || !body.includes(start) || !body.includes(end))
|
|
56
|
-
return null;
|
|
57
|
-
let decoded;
|
|
58
|
-
try {
|
|
59
|
-
decoded = JSON.parse(Buffer.from(match[1], 'base64url').toString('utf8'));
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const parsed = metadata.safeParse(decoded);
|
|
65
|
-
if (!parsed.success)
|
|
66
|
-
return null;
|
|
67
|
-
return { ...parsed.data, id: 'github:' + this.repository + '#' + issue.number, finding: '#' + issue.number,
|
|
68
|
-
title: issue.title, content: body, state: issue.state === 'open' ? 'open' : issue.state_reason === 'not_planned' ? 'wontfix' : 'fixed',
|
|
69
|
-
url: issue.html_url, revision: hash(JSON.stringify(issue)), backend: 'github' };
|
|
70
|
-
}
|
|
71
|
-
// Page through managed findings and sort them by severity.
|
|
72
|
-
async list(state = 'open') {
|
|
73
|
-
const found = [];
|
|
74
|
-
for (let page = 1; page <= 100; page++) {
|
|
75
|
-
const issues = zod_1.z.array(issueSchema).parse(await this.request('?state=' + state + '&per_page=100&page=' + page));
|
|
76
|
-
for (const issue of issues) {
|
|
77
|
-
const item = this.data(issue);
|
|
78
|
-
if (item)
|
|
79
|
-
found.push(item);
|
|
80
|
-
}
|
|
81
|
-
if (issues.length < 100)
|
|
82
|
-
return found.sort((a, b) => ['critical', 'high', 'medium', 'low'].indexOf(a.severity) - ['critical', 'high', 'medium', 'low'].indexOf(b.severity));
|
|
83
|
-
}
|
|
84
|
-
throw new Error('GitHub review listing exceeds 100 pages; narrow the repository backlog before retrying');
|
|
85
|
-
}
|
|
86
|
-
// Extract an issue number belonging to the configured repository.
|
|
87
|
-
number(id) {
|
|
88
|
-
const prefix = 'github:' + this.repository + '#';
|
|
89
|
-
const number = id.startsWith(prefix) ? id.slice(prefix.length) : id.replace(/^#/, '');
|
|
90
|
-
if (!/^[1-9][0-9]*$/.test(number))
|
|
91
|
-
throw new Error('Issue must belong to the configured repository');
|
|
92
|
-
return number;
|
|
93
|
-
}
|
|
94
|
-
// Read a managed GitHub finding by its issue identity.
|
|
95
|
-
async get(id) {
|
|
96
|
-
const item = this.data(issueSchema.parse(await this.request('/' + this.number(id))));
|
|
97
|
-
if (!item)
|
|
98
|
-
throw new Error('Issue is not an agent-mcp review finding');
|
|
99
|
-
return item;
|
|
100
|
-
}
|
|
101
|
-
// Serialize GitHub writes and enforce the explicit write gate.
|
|
102
|
-
async locked(work) {
|
|
103
|
-
if (!this.config.writesEnabled)
|
|
104
|
-
throw new Error('GitHub review writes are disabled; configure writesEnabled explicitly');
|
|
105
|
-
const lock = this.store.safePath('runtime', 'github-review.lock');
|
|
106
|
-
const descriptor = fs.openSync(lock, 'wx', 0o600);
|
|
107
|
-
try {
|
|
108
|
-
return await work();
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
fs.closeSync(descriptor);
|
|
112
|
-
fs.unlinkSync(lock);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Encode a finding inside the reserved GitHub review markers.
|
|
116
|
-
block(input) {
|
|
117
|
-
if (input.content.includes('<!-- agent-mcp-'))
|
|
118
|
-
throw new Error('Finding content contains a reserved marker');
|
|
119
|
-
const encoded = Buffer.from(JSON.stringify({ key: input.key, severity: input.severity, applies_to: input.applies_to })).toString('base64url');
|
|
120
|
-
return start + '\n<!-- agent-mcp-meta:' + encoded + ' -->\nSeverity: ' + input.severity + '\n\n' + input.content + '\n' + end;
|
|
121
|
-
}
|
|
122
|
-
// Create a finding or return the issue already associated with its retry key.
|
|
123
|
-
async create(input) {
|
|
124
|
-
input = exports.reviewInput.parse(input);
|
|
125
|
-
return this.locked(async () => {
|
|
126
|
-
const file = this.store.safePath('runtime', 'github-review-keys-' + hash(this.repository) + '.json');
|
|
127
|
-
const keys = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
128
|
-
if (Object.prototype.hasOwnProperty.call(keys, input.key)) {
|
|
129
|
-
const existing = await this.get(keys[input.key]);
|
|
130
|
-
if (existing.key !== input.key)
|
|
131
|
-
throw new Error('Stored review retry key does not match its GitHub issue');
|
|
132
|
-
return { ...existing, created: false };
|
|
133
|
-
}
|
|
134
|
-
const existing = (await this.list('all')).find((item) => item.key === input.key);
|
|
135
|
-
if (existing)
|
|
136
|
-
return { ...existing, created: false };
|
|
137
|
-
const item = this.data(issueSchema.parse(await this.request('', 'POST', { title: input.title, body: this.block(input) })));
|
|
138
|
-
if (!item)
|
|
139
|
-
throw new Error('GitHub returned an invalid review finding');
|
|
140
|
-
Object.defineProperty(keys, input.key, { value: item.id, enumerable: true, configurable: true, writable: true });
|
|
141
|
-
fs.writeFileSync(file + '.tmp', JSON.stringify(keys), { mode: 0o600 });
|
|
142
|
-
fs.renameSync(file + '.tmp', file);
|
|
143
|
-
return { ...item, created: true };
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
// Revise the managed finding while preserving unrelated issue content.
|
|
147
|
-
async update(id, revision, changes) {
|
|
148
|
-
return this.locked(async () => {
|
|
149
|
-
const current = await this.get(id);
|
|
150
|
-
if (current.revision !== revision)
|
|
151
|
-
throw new Error('GitHub finding changed; read it again before updating');
|
|
152
|
-
const managed = current.content.slice(current.content.indexOf(start), current.content.indexOf(end));
|
|
153
|
-
const block = this.block({ ...current, ...changes, content: changes.content ?? managed.slice(managed.indexOf('\n\n') + 2).trim() });
|
|
154
|
-
const body = current.content.slice(0, current.content.indexOf(start)) + block + current.content.slice(current.content.indexOf(end) + end.length);
|
|
155
|
-
const issue = issueSchema.parse(await this.request('/' + this.number(id), 'PATCH', { title: changes.title ?? current.title, body }));
|
|
156
|
-
return this.data(issue);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
// Close a current finding with its resolution reason.
|
|
160
|
-
async resolve(id, revision, state, reason) {
|
|
161
|
-
return this.locked(async () => {
|
|
162
|
-
const current = await this.get(id);
|
|
163
|
-
if (current.revision !== revision)
|
|
164
|
-
throw new Error('GitHub finding changed; read it again before closing');
|
|
165
|
-
const issue = issueSchema.parse(await this.request('/' + this.number(id), 'PATCH', {
|
|
166
|
-
state: 'closed', state_reason: state === 'fixed' ? 'completed' : 'not_planned', body: current.content + '\n\nResolution: ' + reason
|
|
167
|
-
}));
|
|
168
|
-
return this.data(issue);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.GithubReviews = GithubReviews;
|
|
173
|
-
// Load the optional GitHub review backend for the active profile.
|
|
174
|
-
function githubReviews(store) {
|
|
175
|
-
const file = store.safePath(store.profile ?? 'default', 'review.jsonc');
|
|
176
|
-
if (!fs.existsSync(file))
|
|
177
|
-
return null;
|
|
178
|
-
const errors = [];
|
|
179
|
-
const config = configSchema.parse((0, jsonc_parser_1.parse)(store.read(file), errors));
|
|
180
|
-
if (errors.length)
|
|
181
|
-
throw new Error('Invalid review.jsonc');
|
|
182
|
-
const project = (0, config_1.listBrainProjects)(store.configRoot).find((item) => item.profile === store.profile);
|
|
183
|
-
const repository = config.repository ?? (project?.repository?.url ? (0, repositories_1.githubRepository)(project.repository.url) : null);
|
|
184
|
-
if (!repository)
|
|
185
|
-
throw new Error('GitHub reviews need an explicit repository or a registered GitHub remote');
|
|
186
|
-
return new GithubReviews(store, config, repository);
|
|
187
|
-
}
|