@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-cf3a50c90b895

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 (105) hide show
  1. package/README.md +40 -39
  2. package/dist/acp.js +48 -105
  3. package/dist/agents.js +153 -43
  4. package/dist/api.js +34 -2
  5. package/dist/app-git.js +48 -0
  6. package/dist/bootstrap.json +4 -4
  7. package/dist/bridge.js +36 -57
  8. package/dist/calls.js +63 -0
  9. package/dist/chatgpt.js +32 -0
  10. package/dist/clis.js +127 -70
  11. package/dist/codex-main.js +58 -0
  12. package/dist/connection.js +125 -0
  13. package/dist/conversations.js +540 -305
  14. package/dist/copies.js +188 -128
  15. package/dist/end.js +27 -0
  16. package/dist/enrol-main.js +7 -1
  17. package/dist/events.js +525 -0
  18. package/dist/files.js +22 -2
  19. package/dist/git.js +11 -9
  20. package/dist/home.js +96 -7
  21. package/dist/house-cli.js +291 -0
  22. package/dist/house-main.js +7 -159
  23. package/dist/instructions.js +10 -32
  24. package/dist/kit-cli.js +68 -0
  25. package/dist/kit-main.js +8 -19
  26. package/dist/login.js +118 -103
  27. package/dist/logout.js +14 -13
  28. package/dist/mcp.js +2 -2
  29. package/dist/parts.js +82 -0
  30. package/dist/placement.js +39 -0
  31. package/dist/refusals.js +12 -0
  32. package/dist/relay.js +12 -2
  33. package/dist/resident.js +106 -50
  34. package/dist/scope.js +206 -0
  35. package/dist/secret-input.js +3 -2
  36. package/dist/service-main.js +9 -0
  37. package/dist/service.js +55 -0
  38. package/dist/shell.js +3 -0
  39. package/dist/sign-in.js +37 -31
  40. package/dist/skills.js +84 -15
  41. package/dist/transcription.js +57 -9
  42. package/dist/translate.js +2 -8
  43. package/dist/update.js +71 -50
  44. package/dist/wire.js +22 -0
  45. package/dist/work.js +346 -0
  46. package/how-we-work.md +13 -3
  47. package/package.json +4 -3
  48. package/skills/ask-matt/SKILL.md +17 -11
  49. package/skills/ask-matt/agents/openai.yaml +1 -0
  50. package/skills/code-review/SKILL.md +5 -5
  51. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  52. package/skills/codebase-design/SKILL.md +0 -2
  53. package/skills/diagnosing-bugs/SKILL.md +2 -4
  54. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  55. package/skills/domain-modeling/SKILL.md +12 -14
  56. package/skills/grill-me/SKILL.md +1 -2
  57. package/skills/grill-me/agents/openai.yaml +1 -0
  58. package/skills/grill-with-docs/SKILL.md +1 -2
  59. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  60. package/skills/grilling/SKILL.md +2 -2
  61. package/skills/handoff/SKILL.md +2 -3
  62. package/skills/handoff/agents/openai.yaml +1 -0
  63. package/skills/implement/SKILL.md +5 -4
  64. package/skills/implement/agents/openai.yaml +1 -0
  65. package/skills/implement-spec/SKILL.md +40 -0
  66. package/skills/implement-spec/agents/openai.yaml +5 -0
  67. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  68. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  69. package/skills/pr/CREDITS.md +3 -0
  70. package/skills/pr/LICENSE +21 -0
  71. package/skills/pr/SKILL.md +170 -0
  72. package/skills/pr/agents/openai.yaml +3 -0
  73. package/skills/prototype/SKILL.md +0 -2
  74. package/skills/research/SKILL.md +0 -2
  75. package/skills/retro/LICENSE +21 -0
  76. package/skills/retro/SKILL.md +44 -0
  77. package/skills/retro/agents/openai.yaml +5 -0
  78. package/skills/tdd/SKILL.md +2 -4
  79. package/skills/teach/SKILL.md +3 -4
  80. package/skills/teach/agents/openai.yaml +1 -0
  81. package/skills/to-questionnaire/SKILL.md +1 -2
  82. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  83. package/skills/to-spec/SKILL.md +1 -2
  84. package/skills/to-spec/agents/openai.yaml +1 -0
  85. package/skills/to-tickets/SKILL.md +3 -4
  86. package/skills/to-tickets/agents/openai.yaml +1 -0
  87. package/skills/triage/AGENT-BRIEF.md +207 -0
  88. package/skills/triage/LICENSE +21 -0
  89. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  90. package/skills/triage/SKILL.md +112 -0
  91. package/skills/triage/agents/openai.yaml +5 -0
  92. package/skills/wait-what/SKILL.md +2 -3
  93. package/skills/wait-what/agents/openai.yaml +1 -0
  94. package/skills/wayfinder/SKILL.md +5 -6
  95. package/skills/wayfinder/agents/openai.yaml +1 -0
  96. package/skills/wizard/LICENSE +21 -0
  97. package/skills/wizard/SKILL.md +44 -0
  98. package/skills/wizard/agents/openai.yaml +3 -0
  99. package/skills/wizard/template.sh +223 -0
  100. package/skills/writing-for-agents/SKILL.md +0 -2
  101. package/dist/blocks.js +0 -51
  102. package/dist/stream.js +0 -47
  103. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  104. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  105. /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
