@agentshouse/kit 0.2.1-cde47fd72fe59 → 0.2.1-ce0af1aee9a57

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 (149) hide show
  1. package/README.md +28 -29
  2. package/dist/acp.js +59 -8
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +59 -33
  5. package/dist/api.js +5 -5
  6. package/dist/authority-main.js +3 -3
  7. package/dist/bridge.js +5 -5
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +71 -0
  10. package/dist/chunks.js +49 -0
  11. package/dist/clis.js +47 -45
  12. package/dist/{stream.js → connection.js} +46 -49
  13. package/dist/content.js +63 -0
  14. package/dist/conversations.js +614 -206
  15. package/dist/copies.js +308 -176
  16. package/dist/end.js +14 -4
  17. package/dist/events.js +742 -210
  18. package/dist/files.js +139 -37
  19. package/dist/git.js +47 -13
  20. package/dist/grok.js +39 -0
  21. package/dist/home.js +0 -7
  22. package/dist/house-cli.js +97 -89
  23. package/dist/house-main.js +3 -3
  24. package/dist/instructions.js +29 -11
  25. package/dist/kit-cli.js +5 -8
  26. package/dist/kit-main.js +3 -3
  27. package/dist/login.js +6 -6
  28. package/dist/logout.js +1 -1
  29. package/dist/mcp.js +6 -2
  30. package/dist/placement.js +21 -20
  31. package/dist/relay.js +21 -0
  32. package/dist/resident.js +69 -48
  33. package/dist/scope.js +15 -4
  34. package/dist/scripts.js +255 -0
  35. package/dist/secret-input.js +1 -1
  36. package/dist/service.js +1 -1
  37. package/dist/sign-in.js +22 -21
  38. package/dist/silence.js +28 -0
  39. package/dist/skills.js +42 -97
  40. package/dist/transcription.js +88 -45
  41. package/dist/translate.js +18 -9
  42. package/dist/update.js +113 -124
  43. package/dist/wire.js +37 -3
  44. package/dist/work.js +9 -2
  45. package/package.json +22 -21
  46. package/dist/bootstrap.json +0 -24
  47. package/dist/chatgpt.js +0 -32
  48. package/dist/clis-main.js +0 -23
  49. package/dist/inputs.js +0 -37
  50. package/dist/parts.js +0 -82
  51. package/how-we-work.md +0 -33
  52. package/skills/ask-matt/LICENSE +0 -21
  53. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  54. package/skills/ask-matt/SKILL.md +0 -97
  55. package/skills/ask-matt/agents/openai.yaml +0 -5
  56. package/skills/code-review/LICENSE +0 -21
  57. package/skills/code-review/SKILL.md +0 -89
  58. package/skills/code-review/agents/openai.yaml +0 -3
  59. package/skills/codebase-design/DEEPENING.md +0 -37
  60. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  61. package/skills/codebase-design/LICENSE +0 -21
  62. package/skills/codebase-design/SKILL.md +0 -114
  63. package/skills/codebase-design/agents/openai.yaml +0 -3
  64. package/skills/diagnosing-bugs/LICENSE +0 -21
  65. package/skills/diagnosing-bugs/SKILL.md +0 -138
  66. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  67. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  68. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  69. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  70. package/skills/domain-modeling/LICENSE +0 -21
  71. package/skills/domain-modeling/SKILL.md +0 -74
  72. package/skills/domain-modeling/agents/openai.yaml +0 -3
  73. package/skills/grill-me/LICENSE +0 -21
  74. package/skills/grill-me/SKILL.md +0 -7
  75. package/skills/grill-me/agents/openai.yaml +0 -5
  76. package/skills/grill-with-docs/LICENSE +0 -21
  77. package/skills/grill-with-docs/SKILL.md +0 -7
  78. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  79. package/skills/grilling/LICENSE +0 -21
  80. package/skills/grilling/SKILL.md +0 -30
  81. package/skills/grilling/agents/openai.yaml +0 -3
  82. package/skills/handoff/LICENSE +0 -21
  83. package/skills/handoff/SKILL.md +0 -16
  84. package/skills/handoff/agents/openai.yaml +0 -5
  85. package/skills/implement/LICENSE +0 -21
  86. package/skills/implement/SKILL.md +0 -17
  87. package/skills/implement/agents/openai.yaml +0 -5
  88. package/skills/implement-spec/LICENSE +0 -21
  89. package/skills/implement-spec/SKILL.md +0 -40
  90. package/skills/implement-spec/agents/openai.yaml +0 -5
  91. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  92. package/skills/improve-codebase-architecture/LICENSE +0 -21
  93. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  94. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  95. package/skills/pr/CREDITS.md +0 -3
  96. package/skills/pr/LICENSE +0 -21
  97. package/skills/pr/SKILL.md +0 -170
  98. package/skills/pr/agents/openai.yaml +0 -3
  99. package/skills/prototype/LICENSE +0 -21
  100. package/skills/prototype/LOGIC.md +0 -67
  101. package/skills/prototype/SKILL.md +0 -26
  102. package/skills/prototype/UI.md +0 -112
  103. package/skills/prototype/agents/openai.yaml +0 -3
  104. package/skills/research/LICENSE +0 -21
  105. package/skills/research/SKILL.md +0 -12
  106. package/skills/research/agents/openai.yaml +0 -3
  107. package/skills/retro/LICENSE +0 -21
  108. package/skills/retro/SKILL.md +0 -44
  109. package/skills/retro/agents/openai.yaml +0 -5
  110. package/skills/tdd/LICENSE +0 -21
  111. package/skills/tdd/SKILL.md +0 -38
  112. package/skills/tdd/agents/openai.yaml +0 -3
  113. package/skills/tdd/mocking.md +0 -59
  114. package/skills/tdd/tests.md +0 -77
  115. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  116. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  117. package/skills/teach/LICENSE +0 -21
  118. package/skills/teach/MISSION-FORMAT.md +0 -31
  119. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  120. package/skills/teach/SKILL.md +0 -140
  121. package/skills/teach/agents/openai.yaml +0 -5
  122. package/skills/to-questionnaire/LICENSE +0 -21
  123. package/skills/to-questionnaire/SKILL.md +0 -54
  124. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  125. package/skills/to-spec/LICENSE +0 -21
  126. package/skills/to-spec/SKILL.md +0 -75
  127. package/skills/to-spec/agents/openai.yaml +0 -5
  128. package/skills/to-tickets/LICENSE +0 -21
  129. package/skills/to-tickets/SKILL.md +0 -105
  130. package/skills/to-tickets/agents/openai.yaml +0 -5
  131. package/skills/triage/AGENT-BRIEF.md +0 -207
  132. package/skills/triage/LICENSE +0 -21
  133. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  134. package/skills/triage/SKILL.md +0 -112
  135. package/skills/triage/agents/openai.yaml +0 -5
  136. package/skills/wait-what/LICENSE +0 -21
  137. package/skills/wait-what/SKILL.md +0 -7
  138. package/skills/wait-what/agents/openai.yaml +0 -5
  139. package/skills/wayfinder/LICENSE +0 -21
  140. package/skills/wayfinder/SKILL.md +0 -128
  141. package/skills/wayfinder/agents/openai.yaml +0 -5
  142. package/skills/wizard/LICENSE +0 -21
  143. package/skills/wizard/SKILL.md +0 -44
  144. package/skills/wizard/agents/openai.yaml +0 -3
  145. package/skills/wizard/template.sh +0 -223
  146. package/skills/writing-for-agents/LICENSE +0 -21
  147. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  148. package/skills/writing-for-agents/SKILL.md +0 -81
  149. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -1,12 +1,30 @@
1
- import { HOUSE_REF } from './git.js';
2
- import { readHowWeWork } from './skills.js';
3
- const SOURCE_LINE = "From House:";
4
- const HOUSE_LINE = "Work with House through the `house` CLI: run `house --help`, and `house find_command` for House's guides and formats.";
5
- const FILE_LINE = 'To give the User a file, upload it with `house upload` and link it; for an App, a Site or a website, follow `house find_command \'{"query":"app"}\'`. Never start a server.';
6
- const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
7
- const WAIT_LINE = 'To get what another Agent will write into a Room, `create_trigger` on where it will land with a `conversation` action, then end your turn: this conversation continues when it lands.';
8
- const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
9
- export async function instructions(bridge, base, copies) {
10
- const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, WAIT_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
11
- return [lines.join('\n'), base, (await readHowWeWork(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
1
+ import { agentInstructions } from '@agentshouse/skills';
2
+ const OWNER_RULES = '/rooms/private/owner-rules.md';
3
+ const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
4
+ const FAILED = /^exit: [1-9]\d*$/;
5
+ const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
6
+ function cutOf(lines) {
7
+ const cut = CUT.exec(lines[0] ?? '');
8
+ return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
9
+ }
10
+ async function readOwnerRules(bridge) {
11
+ let document = '';
12
+ for (let command = `cat ${OWNER_RULES}`; command !== undefined;) {
13
+ const read = await bridge.tool('shell', { command });
14
+ const text = read.content.map((content) => content.text).join('\n');
15
+ const lines = text.split('\n');
16
+ if (read.isError === true || (FAILED.test(lines[0] ?? '') && lines[1]?.startsWith('stderr: '))) {
17
+ const refusal = read.isError === true ? text : lines.slice(1).join('\n').replace(/^stderr: /gm, '');
18
+ if (UNREADABLE.test(refusal))
19
+ return '';
20
+ throw new Error(refusal);
21
+ }
22
+ const cut = cutOf(lines);
23
+ document += lines.slice(cut === null ? 0 : 1).join('\n');
24
+ command = cut?.[2];
25
+ }
26
+ return document;
27
+ }
28
+ export async function instructions(bridge, base) {
29
+ return [agentInstructions().join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
12
30
  }
package/dist/kit-cli.js CHANGED
@@ -1,17 +1,16 @@
1
- import { setGlobalProxyFromEnv } from 'node:http';
2
1
  import { parseArgs } from 'node:util';
3
2
  import { answerGitCredential } from './app-git.js';
4
- import { chatgpt } from './chatgpt.js';
5
3
  import { login } from './login.js';
6
4
  import { logout } from './logout.js';
5
+ import { proxyUnlessRelayed } from './relay.js';
7
6
  import { resident } from './resident.js';
8
- const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
7
+ const USAGE = 'usage: kit <login|logout|resident>\n';
9
8
  const COMMANDS = new Map([
10
9
  [
11
10
  'logout',
12
11
  {
13
12
  usage: 'usage: kit logout',
14
- about: "disconnects this computer, stops House Kit and ends your own agent's connection",
13
+ about: "disconnects this computer, stops the Kit process and ends your own agent's connection",
15
14
  operands: 0,
16
15
  run: logout,
17
16
  },
@@ -20,7 +19,7 @@ const COMMANDS = new Map([
20
19
  'resident',
21
20
  {
22
21
  usage: 'usage: kit resident',
23
- about: "keeps this Environment connected; House Kit's service runs it",
22
+ about: "keeps this Environment connected; Kit's service runs it",
24
23
  operands: 0,
25
24
  run: resident,
26
25
  },
@@ -36,12 +35,10 @@ const COMMANDS = new Map([
36
35
  ],
37
36
  ]);
38
37
  const [command, ...argv] = process.argv.slice(2);
39
- setGlobalProxyFromEnv();
38
+ proxyUnlessRelayed();
40
39
  async function run() {
41
40
  if (command === 'login')
42
41
  return login(argv);
43
- if (command === 'chatgpt')
44
- return chatgpt(argv);
45
42
  if (command === '--help') {
46
43
  parseArgs({ args: argv });
47
44
  process.stdout.write(USAGE);
package/dist/kit-main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
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`);
2
+ const [major = 0, minor = 0, patch = 0] = process.versions.node.split('.').map(Number);
3
+ if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
4
+ process.stderr.write(`kit: the Kit needs Node 24.22.1 or newer; this is ${process.versions.node}\n`);
5
5
  process.exitCode = 1;
6
6
  }
7
7
  else {
package/dist/login.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
- import { hostname } from 'node:os';
4
3
  import { parseArgs } from 'node:util';
5
4
  import { HouseRefusal, post, retrying } from './api.js';
6
5
  import { placeAppGit } from './app-git.js';
@@ -11,7 +10,8 @@ import { refusalOf } from './refusals.js';
11
10
  import { selectRelay } from './relay.js';
12
11
  import { startService } from './service.js';
13
12
  import { placeSkillSet } from './skills.js';
14
- export const DEFAULT_HOUSE = 'https://agents.house';
13
+ import { endUnserved } from './wire.js';
14
+ const DEFAULT_HOUSE = 'https://agents.house';
15
15
  const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
16
16
  // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
17
17
  const POLL_INTERVAL_MS = 2000;
@@ -20,12 +20,13 @@ function open(link) {
20
20
  .on('error', () => undefined)
21
21
  .unref();
22
22
  }
23
- export async function accepted(house, credential) {
23
+ async function accepted(house, credential) {
24
24
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
25
25
  if (checked.status === 200)
26
26
  return true;
27
27
  if (checked.status === 401)
28
28
  return false;
29
+ endUnserved(checked.text);
29
30
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
30
31
  }
31
32
  const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
@@ -91,13 +92,12 @@ export async function login(argv) {
91
92
  let named = environment;
92
93
  let exchanged;
93
94
  if (values.code !== undefined) {
94
- exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
95
+ exchanged = await post(house, '/kit/token', { code: values.code });
95
96
  }
96
97
  else {
97
98
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
98
99
  const verifier = randomBytes(32).toString('base64url');
99
100
  const start = () => retrying(() => post(house, '/kit', {
100
- label: hostname(),
101
101
  ...(named === undefined
102
102
  ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
103
103
  : { act: 'existing_environment', environment_id: named }),
@@ -121,7 +121,7 @@ export async function login(argv) {
121
121
  open(started.start_url);
122
122
  exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
123
123
  }
124
- await placeSkillSet();
124
+ await placeSkillSet(house);
125
125
  await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
126
126
  const relayRecord = relay === undefined ? {} : { relay };
127
127
  await writeEnrolment({
package/dist/logout.js CHANGED
@@ -4,7 +4,7 @@ export async function logout() {
4
4
  const enrolled = await readEnrolment();
5
5
  if (enrolled !== null) {
6
6
  try {
7
- await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
7
+ await post(enrolled.house, '/kit/kits/log-out', {}, enrolled.credential);
8
8
  }
9
9
  catch (error) {
10
10
  if (!(error instanceof HouseRefusal && error.status === 401))
package/dist/mcp.js CHANGED
@@ -1,8 +1,11 @@
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
+ import { KIT_WIRE, KIT_WIRE_HEADER } from './wire.js';
4
5
  const MCP_PROTOCOL_VERSION = '2026-07-28';
5
6
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
7
+ export class Unsettled extends Error {
8
+ }
6
9
  export function rpc(method, params) {
7
10
  return { jsonrpc: '2.0', id: randomUUID(), method, params };
8
11
  }
@@ -13,7 +16,7 @@ export function mcpBody(message, operation) {
13
16
  ...message.params,
14
17
  _meta: {
15
18
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
16
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
19
+ 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
17
20
  'io.modelcontextprotocol/clientCapabilities': {},
18
21
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
22
  },
@@ -31,6 +34,7 @@ export async function callHouse(origin, credential, message, operation = null, s
31
34
  'mcp-protocol-version': MCP_PROTOCOL_VERSION,
32
35
  'mcp-method': message.method,
33
36
  ...(tool === null ? {} : { 'mcp-name': tool }),
37
+ [KIT_WIRE_HEADER]: String(KIT_WIRE),
34
38
  },
35
39
  body: mcpBody(message, operation),
36
40
  signal,
package/dist/placement.js CHANGED
@@ -1,26 +1,9 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { run } from './clis.js';
2
+ import { join, resolve } from 'node:path';
4
3
  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
- export function installCommand() {
4
+ function recorded(name) {
22
5
  try {
23
- return readFileSync(join(kitHome(), 'install-command'), 'utf8').trim();
6
+ return readFileSync(join(kitHome(), name), 'utf8').trim();
24
7
  }
25
8
  catch (error) {
26
9
  if (error.code === 'ENOENT')
@@ -28,3 +11,21 @@ export function installCommand() {
28
11
  throw error;
29
12
  }
30
13
  }
14
+ export function installCommand() {
15
+ return recorded('install-command');
16
+ }
17
+ export function machine() {
18
+ const placed = recorded('placement');
19
+ if (placed === 'container' || placed === 'server' || placed === 'windows')
20
+ return placed;
21
+ return process.platform === 'darwin' ? 'macos' : 'linux';
22
+ }
23
+ export function placedPrefix() {
24
+ const prefix = process.env.HOUSE_KIT_PREFIX;
25
+ if (prefix === undefined || prefix === '')
26
+ throw new Error('this Kit process was not started by a launcher its installer placed');
27
+ return resolve(prefix);
28
+ }
29
+ export function releaseDirectory(release) {
30
+ return join(placedPrefix(), 'releases', release);
31
+ }
package/dist/relay.js CHANGED
@@ -1,6 +1,11 @@
1
+ import { setGlobalProxyFromEnv } from 'node:http';
2
+ const PROXY = /^https?_proxy$/i;
3
+ const LOOPBACK = ['127.0.0.1', 'localhost', '::1'];
1
4
  let selected;
5
+ let restoreProxy;
2
6
  export function selectRelay(relay) {
3
7
  selected = relay === undefined || relay === '' ? null : relay;
8
+ proxyUnlessRelayed();
4
9
  }
5
10
  export function relayOrigin() {
6
11
  if (selected !== undefined)
@@ -8,6 +13,22 @@ export function relayOrigin() {
8
13
  const ambient = process.env.HOUSE_KIT_RELAY;
9
14
  return ambient === undefined || ambient === '' ? undefined : ambient;
10
15
  }
16
+ function unlessRelayed() {
17
+ if (relayOrigin() === undefined)
18
+ return { ...process.env };
19
+ return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
20
+ }
21
+ export function proxyUnlessRelayed() {
22
+ restoreProxy?.();
23
+ restoreProxy = setGlobalProxyFromEnv(unlessRelayed());
24
+ }
25
+ export function childEnvironment() {
26
+ const environment = unlessRelayed();
27
+ if (!Object.keys(environment).some((name) => PROXY.test(name)))
28
+ return environment;
29
+ const bypassed = [environment.NO_PROXY ?? environment.no_proxy, ...LOOPBACK].filter((entry) => entry !== undefined && entry !== '').join(',');
30
+ return { ...environment, NO_PROXY: bypassed, no_proxy: bypassed };
31
+ }
11
32
  export function relayed(target) {
12
33
  const url = new URL(target);
13
34
  const relay = relayOrigin();
package/dist/resident.js CHANGED
@@ -8,17 +8,19 @@ import { fileURLToPath } from 'node:url';
8
8
  import { Agents } from './agents.js';
9
9
  import { house } from './api.js';
10
10
  import { received } from './bridge.js';
11
- import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
11
+ import { CONVERSATION_METHODS, Conversations } from './conversations.js';
12
12
  import { LocalCopies } from './copies.js';
13
- import { restart } from './end.js';
14
- import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
15
- import { Inputs } from './inputs.js';
13
+ import { restart, unknownMethod } from './end.js';
14
+ import { agentBase, enrolled, kitHome, ownerLock, ownerSocket, readEnrolment } from './home.js';
15
+ import { Calls } from './calls.js';
16
16
  import { killDescendants } from './scope.js';
17
+ import { removeInputs, Scripts } from './scripts.js';
17
18
  import { quoted } from './shell.js';
18
19
  import { SignIns } from './sign-in.js';
19
20
  import { placeSkillSet } from './skills.js';
20
- import { holdStream } from './stream.js';
21
- import { Updates } from './update.js';
21
+ import { holdConnection } from './connection.js';
22
+ import { KitUpdate } from './update.js';
23
+ import { takeUnservedRelease } from './wire.js';
22
24
  import { codexLauncher } from './work.js';
23
25
  function report(error) {
24
26
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
@@ -47,7 +49,7 @@ async function serveOwner(copies) {
47
49
  if (!claimed(lock)) {
48
50
  lock.close();
49
51
  const running = await runningResident();
50
- throw new Error(`${running === null ? 'another Kit' : `Kit ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another here`);
52
+ throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
51
53
  }
52
54
  const server = createServer(async (request, response) => {
53
55
  try {
@@ -109,14 +111,7 @@ function connected() {
109
111
  }
110
112
  async function started() {
111
113
  await connected();
112
- await forgetRestart();
113
- watch(kitHome(), () => {
114
- if (enrolled())
115
- return;
116
- killDescendants();
117
- process.exit(1);
118
- });
119
- await placeSkillSet();
114
+ await placeSkillSet((await readEnrolment()).house);
120
115
  await mkdir(agentBase(), { recursive: true });
121
116
  await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
122
117
  await installShim(codexLauncher(), 'codex-main');
@@ -126,72 +121,98 @@ export async function resident() {
126
121
  const copies = new LocalCopies(house);
127
122
  await copies.load();
128
123
  await serveOwner(copies);
124
+ await copies.swept();
129
125
  await started().catch((error) => {
130
126
  report(error);
131
127
  process.exit(1);
132
128
  });
133
129
  process.env.HOUSE_KIT_RESIDENT = String(process.pid);
134
130
  const agents = new Agents(house, () => changed());
135
- let stream = null;
131
+ let connection = null;
136
132
  let reported = false;
137
- const idle = () => inputs.idle() && conversations.idle() && agents.idle();
133
+ let stopping = false;
134
+ const stop = async (then) => {
135
+ if (stopping)
136
+ return;
137
+ stopping = true;
138
+ conversations.stopped();
139
+ killDescendants();
140
+ await connection?.close();
141
+ then();
142
+ };
143
+ const idle = () => calls.idle() && conversations.idle() && agents.idle();
138
144
  const changed = () => {
139
145
  if (!idle()) {
140
146
  reported = false;
141
147
  }
142
- else if (restartAsked() && conversations.quiet()) {
143
- restart('restarting for an updated CLI');
148
+ else if (update.placedRelease() !== null && conversations.quiet()) {
149
+ const placed = update.placedRelease();
150
+ void stop(() => restart(`Kit ${placed} is placed; its supervisor starts it`));
144
151
  }
145
152
  else if (!reported) {
146
153
  reported = true;
147
- logged(house.deliver('/kit/idle', {}, idle));
154
+ logged(house.deliver('/kit/kits/report-idle', {}, idle));
148
155
  }
149
156
  };
150
- const inputs = new Inputs(house, changed);
157
+ const calls = new Calls(house, changed);
151
158
  const conversations = new Conversations({
152
159
  house,
153
160
  agents,
154
161
  copies,
155
- inputs,
156
- send: (frame) => stream?.send(frame) ?? false,
162
+ calls,
163
+ send: (oneWayCall) => connection?.send(oneWayCall) ?? false,
157
164
  changed,
158
165
  });
159
- const signIns = new SignIns(house, agents, inputs);
160
- const updates = new Updates(inputs);
166
+ const signIns = new SignIns(house, agents, calls);
167
+ const update = new KitUpdate(calls);
168
+ if (process.env.HOUSE_KIT_SANDBOX !== '1')
169
+ takeUnservedRelease((release) => logged(update.takeRefused(release)));
170
+ removeInputs();
171
+ const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false);
161
172
  for (const signal of ['SIGTERM', 'SIGINT']) {
162
173
  process.once(signal, () => {
163
- killDescendants();
164
- process.kill(process.pid, signal);
174
+ void stop(() => {
175
+ removeInputs();
176
+ process.kill(process.pid, signal);
177
+ });
165
178
  });
166
179
  }
167
- await house.deliver('/kit/restarted', {}).catch(report);
168
- await updates.resumed().catch(report);
180
+ const unenrolled = () => {
181
+ if (!enrolled())
182
+ void stop(() => process.exit(1));
183
+ };
184
+ watch(kitHome(), unenrolled);
185
+ unenrolled();
186
+ await house.deliver('/kit/kits/report-restart', {}).catch(report);
169
187
  logged(agents.refresh());
170
- stream = holdStream({
188
+ agents.keepCurrent(() => process.env.HOUSE_KIT_SANDBOX === '1' && reported);
189
+ connection = holdConnection({
171
190
  opened: () => {
172
191
  conversations.opened();
173
192
  changed();
174
193
  logged(copies.connected());
175
194
  },
176
- frame: (arrived) => {
177
- if (arrived.type === 'watching')
178
- conversations.watching(arrived.watching === true);
179
- if (arrived.type === 'authority_changed')
180
- logged(copies.changed(arrived.rooms));
181
- if (arrived.type === 'work_available' && arrived.subject === 'agents')
182
- logged(agents.refresh());
183
- if (arrived.type === 'input') {
184
- if (arrived.kind === 'sign_in')
185
- signIns.start(arrived);
186
- else if (arrived.kind === 'update')
187
- updates.start(arrived);
188
- else if (CONVERSATION_INPUTS.has(arrived.kind))
189
- conversations.input(arrived);
190
- else {
191
- const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
192
- void inputs.carry(String(arrived.input_id), async () => ({ ack: refused }));
193
- }
195
+ closed: () => scripts.disconnected(),
196
+ call: (call) => {
197
+ if (call.kind === 'sign_in')
198
+ signIns.start(call);
199
+ else if (call.kind === 'update')
200
+ update.take(call);
201
+ else if (call.kind === 'run_wizard' || call.kind === 'run_function')
202
+ scripts.start(call);
203
+ else if (CONVERSATION_METHODS.has(call.kind))
204
+ conversations.call(call);
205
+ else {
206
+ const refused = { refused: unknownMethod(call.kind) };
207
+ void calls.carry(call.input_id, async () => ({ result: refused }));
194
208
  }
195
209
  },
210
+ oneWayCall: (oneWayCall) => {
211
+ if (oneWayCall.type === 'watching')
212
+ conversations.watching(oneWayCall.watching === true);
213
+ if (oneWayCall.type === 'work_available' && oneWayCall.subject === 'agents')
214
+ logged(agents.refresh());
215
+ scripts.notified(oneWayCall);
216
+ },
196
217
  });
197
218
  }
package/dist/scope.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { execFileSync } from 'node:child_process';
2
- import { mkdirSync, readdirSync, readFileSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
2
+ import { mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  const LISTING_BYTES = 1 << 28;
5
5
  const CGROUPS = '/sys/fs/cgroup';
6
6
  const GONE = new Set(['ENOENT', 'ESRCH']);
7
+ const EXITED = new Set(['Z', 'X']);
7
8
  function failure(error) {
8
9
  return error.code ?? '';
9
10
  }
@@ -24,6 +25,8 @@ function read(pid) {
24
25
  try {
25
26
  const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
26
27
  const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
28
+ if (EXITED.has(fields[0]))
29
+ return null;
27
30
  const command = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replaceAll('\0', ' ');
28
31
  return { parent: Number(fields[1]), session: fields[3], command };
29
32
  }
@@ -119,15 +122,23 @@ function members(group) {
119
122
  }
120
123
  return pids;
121
124
  }
125
+ function besideCli(cli) {
126
+ try {
127
+ return `${realpathSync(cli)}-`;
128
+ }
129
+ catch {
130
+ return null;
131
+ }
132
+ }
122
133
  export class Scope {
123
134
  marker;
124
- cli;
135
+ helpers;
125
136
  group;
126
137
  session = null;
127
138
  recorded = null;
128
139
  constructor(marker, name, cli) {
129
140
  this.marker = marker;
130
- this.cli = cli;
141
+ this.helpers = besideCli(cli);
131
142
  const own = ownGroup();
132
143
  this.group = own === null ? null : join(own, name);
133
144
  try {
@@ -165,7 +176,7 @@ export class Scope {
165
176
  return true;
166
177
  if (this.recorded === null)
167
178
  return found.size > 0;
168
- return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || command.startsWith(`${this.cli}-`)));
179
+ return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || (this.helpers !== null && command.startsWith(this.helpers))));
169
180
  }
170
181
  empty() {
171
182
  return this.found()?.size === 0;