@agentshouse/kit 0.2.1-c23b83622c698 → 0.2.1-c2c600f2d2b30

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/agents.js CHANGED
@@ -48,12 +48,14 @@ async function models(kind, adapter, known) {
48
48
  }
49
49
  async function signedIn(kind, cli, known) {
50
50
  const probe = CLIS[kind].signedIn;
51
+ // A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
51
52
  if ('command' in probe)
52
53
  return (await run(cli, probe.command, 30_000)).status === 0;
53
54
  return (await offer(kind, cli, known)).signed_in;
54
55
  }
55
56
  async function offer(kind, cli, known) {
56
57
  const probe = CLIS[kind].signedIn;
58
+ // A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
57
59
  if ('command' in probe && (await run(cli, probe.command, 30_000)).status !== 0)
58
60
  return SIGNED_OUT;
59
61
  let adapter;
@@ -96,10 +98,12 @@ function tooOld(kind, release) {
96
98
  return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
97
99
  }
98
100
  async function sshHostKey() {
101
+ // Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
99
102
  const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
100
103
  return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
101
104
  }
102
105
  async function operatingSystem() {
106
+ // sw_vers answers at once, so ten seconds only bounds a stuck call.
103
107
  if (process.platform === 'darwin')
104
108
  return `macOS ${(await run('sw_vers', ['-productVersion'], 10_000)).output.trim()}`;
105
109
  const release = await readFile('/etc/os-release', 'utf8');
package/dist/api.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { end, SIGN_IN_AGAIN } from './end.js';
1
2
  import { readEnrolment } from './home.js';
2
3
  import { relayed } from './relay.js';
3
4
  export class HouseRefusal extends Error {
@@ -10,6 +11,7 @@ export class HouseRefusal extends Error {
10
11
  }
11
12
  }
12
13
  export function retryDelay(attempt) {
14
+ // 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.
13
15
  return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
14
16
  }
15
17
  export async function post(house, path, body, credential, signal) {
@@ -29,7 +31,14 @@ export async function post(house, path, body, credential, signal) {
29
31
  }
30
32
  async function enrolledPost(path, body, signal) {
31
33
  const { house, credential } = (await readEnrolment());
32
- return post(house, path, body, credential, signal);
34
+ try {
35
+ return await post(house, path, body, credential, signal);
36
+ }
37
+ catch (error) {
38
+ if (error instanceof HouseRefusal && error.status === 401)
39
+ end(SIGN_IN_AGAIN);
40
+ throw error;
41
+ }
33
42
  }
34
43
  export const house = {
35
44
  post: enrolledPost,
@@ -42,6 +51,7 @@ export const house = {
42
51
  if (error instanceof HouseRefusal && error.status < 500)
43
52
  throw error;
44
53
  process.stderr.write(`kit: ${path} did not reach House: ${error.message}\n`);
54
+ // A delivery House did not take is sent again on the jittered curve for as long as it is still current.
45
55
  await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
46
56
  if (!current())
47
57
  throw error;
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
- "version": "0.2.1-c23b83622c698",
3
+ "version": "0.2.1-c2c600f2d2b30",
4
4
  "hosts": {
5
5
  "macos": {
6
6
  "asset": {
7
7
  "name": "connect-linux.sh",
8
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c23b83622c698/connect-linux.sh"
8
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c2c600f2d2b30/connect-linux.sh"
9
9
  }
10
10
  },
11
11
  "linux": {
12
12
  "asset": {
13
13
  "name": "connect-linux.sh",
14
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c23b83622c698/connect-linux.sh"
14
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c2c600f2d2b30/connect-linux.sh"
15
15
  }
16
16
  },
17
17
  "windows": {
18
18
  "asset": {
19
19
  "name": "connect-windows.ps1",
20
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c23b83622c698/connect-windows.ps1"
20
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c2c600f2d2b30/connect-windows.ps1"
21
21
  }
22
22
  }
23
23
  }
package/dist/bridge.js CHANGED
@@ -105,6 +105,7 @@ export async function openBridge(house, copies, conversationId, signal) {
105
105
  const after = resendAfter(forwarded, attempt);
106
106
  if (after === null)
107
107
  return forwarded;
108
+ // A write House did not settle is sent again on the jittered curve, or after the wait House names for a pending one.
108
109
  await delay(after, undefined, { signal: closed.signal });
109
110
  }
110
111
  };
package/dist/clis.js CHANGED
@@ -105,7 +105,9 @@ const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.me
105
105
  export const KIT_VERSION = KIT_PACKAGE.version;
106
106
  const PROXY = /^https?_proxy$/i;
107
107
  const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
108
+ // An install still running after fifteen minutes is ended and reported as failed, so a hung download cannot hold its CLI's report.
108
109
  const INSTALL_MS = 15 * 60_000;
110
+ // A login shell or a version read is ended after half a minute, so a profile that waits for input cannot stall the report.
109
111
  const READ_MS = 30_000;
110
112
  const CAUSE_CHARACTERS = 4000;
111
113
  function prefix(kind) {
package/dist/copies.js CHANGED
@@ -11,7 +11,6 @@ import { changed } from './translate.js';
11
11
  import { relayed } from './relay.js';
12
12
  const BRANCH = 'main';
13
13
  const PROVENANCE = '_provenance';
14
- const REPLICA_RETRY_MS = 30_000;
15
14
  const IDENTITY = { GIT_COMMITTER_NAME: 'House Kit', GIT_COMMITTER_EMAIL: 'house-kit@localhost' };
16
15
  function causeOf(error) {
17
16
  return error instanceof Error ? error.message : String(error);
@@ -439,7 +438,6 @@ export class LocalCopies {
439
438
  return this.received(copy);
440
439
  if (code !== 'replica_behind')
441
440
  throw error;
442
- setTimeout(() => this.deliver(copy.key), REPLICA_RETRY_MS).unref();
443
441
  return copy;
444
442
  }
445
443
  const view = answer.authorities.find((entry) => entry.authority === copy.room_ref);
package/dist/end.js ADDED
@@ -0,0 +1,8 @@
1
+ import { killDescendants } from './acp.js';
2
+ export const REPLACED = 'another Kit started for this Environment';
3
+ export const SIGN_IN_AGAIN = 'sign in again';
4
+ export function end(reason) {
5
+ process.stderr.write(`kit: ${reason}\n`);
6
+ killDescendants();
7
+ process.exit(0);
8
+ }
@@ -13,6 +13,7 @@ export async function holdSecretInput(house, subject, steps, waiting) {
13
13
  if (error instanceof HouseRefusal && error.status < 500)
14
14
  return null;
15
15
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
16
+ // A wait that did not reach House is held again on the jittered curve for as long as its asker still waits.
16
17
  await new Promise((resolve) => setTimeout(resolve, retryDelay(failures++)));
17
18
  }
18
19
  }
package/dist/stream.js CHANGED
@@ -1,17 +1,36 @@
1
- import { retryDelay } from './api.js';
1
+ import { subscribe } from 'node:diagnostics_channel';
2
+ import { HouseRefusal, retryDelay } from './api.js';
3
+ import { end, REPLACED, SIGN_IN_AGAIN } from './end.js';
2
4
  import { readEnrolment } from './home.js';
3
5
  import { relayed } from './relay.js';
6
+ const PATH = '/kit/stream';
4
7
  const SUBPROTOCOL = 'house.kit.stream.1';
8
+ const REFUSAL_HEADER = 'x-house-refusal';
5
9
  function streamUrl(house) {
6
- const url = new URL('/kit/stream', house);
10
+ const url = new URL(PATH, house);
7
11
  url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
8
12
  return url;
9
13
  }
14
+ function header(headers, name) {
15
+ for (let index = 0; index < headers.length; index += 2) {
16
+ if (headers[index].toString('latin1').toLowerCase() === name)
17
+ return headers[index + 1].toString('latin1');
18
+ }
19
+ return '';
20
+ }
21
+ let refused = null;
22
+ subscribe('undici:request:headers', (message) => {
23
+ const { request, response } = message;
24
+ if (!request.path.endsWith(PATH))
25
+ return;
26
+ refused = new HouseRefusal(PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
27
+ });
10
28
  export function holdStream(handlers) {
11
29
  let socket = null;
12
30
  let failures = 0;
13
31
  const connect = async () => {
14
32
  const { house, credential } = (await readEnrolment());
33
+ refused = null;
15
34
  const opening = new WebSocket(relayed(streamUrl(house)), {
16
35
  protocols: [SUBPROTOCOL],
17
36
  headers: { authorization: `Bearer ${credential}` },
@@ -31,8 +50,14 @@ export function holdStream(handlers) {
31
50
  if (socket === opening)
32
51
  socket = null;
33
52
  process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
34
- const delay = opened ? 1000 + Math.random() * 2000 : retryDelay(failures++);
35
- setTimeout(() => void connect(), delay);
53
+ if (event.reason === 'replaced')
54
+ end(REPLACED);
55
+ if (event.reason === 'credential_rejected' || refused?.status === 401)
56
+ end(SIGN_IN_AGAIN);
57
+ if (refused !== null && refused.status >= 400 && refused.status < 500)
58
+ end(refused.message);
59
+ // A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; a failed opening backs off on the jittered curve.
60
+ setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
36
61
  };
37
62
  };
38
63
  void connect();
@@ -36,6 +36,7 @@ function installed(artifact) {
36
36
  return join(directory(), artifact.sha256);
37
37
  }
38
38
  async function executed(command, args, signal) {
39
+ // A download or a transcription runs as long as its size needs; the conversation's interrupt or end aborts it instead.
39
40
  const ran = await run(command, args, 0, false, signal);
40
41
  if (ran.status !== 0)
41
42
  throw new Error(failureOf(ran, basename(command)));
@@ -68,6 +69,7 @@ async function install(artifacts, signal) {
68
69
  try {
69
70
  for (const artifact of missing) {
70
71
  const part = `${installed(artifact)}.part`;
72
+ // Three retries carry a large download past a dropped connection before the transcription fails.
71
73
  await executed('curl', ['-fsSL', '--retry', '3', '-o', part, artifact.url], signal);
72
74
  if ((await sha256(part)) !== artifact.sha256)
73
75
  throw new Error(`${artifact.url} does not match its sha256`);
package/dist/update.js CHANGED
@@ -40,9 +40,11 @@ async function finished(inputId) {
40
40
  const ack = await recorded();
41
41
  if (ack !== null)
42
42
  return ack;
43
+ // systemctl answers at once, so ten seconds only bounds a stuck service manager.
43
44
  if ((await run('systemctl', ['is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
44
45
  return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
45
46
  }
47
+ // The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
46
48
  await new Promise((resolve) => setTimeout(resolve, 1000));
47
49
  }
48
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-c23b83622c698",
3
+ "version": "0.2.1-c2c600f2d2b30",
4
4
  "description": "House Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {