@agentshouse/kit 0.2.1-ccf188e02985d → 0.2.1-cd423aab3dbcc

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 (164) hide show
  1. package/README.md +35 -42
  2. package/dist/acp.js +66 -12
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +122 -53
  5. package/dist/api.js +15 -10
  6. package/dist/binaries.js +60 -0
  7. package/dist/bridge.js +100 -45
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +88 -0
  10. package/dist/chunks.js +54 -0
  11. package/dist/clis.js +62 -50
  12. package/dist/connect.js +121 -0
  13. package/dist/connection.js +120 -0
  14. package/dist/content.js +106 -0
  15. package/dist/conversations.js +617 -240
  16. package/dist/copies.js +1277 -623
  17. package/dist/earlier.js +273 -0
  18. package/dist/end.js +12 -5
  19. package/dist/events.js +549 -281
  20. package/dist/files.js +206 -38
  21. package/dist/git.js +2 -72
  22. package/dist/grok.js +39 -0
  23. package/dist/home.js +86 -29
  24. package/dist/house-cli.js +180 -189
  25. package/dist/house-main.js +3 -3
  26. package/dist/instructions.js +29 -11
  27. package/dist/keys.js +238 -0
  28. package/dist/kit-cli.js +18 -8
  29. package/dist/kit-main.js +3 -3
  30. package/dist/login.js +36 -22
  31. package/dist/logout.js +2 -2
  32. package/dist/manifest.js +75 -0
  33. package/dist/mcp.js +47 -7
  34. package/dist/owner.js +46 -0
  35. package/dist/placement.js +15 -20
  36. package/dist/refusals.js +50 -23
  37. package/dist/relay.js +21 -0
  38. package/dist/resident.js +141 -90
  39. package/dist/scope.js +15 -4
  40. package/dist/scripts.js +319 -0
  41. package/dist/secret-input.js +1 -1
  42. package/dist/settings.js +247 -0
  43. package/dist/sign-in.js +67 -21
  44. package/dist/silence.js +28 -0
  45. package/dist/skills.js +42 -97
  46. package/dist/supervisor.js +163 -0
  47. package/dist/transcription.js +88 -45
  48. package/dist/update.js +118 -120
  49. package/dist/wire.js +30 -4
  50. package/dist/work.js +27 -2
  51. package/dist/workspace.js +113 -0
  52. package/package.json +25 -22
  53. package/dist/authority-main.js +0 -22
  54. package/dist/bootstrap.json +0 -24
  55. package/dist/chatgpt.js +0 -32
  56. package/dist/clis-main.js +0 -23
  57. package/dist/configure-main.js +0 -6
  58. package/dist/enrol-main.js +0 -10
  59. package/dist/git-main.js +0 -153
  60. package/dist/inputs.js +0 -37
  61. package/dist/parts.js +0 -82
  62. package/dist/service-main.js +0 -9
  63. package/dist/service.js +0 -55
  64. package/dist/stream.js +0 -123
  65. package/dist/translate.js +0 -51
  66. package/how-we-work.md +0 -33
  67. package/skills/ask-matt/LICENSE +0 -21
  68. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  69. package/skills/ask-matt/SKILL.md +0 -97
  70. package/skills/ask-matt/agents/openai.yaml +0 -5
  71. package/skills/code-review/LICENSE +0 -21
  72. package/skills/code-review/SKILL.md +0 -89
  73. package/skills/code-review/agents/openai.yaml +0 -3
  74. package/skills/codebase-design/DEEPENING.md +0 -37
  75. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  76. package/skills/codebase-design/LICENSE +0 -21
  77. package/skills/codebase-design/SKILL.md +0 -114
  78. package/skills/codebase-design/agents/openai.yaml +0 -3
  79. package/skills/diagnosing-bugs/LICENSE +0 -21
  80. package/skills/diagnosing-bugs/SKILL.md +0 -138
  81. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  82. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  83. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  84. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  85. package/skills/domain-modeling/LICENSE +0 -21
  86. package/skills/domain-modeling/SKILL.md +0 -74
  87. package/skills/domain-modeling/agents/openai.yaml +0 -3
  88. package/skills/grill-me/LICENSE +0 -21
  89. package/skills/grill-me/SKILL.md +0 -7
  90. package/skills/grill-me/agents/openai.yaml +0 -5
  91. package/skills/grill-with-docs/LICENSE +0 -21
  92. package/skills/grill-with-docs/SKILL.md +0 -7
  93. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  94. package/skills/grilling/LICENSE +0 -21
  95. package/skills/grilling/SKILL.md +0 -30
  96. package/skills/grilling/agents/openai.yaml +0 -3
  97. package/skills/handoff/LICENSE +0 -21
  98. package/skills/handoff/SKILL.md +0 -16
  99. package/skills/handoff/agents/openai.yaml +0 -5
  100. package/skills/implement/LICENSE +0 -21
  101. package/skills/implement/SKILL.md +0 -17
  102. package/skills/implement/agents/openai.yaml +0 -5
  103. package/skills/implement-spec/LICENSE +0 -21
  104. package/skills/implement-spec/SKILL.md +0 -40
  105. package/skills/implement-spec/agents/openai.yaml +0 -5
  106. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  107. package/skills/improve-codebase-architecture/LICENSE +0 -21
  108. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  109. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  110. package/skills/pr/CREDITS.md +0 -3
  111. package/skills/pr/LICENSE +0 -21
  112. package/skills/pr/SKILL.md +0 -170
  113. package/skills/pr/agents/openai.yaml +0 -3
  114. package/skills/prototype/LICENSE +0 -21
  115. package/skills/prototype/LOGIC.md +0 -67
  116. package/skills/prototype/SKILL.md +0 -26
  117. package/skills/prototype/UI.md +0 -112
  118. package/skills/prototype/agents/openai.yaml +0 -3
  119. package/skills/research/LICENSE +0 -21
  120. package/skills/research/SKILL.md +0 -12
  121. package/skills/research/agents/openai.yaml +0 -3
  122. package/skills/retro/LICENSE +0 -21
  123. package/skills/retro/SKILL.md +0 -44
  124. package/skills/retro/agents/openai.yaml +0 -5
  125. package/skills/tdd/LICENSE +0 -21
  126. package/skills/tdd/SKILL.md +0 -38
  127. package/skills/tdd/agents/openai.yaml +0 -3
  128. package/skills/tdd/mocking.md +0 -59
  129. package/skills/tdd/tests.md +0 -77
  130. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  131. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  132. package/skills/teach/LICENSE +0 -21
  133. package/skills/teach/MISSION-FORMAT.md +0 -31
  134. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  135. package/skills/teach/SKILL.md +0 -140
  136. package/skills/teach/agents/openai.yaml +0 -5
  137. package/skills/to-questionnaire/LICENSE +0 -21
  138. package/skills/to-questionnaire/SKILL.md +0 -54
  139. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  140. package/skills/to-spec/LICENSE +0 -21
  141. package/skills/to-spec/SKILL.md +0 -75
  142. package/skills/to-spec/agents/openai.yaml +0 -5
  143. package/skills/to-tickets/LICENSE +0 -21
  144. package/skills/to-tickets/SKILL.md +0 -105
  145. package/skills/to-tickets/agents/openai.yaml +0 -5
  146. package/skills/triage/AGENT-BRIEF.md +0 -207
  147. package/skills/triage/LICENSE +0 -21
  148. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  149. package/skills/triage/SKILL.md +0 -112
  150. package/skills/triage/agents/openai.yaml +0 -5
  151. package/skills/wait-what/LICENSE +0 -21
  152. package/skills/wait-what/SKILL.md +0 -7
  153. package/skills/wait-what/agents/openai.yaml +0 -5
  154. package/skills/wayfinder/LICENSE +0 -21
  155. package/skills/wayfinder/SKILL.md +0 -128
  156. package/skills/wayfinder/agents/openai.yaml +0 -5
  157. package/skills/wizard/LICENSE +0 -21
  158. package/skills/wizard/SKILL.md +0 -44
  159. package/skills/wizard/agents/openai.yaml +0 -3
  160. package/skills/wizard/template.sh +0 -223
  161. package/skills/writing-for-agents/LICENSE +0 -21
  162. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  163. package/skills/writing-for-agents/SKILL.md +0 -81
  164. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/README.md CHANGED
