@agentshouse/kit 0.2.1-alpha.2 → 0.2.1-alpha.21

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 (114) hide show
  1. package/README.md +39 -3
  2. package/dist/abort.js +9 -0
  3. package/dist/acp.js +27 -7
  4. package/dist/agents.js +204 -52
  5. package/dist/api.js +6 -1
  6. package/dist/authority-main.js +22 -0
  7. package/dist/bootstrap.json +31 -0
  8. package/dist/bridge.js +178 -54
  9. package/dist/clis-main.js +23 -0
  10. package/dist/clis.js +106 -32
  11. package/dist/configure-main.js +6 -0
  12. package/dist/conversations.js +128 -36
  13. package/dist/copies.js +809 -0
  14. package/dist/enrol-main.js +4 -0
  15. package/dist/git-main.js +153 -0
  16. package/dist/git.js +85 -0
  17. package/dist/home.js +36 -7
  18. package/dist/house-main.js +112 -41
  19. package/dist/instructions.js +16 -10
  20. package/dist/kit-main.js +2 -0
  21. package/dist/login.js +29 -5
  22. package/dist/mcp.js +38 -0
  23. package/dist/operation.js +12 -0
  24. package/dist/refusals.js +41 -0
  25. package/dist/resident.js +63 -7
  26. package/dist/sign-in.js +21 -5
  27. package/dist/skills.js +78 -0
  28. package/dist/transcription.js +122 -0
  29. package/dist/translate.js +51 -0
  30. package/dist/update.js +117 -0
  31. package/how-we-work.md +23 -0
  32. package/package.json +13 -9
  33. package/skills/ask-matt/LICENSE +21 -0
  34. package/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
  35. package/skills/ask-matt/SKILL.md +91 -0
  36. package/skills/ask-matt/agents/openai.yaml +4 -0
  37. package/skills/code-review/LICENSE +21 -0
  38. package/skills/code-review/SKILL.md +89 -0
  39. package/skills/code-review/agents/openai.yaml +3 -0
  40. package/skills/codebase-design/DEEPENING.md +37 -0
  41. package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  42. package/skills/codebase-design/LICENSE +21 -0
  43. package/skills/codebase-design/SKILL.md +116 -0
  44. package/skills/codebase-design/agents/openai.yaml +3 -0
  45. package/skills/diagnosing-bugs/LICENSE +21 -0
  46. package/skills/diagnosing-bugs/SKILL.md +140 -0
  47. package/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  48. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  49. package/skills/domain-modeling/ADR-FORMAT.md +47 -0
  50. package/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  51. package/skills/domain-modeling/LICENSE +21 -0
  52. package/skills/domain-modeling/SKILL.md +76 -0
  53. package/skills/domain-modeling/agents/openai.yaml +3 -0
  54. package/skills/grill-me/LICENSE +21 -0
  55. package/skills/grill-me/SKILL.md +8 -0
  56. package/skills/grill-me/agents/openai.yaml +4 -0
  57. package/skills/grill-with-docs/LICENSE +21 -0
  58. package/skills/grill-with-docs/SKILL.md +8 -0
  59. package/skills/grill-with-docs/agents/openai.yaml +4 -0
  60. package/skills/grilling/LICENSE +21 -0
  61. package/skills/grilling/SKILL.md +30 -0
  62. package/skills/grilling/agents/openai.yaml +3 -0
  63. package/skills/handoff/LICENSE +21 -0
  64. package/skills/handoff/SKILL.md +17 -0
  65. package/skills/handoff/agents/openai.yaml +4 -0
  66. package/skills/implement/LICENSE +21 -0
  67. package/skills/implement/SKILL.md +16 -0
  68. package/skills/implement/agents/openai.yaml +4 -0
  69. package/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  70. package/skills/improve-codebase-architecture/LICENSE +21 -0
  71. package/skills/improve-codebase-architecture/SKILL.md +72 -0
  72. package/skills/improve-codebase-architecture/agents/openai.yaml +4 -0
  73. package/skills/prototype/LICENSE +21 -0
  74. package/skills/prototype/LOGIC.md +67 -0
  75. package/skills/prototype/SKILL.md +28 -0
  76. package/skills/prototype/UI.md +112 -0
  77. package/skills/prototype/agents/openai.yaml +3 -0
  78. package/skills/research/LICENSE +21 -0
  79. package/skills/research/SKILL.md +14 -0
  80. package/skills/research/agents/openai.yaml +3 -0
  81. package/skills/resolving-merge-conflicts/LICENSE +21 -0
  82. package/skills/resolving-merge-conflicts/SKILL.md +16 -0
  83. package/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
  84. package/skills/tdd/LICENSE +21 -0
  85. package/skills/tdd/SKILL.md +40 -0
  86. package/skills/tdd/agents/openai.yaml +3 -0
  87. package/skills/tdd/mocking.md +59 -0
  88. package/skills/tdd/tests.md +77 -0
  89. package/skills/teach/GLOSSARY-FORMAT.md +35 -0
  90. package/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  91. package/skills/teach/LICENSE +21 -0
  92. package/skills/teach/MISSION-FORMAT.md +31 -0
  93. package/skills/teach/RESOURCES-FORMAT.md +32 -0
  94. package/skills/teach/SKILL.md +141 -0
  95. package/skills/teach/agents/openai.yaml +4 -0
  96. package/skills/to-questionnaire/LICENSE +21 -0
  97. package/skills/to-questionnaire/SKILL.md +55 -0
  98. package/skills/to-questionnaire/agents/openai.yaml +4 -0
  99. package/skills/to-spec/LICENSE +21 -0
  100. package/skills/to-spec/SKILL.md +76 -0
  101. package/skills/to-spec/agents/openai.yaml +4 -0
  102. package/skills/to-tickets/LICENSE +21 -0
  103. package/skills/to-tickets/SKILL.md +106 -0
  104. package/skills/to-tickets/agents/openai.yaml +4 -0
  105. package/skills/wait-what/LICENSE +21 -0
  106. package/skills/wait-what/SKILL.md +8 -0
  107. package/skills/wait-what/agents/openai.yaml +4 -0
  108. package/skills/wayfinder/LICENSE +21 -0
  109. package/skills/wayfinder/SKILL.md +129 -0
  110. package/skills/wayfinder/agents/openai.yaml +4 -0
  111. package/skills/writing-for-agents/LICENSE +21 -0
  112. package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  113. package/skills/writing-for-agents/SKILL.md +83 -0
  114. package/skills/writing-for-agents/agents/openai.yaml +3 -0
package/README.md CHANGED
@@ -7,17 +7,53 @@ through the agent CLIs you chose and gives each Agent the `house` command.
7
7
  ## Install
8
8
 
9
9
  Connect a computer from agents.house. It gives you the one command that
10
- installs House Kit on that computer and updates it when you run it again.
10
+ installs House Kit on that computer and updates it when you run it again. On
11
+ macOS and Linux it installs House Kit natively under your own account, without
12
+ an admin password, as a service that runs while you are logged in. `kit` and
13
+ `house` are then on your login shell's `PATH`, and your workspace is
14
+ `~/AgentsHouse` unless you pass `--workspace <path>`.
15
+
16
+ Add `--container` to run House Kit in one Docker container instead, with your
17
+ workspace mounted at `/agents/house`; your Agents then reach only that
18
+ workspace. On Windows 11 the container is the one choice. Append a `kit` or
19
+ `house` command to the container's command to run it in that container.
20
+ Running the command for the other choice on a connected computer asks you to
21
+ confirm, then replaces its Environment, whose Agents end, with a new one.
22
+
23
+ On your own Ubuntu 26.04 server, run the Linux command with `--linux` to
24
+ install House Kit natively, with its workspace at `/agents/house`; `kit` and
25
+ `house` are then on the server's `PATH`.
26
+
27
+ House Kit runs the agent CLIs your login shell finds and installs a missing
28
+ one through that CLI's own installer. Running the command again offers to
29
+ update each CLI older than House Kit needs; add `--update-clis` to update every
30
+ one to its latest release without asking.
31
+
32
+ House Kit also gives every Agent on the Environment a set of agent skills. Add
33
+ `--no-skills` to the command to leave them out; running it again without the
34
+ flag brings them back.
11
35
 
