@agentshouse/kit 0.2.1-cf110d15f69c8 → 0.2.1-cf2c570b41f24

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 (147) hide show
  1. package/README.md +38 -44
  2. package/dist/acp.js +96 -22
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +221 -65
  5. package/dist/api.js +21 -3
  6. package/dist/app-git.js +10 -26
  7. package/dist/binaries.js +60 -0
  8. package/dist/bridge.js +101 -49
  9. package/dist/building.js +50 -0
  10. package/dist/calls.js +88 -0
  11. package/dist/chunks.js +54 -0
  12. package/dist/clis.js +80 -52
  13. package/dist/connect.js +121 -0
  14. package/dist/connection.js +120 -0
  15. package/dist/content.js +106 -0
  16. package/dist/conversations.js +711 -267
  17. package/dist/copies.js +1293 -595
  18. package/dist/earlier.js +273 -0
  19. package/dist/end.js +15 -3
  20. package/dist/events.js +553 -281
  21. package/dist/files.js +206 -32
  22. package/dist/git.js +2 -70
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +123 -15
  25. package/dist/house-cli.js +282 -0
  26. package/dist/house-main.js +7 -206
  27. package/dist/instructions.js +7 -13
  28. package/dist/keys.js +238 -0
  29. package/dist/kit-cli.js +78 -0
  30. package/dist/kit-main.js +8 -22
  31. package/dist/login.js +71 -39
  32. package/dist/logout.js +2 -4
  33. package/dist/manifest.js +75 -0
  34. package/dist/mcp.js +47 -7
  35. package/dist/owner.js +46 -0
  36. package/dist/placement.js +25 -0
  37. package/dist/refusals.js +50 -23
  38. package/dist/relay.js +22 -1
  39. package/dist/resident.js +153 -53
  40. package/dist/scope.js +15 -4
  41. package/dist/scripts.js +319 -0
  42. package/dist/secret-input.js +1 -1
  43. package/dist/settings.js +247 -0
  44. package/dist/sign-in.js +66 -38
  45. package/dist/silence.js +28 -0
  46. package/dist/skills.js +49 -35
  47. package/dist/supervisor.js +163 -0
  48. package/dist/transcription.js +90 -47
  49. package/dist/update.js +119 -102
  50. package/dist/wire.js +32 -0
  51. package/dist/work.js +30 -7
  52. package/dist/workspace.js +113 -0
  53. package/package.json +25 -21
  54. package/dist/authority-main.js +0 -22
  55. package/dist/bootstrap.json +0 -24
  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/parts.js +0 -82
  61. package/dist/service-main.js +0 -9
  62. package/dist/service.js +0 -33
  63. package/dist/stream.js +0 -74
  64. package/dist/translate.js +0 -51
  65. package/how-we-work.md +0 -23
  66. package/skills/ask-matt/LICENSE +0 -21
  67. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  68. package/skills/ask-matt/SKILL.md +0 -91
  69. package/skills/ask-matt/agents/openai.yaml +0 -4
  70. package/skills/code-review/LICENSE +0 -21
  71. package/skills/code-review/SKILL.md +0 -89
  72. package/skills/code-review/agents/openai.yaml +0 -3
  73. package/skills/codebase-design/DEEPENING.md +0 -37
  74. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  75. package/skills/codebase-design/LICENSE +0 -21
  76. package/skills/codebase-design/SKILL.md +0 -116
  77. package/skills/codebase-design/agents/openai.yaml +0 -3
  78. package/skills/diagnosing-bugs/LICENSE +0 -21
  79. package/skills/diagnosing-bugs/SKILL.md +0 -140
  80. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  81. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  82. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  83. package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
  84. package/skills/domain-modeling/LICENSE +0 -21
  85. package/skills/domain-modeling/SKILL.md +0 -76
  86. package/skills/domain-modeling/agents/openai.yaml +0 -3
  87. package/skills/grill-me/LICENSE +0 -21
  88. package/skills/grill-me/SKILL.md +0 -8
  89. package/skills/grill-me/agents/openai.yaml +0 -4
  90. package/skills/grill-with-docs/LICENSE +0 -21
  91. package/skills/grill-with-docs/SKILL.md +0 -8
  92. package/skills/grill-with-docs/agents/openai.yaml +0 -4
  93. package/skills/grilling/LICENSE +0 -21
  94. package/skills/grilling/SKILL.md +0 -30
  95. package/skills/grilling/agents/openai.yaml +0 -3
  96. package/skills/handoff/LICENSE +0 -21
  97. package/skills/handoff/SKILL.md +0 -17
  98. package/skills/handoff/agents/openai.yaml +0 -4
  99. package/skills/implement/LICENSE +0 -21
  100. package/skills/implement/SKILL.md +0 -16
  101. package/skills/implement/agents/openai.yaml +0 -4
  102. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  103. package/skills/improve-codebase-architecture/LICENSE +0 -21
  104. package/skills/improve-codebase-architecture/SKILL.md +0 -72
  105. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
  106. package/skills/prototype/LICENSE +0 -21
  107. package/skills/prototype/LOGIC.md +0 -67
  108. package/skills/prototype/SKILL.md +0 -28
  109. package/skills/prototype/UI.md +0 -112
  110. package/skills/prototype/agents/openai.yaml +0 -3
  111. package/skills/research/LICENSE +0 -21
  112. package/skills/research/SKILL.md +0 -14
  113. package/skills/research/agents/openai.yaml +0 -3
  114. package/skills/resolving-merge-conflicts/LICENSE +0 -21
  115. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  116. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  117. package/skills/tdd/LICENSE +0 -21
  118. package/skills/tdd/SKILL.md +0 -40
  119. package/skills/tdd/agents/openai.yaml +0 -3
  120. package/skills/tdd/mocking.md +0 -59
  121. package/skills/tdd/tests.md +0 -77
  122. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  123. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  124. package/skills/teach/LICENSE +0 -21
  125. package/skills/teach/MISSION-FORMAT.md +0 -31
  126. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  127. package/skills/teach/SKILL.md +0 -141
  128. package/skills/teach/agents/openai.yaml +0 -4
  129. package/skills/to-questionnaire/LICENSE +0 -21
  130. package/skills/to-questionnaire/SKILL.md +0 -55
  131. package/skills/to-questionnaire/agents/openai.yaml +0 -4
  132. package/skills/to-spec/LICENSE +0 -21
  133. package/skills/to-spec/SKILL.md +0 -76
  134. package/skills/to-spec/agents/openai.yaml +0 -4
  135. package/skills/to-tickets/LICENSE +0 -21
  136. package/skills/to-tickets/SKILL.md +0 -106
  137. package/skills/to-tickets/agents/openai.yaml +0 -4
  138. package/skills/wait-what/LICENSE +0 -21
  139. package/skills/wait-what/SKILL.md +0 -8
  140. package/skills/wait-what/agents/openai.yaml +0 -4
  141. package/skills/wayfinder/LICENSE +0 -21
  142. package/skills/wayfinder/SKILL.md +0 -129
  143. package/skills/wayfinder/agents/openai.yaml +0 -4
  144. package/skills/writing-for-agents/LICENSE +0 -21
  145. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  146. package/skills/writing-for-agents/SKILL.md +0 -83
  147. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/README.md CHANGED
@@ -1,59 +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 `curl -fsSL agents.house/kit | sh`, or `irm agents.house/kit.ps1 | iex` on Windows, and again to update;
9
- options follow `sh -s --`. On macOS and Linux it installs House Kit natively under your own account, without an admin password,
10
- as a service that runs while you are logged in. `kit` and `house` are then on
11
- 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
17
- `house` command to the container's options to run it in that container.
18
- Running the command for the other choice on a connected computer asks you to
19
- confirm, then replaces its Environment, whose Agents end, with a new one.
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`, or in `$HOUSE_KIT_HOME` when it is set. `--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;
39
- `--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.
40
34
  A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
41
- House as you and `git` clones and pushes your Apps at `<house>/app/` as you, until you revoke
42
- that connection on Connections. `house help` lists the Tools. Codex sessions started after a
35
+ House as you and `git` clones and pushes your Apps at `<house>/app/` as you, each through the Kit
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
43
37
  login run a lone `house` command outside their sandbox. `kit logout` disconnects this
44
- computer, stops House Kit and ends your own agent's connection, so `house` and `git` no
45
- longer act as you here; a later `kit login` reconnects the same Environment.
38
+ computer, stops the Kit process and ends your own agent's connection, so `house` and `git` no
39
+ longer act as you here; a later `kit login` reconnects the same Environment, or connects
40
+ this computer as a new one when House no longer holds it.
41
+
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
46
 
47
- `kit resident` keeps the Environment connected and, as it connects, copies each
48
- Room you chose for it as a Git repository in the workspace's `local-copies`.
49
- `house fetch` records House's changes on each copy's `refs/house/received`;
50
- rebase onto it, commit and run `house push --owner` in the copy, through the
51
- install command in the container. An Agent runs both, without `--owner`.
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.
52
48
 
53
- House Kit turns each audio file of your message to an Agent into text on this
54
- computer before the Agent reads it. While transcription is on, the speech
55
- engine and model use about 425 MB in `~/.house-kit`; 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.
56
50
 
57
51
  ## License
58
52
 
59
- MIT. The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
53
+ MIT.
package/dist/acp.js CHANGED
@@ -1,46 +1,116 @@
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
- export async function startAdapter(kind, cli, cwd, app, events = () => undefined, added = {}, signal, scope = null) {
6
+ import { Silence } from './silence.js';
7
+ const RETIRED = 'the CLI was retired';
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) {
7
16
  const adapter = CLIS[kind].adapter;
8
17
  const started = [adapter === null ? cli : adapterCommand(kind), CLIS[kind].args];
9
18
  const [command, args] = scope?.command(...started) ?? started;
10
19
  const child = spawn(command, args, {
11
20
  cwd,
12
- env: { ...withoutProxy(), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
21
+ env: { ...(await cliEnvironment(kind)), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
13
22
  stdio: ['pipe', 'pipe', 'pipe'],
14
23
  detached: true,
15
24
  });
16
- const stop = () => killTree(child);
17
- signal?.addEventListener('abort', stop, { once: true });
18
- child.on('exit', () => signal?.removeEventListener('abort', stop));
25
+ let owned = true;
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
- const exited = new Promise((resolve) => {
24
- child.on('error', (error) => resolve(`the CLI did not start: ${error.message}`));
25
- child.on('exit', (code, signal) => {
26
- const last = stderr.trim().split('\n').at(-1);
27
- resolve(`the CLI exited with ${code ?? signal}${last ? `: ${last}` : ''}`);
28
- });
29
- });
30
43
  const stream = ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
44
+ const output = stream.writable.getWriter();
31
45
  const connection = app.connect({
32
- 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
+ }),
33
61
  readable: stream.readable.pipeThrough(new TransformStream({
34
62
  transform(message, controller) {
35
63
  const read = message;
36
- events(read);
37
- if (read.id !== undefined || (read.method !== 'session/update' && !read.method.startsWith('_'))) {
38
- 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);
39
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);
40
80
  },
41
81
  })),
42
82
  });
43
- void exited.then((cause) => connection.close(new Error(cause)));
83
+ const { promise: lost, resolve: lose } = Promise.withResolvers();
84
+ const exited = new Promise((resolve) => {
85
+ const end = (cause) => {
86
+ over = true;
87
+ silence.stop();
88
+ if (owned)
89
+ lose(cause);
90
+ owned = false;
91
+ connection.close(new Error(cause));
92
+ resolve(cause);
93
+ };
94
+ child.on('error', (error) => end(`the CLI did not start: ${error.message}`));
95
+ child.on('exit', (code, signal) => {
96
+ const last = stderr.trim().split('\n').at(-1);
97
+ end(silent ? SILENT : `the CLI exited with ${code ?? signal}${last ? `: ${last}` : ''}`);
98
+ });
99
+ });
100
+ const retire = () => {
101
+ owned = false;
102
+ over = true;
103
+ silence.stop();
104
+ if (retired)
105
+ return;
106
+ retired = true;
107
+ if (child.pid !== undefined)
108
+ killTree(child);
109
+ scope?.kill();
110
+ connection.close(new Error(RETIRED));
111
+ };
112
+ signal?.addEventListener('abort', retire, { once: true });
113
+ child.on('exit', () => signal?.removeEventListener('abort', retire));
44
114
  try {
45
115
  const initialized = await connection.agent.request('initialize', {
46
116
  protocolVersion: PROTOCOL_VERSION,
@@ -51,13 +121,17 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
51
121
  session: { compaction: {}, notices: {} },
52
122
  _meta: { jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
53
123
  },
54
- clientInfo: { name: '@agentshouse/kit', version: KIT_VERSION },
124
+ clientInfo: { name: '@agentshouse/kit', version: KIT_RELEASE },
55
125
  });
56
126
  scope?.entered(child.pid);
57
- return { child, connection, initialized, exited };
127
+ const turn = (opened) => {
128
+ open = opened;
129
+ watch();
130
+ };
131
+ return { connection, initialized, exited, lost, silent: () => silent, turn, retire };
58
132
  }
59
133
  catch (error) {
60
- child.kill('SIGKILL');
134
+ retire();
61
135
  throw error;
62
136
  }
63
137
  }
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
+ }