@agentshouse/kit 0.2.1-cb0bd1cadcfed → 0.2.1-cbabe8ad337ff

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,53 +1,19 @@
1
+ import { spawn } from 'node:child_process';
1
2
  import { createHash, randomBytes } from 'node:crypto';
2
- import { createServer } from 'node:http';
3
3
  import { hostname } from 'node:os';
4
- import { createInterface } from 'node:readline/promises';
5
4
  import { parseArgs } from 'node:util';
6
- import { post } from './api.js';
5
+ import { post, retrying } from './api.js';
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
9
  const DEFAULT_HOUSE = 'https://agents.house';
10
- function listen() {
11
- return new Promise((resolve, reject) => {
12
- let deliver = () => undefined;
13
- let held = null;
14
- const code = new Promise((settle) => {
15
- deliver = settle;
16
- });
17
- const server = createServer((request, response) => {
18
- const received = new URL(request.url ?? '/', 'http://127.0.0.1').searchParams.get('code');
19
- if (received === null || held !== null) {
20
- response.writeHead(404).end();
21
- return;
22
- }
23
- held = response;
24
- deliver(received);
25
- });
26
- const close = () => {
27
- server.close();
28
- server.closeAllConnections();
29
- };
30
- const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
31
- server.once('error', reject);
32
- server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
33
- const address = server.address();
34
- if (address === null || typeof address === 'string') {
35
- reject(new Error('the login callback has no port'));
36
- return;
37
- }
38
- resolve({
39
- uri: `http://127.0.0.1:${address.port}/callback`,
40
- code,
41
- answer: (text) => new Promise((written) => {
42
- if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
43
- return written();
44
- held.once('close', () => written());
45
- held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
46
- }),
47
- close,
48
- });
49
- });
50
- });
10
+ const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
11
+ // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
12
+ const POLL_INTERVAL_MS = 2000;
13
+ function open(link) {
14
+ spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
15
+ .on('error', () => undefined)
16
+ .unref();
51
17
  }