@@ -1,60 +1,53 @@
1
- # House Kit
1
+ # Kit
2
2
 
3
- House Kit connects an Environment, a Linux computer or server, to [agents.house](https://agents.house). It runs
3
+ Kit connects an Environment, a Linux computer or server, to [agents.house](https://agents.house). It runs
4
4
  your Agents' conversations through the agent CLIs you chose and gives each Agent the `house` command.
5
5
 
6
6
  ## Install
7
7
 
8
- Run `sh -c 'kit=$(curl -fsSL "$0") || { echo "House Kit could not be downloaded; run this command again." >&2; exit 1; }; eval "$kit"' agents.house/kit`,
9
- or `& { try { $kit = irm agents.house/kit.ps1 } catch { throw 'House Kit could not be downloaded; run this command again.' }; & ([scriptblock]::Create($kit)) @args }` on Windows, which run nothing of a failed download, and again to update; options follow `agents.house/kit`.
10
- On macOS and Linux it installs House Kit natively under your own account, without an admin password, as a service that runs
11
- while you are logged in. `kit` and `house` are then on your login shell's `PATH`, and your workspace is `~/AgentsHouse` unless you
12
- pass `--workspace <path>`.
13
-
14
- Add `--container` to run House Kit in one Docker container instead, with your
15
- workspace mounted at `/agents/house`; your Agents then reach only that
16
- workspace. On Windows 11 the container is the one choice. Append a `kit` or `house` command to the container's options to run it in that container.
17
- Running the command for the other choice on a connected computer asks you to
18
- confirm, then replaces its Environment, whose Agents end, with a new one. Running it with another `HOUSE_KIT_HOME`
19
- than the installed Kit's asks you to confirm before it replaces that Kit, and leaves that Kit home as it was.
20
-
21
- On your own Linux server, run the Linux command with `--linux` to
22
- install House Kit natively, with its workspace at `/agents/house`; `kit` and
23
- `house` are then on the server's `PATH`.
24
-
25
- House Kit runs the agent CLIs your login shell finds and installs a missing one
26
- through that CLI's own installer. Running the command again offers to update
27
- each CLI older than House Kit needs; add `--update-clis` to update every one to
28
- its latest release without asking. House Kit also gives every Agent on the
29
- Environment a set of agent skills. Add `--no-skills` to the command to leave
30
- them out; running it again without the flag brings them back.
8
+ Run `sh -c 'kit=$(curl -fsSL "$0") || { echo "Kit could not be downloaded; run this command again." >&2; exit 1; }; eval "$kit"' agents.house/kit`,
9
+ or `& { try { $kit = irm agents.house/kit.ps1 } catch { throw 'Kit could not be downloaded; run this command again.' }; & ([scriptblock]::Create($kit)) @args }` on Windows, which run nothing of a failed download, and again to update; `--code <code>` follows `agents.house/kit` to connect with a login code.
10
+ On macOS and Linux, a server included, it installs Kit natively under your own account, without an admin password, in one folder, `~/.agents/house`: Kit's own files at its top, its releases and their Node.js in `kit`, `kit` and `house` in `bin`, which it adds to your login shell's `PATH`, and its records of the Rooms' copies. Your workspace is `~/house`: each Room's copy in `rooms/<handle>`, so `cd ~/house/rooms/<handle>` and starting your agent CLI there starts it in that Room, and the Agents' folders in `agents`. It stops, changing nothing, where `~/.agents/house` holds something that is not Kit's. On Linux it adds a missing `ca-certificates`, `curl` or `git` through apt. Then `kit connect`, which stops in one line before it connects anything where `~/house` holds something and is not Kit's workspace, writing nothing there, keeps the Environment you connected, redeems the login code or prints a link you confirm, writes Kit's settings where `kit.json` has none, places House's Skills and starts Kit: as a systemd user unit that starts at boot through lingering on Linux, and as a LaunchAgent on macOS. On a Linux without systemd it starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. One account runs one Kit for one Building; to move it to another, run `kit logout` and then the other Building's command.
11
+
12
+ Every run places the Kit release your Building serves, with the Node.js and agent adapters it runs on, in a directory of its own beside the one that runs, then starts it; the earlier one stays until the next release. Kit also updates itself: when your Building takes another release, Kit places it the same way and, once no turn is open, ends so its service starts it. When House no longer serves the wire of the Kit that runs, Kit places your Building's release at once, ending any running turn, and ends the same way; while it cannot, it stays offline, prints why with the command that installs it again, and tries again regularly.
13
+
14
+ A Kit installed before moves itself into `~/.agents/house` on its next update, a Mac's or a Linux desktop's and one running as root; one in a container or under a system unit of another account asks you, on its Environment's page, to run the install command again on that computer, which moves it and removes the container or the unit, keeping its Environment.
15
+
16
+ On Windows the command, run in PowerShell, installs WSL where it is absent, asking you to restart only where Windows needs that and to run the command again after, and Ubuntu where WSL has none, with a default user named after yours; it turns on WSL's Keep WSL running, starts Ubuntu, with no window, when you sign in, and installs Kit inside Ubuntu as on Linux. The Linux command run in a WSL terminal recommends the Windows command instead and installs and starts Kit there only once you agree that it then runs only while a WSL terminal is open, and not after a restart; with no terminal to ask in, it installs nothing and names the Windows command. A Kit that ran in Docker Desktop's `house-kit` container moves into Ubuntu as the same Environment, its workspace kept where it was, and the command removes the container, keeping its volume.
17
+
18
+ Kit is built for macOS 27 on Apple silicon, Ubuntu 26.04 LTS on amd64 and Windows 11 on amd64. On another release, distribution or architecture the command prints one warning line, such as `Warning: macOS 26.7.1 is outdated; update to macOS 27.`, and installs anyway. It refuses only an architecture other than amd64 and arm64, a macOS older than 13.5 and a Linux without glibc 2.28 or newer.
19
+
20
+ Kit runs each agent CLI through the link your login shell finds and installs a missing one through that CLI's own
21
+ installer. When it starts and regularly after, Kit runs each CLI's own update command, such as `claude update`, beside
22
+ your conversations: a running conversation keeps its version and the next one runs the new release. A CLI older than
23
+ the oldest release Kit is built for still runs, though its conversations may fail: Kit tells House its version, that
24
+ oldest release and its update command. Kit also gives every Agent on the Environment the agent skills of
25
+ `@agentshouse/skills`, at the version each Kit release installs, unless its `skills` setting is off.
26
+ An API key you give a CLI on House's page, with an endpoint for another provider, goes into that CLI's own settings on
27
+ this computer, where you use the CLI too: Claude Code's `settings.json`, or Codex's login and `config.toml`. Grok Build
28
+ has no setting for a key that serves all its models, so Kit keeps its key in `~/.agents/house/grok-key.json` and sets
29
+ it, with the endpoint, as `XAI_API_KEY` and `GROK_MODELS_BASE_URL` on the Grok Build it runs, never on yours.
31
30
 
32
31
  ## Commands
33
32
 
34
- `kit login` opens or prints a link you confirm in any browser, on this computer
35
- or another, continues on its own and keeps the Environment's credential in
36
- `$HOUSE_KIT_HOME` when it is set, else in `~/.house-kit`, or in `house-kit-<uid>` under the temporary directory when your home is read-only. `--environment <id>`
37
- reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
38
- only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
33
+ `kit login` opens or prints a link you confirm in any browser, on this computer or another, continues on its own and keeps the Environment's credential in `~/.agents/house`. `--environment <id>` reconnects an Environment you already have, which keeps its Rooms: its page in House changes them. A new Environment takes `--rooms <ref>[,<ref>...]` for only those Rooms and `--no-private` for every Room but your Private Room; `--code <code>` connects immediately without a link.
39
34
  A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
40
35
  House as you and `git` clones and pushes your Apps at `<house>/app/` as you, each through the Kit
41
- home `$HOUSE_KIT_HOME` names where it runs, until you revoke that connection on Connections. `house help` lists the Tools. Codex sessions started after a
36
+ home of the account it runs as, until you revoke that connection on Connections. `house help` lists the Tools and `house help <tool>` one Tool's arguments. Codex sessions started after a
42
37
  login run a lone `house` command outside their sandbox. `kit logout` disconnects this
43
- computer, stops House Kit and ends your own agent's connection, so `house` and `git` no
38
+ computer, stops the Kit process and ends your own agent's connection, so `house` and `git` no
44
39
  longer act as you here; a later `kit login` reconnects the same Environment, or connects
45
40
  this computer as a new one when House no longer holds it.
46
- In a container you do not control, such as ChatGPT's, `npm i -g @agentshouse/kit` and `kit chatgpt --key <key>` with a key made on Connections let `house <tool>` act as you, starting and configuring nothing else.
47
41
 
48
- `kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it as a
49
- Git repository in the workspace's `local-copies`, and erases a Room's copy, unpushed commits included, once the Room
50
- may no longer be copied here. `house fetch` does the same and records House's changes on each copy's
51
- `refs/house/received`; rebase onto it, commit and run `house push --owner` in the copy, through the install command in
52
- the container. An Agent runs both, without `--owner`. `house upload` and `house download` move a Room's other files.
42
+ `kit settings` prints Kit's two settings, which every update and every rerun of the install keep: `skills`, whether Kit places House's Skills, and `workspace`, the folder that holds `rooms` and `agents`, `~/house` unless you set another. `kit settings skills on|off` and `kit settings workspace <absolute path>` change one, as the Environment's page in House does.
43
+ A new workspace must hold no `rooms` or `agents` folder, and none is taken while an Agent works; Kit then ends its conversations' processes, moves both folders there, across filesystems copying and checking them before it deletes the old ones, and ends so its service starts it there.
44
+
45
+ `kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it into a plain folder named by its handle in the workspace's `rooms`, beside a hidden `.house` file recording each file's revision and SHA-256, renames the folder with everything in it when the Room's handle changes, and keeps a Room's copy as it is, no longer refreshing it, once the Room may no longer be copied here; where another Room's folder is to take its name, it first renames that copy's folder to the name with ` (kept)`, adding ` 2` and on where that is taken. `house download` brings House's changes into each copy, overwriting only files unchanged here, and with `--with-attachments` the attachments it lacks up to `--max-size` megabytes, 10 by default. `house upload --owner`, run in a copy, sends every file changed, added or deleted there; House merges a change made on an older revision, and a clash leaves conflict markers in the file to resolve before the next upload; an `AGENTS.md` or `CLAUDE.md` at a copy's top, whatever its case, is Kit's and never sent. An Agent runs both, without `--owner`. With a JSON argument, `house upload` and `house download` move one file between disk and a Room, and a broken upload resumes on its own. A copy made by an earlier Kit keeps its files and its `.git`, which Kit no longer reads. A Kit that kept its workspace in `~/.agents/house` moves it to `~/house` at its first start on this release, each copy with every file to `rooms/<handle>`, a copy it no longer follows to `rooms/<reference> (kept)`, and ends so its service starts it there; a workspace you set elsewhere, or one whose `~/house` holds something else, stays where it is and takes the same layout.
46
+
47
+ Kit turns each audio file your message to an Agent links into text on this computer before the Agent reads it, and keeps a message whose audio it cannot turn into text from starting. While transcription is on, the speech engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
53
48
 
54
- House Kit turns each audio file of your message to an Agent into text on this
55
- computer before the Agent reads it. While transcription is on, the speech
56
- engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
49
+ When you press Run on a Web Wizard's page, Kit runs its script with `bash` in a terminal on this computer, as you, in the home and directory it runs agent CLIs from, with your login shell's `PATH`; the page shows that terminal and takes your typing, and closing the page, or Kit losing its connection to House, ends the script and its child processes. Kit keeps nothing the script prints or you type. A script you keep as a function from a Web Wizard runs as you, from the same home, directory and `PATH`, when a Trigger of your Private Room or your agent runs it, with no terminal and nothing on its standard input, and when you press Run now on its page, in a terminal you can type into. Kit writes the run's input as JSON to a file only you can read, whose path is in `HOUSE_INPUT`, and deletes it when the run ends; it ends the script and its child processes at the run's time limit or when it loses its connection to House, and sends House the end of what the script printed, up to the run's output limit, without any line that holds a line you typed.
57
50
 
58
51
  ## License
59
52
 
60
- MIT. The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
53
+ MIT.
package/dist/acp.js CHANGED
@@ -1,42 +1,90 @@
1
- import { ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
1
+ import { ndJsonStream, PROTOCOL_VERSION, RequestError, } from '@agentclientprotocol/sdk';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { Readable, Writable } from 'node:stream';
4
- import { CLIS, KIT_VERSION, adapterCommand, withoutProxy } from './clis.js';
4
+ import { CLIS, KIT_RELEASE, adapterCommand, cliEnvironment } from './clis.js';
5
5
  import { killTree } from './scope.js';
6
+ import { Silence } from './silence.js';
6
7
  const RETIRED = 'the CLI was retired';
7
- export async function startAdapter(kind, cli, cwd, app, events = () => undefined, added = {}, signal, scope = null) {
8
+ const SIGNED_OUT = RequestError.authRequired().code;
9
+ export function signedOut(error) {
10
+ return typeof error === 'object' && error !== null && error.code === SIGNED_OUT;
11
+ }
12
+ // Claude Code ends a shell command or a model request after ten minutes, so a CLI that owes the Kit an answer and sends nothing for half an hour has hung.
13
+ export const CLI_SILENCE_MS = 30 * 60_000;
14
+ const SILENT = `the CLI sent nothing for ${CLI_SILENCE_MS / 60_000} minutes`;
15
+ export async function startAdapter(kind, cli, cwd, app, events = () => null, added = {}, signal, scope = null) {
8
16
  const adapter = CLIS[kind].adapter;
9
17
  const started = [adapter === null ? cli : adapterCommand(kind), CLIS[kind].args];
10
18
  const [command, args] = scope?.command(...started) ?? started;
11
19
  const child = spawn(command, args, {
12
20
  cwd,
13
- env: { ...withoutProxy(), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
21
+ env: { ...(await cliEnvironment(kind)), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
14
22
  stdio: ['pipe', 'pipe', 'pipe'],
15
23
  detached: true,
16
24
  });
17
25
  let owned = true;
18
26
  let retired = false;
27
+ let silent = false;
28
+ let over = false;
29
+ let open = false;
19
30
  let stderr = '';
31
+ const owed = new Set();
32
+ const asked = new Set();
33
+ const silence = new Silence(CLI_SILENCE_MS, () => {
34
+ silent = true;
35
+ connection.close(new Error(SILENT));
36
+ if (child.pid !== undefined)
37
+ killTree(child);
38
+ });
39
+ const watch = () => (!over && (owed.size > 0 || open) && asked.size === 0 ? silence.heard() : silence.stop());
20
40
  child.stderr.on('data', (chunk) => {
21
41
  stderr = (stderr + chunk.toString('utf8')).slice(-4000);
22
42
  });
23
43
  const stream = ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
44
+ const output = stream.writable.getWriter();
24
45
  const connection = app.connect({
25
- writable: stream.writable,
46
+ writable: new WritableStream({
47
+ write(message) {
48
+ const sent = message;
49
+ if (sent.id !== undefined) {
50
+ if (sent.method === undefined)
51
+ asked.delete(sent.id);
52
+ else
53
+ owed.add(sent.id);
54
+ watch();
55
+ }
56
+ return output.write(message);
57
+ },
58
+ close: () => output.close(),
59
+ abort: (reason) => output.abort(reason),
60
+ }),
26
61
  readable: stream.readable.pipeThrough(new TransformStream({
27
62
  transform(message, controller) {
28
63
  const read = message;
29
- if (owned)
30
- events(read);
31
- if (read.id !== undefined || (read.method !== 'session/update' && !read.method.startsWith('_'))) {
32
- controller.enqueue(message);
64
+ if (read.id !== undefined) {
65
+ if (read.method === undefined)
66
+ owed.delete(read.id);
67
+ else
68
+ asked.add(read.id);
33
69
  }
70
+ watch();
71
+ const held = owned ? events(read) : null;
72
+ const pass = () => {
73
+ if (read.id !== undefined || (read.method !== 'session/update' && !read.method.startsWith('_'))) {
74
+ controller.enqueue(message);
75
+ }
76
+ };
77
+ if (held === null)
78
+ return pass();
79
+ return held.then(pass);
34
80
  },
35
81
  })),
36
82
  });
37
83
  const { promise: lost, resolve: lose } = Promise.withResolvers();
38
84
  const exited = new Promise((resolve) => {
39
85
  const end = (cause) => {
86
+ over = true;
87
+ silence.stop();
40
88
  if (owned)
41
89
  lose(cause);
42
90
  owned = false;
@@ -46,11 +94,13 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
46
94
  child.on('error', (error) => end(`the CLI did not start: ${error.message}`));
47
95
  child.on('exit', (code, signal) => {
48
96
  const last = stderr.trim().split('\n').at(-1);
49
- end(`the CLI exited with ${code ?? signal}${last ? `: ${last}` : ''}`);
97
+ end(silent ? SILENT : `the CLI exited with ${code ?? signal}${last ? `: ${last}` : ''}`);
50
98
  });
51
99
  });
52
100
  const retire = () => {
53
101
  owned = false;
102
+ over = true;
103
+ silence.stop();
54
104
  if (retired)
55
105
  return;
56
106
  retired = true;
@@ -71,10 +121,14 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
71
121
  session: { compaction: {}, notices: {} },
72
122
  _meta: { jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
73
123
  },
74
- clientInfo: { name: '@agentshouse/kit', version: KIT_VERSION },
124
+ clientInfo: { name: '@agentshouse/kit', version: KIT_RELEASE },
75
125
  });
76
126
  scope?.entered(child.pid);
77
- return { connection, initialized, exited, lost, retire };
127
+ const turn = (opened) => {
128
+ open = opened;
129
+ watch();
130
+ };
131
+ return { connection, initialized, exited, lost, silent: () => silent, turn, retire };
78
132
  }
79
133
  catch (error) {
80
134
  retire();
package/dist/afk.js ADDED
@@ -0,0 +1,17 @@
1
+ import { CLIS } from './clis.js';
2
+ const NOBODY_THERE = 'Nobody is there to answer. Decide for yourself and go on.';
3
+ export const PLAN_APPROVED = { outcome: 'approved' };
4
+ function told(fields) {
5
+ return Object.fromEntries(fields.map((field) => [field, NOBODY_THERE]));
6
+ }
7
+ export function permissionAllowed({ options }) {
8
+ const option = options.find(({ kind }) => kind === 'allow_once') ?? options.find(({ kind }) => kind === 'allow_always');
9
+ return { outcome: { outcome: 'selected', optionId: option.optionId } };
10
+ }
11
+ export function formAnswered(kind, request) {
12
+ const fields = CLIS[kind].questionFields(request);
13
+ return fields.length === 0 ? { action: 'decline' } : { action: 'accept', content: told(fields) };
14
+ }
15
+ export function grokQuestionAnswered({ questions }) {
16
+ return { outcome: 'accepted', answers: told(questions.map(({ question }) => question)) };
17
+ }
package/dist/agents.js CHANGED
@@ -1,15 +1,20 @@
1
1
  import { client } from '@agentclientprotocol/sdk';
2
- import { readFile, realpath } from 'node:fs/promises';
2
+ import { KIT_WIRE } from '@agentshouse/kit-wire';
3
+ import { readFile } from 'node:fs/promises';
3
4
  import { setTimeout as delay } from 'node:timers/promises';
4
- import { startAdapter } from './acp.js';
5
- import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
6
- import { agentBase, kitHome } from './home.js';
7
- import { updatesItself } from './placement.js';
5
+ import { signedOut, startAdapter } from './acp.js';
6
+ import { CLIS, KIT_RELEASE, below, cliEnvironment, installCli, locate, run, updateCli, versionOf } from './clis.js';
7
+ import { agentBase, kitHome, reinstall } from './home.js';
8
+ import { heldSettings } from './settings.js';
8
9
  import { holdTranscription, transcriptionReport } from './transcription.js';
9
- import { KIT_WIRE } from './wire.js';
10
10
  // Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
11
11
  const MODEL_PROBE_QUIET_MS = 2_000;
12
- const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
12
+ // A CLI's maker can publish several releases a day, so running each chosen CLI's update command hourly brings a new one to the next conversation within the hour for one small check.
13
+ export const CLI_UPDATE_MS = 60 * 60_000;
14
+ // A sign-in's model read that has not answered in ten seconds leaves its sign-in to the status check, so a hung CLI never holds the sign-in's result.
15
+ const SIGNED_IN_READ_MS = 10_000;
16
+ const UNNAMED = { default_model: null, default_effort: null };
17
+ const SIGNED_OUT = { signed_in: false, models: [], ...UNNAMED, modes: [] };
13
18
  const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
14
19
  function select(options, category) {
15
20
  const option = options.find((candidate) => candidate.category === category);
@@ -21,6 +26,22 @@ function choices(options) {
21
26
  function values(options) {
22
27
  return choices(options).map((entry) => entry.value);
23
28
  }
29
+ const CLI_DEFAULT = 'default';
30
+ function effortsOf(option) {
31
+ return option === undefined ? [] : values(option.options).filter((value) => value !== CLI_DEFAULT);
32
+ }
33
+ function named(options) {
34
+ const listed = choices(options).filter((entry) => entry.value !== CLI_DEFAULT);
35
+ return listed.filter((entry, at) => listed.findIndex((first) => first.name === entry.name) === at);
36
+ }
37
+ function starting(model, effort) {
38
+ const current = choices(model.options).find((entry) => entry.value === model.currentValue);
39
+ const name = current?.value === CLI_DEFAULT ? current.description : current?.name;
40
+ return {
41
+ default_model: named(model.options).find((entry) => entry.name === name)?.value ?? null,
42
+ default_effort: effort === undefined || effort.currentValue === CLI_DEFAULT ? null : effort.currentValue,
43
+ };
44
+ }
24
45
  function causeOf(error) {
25
46
  return error instanceof Error ? error.message : String(error);
26
47
  }
@@ -51,30 +72,23 @@ async function models(kind, adapter, known) {
51
72
  const modes = mode === undefined ? [] : choices(mode.options).map(({ value, name }) => ({ mode: value, name }));
52
73
  const model = select(options, 'model');
53
74
  if (model === undefined)
54
- return { models: [], modes };
75
+ return { models: [], ...UNNAMED, modes };
76
+ const started = starting(model, select(options, 'thought_level'));
55
77
  const offered = [];
56
- for (const value of values(model.options)) {
78
+ for (const { value, name } of named(model.options)) {
57
79
  if (select(options, 'model')?.currentValue !== value) {
58
80
  try {
59
81
  options = (await agent.request('session/set_config_option', { sessionId: opened.sessionId, configId: model.id, value })).configOptions;
60
82
  }
61
83
  catch (error) {
62
84
  process.stderr.write(`kit: ${kind} refused its model ${value}: ${causeOf(error)}\n`);
63
- offered.push({ model: value, efforts: known.find((entry) => entry.model === value)?.efforts ?? [] });
85
+ offered.push({ model: value, name, efforts: known.find((entry) => entry.model === value)?.efforts ?? [] });
64
86
  continue;
65
87
  }
66
88
  }
67
- const effort = select(options, 'thought_level');
68
- offered.push({ model: value, efforts: effort === undefined ? [] : values(effort.options) });
89
+ offered.push({ model: value, name, efforts: effortsOf(select(options, 'thought_level')) });
69
90
  }
70
- return { models: offered, modes };
71
- }
72
- async function signedIn(kind, cli, known, signal) {
73
- const probe = CLIS[kind].signedIn;
74
- // A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
75
- if ('command' in probe)
76
- return (await run(cli, probe.command, 30_000, false, signal)).status === 0;
77
- return (await offer(kind, cli, known, signal)).signed_in;
91
+ return { models: offered, ...started, modes };
78
92
  }
79
93
  function ended(signal) {
80
94
  return new Promise((_, reject) => {
@@ -83,28 +97,41 @@ function ended(signal) {
83
97
  signal.addEventListener('abort', () => reject(signal.reason), { once: true });
84
98
  });
85
99
  }
100
+ function keyedOf({ api_key, provider }) {
101
+ return { ...(api_key === undefined ? {} : { api_key }), ...(provider === undefined ? {} : { provider }) };
102
+ }
86
103
  async function offer(kind, cli, known, signal) {
87
- const probe = CLIS[kind].signedIn;
104
+ const { signedIn: probe, key } = CLIS[kind];
105
+ const keyed = await key.read();
88
106
  // A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
89
- if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
90
- return SIGNED_OUT;
107
+ if ('command' in probe && !keyed.api_key && (await run(cli, probe.command, 30_000, false, signal, await cliEnvironment(kind))).status !== 0) {
108
+ return { ...SIGNED_OUT, ...keyed };
109
+ }
91
110
  let adapter;
92
111
  try {
93
- adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
112
+ adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => null, {}, signal);
94
113
  signal?.throwIfAborted();
95
114
  if ('initializeMeta' in probe) {
96
115
  const method = adapter.initialized._meta?.[probe.initializeMeta];
97
116
  if (typeof method !== 'string' || method.length === 0)
98
- return SIGNED_OUT;
117
+ return { ...SIGNED_OUT, ...keyed };
118
+ if (method === probe.apiKey)
119
+ keyed.api_key = true;
99
120
  }
100
- return { signed_in: true, ...(await models(kind, adapter, known.models)) };
121
+ return { signed_in: true, ...keyed, ...(await models(kind, adapter, known.models)) };
101
122
  }
102
123
  catch (error) {
103
124
  if (!signal?.aborted)
104
125
  process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
126
+ if (signedOut(error))
127
+ return { ...SIGNED_OUT, ...keyed };
128
+ const unread = adapter === undefined && 'initializeMeta' in probe;
105
129
  return {
106
- signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
130
+ signed_in: unread ? known.signed_in : true,
131
+ ...keyedOf({ api_key: unread ? known.api_key : keyed.api_key, provider: keyed.provider }),
107
132
  models: known.models,
133
+ default_model: known.default_model,
134
+ default_effort: known.default_effort,
108
135
  modes: known.modes,
109
136
  };
110
137
  }
@@ -113,23 +140,23 @@ async function offer(kind, cli, known, signal) {
113
140
  }
114
141
  }
115
142
  function reported(kind, reading) {
143
+ const { minimum, update } = CLIS[kind];
116
144
  return {
117
145
  kind,
118
146
  release: reading.release,
119
- ...(reading.minimum === undefined ? {} : { minimum: reading.minimum }),
147
+ ...(reading.release !== null && below(reading.release, minimum) ? { minimum, update } : {}),
120
148
  failure: reading.failure,
121
149
  ...(reading.installing === undefined ? {} : { installing: reading.installing }),
122
150
  signed_in: reading.signed_in,
151
+ ...keyedOf(reading),
123
152
  models: reading.models,
124
153
  modes: reading.modes,
125
154
  full_access: CLIS[kind].fullAccess,
155
+ ...(reading.default_model === null ? {} : { default_model: reading.default_model }),
156
+ ...(reading.default_effort === null ? {} : { default_effort: reading.default_effort }),
126
157
  };
127
158
  }
128
159
  const NOT_READY = "the Agent's CLI is not ready on this computer";
129
- function tooOld(kind, release) {
130
- const cli = CLIS[kind];
131
- return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
132
- }
133
160
  async function sshHostKey() {
134
161
  // Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
135
162
  const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
@@ -171,13 +198,15 @@ export class Agents {
171
198
  sending = Promise.resolve();
172
199
  sent = null;
173
200
  refreshing = 0;
201
+ loaded = Promise.resolve();
202
+ updating = null;
174
203
  changed;
175
204
  constructor(house, changed = () => undefined) {
176
205
  this.house = house;
177
206
  this.changed = changed;
178
207
  }
179
208
  idle() {
180
- return this.refreshing === 0;
209
+ return this.refreshing === 0 && this.updating === null;
181
210
  }
182
211
  read() {
183
212
  return this.reading.then(() => undefined, () => undefined);
@@ -189,11 +218,11 @@ export class Agents {
189
218
  this.refreshing++;
190
219
  this.changed();
191
220
  const reading = this.read().then(async () => {
192
- this.desired = await this.house.deliver('/kit/agents/desired', {});
221
+ this.desired = await this.house.deliver('agents/desired/list', {});
193
222
  return this.desired;
194
223
  });
195
224
  this.reading = reading;
196
- reading
225
+ this.loaded = reading
197
226
  .then(({ agents, transcribe }) => Promise.all([
198
227
  holdTranscription(transcribe)
199
228
  .then((changed) => (changed ? this.report() : undefined))
@@ -209,26 +238,42 @@ export class Agents {
209
238
  });
210
239
  return reading.then(() => undefined);
211
240
  }
241
+ keepCurrent(stopping) {
242
+ this.updateAll(this.loaded);
243
+ setInterval(() => {
244
+ if (!stopping())
245
+ this.updateAll(Promise.resolve());
246
+ }, CLI_UPDATE_MS);
247
+ }
212
248
  cli(kind) {
213
249
  this.starts += 1;
214
250
  return this.queue(kind, async () => {
215
251
  const resolved = await this.resolve(kind);
216
252
  if (!('cli' in resolved)) {
217
253
  this.update(kind, resolved);
218
- throw new Error(resolved.failure === null ? tooOld(kind, resolved.release) : NOT_READY);
254
+ throw new Error(NOT_READY);
219
255
  }
220
256
  const { cli, release } = resolved;
221
257
  const known = this.readings.get(kind);
222
- const kept = known?.release === null || known?.minimum !== undefined ? SIGNED_OUT : (known ?? SIGNED_OUT);
223
- if (known?.release !== release || known.minimum !== undefined || this.installs.has(kind)) {
224
- this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
258
+ const kept = known?.release === null ? SIGNED_OUT : (known ?? SIGNED_OUT);
259
+ if (known?.release !== release || this.installs.has(kind)) {
260
+ this.update(kind, {
261
+ release,
262
+ failure: null,
263
+ signed_in: kept.signed_in,
264
+ ...keyedOf(kept),
265
+ models: kept.models,
266
+ default_model: kept.default_model,
267
+ default_effort: kept.default_effort,
268
+ modes: kept.modes,
269
+ });
225
270
  }
226
271
  const read = this.nextRead(kind);
227
272
  this.quietOffer(kind, cli, kept)
228
273
  .then((offered) => {
229
274
  const current = this.readings.get(kind);
230
275
  if (this.reads.get(kind) === read && current?.release === release)
231
- this.update(kind, { ...current, ...offered });
276
+ this.update(kind, { release, failure: current.failure, ...offered });
232
277
  })
233
278
  .catch(logged);
234
279
  return cli;
@@ -246,7 +291,7 @@ export class Agents {
246
291
  const known = this.readings.get(kind) ?? SIGNED_OUT;
247
292
  const owner = {};
248
293
  try {
249
- await this.examine(kind, known, async (kind, cli) => ((await signedIn(kind, cli, known, signal)) ? { ...known, signed_in: true } : SIGNED_OUT), signal, owner);
294
+ await this.examine(kind, known, (kind, cli) => offer(kind, cli, known, AbortSignal.any([signal, AbortSignal.timeout(SIGNED_IN_READ_MS)])), signal, owner);
250
295
  }
251
296
  finally {
252
297
  this.settle(kind, owner);
@@ -287,9 +332,6 @@ export class Agents {
287
332
  return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
288
333
  }
289
334
  async ensure(kind, signal, owner = {}) {
290
- const failed = await installAdapter(kind, signal);
291
- if (failed !== null)
292
- throw new Error(failed);
293
335
  const found = await locate(kind, signal);
294
336
  if (found !== null)
295
337
  return found;
@@ -308,19 +350,16 @@ export class Agents {
308
350
  async resolve(kind, signal, owner) {
309
351
  let cli;
310
352
  try {
311
- cli = await realpath(await this.ensure(kind, signal, owner));
353
+ cli = await this.ensure(kind, signal, owner);
312
354
  }
313
355
  catch (error) {
314
356
  const failure = causeOf(error);
315
357
  process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
316
358
  return { release: null, failure, ...SIGNED_OUT };
317
359
  }
318
- const release = await versionOf(cli, signal);
360
+ const release = await versionOf(kind, cli, signal);
319
361
  if (release === null)
320
362
  return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
321
- const minimum = CLIS[kind].minimum;
322
- if (below(release, minimum))
323
- return { release, minimum, failure: null, ...SIGNED_OUT };
324
363
  return { cli, release };
325
364
  }
326
365
  async examine(kind, known, read, signal, owner) {
@@ -330,6 +369,35 @@ export class Agents {
330
369
  if (this.reads.get(kind) === current && !signal?.aborted)
331
370
  this.hold(kind, reading);
332
371
  }
372
+ updateAll(after) {
373
+ if (this.updating !== null)
374
+ return;
375
+ this.updating = after
376
+ .then(async () => {
377
+ for (const kind of this.desired.agents) {
378
+ if (this.installs.has(kind) || !this.readings.get(kind)?.release)
379
+ continue;
380
+ const failure = await updateCli(kind);
381
+ if (failure !== null)
382
+ process.stderr.write(`kit: ${kind} did not update: ${failure}\n`);
383
+ await this.readVersion(kind);
384
+ }
385
+ })
386
+ .catch(logged)
387
+ .finally(() => {
388
+ this.updating = null;
389
+ this.changed();
390
+ });
391
+ this.changed();
392
+ }
393
+ async readVersion(kind) {
394
+ const cli = await locate(kind);
395
+ const release = cli === null ? null : await versionOf(kind, cli);
396
+ const current = this.readings.get(kind);
397
+ if (release === null || !current?.release || current.release === release)
398
+ return;
399
+ this.update(kind, { ...current, release });
400
+ }
333
401
  async quietOffer(kind, cli, known) {
334
402
  for (let seen = -1; seen !== this.starts;) {
335
403
  seen = this.starts;
@@ -339,7 +407,7 @@ export class Agents {
339
407
  }
340
408
  async load(kind) {
341
409
  const known = this.readings.get(kind);
342
- if (known !== undefined && known.failure === null && known.minimum === undefined)
410
+ if (known !== undefined && known.failure === null)
343
411
  return;
344
412
  await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
345
413
  await this.report();
@@ -354,10 +422,11 @@ export class Agents {
354
422
  const body = {
355
423
  os: await operatingSystem(),
356
424
  ...(form === undefined ? {} : { form }),
357
- kit_version: KIT_VERSION,
425
+ kit_release: KIT_RELEASE,
358
426
  wire: KIT_WIRE,
359
- updates_itself: await updatesItself(),
360
427
  agent_base: agentBase(),
428
+ ...(reinstall() === undefined ? {} : { reinstall: reinstall() }),
429
+ settings: await heldSettings(),
361
430
  agents,
362
431
  transcription: transcriptionReport(),
363
432
  ...(hostKey === null ? {} : { ssh_host_key: hostKey }),
@@ -365,7 +434,7 @@ export class Agents {
365
434
  const state = JSON.stringify(body);
366
435
  if (state === this.sent)
367
436
  return;
368
- await this.house.deliver('/kit/agents/report', body);
437
+ await this.house.deliver('agents/report', body);
369
438
  this.sent = state;
370
439
  }
371
440
  }