12
36
  ## Commands
13
37
 
14
38
  `kit login` opens a link you confirm in your browser and keeps the
15
39
  Environment's credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is
16
40
  set. Pass `--manual` to paste the code by hand on a machine without a browser,
17
- and `--environment <id>` to reconnect an Environment you already have.
41
+ and `--environment <id>` to reconnect an Environment you already have. It also
42
+ connects your own agent: `house <tool>` run outside an Agent conversation calls
43
+ House as you, until you revoke that connection on Connections.
18
44
 
19
- `kit resident` keeps the Environment connected.
45
+ `kit resident` keeps the Environment connected, and keeps the Rooms you chose
46
+ for this Environment as Git repositories under `working-copies` in the
47
+ workspace. Commit in one and run `house git push --owner` there to send the
48
+ commit to House; in the container, run it through the install command from the
49
+ copy's directory. Inside an Agent conversation the Agent runs `house git push`.
50
+
51
+ House Kit turns each audio file of your message to an Agent into text on this
52
+ computer before the Agent reads the message. The first audio file downloads the
53
+ speech engine and model, about 425 MB, into `~/.house-kit`.
20
54
 
21
55
  ## License
22
56
 
23
57
  MIT
58
+
59
+ The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
package/dist/abort.js ADDED
@@ -0,0 +1,9 @@
1
+ export function unlessAborted(work, signal) {
2
+ return new Promise((resolve, reject) => {
3
+ const aborted = () => reject(signal.reason);
4
+ signal.addEventListener('abort', aborted, { once: true });
5
+ if (signal.aborted)
6
+ aborted();
7
+ work.then(resolve, reject).finally(() => signal.removeEventListener('abort', aborted));
8
+ });
9
+ }
package/dist/acp.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
2
- import { spawn } from 'node:child_process';
2
+ import { execFileSync, spawn } from 'node:child_process';
3
3
  import { readdirSync, readFileSync } from 'node:fs';
4
4
  import { Readable, Writable } from 'node:stream';
5
- import { CLIS, KIT_VERSION, cliCommand } from './clis.js';
5
+ import { CLIS, KIT_VERSION, adapterCommand, withoutProxy } from './clis.js';
6
6
  export const TURN_STARTED = 'kit/turn_started';
7
7
  export const TURN_ENDED = 'kit/turn_ended';
8
- export async function startAdapter(kind, cwd, app, jobs = () => undefined, env = process.env) {
9
- const child = spawn(cliCommand(kind), CLIS[kind].args, {
8
+ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined, added = {}) {
9
+ const adapter = CLIS[kind].adapter;
10
+ const child = spawn(adapter === null ? cli : adapterCommand(kind), CLIS[kind].args, {
10
11
  cwd,
11
- env,
12
+ env: { ...withoutProxy(), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
12
13
  stdio: ['pipe', 'pipe', 'pipe'],
13
14
  detached: true,
14
15
  });
@@ -60,15 +61,29 @@ export async function startAdapter(kind, cwd, app, jobs = () => undefined, env =
60
61
  throw error;
61
62
  }
62
63
  }
64
+ const LISTING_BYTES = 1 << 28;
65
+ function listed(options) {
66
+ return execFileSync('ps', [options, '-o', 'pid=,ppid=,command='], { encoding: 'utf8', maxBuffer: LISTING_BYTES })
67
+ .split('\n')
68
+ .flatMap((line) => {
69
+ const fields = /^\s*(\d+)\s+(\d+)\s?(.*)$/.exec(line);
70
+ return fields === null ? [] : [[Number(fields[1]), Number(fields[2]), fields[3]]];
71
+ });
72
+ }
63
73
  function parents() {
64
74
  const children = new Map();
75
+ const adopt = (pid, parent) => children.set(parent, [...(children.get(parent) ?? []), pid]);
76
+ if (process.platform === 'darwin') {
77
+ for (const [pid, parent] of listed('-Aww'))
78
+ adopt(pid, parent);
79
+ return children;
80
+ }
65
81
  for (const entry of readdirSync('/proc')) {
66
82
  if (!/^\d+$/.test(entry))
67
83
  continue;
68
84
  try {
69
85
  const stat = readFileSync(`/proc/${entry}/stat`, 'utf8');
70
- const parent = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]);
71
- children.set(parent, [...(children.get(parent) ?? []), Number(entry)]);
86
+ adopt(Number(entry), Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]));
72
87
  }
73
88
  catch { }
74
89
  }
@@ -96,6 +111,11 @@ function killAll(pids) {
96
111
  }
97
112
  }
98
113
  function marked(marker) {
114
+ if (process.platform === 'darwin') {
115
+ return listed('-AEww')
116
+ .filter(([, , command]) => ` ${command} `.includes(` ${marker} `))
117
+ .map(([pid]) => pid);
118
+ }
99
119
  return readdirSync('/proc')
100
120
  .filter((entry) => {
101
121
  try {
package/dist/agents.js CHANGED
@@ -1,24 +1,90 @@
1
1
  import { client } from '@agentclientprotocol/sdk';
2
- import { readFile } from 'node:fs/promises';
3
- import { startAdapter } from './acp.js';
4
- import { CLIS, KIT_VERSION, cliCommand, install, run } from './clis.js';
5
- import { kitHome } from './home.js';
6
- async function signedIn(kind) {
7
- const probe = CLIS[kind].signedIn;
8
- if ('command' in probe) {
9
- return (await run(cliCommand(kind), probe.command, 30_000)).status === 0;
2
+ import { readFile, realpath } from 'node:fs/promises';
3
+ import { killTree, startAdapter } from './acp.js';
4
+ import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
5
+ import { agentBase, kitHome } from './home.js';
6
+ const SIGNED_OUT = { signed_in: false, models: [] };
7
+ function select(options, category) {
8
+ const option = options.find((candidate) => candidate.category === category);
9
+ return option?.type === 'select' ? option : undefined;
10
+ }
11
+ function values(options) {
12
+ return options.flatMap((entry) => ('group' in entry ? entry.options : [entry])).map((entry) => entry.value);
13
+ }
14
+ function causeOf(error) {
15
+ return error instanceof Error ? error.message : String(error);
16
+ }
17
+ function logged(error) {
18
+ process.stderr.write(`kit: ${causeOf(error)}\n`);
19
+ }
20
+ async function models(kind, adapter, known) {
21
+ const agent = adapter.connection.agent;
22
+ const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
23
+ let options = opened.configOptions ?? [];
24
+ const model = select(options, 'model');
25
+ if (model === undefined)
26
+ return [];
27
+ const offered = [];
28
+ for (const value of values(model.options)) {
29
+ if (select(options, 'model')?.currentValue !== value) {
30
+ try {
31
+ options = (await agent.request('session/set_config_option', { sessionId: opened.sessionId, configId: model.id, value })).configOptions;
32
+ }
33
+ catch (error) {
34
+ process.stderr.write(`kit: ${kind} refused its model ${value}: ${causeOf(error)}\n`);
35
+ offered.push({ model: value, efforts: known.find((entry) => entry.model === value)?.efforts ?? [] });
36
+ continue;
37
+ }
38
+ }
39
+ const effort = select(options, 'thought_level');
40
+ offered.push({ model: value, efforts: effort === undefined ? [] : values(effort.options) });
10
41
  }
42
+ return offered;
43
+ }
44
+ async function offer(kind, cli, known) {
45
+ const probe = CLIS[kind].signedIn;
46
+ if ('command' in probe && (await run(cli, probe.command, 30_000)).status !== 0)
47
+ return SIGNED_OUT;
48
+ let adapter;
11
49
  try {
12
- const adapter = await startAdapter(kind, kitHome(), client({ name: '@agentshouse/kit' }));
13
- adapter.child.kill('SIGKILL');
14
- const method = adapter.initialized._meta?.[probe.initializeMeta];
15
- return typeof method === 'string' && method.length > 0;
50
+ adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }));
51
+ if ('initializeMeta' in probe) {
52
+ const method = adapter.initialized._meta?.[probe.initializeMeta];
53
+ if (typeof method !== 'string' || method.length === 0)
54
+ return SIGNED_OUT;
55
+ }
56
+ return { signed_in: true, models: await models(kind, adapter, known.models) };
16
57
  }
17
- catch {
18
- return false;
58
+ catch (error) {
59
+ process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
60
+ return { signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true, models: known.models };
19
61
  }
62
+ finally {
63
+ if (adapter !== undefined)
64
+ killTree(adapter.child);
65
+ }
66
+ }
67
+ function reported(kind, reading) {
68
+ return {
69
+ kind,
70
+ release: reading.release,
71
+ ...(reading.minimum === undefined ? {} : { minimum: reading.minimum }),
72
+ failure: reading.failure,
73
+ signed_in: reading.signed_in,
74
+ models: reading.models,
75
+ };
76
+ }
77
+ function tooOld(kind, release) {
78
+ const cli = CLIS[kind];
79
+ return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
80
+ }
81
+ async function sshHostKey() {
82
+ const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
83
+ return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
20
84
  }
21
85
  async function operatingSystem() {
86
+ if (process.platform === 'darwin')
87
+ return `macOS ${(await run('sw_vers', ['-productVersion'], 10_000)).output.trim()}`;
22
88
  const release = await readFile('/etc/os-release', 'utf8');
23
89
  return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
24
90
  }
@@ -26,19 +92,18 @@ export class Agents {
26
92
  desired = { agents: [], routes: [] };
27
93
  house;
28
94
  reading = Promise.resolve();
95
+ queues = new Map();
29
96
  installing = Promise.resolve();
30
- releases = new Map();
31
- reporting = null;
32
- again = false;
97
+ readings = new Map();
98
+ reads = new Map();
99
+ sending = Promise.resolve();
100
+ sent = null;
33
101
  constructor(house) {
34
102
  this.house = house;
35
103
  }
36
104
  read() {
37
105
  return this.reading.then(() => undefined, () => undefined);
38
106
  }
39
- installed() {
40
- return this.installing.catch(() => undefined);
41
- }
42
107
  route(agentId) {
43
108
  return this.desired.routes.find((route) => route.agent_id === agentId);
44
109
  }
@@ -48,43 +113,130 @@ export class Agents {
48
113
  return this.desired;
49
114
  });
50
115
  this.reading = reading;
51
- const installing = this.installed()
52
- .then(() => reading)
53
- .then(({ agents }) => this.install(agents));
54
- this.installing = installing;
55
- if (this.reporting === null)
56
- this.reporting = this.reports();
57
- else
58
- this.again = true;
59
- return Promise.all([installing, this.reporting]).then(() => undefined);
60
- }
61
- async report() {
62
- const agents = [];
63
- for (const [kind, release] of this.releases) {
64
- agents.push({ kind, release, signed_in: release !== null && (await signedIn(kind)) });
65
- }
66
- await this.house.deliver('/kit/agents/report', {
67
- os: await operatingSystem(),
68
- kit_version: KIT_VERSION,
69
- agents,
116
+ return reading.then(({ agents }) => {
117
+ Promise.all(agents.map((kind) => this.queue(kind, () => this.load(kind))))
118
+ .then(() => this.report())
119
+ .catch(logged);
120
+ });
121
+ }
122
+ cli(kind) {
123
+ return this.queue(kind, async () => {
124
+ const resolved = await this.resolve(kind);
125
+ if (!('cli' in resolved)) {
126
+ this.update(kind, resolved);
127
+ throw new Error(resolved.failure ?? tooOld(kind, resolved.release));
128
+ }
129
+ const { cli, release } = resolved;
130
+ const known = this.readings.get(kind);
131
+ const kept = known?.release === null || known?.minimum !== undefined ? SIGNED_OUT : (known ?? SIGNED_OUT);
132
+ if (known?.release !== release || known.minimum !== undefined) {
133
+ this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models });
134
+ }
135
+ const read = this.nextRead(kind);
136
+ offer(kind, cli, kept)
137
+ .then((offered) => {
138
+ const current = this.readings.get(kind);
139
+ if (this.reads.get(kind) === read && current?.release === release)
140
+ this.update(kind, { ...current, ...offered });
141
+ })
142
+ .catch(logged);
143
+ return cli;
70
144
  });
71
145
  }
72
- async install(kinds) {
73
- const releases = new Map();
74
- for (const kind of kinds)
75
- releases.set(kind, await install(kind));
76
- this.releases = releases;
146
+ located(kind) {
147
+ return this.queue(kind, () => this.ensure(kind));
148
+ }
149
+ async reread(kind) {
150
+ await this.queue(kind, async () => {
151
+ this.nextRead(kind);
152
+ this.readings.set(kind, await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT));
153
+ });
154
+ await this.report();
155
+ }
156
+ report() {
157
+ const sending = this.sending.catch(() => undefined).then(() => this.send());
158
+ this.sending = sending;
159
+ return sending;
160
+ }
161
+ nextRead(kind) {
162
+ const read = (this.reads.get(kind) ?? 0) + 1;
163
+ this.reads.set(kind, read);
164
+ return read;
165
+ }
166
+ update(kind, reading) {
167
+ this.readings.set(kind, reading);
168
+ this.report().catch(logged);
169
+ }
170
+ queue(kind, work) {
171
+ const queued = (this.queues.get(kind) ?? Promise.resolve()).then(work);
172
+ this.queues.set(kind, queued.catch(() => undefined));
173
+ return queued;
77
174
  }
78
- async reports() {
175
+ async ensure(kind) {
176
+ const failed = await installAdapter(kind);
177
+ if (failed !== null)
178
+ throw new Error(failed);
179
+ const found = await locate(kind);
180
+ if (found !== null)
181
+ return found;
182
+ const installing = this.installing.catch(() => undefined).then(() => installCli(kind));
183
+ this.installing = installing;
184
+ const failure = await installing;
185
+ if (failure !== null)
186
+ throw new Error(failure);
187
+ const installed = await locate(kind);
188
+ if (installed === null)
189
+ throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
190
+ return installed;
191
+ }
192
+ async resolve(kind) {
193
+ let cli;
79
194
  try {
80
- do {
81
- this.again = false;
82
- await this.installing;
83
- await this.report();
84
- } while (this.again);
195
+ cli = await realpath(await this.ensure(kind));
85
196
  }
86
- finally {
87
- this.reporting = null;
197
+ catch (error) {
198
+ const failure = causeOf(error);
199
+ process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
200
+ return { release: null, failure, ...SIGNED_OUT };
88
201
  }
202
+ const release = await versionOf(cli);
203
+ if (release === null)
204
+ return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
205
+ const minimum = CLIS[kind].minimum;
206
+ if (below(release, minimum))
207
+ return { release, minimum, failure: null, ...SIGNED_OUT };
208
+ return { cli, release };
209
+ }
210
+ async examine(kind, known) {
211
+ const resolved = await this.resolve(kind);
212
+ if (!('cli' in resolved))
213
+ return resolved;
214
+ return { release: resolved.release, failure: null, ...(await offer(kind, resolved.cli, known)) };
215
+ }
216
+ async load(kind) {
217
+ const known = this.readings.get(kind);
218
+ if (known !== undefined && known.failure === null)
219
+ return;
220
+ this.nextRead(kind);
221
+ this.readings.set(kind, await this.examine(kind, SIGNED_OUT));
222
+ }
223
+ async send() {
224
+ const agents = this.desired.agents.flatMap((kind) => {
225
+ const reading = this.readings.get(kind);
226
+ return reading === undefined ? [] : [reported(kind, reading)];
227
+ });
228
+ const hostKey = await sshHostKey();
229
+ const body = {
230
+ os: await operatingSystem(),
231
+ kit_version: KIT_VERSION,
232
+ agent_base: agentBase(),
233
+ agents,
234
+ ...(hostKey === null ? {} : { ssh_host_key: hostKey }),
235
+ };
236
+ const state = JSON.stringify(body);
237
+ if (state === this.sent)
238
+ return;
239
+ await this.house.deliver('/kit/agents/report', body);
240
+ this.sent = state;
89
241
  }
90
242
  }
package/dist/api.js CHANGED
@@ -1,11 +1,16 @@
1
1
  import { readEnrolment } from './home.js';
2
2
  export class HouseRefusal extends Error {
3
3
  status;
4
+ text;
4
5
  constructor(path, status, text) {
5
6
  super(`House refused ${path} with ${status}: ${text}`);
6
7
  this.status = status;
8
+ this.text = text;
7
9
  }
8
10
  }
11
+ export function retryDelay(attempt) {
12
+ return Math.min(30_000, 1000 * 2 ** attempt);
13
+ }
9
14
  export async function post(house, path, body, credential, signal) {
10
15
  const answer = await fetch(new URL(path, house), {
11
16
  method: 'POST',
@@ -36,7 +41,7 @@ export const house = {
36
41
  if (error instanceof HouseRefusal && error.status < 500)
37
42
  throw error;
38
43
  process.stderr.write(`kit: ${path} did not reach House: ${error.message}\n`);
39
- await new Promise((resolve) => setTimeout(resolve, Math.min(30_000, 1000 * 2 ** attempt)));
44
+ await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
40
45
  if (!current())
41
46
  throw error;
42
47
  }
@@ -0,0 +1,22 @@
1
+ import { setGlobalProxyFromEnv } from 'node:http';
2
+ import { HouseRefusal, post } from './api.js';
3
+ import { readEnrolment } from './home.js';
4
+ function unanswered(error) {
5
+ return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
6
+ }
7
+ setGlobalProxyFromEnv();
8
+ try {
9
+ const { house, credential } = (await readEnrolment());
10
+ try {
11
+ await post(house, '/kit/agents/desired', {}, credential);
12
+ }
13
+ catch (error) {
14
+ if (!unanswered(error))
15
+ throw error;
16
+ process.stderr.write(`kit: House did not answer, so the stored credential stands: ${error.message}\n`);
17
+ }
18
+ }
19
+ catch (error) {
20
+ process.stderr.write(`kit: ${error.message}\n`);
21
+ process.exitCode = 1;
22
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "version": "0.2.1-alpha.21",
4
+ "hosts": {
5
+ "linux": {
6
+ "command": "bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.21/connect-linux.sh)",
7
+ "asset": {
8
+ "name": "connect-linux.sh",
9
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.21/connect-linux.sh"
10
+ },
11
+ "workspace": {
12
+ "argument": "--workspace",
13
+ "quoting": "posix"
14
+ },
15
+ "container": {
16
+ "argument": "--container"
17
+ }
18
+ },
19
+ "windows": {
20
+ "command": "& ([scriptblock]::Create((irm https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.21/connect-windows.ps1)))",
21
+ "asset": {
22
+ "name": "connect-windows.ps1",
23
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.21/connect-windows.ps1"
24
+ },
25
+ "workspace": {
26
+ "argument": "--workspace",
27
+ "quoting": "powershell"
28
+ }
29
+ }
30
+ }
31
+ }