@agentshouse/kit 0.2.1-ce47f621f90e1 → 0.2.1-ce8e5419af3f9

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
@@ -20,7 +20,7 @@ from the running Kit process asks you to confirm before it replaces that process
20
20
 
21
21
  On your own Linux server, run the Linux command with `--linux` to install Kit natively, with its workspace at `/agents/house` and a missing `ca-certificates`, `curl` or `git` installed through apt; `kit` and `house` are then on the server's `PATH`.
22
22
 
23
- Kit is built for macOS 27 on Apple silicon, Ubuntu 26.04 LTS on amd64 and Windows 11 on amd64. On another release, distribution or architecture the command prints one warning line, such as `Warning: macOS 26.7.1 is outdated; update to macOS 27.`, and installs anyway. It refuses only an architecture other than amd64 and arm64, and a native install on a Linux without glibc, where `--container` still runs Kit. On a Linux without systemd it installs and connects Kit but starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. `--container` installs Docker Engine on Ubuntu and Debian; another Linux needs a working Docker Engine first.
23
+ Kit is built for macOS 27 on Apple silicon, Ubuntu 26.04 LTS on amd64 and Windows 11 on amd64. On another release, distribution or architecture the command prints one warning line, such as `Warning: macOS 26.7.1 is outdated; update to macOS 27.`, and installs anyway. It refuses only an architecture other than amd64 and arm64, a native install on a macOS older than 13.5, and one on a Linux without glibc 2.28 or newer, where `--container` still runs Kit. On a Linux without systemd it installs and connects Kit but starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. `--container` installs Docker Engine on Ubuntu and Debian; another Linux needs a working Docker Engine first.
24
24
 
25
25
  Kit runs each agent CLI through the link your login shell finds and installs a missing one through that CLI's own
26
26
  installer. When it starts and regularly after, Kit runs each CLI's own update command, such as `claude update`, beside
@@ -43,7 +43,6 @@ login run a lone `house` command outside their sandbox. `kit logout` disconnects
43
43
  computer, stops the Kit process and ends your own agent's connection, so `house` and `git` no
44
44
  longer act as you here; a later `kit login` reconnects the same Environment, or connects
45
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
46
 
48
47
  `kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it as a
49
48
  Git repository in the workspace's `local-copies`, and keeps a Room's copy as it is, no longer refreshing it, once the
package/dist/acp.js CHANGED
@@ -116,7 +116,7 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
116
116
  terminal: false,
117
117
  elicitation: { form: {} },
118
118
  session: { compaction: {}, notices: {} },
119
- _meta: { jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
119
+ _meta: { terminal_output: true, jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
120
120
  },
121
121
  clientInfo: { name: '@agentshouse/kit', version: KIT_RELEASE },
122
122
  });
package/dist/afk.js ADDED
@@ -0,0 +1,17 @@
1
+ import { CLIS } from './clis.js';
2
+ const NOBODY_THERE = 'Nobody is there to answer. Decide for yourself and go on.';
3
+ export const PLAN_APPROVED = { outcome: 'approved' };
4
+ function told(fields) {
5
+ return Object.fromEntries(fields.map((field) => [field, NOBODY_THERE]));
6
+ }
7
+ export function permissionAllowed({ options }) {
8
+ const option = options.find(({ kind }) => kind === 'allow_once') ?? options.find(({ kind }) => kind === 'allow_always');
9
+ return { outcome: { outcome: 'selected', optionId: option.optionId } };
10
+ }
11
+ export function formAnswered(kind, request) {
12
+ const fields = CLIS[kind].questionFields(request);
13
+ return fields.length === 0 ? { action: 'decline' } : { action: 'accept', content: told(fields) };
14
+ }
15
+ export function grokQuestionAnswered({ questions }) {
16
+ return { outcome: 'accepted', answers: told(questions.map(({ question }) => question)) };
17
+ }
package/dist/agents.js CHANGED
@@ -186,7 +186,7 @@ export class Agents {
186
186
  this.refreshing++;
187
187
  this.changed();
188
188
  const reading = this.read().then(async () => {
189
- this.desired = await this.house.deliver('/kit/agents/desired', {});
189
+ this.desired = await this.house.deliver('/kit/agents/desired/list', {});
190
190
  return this.desired;
191
191
  });
192
192
  this.reading = reading;
@@ -206,9 +206,12 @@ export class Agents {
206
206
  });
207
207
  return reading.then(() => undefined);
208
208
  }
209
- keepCurrent() {
209
+ keepCurrent(stopping) {
210
210
  this.updateAll(this.loaded);
211
- setInterval(() => this.updateAll(Promise.resolve()), CLI_UPDATE_MS);
211
+ setInterval(() => {
212
+ if (!stopping())
213
+ this.updateAll(Promise.resolve());
214
+ }, CLI_UPDATE_MS);
212
215
  }
213
216
  cli(kind) {
214
217
  this.starts += 1;
@@ -8,7 +8,7 @@ proxyUnlessRelayed();
8
8
  try {
9
9
  const { house, credential } = (await readEnrolment());
10
10
  try {
11
- await post(house, '/kit/agents/desired', {}, credential);
11
+ await post(house, '/kit/agents/desired/list', {}, credential);
12
12
  }
13
13
  catch (error) {
14
14
  if (!unanswered(error))
package/dist/bridge.js CHANGED
@@ -81,7 +81,7 @@ function editAnswer(forwarded) {
81
81
  export async function openBridge(house, copies, conversationId, signal) {
82
82
  const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
83
83
  const origin = (await readEnrolment()).house;
84
- const { credential } = await retrying(() => house.post(`/kit/conversations/${conversationId}/credential`, {}, signal), signal);
84
+ const { credential } = await retrying(() => house.post('/kit/conversations/credentials/issue', { conversation: conversationId }, signal), signal);
85
85
  const closed = new AbortController();
86
86
  const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
87
87
  const send = async (message, operation) => {
@@ -105,7 +105,7 @@ export async function openBridge(house, copies, conversationId, signal) {
105
105
  const bytes = Buffer.from(JSON.stringify({ changes }));
106
106
  const sha256 = createHash('sha256').update(bytes).digest('hex');
107
107
  const prepared = answered(await send(call('run_command', {
108
- command: 'prepare_edit_upload',
108
+ command: 'files/batch-upload',
109
109
  arguments: { paths: changedPaths(changes), bytes: bytes.length, sha256 },
110
110
  }), operation));
111
111
  if ('refused' in prepared)
@@ -141,7 +141,7 @@ export async function openBridge(house, copies, conversationId, signal) {
141
141
  const caller = {
142
142
  key: `conversation:${conversationId}`,
143
143
  submit: async (operation, changes, held, retain) => {
144
- const inline = call('edit', { changes });
144
+ const inline = call('files_batch', { changes });
145
145
  let upload = held;
146
146
  if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
147
147
  const prepared = await staged(operation, changes);
@@ -150,7 +150,7 @@ export async function openBridge(house, copies, conversationId, signal) {
150
150
  upload = prepared;
151
151
  await retain(upload);
152
152
  }
153
- return editAnswer(await send(upload === undefined ? inline : call('edit', { paths: changedPaths(changes), upload }), operation));
153
+ return editAnswer(await send(upload === undefined ? inline : call('files_batch', { paths: changedPaths(changes), upload }), operation));
154
154
  },
155
155
  };
156
156
  const local = async (path, text) => {
package/dist/calls.js CHANGED
@@ -42,7 +42,7 @@ export class Calls {
42
42
  return carried
43
43
  .then(async ({ result, returned, release }) => {
44
44
  try {
45
- await this.house.deliver(`/kit/inputs/${callId}/ack`, result);
45
+ await this.house.deliver('/kit/kit-calls/results/return', { call: callId, ...result });
46
46
  }
47
47
  finally {
48
48
  this.returned.add(callId);
package/dist/chunks.js ADDED
@@ -0,0 +1,49 @@
1
+ import { readFile, rm } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { downloaded, fetched } from './files.js';
4
+ const DOWNLOADS_AT_ONCE = 6;
5
+ // A chunk is about one megabyte, so a download still unfinished after two minutes holds every Room behind it on a dead connection.
6
+ const CHUNK_DOWNLOAD_MS = 120_000;
7
+ class AddressExpired extends Error {
8
+ constructor() {
9
+ super("House's store refused every chunk it asked for");
10
+ }
11
+ }
12
+ function once(chunk) {
13
+ let asked = false;
14
+ return async () => {
15
+ if (asked)
16
+ throw new AddressExpired();
17
+ asked = true;
18
+ return { download: chunk.download, sha256: chunk.hash };
19
+ };
20
+ }
21
+ export async function stagedChunks(directory, chunks) {
22
+ let next = 0;
23
+ let failure;
24
+ const downloading = async () => {
25
+ while (next < chunks.length && failure === undefined) {
26
+ const chunk = chunks[next++];
27
+ const reading = (url) => fetched(url, AbortSignal.timeout(CHUNK_DOWNLOAD_MS));
28
+ await downloaded(once(chunk), reading, join(directory, chunk.hash), 'A Room chunk').catch((error) => {
29
+ failure ??= error;
30
+ });
31
+ }
32
+ };
33
+ await Promise.all(Array.from({ length: DOWNLOADS_AT_ONCE }, downloading));
34
+ return failure;
35
+ }
36
+ export async function* chunkTexts(directory, chunks, models) {
37
+ yield* models;
38
+ for (const { hash } of chunks) {
39
+ const file = join(directory, hash);
40
+ for (const line of (await readFile(file, 'utf8')).split('\n')) {
41
+ if (line === '')
42
+ continue;
43
+ const entry = JSON.parse(line);
44
+ if (entry.content !== undefined)
45
+ yield entry;
46
+ }
47
+ await rm(file);
48
+ }
49
+ }
package/dist/clis.js CHANGED
@@ -20,6 +20,7 @@ const RAW_SUBTYPES = [
20
20
  'hook_started',
21
21
  'hook_response',
22
22
  ];
23
+ const RAW_TYPES = ['result', 'user', 'assistant', 'rate_limit_event', 'prompt_suggestion'];
23
24
  async function executable(path) {
24
25
  try {
25
26
  await access(path, constants.X_OK);
@@ -62,6 +63,14 @@ export async function allowHouseInCodex(path) {
62
63
  await rename(temporary, file);
63
64
  }
64
65
  async function nothing() { }
66
+ function claudeQuestionFields(request) {
67
+ const properties = request.requestedSchema?.properties ?? {};
68
+ return Object.keys(properties).filter((name) => properties[name]._meta?.jetbrains?.air?.customAnswer !== undefined);
69
+ }
70
+ function codexQuestionFields(request) {
71
+ const { _meta, requestedSchema } = request;
72
+ return _meta?.codex === undefined ? [] : (requestedSchema?.required ?? []);
73
+ }
65
74
  function answered(error) {
66
75
  return typeof error === 'object' && error !== null ? error : {};
67
76
  }
@@ -71,7 +80,7 @@ function bridgeInClaudeSandbox(bridge) {
71
80
  export const CLIS = {
72
81
  'codex-acp': {
73
82
  bin: 'codex',
74
- minimum: '0.160.1',
83
+ minimum: '0.165.0',
75
84
  install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
76
85
  update: 'codex update',
77
86
  adapter: {
@@ -87,15 +96,15 @@ export const CLIS = {
87
96
  const { code, data } = answered(error);
88
97
  return code === -32603 && typeof data?.details === 'string' && data.details.startsWith('no rollout found');
89
98
  },
90
- renames: true,
91
99
  allowHouse: allowHouseInCodex,
100
+ questionFields: codexQuestionFields,
92
101
  signedIn: { command: ['login', 'status'] },
93
102
  login: { args: ['login', '--device-auth'], code: 'show' },
94
103
  air: ['asyncTasks', 'nativeSubagentSessions'],
95
104
  },
96
105
  'claude-agent-acp': {
97
106
  bin: 'claude',
98
- minimum: '2.1.303',
107
+ minimum: '2.1.316',
99
108
  install: 'curl -fsSL https://claude.ai/install.sh | bash',
100
109
  update: 'claude update',
101
110
  adapter: {
@@ -106,20 +115,19 @@ export const CLIS = {
106
115
  },
107
116
  args: [],
108
117
  fullAccess: 'bypassPermissions',
109
- sessionMeta: (bridge, title) => ({
118
+ sessionMeta: (bridge) => ({
110
119
  claudeCode: {
111
120
  options: {
112
121
  allowedTools: ['Bash(house:*)'],
113
122
  includeHookEvents: true,
114
- title,
115
123
  settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
116
124
  },
117
- emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), { type: 'result' }],
125
+ emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), ...RAW_TYPES.map((type) => ({ type }))],
118
126
  },
119
127
  }),
120
128
  unknownSession: (error) => answered(error).code === -32002,
121
- renames: false,
122
129
  allowHouse: nothing,
130
+ questionFields: claudeQuestionFields,
123
131
  signedIn: { command: ['auth', 'status'] },
124
132
  login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
125
133
  air: ['asyncTasks', 'sessionFailure'],
@@ -134,8 +142,8 @@ export const CLIS = {
134
142
  fullAccess: null,
135
143
  sessionMeta: () => ({}),
136
144
  unknownSession: (error) => answered(error).data?.code === 'FS_NOT_FOUND',
137
- renames: false,
138
145
  allowHouse: nothing,
146
+ questionFields: () => [],
139
147
  signedIn: { initializeMeta: 'defaultAuthMethodId' },
140
148
  login: { args: ['login', '--device-auth'], code: 'show' },
141
149
  air: ['asyncTasks'],
@@ -1,4 +1,5 @@
1
1
  import { subscribe } from 'node:diagnostics_channel';
2
+ import { setTimeout as delay } from 'node:timers/promises';
2
3
  import { HouseRefusal, retryDelay } from './api.js';
3
4
  import { end, REPLACED, signInAgain } from './end.js';
4
5
  import { readEnrolment } from './home.js';
@@ -10,6 +11,8 @@ const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
10
11
  const REFUSAL_HEADER = 'x-house-refusal';
11
12
  // House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
12
13
  export const CONNECTION_SILENCE_MS = 60_000;
14
+ // A stopping Kit waits up to two seconds for House to answer its close, so what it sent last reaches House and a House that does not answer holds no stop.
15
+ const CLOSE_ANSWER_MS = 2_000;
13
16
  function connectionUrl(house) {
14
17
  const url = new URL(PATH, house);
15
18
  url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
@@ -33,9 +36,10 @@ export function holdConnection(handlers) {
33
36
  let connection = null;
34
37
  let socket = null;
35
38
  let failures = 0;
39
+ let stopping = false;
36
40
  const connect = async () => {
37
41
  const { house, credential } = (await readEnrolment());
38
- if (socket !== null || unserved())
42
+ if (socket !== null || unserved() || stopping)
39
43
  return;
40
44
  refused = null;
41
45
  const opening = new WebSocket(relayed(connectionUrl(house)), {
@@ -54,6 +58,8 @@ export function holdConnection(handlers) {
54
58
  connection = null;
55
59
  handlers.closed();
56
60
  process.stderr.write(`kit: connection closed ${event.code} ${event.reason}\n`);
61
+ if (stopping)
62
+ return;
57
63
  if (event.reason === 'replaced')
58
64
  end(REPLACED);
59
65
  if (event.reason === 'credential_rejected' || refused?.status === 401) {
@@ -88,18 +94,27 @@ export function holdConnection(handlers) {
88
94
  if (arrived.type === 'input')
89
95
  handlers.call(arrived);
90
96
  else if (arrived.type !== 'beat')
91
- handlers.notification(arrived);
97
+ handlers.oneWayCall(arrived);
92
98
  };
93
99
  opening.onerror = () => undefined;
94
100
  opening.onclose = closed;
95
101
  };
96
102
  void connect();
97
103
  return {
98
- send(notification) {
104
+ send(oneWayCall) {
99
105
  if (connection === null || connection.readyState !== WebSocket.OPEN)
100
106
  return false;
101
- connection.send(JSON.stringify(notification));
107
+ connection.send(JSON.stringify(oneWayCall));
102
108
  return true;
103
109
  },
110
+ close() {
111
+ stopping = true;
112
+ const open = socket;
113
+ if (open === null)
114
+ return Promise.resolve();
115
+ const answered = new Promise((resolve) => open.addEventListener('close', () => resolve(), { once: true }));
116
+ open.close();
117
+ return Promise.race([answered, delay(CLOSE_ANSWER_MS)]);
118
+ },
104
119
  };
105
120
  }
@@ -0,0 +1,63 @@
1
+ import { applied } from '@agentshouse/session-content';
2
+ function whole(part, parent) {
3
+ return { ...part, parent };
4
+ }
5
+ export class Content {
6
+ parts = [];
7
+ emit;
8
+ keys = new Map();
9
+ writing = new Map();
10
+ planned = null;
11
+ constructor(emit) {
12
+ this.emit = emit;
13
+ }
14
+ index(key) {
15
+ return this.keys.get(key);
16
+ }
17
+ write(type, id, parent, text) {
18
+ if (text === '')
19
+ return;
20
+ const writing = this.writing.get(parent);
21
+ if (writing?.type === type && writing.id === id) {
22
+ this.apply({ op: 'append', index: writing.index, text });
23
+ return;
24
+ }
25
+ const index = this.add(parent, { type, text });
26
+ this.writing.set(parent, { type, id, index });
27
+ }
28
+ put(key, parent, part) {
29
+ const index = this.keys.get(key);
30
+ if (index === undefined) {
31
+ const added = this.add(parent, part);
32
+ this.keys.set(key, added);
33
+ return added;
34
+ }
35
+ const changed = whole(part, this.parts[index].parent);
36
+ if (JSON.stringify(changed) !== JSON.stringify(this.parts[index]))
37
+ this.apply({ op: 'set', index, part: changed });
38
+ return index;
39
+ }
40
+ plan(entries) {
41
+ if (this.planned === null) {
42
+ this.planned = this.add(null, { type: 'plan', entries });
43
+ return;
44
+ }
45
+ this.apply({ op: 'set', index: this.planned, part: { type: 'plan', parent: null, entries } });
46
+ }
47
+ add(parent, part) {
48
+ this.writing.delete(parent);
49
+ return this.arrived(parent, part);
50
+ }
51
+ arrived(parent, part) {
52
+ const index = this.parts.length;
53
+ this.apply({ op: 'start', index, part: whole(part, parent) });
54
+ return index;
55
+ }
56
+ operations() {
57
+ return this.parts.map((part, index) => ({ op: 'start', index, part }));
58
+ }
59
+ apply(operation) {
60
+ this.parts = applied(this.parts, operation);
61
+ this.emit(operation);
62
+ }
63
+ }