@agentshouse/kit 0.2.1-cb997daca91ed → 0.2.1-cba216f2c559c

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/dist/clis.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { constants, readFileSync } from 'node:fs';
4
- import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
4
+ import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
5
5
  import { homedir, userInfo } from 'node:os';
6
6
  import { delimiter, dirname, isAbsolute, join } from 'node:path';
7
- import { downloadServed, servedDigest } from './building.js';
8
- import { kitHome } from './home.js';
7
+ import { releaseDirectory } from './placement.js';
9
8
  import { childEnvironment } from './relay.js';
10
9
  const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
11
10
  function houseRule(houses) {
@@ -16,6 +15,7 @@ const RAW_SUBTYPES = [
16
15
  'task_started',
17
16
  'task_updated',
18
17
  'task_notification',
18
+ 'task_progress',
19
19
  'session_state_changed',
20
20
  'hook_started',
21
21
  'hook_response',
@@ -62,6 +62,14 @@ export async function allowHouseInCodex(path) {
62
62
  await rename(temporary, file);
63
63
  }
64
64
  async function nothing() { }
65
+ function claudeQuestionFields(request) {
66
+ const properties = request.requestedSchema?.properties ?? {};
67
+ return Object.keys(properties).filter((name) => properties[name]._meta?.jetbrains?.air?.customAnswer !== undefined);
68
+ }
69
+ function codexQuestionFields(request) {
70
+ const { _meta, requestedSchema } = request;
71
+ return _meta?.codex === undefined ? [] : (requestedSchema?.required ?? []);
72
+ }
65
73
  function answered(error) {
66
74
  return typeof error === 'object' && error !== null ? error : {};
67
75
  }
@@ -73,6 +81,7 @@ export const CLIS = {
73
81
  bin: 'codex',
74
82
  minimum: '0.160.1',
75
83
  install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
84
+ update: 'codex update',
76
85
  adapter: {
77
86
  package: '@agentclientprotocol/codex-acp',
78
87
  bin: 'codex-acp',
@@ -88,6 +97,7 @@ export const CLIS = {
88
97
  },
89
98
  renames: true,
90
99
  allowHouse: allowHouseInCodex,
100
+ questionFields: codexQuestionFields,
91
101
  signedIn: { command: ['login', 'status'] },
92
102
  login: { args: ['login', '--device-auth'], code: 'show' },
93
103
  air: ['asyncTasks', 'nativeSubagentSessions'],
@@ -96,6 +106,7 @@ export const CLIS = {
96
106
  bin: 'claude',
97
107
  minimum: '2.1.303',
98
108
  install: 'curl -fsSL https://claude.ai/install.sh | bash',
109
+ update: 'claude update',
99
110
  adapter: {
100
111
  package: '@agentclientprotocol/claude-agent-acp',
101
112
  bin: 'claude-agent-acp',
@@ -112,12 +123,13 @@ export const CLIS = {
112
123
  title,
113
124
  settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
114
125
  },
115
- emitRawSDKMessages: RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })),
126
+ emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), { type: 'result' }],
116
127
  },
117
128
  }),
118
129
  unknownSession: (error) => answered(error).code === -32002,
119
130
  renames: false,
120
131
  allowHouse: nothing,
132
+ questionFields: claudeQuestionFields,
121
133
  signedIn: { command: ['auth', 'status'] },
122
134
  login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
123
135
  air: ['asyncTasks', 'sessionFailure'],
