@agentshouse/kit 0.2.1-ce3d2bb67177c → 0.2.1-ce46b2b55463f

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 (161) hide show
  1. package/README.md +31 -35
  2. package/dist/acp.js +56 -6
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +120 -51
  5. package/dist/api.js +11 -6
  6. package/dist/binaries.js +79 -0
  7. package/dist/bridge.js +30 -26
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +29 -4
  10. package/dist/chunks.js +49 -0
  11. package/dist/clis.js +61 -49
  12. package/dist/connect.js +108 -0
  13. package/dist/connection.js +33 -38
  14. package/dist/content.js +106 -0
  15. package/dist/conversations.js +325 -141
  16. package/dist/copies.js +720 -247
  17. package/dist/earlier.js +263 -0
  18. package/dist/end.js +4 -5
  19. package/dist/events.js +549 -281
  20. package/dist/files.js +110 -28
  21. package/dist/git-main.js +24 -29
  22. package/dist/git.js +89 -14
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +65 -29
  25. package/dist/house-cli.js +114 -159
  26. package/dist/house-main.js +3 -3
  27. package/dist/instructions.js +29 -11
  28. package/dist/keys.js +238 -0
  29. package/dist/kit-cli.js +16 -6
  30. package/dist/kit-main.js +3 -3
  31. package/dist/login.js +36 -20
  32. package/dist/logout.js +2 -2
  33. package/dist/mcp.js +38 -1
  34. package/dist/owner.js +46 -0
  35. package/dist/placement.js +9 -23
  36. package/dist/refusals.js +37 -21
  37. package/dist/relay.js +21 -0
  38. package/dist/resident.js +109 -65
  39. package/dist/scope.js +12 -4
  40. package/dist/scripts.js +303 -0
  41. package/dist/secret-input.js +1 -1
  42. package/dist/settings.js +188 -0
  43. package/dist/sign-in.js +49 -3
  44. package/dist/silence.js +28 -0
  45. package/dist/skills.js +41 -96
  46. package/dist/supervisor.js +163 -0
  47. package/dist/transcription.js +37 -25
  48. package/dist/translate.js +18 -9
  49. package/dist/update.js +115 -117
  50. package/dist/wire.js +19 -9
  51. package/dist/work.js +9 -2
  52. package/dist/workspace.js +103 -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/chatgpt.js +0 -32
  57. package/dist/clis-main.js +0 -23
  58. package/dist/configure-main.js +0 -6
  59. package/dist/enrol-main.js +0 -10
  60. package/dist/parts.js +0 -82
  61. package/dist/service-main.js +0 -9
  62. package/dist/service.js +0 -55
  63. package/how-we-work.md +0 -33
  64. package/skills/ask-matt/LICENSE +0 -21
  65. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  66. package/skills/ask-matt/SKILL.md +0 -97
  67. package/skills/ask-matt/agents/openai.yaml +0 -5
  68. package/skills/code-review/LICENSE +0 -21
  69. package/skills/code-review/SKILL.md +0 -89
  70. package/skills/code-review/agents/openai.yaml +0 -3
  71. package/skills/codebase-design/DEEPENING.md +0 -37
  72. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  73. package/skills/codebase-design/LICENSE +0 -21
  74. package/skills/codebase-design/SKILL.md +0 -114
  75. package/skills/codebase-design/agents/openai.yaml +0 -3
  76. package/skills/diagnosing-bugs/LICENSE +0 -21
  77. package/skills/diagnosing-bugs/SKILL.md +0 -138
  78. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  79. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  80. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  81. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  82. package/skills/domain-modeling/LICENSE +0 -21
  83. package/skills/domain-modeling/SKILL.md +0 -74
  84. package/skills/domain-modeling/agents/openai.yaml +0 -3
  85. package/skills/grill-me/LICENSE +0 -21
  86. package/skills/grill-me/SKILL.md +0 -7
  87. package/skills/grill-me/agents/openai.yaml +0 -5
  88. package/skills/grill-with-docs/LICENSE +0 -21
  89. package/skills/grill-with-docs/SKILL.md +0 -7
  90. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  91. package/skills/grilling/LICENSE +0 -21
  92. package/skills/grilling/SKILL.md +0 -30
  93. package/skills/grilling/agents/openai.yaml +0 -3
  94. package/skills/handoff/LICENSE +0 -21
  95. package/skills/handoff/SKILL.md +0 -16
  96. package/skills/handoff/agents/openai.yaml +0 -5
  97. package/skills/implement/LICENSE +0 -21
  98. package/skills/implement/SKILL.md +0 -17
  99. package/skills/implement/agents/openai.yaml +0 -5
  100. package/skills/implement-spec/LICENSE +0 -21
  101. package/skills/implement-spec/SKILL.md +0 -40
  102. package/skills/implement-spec/agents/openai.yaml +0 -5
  103. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  104. package/skills/improve-codebase-architecture/LICENSE +0 -21
  105. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  106. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  107. package/skills/pr/CREDITS.md +0 -3
  108. package/skills/pr/LICENSE +0 -21
  109. package/skills/pr/SKILL.md +0 -170
  110. package/skills/pr/agents/openai.yaml +0 -3
  111. package/skills/prototype/LICENSE +0 -21
  112. package/skills/prototype/LOGIC.md +0 -67
  113. package/skills/prototype/SKILL.md +0 -26
  114. package/skills/prototype/UI.md +0 -112
  115. package/skills/prototype/agents/openai.yaml +0 -3
  116. package/skills/research/LICENSE +0 -21
  117. package/skills/research/SKILL.md +0 -12
  118. package/skills/research/agents/openai.yaml +0 -3
  119. package/skills/retro/LICENSE +0 -21
  120. package/skills/retro/SKILL.md +0 -44
  121. package/skills/retro/agents/openai.yaml +0 -5
  122. package/skills/tdd/LICENSE +0 -21
  123. package/skills/tdd/SKILL.md +0 -38
  124. package/skills/tdd/agents/openai.yaml +0 -3
  125. package/skills/tdd/mocking.md +0 -59
  126. package/skills/tdd/tests.md +0 -77
  127. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  128. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  129. package/skills/teach/LICENSE +0 -21
  130. package/skills/teach/MISSION-FORMAT.md +0 -31
  131. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  132. package/skills/teach/SKILL.md +0 -140
  133. package/skills/teach/agents/openai.yaml +0 -5
  134. package/skills/to-questionnaire/LICENSE +0 -21
  135. package/skills/to-questionnaire/SKILL.md +0 -54
  136. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  137. package/skills/to-spec/LICENSE +0 -21
  138. package/skills/to-spec/SKILL.md +0 -75
  139. package/skills/to-spec/agents/openai.yaml +0 -5
  140. package/skills/to-tickets/LICENSE +0 -21
  141. package/skills/to-tickets/SKILL.md +0 -105
  142. package/skills/to-tickets/agents/openai.yaml +0 -5
  143. package/skills/triage/AGENT-BRIEF.md +0 -207
  144. package/skills/triage/LICENSE +0 -21
  145. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  146. package/skills/triage/SKILL.md +0 -112
  147. package/skills/triage/agents/openai.yaml +0 -5
  148. package/skills/wait-what/LICENSE +0 -21
  149. package/skills/wait-what/SKILL.md +0 -7
  150. package/skills/wait-what/agents/openai.yaml +0 -5
  151. package/skills/wayfinder/LICENSE +0 -21
  152. package/skills/wayfinder/SKILL.md +0 -128
  153. package/skills/wayfinder/agents/openai.yaml +0 -5
  154. package/skills/wizard/LICENSE +0 -21
  155. package/skills/wizard/SKILL.md +0 -44
  156. package/skills/wizard/agents/openai.yaml +0 -3
  157. package/skills/wizard/template.sh +0 -223
  158. package/skills/writing-for-agents/LICENSE +0 -21
  159. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  160. package/skills/writing-for-agents/SKILL.md +0 -81
  161. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -0,0 +1,108 @@