@@ -0,0 +1,68 @@
1
+ import { setGlobalProxyFromEnv } from 'node:http';
2
+ import { parseArgs } from 'node:util';
3
+ import { answerGitCredential } from './app-git.js';
4
+ import { chatgpt } from './chatgpt.js';
5
+ import { login } from './login.js';
6
+ import { logout } from './logout.js';
7
+ import { resident } from './resident.js';
8
+ const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
9
+ const COMMANDS = new Map([
10
+ [
11
+ 'logout',
12
+ {
13
+ usage: 'usage: kit logout',
14
+ about: "disconnects this computer, stops the Kit process and ends your own agent's connection",
15
+ operands: 0,
16
+ run: logout,
17
+ },
18
+ ],
19
+ [
20
+ 'resident',
21
+ {
22
+ usage: 'usage: kit resident',
23
+ about: "keeps this Environment connected; Kit's service runs it",
24
+ operands: 0,
25
+ run: resident,
26
+ },
27
+ ],
28
+ [
29
+ 'git-credential',
30
+ {
31
+ usage: 'usage: kit git-credential <get|store|erase>',
32
+ about: "answers git with your own agent's House credential; git runs it",
33
+ operands: 1,
34
+ run: ([operation]) => answerGitCredential(operation),
35
+ },
36
+ ],
37
+ ]);
38
+ const [command, ...argv] = process.argv.slice(2);
39
+ setGlobalProxyFromEnv();
40
+ async function run() {
41
+ if (command === 'login')
42
+ return login(argv);
43
+ if (command === 'chatgpt')
44
+ return chatgpt(argv);
45
+ if (command === '--help') {
46
+ parseArgs({ args: argv });
47
+ process.stdout.write(USAGE);
48
+ return;
49
+ }
50
+ const chosen = COMMANDS.get(command ?? '');
51
+ if (chosen === undefined) {
52
+ process.stderr.write(USAGE);
53
+ process.exitCode = 2;
54
+ return;
55
+ }
56
+ const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
57
+ if (positionals.length > chosen.operands)
58
+ throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
59
+ if (values.help) {
60
+ process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
61
+ return;
62
+ }
63
+ return chosen.run(positionals);
64
+ }
65
+ run().catch((error) => {
66
+ process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
67
+ process.exitCode = 1;
68
+ });
package/dist/kit-main.js CHANGED
@@ -1,21 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { setGlobalProxyFromEnv } from 'node:http';
3
- import { login } from './login.js';
4
- import { logout } from './logout.js';
5
- import { resident } from './resident.js';
6
- const [command, ...argv] = process.argv.slice(2);
7
- setGlobalProxyFromEnv();
8
- async function run() {
9
- if (command === 'login')
10
- return login(argv);
11
- if (command === 'logout')
12
- return logout();
13
- if (command === 'resident')
14
- return resident();
15
- process.stderr.write('usage: kit <login|logout|resident>\n');
16
- process.exitCode = 2;
17
- }
18
- run().catch((error) => {
19
- 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`);
20
5
  process.exitCode = 1;
21
- });
6
+ }
7
+ else {
8
+ await import('./kit-cli.js');
9
+ }
10
+ export {};
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,30 @@ 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 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
+ }
46
+ function gone(error) {
47
+ return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
48
+ }
49
+ function chosenRooms(rooms, noPrivate) {
50
+ if (rooms !== undefined && noPrivate)
51
+ throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
52
+ if (rooms !== undefined)
53
+ return { rooms: { reach: 'selected', refs: rooms.split(',') } };
54
+ return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
71
55
  }
72
56
  export async function login(argv) {
73
57
  const { values } = parseArgs({
@@ -75,62 +59,93 @@ export async function login(argv) {
75
59
  options: {
76
60
  house: { type: 'string' },
77
61
  environment: { type: 'string' },
78
- manual: { type: 'boolean', default: false },
62
+ rooms: { type: 'string' },
63
+ 'no-private': { type: 'boolean', default: false },
64
+ code: { type: 'string' },
65
+ help: { type: 'boolean', default: false },
79
66
  },
80
67
  });
68
+ if (values.help) {
69
+ process.stdout.write(USAGE);
70
+ return;
71
+ }
72
+ if (values.code !== undefined && values.rooms !== undefined)
73
+ throw new Error('--code cannot be used with --rooms');
74
+ if (values.code !== undefined && values['no-private'])
75
+ throw new Error('--code cannot be used with --no-private');
76
+ if (values.code !== undefined && values.environment !== undefined)
77
+ throw new Error('--code cannot be used with --environment');
78
+ const rooms = chosenRooms(values.rooms, values['no-private']);
81
79
  const enrolled = (await readEnrolment()) ?? (await readDisconnected());
80
+ if (values.code !== undefined && enrolled !== null) {
81
+ throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
82
+ }
83
+ const relay = process.env.HOUSE_KIT_RELAY || undefined;
84
+ selectRelay(relay);
82
85
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
83
86
  const replaces = process.env.HOUSE_KIT_REPLACES;
84
- const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
87
+ const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
88
+ const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
85
89
  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;
90
+ let held = false;
91
+ let named = environment;
92
+ let exchanged;
93
+ if (values.code !== undefined) {
94
+ exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
115
95
  }
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`);
96
+ else {
97
+ held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
98
+ const verifier = randomBytes(32).toString('base64url');
99
+ const start = () => retrying(() => post(house, '/kit', {
100
+ label: hostname(),
101
+ ...(named === undefined
102
+ ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
103
+ : { act: 'existing_environment', environment_id: named }),
104
+ ...rooms,
105
+ code_challenge: createHash('sha256').update(verifier).digest('base64url'),
106
+ ...(held ? {} : { headless: true }),
107
+ }));
108
+ let started;
124
109
  try {
125
- await exchange(await callback.code);
110
+ started = await start();
126
111
  }
127
112
  catch (error) {
128
- await callback.answer(`This Environment was not connected: ${error.message}`);
129
- throw error;
113
+ if (remembered === undefined || !gone(error))
114
+ throw error;
115
+ await forgetDisconnected();
116
+ process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
117
+ named = undefined;
118
+ started = await start();
130
119
  }
131
- await callback.answer('This Environment is connected. You can close this tab.');
120
+ process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
121
+ open(started.start_url);
122
+ exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
123
+ }
124
+ await placeSkillSet();
125
+ await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
126
+ const relayRecord = relay === undefined ? {} : { relay };
127
+ await writeEnrolment({
128
+ house,
129
+ ...relayRecord,
130
+ environment: exchanged.environment,
131
+ credential: exchanged.credential,
132
+ });
133
+ process.stdout.write(connected(house, named, exchanged.environment));
134
+ if (exchanged.headless_credential !== undefined) {
135
+ await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
136
+ }
137
+ else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
138
+ await forgetOwnAgent();
139
+ process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
140
+ }
141
+ else if (held && ownAgent !== null) {
142
+ await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
143
+ }
144
+ await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
145
+ try {
146
+ startService();
132
147
  }
