@agentshouse/kit 0.2.1-c4ea88ba9424e → 0.2.1-c53a84236c3d9
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 +13 -12
- package/dist/acp.js +13 -93
- package/dist/agents.js +2 -1
- package/dist/api.js +3 -3
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +11 -37
- package/dist/clis.js +56 -57
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +279 -235
- package/dist/copies.js +126 -101
- package/dist/end.js +1 -1
- package/dist/events.js +521 -0
- package/dist/files.js +14 -0
- package/dist/house-main.js +41 -12
- package/dist/instructions.js +3 -2
- package/dist/login.js +22 -101
- package/dist/logout.js +14 -14
- package/dist/parts.js +64 -0
- package/dist/resident.js +23 -19
- package/dist/scope.js +203 -0
- package/dist/sign-in.js +1 -1
- package/dist/work.js +348 -0
- package/package.json +1 -1
- package/dist/blocks.js +0 -51
package/README.md
CHANGED
|
@@ -33,21 +33,22 @@ them out; running it again without the flag brings them back.
|
|
|
33
33
|
|
|
34
34
|
## Commands
|
|
35
35
|
|
|
36
|
-
`kit login` opens a link you confirm in
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
`kit login` opens or prints a link you confirm in any browser, on this
|
|
37
|
+
computer or another, continues on its own and keeps the Environment's
|
|
38
|
+
credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is set. Pass
|
|
39
|
+
`--environment <id>` to reconnect an Environment you already have. It also
|
|
40
40
|
connects your own agent: outside an Agent conversation, `house <tool>` calls
|
|
41
41
|
House as you and `git` clones and pushes your Apps at `<house>/app/` as you,
|
|
42
42
|
until you revoke that connection on Connections. `house help` lists the Tools.
|
|
43
|
-
`kit logout` disconnects this computer, stops House Kit and ends
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
`kit logout` disconnects this computer, stops House Kit and ends your own
|
|
44
|
+
agent's connection, so `house` and `git` no longer act as you here; a later
|
|
45
|
+
`kit login` reconnects the same Environment.
|
|
46
|
+
|
|
47
|
+
`kit resident` keeps the Environment connected and, as it connects, copies each
|
|
48
|
+
Room you may sync here as a Git repository in the workspace's `local-copies`.
|
|
49
|
+
`house fetch` records House's changes on each copy's `refs/house/received`;
|
|
50
|
+
rebase onto it, commit and run `house push --owner` in the copy, through the
|
|
51
|
+
install command in the container. An Agent runs both, without `--owner`.
|
|
51
52
|
|
|
52
53
|
House Kit turns each audio file of your message to an Agent into text on this
|
|
53
54
|
computer before the Agent reads it. While transcription is on, the speech
|
package/dist/acp.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
|
|
2
|
-
import {
|
|
3
|
-
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
4
3
|
import { Readable, Writable } from 'node:stream';
|
|
5
4
|
import { CLIS, KIT_VERSION, adapterCommand, withoutProxy } from './clis.js';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined, added = {}, signal) {
|
|
5
|
+
import { killTree } from './scope.js';
|
|
6
|
+
export async function startAdapter(kind, cli, cwd, app, events = () => undefined, added = {}, signal, scope = null) {
|
|
9
7
|
const adapter = CLIS[kind].adapter;
|
|
10
|
-
const
|
|
8
|
+
const started = [adapter === null ? cli : adapterCommand(kind), CLIS[kind].args];
|
|
9
|
+
const [command, args] = scope?.command(...started) ?? started;
|
|
10
|
+
const child = spawn(command, args, {
|
|
11
11
|
cwd,
|
|
12
12
|
env: { ...withoutProxy(), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
|
|
13
13
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
@@ -32,16 +32,11 @@ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined,
|
|
|
32
32
|
writable: stream.writable,
|
|
33
33
|
readable: stream.readable.pipeThrough(new TransformStream({
|
|
34
34
|
transform(message, controller) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
jobs(job);
|
|
39
|
-
if (!notice.params?.update?.sessionUpdate?.startsWith('async_task_'))
|
|
35
|
+
const read = message;
|
|
36
|
+
events(read);
|
|
37
|
+
if (read.id !== undefined || (read.method !== 'session/update' && !read.method.startsWith('_'))) {
|
|
40
38
|
controller.enqueue(message);
|
|
41
|
-
|
|
42
|
-
controller.enqueue({ jsonrpc: '2.0', method: TURN_STARTED });
|
|
43
|
-
if (CLIS[kind].turnEnded(notice))
|
|
44
|
-
controller.enqueue({ jsonrpc: '2.0', method: TURN_ENDED });
|
|
39
|
+
}
|
|
45
40
|
},
|
|
46
41
|
})),
|
|
47
42
|
});
|
|
@@ -53,10 +48,12 @@ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined,
|
|
|
53
48
|
fs: { readTextFile: false, writeTextFile: false },
|
|
54
49
|
terminal: false,
|
|
55
50
|
elicitation: { form: {} },
|
|
56
|
-
|
|
51
|
+
session: { compaction: {}, notices: {} },
|
|
52
|
+
_meta: { jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
|
|
57
53
|
},
|
|
58
54
|
clientInfo: { name: '@agentshouse/kit', version: KIT_VERSION },
|
|
59
55
|
});
|
|
56
|
+
scope?.entered(child.pid);
|
|
60
57
|
return { child, connection, initialized, exited };
|
|
61
58
|
}
|
|
62
59
|
catch (error) {
|
|
@@ -64,80 +61,3 @@ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined,
|
|
|
64
61
|
throw error;
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
const LISTING_BYTES = 1 << 28;
|
|
68
|
-
function listed(options) {
|
|
69
|
-
return execFileSync('ps', [options, '-o', 'pid=,ppid=,command='], { encoding: 'utf8', maxBuffer: LISTING_BYTES })
|
|
70
|
-
.split('\n')
|
|
71
|
-
.flatMap((line) => {
|
|
72
|
-
const fields = /^\s*(\d+)\s+(\d+)\s?(.*)$/.exec(line);
|
|
73
|
-
return fields === null ? [] : [[Number(fields[1]), Number(fields[2]), fields[3]]];
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function parents() {
|
|
77
|
-
const children = new Map();
|
|
78
|
-
const adopt = (pid, parent) => children.set(parent, [...(children.get(parent) ?? []), pid]);
|
|
79
|
-
if (process.platform === 'darwin') {
|
|
80
|
-
for (const [pid, parent] of listed('-Aww'))
|
|
81
|
-
adopt(pid, parent);
|
|
82
|
-
return children;
|
|
83
|
-
}
|
|
84
|
-
for (const entry of readdirSync('/proc')) {
|
|
85
|
-
if (!/^\d+$/.test(entry))
|
|
86
|
-
continue;
|
|
87
|
-
try {
|
|
88
|
-
const stat = readFileSync(`/proc/${entry}/stat`, 'utf8');
|
|
89
|
-
adopt(Number(entry), Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]));
|
|
90
|
-
}
|
|
91
|
-
catch { }
|
|
92
|
-
}
|
|
93
|
-
return children;
|
|
94
|
-
}
|
|
95
|
-
function descendants(roots) {
|
|
96
|
-
const children = parents();
|
|
97
|
-
const tree = [];
|
|
98
|
-
const pending = roots.flatMap((root) => children.get(root) ?? []);
|
|
99
|
-
while (pending.length > 0) {
|
|
100
|
-
const pid = pending.pop();
|
|
101
|
-
tree.push(pid);
|
|
102
|
-
pending.push(...(children.get(pid) ?? []));
|
|
103
|
-
}
|
|
104
|
-
return tree;
|
|
105
|
-
}
|
|
106
|
-
function killAll(pids) {
|
|
107
|
-
for (const pid of pids) {
|
|
108
|
-
for (const target of [-pid, pid]) {
|
|
109
|
-
try {
|
|
110
|
-
process.kill(target, 'SIGKILL');
|
|
111
|
-
}
|
|
112
|
-
catch { }
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function marked(marker) {
|
|
117
|
-
if (process.platform === 'darwin') {
|
|
118
|
-
return listed('-AEww')
|
|
119
|
-
.filter(([, , command]) => ` ${command} `.includes(` ${marker} `))
|
|
120
|
-
.map(([pid]) => pid);
|
|
121
|
-
}
|
|
122
|
-
return readdirSync('/proc')
|
|
123
|
-
.filter((entry) => {
|
|
124
|
-
try {
|
|
125
|
-
return /^\d+$/.test(entry) && readFileSync(`/proc/${entry}/environ`, 'utf8').split('\0').includes(marker);
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
.map(Number);
|
|
132
|
-
}
|
|
133
|
-
export function killTree(child) {
|
|
134
|
-
killAll([child.pid, ...descendants([child.pid])]);
|
|
135
|
-
}
|
|
136
|
-
export function killMarked(marker) {
|
|
137
|
-
const pids = marked(marker);
|
|
138
|
-
killAll([...pids, ...descendants(pids)]);
|
|
139
|
-
}
|
|
140
|
-
export function killDescendants() {
|
|
141
|
-
const pids = marked(`HOUSE_KIT_RESIDENT=${process.pid}`);
|
|
142
|
-
killAll([...pids, ...descendants([process.pid, ...pids])]);
|
|
143
|
-
}
|
package/dist/agents.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { startAdapter } from './acp.js';
|
|
4
4
|
import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
|
|
5
5
|
import { agentBase, kitHome } from './home.js';
|
|
6
|
+
import { killTree } from './scope.js';
|
|
6
7
|
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
7
8
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
8
9
|
function select(options, category) {
|
package/dist/api.js
CHANGED
|
@@ -19,7 +19,7 @@ export function retryDelay(attempt) {
|
|
|
19
19
|
// Full jitter, doubling from one second to a 30-second cap, spreads the Kits one outage dropped and retries within half a minute of House's return.
|
|
20
20
|
return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
|
|
21
21
|
}
|
|
22
|
-
export async function retrying(sent, signal) {
|
|
22
|
+
export async function retrying(sent, signal, pause = retryDelay) {
|
|
23
23
|
for (let attempt = 0;; attempt++) {
|
|
24
24
|
try {
|
|
25
25
|
return await sent();
|
|
@@ -28,8 +28,8 @@ export async function retrying(sent, signal) {
|
|
|
28
28
|
if (!(error instanceof HouseRefusal) || retryable(error.text) !== true)
|
|
29
29
|
throw error;
|
|
30
30
|
}
|
|
31
|
-
// A request House refused as retryable is sent again
|
|
32
|
-
await delay(
|
|
31
|
+
// A request House refused as retryable is sent again after the caller's pause, the jittered curve unless it names its own.
|
|
32
|
+
await delay(pause(attempt), undefined, { signal });
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export async function post(house, path, body, credential, signal) {
|
package/dist/bootstrap.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-c53a84236c3d9",
|
|
4
4
|
"hosts": {
|
|
5
5
|
"macos": {
|
|
6
6
|
"asset": {
|
|
7
7
|
"name": "connect-linux.sh",
|
|
8
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
8
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c53a84236c3d9/connect-linux.sh"
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"linux": {
|
|
12
12
|
"asset": {
|
|
13
13
|
"name": "connect-linux.sh",
|
|
14
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
14
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c53a84236c3d9/connect-linux.sh"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"windows": {
|
|
18
18
|
"asset": {
|
|
19
19
|
"name": "connect-windows.ps1",
|
|
20
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
20
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c53a84236c3d9/connect-windows.ps1"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/bridge.js
CHANGED
|
@@ -11,11 +11,10 @@ import { loginPath } from './clis.js';
|
|
|
11
11
|
import { changedPaths, } from './copies.js';
|
|
12
12
|
import { kitHome, readEnrolment } from './home.js';
|
|
13
13
|
import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
|
|
14
|
-
import { operationId
|
|
14
|
+
import { operationId } from './operation.js';
|
|
15
15
|
import { refusalOf, retryable } from './refusals.js';
|
|
16
16
|
import { relayed } from './relay.js';
|
|
17
17
|
const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
18
|
-
const ATTACHMENTS = '/kit/attachments/upload';
|
|
19
18
|
export async function received(request) {
|
|
20
19
|
let text = '';
|
|
21
20
|
request.setEncoding('utf8');
|
|
@@ -68,11 +67,6 @@ function resendAfter(forwarded, attempt) {
|
|
|
68
67
|
const seconds = pendingSeconds(forwarded);
|
|
69
68
|
return seconds === null ? null : seconds * 1000;
|
|
70
69
|
}
|
|
71
|
-
function versioned(conversationId, text) {
|
|
72
|
-
const file = JSON.parse(text);
|
|
73
|
-
const identity = JSON.stringify([conversationId, file.room_ref ?? null, file.name, file.sha256]);
|
|
74
|
-
return JSON.stringify({ ...file, version: uuidOf(createHash('sha256').update(identity).digest(), 8) });
|
|
75
|
-
}
|
|
76
70
|
function editAnswer(forwarded) {
|
|
77
71
|
const answer = answered(forwarded);
|
|
78
72
|
if ('refused' in answer)
|
|
@@ -103,7 +97,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
103
97
|
const after = resendAfter(forwarded, attempt);
|
|
104
98
|
if (after === null)
|
|
105
99
|
return forwarded;
|
|
106
|
-
// A
|
|
100
|
+
// A Tool call House did not settle is sent again on the jittered curve, or after the wait House names for a pending one.
|
|
107
101
|
await delay(after, undefined, { signal: closed.signal });
|
|
108
102
|
}
|
|
109
103
|
};
|
|
@@ -141,32 +135,9 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
141
135
|
const held = JSON.parse(text).transfer;
|
|
142
136
|
return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
|
|
143
137
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
.post('/kit/tools/mutations', {}, closed.signal)
|
|
148
|
-
.then(({ tools }) => new Set(tools.filter((listed) => listed.writes).map((listed) => listed.name)));
|
|
149
|
-
try {
|
|
150
|
-
return (await mutations).has(tool);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
mutations = null;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const forward = async (path, text) => {
|
|
158
|
-
if (path === '/') {
|
|
159
|
-
const message = JSON.parse(text);
|
|
160
|
-
const tool = message.method === 'tools/call' ? String(message.params.name) : null;
|
|
161
|
-
return send(message, tool !== null && (await writes(tool)) ? operationId() : null);
|
|
162
|
-
}
|
|
163
|
-
const answer = await fetch(relayed(new URL(path, origin)), {
|
|
164
|
-
method: 'POST',
|
|
165
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}` },
|
|
166
|
-
body: versioned(conversationId, text),
|
|
167
|
-
signal: closed.signal,
|
|
168
|
-
});
|
|
169
|
-
return { status: answer.status, text: await answer.text() };
|
|
138
|
+
const forward = (text) => {
|
|
139
|
+
const message = JSON.parse(text);
|
|
140
|
+
return send(message, message.method === 'tools/call' ? operationId() : null);
|
|
170
141
|
};
|
|
171
142
|
const caller = {
|
|
172
143
|
key: `conversation:${conversationId}`,
|
|
@@ -188,11 +159,13 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
188
159
|
const { cwd, commit } = JSON.parse(text);
|
|
189
160
|
return { status: 200, text: JSON.stringify(await copies.push(cwd, commit, caller)) };
|
|
190
161
|
}
|
|
162
|
+
if (path === '/git/fetch')
|
|
163
|
+
return { status: 200, text: JSON.stringify(await copies.fetch()) };
|
|
191
164
|
if (path === '/git/observed') {
|
|
192
165
|
await copies.observed(JSON.parse(text));
|
|
193
166
|
return { status: 200, text: '{}' };
|
|
194
167
|
}
|
|
195
|
-
return path === '/'
|
|
168
|
+
return path === '/' ? forward(text) : { status: 404, text: '' };
|
|
196
169
|
};
|
|
197
170
|
const sockets = join(kitHome(), 'bridges');
|
|
198
171
|
await mkdir(sockets, { recursive: true, mode: 0o700 });
|
|
@@ -212,7 +185,8 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
212
185
|
response.writeHead(error.status, { 'content-type': 'application/json' }).end(error.text);
|
|
213
186
|
return;
|
|
214
187
|
}
|
|
215
|
-
|
|
188
|
+
const verb = request.url === '/git/push' || request.url === '/git/fetch';
|
|
189
|
+
response.writeHead(502).end(verb && error instanceof Error ? error.message : UNREACHABLE);
|
|
216
190
|
}
|
|
217
191
|
});
|
|
218
192
|
bridge.listen(socketPath);
|
|
@@ -239,7 +213,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
239
213
|
GIT_CONFIG_VALUE_0: app,
|
|
240
214
|
},
|
|
241
215
|
tool: async (name, args) => {
|
|
242
|
-
const forwarded = await forward(
|
|
216
|
+
const forwarded = await forward(JSON.stringify(call(name, args)));
|
|
243
217
|
if (forwarded.status !== 200)
|
|
244
218
|
throw new Error(`House refused ${name} with ${forwarded.status}: ${forwarded.text}`);
|
|
245
219
|
const answer = JSON.parse(forwarded.text);
|
package/dist/clis.js
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { constants, readFileSync } from 'node:fs';
|
|
3
|
+
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { homedir, userInfo } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
5
|
+
import { delimiter, isAbsolute, join } from 'node:path';
|
|
6
6
|
import { kitHome } from './home.js';
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const RAW_SUBTYPES = [
|
|
8
|
+
'background_tasks_changed',
|
|
9
|
+
'task_started',
|
|
10
|
+
'task_updated',
|
|
11
|
+
'task_notification',
|
|
12
|
+
'session_state_changed',
|
|
13
|
+
'hook_started',
|
|
14
|
+
'hook_response',
|
|
15
|
+
];
|
|
16
|
+
async function executable(path) {
|
|
17
|
+
try {
|
|
18
|
+
await access(path, constants.X_OK);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function allowHouseInCodex(path) {
|
|
26
|
+
const candidates = [...new Set(path.split(delimiter).filter((directory) => isAbsolute(directory)))].map((directory) => join(directory, 'house'));
|
|
27
|
+
const houses = [];
|
|
28
|
+
for (const candidate of candidates)
|
|
29
|
+
if (await executable(candidate))
|
|
30
|
+
houses.push(candidate);
|
|
9
31
|
const rules = join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'rules');
|
|
10
32
|
await mkdir(rules, { recursive: true });
|
|
11
|
-
await writeFile(join(rules, 'house.rules'),
|
|
33
|
+
await writeFile(join(rules, 'house.rules'), `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`);
|
|
12
34
|
}
|
|
13
35
|
async function nothing() { }
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
return undefined;
|
|
17
|
-
return params.update._meta?.codex?.threadStatus?.type;
|
|
18
|
-
}
|
|
19
|
-
function asyncTask({ method, params }) {
|
|
20
|
-
const update = params?.update;
|
|
21
|
-
if (method !== 'session/update' || update?.asyncTaskId === undefined)
|
|
22
|
-
return null;
|
|
23
|
-
if (update.sessionUpdate === 'async_task_spawned')
|
|
24
|
-
return { id: update.asyncTaskId, running: true };
|
|
25
|
-
if (update.sessionUpdate === 'async_task_state_update' && !RUNNING_JOB.has(update.state ?? '')) {
|
|
26
|
-
return { id: update.asyncTaskId, running: false };
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
function airPhase({ _meta }) {
|
|
31
|
-
const phase = _meta?.jetbrains?.air?.phase;
|
|
32
|
-
if (phase === 'commentary')
|
|
33
|
-
return 'note';
|
|
34
|
-
if (phase === 'final_answer')
|
|
35
|
-
return 'answer';
|
|
36
|
-
return null;
|
|
36
|
+
function bridgeInClaudeSandbox(bridge) {
|
|
37
|
+
return process.platform === 'darwin' ? { allowUnixSockets: [bridge] } : { allowAllUnixSockets: true };
|
|
37
38
|
}
|
|
38
39
|
export const CLIS = {
|
|
39
40
|
'codex-acp': {
|
|
40
41
|
bin: 'codex',
|
|
41
42
|
minimum: '0.159.1',
|
|
42
43
|
install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
|
|
43
|
-
adapter: {
|
|
44
|
+
adapter: {
|
|
45
|
+
package: '@agentclientprotocol/codex-acp',
|
|
46
|
+
bin: 'codex-acp',
|
|
47
|
+
executable: 'CODEX_PATH',
|
|
48
|
+
env: { CODEX_CONFIG: JSON.stringify({ features: { shell_zsh_fork: true } }) },
|
|
49
|
+
},
|
|
44
50
|
args: [],
|
|
45
51
|
fullAccess: 'agent-full-access',
|
|
46
|
-
sessionMeta: {},
|
|
52
|
+
sessionMeta: () => ({}),
|
|
53
|
+
renames: true,
|
|
47
54
|
allowHouse: allowHouseInCodex,
|
|
48
55
|
signedIn: { command: ['login', 'status'] },
|
|
49
56
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
50
|
-
|
|
51
|
-
turnStarted: (notice) => threadStatus(notice) === 'active',
|
|
52
|
-
turnEnded: (notice) => threadStatus(notice) === 'idle',
|
|
53
|
-
job: asyncTask,
|
|
54
|
-
phase: airPhase,
|
|
57
|
+
air: ['asyncTasks', 'nativeSubagentSessions'],
|
|
55
58
|
},
|
|
56
59
|
'claude-agent-acp': {
|
|
57
60
|
bin: 'claude',
|
|
@@ -65,40 +68,36 @@ export const CLIS = {
|
|
|
65
68
|
},
|
|
66
69
|
args: [],
|
|
67
70
|
fullAccess: 'bypassPermissions',
|
|
68
|
-
sessionMeta:
|
|
71
|
+
sessionMeta: (bridge, title) => ({
|
|
72
|
+
claudeCode: {
|
|
73
|
+
options: {
|
|
74
|
+
allowedTools: ['Bash(house:*)'],
|
|
75
|
+
includeHookEvents: true,
|
|
76
|
+
title,
|
|
77
|
+
settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
|
|
78
|
+
},
|
|
79
|
+
emitRawSDKMessages: RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })),
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
renames: false,
|
|
69
83
|
allowHouse: nothing,
|
|
70
84
|
signedIn: { command: ['auth', 'status'] },
|
|
71
85
|
login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
|
|
72
|
-
|
|
73
|
-
turnStarted: () => false,
|
|
74
|
-
turnEnded: ({ method, params }) => method === 'session/update' &&
|
|
75
|
-
params?.update?.sessionUpdate === 'usage_update' &&
|
|
76
|
-
params.update._meta?.['_claude/origin'] !== undefined,
|
|
77
|
-
job: asyncTask,
|
|
78
|
-
phase: () => null,
|
|
86
|
+
air: ['asyncTasks', 'sessionFailure'],
|
|
79
87
|
},
|
|
80
88
|
'grok-build': {
|
|
81
89
|
bin: 'grok',
|
|
82
90
|
minimum: '1.0.46',
|
|
83
91
|
install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
|
|
84
92
|
adapter: null,
|
|
85
|
-
args: ['agent', '--always-approve', '--no-leader', 'stdio'],
|
|
93
|
+
args: ['--sandbox', 'off', 'agent', '--always-approve', '--no-leader', 'stdio'],
|
|
86
94
|
fullAccess: null,
|
|
87
|
-
sessionMeta: {},
|
|
95
|
+
sessionMeta: () => ({}),
|
|
96
|
+
renames: false,
|
|
88
97
|
allowHouse: nothing,
|
|
89
98
|
signedIn: { initializeMeta: 'defaultAuthMethodId' },
|
|
90
99
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
91
|
-
|
|
92
|
-
turnStarted: ({ method, params }) => method === '_x.ai/queue/changed' && params?.runningPromptId !== undefined,
|
|
93
|
-
turnEnded: ({ method, params }) => method === '_x.ai/session_notification' && params?.update?.sessionUpdate === 'turn_completed',
|
|
94
|
-
job: ({ method, params }) => {
|
|
95
|
-
if (method === '_x.ai/task_backgrounded')
|
|
96
|
-
return { id: params.update.task_id, running: true };
|
|
97
|
-
if (method === '_x.ai/task_completed')
|
|
98
|
-
return { id: params.update.task_snapshot.task_id, running: false };
|
|
99
|
-
return null;
|
|
100
|
-
},
|
|
101
|
-
phase: () => null,
|
|
100
|
+
air: ['asyncTasks'],
|
|
102
101
|
},
|
|
103
102
|
};
|
|
104
103
|
const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { connect } from 'node:net';
|
|
4
|
+
const KIT_ANSWER = '"house-kit-';
|
|
5
|
+
const SYNC = 'house-kit/sync';
|
|
6
|
+
function lines(each) {
|
|
7
|
+
let buffer = '';
|
|
8
|
+
return (chunk) => {
|
|
9
|
+
buffer += chunk;
|
|
10
|
+
for (let index = buffer.indexOf('\n'); index >= 0; index = buffer.indexOf('\n')) {
|
|
11
|
+
each(buffer.slice(0, index + 1));
|
|
12
|
+
buffer = buffer.slice(index + 1);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function answersKit(line) {
|
|
17
|
+
if (!line.includes(KIT_ANSWER))
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
const message = JSON.parse(line);
|
|
21
|
+
return message.method === undefined && typeof message.id === 'string' && message.id.startsWith(KIT_ANSWER.slice(1));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const args = process.argv.slice(2);
|
|
28
|
+
const serving = args[0] === 'app-server';
|
|
29
|
+
if (process.env.HOUSE_KIT_SANDBOX === '1' && serving)
|
|
30
|
+
args.push('--disable', 'memories');
|
|
31
|
+
const codex = spawn(process.env.HOUSE_KIT_CODEX, args, { stdio: ['pipe', 'pipe', 'inherit'] });
|
|
32
|
+
const stream = serving ? connect(process.env.HOUSE_KIT_CODEX_STREAM) : null;
|
|
33
|
+
stream?.on('error', () => undefined);
|
|
34
|
+
process.stdin.setEncoding('utf8').on('data', lines((line) => codex.stdin.write(line)));
|
|
35
|
+
process.stdin.on('end', () => codex.stdin.end());
|
|
36
|
+
stream?.setEncoding('utf8').on('data', lines((line) => {
|
|
37
|
+
const message = JSON.parse(line);
|
|
38
|
+
if (message.method === SYNC)
|
|
39
|
+
stream.write(`${JSON.stringify({ jsonrpc: '2.0', id: message.id, result: {} })}\n`);
|
|
40
|
+
else
|
|
41
|
+
codex.stdin.write(line);
|
|
42
|
+
}));
|
|
43
|
+
codex.stdout.setEncoding('utf8').on('data', lines((line) => {
|
|
44
|
+
stream?.write(line);
|
|
45
|
+
if (answersKit(line) || process.stdout.write(line))
|
|
46
|
+
return;
|
|
47
|
+
codex.stdout.pause();
|
|
48
|
+
process.stdout.once('drain', () => codex.stdout.resume());
|
|
49
|
+
}));
|
|
50
|
+
codex.stdin.on('error', () => undefined);
|
|
51
|
+
for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP'])
|
|
52
|
+
process.on(signal, () => codex.kill(signal));
|
|
53
|
+
codex.on('exit', (code, signal) => {
|
|
54
|
+
if (signal === null)
|
|
55
|
+
process.exit(code ?? 1);
|
|
56
|
+
process.removeAllListeners(signal);
|
|
57
|
+
process.kill(process.pid, signal);
|
|
58
|
+
});
|