@agentshouse/kit 0.2.1-c5262a8cc063d → 0.2.1-c5883630417e1

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.
Files changed (100) hide show
  1. package/README.md +27 -26
  2. package/dist/acp.js +16 -93
  3. package/dist/agents.js +104 -42
  4. package/dist/api.js +36 -3
  5. package/dist/app-git.js +64 -0
  6. package/dist/bootstrap.json +4 -4
  7. package/dist/bridge.js +36 -52
  8. package/dist/chatgpt.js +26 -0
  9. package/dist/clis.js +128 -65
  10. package/dist/codex-main.js +58 -0
  11. package/dist/conversations.js +288 -236
  12. package/dist/copies.js +167 -139
  13. package/dist/end.js +22 -0
  14. package/dist/enrol-main.js +7 -1
  15. package/dist/events.js +521 -0
  16. package/dist/files.js +23 -2
  17. package/dist/git.js +11 -8
  18. package/dist/home.js +81 -6
  19. package/dist/house-main.js +186 -56
  20. package/dist/instructions.js +9 -32
  21. package/dist/kit-main.js +54 -6
  22. package/dist/login.js +109 -103
  23. package/dist/logout.js +16 -13
  24. package/dist/mcp.js +2 -1
  25. package/dist/parts.js +82 -0
  26. package/dist/placement.js +48 -0
  27. package/dist/refusals.js +12 -0
  28. package/dist/relay.js +20 -0
  29. package/dist/resident.js +38 -27
  30. package/dist/scope.js +203 -0
  31. package/dist/secret-input.js +4 -1
  32. package/dist/service-main.js +9 -0
  33. package/dist/service.js +33 -0
  34. package/dist/shell.js +3 -0
  35. package/dist/sign-in.js +34 -9
  36. package/dist/skills.js +81 -12
  37. package/dist/stream.js +37 -6
  38. package/dist/transcription.js +57 -9
  39. package/dist/update.js +30 -6
  40. package/dist/wire.js +6 -0
  41. package/dist/work.js +348 -0
  42. package/how-we-work.md +13 -3
  43. package/package.json +3 -2
  44. package/skills/ask-matt/SKILL.md +17 -11
  45. package/skills/ask-matt/agents/openai.yaml +1 -0
  46. package/skills/code-review/SKILL.md +5 -5
  47. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  48. package/skills/codebase-design/SKILL.md +0 -2
  49. package/skills/diagnosing-bugs/SKILL.md +2 -4
  50. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  51. package/skills/domain-modeling/SKILL.md +12 -14
  52. package/skills/grill-me/SKILL.md +1 -2
  53. package/skills/grill-me/agents/openai.yaml +1 -0
  54. package/skills/grill-with-docs/SKILL.md +1 -2
  55. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  56. package/skills/grilling/SKILL.md +2 -2
  57. package/skills/handoff/SKILL.md +2 -3
  58. package/skills/handoff/agents/openai.yaml +1 -0
  59. package/skills/implement/SKILL.md +5 -4
  60. package/skills/implement/agents/openai.yaml +1 -0
  61. package/skills/implement-spec/SKILL.md +40 -0
  62. package/skills/implement-spec/agents/openai.yaml +5 -0
  63. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  64. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  65. package/skills/pr/CREDITS.md +3 -0
  66. package/skills/pr/LICENSE +21 -0
  67. package/skills/pr/SKILL.md +170 -0
  68. package/skills/pr/agents/openai.yaml +3 -0
  69. package/skills/prototype/SKILL.md +0 -2
  70. package/skills/research/SKILL.md +0 -2
  71. package/skills/retro/LICENSE +21 -0
  72. package/skills/retro/SKILL.md +44 -0
  73. package/skills/retro/agents/openai.yaml +5 -0
  74. package/skills/tdd/SKILL.md +2 -4
  75. package/skills/teach/SKILL.md +3 -4
  76. package/skills/teach/agents/openai.yaml +1 -0
  77. package/skills/to-questionnaire/SKILL.md +1 -2
  78. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  79. package/skills/to-spec/SKILL.md +1 -2
  80. package/skills/to-spec/agents/openai.yaml +1 -0
  81. package/skills/to-tickets/SKILL.md +3 -4
  82. package/skills/to-tickets/agents/openai.yaml +1 -0
  83. package/skills/triage/AGENT-BRIEF.md +207 -0
  84. package/skills/triage/LICENSE +21 -0
  85. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  86. package/skills/triage/SKILL.md +112 -0
  87. package/skills/triage/agents/openai.yaml +5 -0
  88. package/skills/wait-what/SKILL.md +2 -3
  89. package/skills/wait-what/agents/openai.yaml +1 -0
  90. package/skills/wayfinder/SKILL.md +5 -6
  91. package/skills/wayfinder/agents/openai.yaml +1 -0
  92. package/skills/wizard/LICENSE +21 -0
  93. package/skills/wizard/SKILL.md +44 -0
  94. package/skills/wizard/agents/openai.yaml +3 -0
  95. package/skills/wizard/template.sh +223 -0
  96. package/skills/writing-for-agents/SKILL.md +0 -2
  97. package/dist/blocks.js +0 -51
  98. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  99. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  100. /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/dist/login.js CHANGED
@@ -1,55 +1,26 @@
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';
7
- import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
5
+ import { HouseRefusal, post, retrying } from './api.js';
6
+ import { placeAppGit } from './app-git.js';
7
+ import { writeCodexRule } from './clis.js';
8
+ import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
8
9
  import { callHouse, rpc } from './mcp.js';
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
+ import { refusalOf } from './refusals.js';
11
+ import { selectRelay } from './relay.js';
12
+ import { startService } from './service.js';
13
+ import { placeSkillSet } from './skills.js';
14
+ export const DEFAULT_HOUSE = 'https://agents.house';
15
+ const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
16
+ // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
17
+ const POLL_INTERVAL_MS = 2000;
18
+ function open(link) {
19
+ spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
20
+ .on('error', () => undefined)
21
+ .unref();
51
22
  }
52
- async function accepted(house, credential) {
23
+ export async function accepted(house, credential) {
53
24
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
54
25
  if (checked.status === 200)
55
26
  return true;
@@ -57,17 +28,23 @@ async function accepted(house, credential) {
57
28
  return false;
58
29
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
59
30
  }
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
- }
31
+ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
32
+ kit login [--house <origin>] --code <code>
33
+ --house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
34
+ --environment <id> reconnect this Environment
35
+ --rooms <ref>[,<ref>...] give this Environment only these Rooms
36
+ --no-private give this Environment every Room but your Private Room
37
+ --code <code> connect this machine with a login code
38
+ `;
39
+ function gone(error) {
40
+ return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
41
+ }
42
+ function chosenRooms(rooms, noPrivate) {
43
+ if (rooms !== undefined && noPrivate)
44
+ throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
45
+ if (rooms !== undefined)
46
+ return { rooms: { reach: 'selected', refs: rooms.split(',') } };
47
+ return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
71
48
  }
72
49
  export async function login(argv) {
73
50
  const { values } = parseArgs({
@@ -75,62 +52,91 @@ export async function login(argv) {
75
52
  options: {
76
53
  house: { type: 'string' },
77
54
  environment: { type: 'string' },
78
- manual: { type: 'boolean', default: false },
55
+ rooms: { type: 'string' },
56
+ 'no-private': { type: 'boolean', default: false },
57
+ code: { type: 'string' },
58
+ help: { type: 'boolean', default: false },
79
59
  },
80
60
  });
61
+ if (values.help) {
62
+ process.stdout.write(USAGE);
63
+ return;
64
+ }
65
+ if (values.code !== undefined && values.rooms !== undefined)
66
+ throw new Error('--code cannot be used with --rooms');
67
+ if (values.code !== undefined && values['no-private'])
68
+ throw new Error('--code cannot be used with --no-private');
69
+ if (values.code !== undefined && values.environment !== undefined)
70
+ throw new Error('--code cannot be used with --environment');
71
+ const rooms = chosenRooms(values.rooms, values['no-private']);
81
72
  const enrolled = (await readEnrolment()) ?? (await readDisconnected());
73
+ if (values.code !== undefined && enrolled !== null) {
74
+ throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
75
+ }
76
+ const relay = process.env.HOUSE_KIT_RELAY || undefined;
77
+ selectRelay(relay);
82
78
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
83
79
  const replaces = process.env.HOUSE_KIT_REPLACES;
84
- const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
80
+ const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
81
+ const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
85
82
  const ownAgent = await readOwnAgent();
86
- const held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
87
- const verifier = randomBytes(32).toString('base64url');
88
- const started = {
89
- ...(environment === undefined
90
- ? { act: 'new_environment', label: hostname(), ...(replaces === undefined ? {} : { replaces }) }
91
- : { act: 'existing_environment', environment_id: environment }),
92
- code_challenge: createHash('sha256').update(verifier).digest('base64url'),
93
- ...(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;
83
+ let held = false;
84
+ let exchanged;
85
+ if (values.code !== undefined) {
86
+ exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
115
87
  }
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`);
88
+ else {
89
+ held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
90
+ const verifier = randomBytes(32).toString('base64url');
91
+ const start = (named) => retrying(() => post(house, '/kit', {
92
+ label: hostname(),
93
+ ...(named === undefined
94
+ ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
95
+ : { act: 'existing_environment', environment_id: named }),
96
+ ...rooms,
97
+ code_challenge: createHash('sha256').update(verifier).digest('base64url'),
98
+ ...(held ? {} : { headless: true }),
99
+ }));
100
+ let started;
124
101
  try {
125
- await exchange(await callback.code);
102
+ started = await start(environment);
126
103
  }
127
104
  catch (error) {
128
- await callback.answer(`This Environment was not connected: ${error.message}`);
129
- throw error;
105
+ if (remembered === undefined || !gone(error))
106
+ throw error;
107
+ await forgetDisconnected();
108
+ process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
109
+ started = await start(undefined);
130
110
  }
131
- await callback.answer('This Environment is connected. You can close this tab.');
111
+ process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
112
+ open(started.start_url);
113
+ exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
114
+ }
115
+ await placeSkillSet();
116
+ await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
117
+ const relayRecord = relay === undefined ? {} : { relay };
118
+ await writeEnrolment({
119
+ house,
120
+ ...relayRecord,
121
+ environment: exchanged.environment,
122
+ credential: exchanged.credential,
123
+ });
124
+ process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
125
+ if (exchanged.headless_credential !== undefined) {
126
+ await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
127
+ }
128
+ else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
129
+ await forgetOwnAgent();
130
+ process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
131
+ }
132
+ else if (held && ownAgent !== null) {
133
+ await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
134
+ }
135
+ await placeAppGit(ownAgent, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
136
+ try {
137
+ startService();
132
138
  }
133
- finally {
134
- callback.close();
139
+ catch (error) {
140
+ process.stderr.write(`kit: ${error.message}\n`);
135
141
  }
136
142
  }
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/mcp.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { KIT_VERSION } from './clis.js';
3
+ import { relayed } from './relay.js';
3
4
  const MCP_PROTOCOL_VERSION = '2026-07-28';
4
5
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
5
6
  export function rpc(method, params) {
@@ -21,7 +22,7 @@ export function mcpBody(message, operation) {
21
22
  }
22
23
  export async function callHouse(origin, credential, message, operation = null, signal) {
23
24
  const tool = message.method === 'tools/call' ? String(message.params.name) : null;
24
- const answer = await fetch(new URL('/', origin), {
25
+ const answer = await fetch(relayed(new URL('/', origin)), {
25
26
  method: 'POST',
26
27
  headers: {
27
28
  'content-type': 'application/json',
package/dist/parts.js ADDED
@@ -0,0 +1,82 @@
1
+ export class Parts {
2
+ parts = [];
3
+ context = null;
4
+ emit;
5
+ made = [];
6
+ events = 0;
7
+ writing = null;
8
+ counting = null;
9
+ planned = null;
10
+ constructor(emit) {
11
+ this.emit = emit;
12
+ }
13
+ write(type, id, text) {
14
+ if (text === '')
15
+ return;
16
+ if (this.writing?.type === type && this.writing.id === id) {
17
+ this.parts[this.writing.index].text += text;
18
+ this.emit({ op: 'append', index: this.writing.index, text });
19
+ return;
20
+ }
21
+ this.writing = { type, id, index: this.start({ type, text }) };
22
+ }
23
+ command() {
24
+ if (this.counting === null) {
25
+ this.counting = this.start({ type: 'commands', count: 1 });
26
+ return;
27
+ }
28
+ const part = this.parts[this.counting];
29
+ part.count++;
30
+ this.emit({ op: 'count', index: this.counting, count: part.count });
31
+ }
32
+ start(part) {
33
+ this.writing = null;
34
+ this.counting = null;
35
+ return this.add(part, ++this.events);
36
+ }
37
+ reserve() {
38
+ this.writing = null;
39
+ this.counting = null;
40
+ return ++this.events;
41
+ }
42
+ arrive(part, reserved) {
43
+ this.add(part, reserved);
44
+ }
45
+ done(index, result) {
46
+ const part = this.parts[index];
47
+ part.status = 'done';
48
+ part.result = result;
49
+ this.emit({ op: 'status', index, status: 'done', result });
50
+ }
51
+ plan(entries) {
52
+ if (this.planned === null) {
53
+ this.planned = this.start({ type: 'plan', entries });
54
+ return;
55
+ }
56
+ this.parts[this.planned].entries = entries;
57
+ this.emit({ op: 'plan', index: this.planned, entries });
58
+ }
59
+ measure(context) {
60
+ this.context = context;
61
+ this.emit({ op: 'context', ...context });
62
+ }
63
+ saved() {
64
+ return this.parts
65
+ .map((part, index) => ({ part, made: this.made[index] }))
66
+ .sort((a, b) => a.made - b.made)
67
+ .map(({ part }) => part);
68
+ }
69
+ operations() {
70
+ return [
71
+ ...this.parts.map((part, index) => ({ op: 'start', index, part })),
72
+ ...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
73
+ ];
74
+ }
75
+ add(part, made) {
76
+ this.parts.push(part);
77
+ this.made.push(made);
78
+ const index = this.parts.length - 1;
79
+ this.emit({ op: 'start', index, part });
80
+ return index;
81
+ }
82
+ }
@@ -0,0 +1,48 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { run } from './clis.js';
4
+ import { kitHome } from './home.js';
5
+ import { relayOrigin } from './relay.js';
6
+ export function service() {
7
+ if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
8
+ return null;
9
+ return process.env.MANAGERPID ? 'user' : 'system';
10
+ }
11
+ export function throughSudo() {
12
+ return service() === 'system' && process.getuid() !== 0;
13
+ }
14
+ export async function updatesItself() {
15
+ if (service() === null)
16
+ return false;
17
+ if (!throughSudo())
18
+ return true;
19
+ // sudo answers at once, so ten seconds only bounds a stuck sudo.
20
+ return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
21
+ }
22
+ function installed() {
23
+ try {
24
+ return readFileSync(join(kitHome(), 'placement'), 'utf8').trim();
25
+ }
26
+ catch (error) {
27
+ if (error.code === 'ENOENT')
28
+ return null;
29
+ throw error;
30
+ }
31
+ }
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/refusals.js CHANGED
@@ -21,6 +21,18 @@ function spoken(text) {
21
21
  const detail = said.indexOf('\n');
22
22
  return { code: head[1], text: said, conflicts: detail === -1 ? [] : conflictCodes(said.slice(detail + 1)) };
23
23
  }
24
+ export function retryable(text) {
25
+ let body;
26
+ try {
27
+ body = JSON.parse(text);
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ const error = body?.error;
33
+ const verdict = error?.retryable ?? error?.data?.retryable;
34
+ return typeof verdict === 'boolean' ? verdict : null;
35
+ }
24
36
  export function refusalOf(text) {
25
37
  let body;
26
38
  try {
package/dist/relay.js ADDED
@@ -0,0 +1,20 @@
1
+ let selected;
2
+ export function selectRelay(relay) {
3
+ selected = relay === undefined || relay === '' ? null : relay;
4
+ }
5
+ export 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
+ }
11
+ export function relayed(target) {
12
+ const url = new URL(target);
13
+ const relay = relayOrigin();
14
+ if (relay === undefined)
15
+ return url;
16
+ const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
17
+ if (url.protocol === 'wss:' || url.protocol === 'ws:')
18
+ through.protocol = 'wss:';
19
+ return through;
20
+ }
package/dist/resident.js CHANGED
@@ -2,47 +2,52 @@ 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
- import { Conversations } from './conversations.js';
10
+ import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
12
11
  import { LocalCopies } from './copies.js';
13
- import { agentBase, enrolled, kitHome } from './home.js';
12
+ import { restart } from './end.js';
13
+ import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
14
+ import { killDescendants } from './scope.js';
15
+ import { quoted } from './shell.js';
14
16
  import { SignIns } from './sign-in.js';
15
17
  import { placeSkillSet } from './skills.js';
16
18
  import { holdStream } from './stream.js';
17
19
  import { Updates } from './update.js';
20
+ import { codexLauncher } from './work.js';
18
21
  function report(error) {
19
22
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
20
23
  }
21
24
  function logged(work) {
22
25
  work.catch(report);
23
26
  }
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
- });
27
+ async function installShim(path, module) {
28
+ const main = fileURLToPath(new URL(`./${module}${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
29
+ await mkdir(dirname(path), { recursive: true });
30
+ await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
33
31
  }
34
32
  async function serveOwner(copies) {
35
33
  const socketPath = join(kitHome(), 'owner.sock');
36
34
  await rm(socketPath, { force: true });
37
35
  const server = createServer(async (request, response) => {
38
36
  try {
39
- if (request.url !== '/git/push') {
37
+ const text = await received(request);
38
+ let answered;
39
+ if (request.url === '/git/fetch') {
40
+ answered = await copies.fetch();
41
+ }
42
+ else if (request.url === '/git/push') {
43
+ const { cwd, commit } = JSON.parse(text);
44
+ answered = await copies.push(cwd, commit, copies.owner);
45
+ }
46
+ else {
40
47
  response.writeHead(404).end();
41
48
  return;
42
49
  }
43
- const { cwd, commit } = JSON.parse(await received(request));
44
- const pushed = await copies.push(cwd, commit, copies.owner);
45
- response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(pushed));
50
+ response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(answered));
46
51
  }
47
52
  catch (error) {
48
53
  response.writeHead(502).end(error instanceof Error ? error.message : String(error));
@@ -69,6 +74,7 @@ function connected() {
69
74
  }
70
75
  export async function resident() {
71
76
  await connected();
77
+ await forgetRestart();
72
78
  watch(kitHome(), () => {
73
79
  if (enrolled())
74
80
  return;
@@ -78,18 +84,22 @@ export async function resident() {
78
84
  await placeSkillSet();
79
85
  await mkdir(agentBase(), { recursive: true });
80
86
  process.env.HOUSE_KIT_RESIDENT = String(process.pid);
81
- const agents = new Agents(house);
87
+ const agents = new Agents(house, () => changed());
82
88
  const copies = new LocalCopies(house);
83
89
  await copies.load();
84
- await installShim();
90
+ await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
91
+ await installShim(codexLauncher(), 'codex-main');
85
92
  await serveOwner(copies);
86
93
  let stream = null;
87
94
  let reported = false;
88
- const idle = () => conversations.idle() && signIns.idle();
95
+ const idle = () => conversations.idle() && signIns.idle() && agents.idle();
89
96
  const changed = () => {
90
97
  if (!idle()) {
91
98
  reported = false;
92
99
  }
100
+ else if (restartAsked() && conversations.quiet()) {
101
+ restart('restarting for an updated CLI');
102
+ }
93
103
  else if (!reported) {
94
104
  reported = true;
95
105
  logged(house.deliver('/kit/idle', {}, idle));
@@ -117,24 +127,25 @@ export async function resident() {
117
127
  opened: () => {
118
128
  conversations.opened();
119
129
  changed();
120
- logged(copies.select());
130
+ logged(copies.connected());
121
131
  },
122
132
  frame: (arrived) => {
133
+ if (arrived.type === 'watching')
134
+ conversations.watching(arrived.watching === true);
123
135
  if (arrived.type === 'work_available' && arrived.subject === 'agents')
124
136
  logged(agents.refresh());
125
- if (arrived.type === 'work_available' && arrived.subject === 'local_copy')
126
- logged(copies.select());
127
- if (arrived.type === 'entries') {
128
- copies.entries(arrived);
129
- }
130
137
  if (arrived.type === 'input') {
131
138
  reported = false;
132
139
  if (arrived.kind === 'sign_in')
133
140
  signIns.start(arrived);
134
141
  else if (arrived.kind === 'update')
135
142
  updates.start(arrived);
136
- else
143
+ else if (CONVERSATION_INPUTS.has(arrived.kind))
137
144
  conversations.input(arrived);
145
+ else {
146
+ const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
147
+ logged(house.deliver(`/kit/inputs/${arrived.input_id}/ack`, refused).finally(changed));
148
+ }
138
149
  }
139
150
  },
140
151
  });