@agentshouse/kit 0.2.1-c5d36e97b0fea → 0.2.1-caf3915e29919

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
@@ -1,14 +1,12 @@
1
1
  # House Kit
2
2
 
3
- House Kit connects an Environment, a Linux computer or server, to
4
- [agents.house](https://agents.house). It runs your Agents' conversations
5
- through the agent CLIs you chose and gives each Agent the `house` command.
3
+ House Kit connects an Environment, a Linux computer or server, to [agents.house](https://agents.house). It runs
4
+ your Agents' conversations through the agent CLIs you chose and gives each Agent the `house` command.
6
5
 
7
6
  ## Install
8
7
 
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,
8
+ Run `curl -fsSL agents.house/kit | sh`, or `irm agents.house/kit.ps1 | iex` on Windows, and again to update;
9
+ options follow `sh -s --`. On macOS and Linux it installs House Kit natively under your own account, without an admin password,
12
10
  as a service that runs while you are logged in. `kit` and `house` are then on
13
11
  your login shell's `PATH`, and your workspace is `~/AgentsHouse` unless you
14
12
  pass `--workspace <path>`.
@@ -33,22 +31,24 @@ them out; running it again without the flag brings them back.
33
31
 
34
32
  ## Commands
35
33
 
36
- `kit login` opens or prints a link you confirm in any browser, on this
37
- computer or another, continues on its own and keeps the Environment's
38
- credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is set. Pass
39
- `--environment <id>` to reconnect an Environment you already have. It also
40
- connects your own agent: outside an Agent conversation, `house <tool>` calls
34
+ `kit login` opens or prints a link you confirm in any browser, on this computer
35
+ or another, continues on its own and keeps the Environment's credential in
36
+ `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is set. `--environment <id>`
37
+ reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
38
+ only those Rooms and `--no-private` every Room but your Private Room;
39
+ `--code <code>` connects immediately without a link.
40
+ A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
41
41
  House as you and `git` clones and pushes your Apps at `<house>/app/` as you,
42
42
  until you revoke that connection on Connections. `house help` lists the Tools.
43
43
  `kit logout` disconnects this computer, stops House Kit and ends your own
44
44
  agent's connection, so `house` and `git` no longer act as you here; a later
45
45
  `kit login` reconnects the same Environment.
46
46
 
47
- `kit resident` keeps the Environment connected and the Rooms you chose for it
48
- as Git repositories under `local-copies` in the workspace. `house fetch`
49
- records House's changes on each copy's `refs/house/received`; rebase onto it,
50
- commit and run `house push --owner` in the copy, through the install command in
51
- the container. An Agent runs both, without `--owner`.
47
+ `kit resident` keeps the Environment connected and, as it connects, copies each
48
+ Room you chose for it as a Git repository in the workspace's `local-copies`.
49
+ `house fetch` records House's changes on each copy's `refs/house/received`;
50
+ rebase onto it, commit and run `house push --owner` in the copy, through the
51
+ install command in the container. An Agent runs both, without `--owner`.
52
52
 
53
53
  House Kit turns each audio file of your message to an Agent into text on this
54
54
  computer before the Agent reads it. While transcription is on, the speech
package/dist/agents.js CHANGED
@@ -257,7 +257,7 @@ export class Agents {
257
257
  }
258
258
  async load(kind) {
259
259
  const known = this.readings.get(kind);
260
- if (known !== undefined && known.failure === null)
260
+ if (known !== undefined && known.failure === null && known.minimum === undefined)
261
261
  return;
262
262
  await this.examine(kind, SIGNED_OUT, offer);
263
263
  }
package/dist/api.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { setTimeout as delay } from 'node:timers/promises';
2
- import { end, SIGN_IN_AGAIN } from './end.js';
2
+ import { signInAgain } from './end.js';
3
3
  import { readEnrolment } from './home.js';
4
4
  import { retryable } from './refusals.js';
5
5
  import { relayed } from './relay.js';
@@ -54,7 +54,7 @@ async function enrolledPost(path, body, signal) {
54
54
  }
55
55
  catch (error) {
56
56
  if (error instanceof HouseRefusal && error.status === 401)
57
- end(SIGN_IN_AGAIN);
57
+ await signInAgain(credential);
58
58
  throw error;
59
59
  }
60
60
  }
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
- "version": "0.2.1-c5d36e97b0fea",
3
+ "version": "0.2.1-caf3915e29919",
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-c5d36e97b0fea/connect-linux.sh"
8
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-caf3915e29919/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-c5d36e97b0fea/connect-linux.sh"
14
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-caf3915e29919/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-c5d36e97b0fea/connect-windows.ps1"
20
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-caf3915e29919/connect-windows.ps1"
21
21
  }
22
22
  }
23
23
  }
@@ -132,6 +132,9 @@ export class Conversations {
132
132
  return false;
133
133
  return !conversations.some((conversation) => conversation.running?.scope.working() || [...conversation.leftovers].some((scope) => scope.working()));
134
134
  }
135
+ quiet() {
136
+ return this.idle() && [...this.conversations.values()].every((conversation) => conversation.open === 0);
137
+ }
135
138
  look() {
136
139
  for (const conversation of this.conversations.values()) {
137
140
  for (const scope of conversation.leftovers) {
package/dist/copies.js CHANGED
@@ -42,7 +42,7 @@ function expiredAuthority(error) {
42
42
  return undefined;
43
43
  try {
44
44
  const { error: refused } = JSON.parse(error.text);
45
- return refused?.code === 'position_expired' && typeof refused.authority === 'string' ? refused.authority : undefined;
45
+ return refused?.code === 'expired' && typeof refused.authority === 'string' ? refused.authority : undefined;
46
46
  }
47
47
  catch {
48
48
  return undefined;
@@ -168,7 +168,7 @@ export class LocalCopies {
168
168
  house;
169
169
  copies = new Map();
170
170
  queues = new Map();
171
- selecting = Promise.resolve();
171
+ answering = Promise.resolve();
172
172
  constructor(house) {
173
173
  this.house = house;
174
174
  this.owner = {
@@ -200,39 +200,39 @@ export class LocalCopies {
200
200
  }
201
201
  }
202
202
  async mapping() {
203
- await this.selecting;
203
+ await this.answering;
204
204
  return [...this.copies.values()]
205
205
  .filter((copy) => copy.active)
206
206
  .map((copy) => `${rootOf(copy.room_handle)}: ${copy.repository}`)
207
207
  .sort();
208
208
  }
209
- async select() {
210
- const selected = await this.selected(() => this.fetched(false));
211
- if (selected.refused)
212
- logged(selected.text);
209
+ async connected() {
210
+ const copied = await this.answered(() => this.fetched(false));
211
+ if (copied.refused)
212
+ logged(copied.text);
213
213
  }
214
214
  fetch() {
215
- return this.selected(() => this.fetched(true));
215
+ return this.answered(() => this.fetched(true));
216
216
  }
217
- selected(work) {
218
- const selected = this.selecting.then(work);
219
- this.selecting = selected.catch(() => undefined);
220
- return selected;
217
+ answered(work) {
218
+ const answered = this.answering.then(work);
219
+ this.answering = answered.catch(() => undefined);
220
+ return answered;
221
221
  }
222
222
  async fetched(refreshing) {
223
- const { local_copy: chosen } = await this.house.post('/kit/local-copy/selection', {});
224
- const selected = new Map(chosen.rooms.map((room) => [`rooms/${room.room_ref}`, room.room_handle]));
225
- return this.holding([...new Set([...this.copies.keys(), ...selected.keys()])].sort(), async () => {
223
+ const { local_copy: answer } = await this.house.post('/kit/local-copy/selection', {});
224
+ const synced = new Map(answer.rooms.map((room) => [`rooms/${room.room_ref}`, room.room_handle]));
225
+ return this.holding([...new Set([...this.copies.keys(), ...synced.keys()])].sort(), async () => {
226
226
  const said = [];
227
227
  let refused = false;
228
228
  for (const copy of this.copies.values()) {
229
- if (selected.has(copy.key) || !copy.active)
229
+ if (synced.has(copy.key) || !copy.active)
230
230
  continue;
231
231
  await this.save({ ...copy, active: false });
232
232
  said.push(`${rootOf(copy.room_handle)}: no longer synced to this Environment; its files stay`);
233
233
  }
234
234
  const current = [];
235
- for (const [key, handle] of selected) {
235
+ for (const [key, handle] of synced) {
236
236
  try {
237
237
  const held = this.copies.get(key);
238
238
  if (held === undefined || !(await exists(held.repository))) {
@@ -623,7 +623,7 @@ export class LocalCopies {
623
623
  const { upload, ...unstaged } = copy.push;
624
624
  return this.settle(await this.save({ ...copy, push: unstaged }), caller, true);
625
625
  }
626
- if (outcome.refused.code === 'operation_expired')
626
+ if (outcome.refused.code === 'expired')
627
627
  return this.recovered(copy);
628
628
  const rebased = rebaseFixes(outcome.refused);
629
629
  let settled = await this.save(without(copy));
package/dist/end.js CHANGED
@@ -1,8 +1,18 @@
1
+ import { forgetRejected } from './home.js';
1
2
  import { killDescendants } from './scope.js';
2
3
  export const REPLACED = 'another Kit started for this Environment';
3
- export const SIGN_IN_AGAIN = 'sign in again';
4
- export function end(reason) {
4
+ function exit(reason, status) {
5
5
  process.stderr.write(`kit: ${reason}\n`);
6
6
  killDescendants();
7
- process.exit(0);
7
+ process.exit(status);
8
+ }
9
+ export function end(reason) {
10
+ exit(reason, 0);
11
+ }
12
+ export function restart(reason) {
13
+ exit(reason, 1);
14
+ }
15
+ export async function signInAgain(rejected) {
16
+ await forgetRejected(rejected);
17
+ restart('sign in again');
8
18
  }
@@ -1,4 +1,10 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { writeEnrolment } from './home.js';
3
3
  const [house, environment] = process.argv.slice(2);
4
- await writeEnrolment({ house: house, environment: environment, credential: readFileSync(0, 'utf8').trim() });
4
+ const relay = process.env.HOUSE_KIT_RELAY || undefined;
5
+ await writeEnrolment({
6
+ house: house,
7
+ ...(relay === undefined ? {} : { relay }),
8
+ environment: environment,
9
+ credential: readFileSync(0, 'utf8').trim(),
10
+ });
package/dist/home.js CHANGED
@@ -1,11 +1,13 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, linkSync, readFileSync, renameSync, rmSync } from 'node:fs';
2
2
  import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
3
  import { homedir } from 'node:os';
4
4
  import { join } from 'node:path';
5
+ import { selectRelay } from './relay.js';
5
6
  const ENROLMENT = 'credential.json';
6
7
  const DISCONNECTED = 'disconnected.json';
7
8
  const CONFIGURATION = 'kit.json';
8
9
  const OWN_AGENT = 'own-agent.json';
10
+ const RESTART = 'restart';
9
11
  export function kitHome() {
10
12
  return process.env.HOUSE_KIT_HOME ?? join(homedir(), '.house-kit');
11
13
  }
@@ -32,8 +34,11 @@ export async function writeHome(name, value) {
32
34
  await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
33
35
  await rename(temporary, join(home, name));
34
36
  }
35
- export function readEnrolment() {
36
- return readHome(ENROLMENT);
37
+ export async function readEnrolment() {
38
+ const enrolment = await readHome(ENROLMENT);
39
+ if (enrolment !== null)
40
+ selectRelay(process.env.HOUSE_KIT_RELAY || enrolment.relay);
41
+ return enrolment;
37
42
  }
38
43
  export async function writeEnrolment(enrolment) {
39
44
  await writeHome(ENROLMENT, enrolment);
@@ -46,9 +51,42 @@ export async function forgetEnrolment({ house, environment }) {
46
51
  await writeHome(DISCONNECTED, { house, environment });
47
52
  await rm(join(kitHome(), ENROLMENT), { force: true });
48
53
  }
54
+ export async function forgetRejected(rejected) {
55
+ const held = await readHome(ENROLMENT);
56
+ if (held?.credential !== rejected)
57
+ return;
58
+ await writeHome(DISCONNECTED, { house: held.house, environment: held.environment });
59
+ const enrolment = join(kitHome(), ENROLMENT);
60
+ const taken = `${enrolment}.${process.pid}`;
61
+ try {
62
+ renameSync(enrolment, taken);
63
+ }
64
+ catch (error) {
65
+ if (error.code === 'ENOENT')
66
+ return;
67
+ throw error;
68
+ }
69
+ if (JSON.parse(readFileSync(taken, 'utf8')).credential !== rejected) {
70
+ try {
71
+ linkSync(taken, enrolment);
72
+ }
73
+ catch (error) {
74
+ if (error.code !== 'EEXIST')
75
+ throw error;
76
+ }
77
+ rmSync(join(kitHome(), DISCONNECTED), { force: true });
78
+ }
79
+ rmSync(taken);
80
+ }
49
81
  export function enrolled() {
50
82
  return existsSync(join(kitHome(), ENROLMENT));
51
83
  }
84
+ export function restartAsked() {
85
+ return existsSync(join(kitHome(), RESTART));
86
+ }
87
+ export function forgetRestart() {
88
+ return rm(join(kitHome(), RESTART), { force: true });
89
+ }
52
90
  export function readOwnAgent() {
53
91
  return readHome(OWN_AGENT);
54
92
  }
@@ -4,7 +4,7 @@ import { readFile } from 'node:fs/promises';
4
4
  import { request, setGlobalProxyFromEnv } from 'node:http';
5
5
  import { basename, join } from 'node:path';
6
6
  import { HOUSE_REF } from './git.js';
7
- import { kitHome, readOwnAgent } from './home.js';
7
+ import { kitHome, readEnrolment, readOwnAgent } from './home.js';
8
8
  import { callHouse, rpc, UNREACHABLE } from './mcp.js';
9
9
  import { refusalOf } from './refusals.js';
10
10
  import { relayed } from './relay.js';
@@ -56,6 +56,7 @@ async function direct(message) {
56
56
  const ownAgent = await readOwnAgent();
57
57
  if (ownAgent === null)
58
58
  throw new Error(UNCONNECTED);
59
+ await readEnrolment();
59
60
  setGlobalProxyFromEnv();
60
61
  const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
61
62
  throw new Error(UNREACHABLE);
@@ -1,8 +1,9 @@
1
1
  import { HOUSE_REF } from './git.js';
2
2
  import { HOW_WE_WORK } from './skills.js';
3
+ const SOURCE_LINE = "From House:";
3
4
  const HOUSE_LINE = 'Work with House through the `house` CLI: run `house --help`.';
4
5
  const FILE_LINE = 'To give the User a file or a page, upload it with `house upload` and link it; never start a server.';
5
- const READ_LINE = 'Before working in a Room, read `/rooms/private/rooms/<handle>/AGENTS.md`.';
6
+ const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
6
7
  const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
7
8
  const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
8
9
  const FAILED = /^exit: [1-9]\d*$/;
@@ -30,6 +31,6 @@ async function howWeWork(bridge) {
30
31
  return document.replace(/\n$/, '');
31
32
  }
32
33
  export async function instructions(bridge, base, copies) {
33
- const lines = [HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
34
+ const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
34
35
  return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
35
36
  }
package/dist/login.js CHANGED
@@ -6,6 +6,8 @@ import { post, retrying } from './api.js';
6
6
  import { placeAppGit } from './app-git.js';
7
7
  import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
8
8
  import { callHouse, rpc } from './mcp.js';
9
+ import { selectRelay } from './relay.js';
10
+ import { startService } from './service.js';
9
11
  const DEFAULT_HOUSE = 'https://agents.house';
10
12
  const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
11
13
  // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
@@ -23,39 +25,92 @@ async function accepted(house, credential) {
23
25
  return false;
24
26
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
25
27
  }
28
+ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private] [--code <code>]
29
+ --house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
30
+ --environment <id> reconnect this Environment
31
+ --rooms <ref>[,<ref>...] give this Environment only these Rooms
32
+ --no-private give this Environment every Room but your Private Room
33
+ --code <code> connect this machine with a login code
34
+ `;
35
+ function chosenRooms(rooms, noPrivate) {
36
+ if (rooms !== undefined && noPrivate)
37
+ throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
38
+ if (rooms !== undefined)
39
+ return { rooms: { reach: 'selected', refs: rooms.split(',') } };
40
+ return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
41
+ }
26
42
  export async function login(argv) {
27
43
  const { values } = parseArgs({
28
44
  args: argv,
29
45
  options: {
30
46
  house: { type: 'string' },
31
47
  environment: { type: 'string' },
48
+ rooms: { type: 'string' },
49
+ 'no-private': { type: 'boolean', default: false },
50
+ code: { type: 'string' },
51
+ help: { type: 'boolean', default: false },
32
52
  },
33
53
  });
54
+ if (values.help) {
55
+ process.stdout.write(USAGE);
56
+ return;
57
+ }
58
+ if (values.code !== undefined && values.rooms !== undefined)
59
+ throw new Error('--code cannot be used with --rooms');
60
+ if (values.code !== undefined && values['no-private'])
61
+ throw new Error('--code cannot be used with --no-private');
62
+ if (values.code !== undefined && values.environment !== undefined)
63
+ throw new Error('--code cannot be used with --environment');
64
+ const rooms = chosenRooms(values.rooms, values['no-private']);
34
65
  const enrolled = (await readEnrolment()) ?? (await readDisconnected());
66
+ if (values.code !== undefined && enrolled !== null) {
67
+ throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
68
+ }
69
+ const relay = process.env.HOUSE_KIT_RELAY || undefined;
70
+ selectRelay(relay);
35
71
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
36
72
  const replaces = process.env.HOUSE_KIT_REPLACES;
37
73
  const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
38
74
  const ownAgent = await readOwnAgent();
39
- const held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
40
- const verifier = randomBytes(32).toString('base64url');
41
- const started = await retrying(() => post(house, '/kit', {
42
- ...(environment === undefined
43
- ? { act: 'new_environment', label: hostname(), ...(replaces === undefined ? {} : { replaces }) }
44
- : { act: 'existing_environment', environment_id: environment }),
45
- code_challenge: createHash('sha256').update(verifier).digest('base64url'),
46
- ...(held ? {} : { headless: true }),
47
- }));
48
- process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
49
- open(started.start_url);
50
- const exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
51
- await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
75
+ let held = false;
76
+ let exchanged;
77
+ if (values.code !== undefined) {
78
+ exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
79
+ }
80
+ else {
81
+ held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
82
+ const verifier = randomBytes(32).toString('base64url');
83
+ const started = await retrying(() => post(house, '/kit', {
84
+ ...(environment === undefined
85
+ ? { act: 'new_environment', label: hostname(), ...(replaces === undefined ? {} : { replaces }) }
86
+ : { act: 'existing_environment', environment_id: environment }),
87
+ ...rooms,
88
+ code_challenge: createHash('sha256').update(verifier).digest('base64url'),
89
+ ...(held ? {} : { headless: true }),
90
+ }));
91
+ process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
92
+ open(started.start_url);
93
+ exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
94
+ }
95
+ await writeEnrolment({
96
+ house,
97
+ ...(relay === undefined ? {} : { relay }),
98
+ environment: exchanged.environment,
99
+ credential: exchanged.credential,
100
+ });
52
101
  process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
53
102
  if (exchanged.headless_credential !== undefined) {
54
103
  await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
55
104
  }
56
- else if (held && ownAgent.user !== exchanged.user) {
105
+ else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
57
106
  await forgetOwnAgent();
58
107
  process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
59
108
  }
60
109
  await placeAppGit(ownAgent, await readOwnAgent());
110
+ try {
111
+ startService();
112
+ }
113
+ catch (error) {
114
+ process.stderr.write(`kit: ${error.message}\n`);
115
+ }
61
116
  }
package/dist/relay.js CHANGED
@@ -1,7 +1,17 @@
1
+ let selected;
2
+ export function selectRelay(relay) {
3
+ selected = relay === undefined || relay === '' ? null : relay;
4
+ }
5
+ function relayOrigin() {
6
+ if (selected !== undefined)
7
+ return selected ?? undefined;
8
+ const ambient = process.env.HOUSE_KIT_RELAY;
9
+ return ambient === undefined || ambient === '' ? undefined : ambient;
10
+ }
1
11
  export function relayed(target) {
2
12
  const url = new URL(target);
3
- const relay = process.env.HOUSE_KIT_RELAY;
4
- if (relay === undefined || relay === '')
13
+ const relay = relayOrigin();
14
+ if (relay === undefined)
5
15
  return url;
6
16
  const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
7
17
  if (url.protocol === 'wss:' || url.protocol === 'ws:')
package/dist/resident.js CHANGED
@@ -9,7 +9,8 @@ import { house } from './api.js';
9
9
  import { received } from './bridge.js';
10
10
  import { Conversations } from './conversations.js';
11
11
  import { LocalCopies } from './copies.js';
12
- import { agentBase, enrolled, kitHome } from './home.js';
12
+ import { restart } from './end.js';
13
+ import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
13
14
  import { killDescendants } from './scope.js';
14
15
  import { quoted } from './shell.js';
15
16
  import { SignIns } from './sign-in.js';
@@ -73,6 +74,7 @@ function connected() {
73
74
  }
74
75
  export async function resident() {
75
76
  await connected();
77
+ await forgetRestart();
76
78
  watch(kitHome(), () => {
77
79
  if (enrolled())
78
80
  return;
@@ -95,6 +97,9 @@ export async function resident() {
95
97
  if (!idle()) {
96
98
  reported = false;
97
99
  }
100
+ else if (restartAsked() && conversations.quiet()) {
101
+ restart('restarting for an updated CLI');
102
+ }
98
103
  else if (!reported) {
99
104
  reported = true;
100
105
  logged(house.deliver('/kit/idle', {}, idle));
@@ -122,7 +127,7 @@ export async function resident() {
122
127
  opened: () => {
123
128
  conversations.opened();
124
129
  changed();
125
- logged(copies.select());
130
+ logged(copies.connected());
126
131
  },
127
132
  frame: (arrived) => {
128
133
  if (arrived.type === 'watching')
@@ -0,0 +1,9 @@
1
+ import { startService } from './service.js';
2
+ try {
3
+ if (startService())
4
+ process.stdout.write('started\n');
5
+ }
6
+ catch (error) {
7
+ process.stderr.write(`kit: ${error.message}\n`);
8
+ process.exitCode = 1;
9
+ }
@@ -0,0 +1,33 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ const UNIT = 'house-kit.service';
3
+ // launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
4
+ const MANAGER_MS = 10_000;
5
+ function manage(command, args) {
6
+ return spawnSync(command, args, { encoding: 'utf8', timeout: MANAGER_MS });
7
+ }
8
+ function start(command, args) {
9
+ const started = manage(command, args);
10
+ if (started.status === 0)
11
+ return;
12
+ const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
13
+ throw new Error(`the House Kit service could not be started: ${cause}`);
14
+ }
15
+ export function startService() {
16
+ if (process.platform === 'darwin') {
17
+ const service = `gui/${process.getuid()}/house-kit`;
18
+ const printed = manage('launchctl', ['print', service]);
19
+ if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
20
+ return false;
21
+ start('launchctl', ['kickstart', service]);
22
+ return true;
23
+ }
24
+ for (const scope of [['--user'], []]) {
25
+ if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
26
+ continue;
27
+ if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
28
+ return false;
29
+ start('systemctl', [...scope, 'start', UNIT]);
30
+ return true;
31
+ }
32
+ return false;
33
+ }
package/dist/stream.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { subscribe } from 'node:diagnostics_channel';
2
2
  import { finalRefusal, HouseRefusal, retryDelay } from './api.js';
3
- import { end, REPLACED, SIGN_IN_AGAIN } from './end.js';
3
+ import { end, REPLACED, signInAgain } from './end.js';
4
4
  import { readEnrolment } from './home.js';
5
5
  import { relayed } from './relay.js';
6
6
  const PATH = '/kit/stream';
@@ -52,8 +52,10 @@ export function holdStream(handlers) {
52
52
  process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
53
53
  if (event.reason === 'replaced')
54
54
  end(REPLACED);
55
- if (event.reason === 'credential_rejected' || refused?.status === 401)
56
- end(SIGN_IN_AGAIN);
55
+ if (event.reason === 'credential_rejected' || refused?.status === 401) {
56
+ void signInAgain(credential);
57
+ return;
58
+ }
57
59
  if (finalRefusal(refused))
58
60
  end(refused.message);
59
61
  // A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused as retryable or left unanswered backs off on the jittered curve.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-c5d36e97b0fea",
3
+ "version": "0.2.1-caf3915e29919",
4
4
  "description": "House Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@agentclientprotocol/sdk": "1.7.0",
30
- "@agentshouse/mdmodel": "0.1.0-alpha.19",
30
+ "@agentshouse/mdmodel": "0.1.0-c68e2039f1ca8",
31
31
  "yaml": "2.9.1"
32
32
  },
33
33
  "peerDependencies": {