133
- finally {
134
- callback.close();
148
+ catch (error) {
149
+ process.stderr.write(`kit: ${error.message}\n`);
135
150
  }
136
151
  }
package/dist/logout.js CHANGED
@@ -1,18 +1,19 @@
1
1
  import { HouseRefusal, post } from './api.js';
2
- import { forgetEnrolment, readEnrolment } from './home.js';
2
+ import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
3
3
  export async function logout() {
4
4
  const enrolled = await readEnrolment();
5
- if (enrolled === null) {
6
- process.stdout.write('This computer is not connected to House.\n');
7
- return;
5
+ if (enrolled !== null) {
6
+ try {
7
+ await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
8
+ }
9
+ catch (error) {
10
+ if (!(error instanceof HouseRefusal && error.status === 401))
11
+ throw error;
12
+ }
13
+ await forgetEnrolment(enrolled);
8
14
  }
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`);
15
+ await forgetOwnAgent();
16
+ process.stdout.write(enrolled === null
17
+ ? 'This computer is not connected to House.\n'
18
+ : `Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
18
19
  }
package/dist/mcp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { KIT_VERSION } from './clis.js';
2
+ import { KIT_RELEASE } from './clis.js';
3
3
  import { relayed } from './relay.js';
4
4
  const MCP_PROTOCOL_VERSION = '2026-07-28';
5
5
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
@@ -13,7 +13,7 @@ export function mcpBody(message, operation) {
13
13
  ...message.params,
14
14
  _meta: {
15
15
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
16
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
16
+ 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
17
17
  'io.modelcontextprotocol/clientCapabilities': {},
18
18
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
19
  },
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,39 @@
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
+ export function service() {
6
+ if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
7
+ return null;
8
+ return process.env.MANAGERPID ? 'user' : 'system';
9
+ }
10
+ export function throughSudo() {
11
+ return service() === 'system' && process.getuid() !== 0;
12
+ }
13
+ export async function updatesItself() {
14
+ if (service() === null)
15
+ return false;
16
+ if (!throughSudo())
17
+ return true;
18
+ // sudo answers at once, so ten seconds only bounds a stuck sudo.
19
+ return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
20
+ }
21
+ function recorded(name) {
22
+ try {
23
+ return readFileSync(join(kitHome(), name), 'utf8').trim();
24
+ }
25
+ catch (error) {
26
+ if (error.code === 'ENOENT')
27
+ return null;
28
+ throw error;
29
+ }
30
+ }
31
+ export function installCommand() {
32
+ return recorded('install-command');
33
+ }
34
+ export function machine() {
35
+ const placed = recorded('placement');
36
+ if (placed === 'container' || placed === 'server' || placed === 'windows')
37
+ return placed;
38
+ return process.platform === 'darwin' ? 'macos' : 'linux';
39
+ }
package/dist/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 CHANGED
@@ -1,7 +1,17 @@
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
+ }
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:')