52
18
  async function accepted(house, credential) {
53
19
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
@@ -57,25 +23,12 @@ async function accepted(house, credential) {
57
23
  return false;
58
24
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
59
25
  }
60
- async function typed(question) {
61
- const reader = createInterface({ input: process.stdin, output: process.stdout });
62
- const closed = new Promise((_, reject) => {
63
- reader.once('close', () => reject(new Error('no code was typed')));
64
- });
65
- try {
66
- return (await Promise.race([reader.question(question), closed])).trim();
67
- }
68
- finally {
69
- reader.close();
70
- }
71
- }
72
26
  export async function login(argv) {
73
27
  const { values } = parseArgs({
74
28
  args: argv,
75
29
  options: {
76
30
  house: { type: 'string' },
77
31
  environment: { type: 'string' },
78
- manual: { type: 'boolean', default: false },
79
32
  },
80
33
  });
81
34
  const enrolled = (await readEnrolment()) ?? (await readDisconnected());
@@ -85,52 +38,24 @@ export async function login(argv) {
85
38
  const ownAgent = await readOwnAgent();
86
39
  const held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
87
40
  const verifier = randomBytes(32).toString('base64url');
88
- const started = {
41
+ const started = await retrying(() => post(house, '/kit', {
89
42
  ...(environment === undefined
90
43
  ? { act: 'new_environment', label: hostname(), ...(replaces === undefined ? {} : { replaces }) }
91
44
  : { act: 'existing_environment', environment_id: environment }),
92
45
  code_challenge: createHash('sha256').update(verifier).digest('base64url'),
93
46
  ...(held ? {} : { headless: true }),
94
- };
95
- const exchange = async (code) => {
96
- const exchanged = await post(house, '/kit/token', { code, code_verifier: verifier });
97
- await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
98
- process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
99
- if (exchanged.headless_credential !== undefined) {
100
- await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
101
- }
102
- else if (held && ownAgent.user !== exchanged.user) {
103
- await forgetOwnAgent();
104
- process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
105
- }
106
- };
107
- if (values.manual) {
108
- const { start_url } = await post(house, '/kit', {
109
- ...started,
110
- presentation: 'manual',
111
- });
112
- process.stdout.write(`Open this link and confirm: ${start_url}\n`);
113
- await exchange(await typed('Code: '));
114
- return;
115
- }
116
- const callback = await listen();
117
- try {
118
- const { start_url } = await post(house, '/kit', {
119
- ...started,
120
- presentation: 'loopback',
121
- loopback_uri: callback.uri,
122
- });
123
- process.stdout.write(`Open this link and confirm: ${start_url}\n`);
124
- try {
125
- await exchange(await callback.code);
126
- }
127
- catch (error) {
128
- await callback.answer(`This Environment was not connected: ${error.message}`);
129
- throw error;
130
- }
131
- await callback.answer('This Environment is connected. You can close this tab.');
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 });
52
+ process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
53
+ if (exchanged.headless_credential !== undefined) {
54
+ await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
132
55
  }
133
- finally {
134
- callback.close();
56
+ else if (held && ownAgent.user !== exchanged.user) {
57
+ await forgetOwnAgent();
58
+ process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
135
59
  }
60
+ await placeAppGit(ownAgent, await readOwnAgent());
136
61
  }
package/dist/logout.js CHANGED
@@ -1,18 +1,21 @@
1
1
  import { HouseRefusal, post } from './api.js';
2
- import { forgetEnrolment, readEnrolment } from './home.js';
2
+ import { forgetAppGit } from './app-git.js';
3
+ import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
3
4
  export async function logout() {
4
5
  const enrolled = await readEnrolment();
5
- if (enrolled === null) {
6
- process.stdout.write('This computer is not connected to House.\n');
7
- return;
6
+ if (enrolled !== null) {
7
+ try {
8
+ await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
9
+ }
10
+ catch (error) {
11
+ if (!(error instanceof HouseRefusal && error.status === 401))
12
+ throw error;
13
+ }
14
+ await forgetEnrolment(enrolled);
8
15
  }
9
- try {
10
- await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
11
- }
12
- catch (error) {
13
- if (!(error instanceof HouseRefusal && error.status === 401))
14
- throw error;
15
- }
16
- await forgetEnrolment(enrolled);
17
- process.stdout.write(`Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
16
+ await forgetAppGit();
17
+ await forgetOwnAgent();
18
+ process.stdout.write(enrolled === null
19
+ ? 'This computer is not connected to House.\n'
20
+ : `Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
18
21
  }
package/dist/parts.js ADDED
@@ -0,0 +1,64 @@
1
+ export class Parts {
2
+ parts = [];
3
+ context = null;
4
+ emit;
5
+ writing = null;
6
+ planned = null;
7
+ constructor(emit) {
8
+ this.emit = emit;
9
+ }
10
+ write(type, id, text) {
11
+ if (text === '')
12
+ return;
13
+ const last = this.parts.length - 1;
14
+ const part = this.parts[last];
15
+ if (this.writing?.type === type && this.writing.id === id && part?.type === type) {
16
+ part.text += text;
17
+ this.emit({ op: 'append', index: last, text });
18
+ return;
19
+ }
20
+ this.start({ type, text });
21
+ this.writing = { type, id };
22
+ }
23
+ command() {
24
+ const last = this.parts.length - 1;
25
+ const part = this.parts[last];
26
+ if (part?.type !== 'commands') {
27
+ this.start({ type: 'commands', count: 1 });
28
+ return;
29
+ }
30
+ part.count++;
31
+ this.emit({ op: 'count', index: last, count: part.count });
32
+ }
33
+ start(part) {
34
+ this.writing = null;
35
+ this.parts.push(part);
36
+ const index = this.parts.length - 1;
37
+ this.emit({ op: 'start', index, part });
38
+ return index;
39
+ }
40
+ done(index, result) {
41
+ const part = this.parts[index];
42
+ part.status = 'done';
43
+ part.result = result;
44
+ this.emit({ op: 'status', index, status: 'done', result });
45
+ }
46
+ plan(entries) {
47
+ if (this.planned === null) {
48
+ this.planned = this.start({ type: 'plan', entries });
49
+ return;
50
+ }
51
+ this.parts[this.planned].entries = entries;
52
+ this.emit({ op: 'plan', index: this.planned, entries });
53
+ }
54
+ measure(context) {
55
+ this.context = context;
56
+ this.emit({ op: 'context', ...context });
57
+ }
58
+ operations() {
59
+ return [
60
+ ...this.parts.map((part, index) => ({ op: 'start', index, part })),
61
+ ...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
62
+ ];
63
+ }
64
+ }
package/dist/resident.js CHANGED
@@ -2,34 +2,31 @@ import { once } from 'node:events';
2
2
  import { watch } from 'node:fs';
3
3
  import { mkdir, rm, writeFile } from 'node:fs/promises';
4
4
  import { createServer } from 'node:http';
5
- import { extname, join } from 'node:path';
5
+ import { dirname, extname, join } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
- import { killDescendants } from './acp.js';
8
7
  import { Agents } from './agents.js';
9
8
  import { house } from './api.js';
10
9
  import { received } from './bridge.js';
11
10
  import { Conversations } from './conversations.js';
12
11
  import { LocalCopies } from './copies.js';
13
12
  import { agentBase, enrolled, kitHome } from './home.js';
13
+ import { killDescendants } from './scope.js';
14
+ import { quoted } from './shell.js';
14
15
  import { SignIns } from './sign-in.js';
15
16
  import { placeSkillSet } from './skills.js';
16
17
  import { holdStream } from './stream.js';
17
18
  import { Updates } from './update.js';
19
+ import { codexLauncher } from './work.js';
18
20
  function report(error) {
19
21
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
20
22
  }
21
23
  function logged(work) {
22
24
  work.catch(report);
23
25
  }
24
- function quoted(value) {
25
- return `'${value.replaceAll("'", `'\\''`)}'`;
26
- }
27
- async function installShim() {
28
- const main = fileURLToPath(new URL(`./git-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
29
- await mkdir(join(kitHome(), 'shim'), { recursive: true });
30
- await writeFile(join(kitHome(), 'shim', 'git'), `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, {
31
- mode: 0o755,
32
- });
26
+ async function installShim(path, module) {
27
+ const main = fileURLToPath(new URL(`./${module}${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
28
+ await mkdir(dirname(path), { recursive: true });
29
+ await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
33
30
  }
34
31
  async function serveOwner(copies) {
35
32
  const socketPath = join(kitHome(), 'owner.sock');
@@ -81,7 +78,8 @@ export async function resident() {
81
78
  const agents = new Agents(house);
82
79
  const copies = new LocalCopies(house);
83
80
  await copies.load();
84
- await installShim();
81
+ await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
82
+ await installShim(codexLauncher(), 'codex-main');
85
83
  await serveOwner(copies);
86
84
  let stream = null;
87
85
  let reported = false;
@@ -120,6 +118,8 @@ export async function resident() {
120
118
  logged(copies.select());
121
119
  },
122
120
  frame: (arrived) => {
121
+ if (arrived.type === 'watching')
122
+ conversations.watching(arrived.watching === true);
123
123
  if (arrived.type === 'work_available' && arrived.subject === 'agents')
124
124
  logged(agents.refresh());
125
125
  if (arrived.type === 'work_available' && arrived.subject === 'local_copy')
package/dist/scope.js ADDED
@@ -0,0 +1,203 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { mkdirSync, readdirSync, readFileSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ const LISTING_BYTES = 1 << 28;
5
+ const CGROUPS = '/sys/fs/cgroup';
6
+ const GONE = new Set(['ENOENT', 'ESRCH']);
7
+ function failure(error) {
8
+ return error.code ?? '';
9
+ }
10
+ function listed(environment) {
11
+ const found = new Map();
12
+ const output = execFileSync('ps', [environment ? '-AEww' : '-Aww', '-o', 'pid=,ppid=,sess=,command='], {
13
+ encoding: 'utf8',
14
+ maxBuffer: LISTING_BYTES,
15
+ });
16
+ for (const line of output.split('\n')) {
17
+ const fields = /^\s*(\d+)\s+(\d+)\s+(\S+)\s?(.*)$/.exec(line);
18
+ if (fields !== null)
19
+ found.set(Number(fields[1]), { parent: Number(fields[2]), session: fields[3], command: fields[4] });
20
+ }
21
+ return found;
22
+ }
23
+ function read(pid) {
24
+ try {
25
+ const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
26
+ const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
27
+ const command = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replaceAll('\0', ' ');
28
+ return { parent: Number(fields[1]), session: fields[3], command };
29
+ }
30
+ catch (error) {
31
+ if (GONE.has(failure(error)))
32
+ return null;
33
+ throw error;
34
+ }
35
+ }
36
+ function processes() {
37
+ if (process.platform === 'darwin')
38
+ return listed(false);
39
+ const found = new Map();
40
+ for (const entry of readdirSync('/proc')) {
41
+ const running = /^\d+$/.test(entry) ? read(entry) : null;
42
+ if (running !== null)
43
+ found.set(Number(entry), running);
44
+ }
45
+ return found;
46
+ }
47
+ function descendants(roots, table = processes()) {
48
+ const children = new Map();
49
+ for (const [pid, { parent }] of table)
50
+ children.set(parent, [...(children.get(parent) ?? []), pid]);
51
+ const tree = [];
52
+ const pending = roots.flatMap((root) => children.get(root) ?? []);
53
+ while (pending.length > 0) {
54
+ const pid = pending.pop();
55
+ tree.push(pid);
56
+ pending.push(...(children.get(pid) ?? []));
57
+ }
58
+ return tree;
59
+ }
60
+ function marked(marker, doubted) {
61
+ if (process.platform === 'darwin') {
62
+ return [...listed(true)].filter(([, { command }]) => ` ${command} `.includes(` ${marker} `)).map(([pid]) => pid);
63
+ }
64
+ return readdirSync('/proc')
65
+ .filter((entry) => /^\d+$/.test(entry) && carries(entry, marker, doubted))
66
+ .map(Number);
67
+ }
68
+ function carries(pid, marker, doubted) {
69
+ try {
70
+ return readFileSync(`/proc/${pid}/environ`, 'utf8').split('\0').includes(marker);
71
+ }
72
+ catch (error) {
73
+ if (GONE.has(failure(error)))
74
+ return false;
75
+ if (failure(error) !== 'EACCES')
76
+ throw error;
77
+ return doubted && statSync(`/proc/${pid}`, { throwIfNoEntry: false })?.uid === process.getuid();
78
+ }
79
+ }
80
+ function killAll(pids) {
81
+ for (const pid of pids) {
82
+ for (const target of [-pid, pid]) {
83
+ try {
84
+ process.kill(target, 'SIGKILL');
85
+ }
86
+ catch { }
87
+ }
88
+ }
89
+ }
90
+ export function killTree(child) {
91
+ killAll([child.pid, ...descendants([child.pid])]);
92
+ }
93
+ export function killMarked(marker) {
94
+ const pids = marked(marker, false);
95
+ killAll([...pids, ...descendants(pids)]);
96
+ }
97
+ export function killDescendants() {
98
+ const pids = marked(`HOUSE_KIT_RESIDENT=${process.pid}`, false);
99
+ killAll([...pids, ...descendants([process.pid, ...pids])]);
100
+ }
101
+ function ownGroup() {
102
+ if (process.platform !== 'linux')
103
+ return null;
104
+ try {
105
+ const line = readFileSync('/proc/self/cgroup', 'utf8')
106
+ .split('\n')
107
+ .find((entry) => entry.startsWith('0::'));
108
+ return line === undefined ? null : join(CGROUPS, line.slice(3));
109
+ }
110
+ catch {
111
+ return null;
112
+ }
113
+ }
114
+ function members(group) {
115
+ const pids = readFileSync(join(group, 'cgroup.procs'), 'utf8').split('\n').filter(Boolean).map(Number);
116
+ for (const entry of readdirSync(group, { withFileTypes: true })) {
117
+ if (entry.isDirectory())
118
+ pids.push(...members(join(group, entry.name)));
119
+ }
120
+ return pids;
121
+ }
122
+ export class Scope {
123
+ marker;
124
+ cli;
125
+ group;
126
+ session = null;
127
+ recorded = null;
128
+ constructor(marker, name, cli) {
129
+ this.marker = marker;
130
+ this.cli = cli;
131
+ const own = ownGroup();
132
+ this.group = own === null ? null : join(own, name);
133
+ try {
134
+ if (this.group !== null)
135
+ mkdirSync(this.group);
136
+ }
137
+ catch {
138
+ this.group = null;
139
+ }
140
+ }
141
+ command(command, args) {
142
+ if (this.group === null)
143
+ return [command, args];
144
+ return ['/bin/sh', ['-c', 'echo $$ > "$0/cgroup.procs" 2>/dev/null; exec "$@"', this.group, command, ...args]];
145
+ }
146
+ entered(pid) {
147
+ this.session = process.platform === 'darwin' ? (listed(false).get(pid)?.session ?? null) : String(pid);
148
+ if (this.group === null)
149
+ return;
150
+ const joined = readFileSync(`/proc/${pid}/cgroup`, 'utf8').split('\n').find((entry) => entry.startsWith('0::'));
151
+ if (joined !== undefined && join(CGROUPS, joined.slice(3)) === this.group)
152
+ return;
153
+ this.close();
154
+ this.group = null;
155
+ }
156
+ record() {
157
+ const found = this.found();
158
+ if (found === null)
159
+ return;
160
+ this.recorded = new Set([...found].filter(([, { session }]) => session === this.session).map(([pid]) => pid));
161
+ }
162
+ working() {
163
+ const found = this.found();
164
+ if (found === null)
165
+ return true;
166
+ if (this.recorded === null)
167
+ return found.size > 0;
168
+ return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || command.startsWith(`${this.cli}-`)));
169
+ }
170
+ empty() {
171
+ return this.found()?.size === 0;
172
+ }
173
+ kill() {
174
+ killMarked(this.marker);
175
+ if (this.group === null)
176
+ return;
177
+ try {
178
+ writeFileSync(join(this.group, 'cgroup.kill'), '1');
179
+ }
180
+ catch {
181
+ killAll([...(this.found()?.keys() ?? [])]);
182
+ }
183
+ }
184
+ close() {
185
+ if (this.group === null)
186
+ return;
187
+ try {
188
+ rmdirSync(this.group);
189
+ }
190
+ catch { }
191
+ }
192
+ found() {
193
+ try {
194
+ const table = processes();
195
+ const roots = this.group === null ? marked(this.marker, true) : members(this.group);
196
+ const pids = this.group === null ? [...roots, ...descendants(roots, table)] : roots;
197
+ return new Map(pids.flatMap((pid) => (table.has(pid) ? [[pid, table.get(pid)]] : [])));
198
+ }
199
+ catch {
200
+ return null;
201
+ }
202
+ }
203
+ }
package/dist/shell.js ADDED
@@ -0,0 +1,3 @@
1
+ export function quoted(value) {
2
+ return `'${value.replaceAll("'", `'\\''`)}'`;
3
+ }
package/dist/sign-in.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createInterface } from 'node:readline';
3
- import { killTree } from './acp.js';
4
3
  import { CLIS, withoutProxy } from './clis.js';
4
+ import { killTree } from './scope.js';
5
5
  import { holdSecretInput } from './secret-input.js';
6
6
  const ESCAPE = /\u001b\[[\d;]*m/g;
7
7
  const LINK = /https:\/\/\S+/;
@@ -12,6 +12,9 @@ function causeOf(error) {
12
12
  function logged(error) {
13
13
  process.stderr.write(`kit: ${causeOf(error)}\n`);
14
14
  }
15
+ function endOf(signal) {
16
+ return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
17
+ }
15
18
  export class SignIns {
16
19
  house;
17
20
  agents;
@@ -30,25 +33,43 @@ export class SignIns {
30
33
  return;
31
34
  this.running.add(input.input_id);
32
35
  this.changed();
33
- this.login(input)
34
- .then(() => this.agents.recheck(input.cli))
35
- .then(() => this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {}))
36
- .then(() => this.agents.reread(input.cli))
36
+ this.signIn(input)
37
37
  .catch(logged)
38
38
  .finally(() => {
39
39
  this.running.delete(input.input_id);
40
40
  this.changed();
41
41
  });
42
42
  }
43
- async login(input) {
43
+ async signIn(input) {
44
+ const ending = new AbortController();
45
+ // 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.
46
+ const timer = setTimeout(() => ending.abort(), input.ends_in * 1000);
47
+ const ended = await Promise.race([this.signedIn(input, ending.signal), endOf(ending.signal)]);
48
+ clearTimeout(timer);
49
+ if (ended)
50
+ process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
51
+ await this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {});
52
+ if (!ended)
53
+ await this.agents.reread(input.cli);
54
+ }
55
+ async signedIn(input, signal) {
56
+ await this.login(input, signal);
57
+ if (!signal.aborted)
58
+ await this.agents.recheck(input.cli, signal);
59
+ return false;
60
+ }
61
+ async login(input, signal) {
44
62
  let cli;
45
63
  try {
46
- cli = await this.agents.located(input.cli);
64
+ cli = await this.agents.located(input.cli, signal);
47
65
  }
48
66
  catch (error) {
49
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
67
+ if (!signal.aborted)
68
+ process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
50
69
  return;
51
70
  }
71
+ if (signal.aborted)
72
+ return;
52
73
  const login = CLIS[input.cli].login;
53
74
  const child = spawn(cli, login.args, {
54
75
  stdio: ['pipe', 'pipe', 'pipe'],
@@ -56,6 +77,8 @@ export class SignIns {
56
77
  env: withoutProxy(),
57
78
  });
58
79
  const running = () => child.exitCode === null && child.signalCode === null;
80
+ const stop = () => killTree(child);
81
+ signal.addEventListener('abort', stop, { once: true });
59
82
  let link;
60
83
  let code;
61
84
  let last = '';
@@ -92,9 +115,10 @@ export class SignIns {
92
115
  createInterface({ input: output }).on('line', read);
93
116
  const failed = await new Promise((resolve) => {
94
117
  child.on('error', (error) => resolve(error.message));
95
- child.on('close', (status, signal) => resolve(status === 0 ? null : `exited with ${status ?? signal}${last ? `: ${last}` : ''}`));
118
+ child.on('close', (status, killed) => resolve(status === 0 ? null : `exited with ${status ?? killed}${last ? `: ${last}` : ''}`));
96
119
  });
97
- if (failed !== null)
120
+ signal.removeEventListener('abort', stop);
121
+ if (failed !== null && !signal.aborted)
98
122
  process.stderr.write(`kit: the ${input.cli} sign-in failed: ${failed}\n`);
99
123
  }
100
124
  }