1
+ import { existsSync, mkdirSync, renameSync, rmSync } from 'node:fs';
2
+ import { writeFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { parseArgs } from 'node:util';
5
+ import { HouseRefusal, kitAct } from './api.js';
6
+ import { KIT_RELEASE } from './clis.js';
7
+ import { takeOverEarlier } from './earlier.js';
8
+ import { kitHome, readEnrolment, storedConfiguration, writeConfiguration } from './home.js';
9
+ import { DEFAULT_HOUSE, enrol, placeConnection } from './login.js';
10
+ import { runningRelease } from './owner.js';
11
+ import { quoted } from './shell.js';
12
+ import { defineSupervisor, launcher, supervise, systemd } from './supervisor.js';
13
+ const USAGE = `usage: kit connect [--house <origin>] [--code <code>]
14
+ --house <origin> the Building this account's Kit serves, ${DEFAULT_HOUSE} unless one is stored
15
+ --code <code> connect this computer with a login code when Kit holds no credential House accepts
16
+ `;
17
+ const HELD = 'held-enrolment';
18
+ const RECORDS = ['credential.json', 'disconnected.json'];
19
+ const ENDS = ['SIGHUP', 'SIGINT', 'SIGTERM'];
20
+ function unanswered(error) {
21
+ return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
22
+ }
23
+ async function standing(house, credential) {
24
+ try {
25
+ await kitAct(house, 'agents/desired/list', {}, credential);
26
+ return true;
27
+ }
28
+ catch (error) {
29
+ if (!unanswered(error))
30
+ return false;
31
+ process.stderr.write(`kit: House did not answer, so the stored credential stands: ${error.message}\n`);
32
+ return true;
33
+ }
34
+ }
35
+ function settleHeld() {
36
+ const held = join(kitHome(), HELD);
37
+ if (!existsSync(held))
38
+ return;
39
+ if (!existsSync(join(kitHome(), RECORDS[0]))) {
40
+ for (const record of RECORDS)
41
+ if (existsSync(join(held, record)))
42
+ renameSync(join(held, record), join(kitHome(), record));
43
+ }
44
+ rmSync(held, { recursive: true, force: true });
45
+ }
46
+ async function heldWhile(work) {
47
+ const held = join(kitHome(), HELD);
48
+ mkdirSync(held, { mode: 0o700 });
49
+ const ended = () => {
50
+ settleHeld();
51
+ process.exit(130);
52
+ };
53
+ for (const signal of ENDS)
54
+ process.once(signal, ended);
55
+ try {
56
+ for (const record of RECORDS)
57
+ if (existsSync(join(kitHome(), record)))
58
+ renameSync(join(kitHome(), record), join(held, record));
59
+ await work();
60
+ }
61
+ finally {
62
+ for (const signal of ENDS)
63
+ process.off(signal, ended);
64
+ settleHeld();
65
+ }
66
+ }
67
+ export async function connect(argv) {
68
+ const { values } = parseArgs({
69
+ args: argv,
70
+ options: { house: { type: 'string' }, code: { type: 'string' }, help: { type: 'boolean', default: false } },
71
+ });
72
+ if (values.help) {
73
+ process.stdout.write(USAGE);
74
+ return;
75
+ }
76
+ await takeOverEarlier();
77
+ settleHeld();
78
+ const stored = await readEnrolment();
79
+ const house = values.house ?? stored?.house ?? DEFAULT_HOUSE;
80
+ if (stored !== null && stored.house !== house) {
81
+ throw new Error(`this account's Kit serves ${stored.house}; kit logout disconnects it from there, then this command connects it to ${house}`);
82
+ }
83
+ const install = process.env.HOUSE_KIT_INSTALL_COMMAND;
84
+ if (install !== undefined && install !== '')
85
+ await writeFile(join(kitHome(), 'install-command'), `${install}\n`, { mode: 0o600 });
86
+ if (stored === null || !(await standing(stored.house, stored.credential))) {
87
+ if (values.code === undefined)
88
+ await enrol({ house, 'no-private': false });
89
+ else
90
+ await heldWhile(() => enrol({ house, code: values.code, 'no-private': false }));
91
+ if ((await readEnrolment()) === null)
92
+ throw new Error('kit login connected no Environment');
93
+ }
94
+ const settings = await storedConfiguration();
95
+ if (settings.skills === undefined || settings.workspace === undefined) {
96
+ await writeConfiguration({ skills: true, workspace: kitHome(), ...settings });
97
+ }
98
+ await placeConnection(house);
99
+ const { environment } = (await readEnrolment());
100
+ if (process.platform !== 'darwin' && !systemd()) {
101
+ process.stdout.write(`Kit ${KIT_RELEASE} is installed for Environment ${environment}, but no systemd runs on this host to start it; run ${quoted(launcher())} resident under your own service manager, restarting it whenever it ends with a failure.\n`);
102
+ return;
103
+ }
104
+ const changed = await defineSupervisor();
105
+ const running = await runningRelease();
106
+ await supervise(changed, running !== null && running !== KIT_RELEASE);
107
+ process.stdout.write(`Kit connected for Environment ${environment}.\n`);
108
+ }
@@ -1,44 +1,20 @@
1
+ import { KIT_CONNECTION_PATH, KIT_CONNECTION_PROTOCOL_PREFIX, KIT_WIRE, } from '@agentshouse/kit-wire';
1
2
  import { subscribe } from 'node:diagnostics_channel';
3
+ import { setTimeout as delay } from 'node:timers/promises';
2
4
  import { HouseRefusal, retryDelay } from './api.js';
3
5
  import { end, REPLACED, signInAgain } from './end.js';
4
6
  import { readEnrolment } from './home.js';
5
7
  import { relayed } from './relay.js';
6
- import { endUnserved, KIT_WIRE } from './wire.js';
7
- const PATH = '/kit/stream';
8
- const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
8
+ import { Silence } from './silence.js';
9
+ import { endUnserved, unserved } from './wire.js';
10
+ const SUBPROTOCOL = `${KIT_CONNECTION_PROTOCOL_PREFIX}${KIT_WIRE}`;
9
11
  const REFUSAL_HEADER = 'x-house-refusal';
10
12
  // House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
11
13
  export const CONNECTION_SILENCE_MS = 60_000;
12
- const SYSTEM_CONNECTION_CLOCK = {
13
- later: (delay, callback) => setTimeout(callback, delay),
14
- clear: (timer) => clearTimeout(timer),
15
- };
16
- export class ConnectionSilence {
17
- timer = null;
18
- silent;
19
- clock;
20
- interval;
21
- constructor(silent, clock = SYSTEM_CONNECTION_CLOCK, interval = CONNECTION_SILENCE_MS) {
22
- this.silent = silent;
23
- this.clock = clock;
24
- this.interval = interval;
25
- }
26
- heard() {
27
- this.stop();
28
- this.timer = this.clock.later(this.interval, () => {
29
- this.timer = null;
30
- this.silent();
31
- });
32
- }
33
- stop() {
34
- if (this.timer === null)
35
- return;
36
- this.clock.clear(this.timer);
37
- this.timer = null;
38
- }
39
- }
14
+ // A stopping Kit waits up to two seconds for House to answer its close, so what it sent last reaches House and a House that does not answer holds no stop.
15
+ const CLOSE_ANSWER_MS = 2_000;
40
16
  function connectionUrl(house) {
41
- const url = new URL(PATH, house);
17
+ const url = new URL(KIT_CONNECTION_PATH, house);
42
18
  url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
43
19
  return url;
44
20
  }
@@ -52,28 +28,38 @@ function header(headers, name) {
52
28
  let refused = null;
53
29
  subscribe('undici:request:headers', (message) => {
54
30
  const { request, response } = message;
55
- if (!request.path.endsWith(PATH))
31
+ if (!request.path.endsWith(KIT_CONNECTION_PATH))
56
32
  return;
57
- refused = new HouseRefusal(PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
33
+ refused = new HouseRefusal(KIT_CONNECTION_PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
58
34
  });
59
35
  export function holdConnection(handlers) {
60
36
  let connection = null;
37
+ let socket = null;
61
38
  let failures = 0;
39
+ let stopping = false;
62
40
  const connect = async () => {
63
41
  const { house, credential } = (await readEnrolment());
42
+ if (socket !== null || unserved() || stopping)
43
+ return;
64
44
  refused = null;
65
45
  const opening = new WebSocket(relayed(connectionUrl(house)), {
66
46
  protocols: [SUBPROTOCOL],
67
47
  headers: { authorization: `Bearer ${credential}` },
68
48
  });
49
+ socket = opening;
69
50
  let opened = false;
70
51
  let silence = null;
71
52
  const closed = (event) => {
72
53
  silence?.stop();
73
54
  silence = null;
55
+ if (socket === opening)
56
+ socket = null;
74
57
  if (connection === opening)
75
58
  connection = null;
59
+ handlers.closed();
76
60
  process.stderr.write(`kit: connection closed ${event.code} ${event.reason}\n`);
61
+ if (stopping)
62
+ return;
77
63
  if (event.reason === 'replaced')
78
64
  end(REPLACED);
79
65
  if (event.reason === 'credential_rejected' || refused?.status === 401) {
@@ -91,7 +77,7 @@ export function holdConnection(handlers) {
91
77
  opened = true;
92
78
  failures = 0;
93
79
  connection = opening;
94
- silence = new ConnectionSilence(() => {
80
+ silence = new Silence(CONNECTION_SILENCE_MS, () => {
95
81
  if (connection !== opening)
96
82
  return;
97
83
  connection = null;
@@ -108,18 +94,27 @@ export function holdConnection(handlers) {
108
94
  if (arrived.type === 'input')
109
95
  handlers.call(arrived);
110
96
  else if (arrived.type !== 'beat')
111
- handlers.notification(arrived);
97
+ handlers.oneWayCall(arrived);
112
98
  };
113
99
  opening.onerror = () => undefined;
114
100
  opening.onclose = closed;
115
101
  };
116
102
  void connect();
117
103
  return {
118
- send(notification) {
104
+ send(oneWayCall) {
119
105
  if (connection === null || connection.readyState !== WebSocket.OPEN)
120
106
  return false;
121
- connection.send(JSON.stringify(notification));
107
+ connection.send(JSON.stringify(oneWayCall));
122
108
  return true;
123
109
  },
110
+ close() {
111
+ stopping = true;
112
+ const open = socket;
113
+ if (open === null)
114
+ return Promise.resolve();
115
+ const answered = new Promise((resolve) => open.addEventListener('close', () => resolve(), { once: true }));
116
+ open.close();
117
+ return Promise.race([answered, delay(CLOSE_ANSWER_MS)]);
118
+ },
124
119
  };
125
120
  }
@@ -0,0 +1,106 @@
1
+ import { applied } from '@agentshouse/session-content';
2
+ function filesOf(files) {
3
+ const held = new Map();
4
+ for (const { path, added, removed } of files) {
5
+ const before = held.get(path);
6
+ held.set(path, { added: (before?.added ?? 0) + added, removed: (before?.removed ?? 0) + removed });
7
+ }
8
+ return held;
9
+ }
10
+ function none() {
11
+ return { type: 'counts', commands: 0, edited: 0, other: 0, added: 0, removed: 0, failed: 0 };
12
+ }
13
+ export class Content {
14
+ parts = [];
15
+ emit;
16
+ calls = new Map();
17
+ writing = null;
18
+ stretch = null;
19
+ constructor(emit) {
20
+ this.emit = emit;
21
+ }
22
+ holds(key) {
23
+ return this.calls.has(key);
24
+ }
25
+ write(id, text) {
26
+ if (text === '')
27
+ return;
28
+ if (this.writing !== null && this.writing.id === id) {
29
+ this.apply({ op: 'append', index: this.writing.index, text });
30
+ return;
31
+ }
32
+ this.stretch = null;
33
+ this.writing = { id, index: this.started({ type: 'text', text }) };
34
+ }
35
+ add(part) {
36
+ this.writing = null;
37
+ this.started(part);
38
+ }
39
+ arrived(part) {
40
+ this.started(part);
41
+ }
42
+ call(key, parent, called) {
43
+ const held = this.calls.get(key);
44
+ if (held !== undefined) {
45
+ held.files = filesOf(called.files);
46
+ held.failed = called.failed;
47
+ this.settle(this.tally());
48
+ return;
49
+ }
50
+ if (parent !== null && !this.calls.has(parent))
51
+ return;
52
+ if (parent === null)
53
+ this.writing = null;
54
+ const stretch = parent === null ? this.stretch : this.calls.get(parent).stretch;
55
+ const at = stretch ?? this.parts.length;
56
+ this.calls.set(key, { stretch: at, kind: called.kind, files: filesOf(called.files), failed: called.failed });
57
+ const tallied = this.tally();
58
+ if (stretch === null)
59
+ this.stretch = this.started(tallied.get(at));
60
+ this.settle(tallied);
61
+ }
62
+ operations() {
63
+ return this.parts.map((part, index) => ({ op: 'start', index, part }));
64
+ }
65
+ tally() {
66
+ const stretches = new Map();
67
+ const first = new Set();
68
+ for (const call of this.calls.values()) {
69
+ const counts = stretches.get(call.stretch) ?? none();
70
+ stretches.set(call.stretch, counts);
71
+ if (call.kind === 'command')
72
+ counts.commands += 1;
73
+ if (call.kind === 'other')
74
+ counts.other += 1;
75
+ if (call.failed)
76
+ counts.failed += 1;
77
+ if (call.kind !== 'edit')
78
+ continue;
79
+ if (call.files.size === 0)
80
+ counts.edited += 1;
81
+ for (const [path, lines] of call.files) {
82
+ if (!first.has(path))
83
+ counts.edited += 1;
84
+ first.add(path);
85
+ counts.added += lines.added;
86
+ counts.removed += lines.removed;
87
+ }
88
+ }
89
+ return stretches;
90
+ }
91
+ settle(tallied) {
92
+ for (const [index, counts] of tallied) {
93
+ if (JSON.stringify(counts) !== JSON.stringify(this.parts[index]))
94
+ this.apply({ op: 'set', index, part: counts });
95
+ }
96
+ }
97
+ started(part) {
98
+ const index = this.parts.length;
99
+ this.apply({ op: 'start', index, part });
100
+ return index;
101
+ }
102
+ apply(operation) {
103
+ this.parts = applied(this.parts, operation);
104
+ this.emit(operation);
105
+ }
106
+ }