@agentshouse/kit 0.2.1-cde47fd72fe59 → 0.2.1-ce3d2bb67177c

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/login.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
- import { hostname } from 'node:os';
4
3
  import { parseArgs } from 'node:util';
5
4
  import { HouseRefusal, post, retrying } from './api.js';
6
5
  import { placeAppGit } from './app-git.js';
@@ -91,13 +90,12 @@ export async function login(argv) {
91
90
  let named = environment;
92
91
  let exchanged;
93
92
  if (values.code !== undefined) {
94
- exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
93
+ exchanged = await post(house, '/kit/token', { code: values.code });
95
94
  }
96
95
  else {
97
96
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
98
97
  const verifier = randomBytes(32).toString('base64url');
99
98
  const start = () => retrying(() => post(house, '/kit', {
100
- label: hostname(),
101
99
  ...(named === undefined
102
100
  ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
103
101
  : { act: 'existing_environment', environment_id: named }),
package/dist/mcp.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { KIT_VERSION } from './clis.js';
2
+ import { KIT_RELEASE } from './clis.js';
3
3
  import { relayed } from './relay.js';
4
4
  const MCP_PROTOCOL_VERSION = '2026-07-28';
5
5
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
6
+ export class Unsettled extends Error {
7
+ }
6
8
  export function rpc(method, params) {
7
9
  return { jsonrpc: '2.0', id: randomUUID(), method, params };
8
10
  }
@@ -13,7 +15,7 @@ export function mcpBody(message, operation) {
13
15
  ...message.params,
14
16
  _meta: {
15
17
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
16
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
18
+ 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
17
19
  'io.modelcontextprotocol/clientCapabilities': {},
18
20
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
21
  },
package/dist/placement.js CHANGED
@@ -18,9 +18,9 @@ export async function updatesItself() {
18
18
  // sudo answers at once, so ten seconds only bounds a stuck sudo.
19
19
  return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
20
20
  }
21
- export function installCommand() {
21
+ function recorded(name) {
22
22
  try {
23
- return readFileSync(join(kitHome(), 'install-command'), 'utf8').trim();
23
+ return readFileSync(join(kitHome(), name), 'utf8').trim();
24
24
  }
25
25
  catch (error) {
26
26
  if (error.code === 'ENOENT')
@@ -28,3 +28,12 @@ export function installCommand() {
28
28
  throw error;
29
29
  }
30
30
  }
31
+ export function installCommand() {
32
+ return recorded('install-command');
33
+ }
34
+ export function machine() {
35
+ const placed = recorded('placement');
36
+ if (placed === 'container' || placed === 'server' || placed === 'windows')
37
+ return placed;
38
+ return process.platform === 'darwin' ? 'macos' : 'linux';
39
+ }
package/dist/resident.js CHANGED
@@ -8,17 +8,17 @@ import { fileURLToPath } from 'node:url';
8
8
  import { Agents } from './agents.js';
9
9
  import { house } from './api.js';
10
10
  import { received } from './bridge.js';
11
- import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
11
+ import { CONVERSATION_METHODS, Conversations } from './conversations.js';
12
12
  import { LocalCopies } from './copies.js';
13
13
  import { restart } from './end.js';
14
14
  import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
15
- import { Inputs } from './inputs.js';
15
+ import { Calls } from './calls.js';
16
16
  import { killDescendants } from './scope.js';
17
17
  import { quoted } from './shell.js';
18
18
  import { SignIns } from './sign-in.js';
19
19
  import { placeSkillSet } from './skills.js';
20
- import { holdStream } from './stream.js';
21
- import { Updates } from './update.js';
20
+ import { holdConnection } from './connection.js';
21
+ import { KitUpdate } from './update.js';
22
22
  import { codexLauncher } from './work.js';
23
23
  function report(error) {
24
24
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
@@ -47,7 +47,7 @@ async function serveOwner(copies) {
47
47
  if (!claimed(lock)) {
48
48
  lock.close();
49
49
  const running = await runningResident();
50
- throw new Error(`${running === null ? 'another Kit' : `Kit ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another here`);
50
+ throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
51
51
  }
52
52
  const server = createServer(async (request, response) => {
53
53
  try {
@@ -132,9 +132,9 @@ export async function resident() {
132
132
  });
133
133
  process.env.HOUSE_KIT_RESIDENT = String(process.pid);
134
134
  const agents = new Agents(house, () => changed());
135
- let stream = null;
135
+ let connection = null;
136
136
  let reported = false;
137
- const idle = () => inputs.idle() && conversations.idle() && agents.idle();
137
+ const idle = () => calls.idle() && conversations.idle() && agents.idle();
138
138
  const changed = () => {
139
139
  if (!idle()) {
140
140
  reported = false;
@@ -147,17 +147,17 @@ export async function resident() {
147
147
  logged(house.deliver('/kit/idle', {}, idle));
148
148
  }
149
149
  };
150
- const inputs = new Inputs(house, changed);
150
+ const calls = new Calls(house, changed);
151
151
  const conversations = new Conversations({
152
152
  house,
153
153
  agents,
154
154
  copies,
155
- inputs,
156
- send: (frame) => stream?.send(frame) ?? false,
155
+ calls,
156
+ send: (notification) => connection?.send(notification) ?? false,
157
157
  changed,
158
158
  });
159
- const signIns = new SignIns(house, agents, inputs);
160
- const updates = new Updates(inputs);
159
+ const signIns = new SignIns(house, agents, calls);
160
+ const update = new KitUpdate(calls);
161
161
  for (const signal of ['SIGTERM', 'SIGINT']) {
162
162
  process.once(signal, () => {
163
163
  killDescendants();
@@ -165,33 +165,33 @@ export async function resident() {
165
165
  });
166
166
  }
167
167
  await house.deliver('/kit/restarted', {}).catch(report);
168
- await updates.resumed().catch(report);
168
+ await update.resumed().catch(report);
169
169
  logged(agents.refresh());
170
- stream = holdStream({
170
+ connection = holdConnection({
171
171
  opened: () => {
172
172
  conversations.opened();
173
173
  changed();
174
174
  logged(copies.connected());
175
175
  },
176
- frame: (arrived) => {
177
- if (arrived.type === 'watching')
178
- conversations.watching(arrived.watching === true);
179
- if (arrived.type === 'authority_changed')
180
- logged(copies.changed(arrived.rooms));
181
- if (arrived.type === 'work_available' && arrived.subject === 'agents')
182
- logged(agents.refresh());
183
- if (arrived.type === 'input') {
184
- if (arrived.kind === 'sign_in')
185
- signIns.start(arrived);
186
- else if (arrived.kind === 'update')
187
- updates.start(arrived);
188
- else if (CONVERSATION_INPUTS.has(arrived.kind))
189
- conversations.input(arrived);
190
- else {
191
- const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
192
- void inputs.carry(String(arrived.input_id), async () => ({ ack: refused }));
193
- }
176
+ call: (call) => {
177
+ if (call.kind === 'sign_in')
178
+ signIns.start(call);
179
+ else if (call.kind === 'update')
180
+ update.start(call);
181
+ else if (CONVERSATION_METHODS.has(call.kind))
182
+ conversations.call(call);
183
+ else {
184
+ const refused = { refused: `This Kit does not know ${call.kind}; update the Kit` };
185
+ void calls.carry(call.input_id, async () => ({ result: refused }));
194
186
  }
195
187
  },
188
+ notification: (notification) => {
189
+ if (notification.type === 'watching')
190
+ conversations.watching(notification.watching === true);
191
+ if (notification.type === 'authority_changed')
192
+ logged(copies.changed(notification.rooms));
193
+ if (notification.type === 'work_available' && notification.subject === 'agents')
194
+ logged(agents.refresh());
195
+ },
196
196
  });
197
197
  }
package/dist/scope.js CHANGED
@@ -4,6 +4,7 @@ import { join } from 'node:path';
4
4
  const LISTING_BYTES = 1 << 28;
5
5
  const CGROUPS = '/sys/fs/cgroup';
6
6
  const GONE = new Set(['ENOENT', 'ESRCH']);
7
+ const EXITED = new Set(['Z', 'X']);
7
8
  function failure(error) {
8
9
  return error.code ?? '';
9
10
  }
@@ -24,6 +25,8 @@ function read(pid) {
24
25
  try {
25
26
  const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
26
27
  const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
28
+ if (EXITED.has(fields[0]))
29
+ return null;
27
30
  const command = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replaceAll('\0', ' ');
28
31
  return { parent: Number(fields[1]), session: fields[3], command };
29
32
  }
package/dist/service.js CHANGED
@@ -13,7 +13,7 @@ function start(command, args) {
13
13
  if (started.status === 0)
14
14
  return;
15
15
  const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
16
- throw new Error(`the House Kit service could not be started: ${cause}`);
16
+ throw new Error(`the Kit service could not be started: ${cause}`);
17
17
  }
18
18
  function physical(path) {
19
19
  return existsSync(path) ? realpathSync(path) : resolve(path);
package/dist/sign-in.js CHANGED
@@ -15,44 +15,44 @@ function endOf(signal) {
15
15
  export class SignIns {
16
16
  house;
17
17
  agents;
18
- inputs;
19
- constructor(house, agents, inputs) {
18
+ calls;
19
+ constructor(house, agents, calls) {
20
20
  this.house = house;
21
21
  this.agents = agents;
22
- this.inputs = inputs;
22
+ this.calls = calls;
23
23
  }
24
- start(input) {
25
- void this.inputs.carry(input.input_id, () => this.signIn(input));
24
+ start(call) {
25
+ void this.calls.carry(call.input_id, () => this.signIn(call));
26
26
  }
27
- async signIn(input) {
27
+ async signIn(call) {
28
28
  const ending = new AbortController();
29
29
  // House stops waiting for a sign-in ten minutes after it wrote it and sends the seconds left, so its install and login end with the page.
30
- const timer = setTimeout(() => ending.abort(), input.ends_in * 1000);
31
- const ended = await Promise.race([this.signedIn(input, ending.signal), endOf(ending.signal)]);
30
+ const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
31
+ const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
32
32
  clearTimeout(timer);
33
33
  if (ended)
34
- process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
35
- return ended ? { ack: {} } : { ack: {}, acknowledged: () => this.agents.reread(input.cli) };
34
+ process.stderr.write(`kit: the ${call.cli} sign-in reached the end House set for it\n`);
35
+ return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
36
36
  }
37
- async signedIn(input, signal) {
38
- await this.login(input, signal);
37
+ async signedIn(call, signal) {
38
+ await this.login(call, signal);
39
39
  if (!signal.aborted)
40
- await this.agents.recheck(input.cli, signal);
40
+ await this.agents.recheck(call.cli, signal);
41
41
  return false;
42
42
  }
43
- async login(input, signal) {
43
+ async login(call, signal) {
44
44
  let cli;
45
45
  try {
46
- cli = await this.agents.located(input.cli, signal);
46
+ cli = await this.agents.located(call.cli, signal);
47
47
  }
48
48
  catch (error) {
49
49
  if (!signal.aborted)
50
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
50
+ process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
51
51
  return;
52
52
  }
53
53
  if (signal.aborted)
54
54
  return;
55
- const login = CLIS[input.cli].login;
55
+ const login = CLIS[call.cli].login;
56
56
  const child = spawn(cli, login.args, {
57
57
  stdio: ['pipe', 'pipe', 'pipe'],
58
58
  detached: true,
@@ -84,7 +84,7 @@ export class SignIns {
84
84
  return;
85
85
  held = true;
86
86
  const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
87
- void holdSecretInput(this.house, input.input_id, steps, running).then((content) => {
87
+ void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
88
88
  if (!running())
89
89
  return;
90
90
  if (content === null)
@@ -101,6 +101,6 @@ export class SignIns {
101
101
  });
102
102
  signal.removeEventListener('abort', stop);
103
103
  if (failed !== null && !signal.aborted)
104
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${failed}\n`);
104
+ process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
105
105
  }
106
106
  }
package/dist/skills.js CHANGED
@@ -5,7 +5,7 @@ import { homedir } from 'node:os';
5
5
  import { join, relative } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { parse } from 'yaml';
8
- import { KIT_VERSION } from './clis.js';
8
+ import { KIT_RELEASE } from './clis.js';
9
9
  import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
10
10
  import { refusalOf } from './refusals.js';
11
11
  const HOW_WE_WORK = '/rooms/private/how-we-work.md';
@@ -60,7 +60,7 @@ async function install() {
60
60
  if (claude !== skills)
61
61
  await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
62
62
  }
63
- await writeHome(RECORD, { version: KIT_VERSION, names });
63
+ await writeHome(RECORD, { version: KIT_RELEASE, names });
64
64
  }
65
65
  export async function placeSkillSet() {
66
66
  try {
@@ -73,7 +73,7 @@ export async function placeSkillSet() {
73
73
  async function replaceSkillSet() {
74
74
  const accepted = (await readConfiguration()).skills;
75
75
  const installed = await readHome(RECORD);
76
- if (accepted && installed?.version === KIT_VERSION)
76
+ if (accepted && installed?.version === KIT_RELEASE)
77
77
  return;
78
78
  for (const name of installed?.names ?? []) {
79
79
  await rm(join(claudeDirectory(), name), { recursive: true, force: true });
@@ -6,6 +6,7 @@ import { basename, join } from 'node:path';
6
6
  import { pipeline } from 'node:stream/promises';
7
7
  import { unlessAborted } from './abort.js';
8
8
  import { failureOf, run } from './clis.js';
9
+ import { downloaded, fetched } from './files.js';
9
10
  import { kitHome } from './home.js';
10
11
  const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
11
12
  export const MODEL = {
@@ -28,6 +29,11 @@ export const ENGINES = {
28
29
  },
29
30
  };
30
31
  const CHUNK_SECONDS = 20;
32
+ const OFF = "transcription is off on the Agent's Environment, so this message's audio has no text; turn it on or write instead";
33
+ const NOT_INSTALLED = "the speech engine is not installed on the Agent's Environment, so this message's audio has no text";
34
+ const NOT_DOWNLOADED = 'an audio file this message links could not be downloaded; send the message again';
35
+ const UNDECODABLE = 'an audio file this message links could not be decoded';
36
+ const UNTRANSCRIBED = 'an audio file this message links could not be transcribed';
31
37
  let held = Promise.resolve();
32
38
  let holding = Promise.resolve();
33
39
  let setting = null;
@@ -62,6 +68,20 @@ async function sha256(path) {
62
68
  function causeOf(error) {
63
69
  return error instanceof Error ? error.message : String(error);
64
70
  }
71
+ async function failing(reason, work) {
72
+ try {
73
+ return await work;
74
+ }
75
+ catch (error) {
76
+ throw new Error(reason, { cause: error });
77
+ }
78
+ }
79
+ function ready() {
80
+ if (setting !== true)
81
+ throw new Error(OFF);
82
+ if (!readiness.installed)
83
+ throw new Error(NOT_INSTALLED);
84
+ }
65
85
  function pinnedHere() {
66
86
  return ENGINES[`${process.platform}-${process.arch}`];
67
87
  }
@@ -133,27 +153,23 @@ export function holdTranscription(transcribe) {
133
153
  export function transcriptionReport() {
134
154
  return readiness;
135
155
  }
136
- async function transcribed(path, signal) {
156
+ async function transcribed(audio, parts, signal) {
137
157
  const pinned = pinnedHere();
138
- const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
139
- try {
140
- await executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', path, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
141
- '-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(work, '%05d.wav')], signal);
142
- const parts = (await readdir(work)).sort().flatMap((part) => ['-f', join(work, part)]);
143
- const text = await executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...parts], signal);
144
- return text
145
- .split('\n')
146
- .map((line) => line.trim())
147
- .filter((line) => line !== '')
148
- .join(' ');
149
- }
150
- finally {
151
- await rm(work, { recursive: true, force: true });
152
- }
158
+ await mkdir(parts);
159
+ await failing(UNDECODABLE, executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
160
+ '-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(parts, '%05d.wav')], signal));
161
+ const segments = (await readdir(parts)).sort().flatMap((part) => ['-f', join(parts, part)]);
162
+ const said = await failing(UNTRANSCRIBED, executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...segments], signal));
163
+ const text = said
164
+ .split('\n')
165
+ .map((line) => line.trim())
166
+ .filter((line) => line !== '')
167
+ .join(' ');
168
+ if (text === '')
169
+ throw new Error(UNTRANSCRIBED);
170
+ return text;
153
171
  }
154
- export async function transcribe(path, signal) {
155
- if (!readiness.installed)
156
- return null;
172
+ async function alone(work, signal) {
157
173
  const before = held;
158
174
  let release;
159
175
  const mine = new Promise((resolve) => {
@@ -162,9 +178,24 @@ export async function transcribe(path, signal) {
162
178
  held = Promise.all([before, mine]);
163
179
  try {
164
180
  await unlessAborted(before, signal);
165
- return readiness.installed ? await transcribed(path, signal) : null;
181
+ return await work();
166
182
  }
167
183
  finally {
168
184
  release();
169
185
  }
170
186
  }
187
+ export async function transcribe(address, signal) {
188
+ ready();
189
+ const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
190
+ try {
191
+ const audio = join(work, 'audio');
192
+ await failing(NOT_DOWNLOADED, downloaded(address, (url) => fetched(url, signal), audio, 'audio'));
193
+ return await alone(() => {
194
+ ready();
195
+ return transcribed(audio, join(work, 'parts'), signal);
196
+ }, signal);
197
+ }
198
+ finally {
199
+ await rm(work, { recursive: true, force: true });
200
+ }
201
+ }
package/dist/update.js CHANGED
@@ -15,8 +15,8 @@ function pending() {
15
15
  function outcome() {
16
16
  return join(directory(), 'outcome');
17
17
  }
18
- function unit(inputId) {
19
- return `house-kit-update-${inputId}`;
18
+ function unit(callId) {
19
+ return `house-kit-update-${callId}`;
20
20
  }
21
21
  function manager() {
22
22
  return service() === 'user' ? ['--user'] : [];
@@ -33,7 +33,7 @@ function placement() {
33
33
  function record() {
34
34
  return `outcome=$1; shift; bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
35
35
  }
36
- async function pendingInput() {
36
+ async function pendingCall() {
37
37
  try {
38
38
  return JSON.parse(await readFile(pending(), 'utf8')).input_id;
39
39
  }
@@ -47,26 +47,26 @@ async function recorded() {
47
47
  return null;
48
48
  return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
49
49
  }
50
- async function forget(inputId) {
51
- if ((await pendingInput()) !== inputId)
50
+ async function forget(callId) {
51
+ if ((await pendingCall()) !== callId)
52
52
  return;
53
53
  await rm(pending(), { force: true });
54
54
  await rm(outcome(), { force: true });
55
55
  }
56
- async function finished(inputId) {
56
+ async function finished(callId) {
57
57
  for (;;) {
58
- const ack = await recorded();
59
- if (ack !== null)
60
- return ack;
58
+ const result = await recorded();
59
+ if (result !== null)
60
+ return result;
61
61
  // systemctl answers at once, so ten seconds only bounds a stuck service manager.
62
- if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
62
+ if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(callId)], 10_000)).status !== 0) {
63
63
  return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
64
64
  }
65
65
  // The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
66
66
  await new Promise((resolve) => setTimeout(resolve, 1000));
67
67
  }
68
68
  }
69
- function rerun(script, inputId, flags) {
69
+ function rerun(script, callId, flags) {
70
70
  return new Promise((resolve) => {
71
71
  const [command, ...args] = [
72
72
  ...elevated(),
@@ -76,7 +76,7 @@ function rerun(script, inputId, flags) {
76
76
  '--wait',
77
77
  '--collect',
78
78
  '--quiet',
79
- `--unit=${unit(inputId)}`,
79
+ `--unit=${unit(callId)}`,
80
80
  `--setenv=HOME=${homedir()}`,
81
81
  `--setenv=HOUSE_KIT_HOME=${kitHome()}`,
82
82
  '/bin/sh',
@@ -88,50 +88,50 @@ function rerun(script, inputId, flags) {
88
88
  ...flags,
89
89
  ];
90
90
  const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
91
- child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
91
+ child.on('error', () => resolve({ refused: 'no service manager runs this Kit process' }));
92
92
  child.on('close', () => resolve(null));
93
93
  });
94
94
  }
95
- export class Updates {
96
- inputs;
95
+ export class KitUpdate {
96
+ calls;
97
97
  queue = Promise.resolve();
98
- constructor(inputs) {
99
- this.inputs = inputs;
98
+ constructor(calls) {
99
+ this.calls = calls;
100
100
  }
101
101
  async resumed() {
102
- const inputId = await pendingInput();
103
- if (inputId === null)
102
+ const callId = await pendingCall();
103
+ if (callId === null)
104
104
  return;
105
- await this.enqueue(inputId, () => finished(inputId));
105
+ await this.enqueue(callId, () => finished(callId));
106
106
  }
107
- start(input) {
108
- void this.enqueue(input.input_id, () => this.carry(input));
107
+ start(call) {
108
+ void this.enqueue(call.input_id, () => this.carry(call));
109
109
  }
110
- enqueue(inputId, work) {
110
+ enqueue(callId, work) {
111
111
  const before = this.queue;
112
- const carried = this.inputs.carry(inputId, async () => {
112
+ const carried = this.calls.carry(callId, async () => {
113
113
  await before;
114
- return { ack: await work(), acknowledged: () => forget(inputId) };
114
+ return { result: await work(), returned: () => forget(callId) };
115
115
  });
116
116
  this.queue = before.then(() => carried);
117
117
  return carried;
118
118
  }
119
- async carry(input) {
120
- if ((await pendingInput()) === input.input_id)
121
- return finished(input.input_id);
122
- const answer = await fetch(input.bootstrap);
119
+ async carry(call) {
120
+ if ((await pendingCall()) === call.input_id)
121
+ return finished(call.input_id);
122
+ const answer = await fetch(call.bootstrap);
123
123
  if (!answer.ok)
124
124
  return { refused: `the Kit bootstrap could not be downloaded: ${answer.status}` };
125
125
  const script = Buffer.from(await answer.arrayBuffer());
126
- if (createHash('sha256').update(script).digest('hex') !== input.sha256) {
126
+ if (createHash('sha256').update(script).digest('hex') !== call.sha256) {
127
127
  return { refused: 'the Kit bootstrap does not match its sha256' };
128
128
  }
129
129
  await mkdir(directory(), { recursive: true, mode: 0o700 });
130
130
  const path = join(directory(), 'connect-linux.sh');
131
131
  await writeFile(path, script, { mode: 0o700 });
132
132
  await rm(outcome(), { force: true });
133
- await writeFile(pending(), `${JSON.stringify({ input_id: input.input_id })}\n`, { mode: 0o600 });
134
- return (await rerun(path, input.input_id, input.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
133
+ await writeFile(pending(), `${JSON.stringify({ input_id: call.input_id })}\n`, { mode: 0o600 });
134
+ return (await rerun(path, call.input_id, call.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
135
135
  refused: 'the Kit bootstrap did not finish',
136
136
  };
137
137
  }
package/dist/wire.js CHANGED
@@ -1,6 +1,22 @@
1
+ import { newerThanHouse, updateRequired } from './end.js';
2
+ import { machine } from './placement.js';
1
3
  import { refusalOf } from './refusals.js';
2
- export const KIT_WIRE = 2;
4
+ export const KIT_WIRE = 3;
3
5
  export const KIT_WIRE_HEADER = 'x-house-kit-wire';
4
- export function tooOld(text) {
5
- return refusalOf(text)?.code === 'kit_update_required';
6
+ function newer(text) {
7
+ let body;
8
+ try {
9
+ body = JSON.parse(text);
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ return body?.error?.code === 'kit_newer_than_house' ? body.error : null;
15
+ }
16
+ export function endUnserved(text) {
17
+ if (refusalOf(text)?.code === 'kit_update_required')
18
+ updateRequired();
19
+ const refused = newer(text);
20
+ if (refused !== null)
21
+ newerThanHouse(refused.release, refused.commands[machine()]);
6
22
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-cde47fd72fe59",
4
- "description": "House Kit connects an Environment to agents.house.",
3
+ "version": "0.2.1-ce3d2bb67177c",
4
+ "description": "Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
package/dist/inputs.js DELETED
@@ -1,37 +0,0 @@
1
- function logged(error) {
2
- process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
3
- }
4
- export class Inputs {
5
- house;
6
- changed;
7
- carried = new Map();
8
- open = 0;
9
- constructor(house, changed) {
10
- this.house = house;
11
- this.changed = changed;
12
- }
13
- idle() {
14
- return this.open === 0;
15
- }
16
- carry(inputId, work) {
17
- const known = this.carried.get(inputId);
18
- const carried = known ?? work();
19
- if (known === undefined) {
20
- this.carried.set(inputId, carried);
21
- carried.catch(() => this.carried.delete(inputId));
22
- }
23
- this.open++;
24
- this.changed();
25
- return carried
26
- .then(async ({ ack, acknowledged }) => {
27
- await this.house.deliver(`/kit/inputs/${inputId}/ack`, ack);
28
- if (known === undefined)
29
- await acknowledged?.();
30
- })
31
- .catch(logged)
32
- .finally(() => {
33
- this.open--;
34
- this.changed();
35
- });
36
- }
37
- }