@agentshouse/kit 0.2.1-c3e4a20bb3183 → 0.2.1-c4ea88ba9424e

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
@@ -6,17 +6,17 @@ through the agent CLIs you chose and gives each Agent the `house` command.
6
6
 
7
7
  ## Install
8
8
 
9
- Connect a computer from agents.house. It gives you the one command that
10
- installs House Kit on that computer and updates it when you run it again. On
11
- macOS and Linux it installs House Kit natively under your own account, without
12
- an admin password, as a service that runs while you are logged in. `kit` and
13
- `house` are then on your login shell's `PATH`, and your workspace is
14
- `~/AgentsHouse` unless you pass `--workspace <path>`.
9
+ Run `curl -fsSL agents.house/kit | sh`, or `irm agents.house/kit.ps1 | iex` on
10
+ Windows, and again to update; options follow `sh -s --`. On macOS and Linux it
11
+ installs House Kit natively under your own account, without an admin password,
12
+ as a service that runs while you are logged in. `kit` and `house` are then on
13
+ your login shell's `PATH`, and your workspace is `~/AgentsHouse` unless you
14
+ pass `--workspace <path>`.
15
15
 
16
16
  Add `--container` to run House Kit in one Docker container instead, with your
17
17
  workspace mounted at `/agents/house`; your Agents then reach only that
18
18
  workspace. On Windows 11 the container is the one choice. Append a `kit` or
19
- `house` command to the container's command to run it in that container.
19
+ `house` command to the container's options to run it in that container.
20
20
  Running the command for the other choice on a connected computer asks you to
21
21
  confirm, then replaces its Environment, whose Agents end, with a new one.
22
22
 
@@ -24,14 +24,12 @@ On your own Ubuntu 26.04 server, run the Linux command with `--linux` to
24
24
  install House Kit natively, with its workspace at `/agents/house`; `kit` and
25
25
  `house` are then on the server's `PATH`.
26
26
 
27
- House Kit runs the agent CLIs your login shell finds and installs a missing
28
- one through that CLI's own installer. Running the command again offers to
29
- update each CLI older than House Kit needs; add `--update-clis` to update every
30
- one to its latest release without asking.
31
-
32
- House Kit also gives every Agent on the Environment a set of agent skills. Add
33
- `--no-skills` to the command to leave them out; running it again without the
34
- flag brings them back.
27
+ House Kit runs the agent CLIs your login shell finds and installs a missing one
28
+ through that CLI's own installer. Running the command again offers to update
29
+ each CLI older than House Kit needs; add `--update-clis` to update every one to
30
+ its latest release without asking. House Kit also gives every Agent on the
31
+ Environment a set of agent skills. Add `--no-skills` to the command to leave
32
+ them out; running it again without the flag brings them back.
35
33
 
36
34
  ## Commands
37
35
 
@@ -39,21 +37,22 @@ flag brings them back.
39
37
  Environment's credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is
40
38
  set. Pass `--manual` to paste the code by hand on a machine without a browser,
41
39
  and `--environment <id>` to reconnect an Environment you already have. It also
42
- connects your own agent: `house <tool>` run outside an Agent conversation calls
43
- House as you, until you revoke that connection on Connections.
40
+ 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
+ until you revoke that connection on Connections. `house help` lists the Tools.
43
+ `kit logout` disconnects this computer, stops House Kit and ends that Git
44
+ access; a later `kit login` reconnects the same Environment.
44
45
 
45
46
  `kit resident` keeps the Environment connected, and keeps the Rooms you chose
46
47
  for this Environment as Git repositories under `local-copies` in the
47
- workspace. Commit in one and run `house git push --owner` there to send the
48
+ workspace. Commit in one and run `house push --owner` there to send the
48
49
  commit to House; in the container, run it through the install command from the
49
- copy's directory. Inside an Agent conversation the Agent runs `house git push`.
50
+ copy's directory. Inside an Agent conversation the Agent runs `house push`.
50
51
 
51
52
  House Kit turns each audio file of your message to an Agent into text on this
