@agentshouse/kit 0.2.1-c9a26041e119a → 0.2.1-c9c41d009d46a

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/kit-main.js CHANGED
@@ -1,69 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { setGlobalProxyFromEnv } from 'node:http';
3
- import { parseArgs } from 'node:util';
4
- import { answerGitCredential } from './app-git.js';
5
- import { chatgpt } from './chatgpt.js';
6
- import { login } from './login.js';
7
- import { logout } from './logout.js';
8
- import { resident } from './resident.js';
9
- const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
10
- const COMMANDS = new Map([
11
- [
12
- 'logout',
13
- {
14
- usage: 'usage: kit logout',
15
- about: "disconnects this computer, stops House Kit and ends your own agent's connection",
16
- operands: 0,
17
- run: logout,
18
- },
19
- ],
20
- [
21
- 'resident',
22
- {
23
- usage: 'usage: kit resident',
24
- about: "keeps this Environment connected; House Kit's service runs it",
25
- operands: 0,
26
- run: resident,
27
- },
28
- ],
29
- [
30
- 'git-credential',
31
- {
32
- usage: 'usage: kit git-credential <get|store|erase>',
33
- about: "answers git with your own agent's House credential; git runs it",
34
- operands: 1,
35
- run: ([operation]) => answerGitCredential(operation),
36
- },
37
- ],
38
- ]);
39
- const [command, ...argv] = process.argv.slice(2);
40
- setGlobalProxyFromEnv();
41
- async function run() {
42
- if (command === 'login')
43
- return login(argv);
44
- if (command === 'chatgpt')
45
- return chatgpt(argv);
46
- if (command === '--help') {
47
- parseArgs({ args: argv });
48
- process.stdout.write(USAGE);
49
- return;
50
- }
51
- const chosen = COMMANDS.get(command ?? '');
52
- if (chosen === undefined) {
53
- process.stderr.write(USAGE);
54
- process.exitCode = 2;
55
- return;
56
- }
57
- const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
58
- if (positionals.length > chosen.operands)
59
- throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
60
- if (values.help) {
61
- process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
62
- return;
63
- }
64
- return chosen.run(positionals);
65
- }
66
- run().catch((error) => {
67
- process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
2
+ const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
3
+ if (major < 24 || (major === 24 && minor < 14)) {
4
+ process.stderr.write(`kit: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
68
5
  process.exitCode = 1;
69
- });
6
+ }
7
+ else {
8
+ await import('./kit-cli.js');
9
+ }
10
+ export {};
package/dist/login.js CHANGED
@@ -36,6 +36,13 @@ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms
36
36
  --no-private give this Environment every Room but your Private Room
37
37
  --code <code> connect this machine with a login code
38
38
  `;
39
+ function connected(house, named, environment) {
40
+ if (named === undefined)
41
+ return `Environment ${environment} is connected to ${house}.\n`;
42
+ if (named === environment)
43
+ return `Environment ${environment} is reconnected to ${house}.\n`;
44
+ return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
45
+ }
39
46
  function gone(error) {
40
47
  return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
41
48
  }
@@ -81,6 +88,7 @@ export async function login(argv) {
81
88
  const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
82
89
  const ownAgent = await readOwnAgent();
83
90
  let held = false;
91
+ let named = environment;
84
92
  let exchanged;
85
93
  if (values.code !== undefined) {
86
94
  exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
@@ -88,7 +96,7 @@ export async function login(argv) {
88
96
  else {
89
97
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
90
98
  const verifier = randomBytes(32).toString('base64url');
91
- const start = (named) => retrying(() => post(house, '/kit', {
99
+ const start = () => retrying(() => post(house, '/kit', {
92
100
  label: hostname(),
93
101
  ...(named === undefined
94
102
  ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
@@ -99,14 +107,15 @@ export async function login(argv) {
99
107
  }));
100
108
  let started;
101
109
  try {
102
- started = await start(environment);
110
+ started = await start();
103
111
  }
104
112
  catch (error) {
105
113
  if (remembered === undefined || !gone(error))
106
114
  throw error;
107
115
  await forgetDisconnected();
108
116
  process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
109
- started = await start(undefined);
117
+ named = undefined;
118
+ started = await start();
110
119
  }
111
120
  process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
112
121
  open(started.start_url);
@@ -121,7 +130,7 @@ export async function login(argv) {
121
130
  environment: exchanged.environment,
122
131
  credential: exchanged.credential,
123
132
  });
124
- process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
133
+ process.stdout.write(connected(house, named, exchanged.environment));
125
134
  if (exchanged.headless_credential !== undefined) {
126
135
  await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
127
136
  }
@@ -132,7 +141,7 @@ export async function login(argv) {
132
141
  else if (held && ownAgent !== null) {
133
142
  await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
134
143
  }
135
- await placeAppGit(ownAgent, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
144
+ await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
136
145
  try {
137
146
  startService();
138
147
  }
package/dist/logout.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { HouseRefusal, post } from './api.js';
2
- import { forgetAppGit } from './app-git.js';
3
2
  import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
4
3
  export async function logout() {
5
4
  const enrolled = await readEnrolment();
@@ -13,7 +12,6 @@ export async function logout() {
13
12
  }
14
13
  await forgetEnrolment(enrolled);
15
14
  }
16
- await forgetAppGit();
17
15
  await forgetOwnAgent();
18
16
  process.stdout.write(enrolled === null
19
17
  ? 'This computer is not connected to House.\n'
package/dist/placement.js CHANGED
@@ -2,7 +2,6 @@ import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { run } from './clis.js';
4
4
  import { kitHome } from './home.js';
5
- import { relayOrigin } from './relay.js';
6
5
  export function service() {
7
6
  if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
8
7
  return null;
@@ -19,9 +18,9 @@ export async function updatesItself() {
19
18
  // sudo answers at once, so ten seconds only bounds a stuck sudo.
20
19
  return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
21
20
  }
22
- function installed() {
21
+ export function installCommand() {
23
22
  try {
24
- return readFileSync(join(kitHome(), 'placement'), 'utf8').trim();
23
+ return readFileSync(join(kitHome(), 'install-command'), 'utf8').trim();
25
24
  }
26
25
  catch (error) {
27
26
  if (error.code === 'ENOENT')
@@ -29,20 +28,3 @@ function installed() {
29
28
  throw error;
30
29
  }
31
30
  }
32
- function entries(house) {
33
- const host = new URL(house).host;
34
- const relay = relayOrigin();
35
- if (relay === undefined)
36
- return [`curl -fsSL ${host}/kit | sh`, `irm ${host}/kit.ps1 | iex`];
37
- const entry = `${relay}/${host}/kit`;
38
- return [`curl -fsSL ${entry} | HOUSE_KIT_RELAY=${relay} sh`, `$env:HOUSE_KIT_RELAY='${relay}'; irm ${entry}.ps1 | iex`];
39
- }
40
- export function installCommand(house) {
41
- const [shell, windows] = entries(house);
42
- const placement = installed();
43
- if (placement === 'native')
44
- return shell;
45
- if (placement === 'server')
46
- return `${shell} -s -- --linux`;
47
- return `${shell} -s -- --container, or ${windows} on Windows`;
48
- }
package/dist/resident.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { once } from 'node:events';
2
2
  import { watch } from 'node:fs';
3
3
  import { mkdir, rm, writeFile } from 'node:fs/promises';
4
- import { createServer } from 'node:http';
4
+ import { createServer, get } from 'node:http';
5
5
  import { dirname, extname, join } from 'node:path';
6
+ import { DatabaseSync } from 'node:sqlite';
6
7
  import { fileURLToPath } from 'node:url';
7
8
  import { Agents } from './agents.js';
8
9
  import { house } from './api.js';
@@ -10,7 +11,7 @@ import { received } from './bridge.js';
10
11
  import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
11
12
  import { LocalCopies } from './copies.js';
12
13
  import { restart } from './end.js';
13
- import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
14
+ import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
14
15
  import { killDescendants } from './scope.js';
15
16
  import { quoted } from './shell.js';
16
17
  import { SignIns } from './sign-in.js';
@@ -29,13 +30,32 @@ async function installShim(path, module) {
29
30
  await mkdir(dirname(path), { recursive: true });
30
31
  await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
31
32
  }
33
+ function claimed(lock) {
34
+ try {
35
+ lock.exec('BEGIN EXCLUSIVE');
36
+ return true;
37
+ }
38
+ catch (error) {
39
+ if (error.errcode === 5)
40
+ return false;
41
+ throw error;
42
+ }
43
+ }
32
44
  async function serveOwner(copies) {
33
- const socketPath = join(kitHome(), 'owner.sock');
34
- await rm(socketPath, { force: true });
45
+ const lock = new DatabaseSync(ownerLock());
46
+ if (!claimed(lock)) {
47
+ lock.close();
48
+ const running = await runningResident();
49
+ 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
+ }
35
51
  const server = createServer(async (request, response) => {
36
52
  try {
37
53
  const text = await received(request);
38
54
  let answered;
55
+ if (request.url === '/resident') {
56
+ response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
57
+ return;
58
+ }
39
59
  if (request.url === '/git/fetch') {
40
60
  answered = await copies.fetch();
41
61
  }
@@ -53,9 +73,23 @@ async function serveOwner(copies) {
53
73
  response.writeHead(502).end(error instanceof Error ? error.message : String(error));
54
74
  }
55
75
  });
56
- server.listen(socketPath);
76
+ server.on('close', () => lock.close());
77
+ await rm(ownerSocket(), { force: true });
78
+ server.listen(ownerSocket());
57
79
  await once(server, 'listening');
58
80
  }
81
+ function runningResident() {
82
+ return new Promise((resolve, reject) => {
83
+ get({ socketPath: ownerSocket(), path: '/resident' }, (answer) => {
84
+ received(answer).then((text) => resolve(JSON.parse(text).pid), reject);
85
+ }).on('error', (error) => {
86
+ if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
87
+ resolve(null);
88
+ else
89
+ reject(error);
90
+ });
91
+ });
92
+ }
59
93
  function connected() {
60
94
  return new Promise((resolve) => {
61
95
  const watcher = watch(kitHome(), () => {
@@ -72,7 +106,7 @@ function connected() {
72
106
  resolve();
73
107
  });
74
108
  }
75
- export async function resident() {
109
+ async function started() {
76
110
  await connected();
77
111
  await forgetRestart();
78
112
  watch(kitHome(), () => {
@@ -83,13 +117,20 @@ export async function resident() {
83
117
  });
84
118
  await placeSkillSet();
85
119
  await mkdir(agentBase(), { recursive: true });
86
- process.env.HOUSE_KIT_RESIDENT = String(process.pid);
87
- const agents = new Agents(house, () => changed());
88
- const copies = new LocalCopies(house);
89
- await copies.load();
90
120
  await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
91
121
  await installShim(codexLauncher(), 'codex-main');
122
+ }
123
+ export async function resident() {
124
+ await mkdir(kitHome(), { recursive: true, mode: 0o700 });
125
+ const copies = new LocalCopies(house);
126
+ await copies.load();
92
127
  await serveOwner(copies);
128
+ await started().catch((error) => {
129
+ report(error);
130
+ process.exit(1);
131
+ });
132
+ process.env.HOUSE_KIT_RESIDENT = String(process.pid);
133
+ const agents = new Agents(house, () => changed());
93
134
  let stream = null;
94
135
  let reported = false;
95
136
  const idle = () => conversations.idle() && signIns.idle() && agents.idle();
package/dist/stream.js CHANGED
@@ -81,7 +81,7 @@ export function holdStream(handlers) {
81
81
  return;
82
82
  }
83
83
  if (refused !== null && tooOld(refused.text))
84
- updateRequired(house);
84
+ updateRequired();
85
85
  if (finalRefusal(refused))
86
86
  end(refused.message);
87
87
  // 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/dist/work.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { once } from 'node:events';
3
3
  import { readFileSync } from 'node:fs';
4
- import { mkdir, rm } from 'node:fs/promises';
4
+ import { rm } from 'node:fs/promises';
5
5
  import { createServer } from 'node:net';
6
6
  import { join } from 'node:path';
7
7
  import { RUNNING_JOB } from './events.js';
8
- import { kitHome } from './home.js';
8
+ import { kitHome, socketDirectory } from './home.js';
9
9
  const ENDED_TASK = new Set(['completed', 'failed', 'killed']);
10
10
  const SCHEDULING = new Set(['CronCreate', 'CronDelete', 'ScheduleWakeup']);
11
11
  const QUEUE_LIST = 'house-kit-queue-';
@@ -194,9 +194,7 @@ class CodexWork extends Work {
194
194
  proving = -1;
195
195
  proven = -1;
196
196
  async open(cli) {
197
- const sockets = join(kitHome(), 'bridges');
198
- await mkdir(sockets, { recursive: true, mode: 0o700 });
199
- this.path = join(sockets, `${randomUUID()}.sock`);
197
+ this.path = join(socketDirectory(), `${randomUUID()}.sock`);
200
198
  this.server = createServer((socket) => this.connected(socket));
201
199
  this.server.listen(this.path);
202
200
  await once(this.server, 'listening');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-c9a26041e119a",
3
+ "version": "0.2.1-c9c41d009d46a",
4
4
  "description": "House Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {