@agentshouse/kit 0.2.1-c46722ad48058 → 0.2.1-c4823db4ff116
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 +17 -16
- package/dist/agents.js +73 -7
- package/dist/api.js +6 -2
- package/dist/bootstrap.json +4 -4
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +42 -9
- package/dist/conversations.js +29 -9
- package/dist/copies.js +28 -10
- package/dist/end.js +17 -3
- package/dist/events.js +3 -0
- package/dist/files.js +7 -1
- package/dist/git.js +10 -8
- package/dist/home.js +75 -4
- package/dist/house-cli.js +291 -0
- package/dist/house-main.js +7 -189
- package/dist/instructions.js +6 -31
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +56 -14
- package/dist/parts.js +34 -16
- package/dist/placement.js +48 -0
- package/dist/relay.js +1 -1
- package/dist/resident.js +14 -5
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/skills.js +81 -12
- package/dist/stream.js +66 -15
- package/dist/transcription.js +3 -3
- package/dist/update.js +28 -6
- package/dist/wire.js +6 -0
- package/how-we-work.md +13 -3
- package/package.json +2 -1
- package/skills/ask-matt/SKILL.md +17 -11
- package/skills/ask-matt/agents/openai.yaml +1 -0
- package/skills/code-review/SKILL.md +5 -5
- package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
- package/skills/codebase-design/SKILL.md +0 -2
- package/skills/diagnosing-bugs/SKILL.md +2 -4
- package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
- package/skills/domain-modeling/SKILL.md +12 -14
- package/skills/grill-me/SKILL.md +1 -2
- package/skills/grill-me/agents/openai.yaml +1 -0
- package/skills/grill-with-docs/SKILL.md +1 -2
- package/skills/grill-with-docs/agents/openai.yaml +1 -0
- package/skills/grilling/SKILL.md +2 -2
- package/skills/handoff/SKILL.md +2 -3
- package/skills/handoff/agents/openai.yaml +1 -0
- package/skills/implement/SKILL.md +5 -4
- package/skills/implement/agents/openai.yaml +1 -0
- package/skills/implement-spec/SKILL.md +40 -0
- package/skills/implement-spec/agents/openai.yaml +5 -0
- package/skills/improve-codebase-architecture/SKILL.md +6 -7
- package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
- package/skills/pr/CREDITS.md +3 -0
- package/skills/pr/LICENSE +21 -0
- package/skills/pr/SKILL.md +170 -0
- package/skills/pr/agents/openai.yaml +3 -0
- package/skills/prototype/SKILL.md +0 -2
- package/skills/research/SKILL.md +0 -2
- package/skills/retro/LICENSE +21 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/tdd/SKILL.md +2 -4
- package/skills/teach/SKILL.md +3 -4
- package/skills/teach/agents/openai.yaml +1 -0
- package/skills/to-questionnaire/SKILL.md +1 -2
- package/skills/to-questionnaire/agents/openai.yaml +1 -0
- package/skills/to-spec/SKILL.md +1 -2
- package/skills/to-spec/agents/openai.yaml +1 -0
- package/skills/to-tickets/SKILL.md +3 -4
- package/skills/to-tickets/agents/openai.yaml +1 -0
- package/skills/triage/AGENT-BRIEF.md +207 -0
- package/skills/triage/LICENSE +21 -0
- package/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/skills/triage/SKILL.md +112 -0
- package/skills/triage/agents/openai.yaml +5 -0
- package/skills/wait-what/SKILL.md +2 -3
- package/skills/wait-what/agents/openai.yaml +1 -0
- package/skills/wayfinder/SKILL.md +5 -6
- package/skills/wayfinder/agents/openai.yaml +1 -0
- package/skills/wizard/LICENSE +21 -0
- package/skills/wizard/SKILL.md +44 -0
- package/skills/wizard/agents/openai.yaml +3 -0
- package/skills/wizard/template.sh +223 -0
- package/skills/writing-for-agents/SKILL.md +0 -2
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ workspace. On Windows 11 the container is the one choice. Append a `kit` or
|
|
|
18
18
|
Running the command for the other choice on a connected computer asks you to
|
|
19
19
|
confirm, then replaces its Environment, whose Agents end, with a new one.
|
|
20
20
|
|
|
21
|
-
On your own
|
|
21
|
+
On your own Linux server, run the Linux command with `--linux` to
|
|
22
22
|
install House Kit natively, with its workspace at `/agents/house`; `kit` and
|
|
23
23
|
`house` are then on the server's `PATH`.
|
|
24
24
|
|
|
@@ -33,26 +33,27 @@ them out; running it again without the flag brings them back.
|
|
|
33
33
|
|
|
34
34
|
`kit login` opens or prints a link you confirm in any browser, on this computer
|
|
35
35
|
or another, continues on its own and keeps the Environment's credential in
|
|
36
|
-
`~/.house-kit`, or in
|
|
36
|
+
`$HOUSE_KIT_HOME` when it is set, else in `~/.house-kit`, or in `house-kit-<uid>` under the temporary directory when your home is read-only. `--environment <id>`
|
|
37
37
|
reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
|
|
38
|
-
only those Rooms and `--no-private` every Room but your Private Room;
|
|
39
|
-
`--code <code>` connects immediately without a link.
|
|
38
|
+
only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
|
|
40
39
|
A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
|
|
41
|
-
House as you and `git` clones and pushes your Apps at `<house>/app/` as you,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
agent's connection, so `house` and `git` no
|
|
45
|
-
`kit login` reconnects the same Environment
|
|
46
|
-
|
|
47
|
-
`kit
|
|
48
|
-
|
|
49
|
-
`
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
House as you and `git` clones and pushes your Apps at `<house>/app/` as you, until you revoke
|
|
41
|
+
that connection on Connections. `house help` lists the Tools. Codex sessions started after a
|
|
42
|
+
login run a lone `house` command outside their sandbox. `kit logout` disconnects this
|
|
43
|
+
computer, stops House Kit and ends your own agent's connection, so `house` and `git` no
|
|
44
|
+
longer act as you here; a later `kit login` reconnects the same Environment, or connects
|
|
45
|
+
this computer as a new one when House no longer holds it.
|
|
46
|
+
In a container you do not control, such as ChatGPT's, `npm i -g @agentshouse/kit` and `kit chatgpt --key <key>` with a key made on Connections let `house <tool>` act as you, starting and configuring nothing else.
|
|
47
|
+
|
|
48
|
+
`kit resident` keeps the Environment connected and, as it connects, copies the text of each Room
|
|
49
|
+
you chose for it as a Git repository in the workspace's `local-copies`. `house fetch` records
|
|
50
|
+
House's changes on each copy's `refs/house/received`; rebase onto it, commit and run
|
|
51
|
+
`house push --owner` in the copy, through the install command in the container. An Agent runs
|
|
52
|
+
both, without `--owner`. `house upload` and `house download` move a Room's other files.
|
|
52
53
|
|
|
53
54
|
House Kit turns each audio file of your message to an Agent into text on this
|
|
54
55
|
computer before the Agent reads it. While transcription is on, the speech
|
|
55
|
-
engine and model use about 425 MB
|
|
56
|
+
engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
|
|
56
57
|
|
|
57
58
|
## License
|
|
58
59
|
|
package/dist/agents.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
4
|
import { startAdapter } from './acp.js';
|
|
4
5
|
import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
|
|
5
6
|
import { agentBase, kitHome } from './home.js';
|
|
7
|
+
import { updatesItself } from './placement.js';
|
|
6
8
|
import { killTree } from './scope.js';
|
|
7
9
|
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
10
|
+
import { KIT_WIRE } from './wire.js';
|
|
11
|
+
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
12
|
+
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
8
13
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
9
14
|
function select(options, category) {
|
|
10
15
|
const option = options.find((candidate) => candidate.category === category);
|
|
@@ -22,6 +27,22 @@ function causeOf(error) {
|
|
|
22
27
|
function logged(error) {
|
|
23
28
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
24
29
|
}
|
|
30
|
+
const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
|
|
31
|
+
const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
|
|
32
|
+
const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
|
|
33
|
+
export function chassisForm(value) {
|
|
34
|
+
const chassis = value.trim();
|
|
35
|
+
if (LAPTOP_CHASSIS.has(chassis))
|
|
36
|
+
return 'laptop';
|
|
37
|
+
if (DESKTOP_CHASSIS.has(chassis))
|
|
38
|
+
return 'desktop';
|
|
39
|
+
if (SERVER_CHASSIS.has(chassis))
|
|
40
|
+
return 'server';
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
export function hostVm(version) {
|
|
44
|
+
return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
|
|
45
|
+
}
|
|
25
46
|
async function models(kind, adapter, known) {
|
|
26
47
|
const agent = adapter.connection.agent;
|
|
27
48
|
const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
|
|
@@ -120,6 +141,22 @@ async function operatingSystem() {
|
|
|
120
141
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
121
142
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
122
143
|
}
|
|
144
|
+
async function hostForm() {
|
|
145
|
+
if (process.platform === 'darwin') {
|
|
146
|
+
const battery = await run('pmset', ['-g', 'batt'], 10_000);
|
|
147
|
+
return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
|
|
148
|
+
}
|
|
149
|
+
if (process.platform !== 'linux')
|
|
150
|
+
return undefined;
|
|
151
|
+
const [container, version, chassis] = await Promise.all([
|
|
152
|
+
readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
|
|
153
|
+
readFile('/proc/version', 'utf8').catch(() => ''),
|
|
154
|
+
readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
|
|
155
|
+
]);
|
|
156
|
+
if (container && hostVm(version))
|
|
157
|
+
return undefined;
|
|
158
|
+
return chassisForm(chassis);
|
|
159
|
+
}
|
|
123
160
|
export class Agents {
|
|
124
161
|
desired = { agents: [], routes: [], transcribe: false };
|
|
125
162
|
house;
|
|
@@ -128,10 +165,17 @@ export class Agents {
|
|
|
128
165
|
installing = Promise.resolve();
|
|
129
166
|
readings = new Map();
|
|
130
167
|
reads = new Map();
|
|
168
|
+
starts = 0;
|
|
131
169
|
sending = Promise.resolve();
|
|
132
170
|
sent = null;
|
|
133
|
-
|
|
171
|
+
refreshing = 0;
|
|
172
|
+
changed;
|
|
173
|
+
constructor(house, changed = () => undefined) {
|
|
134
174
|
this.house = house;
|
|
175
|
+
this.changed = changed;
|
|
176
|
+
}
|
|
177
|
+
idle() {
|
|
178
|
+
return this.refreshing === 0;
|
|
135
179
|
}
|
|
136
180
|
read() {
|
|
137
181
|
return this.reading.then(() => undefined, () => undefined);
|
|
@@ -140,21 +184,31 @@ export class Agents {
|
|
|
140
184
|
return this.desired.routes.find((route) => route.agent_id === agentId);
|
|
141
185
|
}
|
|
142
186
|
refresh() {
|
|
187
|
+
this.refreshing++;
|
|
188
|
+
this.changed();
|
|
143
189
|
const reading = this.read().then(async () => {
|
|
144
190
|
this.desired = await this.house.deliver('/kit/agents/desired', {});
|
|
145
191
|
return this.desired;
|
|
146
192
|
});
|
|
147
193
|
this.reading = reading;
|
|
148
|
-
|
|
194
|
+
reading
|
|
195
|
+
.then(({ agents, transcribe }) => Promise.all([
|
|
149
196
|
holdTranscription(transcribe)
|
|
150
197
|
.then((changed) => (changed ? this.report() : undefined))
|
|
151
|
-
.catch(logged)
|
|
198
|
+
.catch(logged),
|
|
152
199
|
Promise.all(agents.map((kind) => this.load(kind)))
|
|
153
200
|
.then(() => this.report())
|
|
154
|
-
.catch(logged)
|
|
201
|
+
.catch(logged),
|
|
202
|
+
]))
|
|
203
|
+
.catch(() => undefined)
|
|
204
|
+
.finally(() => {
|
|
205
|
+
this.refreshing--;
|
|
206
|
+
this.changed();
|
|
155
207
|
});
|
|
208
|
+
return reading.then(() => undefined);
|
|
156
209
|
}
|
|
157
210
|
cli(kind) {
|
|
211
|
+
this.starts += 1;
|
|
158
212
|
return this.queue(kind, async () => {
|
|
159
213
|
const resolved = await this.resolve(kind);
|
|
160
214
|
if (!('cli' in resolved)) {
|
|
@@ -168,7 +222,7 @@ export class Agents {
|
|
|
168
222
|
this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
|
|
169
223
|
}
|
|
170
224
|
const read = this.nextRead(kind);
|
|
171
|
-
|
|
225
|
+
this.quietOffer(kind, cli, kept)
|
|
172
226
|
.then((offered) => {
|
|
173
227
|
const current = this.readings.get(kind);
|
|
174
228
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
@@ -255,11 +309,19 @@ export class Agents {
|
|
|
255
309
|
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
256
310
|
this.readings.set(kind, reading);
|
|
257
311
|
}
|
|
312
|
+
async quietOffer(kind, cli, known) {
|
|
313
|
+
for (let seen = -1; seen !== this.starts;) {
|
|
314
|
+
seen = this.starts;
|
|
315
|
+
await delay(MODEL_PROBE_QUIET_MS);
|
|
316
|
+
}
|
|
317
|
+
return offer(kind, cli, known);
|
|
318
|
+
}
|
|
258
319
|
async load(kind) {
|
|
259
320
|
const known = this.readings.get(kind);
|
|
260
|
-
if (known !== undefined && known.failure === null)
|
|
321
|
+
if (known !== undefined && known.failure === null && known.minimum === undefined)
|
|
261
322
|
return;
|
|
262
|
-
await this.examine(kind, SIGNED_OUT,
|
|
323
|
+
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
324
|
+
await this.report();
|
|
263
325
|
}
|
|
264
326
|
async send() {
|
|
265
327
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
@@ -267,9 +329,13 @@ export class Agents {
|
|
|
267
329
|
return reading === undefined ? [] : [reported(kind, reading)];
|
|
268
330
|
});
|
|
269
331
|
const hostKey = await sshHostKey();
|
|
332
|
+
const form = await hostForm();
|
|
270
333
|
const body = {
|
|
271
334
|
os: await operatingSystem(),
|
|
335
|
+
...(form === undefined ? {} : { form }),
|
|
272
336
|
kit_version: KIT_VERSION,
|
|
337
|
+
wire: KIT_WIRE,
|
|
338
|
+
updates_itself: await updatesItself(),
|
|
273
339
|
agent_base: agentBase(),
|
|
274
340
|
agents,
|
|
275
341
|
transcription: transcriptionReport(),
|
package/dist/api.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
-
import {
|
|
2
|
+
import { signInAgain, updateRequired } from './end.js';
|
|
3
3
|
import { readEnrolment } from './home.js';
|
|
4
4
|
import { retryable } from './refusals.js';
|
|
5
5
|
import { relayed } from './relay.js';
|
|
6
|
+
import { KIT_WIRE, KIT_WIRE_HEADER, tooOld } from './wire.js';
|
|
6
7
|
export class HouseRefusal extends Error {
|
|
7
8
|
status;
|
|
8
9
|
text;
|
|
@@ -37,12 +38,15 @@ export async function post(house, path, body, credential, signal) {
|
|
|
37
38
|
method: 'POST',
|
|
38
39
|
headers: {
|
|
39
40
|
'content-type': 'application/json',
|
|
41
|
+
[KIT_WIRE_HEADER]: String(KIT_WIRE),
|
|
40
42
|
...(credential === undefined ? {} : { authorization: `Bearer ${credential}` }),
|
|
41
43
|
},
|
|
42
44
|
body: JSON.stringify(body),
|
|
43
45
|
signal,
|
|
44
46
|
});
|
|
45
47
|
const text = await answer.text();
|
|
48
|
+
if (!answer.ok && tooOld(text))
|
|
49
|
+
updateRequired(house);
|
|
46
50
|
if (!answer.ok)
|
|
47
51
|
throw new HouseRefusal(path, answer.status, text);
|
|
48
52
|
return JSON.parse(text);
|
|
@@ -54,7 +58,7 @@ async function enrolledPost(path, body, signal) {
|
|
|
54
58
|
}
|
|
55
59
|
catch (error) {
|
|
56
60
|
if (error instanceof HouseRefusal && error.status === 401)
|
|
57
|
-
|
|
61
|
+
await signInAgain(credential);
|
|
58
62
|
throw error;
|
|
59
63
|
}
|
|
60
64
|
}
|
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-c4823db4ff116",
|
|
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-c4823db4ff116/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-c4823db4ff116/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-c4823db4ff116/connect-windows.ps1"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/chatgpt.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { placeAppGit } from './app-git.js';
|
|
3
|
+
import { kitHome, readOwnAgent, writeOwnAgent } from './home.js';
|
|
4
|
+
import { accepted, DEFAULT_HOUSE } from './login.js';
|
|
5
|
+
const KEY_SOURCE = 'New key for a script on Connections';
|
|
6
|
+
const USAGE = `usage: kit chatgpt --key <key> [--house <origin>]
|
|
7
|
+
--key <key> a key from ${KEY_SOURCE}
|
|
8
|
+
--house <origin> the House of the key, ${DEFAULT_HOUSE} unless one is stored
|
|
9
|
+
`;
|
|
10
|
+
export async function chatgpt(argv) {
|
|
11
|
+
const { values } = parseArgs({
|
|
12
|
+
args: argv,
|
|
13
|
+
options: { key: { type: 'string' }, house: { type: 'string' }, help: { type: 'boolean', default: false } },
|
|
14
|
+
});
|
|
15
|
+
if (values.help) {
|
|
16
|
+
process.stdout.write(USAGE);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (values.key === undefined)
|
|
20
|
+
throw new Error(`pass --key with a key from ${KEY_SOURCE}`);
|
|
21
|
+
const before = await readOwnAgent();
|
|
22
|
+
const house = values.house ?? before?.house ?? DEFAULT_HOUSE;
|
|
23
|
+
if (!(await accepted(house, values.key)))
|
|
24
|
+
throw new Error(`${house} does not accept this key; pass one from ${KEY_SOURCE}`);
|
|
25
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
26
|
+
await writeOwnAgent({ house, ...(relay === undefined ? {} : { relay }), credential: values.key });
|
|
27
|
+
await placeAppGit(before, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
28
|
+
if (before !== null && before.credential !== values.key) {
|
|
29
|
+
process.stdout.write('This replaced the key this Kit home held; give each session its own HOUSE_KIT_HOME to keep its own key.\n');
|
|
30
|
+
}
|
|
31
|
+
process.stdout.write(`house now calls ${house} as you, with the key kept in ${kitHome()}.\n`);
|
|
32
|
+
}
|
package/dist/clis.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { constants, readFileSync } from 'node:fs';
|
|
3
|
-
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
4
5
|
import { homedir, userInfo } from 'node:os';
|
|
5
|
-
import { delimiter, isAbsolute, join } from 'node:path';
|
|
6
|
+
import { delimiter, dirname, isAbsolute, join } from 'node:path';
|
|
6
7
|
import { kitHome } from './home.js';
|
|
8
|
+
const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
|
|
9
|
+
function houseRule(houses) {
|
|
10
|
+
return `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`;
|
|
11
|
+
}
|
|
7
12
|
const RAW_SUBTYPES = [
|
|
8
13
|
'background_tasks_changed',
|
|
9
14
|
'task_started',
|
|
@@ -22,15 +27,37 @@ async function executable(path) {
|
|
|
22
27
|
return false;
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
|
-
async function
|
|
30
|
+
async function listedHouses(file) {
|
|
31
|
+
let text;
|
|
32
|
+
try {
|
|
33
|
+
text = await readFile(file, 'utf8');
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.code === 'ENOENT')
|
|
37
|
+
return [];
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const listed = JSON.parse(HOUSE_EXECUTABLES.exec(text)?.[1] ?? '[]');
|
|
42
|
+
return Array.isArray(listed) ? listed.filter((house) => typeof house === 'string') : [];
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function allowHouseInCodex(path) {
|
|
26
49
|
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);
|
|
31
50
|
const rules = join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'rules');
|
|
51
|
+
const file = join(rules, 'house.rules');
|
|
52
|
+
const houses = [];
|
|
53
|
+
for (const house of [...(await listedHouses(file)), ...candidates]) {
|
|
54
|
+
if (!houses.includes(house) && (await executable(house)))
|
|
55
|
+
houses.push(house);
|
|
56
|
+
}
|
|
32
57
|
await mkdir(rules, { recursive: true });
|
|
33
|
-
|
|
58
|
+
const temporary = `${file}.${randomUUID()}`;
|
|
59
|
+
await writeFile(temporary, houseRule(houses));
|
|
60
|
+
await rename(temporary, file);
|
|
34
61
|
}
|
|
35
62
|
async function nothing() { }
|
|
36
63
|
function bridgeInClaudeSandbox(bridge) {
|
|
@@ -173,7 +200,7 @@ export async function installAdapter(kind, signal) {
|
|
|
173
200
|
const release = KIT_PACKAGE.peerDependencies[adapter.package];
|
|
174
201
|
if ((await installedAdapter(kind)) === release)
|
|
175
202
|
return null;
|
|
176
|
-
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
|
|
203
|
+
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--cache', join(kitHome(), 'npm-cache'), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
|
|
177
204
|
return ran.status === 0 ? null : failureOf(ran, 'npm');
|
|
178
205
|
}
|
|
179
206
|
export async function installCli(kind, signal) {
|
|
@@ -198,6 +225,12 @@ export async function loginPath() {
|
|
|
198
225
|
const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
|
|
199
226
|
return ran.stdout.split('\n').findLast((line) => line.startsWith(marker)).slice(marker.length);
|
|
200
227
|
}
|
|
228
|
+
export async function writeCodexRule() {
|
|
229
|
+
const shell = await loginPath().catch(() => '');
|
|
230
|
+
await allowHouseInCodex([dirname(process.execPath), process.env.PATH ?? '', shell].join(delimiter)).catch((error) => {
|
|
231
|
+
throw new Error(`Codex's rule for house could not be written: ${error.message}`);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
201
234
|
export async function versionOf(path, signal) {
|
|
202
235
|
return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal)).stdout)?.[0] ?? null;
|
|
203
236
|
}
|
package/dist/conversations.js
CHANGED
|
@@ -6,7 +6,7 @@ import { unlessAborted } from './abort.js';
|
|
|
6
6
|
import { startAdapter } from './acp.js';
|
|
7
7
|
import { openBridge } from './bridge.js';
|
|
8
8
|
import { CLIS } from './clis.js';
|
|
9
|
-
import { readerFor } from './events.js';
|
|
9
|
+
import { answeredFailure, readerFor } from './events.js';
|
|
10
10
|
import { placeFiles, uploadBytes } from './files.js';
|
|
11
11
|
import { agentBase } from './home.js';
|
|
12
12
|
import { instructions } from './instructions.js';
|
|
@@ -17,6 +17,16 @@ import { createHowWeWork } from './skills.js';
|
|
|
17
17
|
import { transcribe } from './transcription.js';
|
|
18
18
|
import { workFor } from './work.js';
|
|
19
19
|
const KILLED = 'the conversation was killed';
|
|
20
|
+
const REFUSED = 'the CLI refused the prompt';
|
|
21
|
+
const EXIT_PLAN_MODE = {
|
|
22
|
+
parse(value) {
|
|
23
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
24
|
+
throw new Error('_x.ai/exit_plan_mode needs an object');
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export const CONVERSATION_INPUTS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
|
|
20
30
|
function causeOf(error) {
|
|
21
31
|
return error instanceof Error ? error.message : String(error);
|
|
22
32
|
}
|
|
@@ -132,6 +142,9 @@ export class Conversations {
|
|
|
132
142
|
return false;
|
|
133
143
|
return !conversations.some((conversation) => conversation.running?.scope.working() || [...conversation.leftovers].some((scope) => scope.working()));
|
|
134
144
|
}
|
|
145
|
+
quiet() {
|
|
146
|
+
return this.idle() && [...this.conversations.values()].every((conversation) => conversation.open === 0);
|
|
147
|
+
}
|
|
135
148
|
look() {
|
|
136
149
|
for (const conversation of this.conversations.values()) {
|
|
137
150
|
for (const scope of conversation.leftovers) {
|
|
@@ -344,7 +357,8 @@ export class Conversations {
|
|
|
344
357
|
reader.session = sessionId;
|
|
345
358
|
const app = client({ name: '@agentshouse/kit' })
|
|
346
359
|
.onRequest('session/request_permission', ({ params, signal }) => this.ask(conversation, 'session/request_permission', params, false, signal))
|
|
347
|
-
.onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
|
|
360
|
+
.onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
|
|
361
|
+
.onRequest('_x.ai/exit_plan_mode', EXIT_PLAN_MODE, ({ params, signal }) => this.ask(conversation, '_x.ai/exit_plan_mode', params, false, signal));
|
|
348
362
|
const cli = await unlessAborted(this.kit.agents.cli(route.kind), conversation.killed.signal);
|
|
349
363
|
const bridge = await openBridge(this.kit.house, this.kit.copies, conversation.id, conversation.killed.signal);
|
|
350
364
|
if (conversation.kills > 0) {
|
|
@@ -487,19 +501,21 @@ export class Conversations {
|
|
|
487
501
|
this.kit.changed();
|
|
488
502
|
return turn;
|
|
489
503
|
}
|
|
490
|
-
end(conversation, turn, failed) {
|
|
504
|
+
end(conversation, turn, failed, notice = null) {
|
|
491
505
|
if (turn.ended)
|
|
492
506
|
return;
|
|
493
507
|
if (conversation.turn === turn) {
|
|
494
508
|
for (const event of conversation.running?.reader.closeTurn() ?? [])
|
|
495
509
|
this.apply(conversation, turn, event);
|
|
496
510
|
}
|
|
511
|
+
if (notice !== null)
|
|
512
|
+
turn.parts.start({ type: 'marker', marker: 'retry', text: notice });
|
|
497
513
|
turn.ended = true;
|
|
498
514
|
conversation.open--;
|
|
499
515
|
if (conversation.turn === turn)
|
|
500
516
|
conversation.turn = null;
|
|
501
517
|
const body = Promise.allSettled(turn.uploads).then(() => ({
|
|
502
|
-
parts: turn.parts.
|
|
518
|
+
parts: turn.parts.saved(),
|
|
503
519
|
context: turn.parts.context,
|
|
504
520
|
...failed,
|
|
505
521
|
}));
|
|
@@ -511,7 +527,11 @@ export class Conversations {
|
|
|
511
527
|
const running = conversation.running;
|
|
512
528
|
const turn = this.begin(conversation);
|
|
513
529
|
turn.prompted = true;
|
|
514
|
-
running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then(() =>
|
|
530
|
+
running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then((answer) => {
|
|
531
|
+
const notice = answeredFailure(answer);
|
|
532
|
+
const failed = notice ?? (answer.stopReason === 'refusal' ? REFUSED : null);
|
|
533
|
+
this.end(conversation, turn, failed === null ? null : { failed }, notice);
|
|
534
|
+
}, async (error) => {
|
|
515
535
|
if (running.adapter.connection.signal.aborted) {
|
|
516
536
|
this.end(conversation, turn, { failed: running.killed ? KILLED : await running.adapter.exited });
|
|
517
537
|
}
|
|
@@ -644,7 +664,7 @@ export class Conversations {
|
|
|
644
664
|
turn.parts.plan(event.entries);
|
|
645
665
|
return;
|
|
646
666
|
case 'image':
|
|
647
|
-
turn.uploads.push(this.image(conversation, turn, event.data, event.mediaType));
|
|
667
|
+
turn.uploads.push(this.image(conversation, turn, turn.parts.reserve(), event.data, event.mediaType));
|
|
648
668
|
this.kit.changed();
|
|
649
669
|
return;
|
|
650
670
|
}
|
|
@@ -664,7 +684,7 @@ export class Conversations {
|
|
|
664
684
|
else
|
|
665
685
|
conversation.turn.parts.start(part);
|
|
666
686
|
}
|
|
667
|
-
async image(conversation, turn, data, mediaType) {
|
|
687
|
+
async image(conversation, turn, reserved, data, mediaType) {
|
|
668
688
|
const bytes = Buffer.from(data, 'base64');
|
|
669
689
|
const name = `image-${++turn.images}.${mediaType.split('/')[1]}`;
|
|
670
690
|
try {
|
|
@@ -677,10 +697,10 @@ export class Conversations {
|
|
|
677
697
|
const saved = declared.upload === undefined ? declared : await uploadBytes(declared.upload, bytes);
|
|
678
698
|
if (saved.save.status !== 'saved')
|
|
679
699
|
throw new Error(saved.save.failure ?? saved.save.status);
|
|
680
|
-
turn.parts.
|
|
700
|
+
turn.parts.arrive({ type: 'image', file: saved.version, name, media_type: mediaType }, reserved);
|
|
681
701
|
}
|
|
682
702
|
catch (error) {
|
|
683
|
-
turn.parts.
|
|
703
|
+
turn.parts.arrive({ type: 'marker', marker: 'retry', text: `${name} was not saved: ${causeOf(error)}` }, reserved);
|
|
684
704
|
}
|
|
685
705
|
}
|
|
686
706
|
}
|
package/dist/copies.js
CHANGED
|
@@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
3
3
|
import { mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { finalRefusal, HouseRefusal, retrying } from './api.js';
|
|
6
|
-
import { blobId, blobText, git, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
|
|
6
|
+
import { blobId, blobText, git, isText, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
|
|
7
7
|
import { kitHome } from './home.js';
|
|
8
8
|
import { operationId } from './operation.js';
|
|
9
9
|
import { refusalOf } from './refusals.js';
|
|
@@ -15,6 +15,9 @@ const IDENTITY = { GIT_COMMITTER_NAME: 'House Kit', GIT_COMMITTER_EMAIL: 'house-
|
|
|
15
15
|
function causeOf(error) {
|
|
16
16
|
return error instanceof Error ? error.message : String(error);
|
|
17
17
|
}
|
|
18
|
+
function houseCause(error) {
|
|
19
|
+
return error instanceof HouseRefusal ? (refusalOf(error.text)?.text ?? causeOf(error)) : causeOf(error);
|
|
20
|
+
}
|
|
18
21
|
function logged(error) {
|
|
19
22
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
20
23
|
}
|
|
@@ -29,6 +32,10 @@ const REBASED = new Set([
|
|
|
29
32
|
function rebaseFixes(refusal) {
|
|
30
33
|
return refusal.code === 'edit_conflict' && refusal.conflicts.some((code) => REBASED.has(code));
|
|
31
34
|
}
|
|
35
|
+
function textOnly(paths) {
|
|
36
|
+
const [named, them] = paths.length === 1 ? [`${paths[0]} is`, 'it'] : [`${paths.join(', ')} are`, 'them'];
|
|
37
|
+
return `${named} not text, and house push sends text only; remove ${them} from the commit and place ${them} with house upload`;
|
|
38
|
+
}
|
|
32
39
|
function short(commit) {
|
|
33
40
|
return commit.slice(0, 12);
|
|
34
41
|
}
|
|
@@ -257,7 +264,7 @@ export class LocalCopies {
|
|
|
257
264
|
}
|
|
258
265
|
catch (error) {
|
|
259
266
|
refused = true;
|
|
260
|
-
said.push(
|
|
267
|
+
said.push(houseCause(error));
|
|
261
268
|
}
|
|
262
269
|
}
|
|
263
270
|
return { refused, text: said.length === 0 ? 'Nothing new from House.' : said.join('\n') };
|
|
@@ -545,7 +552,7 @@ export class LocalCopies {
|
|
|
545
552
|
changes = await this.derived(copy, base, commit);
|
|
546
553
|
}
|
|
547
554
|
catch (error) {
|
|
548
|
-
return { refused: true, text:
|
|
555
|
+
return { refused: true, text: houseCause(error) };
|
|
549
556
|
}
|
|
550
557
|
if (changes.length === 0)
|
|
551
558
|
return { refused: false, text: `Nothing to submit: ${short(commit)} matches House.` };
|
|
@@ -572,7 +579,18 @@ export class LocalCopies {
|
|
|
572
579
|
const after = await tree(copy.repository, commit);
|
|
573
580
|
const moved = movedPaths(copy.moves, before, after);
|
|
574
581
|
const arrived = new Set(moved.values());
|
|
575
|
-
const
|
|
582
|
+
const arriving = [...after].filter(([path, entry]) => before.get(path) !== entry);
|
|
583
|
+
if (arriving.length > 0) {
|
|
584
|
+
const { bounds } = await this.house.post('/kit/door/discover', { prefixes: [root] });
|
|
585
|
+
const binary = [];
|
|
586
|
+
for (const [path, entry] of arriving) {
|
|
587
|
+
if (!(await isText(copy.repository, entry, bounds.max_authored_file_bytes)))
|
|
588
|
+
binary.push(path);
|
|
589
|
+
}
|
|
590
|
+
if (binary.length > 0)
|
|
591
|
+
throw new Error(textOnly(binary));
|
|
592
|
+
}
|
|
593
|
+
const text = (entry) => blobText(copy.repository, entry);
|
|
576
594
|
const changes = [];
|
|
577
595
|
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
578
596
|
if (arrived.has(path))
|
|
@@ -585,7 +603,7 @@ export class LocalCopies {
|
|
|
585
603
|
changes.push({ op: 'rename', path: `${root}/${path}`, to: `${root}/${to}`, base: known });
|
|
586
604
|
const moving = after.get(to);
|
|
587
605
|
if (moving !== prior) {
|
|
588
|
-
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving
|
|
606
|
+
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving) });
|
|
589
607
|
}
|
|
590
608
|
continue;
|
|
591
609
|
}
|
|
@@ -594,9 +612,9 @@ export class LocalCopies {
|
|
|
594
612
|
if (next === undefined)
|
|
595
613
|
changes.push({ op: 'remove', path: `${root}/${path}`, base: known });
|
|
596
614
|
else if (prior === undefined)
|
|
597
|
-
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next
|
|
615
|
+
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next) });
|
|
598
616
|
else
|
|
599
|
-
changes.push(...changed(`${root}/${path}`, path, known, await text(prior
|
|
617
|
+
changes.push(...changed(`${root}/${path}`, path, known, await text(prior), await text(next)));
|
|
600
618
|
}
|
|
601
619
|
return changes;
|
|
602
620
|
}
|
|
@@ -663,7 +681,7 @@ export class LocalCopies {
|
|
|
663
681
|
written.push({
|
|
664
682
|
path: `${root}/${path}`,
|
|
665
683
|
revision: entry === undefined ? null : (revisionAt(current, current.house, path) ?? null),
|
|
666
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
684
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
667
685
|
});
|
|
668
686
|
}
|
|
669
687
|
return this.finished(await this.save({ ...current, push: { ...push, state: 'accepted', written } }));
|
|
@@ -707,7 +725,7 @@ export class LocalCopies {
|
|
|
707
725
|
{
|
|
708
726
|
path: `${rootOf(copy.room_handle)}/${path}`,
|
|
709
727
|
revision: entry === undefined ? null : (revisionAt(copy, copy.house, path) ?? null),
|
|
710
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
728
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
711
729
|
},
|
|
712
730
|
];
|
|
713
731
|
}
|
|
@@ -752,7 +770,7 @@ export class LocalCopies {
|
|
|
752
770
|
async landed(repository, changes, house, selected) {
|
|
753
771
|
const text = async (path) => {
|
|
754
772
|
const entry = house.get(relative(path));
|
|
755
|
-
return entry === undefined ? undefined : blobText(repository, entry
|
|
773
|
+
return entry === undefined ? undefined : blobText(repository, entry);
|
|
756
774
|
};
|
|
757
775
|
for (const change of changes) {
|
|
758
776
|
const current = await text(change.path);
|
package/dist/end.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
import { forgetRejected } from './home.js';
|
|
2
|
+
import { installCommand } from './placement.js';
|
|
1
3
|
import { killDescendants } from './scope.js';
|
|
2
4
|
export const REPLACED = 'another Kit started for this Environment';
|
|
3
|
-
|
|
4
|
-
export function end(reason) {
|
|
5
|
+
function exit(reason, status) {
|
|
5
6
|
process.stderr.write(`kit: ${reason}\n`);
|
|
6
7
|
killDescendants();
|
|
7
|
-
process.exit(
|
|
8
|
+
process.exit(status);
|
|
9
|
+
}
|
|
10
|
+
export function end(reason) {
|
|
11
|
+
exit(reason, 0);
|
|
12
|
+
}
|
|
13
|
+
export function restart(reason) {
|
|
14
|
+
exit(reason, 1);
|
|
15
|
+
}
|
|
16
|
+
export function updateRequired(house) {
|
|
17
|
+
end(`This Kit is too old for House. Update it: ${installCommand(house)}`);
|
|
18
|
+
}
|
|
19
|
+
export async function signInAgain(rejected) {
|
|
20
|
+
await forgetRejected(rejected);
|
|
21
|
+
restart('sign in again');
|
|
8
22
|
}
|
package/dist/events.js
CHANGED
|
@@ -512,6 +512,9 @@ class GrokReader extends Reader {
|
|
|
512
512
|
return [];
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
|
+
export function answeredFailure(answer) {
|
|
516
|
+
return answer._meta?.jetbrains?.air?.sessionFailure?.title ?? null;
|
|
517
|
+
}
|
|
515
518
|
export function readerFor(kind) {
|
|
516
519
|
if (kind === 'claude-agent-acp')
|
|
517
520
|
return new ClaudeReader();
|