@agentshouse/kit 0.2.1-alpha.1 → 0.2.1-alpha.11
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 +20 -2
- package/dist/acp.js +3 -3
- package/dist/agents.js +6 -0
- package/dist/api.js +6 -1
- package/dist/authority-main.js +22 -0
- package/dist/bootstrap.json +28 -0
- package/dist/bridge.js +198 -46
- package/dist/clis.js +16 -1
- package/dist/configure-main.js +6 -0
- package/dist/conversations.js +97 -20
- package/dist/copies.js +809 -0
- package/dist/enrol-main.js +4 -0
- package/dist/git-main.js +153 -0
- package/dist/git.js +81 -0
- package/dist/home.js +19 -6
- package/dist/house-main.js +90 -29
- package/dist/instructions.js +15 -10
- package/dist/kit-main.js +2 -0
- package/dist/login.js +6 -2
- package/dist/operation.js +12 -0
- package/dist/refusals.js +41 -0
- package/dist/resident.js +62 -7
- package/dist/sign-in.js +6 -2
- package/dist/skills.js +78 -0
- package/dist/translate.js +51 -0
- package/dist/update.js +116 -0
- package/how-we-work.md +23 -0
- package/package.json +11 -4
- package/skills/ask-matt/LICENSE +21 -0
- package/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/skills/ask-matt/SKILL.md +91 -0
- package/skills/ask-matt/agents/openai.yaml +4 -0
- package/skills/code-review/LICENSE +21 -0
- package/skills/code-review/SKILL.md +89 -0
- package/skills/code-review/agents/openai.yaml +3 -0
- package/skills/codebase-design/DEEPENING.md +37 -0
- package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/skills/codebase-design/LICENSE +21 -0
- package/skills/codebase-design/SKILL.md +116 -0
- package/skills/codebase-design/agents/openai.yaml +3 -0
- package/skills/diagnosing-bugs/LICENSE +21 -0
- package/skills/diagnosing-bugs/SKILL.md +140 -0
- package/skills/diagnosing-bugs/agents/openai.yaml +3 -0
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/skills/domain-modeling/LICENSE +21 -0
- package/skills/domain-modeling/SKILL.md +76 -0
- package/skills/domain-modeling/agents/openai.yaml +3 -0
- package/skills/grill-me/LICENSE +21 -0
- package/skills/grill-me/SKILL.md +8 -0
- package/skills/grill-me/agents/openai.yaml +4 -0
- package/skills/grill-with-docs/LICENSE +21 -0
- package/skills/grill-with-docs/SKILL.md +8 -0
- package/skills/grill-with-docs/agents/openai.yaml +4 -0
- package/skills/grilling/LICENSE +21 -0
- package/skills/grilling/SKILL.md +30 -0
- package/skills/grilling/agents/openai.yaml +3 -0
- package/skills/handoff/LICENSE +21 -0
- package/skills/handoff/SKILL.md +17 -0
- package/skills/handoff/agents/openai.yaml +4 -0
- package/skills/implement/LICENSE +21 -0
- package/skills/implement/SKILL.md +16 -0
- package/skills/implement/agents/openai.yaml +4 -0
- package/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/skills/improve-codebase-architecture/LICENSE +21 -0
- package/skills/improve-codebase-architecture/SKILL.md +72 -0
- package/skills/improve-codebase-architecture/agents/openai.yaml +4 -0
- package/skills/prototype/LICENSE +21 -0
- package/skills/prototype/LOGIC.md +67 -0
- package/skills/prototype/SKILL.md +28 -0
- package/skills/prototype/UI.md +112 -0
- package/skills/prototype/agents/openai.yaml +3 -0
- package/skills/research/LICENSE +21 -0
- package/skills/research/SKILL.md +14 -0
- package/skills/research/agents/openai.yaml +3 -0
- package/skills/resolving-merge-conflicts/LICENSE +21 -0
- package/skills/resolving-merge-conflicts/SKILL.md +16 -0
- package/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/skills/tdd/LICENSE +21 -0
- package/skills/tdd/SKILL.md +40 -0
- package/skills/tdd/agents/openai.yaml +3 -0
- package/skills/tdd/mocking.md +59 -0
- package/skills/tdd/tests.md +77 -0
- package/skills/teach/GLOSSARY-FORMAT.md +35 -0
- package/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/skills/teach/LICENSE +21 -0
- package/skills/teach/MISSION-FORMAT.md +31 -0
- package/skills/teach/RESOURCES-FORMAT.md +32 -0
- package/skills/teach/SKILL.md +141 -0
- package/skills/teach/agents/openai.yaml +4 -0
- package/skills/to-questionnaire/LICENSE +21 -0
- package/skills/to-questionnaire/SKILL.md +55 -0
- package/skills/to-questionnaire/agents/openai.yaml +4 -0
- package/skills/to-spec/LICENSE +21 -0
- package/skills/to-spec/SKILL.md +76 -0
- package/skills/to-spec/agents/openai.yaml +4 -0
- package/skills/to-tickets/LICENSE +21 -0
- package/skills/to-tickets/SKILL.md +106 -0
- package/skills/to-tickets/agents/openai.yaml +4 -0
- package/skills/wait-what/LICENSE +21 -0
- package/skills/wait-what/SKILL.md +8 -0
- package/skills/wait-what/agents/openai.yaml +4 -0
- package/skills/wayfinder/LICENSE +21 -0
- package/skills/wayfinder/SKILL.md +129 -0
- package/skills/wayfinder/agents/openai.yaml +4 -0
- package/skills/writing-for-agents/LICENSE +21 -0
- package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/skills/writing-for-agents/SKILL.md +83 -0
- package/skills/writing-for-agents/agents/openai.yaml +3 -0
package/README.md
CHANGED
|
@@ -7,7 +7,19 @@ through the agent CLIs you chose and gives each Agent the `house` command.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
Connect a computer from agents.house. It gives you the one command that
|
|
10
|
-
installs House Kit on that computer and updates it when you run it again.
|
|
10
|
+
installs House Kit on that computer and updates it when you run it again. On
|
|
11
|
+
Linux, macOS and Windows 11 it runs House Kit in one Docker container with
|
|
12
|
+
your workspace, `~/AgentsHouse` unless you pass `--workspace <path>`, mounted
|
|
13
|
+
at `/agents/house`. Append a `kit` or `house` command to the same command to
|
|
14
|
+
run it in that container.
|
|
15
|
+
|
|
16
|
+
On your own Ubuntu 26.04 server, run the Linux command with `--linux` to
|
|
17
|
+
install House Kit natively, with its workspace at `/agents/house`; `kit` and
|
|
18
|
+
`house` are then on the server's `PATH`.
|
|
19
|
+
|
|
20
|
+
House Kit also gives every Agent on the Environment a set of agent skills. Add
|
|
21
|
+
`--no-skills` to the command to leave them out; running it again without the
|
|
22
|
+
flag brings them back.
|
|
11
23
|
|
|
12
24
|
## Commands
|
|
13
25
|
|
|
@@ -16,8 +28,14 @@ Environment's credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is
|
|
|
16
28
|
set. Pass `--manual` to paste the code by hand on a machine without a browser,
|
|
17
29
|
and `--environment <id>` to reconnect an Environment you already have.
|
|
18
30
|
|
|
19
|
-
`kit resident` keeps the Environment connected
|
|
31
|
+
`kit resident` keeps the Environment connected, and keeps the Rooms you chose
|
|
32
|
+
for this Environment as Git repositories under `/agents/house/working-copies`.
|
|
33
|
+
Commit in one and run `house git push --owner` there to send the commit to
|
|
34
|
+
House; on a computer, run it through the install command from the copy's
|
|
35
|
+
directory. Inside an Agent conversation the Agent runs `house git push`.
|
|
20
36
|
|
|
21
37
|
## License
|
|
22
38
|
|
|
23
39
|
MIT
|
|
40
|
+
|
|
41
|
+
The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
|
package/dist/acp.js
CHANGED
|
@@ -2,13 +2,13 @@ import { ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { readdirSync, readFileSync } from 'node:fs';
|
|
4
4
|
import { Readable, Writable } from 'node:stream';
|
|
5
|
-
import { CLIS, KIT_VERSION, cliCommand } from './clis.js';
|
|
5
|
+
import { CLIS, KIT_VERSION, cliCommand, withoutProxy } from './clis.js';
|
|
6
6
|
export const TURN_STARTED = 'kit/turn_started';
|
|
7
7
|
export const TURN_ENDED = 'kit/turn_ended';
|
|
8
|
-
export async function startAdapter(kind, cwd, app, jobs = () => undefined,
|
|
8
|
+
export async function startAdapter(kind, cwd, app, jobs = () => undefined, added = {}) {
|
|
9
9
|
const child = spawn(cliCommand(kind), CLIS[kind].args, {
|
|
10
10
|
cwd,
|
|
11
|
-
env,
|
|
11
|
+
env: { ...withoutProxy(), ...added },
|
|
12
12
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
13
13
|
detached: true,
|
|
14
14
|
});
|
package/dist/agents.js
CHANGED
|
@@ -18,6 +18,10 @@ async function signedIn(kind) {
|
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
async function sshHostKey() {
|
|
22
|
+
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
23
|
+
return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
|
|
24
|
+
}
|
|
21
25
|
async function operatingSystem() {
|
|
22
26
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
23
27
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
@@ -63,10 +67,12 @@ export class Agents {
|
|
|
63
67
|
for (const [kind, release] of this.releases) {
|
|
64
68
|
agents.push({ kind, release, signed_in: release !== null && (await signedIn(kind)) });
|
|
65
69
|
}
|
|
70
|
+
const hostKey = await sshHostKey();
|
|
66
71
|
await this.house.deliver('/kit/agents/report', {
|
|
67
72
|
os: await operatingSystem(),
|
|
68
73
|
kit_version: KIT_VERSION,
|
|
69
74
|
agents,
|
|
75
|
+
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
70
76
|
});
|
|
71
77
|
}
|
|
72
78
|
async install(kinds) {
|
package/dist/api.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { readEnrolment } from './home.js';
|
|
2
2
|
export class HouseRefusal extends Error {
|
|
3
3
|
status;
|
|
4
|
+
text;
|
|
4
5
|
constructor(path, status, text) {
|
|
5
6
|
super(`House refused ${path} with ${status}: ${text}`);
|
|
6
7
|
this.status = status;
|
|
8
|
+
this.text = text;
|
|
7
9
|
}
|
|
8
10
|
}
|
|
11
|
+
export function retryDelay(attempt) {
|
|
12
|
+
return Math.min(30_000, 1000 * 2 ** attempt);
|
|
13
|
+
}
|
|
9
14
|
export async function post(house, path, body, credential, signal) {
|
|
10
15
|
const answer = await fetch(new URL(path, house), {
|
|
11
16
|
method: 'POST',
|
|
@@ -36,7 +41,7 @@ export const house = {
|
|
|
36
41
|
if (error instanceof HouseRefusal && error.status < 500)
|
|
37
42
|
throw error;
|
|
38
43
|
process.stderr.write(`kit: ${path} did not reach House: ${error.message}\n`);
|
|
39
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
|
|
40
45
|
if (!current())
|
|
41
46
|
throw error;
|
|
42
47
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
import { HouseRefusal, post } from './api.js';
|
|
3
|
+
import { readEnrolment } from './home.js';
|
|
4
|
+
function unanswered(error) {
|
|
5
|
+
return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
|
|
6
|
+
}
|
|
7
|
+
setGlobalProxyFromEnv();
|
|
8
|
+
try {
|
|
9
|
+
const { house, credential } = (await readEnrolment());
|
|
10
|
+
try {
|
|
11
|
+
await post(house, '/kit/agents/desired', {}, credential);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (!unanswered(error))
|
|
15
|
+
throw error;
|
|
16
|
+
process.stderr.write(`kit: House did not answer, so the stored credential stands: ${error.message}\n`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"version": "0.2.1-alpha.11",
|
|
4
|
+
"hosts": {
|
|
5
|
+
"linux": {
|
|
6
|
+
"command": "bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.11/connect-linux.sh)",
|
|
7
|
+
"asset": {
|
|
8
|
+
"name": "connect-linux.sh",
|
|
9
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.11/connect-linux.sh"
|
|
10
|
+
},
|
|
11
|
+
"workspace": {
|
|
12
|
+
"argument": "--workspace",
|
|
13
|
+
"quoting": "posix"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"windows": {
|
|
17
|
+
"command": "& ([scriptblock]::Create((irm https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.11/connect-windows.ps1)))",
|
|
18
|
+
"asset": {
|
|
19
|
+
"name": "connect-windows.ps1",
|
|
20
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.11/connect-windows.ps1"
|
|
21
|
+
},
|
|
22
|
+
"workspace": {
|
|
23
|
+
"argument": "--workspace",
|
|
24
|
+
"quoting": "powershell"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/bridge.js
CHANGED
|
@@ -1,79 +1,236 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { once } from 'node:events';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
4
|
import { mkdir } from 'node:fs/promises';
|
|
4
5
|
import { createServer, request as httpRequest } from 'node:http';
|
|
5
6
|
import { request as httpsRequest } from 'node:https';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
+
import { delimiter, join } from 'node:path';
|
|
8
|
+
import { parse } from 'yaml';
|
|
9
|
+
import { HouseRefusal, retryDelay } from './api.js';
|
|
7
10
|
import { KIT_VERSION } from './clis.js';
|
|
11
|
+
import { changedPaths, } from './copies.js';
|
|
8
12
|
import { kitHome, readEnrolment } from './home.js';
|
|
13
|
+
import { operationId, uuidOf } from './operation.js';
|
|
14
|
+
import { refusalOf } from './refusals.js';
|
|
9
15
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
bytes.writeUIntBE(Date.now(), 0, 6);
|
|
14
|
-
bytes[6] = 0x70 | (bytes[6] & 0x0f);
|
|
15
|
-
bytes[8] = 0x80 | (bytes[8] & 0x3f);
|
|
16
|
-
const hex = bytes.toString('hex');
|
|
17
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
18
|
-
}
|
|
19
|
-
async function received(request) {
|
|
16
|
+
const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
17
|
+
const ATTACHMENTS = '/kit/attachments/upload';
|
|
18
|
+
export async function received(request) {
|
|
20
19
|
let text = '';
|
|
21
20
|
request.setEncoding('utf8');
|
|
22
21
|
for await (const chunk of request)
|
|
23
22
|
text += chunk;
|
|
24
23
|
return text;
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
function relay(request, response, target, authorization) {
|
|
26
|
+
const send = target.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
27
|
+
const forwarded = send(target, {
|
|
28
|
+
method: request.method,
|
|
29
|
+
headers: { ...request.headers, host: target.host, ...(authorization === undefined ? {} : { authorization }) },
|
|
30
|
+
}, (answer) => {
|
|
31
|
+
response.writeHead(answer.statusCode, answer.headers);
|
|
32
|
+
answer.pipe(response);
|
|
33
|
+
});
|
|
34
|
+
forwarded.on('error', () => response.destroy());
|
|
35
|
+
request.pipe(forwarded);
|
|
36
|
+
}
|
|
37
|
+
const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
38
|
+
function refusalIn(text, status) {
|
|
39
|
+
return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [] };
|
|
40
|
+
}
|
|
41
|
+
function answered(forwarded) {
|
|
42
|
+
if (forwarded.status >= 500)
|
|
43
|
+
throw new HouseRefusal('/', forwarded.status, forwarded.text);
|
|
44
|
+
if (forwarded.status !== 200)
|
|
45
|
+
return { refused: refusalIn(forwarded.text, forwarded.status) };
|
|
46
|
+
const answer = JSON.parse(forwarded.text);
|
|
47
|
+
if (answer.error !== undefined)
|
|
48
|
+
return { refused: refusalIn(answer.error.message, forwarded.status) };
|
|
49
|
+
const text = answer.result.content.map((content) => content.text).join('\n');
|
|
50
|
+
return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
|
|
51
|
+
}
|
|
52
|
+
function pendingSeconds(forwarded) {
|
|
53
|
+
if (forwarded.status !== 200)
|
|
54
|
+
return null;
|
|
55
|
+
const { result } = JSON.parse(forwarded.text);
|
|
56
|
+
if (result === undefined || result.isError === true)
|
|
57
|
+
return null;
|
|
58
|
+
const text = result.content.map((content) => content.text).join('\n');
|
|
59
|
+
if (!text.startsWith('{"pending":'))
|
|
60
|
+
return null;
|
|
61
|
+
const seconds = JSON.parse(text).pending.retry_after;
|
|
62
|
+
return typeof seconds === 'number' ? seconds : null;
|
|
63
|
+
}
|
|
64
|
+
function resendAfter(forwarded, attempt) {
|
|
65
|
+
if (forwarded === null)
|
|
66
|
+
return retryDelay(attempt);
|
|
67
|
+
if (forwarded.status >= 500)
|
|
68
|
+
return refusalOf(forwarded.text) === null ? retryDelay(attempt) : null;
|
|
69
|
+
const seconds = pendingSeconds(forwarded);
|
|
70
|
+
return seconds === null ? null : seconds * 1000;
|
|
71
|
+
}
|
|
72
|
+
function versioned(conversationId, text) {
|
|
73
|
+
const file = JSON.parse(text);
|
|
74
|
+
const identity = JSON.stringify([conversationId, file.room_ref ?? null, file.name, file.sha256]);
|
|
75
|
+
return JSON.stringify({ ...file, version: uuidOf(createHash('sha256').update(identity).digest(), 8) });
|
|
76
|
+
}
|
|
77
|
+
function editAnswer(forwarded) {
|
|
78
|
+
const answer = answered(forwarded);
|
|
79
|
+
if ('refused' in answer)
|
|
80
|
+
return answer;
|
|
81
|
+
const { results } = parse(answer.text);
|
|
82
|
+
return {
|
|
83
|
+
accepted: results.flatMap((result) => [
|
|
84
|
+
...(result.from === undefined ? [] : [{ path: result.from, revision: null, content: null }]),
|
|
85
|
+
{ path: result.path, revision: result.revision ?? null },
|
|
86
|
+
]),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export async function openBridge(house, copies, conversationId, signal) {
|
|
27
90
|
const origin = (await readEnrolment()).house;
|
|
28
91
|
const { credential } = await house.post(`/kit/conversations/${conversationId}/credential`, {}, signal);
|
|
29
92
|
const closed = new AbortController();
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
93
|
+
const body = (message, operation) => JSON.stringify({
|
|
94
|
+
...message,
|
|
95
|
+
params: {
|
|
96
|
+
...message.params,
|
|
97
|
+
_meta: {
|
|
98
|
+
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
99
|
+
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
|
|
100
|
+
'io.modelcontextprotocol/clientCapabilities': {},
|
|
101
|
+
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
const sent = async (message, operation) => {
|
|
106
|
+
const tool = message.method === 'tools/call' ? String(message.params?.name) : null;
|
|
107
|
+
const answer = await fetch(new URL('/', origin), {
|
|
108
|
+
method: 'POST',
|
|
36
109
|
headers: {
|
|
110
|
+
'content-type': 'application/json',
|
|
111
|
+
authorization: `Bearer ${credential}`,
|
|
37
112
|
accept: 'application/json, text/event-stream',
|
|
38
113
|
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
39
114
|
'mcp-method': message.method,
|
|
40
115
|
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
41
116
|
},
|
|
42
|
-
body:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
117
|
+
body: body(message, operation),
|
|
118
|
+
signal: closed.signal,
|
|
119
|
+
});
|
|
120
|
+
return { status: answer.status, text: await answer.text() };
|
|
121
|
+
};
|
|
122
|
+
const send = async (message, operation) => {
|
|
123
|
+
if (operation === null)
|
|
124
|
+
return sent(message, null);
|
|
125
|
+
for (let attempt = 0;; attempt++) {
|
|
126
|
+
const forwarded = await sent(message, operation).catch((error) => {
|
|
127
|
+
if (closed.signal.aborted)
|
|
128
|
+
throw error;
|
|
129
|
+
return null;
|
|
130
|
+
});
|
|
131
|
+
const after = resendAfter(forwarded, attempt);
|
|
132
|
+
if (after === null)
|
|
133
|
+
return forwarded;
|
|
134
|
+
await delay(after, undefined, { signal: closed.signal });
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const call = (name, args) => ({ jsonrpc: '2.0', id: randomUUID(), method: 'tools/call', params: { name, arguments: args } });
|
|
138
|
+
const staged = async (operation, changes) => {
|
|
139
|
+
const bytes = Buffer.from(JSON.stringify({ changes }));
|
|
140
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
141
|
+
const prepared = answered(await send(call('run_command', {
|
|
142
|
+
command: 'prepare_edit_upload',
|
|
143
|
+
arguments: { paths: changedPaths(changes), bytes: bytes.length, sha256 },
|
|
144
|
+
}), operation));
|
|
145
|
+
if ('refused' in prepared)
|
|
146
|
+
return prepared;
|
|
147
|
+
const { transfer } = parse(prepared.text);
|
|
148
|
+
const posted = await fetch(transfer.url, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers: { 'content-type': 'text/plain; charset=utf-8' },
|
|
151
|
+
body: Buffer.concat([Buffer.from(`${transfer.operation}\n`), bytes]),
|
|
152
|
+
signal: closed.signal,
|
|
153
|
+
});
|
|
154
|
+
const text = await posted.text();
|
|
155
|
+
if (posted.status >= 500)
|
|
156
|
+
throw new HouseRefusal('/', posted.status, text);
|
|
157
|
+
if (!posted.ok)
|
|
158
|
+
return { refused: refusalIn(text, posted.status) };
|
|
159
|
+
const held = JSON.parse(text).transfer;
|
|
160
|
+
return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
|
|
161
|
+
};
|
|
162
|
+
let mutations = null;
|
|
163
|
+
const writes = async (tool) => {
|
|
164
|
+
mutations ??= house
|
|
165
|
+
.post('/kit/tools/mutations', {}, closed.signal)
|
|
166
|
+
.then(({ tools }) => new Set(tools.filter((listed) => listed.writes).map((listed) => listed.name)));
|
|
167
|
+
try {
|
|
168
|
+
return (await mutations).has(tool);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
mutations = null;
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
55
174
|
};
|
|
56
175
|
const forward = async (path, text) => {
|
|
57
|
-
|
|
176
|
+
if (path === '/') {
|
|
177
|
+
const message = JSON.parse(text);
|
|
178
|
+
const tool = message.method === 'tools/call' ? String(message.params?.name) : null;
|
|
179
|
+
return send(message, tool !== null && (await writes(tool)) ? operationId() : null);
|
|
180
|
+
}
|
|
58
181
|
const answer = await fetch(new URL(path, origin), {
|
|
59
182
|
method: 'POST',
|
|
60
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}
|
|
61
|
-
body:
|
|
183
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}` },
|
|
184
|
+
body: versioned(conversationId, text),
|
|
62
185
|
signal: closed.signal,
|
|
63
186
|
});
|
|
64
187
|
return { status: answer.status, text: await answer.text() };
|
|
65
188
|
};
|
|
189
|
+
const caller = {
|
|
190
|
+
key: `conversation:${conversationId}`,
|
|
191
|
+
submit: async (operation, changes, held, retain) => {
|
|
192
|
+
const inline = call('edit', { changes });
|
|
193
|
+
let upload = held;
|
|
194
|
+
if (upload === undefined && Buffer.byteLength(body(inline, operation)) > MCP_REQUEST_BYTES) {
|
|
195
|
+
const prepared = await staged(operation, changes);
|
|
196
|
+
if ('refused' in prepared)
|
|
197
|
+
return prepared;
|
|
198
|
+
upload = prepared;
|
|
199
|
+
await retain(upload);
|
|
200
|
+
}
|
|
201
|
+
return editAnswer(await send(upload === undefined ? inline : call('edit', { paths: changedPaths(changes), upload }), operation));
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
const local = async (path, text) => {
|
|
205
|
+
if (path === '/git/push') {
|
|
206
|
+
const { cwd, commit } = JSON.parse(text);
|
|
207
|
+
return { status: 200, text: JSON.stringify(await copies.push(cwd, commit, caller)) };
|
|
208
|
+
}
|
|
209
|
+
if (path === '/git/observed') {
|
|
210
|
+
await copies.observed(JSON.parse(text));
|
|
211
|
+
return { status: 200, text: '{}' };
|
|
212
|
+
}
|
|
213
|
+
return path === '/' || path === ATTACHMENTS ? forward(path, text) : { status: 404, text: '' };
|
|
214
|
+
};
|
|
66
215
|
const sockets = join(kitHome(), 'bridges');
|
|
67
216
|
await mkdir(sockets, { recursive: true, mode: 0o700 });
|
|
68
217
|
const socketPath = join(sockets, `${randomUUID()}.sock`);
|
|
69
218
|
const bridge = createServer(async (request, response) => {
|
|
70
219
|
try {
|
|
71
220
|
const path = request.url ?? '';
|
|
72
|
-
|
|
73
|
-
|
|
221
|
+
if (URL.canParse(path)) {
|
|
222
|
+
relay(request, response, new URL(path));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const answered = await local(path, await received(request));
|
|
226
|
+
response.writeHead(answered.status, { 'content-type': 'application/json' }).end(answered.text);
|
|
74
227
|
}
|
|
75
228
|
catch (error) {
|
|
76
|
-
|
|
229
|
+
if (error instanceof HouseRefusal) {
|
|
230
|
+
response.writeHead(error.status, { 'content-type': 'application/json' }).end(error.text);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
response.writeHead(502).end(request.url === '/git/push' && error instanceof Error ? error.message : UNREACHABLE);
|
|
77
234
|
}
|
|
78
235
|
});
|
|
79
236
|
bridge.listen(socketPath);
|
|
@@ -86,13 +243,7 @@ export async function openBridge(house, conversationId, signal) {
|
|
|
86
243
|
response.writeHead(404).end();
|
|
87
244
|
return;
|
|
88
245
|
}
|
|
89
|
-
|
|
90
|
-
const forwarded = send(target, { method: request.method, headers: { ...request.headers, host: target.host, authorization } }, (answer) => {
|
|
91
|
-
response.writeHead(answer.statusCode, answer.headers);
|
|
92
|
-
answer.pipe(response);
|
|
93
|
-
});
|
|
94
|
-
forwarded.on('error', () => response.destroy());
|
|
95
|
-
request.pipe(forwarded);
|
|
246
|
+
relay(request, response, target, authorization);
|
|
96
247
|
});
|
|
97
248
|
git.listen(0, '127.0.0.1');
|
|
98
249
|
await once(git, 'listening');
|
|
@@ -100,12 +251,13 @@ export async function openBridge(house, conversationId, signal) {
|
|
|
100
251
|
return {
|
|
101
252
|
env: {
|
|
102
253
|
HOUSE_BRIDGE: socketPath,
|
|
254
|
+
PATH: `${join(kitHome(), 'shim')}${delimiter}${process.env.PATH ?? ''}`,
|
|
103
255
|
GIT_CONFIG_COUNT: '1',
|
|
104
256
|
GIT_CONFIG_KEY_0: `url.${proxy}/app/.insteadOf`,
|
|
105
257
|
GIT_CONFIG_VALUE_0: app,
|
|
106
258
|
},
|
|
107
259
|
tool: async (name, args) => {
|
|
108
|
-
const forwarded = await forward('/', JSON.stringify({ jsonrpc: '2.0', id:
|
|
260
|
+
const forwarded = await forward('/', JSON.stringify({ jsonrpc: '2.0', id: randomUUID(), method: 'tools/call', params: { name, arguments: args } }));
|
|
109
261
|
if (forwarded.status !== 200)
|
|
110
262
|
throw new Error(`House refused ${name} with ${forwarded.status}: ${forwarded.text}`);
|
|
111
263
|
const answer = JSON.parse(forwarded.text);
|
package/dist/clis.js
CHANGED
|
@@ -20,6 +20,14 @@ function asyncTask({ method, params }) {
|
|
|
20
20
|
}
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
+
function airPhase({ _meta }) {
|
|
24
|
+
const phase = _meta?.jetbrains?.air?.phase;
|
|
25
|
+
if (phase === 'commentary')
|
|
26
|
+
return 'note';
|
|
27
|
+
if (phase === 'final_answer')
|
|
28
|
+
return 'answer';
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
23
31
|
export const CLIS = {
|
|
24
32
|
'codex-acp': {
|
|
25
33
|
package: '@agentclientprotocol/codex-acp',
|
|
@@ -31,6 +39,7 @@ export const CLIS = {
|
|
|
31
39
|
turnStarted: (notice) => threadStatus(notice) === 'active',
|
|
32
40
|
turnEnded: (notice) => threadStatus(notice) === 'idle',
|
|
33
41
|
job: asyncTask,
|
|
42
|
+
phase: airPhase,
|
|
34
43
|
},
|
|
35
44
|
'claude-agent-acp': {
|
|
36
45
|
package: '@agentclientprotocol/claude-agent-acp',
|
|
@@ -44,6 +53,7 @@ export const CLIS = {
|
|
|
44
53
|
params?.update?.sessionUpdate === 'usage_update' &&
|
|
45
54
|
params.update._meta?.['_claude/origin'] !== undefined,
|
|
46
55
|
job: asyncTask,
|
|
56
|
+
phase: () => null,
|
|
47
57
|
},
|
|
48
58
|
'grok-build': {
|
|
49
59
|
package: '@xai-official/grok',
|
|
@@ -61,10 +71,12 @@ export const CLIS = {
|
|
|
61
71
|
return { id: params.update.task_snapshot.task_id, running: false };
|
|
62
72
|
return null;
|
|
63
73
|
},
|
|
74
|
+
phase: () => null,
|
|
64
75
|
},
|
|
65
76
|
};
|
|
66
77
|
const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
67
78
|
export const KIT_VERSION = KIT_PACKAGE.version;
|
|
79
|
+
const PROXY = /^https?_proxy$/i;
|
|
68
80
|
export function pinned(kind) {
|
|
69
81
|
return KIT_PACKAGE.peerDependencies[CLIS[kind].package];
|
|
70
82
|
}
|
|
@@ -83,9 +95,12 @@ export async function installedRelease(kind) {
|
|
|
83
95
|
return null;
|
|
84
96
|
}
|
|
85
97
|
}
|
|
98
|
+
export function withoutProxy() {
|
|
99
|
+
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
100
|
+
}
|
|
86
101
|
export function run(command, args, timeoutMs) {
|
|
87
102
|
return new Promise((resolve) => {
|
|
88
|
-
const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], timeout: timeoutMs });
|
|
103
|
+
const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], timeout: timeoutMs, env: withoutProxy() });
|
|
89
104
|
let output = '';
|
|
90
105
|
child.stdout.on('data', (chunk) => {
|
|
91
106
|
output += chunk.toString('utf8');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { readConfiguration, writeConfiguration } from './home.js';
|
|
2
|
+
const skills = !process.argv.slice(2).includes('--no-skills');
|
|
3
|
+
const stored = await readConfiguration();
|
|
4
|
+
await writeConfiguration({ skills });
|
|
5
|
+
if (stored.skills !== skills)
|
|
6
|
+
process.stdout.write('changed\n');
|