52
- computer before the Agent reads the message. The first audio file downloads the
53
- speech engine and model, about 425 MB, into `~/.house-kit`.
53
+ computer before the Agent reads it. While transcription is on, the speech
54
+ engine and model use about 425 MB in `~/.house-kit`; turning it off deletes them.
54
55
 
55
56
  ## License
56
57
 
57
- MIT
58
-
59
- The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
58
+ MIT. The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
package/dist/acp.js CHANGED
@@ -5,7 +5,7 @@ import { Readable, Writable } from 'node:stream';
5
5
  import { CLIS, KIT_VERSION, adapterCommand, withoutProxy } from './clis.js';
6
6
  export const TURN_STARTED = 'kit/turn_started';
7
7
  export const TURN_ENDED = 'kit/turn_ended';
8
- export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined, added = {}) {
8
+ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined, added = {}, signal) {
9
9
  const adapter = CLIS[kind].adapter;
10
10
  const child = spawn(adapter === null ? cli : adapterCommand(kind), CLIS[kind].args, {
11
11
  cwd,
@@ -13,6 +13,9 @@ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined,
13
13
  stdio: ['pipe', 'pipe', 'pipe'],
14
14
  detached: true,
15
15
  });
16
+ const stop = () => killTree(child);
17
+ signal?.addEventListener('abort', stop, { once: true });
18
+ child.on('exit', () => signal?.removeEventListener('abort', stop));
16
19
  let stderr = '';
17
20
  child.stderr.on('data', (chunk) => {
18
21
  stderr = (stderr + chunk.toString('utf8')).slice(-4000);
package/dist/agents.js CHANGED
@@ -3,13 +3,17 @@ import { readFile, realpath } from 'node:fs/promises';
3
3
  import { killTree, startAdapter } from './acp.js';
4
4
  import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
5
5
  import { agentBase, kitHome } from './home.js';
6
- const SIGNED_OUT = { signed_in: false, models: [] };
6
+ import { holdTranscription, transcriptionReport } from './transcription.js';
7
+ const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
7
8
  function select(options, category) {
8
9
  const option = options.find((candidate) => candidate.category === category);
9
10
  return option?.type === 'select' ? option : undefined;
10
11
  }
12
+ function choices(options) {
13
+ return options.flatMap((entry) => ('group' in entry ? entry.options : [entry]));
14
+ }
11
15
  function values(options) {
12
- return options.flatMap((entry) => ('group' in entry ? entry.options : [entry])).map((entry) => entry.value);
16
+ return choices(options).map((entry) => entry.value);
13
17
  }
14
18
  function causeOf(error) {
15
19
  return error instanceof Error ? error.message : String(error);
@@ -21,9 +25,11 @@ async function models(kind, adapter, known) {
21
25
  const agent = adapter.connection.agent;
22
26
  const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
23
27
  let options = opened.configOptions ?? [];
28
+ const mode = select(options, 'mode');
29
+ const modes = mode === undefined ? [] : choices(mode.options).map(({ value, name }) => ({ mode: value, name }));
24
30
  const model = select(options, 'model');
25
31
  if (model === undefined)
26
- return [];
32
+ return { models: [], modes };
27
33
  const offered = [];
28
34
  for (const value of values(model.options)) {
29
35
  if (select(options, 'model')?.currentValue !== value) {
@@ -39,25 +45,46 @@ async function models(kind, adapter, known) {
39
45
  const effort = select(options, 'thought_level');
40
46
  offered.push({ model: value, efforts: effort === undefined ? [] : values(effort.options) });
41
47
  }
42
- return offered;
48
+ return { models: offered, modes };
43
49
  }
44
- async function offer(kind, cli, known) {
50
+ async function signedIn(kind, cli, known, signal) {
45
51
  const probe = CLIS[kind].signedIn;
46
- if ('command' in probe && (await run(cli, probe.command, 30_000)).status !== 0)
52
+ // A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
53
+ if ('command' in probe)
54
+ return (await run(cli, probe.command, 30_000, false, signal)).status === 0;
55
+ return (await offer(kind, cli, known, signal)).signed_in;
56
+ }
57
+ function ended(signal) {
58
+ return new Promise((_, reject) => {
59
+ if (signal.aborted)
60
+ reject(signal.reason);
61
+ signal.addEventListener('abort', () => reject(signal.reason), { once: true });
62
+ });
63
+ }
64
+ async function offer(kind, cli, known, signal) {
65
+ const probe = CLIS[kind].signedIn;
66
+ // A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
67
+ if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
47
68
  return SIGNED_OUT;
48
69
  let adapter;
49
70
  try {
50
- adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }));
71
+ adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
72
+ signal?.throwIfAborted();
51
73
  if ('initializeMeta' in probe) {
52
74
  const method = adapter.initialized._meta?.[probe.initializeMeta];
53
75
  if (typeof method !== 'string' || method.length === 0)
54
76
  return SIGNED_OUT;
55
77
  }
56
- return { signed_in: true, models: await models(kind, adapter, known.models) };
78
+ return { signed_in: true, ...(await models(kind, adapter, known.models)) };
57
79
  }
58
80
  catch (error) {
59
- process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
60
- return { signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true, models: known.models };
81
+ if (!signal?.aborted)
82
+ process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
83
+ return {
84
+ signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
85
+ models: known.models,
86
+ modes: known.modes,
87
+ };
61
88
  }
62
89
  finally {
63
90
  if (adapter !== undefined)
@@ -72,6 +99,8 @@ function reported(kind, reading) {
72
99
  failure: reading.failure,
73
100
  signed_in: reading.signed_in,
74
101
  models: reading.models,
102
+ modes: reading.modes,
103
+ full_access: CLIS[kind].fullAccess,
75
104
  };
76
105
  }
77
106
  function tooOld(kind, release) {
@@ -79,17 +108,19 @@ function tooOld(kind, release) {
79
108
  return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
80
109
  }
81
110
  async function sshHostKey() {
111
+ // Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
82
112
  const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
83
113
  return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
84
114
  }
85
115
  async function operatingSystem() {
116
+ // sw_vers answers at once, so ten seconds only bounds a stuck call.
86
117
  if (process.platform === 'darwin')
87
118
  return `macOS ${(await run('sw_vers', ['-productVersion'], 10_000)).output.trim()}`;
88
119
  const release = await readFile('/etc/os-release', 'utf8');
89
120
  return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
90
121
  }
91
122
  export class Agents {
92
- desired = { agents: [], routes: [] };
123
+ desired = { agents: [], routes: [], transcribe: false };
93
124
  house;
94
125
  reading = Promise.resolve();
95
126
  queues = new Map();
@@ -113,8 +144,11 @@ export class Agents {
113
144
  return this.desired;
114
145
  });
115
146
  this.reading = reading;
116
- return reading.then(({ agents }) => {
117
- Promise.all(agents.map((kind) => this.queue(kind, () => this.load(kind))))
147
+ return reading.then(({ agents, transcribe }) => {
148
+ holdTranscription(transcribe)
149
+ .then((changed) => (changed ? this.report() : undefined))
150
+ .catch(logged);
151
+ Promise.all(agents.map((kind) => this.load(kind)))
118
152
  .then(() => this.report())
119
153
  .catch(logged);
120
154
  });
@@ -130,7 +164,7 @@ export class Agents {
130
164
  const known = this.readings.get(kind);
131
165
  const kept = known?.release === null || known?.minimum !== undefined ? SIGNED_OUT : (known ?? SIGNED_OUT);
132
166
  if (known?.release !== release || known.minimum !== undefined) {
133
- this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models });
167
+ this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
134
168
  }
135
169
  const read = this.nextRead(kind);
136
170
  offer(kind, cli, kept)
@@ -143,16 +177,19 @@ export class Agents {
143
177
  return cli;
144
178
  });
145
179
  }
146
- located(kind) {
147
- return this.queue(kind, () => this.ensure(kind));
180
+ located(kind, signal) {
181
+ return this.queue(kind, () => this.ensure(kind, signal), signal);
148
182
  }
149
183
  async reread(kind) {
150
- await this.queue(kind, async () => {
151
- this.nextRead(kind);
152
- this.readings.set(kind, await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT));
153
- });
184
+ await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT, offer);
154
185
  await this.report();
155
186
  }
187
+ async recheck(kind, signal) {
188
+ const known = this.readings.get(kind) ?? SIGNED_OUT;
189
+ await this.examine(kind, known, async (kind, cli) => ((await signedIn(kind, cli, known, signal)) ? { ...known, signed_in: true } : SIGNED_OUT), signal);
190
+ if (!signal.aborted)
191
+ await this.report();
192
+ }
156
193
  report() {
157
194
  const sending = this.sending.catch(() => undefined).then(() => this.send());
158
195
  this.sending = sending;
@@ -167,39 +204,42 @@ export class Agents {
167
204
  this.readings.set(kind, reading);
168
205
  this.report().catch(logged);
169
206
  }
170
- queue(kind, work) {
171
- const queued = (this.queues.get(kind) ?? Promise.resolve()).then(work);
207
+ queue(kind, work, signal) {
208
+ const queued = (this.queues.get(kind) ?? Promise.resolve()).then(() => {
209
+ signal?.throwIfAborted();
210
+ return work();
211
+ });
172
212
  this.queues.set(kind, queued.catch(() => undefined));
173
- return queued;
213
+ return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
174
214
  }
175
- async ensure(kind) {
176
- const failed = await installAdapter(kind);
215
+ async ensure(kind, signal) {
216
+ const failed = await installAdapter(kind, signal);
177
217
  if (failed !== null)
178
218
  throw new Error(failed);
179
- const found = await locate(kind);
219
+ const found = await locate(kind, signal);
180
220
  if (found !== null)
181
221
  return found;
182
- const installing = this.installing.catch(() => undefined).then(() => installCli(kind));
222
+ const installing = this.installing.catch(() => undefined).then(() => installCli(kind, signal));
183
223
  this.installing = installing;
184
224
  const failure = await installing;
185
225
  if (failure !== null)
186
226
  throw new Error(failure);
187
- const installed = await locate(kind);
227
+ const installed = await locate(kind, signal);
188
228
  if (installed === null)
189
229
  throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
190
230
  return installed;
191
231
  }
192
- async resolve(kind) {
232
+ async resolve(kind, signal) {
193
233
  let cli;
194
234
  try {
195
- cli = await realpath(await this.ensure(kind));
235
+ cli = await realpath(await this.ensure(kind, signal));
196
236
  }
197
237
  catch (error) {
198
238
  const failure = causeOf(error);
199
239
  process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
200
240
  return { release: null, failure, ...SIGNED_OUT };
201
241
  }
202
- const release = await versionOf(cli);
242
+ const release = await versionOf(cli, signal);
203
243
  if (release === null)
204
244
  return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
205
245
  const minimum = CLIS[kind].minimum;
@@ -207,18 +247,18 @@ export class Agents {
207
247
  return { release, minimum, failure: null, ...SIGNED_OUT };
208
248
  return { cli, release };
209
249
  }
210
- async examine(kind, known) {
211
- const resolved = await this.resolve(kind);
212
- if (!('cli' in resolved))
213
- return resolved;
214
- return { release: resolved.release, failure: null, ...(await offer(kind, resolved.cli, known)) };
250
+ async examine(kind, known, read, signal) {
251
+ const current = this.nextRead(kind);
252
+ const resolved = await this.queue(kind, () => this.resolve(kind, signal), signal);
253
+ const reading = 'cli' in resolved ? { release: resolved.release, failure: null, ...(await read(kind, resolved.cli, known)) } : resolved;
254
+ if (this.reads.get(kind) === current && !signal?.aborted)
255
+ this.readings.set(kind, reading);
215
256
  }
216
257
  async load(kind) {
217
258
  const known = this.readings.get(kind);
218
259
  if (known !== undefined && known.failure === null)
219
260
  return;
220
- this.nextRead(kind);
221
- this.readings.set(kind, await this.examine(kind, SIGNED_OUT));
261
+ await this.examine(kind, SIGNED_OUT, offer);
222
262
  }
223
263
  async send() {
224
264
  const agents = this.desired.agents.flatMap((kind) => {
@@ -231,6 +271,7 @@ export class Agents {
231
271
  kit_version: KIT_VERSION,
232
272
  agent_base: agentBase(),
233
273
  agents,
274
+ transcription: transcriptionReport(),
234
275
  ...(hostKey === null ? {} : { ssh_host_key: hostKey }),
235
276
  };
236
277
  const state = JSON.stringify(body);
package/dist/api.js CHANGED
@@ -1,4 +1,8 @@
1
+ import { setTimeout as delay } from 'node:timers/promises';
2
+ import { end, SIGN_IN_AGAIN } from './end.js';
1
3
  import { readEnrolment } from './home.js';
4
+ import { retryable } from './refusals.js';
5
+ import { relayed } from './relay.js';
2
6
  export class HouseRefusal extends Error {
3
7
  status;
4
8
  text;
@@ -8,11 +12,28 @@ export class HouseRefusal extends Error {
8
12
  this.text = text;
9
13
  }
10
14
  }
15
+ export function finalRefusal(error) {
16
+ return error instanceof HouseRefusal && retryable(error.text) === false;
17
+ }
11
18
  export function retryDelay(attempt) {
19
+ // Full jitter, doubling from one second to a 30-second cap, spreads the Kits one outage dropped and retries within half a minute of House's return.
12
20
  return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
13
21
  }
22
+ export async function retrying(sent, signal) {
23
+ for (let attempt = 0;; attempt++) {
24
+ try {
25
+ return await sent();
26
+ }
27
+ catch (error) {
28
+ if (!(error instanceof HouseRefusal) || retryable(error.text) !== true)
29
+ throw error;
30
+ }
31
+ // A request House refused as retryable is sent again on the jittered curve.
32
+ await delay(retryDelay(attempt), undefined, { signal });
33
+ }
34
+ }
14
35
  export async function post(house, path, body, credential, signal) {
15
- const answer = await fetch(new URL(path, house), {
36
+ const answer = await fetch(relayed(new URL(path, house)), {
16
37
  method: 'POST',
17
38
  headers: {
18
39
  'content-type': 'application/json',
@@ -28,7 +49,14 @@ export async function post(house, path, body, credential, signal) {
28
49
  }
29
50
  async function enrolledPost(path, body, signal) {
30
51
  const { house, credential } = (await readEnrolment());
31
- return post(house, path, body, credential, signal);
52
+ try {
53
+ return await post(house, path, body, credential, signal);
54
+ }
55
+ catch (error) {
56
+ if (error instanceof HouseRefusal && error.status === 401)
57
+ end(SIGN_IN_AGAIN);
58
+ throw error;
59
+ }
32
60
  }
33
61
  export const house = {
34
62
  post: enrolledPost,
@@ -38,9 +66,10 @@ export const house = {
38
66
  return await enrolledPost(path, body);
39
67
  }
40
68
  catch (error) {
41
- if (error instanceof HouseRefusal && error.status < 500)
69
+ if (finalRefusal(error))
42
70
  throw error;
43
71
  process.stderr.write(`kit: ${path} did not reach House: ${error.message}\n`);
72
+ // A delivery House did not take is sent again on the jittered curve for as long as it is still current.
44
73
  await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
45
74
  if (!current())
46
75
  throw error;
@@ -0,0 +1,64 @@
1
+ import { extname, resolve } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { run } from './git.js';
4
+ import { kitHome, readOwnAgent } from './home.js';
5
+ import { quoted } from './shell.js';
6
+ function section(house) {
7
+ return `credential.${new URL('/app/', house).href}`;
8
+ }
9
+ function helper() {
10
+ const main = fileURLToPath(new URL(`./kit-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
11
+ return `!HOUSE_KIT_HOME=${quoted(resolve(kitHome()))} ${quoted(process.execPath)} ${quoted(main)} git-credential`;
12
+ }
13
+ async function configured(args) {
14
+ try {
15
+ return await run(kitHome(), ['config', '--global', ...args]);
16
+ }
17
+ catch (error) {
18
+ if (error.code === 'ENOENT')
19
+ return null;
20
+ throw error;
21
+ }
22
+ }
23
+ async function forget(house) {
24
+ await configured(['--remove-section', section(house)]);
25
+ }
26
+ async function register(house) {
27
+ await forget(house);
28
+ for (const value of ['', helper()]) {
29
+ const ran = await configured(['--add', `${section(house)}.helper`, value]);
30
+ if (ran === null)
31
+ return;
32
+ if (ran.status !== 0)
33
+ throw new Error(`git config failed: ${ran.stderr.trim()}`);
34
+ }
35
+ }
36
+ export async function placeAppGit(before, after) {
37
+ if (before !== null && before.house !== after?.house)
38
+ await forget(before.house);
39
+ if (after !== null)
40
+ await register(after.house);
41
+ }
42
+ export async function forgetAppGit() {
43
+ const ownAgent = await readOwnAgent();
44
+ if (ownAgent !== null)
45
+ await forget(ownAgent.house);
46
+ }
47
+ export async function answerGitCredential(operation) {
48
+ let asked = '';
49
+ for await (const chunk of process.stdin)
50
+ asked += String(chunk);
51
+ if (operation !== 'get')
52
+ return;
53
+ const attributes = new Map(asked
54
+ .split('\n')
55
+ .filter((line) => line.includes('='))
56
+ .map((line) => [line.slice(0, line.indexOf('=')), line.slice(line.indexOf('=') + 1)]));
57
+ const ownAgent = await readOwnAgent();
58
+ if (ownAgent === null)
59
+ return;
60
+ const house = new URL(ownAgent.house);
61
+ if (attributes.get('protocol') !== house.protocol.slice(0, -1) || attributes.get('host') !== house.host)
62
+ return;
63
+ process.stdout.write(`username=house\npassword=${ownAgent.credential}\n`);
64
+ }
@@ -1,30 +1,23 @@
1
1
  {
2
- "schemaVersion": 1,
3
- "version": "0.2.1-c3e4a20bb3183",
2
+ "schemaVersion": 2,
3
+ "version": "0.2.1-c4ea88ba9424e",
4
4
  "hosts": {
5
+ "macos": {
6
+ "asset": {
7
+ "name": "connect-linux.sh",
8
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c4ea88ba9424e/connect-linux.sh"
9
+ }
10
+ },
5
11
  "linux": {
6
- "command": "bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.2.1-c3e4a20bb3183/connect-linux.sh)",
7
12
  "asset": {
8
13
  "name": "connect-linux.sh",
9
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c3e4a20bb3183/connect-linux.sh"
10
- },
11
- "workspace": {
12
- "argument": "--workspace",
13
- "quoting": "posix"
14
- },
15
- "container": {
16
- "argument": "--container"
14
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c4ea88ba9424e/connect-linux.sh"
17
15
  }
18
16
  },
19
17
  "windows": {
20
- "command": "& ([scriptblock]::Create((irm https://github.com/agentshouse/kit/releases/download/v0.2.1-c3e4a20bb3183/connect-windows.ps1)))",
21
18
  "asset": {
22
19
  "name": "connect-windows.ps1",
23
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c3e4a20bb3183/connect-windows.ps1"
24
- },
25
- "workspace": {
26
- "argument": "--workspace",
27
- "quoting": "powershell"
20
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c4ea88ba9424e/connect-windows.ps1"
28
21
  }
29
22
  }
30
23
  }
package/dist/bridge.js CHANGED
@@ -6,13 +6,14 @@ import { createServer, request as httpRequest } from 'node:http';
6
6
  import { request as httpsRequest } from 'node:https';
7
7
  import { delimiter, dirname, join } from 'node:path';
8
8
  import { parse } from 'yaml';
9
- import { HouseRefusal, retryDelay } from './api.js';
9
+ import { finalRefusal, HouseRefusal, retryDelay, retrying } from './api.js';
10
10
  import { loginPath } from './clis.js';
11
11
  import { changedPaths, } from './copies.js';
12
12
  import { kitHome, readEnrolment } from './home.js';
13
13
  import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
14
14
  import { operationId, uuidOf } from './operation.js';
15
- import { refusalOf } from './refusals.js';
15
+ import { refusalOf, retryable } from './refusals.js';
16
+ import { relayed } from './relay.js';
16
17
  const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
17
18
  const ATTACHMENTS = '/kit/attachments/upload';
18
19
  export async function received(request) {
@@ -22,7 +23,8 @@ export async function received(request) {
22
23
  text += chunk;
23
24
  return text;
24
25
  }
25
- function relay(request, response, target, authorization) {
26
+ function relay(request, response, house, authorization) {
27
+ const target = relayed(house);
26
28
  const send = target.protocol === 'https:' ? httpsRequest : httpRequest;
27
29
  const forwarded = send(target, {
28
30
  method: request.method,
@@ -38,8 +40,6 @@ function refusalIn(text, status) {
38
40
  return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [] };
39
41
  }
40
42
  function answered(forwarded) {
41
- if (forwarded.status >= 500)
42
- throw new HouseRefusal('/', forwarded.status, forwarded.text);
43
43
  if (forwarded.status !== 200)
44
44
  return { refused: refusalIn(forwarded.text, forwarded.status) };
45
45
  const answer = JSON.parse(forwarded.text);
@@ -63,8 +63,8 @@ function pendingSeconds(forwarded) {
63
63
  function resendAfter(forwarded, attempt) {
64
64
  if (forwarded === null)
65
65
  return retryDelay(attempt);
66
- if (forwarded.status >= 500)
67
- return refusalOf(forwarded.text) === null ? retryDelay(attempt) : null;
66
+ if (forwarded.status !== 200)
67
+ return retryable(forwarded.text) === false ? null : retryDelay(attempt);
68
68
  const seconds = pendingSeconds(forwarded);
69
69
  return seconds === null ? null : seconds * 1000;
70
70
  }
@@ -103,6 +103,7 @@ export async function openBridge(house, copies, conversationId, signal) {
103
103
  const after = resendAfter(forwarded, attempt);
104
104
  if (after === null)
105
105
  return forwarded;
106
+ // A write House did not settle is sent again on the jittered curve, or after the wait House names for a pending one.
106
107
  await delay(after, undefined, { signal: closed.signal });
107
108
  }
108
109
  };
@@ -117,17 +118,26 @@ export async function openBridge(house, copies, conversationId, signal) {
117
118
  if ('refused' in prepared)
118
119
  return prepared;
119
120
  const { transfer } = parse(prepared.text);
120
- const posted = await fetch(transfer.url, {
121
- method: 'POST',
122
- headers: { 'content-type': 'text/plain; charset=utf-8' },
123
- body: Buffer.concat([Buffer.from(`${transfer.operation}\n`), bytes]),
124
- signal: closed.signal,
125
- });
126
- const text = await posted.text();
127
- if (posted.status >= 500)
128
- throw new HouseRefusal('/', posted.status, text);
129
- if (!posted.ok)
130
- return { refused: refusalIn(text, posted.status) };
121
+ let text;
122
+ try {
123
+ text = await retrying(async () => {
124
+ const posted = await fetch(relayed(transfer.url), {
125
+ method: 'POST',
126
+ headers: { 'content-type': 'text/plain; charset=utf-8' },
127
+ body: Buffer.concat([Buffer.from(`${transfer.operation}\n`), bytes]),
128
+ signal: closed.signal,
129
+ });
130
+ const answer = await posted.text();
131
+ if (!posted.ok)
132
+ throw new HouseRefusal('/', posted.status, answer);
133
+ return answer;
134
+ }, closed.signal);
135
+ }
136
+ catch (error) {
137
+ if (!finalRefusal(error))
138
+ throw error;
139
+ return { refused: refusalIn(error.text, error.status) };
140
+ }
131
141
  const held = JSON.parse(text).transfer;
132
142
  return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
133
143
  };
@@ -150,7 +160,7 @@ export async function openBridge(house, copies, conversationId, signal) {
150
160
  const tool = message.method === 'tools/call' ? String(message.params.name) : null;
151
161
  return send(message, tool !== null && (await writes(tool)) ? operationId() : null);
152
162
  }
153
- const answer = await fetch(new URL(path, origin), {
163
+ const answer = await fetch(relayed(new URL(path, origin)), {
154
164
  method: 'POST',
155
165
  headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}` },
156
166
  body: versioned(conversationId, text),