@agentshouse/kit 0.2.1-ccffb3f637815 → 0.2.1-cd423aab3dbcc

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 CHANGED
@@ -7,7 +7,7 @@ your Agents' conversations through the agent CLIs you chose and gives each Agent
7
7
 
8
8
  Run `sh -c 'kit=$(curl -fsSL "$0") || { echo "Kit could not be downloaded; run this command again." >&2; exit 1; }; eval "$kit"' agents.house/kit`,
9
9
  or `& { try { $kit = irm agents.house/kit.ps1 } catch { throw 'Kit could not be downloaded; run this command again.' }; & ([scriptblock]::Create($kit)) @args }` on Windows, which run nothing of a failed download, and again to update; `--code <code>` follows `agents.house/kit` to connect with a login code.
10
- On macOS and Linux, a server included, it installs Kit natively under your own account, without an admin password, in one folder, `~/.agents/house`: Kit's own files at its top, its releases and their Node.js in `kit`, `kit` and `house` in `bin`, which it adds to your login shell's `PATH`, and your workspace, the Agents' folders in `agents` and the Rooms' copies in `local-copies`. It stops, changing nothing, where `~/.agents/house` holds something that is not Kit's. On Linux it adds a missing `ca-certificates`, `curl` or `git` through apt. Then `kit connect` keeps the Environment you connected, redeems the login code or prints a link you confirm, writes Kit's settings where `kit.json` has none, places House's Skills and starts Kit: as a systemd user unit that starts at boot through lingering on Linux, and as a LaunchAgent on macOS. On a Linux without systemd it starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. One account runs one Kit for one Building; to move it to another, run `kit logout` and then the other Building's command.
10
+ On macOS and Linux, a server included, it installs Kit natively under your own account, without an admin password, in one folder, `~/.agents/house`: Kit's own files at its top, its releases and their Node.js in `kit`, `kit` and `house` in `bin`, which it adds to your login shell's `PATH`, and its records of the Rooms' copies. Your workspace is `~/house`: each Room's copy in `rooms/<handle>`, so `cd ~/house/rooms/<handle>` and starting your agent CLI there starts it in that Room, and the Agents' folders in `agents`. It stops, changing nothing, where `~/.agents/house` holds something that is not Kit's. On Linux it adds a missing `ca-certificates`, `curl` or `git` through apt. Then `kit connect`, which stops in one line before it connects anything where `~/house` holds something and is not Kit's workspace, writing nothing there, keeps the Environment you connected, redeems the login code or prints a link you confirm, writes Kit's settings where `kit.json` has none, places House's Skills and starts Kit: as a systemd user unit that starts at boot through lingering on Linux, and as a LaunchAgent on macOS. On a Linux without systemd it starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. One account runs one Kit for one Building; to move it to another, run `kit logout` and then the other Building's command.
11
11
 
12
12
  Every run places the Kit release your Building serves, with the Node.js and agent adapters it runs on, in a directory of its own beside the one that runs, then starts it; the earlier one stays until the next release. Kit also updates itself: when your Building takes another release, Kit places it the same way and, once no turn is open, ends so its service starts it. When House no longer serves the wire of the Kit that runs, Kit places your Building's release at once, ending any running turn, and ends the same way; while it cannot, it stays offline, prints why with the command that installs it again, and tries again regularly.
13
13
 
@@ -39,13 +39,10 @@ computer, stops the Kit process and ends your own agent's connection, so `house`
39
39
  longer act as you here; a later `kit login` reconnects the same Environment, or connects
40
40
  this computer as a new one when House no longer holds it.
41
41
 
