feat(brain): a sandboxed language model session with an MCP channel to the box
The brain: a long-running Claude Code session, confined with bwrap to its workspace, that hears the box through a channel and works the TV with the box's ir and look capabilities. - brain/channel.js: MCP on stdio to the brain (reply, say, ir_listen, ir_send, look, report_problem), and the ask capability, behind a gate, to the box - brain/ask.js: the conversations between them; report.js: an issue on one repository, by a token that can do nothing else - brain/brain.service: the session in tmux, in bwrap: a read-only system, an empty home but for its workspace, keys, and claude - brain/instructions.md: how to work the TV; it imports household.md, who's who (an example, with no real people) - brain/Makefile: make install, attach, status - checks: brain-js (unit tests), brain (the package, put together) Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
190600a696
commit
5cbea49349
16 files changed
+927
-1
No files matched your search
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file The brain's report_problem: open an issue on one GitHub repo, assigned to whoever looks after
|
||||
* the box, so they get mail. The authority is a fine-grained token for that repo alone, with Issues
|
||||
* read/write and nothing else.
|
||||
*/
|
||||
|
||||
export const MAX_TITLE_CHARS = 200;
|
||||
export const MAX_DETAILS_CHARS = 10_000;
|
||||
|
||||
/**
|
||||
* @param {(path: string, body: object) => Promise<{ status: number, json: any }>} post
|
||||
* POSTs JSON to the GitHub API, authorized with the token
|
||||
* @param {string} repo owner/name
|
||||
* @param {string} assignee who gets the mail
|
||||
*/
|
||||
export const makeReporter = (post, repo, assignee) =>
|
||||
/** @param {string} title @param {string} details */
|
||||
async (title, details) => {
|
||||
if (typeof title !== 'string' || !title.trim()) throw new TypeError('title: a short summary');
|
||||
if (title.length > MAX_TITLE_CHARS) throw new RangeError(`title over ${MAX_TITLE_CHARS} chars`);
|
||||
if (typeof details !== 'string') throw new TypeError('details: what happened, and what you tried');
|
||||
if (details.length > MAX_DETAILS_CHARS) throw new RangeError(`details over ${MAX_DETAILS_CHARS} chars`);
|
||||
const { status, json } = await post(`/repos/${repo}/issues`, {
|
||||
title: title.trim(),
|
||||
body: `${details}\n\n— reported by the agent at the TV`,
|
||||
assignees: [assignee],
|
||||
});
|
||||
if (status !== 201) throw new Error(`GitHub said ${status}: ${json?.message ?? ''}`);
|
||||
return `reported as #${json.number}: ${json.html_url}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* POST JSON to the GitHub API with a token.
|
||||
* @param {typeof fetch} fetch
|
||||
* @param {string} token
|
||||
*/
|
||||
export const makeGitHubPost = (fetch, token) =>
|
||||
/** @param {string} path @param {object} body */
|
||||
async (path, body) => {
|
||||
const res = await fetch(`https://api.github.com${path}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
accept: 'application/vnd.github+json',
|
||||
'content-type': 'application/json',
|
||||
'user-agent': 'pdtv26-brain (brain/report.js)',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
return { status: res.status, json: await res.json().catch(() => undefined) };
|
||||
};
|
||||
Reference in new issue
Block a user