@agentshouse/kit 0.2.1-c14f8446ba284 → 0.2.1-c1873657edab7
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.
- package/README.md +42 -40
- package/dist/acp.js +36 -16
- package/dist/agents.js +111 -24
- package/dist/api.js +7 -3
- package/dist/app-git.js +10 -26
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +10 -24
- package/dist/calls.js +63 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +52 -10
- package/dist/connection.js +125 -0
- package/dist/conversations.js +405 -155
- package/dist/copies.js +185 -123
- package/dist/end.js +23 -4
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +6 -2
- package/dist/files.js +123 -31
- package/dist/git.js +11 -9
- package/dist/home.js +96 -7
- package/dist/house-cli.js +286 -0
- package/dist/house-main.js +7 -177
- package/dist/instructions.js +7 -9
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +111 -23
- package/dist/logout.js +14 -16
- package/dist/mcp.js +4 -2
- package/dist/parts.js +34 -16
- package/dist/placement.js +39 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +99 -43
- package/dist/scope.js +3 -0
- package/dist/service-main.js +9 -0
- package/dist/service.js +55 -0
- package/dist/sign-in.js +19 -37
- package/dist/skills.js +20 -32
- package/dist/transcription.js +53 -22
- package/dist/translate.js +2 -8
- package/dist/update.js +69 -50
- package/dist/wire.js +22 -0
- package/dist/work.js +3 -5
- package/package.json +6 -6
- package/dist/stream.js +0 -72
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { run } from './clis.js';
|
|
4
|
+
import { kitHome } from './home.js';
|
|
5
|
+
export function service() {
|
|
6
|
+
if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
|
|
7
|
+
return null;
|
|
8
|
+
return process.env.MANAGERPID ? 'user' : 'system';
|
|
9
|
+
}
|
|
10
|
+
export function throughSudo() {
|
|
11
|
+
return service() === 'system' && process.getuid() !== 0;
|
|
12
|
+
}
|
|
13
|
+
export async function updatesItself() {
|
|
14
|
+
if (service() === null)
|
|
15
|
+
return false;
|
|
16
|
+
if (!throughSudo())
|
|
17
|
+
return true;
|
|
18
|
+
// sudo answers at once, so ten seconds only bounds a stuck sudo.
|
|
19
|
+
return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
|
|
20
|
+
}
|
|
21
|
+
function recorded(name) {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(join(kitHome(), name), 'utf8').trim();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return null;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function installCommand() {
|
|
32
|
+
return recorded('install-command');
|
|
33
|
+
}
|
|
34
|
+
export function machine() {
|
|
35
|
+
const placed = recorded('placement');
|
|
36
|
+
if (placed === 'container' || placed === 'server' || placed === 'windows')
|
|
37
|
+
return placed;
|
|
38
|
+
return process.platform === 'darwin' ? 'macos' : 'linux';
|
|
39
|
+
}
|
package/dist/relay.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
let selected;
|
|
2
|
+
export function selectRelay(relay) {
|
|
3
|
+
selected = relay === undefined || relay === '' ? null : relay;
|
|
4
|
+
}
|
|
5
|
+
export function relayOrigin() {
|
|
6
|
+
if (selected !== undefined)
|
|
7
|
+
return selected ?? undefined;
|
|
8
|
+
const ambient = process.env.HOUSE_KIT_RELAY;
|
|
9
|
+
return ambient === undefined || ambient === '' ? undefined : ambient;
|
|
10
|
+
}
|
|
1
11
|
export function relayed(target) {
|
|
2
12
|
const url = new URL(target);
|
|
3
|
-
const relay =
|
|
4
|
-
if (relay === undefined
|
|
13
|
+
const relay = relayOrigin();
|
|
14
|
+
if (relay === undefined)
|
|
5
15
|
return url;
|
|
6
16
|
const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
|
|
7
17
|
if (url.protocol === 'wss:' || url.protocol === 'ws:')
|
package/dist/resident.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { once } from 'node:events';
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { createServer } from 'node:http';
|
|
4
|
+
import { createServer, get } from 'node:http';
|
|
5
5
|
import { dirname, extname, join } from 'node:path';
|
|
6
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { Agents } from './agents.js';
|
|
8
9
|
import { house } from './api.js';
|
|
9
10
|
import { received } from './bridge.js';
|
|
10
|
-
import { Conversations } from './conversations.js';
|
|
11
|
+
import { CONVERSATION_METHODS, Conversations } from './conversations.js';
|
|
11
12
|
import { LocalCopies } from './copies.js';
|
|
12
|
-
import {
|
|
13
|
+
import { restart } from './end.js';
|
|
14
|
+
import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
|
|
15
|
+
import { Calls } from './calls.js';
|
|
13
16
|
import { killDescendants } from './scope.js';
|
|
14
17
|
import { quoted } from './shell.js';
|
|
15
18
|
import { SignIns } from './sign-in.js';
|
|
16
19
|
import { placeSkillSet } from './skills.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
20
|
+
import { holdConnection } from './connection.js';
|
|
21
|
+
import { KitUpdate } from './update.js';
|
|
19
22
|
import { codexLauncher } from './work.js';
|
|
20
23
|
function report(error) {
|
|
21
24
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -28,26 +31,66 @@ async function installShim(path, module) {
|
|
|
28
31
|
await mkdir(dirname(path), { recursive: true });
|
|
29
32
|
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
30
33
|
}
|
|
34
|
+
function claimed(lock) {
|
|
35
|
+
try {
|
|
36
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.errcode === 5)
|
|
41
|
+
return false;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
31
45
|
async function serveOwner(copies) {
|
|
32
|
-
const
|
|
33
|
-
|
|
46
|
+
const lock = new DatabaseSync(ownerLock());
|
|
47
|
+
if (!claimed(lock)) {
|
|
48
|
+
lock.close();
|
|
49
|
+
const running = await runningResident();
|
|
50
|
+
throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
|
|
51
|
+
}
|
|
34
52
|
const server = createServer(async (request, response) => {
|
|
35
53
|
try {
|
|
36
|
-
|
|
54
|
+
const text = await received(request);
|
|
55
|
+
let answered;
|
|
56
|
+
if (request.url === '/resident') {
|
|
57
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (request.url === '/git/fetch') {
|
|
61
|
+
answered = await copies.fetch();
|
|
62
|
+
}
|
|
63
|
+
else if (request.url === '/git/push') {
|
|
64
|
+
const { cwd, commit } = JSON.parse(text);
|
|
65
|
+
answered = await copies.push(cwd, commit, copies.owner);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
37
68
|
response.writeHead(404).end();
|
|
38
69
|
return;
|
|
39
70
|
}
|
|
40
|
-
|
|
41
|
-
const pushed = await copies.push(cwd, commit, copies.owner);
|
|
42
|
-
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(pushed));
|
|
71
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(answered));
|
|
43
72
|
}
|
|
44
73
|
catch (error) {
|
|
45
74
|
response.writeHead(502).end(error instanceof Error ? error.message : String(error));
|
|
46
75
|
}
|
|
47
76
|
});
|
|
48
|
-
server.
|
|
77
|
+
server.on('close', () => lock.close());
|
|
78
|
+
await rm(ownerSocket(), { force: true });
|
|
79
|
+
server.listen(ownerSocket());
|
|
49
80
|
await once(server, 'listening');
|
|
50
81
|
}
|
|
82
|
+
function runningResident() {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
get({ socketPath: ownerSocket(), path: '/resident' }, (answer) => {
|
|
85
|
+
received(answer).then((text) => resolve(JSON.parse(text).pid), reject);
|
|
86
|
+
}).on('error', (error) => {
|
|
87
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
88
|
+
resolve(null);
|
|
89
|
+
else
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
51
94
|
function connected() {
|
|
52
95
|
return new Promise((resolve) => {
|
|
53
96
|
const watcher = watch(kitHome(), () => {
|
|
@@ -64,8 +107,9 @@ function connected() {
|
|
|
64
107
|
resolve();
|
|
65
108
|
});
|
|
66
109
|
}
|
|
67
|
-
|
|
110
|
+
async function started() {
|
|
68
111
|
await connected();
|
|
112
|
+
await forgetRestart();
|
|
69
113
|
watch(kitHome(), () => {
|
|
70
114
|
if (enrolled())
|
|
71
115
|
return;
|
|
@@ -74,34 +118,46 @@ export async function resident() {
|
|
|
74
118
|
});
|
|
75
119
|
await placeSkillSet();
|
|
76
120
|
await mkdir(agentBase(), { recursive: true });
|
|
77
|
-
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
78
|
-
const agents = new Agents(house);
|
|
79
|
-
const copies = new LocalCopies(house);
|
|
80
|
-
await copies.load();
|
|
81
121
|
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
82
122
|
await installShim(codexLauncher(), 'codex-main');
|
|
123
|
+
}
|
|
124
|
+
export async function resident() {
|
|
125
|
+
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
126
|
+
const copies = new LocalCopies(house);
|
|
127
|
+
await copies.load();
|
|
83
128
|
await serveOwner(copies);
|
|
84
|
-
|
|
129
|
+
await started().catch((error) => {
|
|
130
|
+
report(error);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
});
|
|
133
|
+
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
134
|
+
const agents = new Agents(house, () => changed());
|
|
135
|
+
let connection = null;
|
|
85
136
|
let reported = false;
|
|
86
|
-
const idle = () => conversations.idle() &&
|
|
137
|
+
const idle = () => calls.idle() && conversations.idle() && agents.idle();
|
|
87
138
|
const changed = () => {
|
|
88
139
|
if (!idle()) {
|
|
89
140
|
reported = false;
|
|
90
141
|
}
|
|
142
|
+
else if (restartAsked() && conversations.quiet()) {
|
|
143
|
+
restart('restarting for an updated CLI');
|
|
144
|
+
}
|
|
91
145
|
else if (!reported) {
|
|
92
146
|
reported = true;
|
|
93
147
|
logged(house.deliver('/kit/idle', {}, idle));
|
|
94
148
|
}
|
|
95
149
|
};
|
|
150
|
+
const calls = new Calls(house, changed);
|
|
96
151
|
const conversations = new Conversations({
|
|
97
152
|
house,
|
|
98
153
|
agents,
|
|
99
154
|
copies,
|
|
100
|
-
|
|
155
|
+
calls,
|
|
156
|
+
send: (notification) => connection?.send(notification) ?? false,
|
|
101
157
|
changed,
|
|
102
158
|
});
|
|
103
|
-
const signIns = new SignIns(house, agents,
|
|
104
|
-
const
|
|
159
|
+
const signIns = new SignIns(house, agents, calls);
|
|
160
|
+
const update = new KitUpdate(calls);
|
|
105
161
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
106
162
|
process.once(signal, () => {
|
|
107
163
|
killDescendants();
|
|
@@ -109,33 +165,33 @@ export async function resident() {
|
|
|
109
165
|
});
|
|
110
166
|
}
|
|
111
167
|
await house.deliver('/kit/restarted', {}).catch(report);
|
|
112
|
-
await
|
|
168
|
+
await update.resumed().catch(report);
|
|
113
169
|
logged(agents.refresh());
|
|
114
|
-
|
|
170
|
+
connection = holdConnection({
|
|
115
171
|
opened: () => {
|
|
116
172
|
conversations.opened();
|
|
117
173
|
changed();
|
|
118
|
-
logged(copies.
|
|
174
|
+
logged(copies.connected());
|
|
119
175
|
},
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (arrived.type === 'input') {
|
|
131
|
-
reported = false;
|
|
132
|
-
if (arrived.kind === 'sign_in')
|
|
133
|
-
signIns.start(arrived);
|
|
134
|
-
else if (arrived.kind === 'update')
|
|
135
|
-
updates.start(arrived);
|
|
136
|
-
else
|
|
137
|
-
conversations.input(arrived);
|
|
176
|
+
call: (call) => {
|
|
177
|
+
if (call.kind === 'sign_in')
|
|
178
|
+
signIns.start(call);
|
|
179
|
+
else if (call.kind === 'update')
|
|
180
|
+
update.start(call);
|
|
181
|
+
else if (CONVERSATION_METHODS.has(call.kind))
|
|
182
|
+
conversations.call(call);
|
|
183
|
+
else {
|
|
184
|
+
const refused = { refused: `This Kit does not know ${call.kind}; update the Kit` };
|
|
185
|
+
void calls.carry(call.input_id, async () => ({ result: refused }));
|
|
138
186
|
}
|
|
139
187
|
},
|
|
188
|
+
notification: (notification) => {
|
|
189
|
+
if (notification.type === 'watching')
|
|
190
|
+
conversations.watching(notification.watching === true);
|
|
191
|
+
if (notification.type === 'authority_changed')
|
|
192
|
+
logged(copies.changed(notification.rooms));
|
|
193
|
+
if (notification.type === 'work_available' && notification.subject === 'agents')
|
|
194
|
+
logged(agents.refresh());
|
|
195
|
+
},
|
|
140
196
|
});
|
|
141
197
|
}
|
package/dist/scope.js
CHANGED
|
@@ -4,6 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
const LISTING_BYTES = 1 << 28;
|
|
5
5
|
const CGROUPS = '/sys/fs/cgroup';
|
|
6
6
|
const GONE = new Set(['ENOENT', 'ESRCH']);
|
|
7
|
+
const EXITED = new Set(['Z', 'X']);
|
|
7
8
|
function failure(error) {
|
|
8
9
|
return error.code ?? '';
|
|
9
10
|
}
|
|
@@ -24,6 +25,8 @@ function read(pid) {
|
|
|
24
25
|
try {
|
|
25
26
|
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
26
27
|
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
28
|
+
if (EXITED.has(fields[0]))
|
|
29
|
+
return null;
|
|
27
30
|
const command = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replaceAll('\0', ' ');
|
|
28
31
|
return { parent: Number(fields[1]), session: fields[3], command };
|
|
29
32
|
}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { kitHome } from './home.js';
|
|
5
|
+
const UNIT = 'house-kit.service';
|
|
6
|
+
// launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
|
|
7
|
+
const MANAGER_MS = 10_000;
|
|
8
|
+
function manage(command, args) {
|
|
9
|
+
return spawnSync(command, args, { encoding: 'utf8', timeout: MANAGER_MS });
|
|
10
|
+
}
|
|
11
|
+
function start(command, args) {
|
|
12
|
+
const started = manage(command, args);
|
|
13
|
+
if (started.status === 0)
|
|
14
|
+
return;
|
|
15
|
+
const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
|
|
16
|
+
throw new Error(`the Kit service could not be started: ${cause}`);
|
|
17
|
+
}
|
|
18
|
+
function physical(path) {
|
|
19
|
+
return existsSync(path) ? realpathSync(path) : resolve(path);
|
|
20
|
+
}
|
|
21
|
+
function systemdHome(environment) {
|
|
22
|
+
for (const [, quoted, bare] of environment.matchAll(/"((?:[^"\\]|\\.)*)"|(\S+)/g)) {
|
|
23
|
+
const assignment = bare ?? quoted.replace(/\\(.)/g, '$1');
|
|
24
|
+
if (assignment.startsWith('HOUSE_KIT_HOME='))
|
|
25
|
+
return assignment.slice('HOUSE_KIT_HOME='.length);
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
function runsThisHome(served) {
|
|
30
|
+
return served !== undefined && physical(served) === physical(kitHome());
|
|
31
|
+
}
|
|
32
|
+
export function startService() {
|
|
33
|
+
if (process.platform === 'darwin') {
|
|
34
|
+
const service = `gui/${process.getuid()}/house-kit`;
|
|
35
|
+
const printed = manage('launchctl', ['print', service]);
|
|
36
|
+
if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
|
|
37
|
+
return false;
|
|
38
|
+
if (!runsThisHome(/^\t+HOUSE_KIT_HOME => (.+)$/m.exec(printed.stdout)?.[1]))
|
|
39
|
+
return false;
|
|
40
|
+
start('launchctl', ['kickstart', service]);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
for (const scope of [['--user'], []]) {
|
|
44
|
+
if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
|
|
45
|
+
continue;
|
|
46
|
+
const environment = manage('systemctl', [...scope, 'show', '--property=Environment', '--value', UNIT]).stdout;
|
|
47
|
+
if (!runsThisHome(systemdHome(environment)))
|
|
48
|
+
continue;
|
|
49
|
+
if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
|
|
50
|
+
return false;
|
|
51
|
+
start('systemctl', [...scope, 'start', UNIT]);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
package/dist/sign-in.js
CHANGED
|
@@ -9,68 +9,50 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
|
|
|
9
9
|
function causeOf(error) {
|
|
10
10
|
return error instanceof Error ? error.message : String(error);
|
|
11
11
|
}
|
|
12
|
-
function logged(error) {
|
|
13
|
-
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
14
|
-
}
|
|
15
12
|
function endOf(signal) {
|
|
16
13
|
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
17
14
|
}
|
|
18
15
|
export class SignIns {
|
|
19
16
|
house;
|
|
20
17
|
agents;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor(house, agents, changed) {
|
|
18
|
+
calls;
|
|
19
|
+
constructor(house, agents, calls) {
|
|
24
20
|
this.house = house;
|
|
25
21
|
this.agents = agents;
|
|
26
|
-
this.
|
|
27
|
-
}
|
|
28
|
-
idle() {
|
|
29
|
-
return this.running.size === 0;
|
|
22
|
+
this.calls = calls;
|
|
30
23
|
}
|
|
31
|
-
start(
|
|
32
|
-
|
|
33
|
-
return;
|
|
34
|
-
this.running.add(input.input_id);
|
|
35
|
-
this.changed();
|
|
36
|
-
this.signIn(input)
|
|
37
|
-
.catch(logged)
|
|
38
|
-
.finally(() => {
|
|
39
|
-
this.running.delete(input.input_id);
|
|
40
|
-
this.changed();
|
|
41
|
-
});
|
|
24
|
+
start(call) {
|
|
25
|
+
void this.calls.carry(call.input_id, () => this.signIn(call));
|
|
42
26
|
}
|
|
43
|
-
async signIn(
|
|
27
|
+
async signIn(call) {
|
|
44
28
|
const ending = new AbortController();
|
|
45
29
|
// House stops waiting for a sign-in ten minutes after it wrote it and sends the seconds left, so its install and login end with the page.
|
|
46
|
-
const timer = setTimeout(() => ending.abort(),
|
|
47
|
-
const ended = await Promise.race([this.signedIn(
|
|
30
|
+
const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
|
|
31
|
+
const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
|
|
48
32
|
clearTimeout(timer);
|
|
49
33
|
if (ended)
|
|
50
|
-
process.stderr.write(`kit: the ${
|
|
51
|
-
|
|
52
|
-
if (!ended)
|
|
53
|
-
await this.agents.reread(input.cli);
|
|
34
|
+
process.stderr.write(`kit: the ${call.cli} sign-in reached the end House set for it\n`);
|
|
35
|
+
return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
|
|
54
36
|
}
|
|
55
|
-
async signedIn(
|
|
56
|
-
await this.login(
|
|
37
|
+
async signedIn(call, signal) {
|
|
38
|
+
await this.login(call, signal);
|
|
57
39
|
if (!signal.aborted)
|
|
58
|
-
await this.agents.recheck(
|
|
40
|
+
await this.agents.recheck(call.cli, signal);
|
|
59
41
|
return false;
|
|
60
42
|
}
|
|
61
|
-
async login(
|
|
43
|
+
async login(call, signal) {
|
|
62
44
|
let cli;
|
|
63
45
|
try {
|
|
64
|
-
cli = await this.agents.located(
|
|
46
|
+
cli = await this.agents.located(call.cli, signal);
|
|
65
47
|
}
|
|
66
48
|
catch (error) {
|
|
67
49
|
if (!signal.aborted)
|
|
68
|
-
process.stderr.write(`kit: the ${
|
|
50
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
|
|
69
51
|
return;
|
|
70
52
|
}
|
|
71
53
|
if (signal.aborted)
|
|
72
54
|
return;
|
|
73
|
-
const login = CLIS[
|
|
55
|
+
const login = CLIS[call.cli].login;
|
|
74
56
|
const child = spawn(cli, login.args, {
|
|
75
57
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
76
58
|
detached: true,
|
|
@@ -102,7 +84,7 @@ export class SignIns {
|
|
|
102
84
|
return;
|
|
103
85
|
held = true;
|
|
104
86
|
const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
|
|
105
|
-
void holdSecretInput(this.house,
|
|
87
|
+
void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
|
|
106
88
|
if (!running())
|
|
107
89
|
return;
|
|
108
90
|
if (content === null)
|
|
@@ -119,6 +101,6 @@ export class SignIns {
|
|
|
119
101
|
});
|
|
120
102
|
signal.removeEventListener('abort', stop);
|
|
121
103
|
if (failed !== null && !signal.aborted)
|
|
122
|
-
process.stderr.write(`kit: the ${
|
|
104
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
|
|
123
105
|
}
|
|
124
106
|
}
|
package/dist/skills.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cp, lstat, mkdir, readdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { cp, lstat, mkdir, realpath, rm, symlink } from 'node:fs/promises';
|
|
3
2
|
import { homedir } from 'node:os';
|
|
4
3
|
import { join, relative } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { listSkills } from '@agentshouse/skills';
|
|
5
|
+
import { KIT_RELEASE } from './clis.js';
|
|
7
6
|
import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
|
|
8
|
-
import { refusalOf } from './refusals.js';
|
|
9
|
-
export const HOW_WE_WORK = '/rooms/private/how-we-work.md';
|
|
10
|
-
const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
|
|
11
|
-
const HOW_WE_WORK_TEXT = readFileSync(new URL('../how-we-work.md', import.meta.url), 'utf8');
|
|
12
7
|
const RECORD = 'skill-set.json';
|
|
13
|
-
const CREATED = 'how-we-work-created';
|
|
14
|
-
const UNWRITABLE = new Set(['room_not_found', 'operation_denied']);
|
|
15
8
|
function skillsDirectory() {
|
|
16
9
|
return join(homedir(), '.agents', 'skills');
|
|
17
10
|
}
|
|
@@ -30,28 +23,37 @@ async function present(path) {
|
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
25
|
async function install() {
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
if (!(await present(join(skillsDirectory(), name))) && !(await present(join(claudeDirectory(), name)))) {
|
|
36
|
-
|
|
26
|
+
const placed = [];
|
|
27
|
+
for (const skill of listSkills()) {
|
|
28
|
+
if (!(await present(join(skillsDirectory(), skill.name))) && !(await present(join(claudeDirectory(), skill.name)))) {
|
|
29
|
+
placed.push(skill);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
32
|
+
const names = placed.map((skill) => skill.name);
|
|
39
33
|
await writeHome(RECORD, { names });
|
|
40
34
|
await mkdir(skillsDirectory(), { recursive: true });
|
|
41
35
|
await mkdir(claudeDirectory(), { recursive: true });
|
|
42
36
|
const skills = await realpath(skillsDirectory());
|
|
43
37
|
const claude = await realpath(claudeDirectory());
|
|
44
|
-
for (const name of
|
|
45
|
-
await cp(
|
|
38
|
+
for (const { name, directory } of placed) {
|
|
39
|
+
await cp(directory, join(skillsDirectory(), name), { recursive: true });
|
|
46
40
|
if (claude !== skills)
|
|
47
41
|
await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
|
|
48
42
|
}
|
|
49
|
-
await writeHome(RECORD, { version:
|
|
43
|
+
await writeHome(RECORD, { version: KIT_RELEASE, names });
|
|
50
44
|
}
|
|
51
45
|
export async function placeSkillSet() {
|
|
46
|
+
try {
|
|
47
|
+
await replaceSkillSet();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function replaceSkillSet() {
|
|
52
54
|
const accepted = (await readConfiguration()).skills;
|
|
53
55
|
const installed = await readHome(RECORD);
|
|
54
|
-
if (accepted && installed?.version ===
|
|
56
|
+
if (accepted && installed?.version === KIT_RELEASE)
|
|
55
57
|
return;
|
|
56
58
|
for (const name of installed?.names ?? []) {
|
|
57
59
|
await rm(join(claudeDirectory(), name), { recursive: true, force: true });
|
|
@@ -62,17 +64,3 @@ export async function placeSkillSet() {
|
|
|
62
64
|
else
|
|
63
65
|
await rm(join(kitHome(), RECORD), { force: true });
|
|
64
66
|
}
|
|
65
|
-
export async function createHowWeWork(bridge) {
|
|
66
|
-
if ((await readHome(RECORD)) === null || (await present(join(kitHome(), CREATED))))
|
|
67
|
-
return;
|
|
68
|
-
const created = await bridge.tool('edit', { changes: [{ op: 'create', path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
|
|
69
|
-
if (created.isError === true) {
|
|
70
|
-
const text = created.content.map((content) => content.text).join('\n');
|
|
71
|
-
const refusal = refusalOf(text);
|
|
72
|
-
if (UNWRITABLE.has(refusal?.code ?? ''))
|
|
73
|
-
return;
|
|
74
|
-
if (refusal?.code !== 'edit_conflict' || !refusal.conflicts.includes('path_exists'))
|
|
75
|
-
throw new Error(text);
|
|
76
|
-
}
|
|
77
|
-
await writeFile(join(kitHome(), CREATED), '');
|
|
78
|
-
}
|