42
- `kit settings` prints Kit's two settings, which every update and every rerun of the install keep: `skills`, whether Kit places House's Skills, and `workspace`, the folder that holds `agents` and `local-copies`. `kit settings skills on|off` and `kit settings workspace <absolute path>` change one, as the Environment's page in House does.
43
- A new workspace must hold no `agents` or `local-copies` folder, and none is taken while an Agent works; Kit then ends its conversations' processes, moves both folders there, across filesystems copying and checking them before it deletes the old ones, and ends so its service starts it there.
42
+ `kit settings` prints Kit's two settings, which every update and every rerun of the install keep: `skills`, whether Kit places House's Skills, and `workspace`, the folder that holds `rooms` and `agents`, `~/house` unless you set another. `kit settings skills on|off` and `kit settings workspace <absolute path>` change one, as the Environment's page in House does.
43
+ A new workspace must hold no `rooms` or `agents` folder, and none is taken while an Agent works; Kit then ends its conversations' processes, moves both folders there, across filesystems copying and checking them before it deletes the old ones, and ends so its service starts it there.
44
44
 
45
- `kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it as a
46
- Git repository in the workspace's `local-copies`, and keeps a Room's copy as it is, no longer refreshing it, once the
47
- Room may no longer be copied here. `house fetch` does the same and records House's changes on each copy's
48
- `refs/house/received`; rebase onto it, commit and run `house push --owner` in the copy. An Agent runs both, without `--owner`. `house upload` and `house download` move a Room's other files straight between disk and House's store, and a broken upload resumes on its own.
45
+ `kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it into a plain folder named by its handle in the workspace's `rooms`, beside a hidden `.house` file recording each file's revision and SHA-256, renames the folder with everything in it when the Room's handle changes, and keeps a Room's copy as it is, no longer refreshing it, once the Room may no longer be copied here; where another Room's folder is to take its name, it first renames that copy's folder to the name with ` (kept)`, adding ` 2` and on where that is taken. `house download` brings House's changes into each copy, overwriting only files unchanged here, and with `--with-attachments` the attachments it lacks up to `--max-size` megabytes, 10 by default. `house upload --owner`, run in a copy, sends every file changed, added or deleted there; House merges a change made on an older revision, and a clash leaves conflict markers in the file to resolve before the next upload; an `AGENTS.md` or `CLAUDE.md` at a copy's top, whatever its case, is Kit's and never sent. An Agent runs both, without `--owner`. With a JSON argument, `house upload` and `house download` move one file between disk and a Room, and a broken upload resumes on its own. A copy made by an earlier Kit keeps its files and its `.git`, which Kit no longer reads. A Kit that kept its workspace in `~/.agents/house` moves it to `~/house` at its first start on this release, each copy with every file to `rooms/<handle>`, a copy it no longer follows to `rooms/<reference> (kept)`, and ends so its service starts it there; a workspace you set elsewhere, or one whose `~/house` holds something else, stays where it is and takes the same layout.
49
46
 
50
47
  Kit turns each audio file your message to an Agent links into text on this computer before the Agent reads it, and keeps a message whose audio it cannot turn into text from starting. While transcription is on, the speech engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
51
48
 
package/dist/binaries.js CHANGED
@@ -1,50 +1,21 @@
1
- import { createHash, randomUUID } from 'node:crypto';
2
- import { createWriteStream } from 'node:fs';
3
- import { mkdir, rm } from 'node:fs/promises';
4
- import { join } from 'node:path';
5
- import { Readable } from 'node:stream';
6
- import { pipeline } from 'node:stream/promises';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { copyFile, rm } from 'node:fs/promises';
7
3
  import { downloaded, fetched, fileRange, mediaTypeOf, sentPart, uploaded } from './files.js';
8
- import { blobBytes, blobSizes, isText, storedFile } from './git.js';
4
+ import { hashed } from './manifest.js';
5
+ export class Changed extends Error {
6
+ }
9
7
  const SENT_AT_ONCE = 10;
10
- const UPLOADS = 'house-uploads';
11
- const DOWNLOADS = 'house-downloads';
12
8
  const OCTET_STREAM = 'application/octet-stream';
13
9
  const MARKDOWN = /\.md$/i;
14
10
  const STORE = {
15
11
  unreached: (error) => new Error(`the store did not answer (${error.code ?? error.message})`),
16
12
  refused: (status) => new Error(`the store answered ${status}`),
17
13
  };
18
- async function digestOf(repository, object) {
19
- const digest = createHash('sha256');
20
- let bytes = 0;
21
- for await (const chunk of blobBytes(repository, object)) {
22
- bytes += chunk.length;
23
- digest.update(chunk);
24
- }
25
- return { bytes, sha256: digest.digest('hex') };
26
- }
27
14
  export function isDocument(path) {
28
15
  return MARKDOWN.test(path);
29
16
  }
30
- export async function untext(repository, documents, maxBytes) {
31
- const sizes = await blobSizes(repository, documents.map(([, object]) => object));
32
- const refused = [];
33
- for (const [path, object] of documents) {
34
- if (!(await isText(repository, object, sizes.get(object), maxBytes)))
35
- refused.push(path);
36
- }
37
- return refused;
38
- }
39
- export async function attachments(repository, arriving) {
40
- const described = new Map();
41
- for (const [path, object] of arriving)
42
- described.set(path, { ...(await digestOf(repository, object)), media_type: mediaTypeOf(path) ?? OCTET_STREAM });
43
- return described;
44
- }
45
- export async function holds(repository, object, file) {
46
- const held = await digestOf(repository, object);
47
- return held.bytes === file.bytes && held.sha256 === file.sha256;
17
+ export function mediaType(path) {
18
+ return mediaTypeOf(path) ?? OCTET_STREAM;
48
19
  }
49
20
  export async function eachAtOnce(items, work) {
50
21
  let next = 0;
@@ -54,16 +25,19 @@ export async function eachAtOnce(items, work) {
54
25
  };
55
26
  await Promise.all(Array.from({ length: Math.min(SENT_AT_ONCE, items.length) }, working));
56
27
  }
57
- export async function sentBinary(repository, object, name, file, upload, finish) {
58
- const directory = join(repository, '.git', UPLOADS);
59
- await mkdir(directory, { recursive: true });
60
- const copy = join(directory, randomUUID());
28
+ export async function sentBinary(staging, file, name, part, upload, finish) {
29
+ const copy = `${staging}${randomUUID()}`;
61
30
  try {
62
- await pipeline(Readable.from(blobBytes(repository, object)), createWriteStream(copy, { flags: 'wx' }));
31
+ await copyFile(file, copy).catch(() => {
32
+ throw new Changed(`${name} is gone since house upload read it`);
33
+ });
34
+ const held = await hashed(copy);
35
+ if (held?.sha256 !== part.sha256 || held.bytes !== part.bytes)
36
+ throw new Changed(`${name} changed since house upload read it`);
63
37
  await uploaded({ id: upload.id, part_bytes: upload.part_bytes }, {
64
38
  name,
65
- bytes: file.bytes,
66
- sha256: file.sha256,
39
+ bytes: part.bytes,
40
+ sha256: part.sha256,
67
41
  read: (start, end) => fileRange(copy, start, end, (error) => error),
68
42
  send: (url, start, end, headers) => sentPart(url, copy, start, end, headers, STORE),
69
43
  finish,
@@ -73,17 +47,14 @@ export async function sentBinary(repository, object, name, file, upload, finish)
73
47
  await rm(copy, { force: true });
74
48
  }
75
49
  }
76
- export async function receivedBinary(repository, name, address) {
77
- const file = join(repository, '.git', DOWNLOADS, randomUUID());
50
+ export async function receivedBinary(staging, name, address) {
51
+ const file = `${staging}${randomUUID()}`;
78
52
  try {
79
53
  await downloaded(address, (url) => fetched(url), file, name);
80
- return await storedFile(repository, file);
54
+ return file;
81
55
  }
82
- finally {
56
+ catch (error) {
83
57
  await rm(file, { force: true });
58
+ throw error;
84
59
  }
85
60
  }
86
- export async function sweptTransfers(repository) {
87
- for (const directory of [UPLOADS, DOWNLOADS])
88
- await rm(join(repository, '.git', directory), { recursive: true, force: true });
89
- }
package/dist/bridge.js CHANGED
@@ -4,16 +4,20 @@ import { setTimeout as delay } from 'node:timers/promises';
4
4
  import { createServer, request as httpRequest } from 'node:http';
5
5
  import { request as httpsRequest } from 'node:https';
6
6
  import { delimiter, dirname, join } from 'node:path';
7
+ import { FUNCTION_RUN_META_KEY } from '@agentshouse/kit-wire';
7
8
  import { parse } from 'yaml';
8
9
  import { finalRefusal, HouseRefusal, retryDelay, retrying } from './api.js';
9
10
  import { loginPath } from './clis.js';
10
- import { changedPaths, } from './copies.js';
11
+ import { changedPaths, DEFAULT_MAX_SIZE, UPLOAD_NEEDS_OWNER, } from './copies.js';
11
12
  import { fileInfo } from './files.js';
12
- import { kitHome, readEnrolment, socketDirectory } from './home.js';
13
- import { callHouse, mcpBody, refusalIn, rpc, toolAnswer, UNREACHABLE } from './mcp.js';
13
+ import { readEnrolment, readOwnAgent, socketDirectory } from './home.js';
14
+ import { callHouse, DISCONNECTED, mcpBody, refusalIn, rpc, toolAnswer, UNREACHABLE } from './mcp.js';
14
15
  import { operationId } from './operation.js';
15
16
  import { refusalOf, retryable, stopsPush } from './refusals.js';
16
17
  import { relayed } from './relay.js';
18
+ class Said extends Error {
19
+ }
20
+ const OWNER_IN_CONVERSATION = '--owner is not for Agent conversations; run house upload without it';
17
21
  const MCP_REQUEST_BYTES = 4_000_000;
18
22
  export async function received(request) {
19
23
  let text = '';
@@ -66,17 +70,58 @@ function editAnswer(forwarded) {
66
70
  return {
67
71
  accepted: results.flatMap((result) => [
68
72
  ...(result.from === undefined ? [] : [{ path: result.from, revision: null, content: null }]),
69
- { path: result.path, revision: result.revision ?? null },
73
+ { path: result.path, revision: result.revision ?? null, ...(result.content === undefined ? {} : { content: result.content }) },
70
74
  ]),
71
75
  };
72
76
  }
73
77
  export async function openBridge(house, copies, conversationId, signal) {
74
- const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
75
- const origin = (await readEnrolment()).house;
76
78
  const { credential } = await retrying(() => house.act('conversations/credentials/issue', { conversation: conversationId }, signal), signal);
79
+ return bridgeFor(copies, {
80
+ key: `conversation:${conversationId}`,
81
+ origin: (await readEnrolment()).house,
82
+ credential,
83
+ named: {},
84
+ ownAgent: false,
85
+ owner: false,
86
+ path: [dirname(process.execPath), await loginPath()].join(delimiter),
87
+ });
88
+ }
89
+ async function runCredential(house, run, signal) {
90
+ try {
91
+ return (await retrying(() => house.act('function-runs/credentials/issue', { run }, signal), signal)).credential;
92
+ }
93
+ catch (error) {
94
+ if (finalRefusal(error))
95
+ return null;
96
+ throw error;
97
+ }
98
+ }
99
+ export async function openRunBridge(house, copies, run, signal) {
100
+ const named = { [FUNCTION_RUN_META_KEY]: run };
101
+ const ownAgent = await readOwnAgent();
102
+ if (ownAgent !== null) {
103
+ return bridgeFor(copies, {
104
+ key: `function-run:${run}`,
105
+ origin: ownAgent.house,
106
+ credential: ownAgent.credential,
107
+ named,
108
+ ownAgent: true,
109
+ owner: true,
110
+ path: null,
111
+ });
112
+ }
113
+ const credential = await runCredential(house, run, signal);
114
+ if (credential === null)
115
+ return null;
116
+ const origin = (await readEnrolment()).house;
117
+ return bridgeFor(copies, { key: `function-run:${run}`, origin, credential, named, ownAgent: false, owner: true, path: null });
118
+ }
119
+ async function bridgeFor(copies, holder) {
120
+ const { origin, credential, named, path } = holder;
77
121
  const closed = new AbortController();
78
- const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
79
- const send = async (message, operation, pushing = false) => {
122
+ const sent = (message, operation) => callHouse(origin, credential, message, { operation, named, signal: closed.signal });
123
+ const send = async (message, asked, pushing = false) => {
124
+ const operation = holder.ownAgent ? null : asked;
80
125
  if (operation === null)
81
126
  return sent(message, null);
82
127
  for (let attempt = 0;; attempt++) {
@@ -128,11 +173,11 @@ export async function openBridge(house, copies, conversationId, signal) {
128
173
  return send(message, message.method === 'tools/call' ? operationId() : null);
129
174
  };
130
175
  const caller = {
131
- key: `conversation:${conversationId}`,
176
+ key: holder.key,
132
177
  submit: async (operation, changes, held, retain) => {
133
178
  const inline = call('update', { changes });
134
179
  let upload = held;
135
- if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
180
+ if (upload === undefined && Buffer.byteLength(mcpBody(inline, { operation, named })) > MCP_REQUEST_BYTES) {
136
181
  const prepared = await staged(operation, changes);
137
182
  if ('refused' in prepared)
138
183
  return prepared;
@@ -141,8 +186,8 @@ export async function openBridge(house, copies, conversationId, signal) {
141
186
  }
142
187
  return editAnswer(await send(upload === undefined ? inline : call('update', { paths: changedPaths(changes), upload }), operation, true));
143
188
  },
144
- finish: async (upload, room, partSha256) => {
145
- const answer = toolAnswer(await send(call('upload', { upload, room_ref: room, part_sha256: partSha256 }), operationId(), true));
189
+ finish: async (upload, path, partSha256) => {
190
+ const answer = toolAnswer(await send(call('upload', { upload, path, part_sha256: partSha256 }), operationId(), true));
146
191
  if ('refused' in answer)
147
192
  throw new Error(answer.refused.text);
148
193
  return parse(answer.text);
@@ -154,18 +199,23 @@ export async function openBridge(house, copies, conversationId, signal) {
154
199
  return fileInfo(answer.text);
155
200
  },
156
201
  };
202
+ const uploader = holder.owner ? copies.owner : caller;
157
203
  const local = async (path, text) => {
158
- if (path === '/git/push') {
159
- const { cwd, commit } = JSON.parse(text);
160
- return { status: 200, text: JSON.stringify(await copies.push(cwd, commit, caller)) };
204
+ if (path === '/copy/upload') {
205
+ const { cwd, owner } = JSON.parse(text);
206
+ const uploaded = owner === holder.owner ? await copies.upload(cwd, uploader) : { refused: true, text: owner ? OWNER_IN_CONVERSATION : UPLOAD_NEEDS_OWNER };
207
+ return { status: 200, text: JSON.stringify(uploaded) };
161
208
  }
162
- if (path === '/git/fetch')
163
- return { status: 200, text: JSON.stringify(await copies.fetch(caller)) };
164
- if (path === '/git/observed') {
165
- await copies.observed(JSON.parse(text));
166
- return { status: 200, text: '{}' };
209
+ if (path === '/copy/download') {
210
+ const { attachments = false, max_size: maxSize = DEFAULT_MAX_SIZE } = JSON.parse(text);
211
+ return { status: 200, text: JSON.stringify(await copies.download(uploader, { attachments, maxSize })) };
167
212
  }
168
- return path === '/' ? forward(text) : { status: 404, text: '' };
213
+ if (path !== '/')
214
+ return { status: 404, text: '' };
215
+ const forwarded = await forward(text);
216
+ if (holder.ownAgent && forwarded.status === 401)
217
+ throw new Said(DISCONNECTED);
218
+ return forwarded;
169
219
  };
170
220
  const socketPath = join(socketDirectory(), `${randomUUID()}.sock`);
171
221
  const bridge = createServer(async (request, response) => {
@@ -179,11 +229,15 @@ export async function openBridge(house, copies, conversationId, signal) {
179
229
  response.writeHead(answered.status, { 'content-type': 'application/json' }).end(answered.text);
180
230
  }
181
231
  catch (error) {
232
+ if (error instanceof Said) {
233
+ response.writeHead(502).end(error.message);
234
+ return;
235
+ }
182
236
  if (error instanceof HouseRefusal) {
183
237
  response.writeHead(error.status, { 'content-type': 'application/json' }).end(error.text);
184
238
  return;
185
239
  }
186
- const verb = request.url === '/git/push' || request.url === '/git/fetch';
240
+ const verb = request.url === '/copy/upload' || request.url === '/copy/download';
187
241
  response.writeHead(502).end(verb && error instanceof Error ? error.message : UNREACHABLE);
188
242
  }
189
243
  });
@@ -205,7 +259,7 @@ export async function openBridge(house, copies, conversationId, signal) {
205
259
  return {
206
260
  env: {
207
261
  HOUSE_BRIDGE: socketPath,
208
- PATH: path,
262
+ ...(path === null ? {} : { PATH: path }),
209
263
  GIT_CONFIG_COUNT: '1',
210
264
  GIT_CONFIG_KEY_0: `url.${proxy}/app/.insteadOf`,
211
265
  GIT_CONFIG_VALUE_0: app,
package/dist/chunks.js CHANGED
@@ -34,6 +34,11 @@ export async function stagedChunks(directory, chunks) {
34
34
  return failure;
35
35
  }
36
36
  export async function* chunkEntries(directory, chunks, models) {
37
+ for (const { hash } of chunks) {
38
+ for (const line of (await readFile(join(directory, hash), 'utf8')).split('\n'))
39
+ if (line !== '')
40
+ JSON.parse(line);
41
+ }
37
42
  yield* models;
38
43
  for (const { hash } of chunks) {
39
44
  const file = join(directory, hash);
package/dist/connect.js CHANGED
@@ -4,10 +4,11 @@ import { join } from 'node:path';
4
4
  import { parseArgs } from 'node:util';
5
5
  import { HouseRefusal, kitAct } from './api.js';
6
6
  import { KIT_RELEASE } from './clis.js';
7
- import { takeOverEarlier } from './earlier.js';
8
- import { kitHome, readEnrolment, storedConfiguration, writeConfiguration } from './home.js';
7
+ import { otherAccountKit, takeOverEarlier } from './earlier.js';
8
+ import { kitHome, readDisconnected, readEnrolment, storedConfiguration, writeConfiguration } from './home.js';
9
9
  import { DEFAULT_HOUSE, enrol, placeConnection } from './login.js';
10
10
  import { runningRelease } from './owner.js';
11
+ import { HOUSE_NOT_KITS, houseRoot } from './settings.js';
11
12
  import { quoted } from './shell.js';
12
13
  import { defineSupervisor, launcher, supervise, systemd } from './supervisor.js';
13
14
  const USAGE = `usage: kit connect [--house <origin>] [--code <code>]
@@ -26,8 +27,10 @@ async function standing(house, credential) {
26
27
  return true;
27
28
  }
28
29
  catch (error) {
29
- if (!unanswered(error))
30
+ if (error instanceof HouseRefusal && error.status === 401)
30
31
  return false;
32
+ if (!unanswered(error))
33
+ throw error;
31
34
  process.stderr.write(`kit: House did not answer, so the stored credential stands: ${error.message}\n`);
32
35
  return true;
33
36
  }
@@ -75,14 +78,18 @@ export async function connect(argv) {
75
78
  }
76
79
  await takeOverEarlier();
77
80
  settleHeld();
81
+ const held = await storedConfiguration();
82
+ const workspace = held.workspace ?? (await houseRoot());
83
+ if (workspace === null)
84
+ throw new Error(HOUSE_NOT_KITS);
78
85
  const stored = await readEnrolment();
86
+ const other = stored === null && (await readDisconnected()) === null ? otherAccountKit() : null;
87
+ if (other !== null)
88
+ throw new Error(`this computer's Kit runs as ${other}; run this command as ${other} to update it`);
79
89
  const house = values.house ?? stored?.house ?? DEFAULT_HOUSE;
80
90
  if (stored !== null && stored.house !== house) {
81
91
  throw new Error(`this account's Kit serves ${stored.house}; kit logout disconnects it from there, then this command connects it to ${house}`);
82
92
  }
83
- const install = process.env.HOUSE_KIT_INSTALL_COMMAND;
84
- if (install !== undefined && install !== '')
85
- await writeFile(join(kitHome(), 'install-command'), `${install}\n`, { mode: 0o600 });
86
93
  if (stored === null || !(await standing(stored.house, stored.credential))) {
87
94
  if (values.code === undefined)
88
95
  await enrol({ house, 'no-private': false });
@@ -91,9 +98,15 @@ export async function connect(argv) {
91
98
  if ((await readEnrolment()) === null)
92
99
  throw new Error('kit login connected no Environment');
93
100
  }
101
+ else if (values.code !== undefined) {
102
+ process.stdout.write(`This computer is already connected as Environment ${stored.environment}; the login code was not used.\n`);
103
+ }
104
+ const install = process.env.HOUSE_KIT_INSTALL_COMMAND;
105
+ if (install !== undefined && install !== '')
106
+ await writeFile(join(kitHome(), 'install-command'), `${install}\n`, { mode: 0o600 });
94
107
  const settings = await storedConfiguration();
95
108
  if (settings.skills === undefined || settings.workspace === undefined) {
96
- await writeConfiguration({ skills: true, workspace: kitHome(), ...settings });
109
+ await writeConfiguration({ skills: true, workspace, ...settings });
97
110
  }
98
111
  await placeConnection(house);
99
112
  const { environment } = (await readEnrolment());
@@ -20,6 +20,10 @@ import { killMarked, Scope } from './scope.js';
20
20
  import { holdSecretInput } from './secret-input.js';
21
21
  import { transcribe } from './transcription.js';
22
22
  import { workFor } from './work.js';
23
+ const EFFORT = 'thought_level';
24
+ function conversationRoute(route, chosen) {
25
+ return { ...route, model: chosen.model ?? route.model, effort: chosen.effort ?? route.effort };
26
+ }
23
27
  const KILLED = 'the conversation was killed';
24
28
  const INTERRUPTED = 'the conversation was interrupted';
25
29
  const REFUSED = 'the CLI refused the prompt';
@@ -176,7 +180,6 @@ class Conversation {
176
180
  tokens = null;
177
181
  leftovers = new Set();
178
182
  waiting = [];
179
- done = false;
180
183
  sending = null;
181
184
  subagents = new Set();
182
185
  opening = null;
@@ -314,11 +317,6 @@ export class Conversations {
314
317
  return this.open(conversation, call);
315
318
  if (call.kind === 'message')
316
319
  return this.message(conversation, call);
317
- if (call.kind === 'done') {
318
- conversation.done = true;
319
- this.next(conversation);
320
- return { result: Promise.resolve({}) };
321
- }
322
320
  if (call.kind === 'take_out')
323
321
  return { result: Promise.resolve(this.takeOut(conversation, call.message_id)) };
324
322
  await this.launched(conversation);
@@ -334,7 +332,7 @@ export class Conversations {
334
332
  conversation.killed = new AbortController();
335
333
  }
336
334
  if (call.kind === 'option')
337
- await this.option(conversation, call.option, call.value);
335
+ await this.option(conversation, call);
338
336
  if (call.kind === 'answer') {
339
337
  const question = this.questions.get(call.interaction_id);
340
338
  if (question === undefined) {
@@ -355,7 +353,8 @@ export class Conversations {
355
353
  }
356
354
  async open(conversation, call) {
357
355
  await this.stop(conversation);
358
- const launch = conversation.launch ?? this.launch(conversation, this.route(conversation, call.agent_id), null, true);
356
+ const launch = conversation.launch ??
357
+ this.launch(conversation, this.route(conversation, call.agent_id).then((route) => conversationRoute(route, call)), null, true);
359
358
  return {
360
359
  result: launch.session.then((session) => ({ provider_session_id: session }), (error) => ({ refused: refusal(conversation, error) })),
361
360
  };
@@ -409,7 +408,7 @@ export class Conversations {
409
408
  let route;
410
409
  let instructing = null;
411
410
  try {
412
- route = await this.route(conversation, call.agent_id);
411
+ route = conversationRoute(await this.route(conversation, call.agent_id), call);
413
412
  if (call.first === true)
414
413
  instructing = this.instructed(conversation, route);
415
414
  if (call.message_id !== null)
@@ -486,8 +485,6 @@ export class Conversations {
486
485
  const step = conversation.preparing ?? (conversation.launch === null ? null : 'session');
487
486
  if (conversation.starting !== step)
488
487
  this.starts(conversation, step);
489
- if (conversation.done && conversation.launch === null)
490
- void this.stop(conversation).catch(logged);
491
488
  return;
492
489
  }
493
490
  conversation.sending = this.send(conversation, waiting).finally(() => {
@@ -652,25 +649,38 @@ export class Conversations {
652
649
  this.halt(conversation);
653
650
  await running?.adapter.exited;
654
651
  }
655
- async option(conversation, option, value) {
652
+ async option(conversation, chosen) {
653
+ while (conversation.running === null && conversation.sending !== null)
654
+ await conversation.sending;
656
655
  const running = conversation.running;
657
656
  if (running === null)
658
657
  return;
659
- try {
660
- if (conversation.options?.find(({ id }) => id === option)?.category === 'mode') {
661
- throw new Error(`conversation ${conversation.id} keeps the mode its Agent's launch settings name`);
658
+ for (const [category, value] of [['model', chosen.model], [EFFORT, chosen.effort]]) {
659
+ if (value === undefined)
660
+ continue;
661
+ try {
662
+ const options = await this.setOption(running, conversation.options ?? [], category, value);
663
+ if (options !== null)
664
+ this.options(conversation, options);
665
+ }
666
+ catch (error) {
667
+ logged(error);
662
668
  }
663
- running.reader.requested(option, value);
664
- const answered = await running.adapter.connection.agent.request('session/set_config_option', {
665
- sessionId: running.sessionId,
666
- configId: option,
667
- ...(typeof value === 'boolean' ? { type: 'boolean', value } : { value: String(value) }),
668
- });
669
- this.options(conversation, answered.configOptions);
669
+ }
670
+ }
671
+ async setOption(running, options, category, value) {
672
+ const option = options.find((candidate) => candidate.category === category);
673
+ if (option === undefined && category === EFFORT)
674
+ return null;
675
+ const configId = option?.id ?? category;
676
+ running.reader.requested(configId, value);
677
+ try {
678
+ const answered = await running.adapter.connection.agent.request('session/set_config_option', { sessionId: running.sessionId, configId, value });
679
+ return answered.configOptions;
670
680
  }
671
681
  catch (error) {
672
- running.reader.refused(option);
673
- logged(error);
682
+ running.reader.refused(configId);
683
+ throw error;
674
684
  }
675
685
  }
676
686
  async route(conversation, agentId) {
@@ -765,19 +775,11 @@ export class Conversations {
765
775
  const settings = [
766
776
  ['mode', route.mode ?? CLIS[route.kind].fullAccess],
767
777
  ['model', route.model],
768
- ['thought_level', route.effort],
778
+ [EFFORT, route.effort],
769
779
  ];
770
780
  for (const [category, value] of settings) {
771
- if (value === null)
772
- continue;
773
- const option = options.find((candidate) => candidate.category === category);
774
- running.reader.requested(option?.id ?? category, value);
775
- const answered = await running.adapter.connection.agent.request('session/set_config_option', {
776
- sessionId: running.sessionId,
777
- configId: option?.id ?? category,
778
- value,
779
- });
780
- options = answered.configOptions;
781
+ if (value !== null)
782
+ options = (await this.setOption(running, options, category, value)) ?? options;
781
783
  }
782
784
  return options;
783
785
  }
@@ -840,7 +842,7 @@ export class Conversations {
840
842
  const value = options.find((option) => option.category === category)?.currentValue;
841
843
  return value === undefined ? null : String(value);
842
844
  };
843
- this.stated(conversation, { model: chosen('model'), effort: chosen('thought_level'), mode: chosen('mode') });
845
+ this.stated(conversation, { model: chosen('model'), effort: chosen(EFFORT), mode: chosen('mode') });
844
846
  }
845
847
  deliver(conversation, act, request, current) {
846
848
  this.reporting++;