@agentshouse/kit 0.2.1-cd646adba3f64 → 0.2.1-cdc381ebf021f

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 (141) hide show
  1. package/README.md +42 -48
  2. package/dist/acp.js +102 -108
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +227 -68
  5. package/dist/api.js +19 -10
  6. package/dist/app-git.js +10 -26
  7. package/dist/bridge.js +18 -47
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +88 -0
  10. package/dist/chunks.js +49 -0
  11. package/dist/clis.js +157 -100
  12. package/dist/codex-main.js +58 -0
  13. package/dist/connect.js +108 -0
  14. package/dist/connection.js +120 -0
  15. package/dist/content.js +106 -0
  16. package/dist/conversations.js +815 -335
  17. package/dist/copies.js +439 -232
  18. package/dist/earlier.js +263 -0
  19. package/dist/end.js +23 -5
  20. package/dist/events.js +793 -0
  21. package/dist/files.js +139 -17
  22. package/dist/git.js +57 -21
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +122 -8
  25. package/dist/house-cli.js +359 -0
  26. package/dist/house-main.js +7 -159
  27. package/dist/instructions.js +7 -11
  28. package/dist/kit-cli.js +78 -0
  29. package/dist/kit-main.js +8 -22
  30. package/dist/login.js +132 -107
  31. package/dist/logout.js +15 -17
  32. package/dist/mcp.js +6 -2
  33. package/dist/owner.js +46 -0
  34. package/dist/placement.js +25 -0
  35. package/dist/relay.js +33 -2
  36. package/dist/resident.js +160 -58
  37. package/dist/scope.js +214 -0
  38. package/dist/scripts.js +303 -0
  39. package/dist/secret-input.js +1 -1
  40. package/dist/settings.js +188 -0
  41. package/dist/sign-in.js +40 -33
  42. package/dist/silence.js +28 -0
  43. package/dist/skills.js +49 -35
  44. package/dist/supervisor.js +163 -0
  45. package/dist/transcription.js +90 -47
  46. package/dist/translate.js +19 -16
  47. package/dist/update.js +119 -102
  48. package/dist/wire.js +32 -0
  49. package/dist/work.js +353 -0
  50. package/dist/workspace.js +103 -0
  51. package/package.json +25 -21
  52. package/dist/authority-main.js +0 -22
  53. package/dist/blocks.js +0 -51
  54. package/dist/bootstrap.json +0 -24
  55. package/dist/clis-main.js +0 -23
  56. package/dist/configure-main.js +0 -6
  57. package/dist/enrol-main.js +0 -4
  58. package/dist/stream.js +0 -72
  59. package/how-we-work.md +0 -23
  60. package/skills/ask-matt/LICENSE +0 -21
  61. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  62. package/skills/ask-matt/SKILL.md +0 -91
  63. package/skills/ask-matt/agents/openai.yaml +0 -4
  64. package/skills/code-review/LICENSE +0 -21
  65. package/skills/code-review/SKILL.md +0 -89
  66. package/skills/code-review/agents/openai.yaml +0 -3
  67. package/skills/codebase-design/DEEPENING.md +0 -37
  68. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  69. package/skills/codebase-design/LICENSE +0 -21
  70. package/skills/codebase-design/SKILL.md +0 -116
  71. package/skills/codebase-design/agents/openai.yaml +0 -3
  72. package/skills/diagnosing-bugs/LICENSE +0 -21
  73. package/skills/diagnosing-bugs/SKILL.md +0 -140
  74. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  75. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  76. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  77. package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
  78. package/skills/domain-modeling/LICENSE +0 -21
  79. package/skills/domain-modeling/SKILL.md +0 -76
  80. package/skills/domain-modeling/agents/openai.yaml +0 -3
  81. package/skills/grill-me/LICENSE +0 -21
  82. package/skills/grill-me/SKILL.md +0 -8
  83. package/skills/grill-me/agents/openai.yaml +0 -4
  84. package/skills/grill-with-docs/LICENSE +0 -21
  85. package/skills/grill-with-docs/SKILL.md +0 -8
  86. package/skills/grill-with-docs/agents/openai.yaml +0 -4
  87. package/skills/grilling/LICENSE +0 -21
  88. package/skills/grilling/SKILL.md +0 -30
  89. package/skills/grilling/agents/openai.yaml +0 -3
  90. package/skills/handoff/LICENSE +0 -21
  91. package/skills/handoff/SKILL.md +0 -17
  92. package/skills/handoff/agents/openai.yaml +0 -4
  93. package/skills/implement/LICENSE +0 -21
  94. package/skills/implement/SKILL.md +0 -16
  95. package/skills/implement/agents/openai.yaml +0 -4
  96. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  97. package/skills/improve-codebase-architecture/LICENSE +0 -21
  98. package/skills/improve-codebase-architecture/SKILL.md +0 -72
  99. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
  100. package/skills/prototype/LICENSE +0 -21
  101. package/skills/prototype/LOGIC.md +0 -67
  102. package/skills/prototype/SKILL.md +0 -28
  103. package/skills/prototype/UI.md +0 -112
  104. package/skills/prototype/agents/openai.yaml +0 -3
  105. package/skills/research/LICENSE +0 -21
  106. package/skills/research/SKILL.md +0 -14
  107. package/skills/research/agents/openai.yaml +0 -3
  108. package/skills/resolving-merge-conflicts/LICENSE +0 -21
  109. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  110. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  111. package/skills/tdd/LICENSE +0 -21
  112. package/skills/tdd/SKILL.md +0 -40
  113. package/skills/tdd/agents/openai.yaml +0 -3
  114. package/skills/tdd/mocking.md +0 -59
  115. package/skills/tdd/tests.md +0 -77
  116. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  117. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  118. package/skills/teach/LICENSE +0 -21
  119. package/skills/teach/MISSION-FORMAT.md +0 -31
  120. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  121. package/skills/teach/SKILL.md +0 -141
  122. package/skills/teach/agents/openai.yaml +0 -4
  123. package/skills/to-questionnaire/LICENSE +0 -21
  124. package/skills/to-questionnaire/SKILL.md +0 -55
  125. package/skills/to-questionnaire/agents/openai.yaml +0 -4
  126. package/skills/to-spec/LICENSE +0 -21
  127. package/skills/to-spec/SKILL.md +0 -76
  128. package/skills/to-spec/agents/openai.yaml +0 -4
  129. package/skills/to-tickets/LICENSE +0 -21
  130. package/skills/to-tickets/SKILL.md +0 -106
  131. package/skills/to-tickets/agents/openai.yaml +0 -4
  132. package/skills/wait-what/LICENSE +0 -21
  133. package/skills/wait-what/SKILL.md +0 -8
  134. package/skills/wait-what/agents/openai.yaml +0 -4
  135. package/skills/wayfinder/LICENSE +0 -21
  136. package/skills/wayfinder/SKILL.md +0 -129
  137. package/skills/wayfinder/agents/openai.yaml +0 -4
  138. package/skills/writing-for-agents/LICENSE +0 -21
  139. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  140. package/skills/writing-for-agents/SKILL.md +0 -83
  141. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -0,0 +1,263 @@
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { readFile, rename, rm, writeFile } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { setTimeout as delay } from 'node:timers/promises';
7
+ import { KIT_RELEASE } from './clis.js';
8
+ import { restart } from './end.js';
9
+ import { awaitsTakeover, desktopPrefix, earlierHome, earlierPrefix, oneFolder } from './home.js';
10
+ import { defineSupervisor, launchAgent, linger, manage, required, systemd, userUnit } from './supervisor.js';
11
+ import { placeServedRelease } from './update.js';
12
+ import { followRoot, merged, removeFolder } from './workspace.js';
13
+ const SERVER_PREFIX = '/opt/house-kit';
14
+ const SERVER_BIN = '/usr/local/bin';
15
+ const SERVER_UNIT = '/etc/systemd/system/house-kit.service';
16
+ const SERVER_WORKSPACE = '/agents/house';
17
+ const CONTAINER = 'house-kit';
18
+ const CONTAINER_HOME = '/kit-home';
19
+ const CONTAINER_WORKSPACE = '/agents/house';
20
+ const WINDOWS_COPY = '.house-kit-home';
21
+ const WINDOWS_WORKSPACE = 'workspace';
22
+ const PLACEMENT = 'placement';
23
+ const RELEASES = 'kit';
24
+ const WORKSPACE_FOLDERS = ['agents', 'local-copies'];
25
+ const RECORDS = join('local-copies', 'rooms');
26
+ const COMMANDS = ['kit', 'house'];
27
+ const DROPPED_FLAGS = / --(?:linux|container)$/u;
28
+ // A Mac's LaunchAgent is reloaded by a process of its own, which ends this one within moments; a minute bounds a reload that never comes.
29
+ const RELOAD_MS = 60_000;
30
+ function root() {
31
+ return process.getuid() === 0;
32
+ }
33
+ function desktopWorkspace() {
34
+ return join(homedir(), 'AgentsHouse');
35
+ }
36
+ function desktopBin() {
37
+ return join(homedir(), '.local', 'bin');
38
+ }
39
+ function unitValue(text, name) {
40
+ const quoted = new RegExp(`^Environment="${name}=((?:[^"\\\\]|\\\\.)*)"$`, 'mu').exec(text)?.[1];
41
+ return quoted?.replace(/\\(.)/gu, '$1').replaceAll('%%', '%');
42
+ }
43
+ function plistValue(text, name) {
44
+ const value = new RegExp(`<key>${name}</key>\\s*<string>([^<]*)</string>`, 'u').exec(text)?.[1];
45
+ return value?.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&amp;', '&');
46
+ }
47
+ function readText(path) {
48
+ try {
49
+ return readFileSync(path, 'utf8');
50
+ }
51
+ catch (error) {
52
+ if (error.code === 'ENOENT')
53
+ return null;
54
+ throw error;
55
+ }
56
+ }
57
+ function desktopKit() {
58
+ const darwin = process.platform === 'darwin';
59
+ const definition = readText(darwin ? launchAgent() : userUnit()) ?? '';
60
+ const value = (name) => (darwin ? plistValue(definition, name) : unitValue(definition, name));
61
+ const named = value('HOUSE_KIT_HOME');
62
+ if (named === undefined && !existsSync(desktopPrefix()))
63
+ return null;
64
+ const workspace = value('HOUSE_KIT_WORKSPACE') ?? desktopWorkspace();
65
+ return { kind: 'desktop', home: named ?? join(homedir(), '.house-kit'), workspace, seen: workspace, unit: named !== undefined };
66
+ }
67
+ function serverKit() {
68
+ const unit = readText(SERVER_UNIT);
69
+ const account = spawnSync('id', ['-un'], { encoding: 'utf8' }).stdout.trim();
70
+ if (unit !== null && !new RegExp(`^User=${account}$`, 'mu').test(unit))
71
+ return null;
72
+ if (unit === null && !(root() && existsSync(SERVER_PREFIX)))
73
+ return null;
74
+ const home = (unit === null ? undefined : unitValue(unit, 'HOUSE_KIT_HOME')) ?? join(homedir(), '.house-kit');
75
+ return { kind: 'server', home, workspace: SERVER_WORKSPACE, seen: SERVER_WORKSPACE, unit: unit !== null };
76
+ }
77
+ function docker(args) {
78
+ return spawnSync('docker', args, { encoding: 'utf8' });
79
+ }
80
+ function containerKit() {
81
+ const inspected = docker(['container', 'inspect', '--format', '{{json .Mounts}}', CONTAINER]);
82
+ if (inspected.error !== undefined)
83
+ return null;
84
+ if (inspected.status !== 0) {
85
+ if (readText(join(homedir(), '.house-kit', 'placement'))?.trim() !== 'container' || docker(['info']).status === 0)
86
+ return null;
87
+ throw new Error(`Kit runs in the container ${CONTAINER} on this computer and Docker does not answer; start Docker, then run this command again`);
88
+ }
89
+ const mounts = JSON.parse(inspected.stdout);
90
+ const source = (destination) => mounts.find((mount) => mount.Destination === destination)?.Source;
91
+ const home = source(CONTAINER_HOME);
92
+ const workspace = source(CONTAINER_WORKSPACE);
93
+ if (home === undefined || workspace === undefined)
94
+ throw new Error(`the container ${CONTAINER} mounts no Kit home or no workspace`);
95
+ return { kind: 'container', home, workspace, seen: CONTAINER_WORKSPACE, unit: false };
96
+ }
97
+ function windowsKit() {
98
+ const home = join(homedir(), WINDOWS_COPY);
99
+ const workspace = readText(join(home, WINDOWS_WORKSPACE))?.trim();
100
+ if (workspace === undefined)
101
+ return null;
102
+ return { kind: 'windows', home, workspace, seen: CONTAINER_WORKSPACE, unit: false };
103
+ }
104
+ function defaulted(earlier) {
105
+ return earlier.kind === 'server' || earlier.workspace === desktopWorkspace();
106
+ }
107
+ async function relocate(earlier) {
108
+ const folder = oneFolder();
109
+ const copied = earlier.kind === 'windows';
110
+ const kept = (copied ? [RELEASES, PLACEMENT, WINDOWS_WORKSPACE] : [RELEASES]).map((name) => join(earlier.home, name));
111
+ await merged(earlier.home, folder, (source) => (kept.includes(source) ? 'stays' : 'moves'));
112
+ if (earlier.kind === 'container')
113
+ await rm(join(earlier.home, RELEASES), { recursive: true, force: true });
114
+ if (!copied)
115
+ await removeFolder(earlier.home);
116
+ const command = join(folder, 'install-command');
117
+ const recorded = await readFile(command, 'utf8').catch(() => null);
118
+ if (recorded !== null && DROPPED_FLAGS.test(recorded.trim()))
119
+ await writeFile(command, `${recorded.trim().replace(DROPPED_FLAGS, '')}\n`);
120
+ const workspace = defaulted(earlier) ? folder : earlier.workspace;
121
+ if (defaulted(earlier)) {
122
+ for (const name of WORKSPACE_FOLDERS)
123
+ await merged(join(earlier.workspace, name), join(folder, name));
124
+ if (earlier.kind !== 'server')
125
+ await removeFolder(earlier.workspace);
126
+ }
127
+ else {
128
+ const settings = join(folder, 'kit.json');
129
+ const stored = JSON.parse((await readFile(settings, 'utf8').catch(() => null)) ?? '{}');
130
+ if (stored.workspace === undefined) {
131
+ await writeFile(`${settings}.new`, `${JSON.stringify({ ...stored, workspace })}\n`, { mode: 0o600 });
132
+ await rename(`${settings}.new`, settings);
133
+ }
134
+ }
135
+ await followRoot(join(folder, RECORDS), earlier.seen, workspace);
136
+ if (copied)
137
+ await rm(earlier.home, { recursive: true, force: true });
138
+ }
139
+ function elevated(args, failed) {
140
+ if (root())
141
+ required(args[0], args.slice(1), failed);
142
+ else
143
+ required('sudo', args, failed);
144
+ }
145
+ function stopServer(earlier, now) {
146
+ if (!earlier.unit)
147
+ return;
148
+ elevated(['systemctl', 'disable', ...(now ? ['--now'] : []), 'house-kit.service'], 'the earlier Kit service could not be stopped');
149
+ }
150
+ function removeServer(earlier) {
151
+ if (earlier.unit) {
152
+ elevated(['rm', '-f', SERVER_UNIT], `${SERVER_UNIT} could not be removed`);
153
+ elevated(['systemctl', 'daemon-reload'], 'systemd could not forget the earlier Kit service');
154
+ }
155
+ elevated(['rm', '-rf', SERVER_PREFIX, ...COMMANDS.map((command) => join(SERVER_BIN, command))], `${SERVER_PREFIX} could not be removed`);
156
+ const emptied = [SERVER_WORKSPACE, '/agents'].filter((path) => existsSync(path));
157
+ if (emptied.length > 0)
158
+ elevated(['rmdir', '--ignore-fail-on-non-empty', ...emptied], `${SERVER_WORKSPACE} could not be removed`);
159
+ }
160
+ async function removeDesktop() {
161
+ await rm(desktopPrefix(), { recursive: true, force: true });
162
+ for (const command of COMMANDS)
163
+ await rm(join(desktopBin(), command), { force: true });
164
+ }
165
+ function stopDesktop() {
166
+ if (process.platform === 'darwin') {
167
+ manage('launchctl', ['bootout', `gui/${process.getuid()}/house-kit`]);
168
+ return;
169
+ }
170
+ manage('systemctl', ['--user', 'disable', '--now', 'house-kit.service']);
171
+ }
172
+ export async function takeOverEarlier() {
173
+ const earlier = windowsKit() ?? containerKit() ?? serverKit() ?? desktopKit();
174
+ if (earlier === null)
175
+ return;
176
+ process.stdout.write(`Moving the Kit installed before into ${oneFolder()}.\n`);
177
+ if (earlier.kind === 'container')
178
+ required('docker', ['rm', '-f', CONTAINER], `the container ${CONTAINER} could not be removed`);
179
+ if (earlier.kind === 'server' && earlier.unit && !root())
180
+ process.stdout.write('Removing the earlier Kit service; sudo may ask for your password.\n');
181
+ if (earlier.kind === 'server')
182
+ stopServer(earlier, true);
183
+ if (earlier.kind === 'desktop')
184
+ stopDesktop();
185
+ await relocate(earlier);
186
+ if (earlier.kind === 'server')
187
+ removeServer(earlier);
188
+ if (earlier.kind === 'desktop')
189
+ await removeDesktop();
190
+ }
191
+ function movable() {
192
+ if (awaitsTakeover())
193
+ return null;
194
+ if (root())
195
+ return existsSync(SERVER_PREFIX) ? serverKit() : null;
196
+ if (!existsSync(desktopPrefix()))
197
+ return null;
198
+ const desktop = desktopKit();
199
+ if (earlierPrefix() === null)
200
+ return desktop;
201
+ return { ...desktop, home: earlierHome(), workspace: process.env.HOUSE_KIT_WORKSPACE ?? desktop.workspace };
202
+ }
203
+ function supervised() {
204
+ return process.platform === 'darwin' || (systemd() && process.env.HOUSE_KIT_SANDBOX !== '1');
205
+ }
206
+ async function ready() {
207
+ try {
208
+ if (supervised() && process.platform !== 'darwin')
209
+ await linger();
210
+ }
211
+ catch (error) {
212
+ process.stderr.write(`kit: Kit stays where it was installed and moves at its next start: ${error.message}\n`);
213
+ return false;
214
+ }
215
+ const failure = await placeServedRelease(join(oneFolder(), RELEASES));
216
+ if (failure === null)
217
+ return true;
218
+ process.stderr.write(`kit: Kit stays where it was installed and moves at its next start: ${failure}\n`);
219
+ return false;
220
+ }
221
+ async function reloadLaunchAgent() {
222
+ const target = `gui/${process.getuid()}`;
223
+ spawn('/bin/sh', ['-c', `launchctl bootout ${target}/house-kit; launchctl bootstrap ${target} "$0"`, launchAgent()], {
224
+ detached: true,
225
+ stdio: 'ignore',
226
+ }).unref();
227
+ await delay(RELOAD_MS);
228
+ restart('the LaunchAgent was not reloaded; its next start runs Kit from its one folder');
229
+ }
230
+ export async function moveEarlier() {
231
+ const earlier = movable();
232
+ if (earlier === null)
233
+ return;
234
+ const within = earlierPrefix() !== null;
235
+ if (within && !(await ready()))
236
+ return;
237
+ process.stderr.write(`kit: moving Kit home ${earlier.home} into ${oneFolder()}\n`);
238
+ await relocate(earlier);
239
+ if (within && supervised())
240
+ await defineSupervisor();
241
+ if (within && supervised() && process.platform !== 'darwin') {
242
+ required('systemctl', ['--user', 'daemon-reload'], 'systemd could not read the Kit service');
243
+ required('systemctl', ['--user', '--quiet', 'reenable', 'house-kit.service'], 'the Kit service could not be enabled');
244
+ }
245
+ if (earlier.kind === 'server') {
246
+ if (within && earlier.unit && supervised())
247
+ required('systemctl', ['--user', '--no-block', 'start', 'house-kit.service'], 'the Kit service could not be started');
248
+ stopServer(earlier, false);
249
+ removeServer(earlier);
250
+ }
251
+ else {
252
+ await removeDesktop();
253
+ }
254
+ if (!within)
255
+ return;
256
+ if (process.platform === 'darwin')
257
+ await reloadLaunchAgent();
258
+ if (earlier.kind === 'server' && earlier.unit) {
259
+ manage('systemctl', ['--no-block', 'stop', 'house-kit.service']);
260
+ await delay(RELOAD_MS);
261
+ }
262
+ restart(`Kit ${KIT_RELEASE} moved into ${oneFolder()}; its supervisor starts it there`);
263
+ }
package/dist/end.js CHANGED
@@ -1,8 +1,26 @@
1
- import { killDescendants } from './acp.js';
2
- export const REPLACED = 'another Kit started for this Environment';
3
- export const SIGN_IN_AGAIN = 'sign in again';
4
- export function end(reason) {
1
+ import { forgetRejected } from './home.js';
2
+ import { installCommand } from './placement.js';
3
+ import { killDescendants } from './scope.js';
4
+ export const REPLACED = 'another Kit process started for this Environment';
5
+ function exit(reason, status) {
5
6
  process.stderr.write(`kit: ${reason}\n`);
6
7
  killDescendants();
7
- process.exit(0);
8
+ process.exit(status);
9
+ }
10
+ export function end(reason) {
11
+ exit(reason, process.env.HOUSE_KIT_RESIDENT === String(process.pid) ? 0 : 1);
12
+ }
13
+ export function restart(reason) {
14
+ exit(reason, 1);
15
+ }
16
+ export function updateLine(lead) {
17
+ const command = installCommand();
18
+ return command === null ? `${lead}; install it again.` : `${lead}. Update it: ${command}`;
19
+ }
20
+ export function updateRequired() {
21
+ end(updateLine("House does not serve this Kit's wire"));
22
+ }
23
+ export async function signInAgain(rejected) {
24
+ await forgetRejected(rejected);
25
+ restart('sign in again');
8
26
  }