@@ -126,6 +138,7 @@ export const CLIS = {
126
138
  bin: 'grok',
127
139
  minimum: '1.0.46',
128
140
  install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
141
+ update: 'grok update',
129
142
  adapter: null,
130
143
  args: ['--sandbox', 'off', 'agent', '--always-approve', '--no-leader', 'stdio'],
131
144
  fullAccess: null,
@@ -133,6 +146,7 @@ export const CLIS = {
133
146
  unknownSession: (error) => answered(error).data?.code === 'FS_NOT_FOUND',
134
147
  renames: false,
135
148
  allowHouse: nothing,
149
+ questionFields: () => [],
136
150
  signedIn: { initializeMeta: 'defaultAuthMethodId' },
137
151
  login: { args: ['login', '--device-auth'], code: 'show' },
138
152
  air: ['asyncTasks'],
@@ -141,25 +155,13 @@ export const CLIS = {
141
155
  const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
142
156
  export const KIT_RELEASE = KIT_PACKAGE.version;
143
157
  const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
144
- // An install still running after fifteen minutes is ended and reported as failed, so a hung download cannot hold its CLI's report.
158
+ // An install or update still running after fifteen minutes is ended as failed, so a hung download can neither hold its CLI's report nor keep the Kit busy.
145
159
  const INSTALL_MS = 15 * 60_000;
146
160
  // A login shell or a version read is ended after half a minute, so a profile that waits for input cannot stall the report.
147
161
  const READ_MS = 30_000;
148
162
  const CAUSE_CHARACTERS = 4000;
149
- function prefix(kind) {
150
- return join(kitHome(), 'agents', kind);
151
- }
152
163
  export function adapterCommand(kind) {
153
- return join(prefix(kind), 'node_modules', '.bin', CLIS[kind].adapter.bin);
154
- }
155
- async function installedAdapter(kind) {
156
- try {
157
- const manifest = join(prefix(kind), 'node_modules', CLIS[kind].adapter.package, 'package.json');
158
- return JSON.parse(await readFile(manifest, 'utf8')).version;
159
- }
160
- catch {
161
- return null;
162
- }
164
+ return join(releaseDirectory(KIT_RELEASE), 'adapters', kind, 'node_modules', '.bin', CLIS[kind].adapter.bin);
163
165
  }
164
166
  export function run(command, args, timeoutMs, detached = false, signal) {
165
167
  return new Promise((resolve) => {
@@ -203,38 +205,15 @@ export function failureOf(ran, program) {
203
205
  export function adapterArchive(kind) {
204
206
  return `${kind}-${KIT_PACKAGE.peerDependencies[CLIS[kind].adapter.package]}.tar.gz`;
205
207
  }
206
- export async function installAdapter(kind, signal) {
207
- const adapter = CLIS[kind].adapter;
208
- if (adapter === null)
209
- return null;
210
- if ((await installedAdapter(kind)) === KIT_PACKAGE.peerDependencies[adapter.package])
211
- return null;
212
- const name = adapterArchive(kind);
213
- const archive = `${prefix(kind)}.tar.gz`;
208
+ async function bounded(program, work, signal) {
214
209
  const deadline = AbortSignal.timeout(INSTALL_MS);
215
- const bounded = signal === undefined ? deadline : AbortSignal.any([signal, deadline]);
216
- try {
217
- const sha256 = await servedDigest(name, bounded);
218
- if (sha256 === null)
219
- return `House serves no ${name}`;
220
- await rm(prefix(kind), { recursive: true, force: true });
221
- await mkdir(prefix(kind), { recursive: true });
222
- await downloadServed(name, sha256, archive, bounded);
223
- const ran = await run('tar', ['-xzf', archive, '-C', prefix(kind)], INSTALL_MS, true, signal);
224
- return ran.status === 0 ? null : failureOf(ran, 'tar');
225
- }
226
- catch (error) {
227
- if (deadline.aborted && signal?.aborted !== true)
228
- return `${name} did not arrive within ${INSTALL_MS / 1000} seconds`;
229
- return error instanceof Error ? error.message : String(error);
230
- }
231
- finally {
232
- await rm(archive, { force: true });
233
- }
210
+ const ran = await work(signal === undefined ? deadline : AbortSignal.any([signal, deadline]));
211
+ if (deadline.aborted && signal?.aborted !== true)
212
+ return `${program} did not end within ${INSTALL_MS / 1000} seconds`;
213
+ return ran.status === 0 ? null : failureOf(ran, program);
234
214
  }
235
- export async function installCli(kind, signal) {
236
- const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, signal);
237
- return ran.status === 0 ? null : failureOf(ran, 'the install');
215
+ export function installCli(kind, signal) {
216
+ return bounded('the install', (within) => run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, within), signal);
238
217
  }
239
218
  function loginShell() {
240
219
  return process.env.SHELL || userInfo().shell;
@@ -242,8 +221,8 @@ function loginShell() {
242
221
  const FOUND = 'house-kit-cli ';
243
222
  const LOOKUP = `found=$(command -v "$1") || exit 0; case $found in /*) ;; *) found=$(pwd -P)/$found ;; esac; printf "${FOUND}%s\\n" "$found"`;
244
223
  const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$HOME/.local/bin" ;; esac; export PATH';
245
- function inLoginShell(script, argument = '', signal) {
246
- return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true, signal);
224
+ function inLoginShell(script, argument = '', signal, timeoutMs = READ_MS) {
225
+ return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], timeoutMs, true, signal);
247
226
  }
248
227
  export async function onLoginPath(program, signal) {
249
228
  const ran = await inLoginShell(LOOKUP, program, signal);
@@ -252,6 +231,9 @@ export async function onLoginPath(program, signal) {
252
231
  export function locate(kind, signal) {
253
232
  return onLoginPath(CLIS[kind].bin, signal);
254
233
  }
234
+ export function updateCli(kind) {
235
+ return bounded('the update', (within) => inLoginShell(CLIS[kind].update, '', within, INSTALL_MS));
236
+ }
255
237
  export async function loginPath() {
256
238
  const marker = 'house-kit-path ';
257
239
  const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
@@ -3,40 +3,13 @@ import { HouseRefusal, retryDelay } from './api.js';
3
3
  import { end, REPLACED, signInAgain } from './end.js';
4
4
  import { readEnrolment } from './home.js';
5
5
  import { relayed } from './relay.js';
6
- import { endUnserved, KIT_WIRE } from './wire.js';
6
+ import { Silence } from './silence.js';
7
+ import { endUnserved, KIT_WIRE, unserved } from './wire.js';
7
8
  const PATH = '/kit/stream';
8
9
  const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
9
10
  const REFUSAL_HEADER = 'x-house-refusal';
10
11
  // House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
11
12
  export const CONNECTION_SILENCE_MS = 60_000;
12
- const SYSTEM_CONNECTION_CLOCK = {
13
- later: (delay, callback) => setTimeout(callback, delay),
14
- clear: (timer) => clearTimeout(timer),
15
- };
16
- export class ConnectionSilence {
17
- timer = null;
18
- silent;
19
- clock;
20
- interval;
21
- constructor(silent, clock = SYSTEM_CONNECTION_CLOCK, interval = CONNECTION_SILENCE_MS) {
22
- this.silent = silent;
23
- this.clock = clock;
24
- this.interval = interval;
25
- }
26
- heard() {
27
- this.stop();
28
- this.timer = this.clock.later(this.interval, () => {
29
- this.timer = null;
30
- this.silent();
31
- });
32
- }
33
- stop() {
34
- if (this.timer === null)
35
- return;
36
- this.clock.clear(this.timer);
37
- this.timer = null;
38
- }
39
- }
40
13
  function connectionUrl(house) {
41
14
  const url = new URL(PATH, house);
42
15
  url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
@@ -59,11 +32,10 @@ subscribe('undici:request:headers', (message) => {
59
32
  export function holdConnection(handlers) {
60
33
  let connection = null;
61
34
  let socket = null;
62
- let paused = false;
63
35
  let failures = 0;
64
36
  const connect = async () => {
65
37
  const { house, credential } = (await readEnrolment());
66
- if (paused || socket !== null)
38
+ if (socket !== null || unserved())
67
39
  return;
68
40
  refused = null;
69
41
  const opening = new WebSocket(relayed(connectionUrl(house)), {
@@ -92,8 +64,6 @@ export function holdConnection(handlers) {
92
64
  endUnserved(refused.text);
93
65
  if (!opened && refused !== null)
94
66
  process.stderr.write(`kit: ${refused.message}\n`);
95
- if (paused)
96
- return;
97
67
  // A closed connection reopens in one to three seconds, spread so Kit processes one restart closed return apart; an opening House refused or left unanswered backs off on the jittered curve, retryable or not, since a resident outlives a House deploy.
98
68
  setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
99
69
  };
@@ -101,7 +71,7 @@ export function holdConnection(handlers) {
101
71
  opened = true;
102
72
  failures = 0;
103
73
  connection = opening;
104
- silence = new ConnectionSilence(() => {
74
+ silence = new Silence(CONNECTION_SILENCE_MS, () => {
105
75
  if (connection !== opening)
106
76
  return;
107
77
  connection = null;
@@ -118,26 +88,18 @@ export function holdConnection(handlers) {
118
88
  if (arrived.type === 'input')
119
89
  handlers.call(arrived);
120
90
  else if (arrived.type !== 'beat')
121
- handlers.notification(arrived);
91
+ handlers.oneWayCall(arrived);
122
92
  };
123
93
  opening.onerror = () => undefined;
124
94
  opening.onclose = closed;
125
95
  };
126
96
  void connect();
127
97
  return {
128
- send(notification) {
98
+ send(oneWayCall) {
129
99
  if (connection === null || connection.readyState !== WebSocket.OPEN)
130
100
  return false;
131
- connection.send(JSON.stringify(notification));
101
+ connection.send(JSON.stringify(oneWayCall));
132
102
  return true;
133
103
  },
134
- pause() {
135
- paused = true;
136
- socket?.close();
137
- return () => {
138
- paused = false;
139
- void connect();
140
- };
141
- },
142
104
  };
143
105
  }