@agentshouse/kit 0.2.1-c5d36e97b0fea → 0.2.1-c681dfca497a8
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 +24 -24
- package/dist/agents.js +24 -5
- package/dist/api.js +6 -2
- package/dist/bootstrap.json +4 -4
- package/dist/chatgpt.js +26 -0
- package/dist/clis.js +41 -9
- package/dist/conversations.js +9 -5
- package/dist/copies.js +36 -26
- package/dist/end.js +17 -3
- package/dist/enrol-main.js +7 -1
- package/dist/files.js +7 -1
- package/dist/git.js +11 -8
- package/dist/home.js +76 -5
- package/dist/house-main.js +164 -63
- package/dist/instructions.js +5 -4
- package/dist/kit-main.js +53 -8
- package/dist/login.js +83 -18
- package/dist/parts.js +34 -16
- package/dist/placement.js +48 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +15 -6
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/skills.js +11 -1
- package/dist/stream.js +9 -4
- package/dist/update.js +28 -6
- package/dist/wire.js +6 -0
- package/how-we-work.md +11 -3
- package/package.json +3 -2
- package/skills/ask-matt/SKILL.md +17 -11
- package/skills/ask-matt/agents/openai.yaml +1 -0
- package/skills/code-review/SKILL.md +5 -5
- package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
- package/skills/codebase-design/SKILL.md +0 -2
- package/skills/diagnosing-bugs/SKILL.md +2 -4
- package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
- package/skills/domain-modeling/SKILL.md +12 -14
- package/skills/grill-me/SKILL.md +1 -2
- package/skills/grill-me/agents/openai.yaml +1 -0
- package/skills/grill-with-docs/SKILL.md +1 -2
- package/skills/grill-with-docs/agents/openai.yaml +1 -0
- package/skills/grilling/SKILL.md +2 -2
- package/skills/handoff/SKILL.md +2 -3
- package/skills/handoff/agents/openai.yaml +1 -0
- package/skills/implement/SKILL.md +5 -4
- package/skills/implement/agents/openai.yaml +1 -0
- package/skills/implement-spec/SKILL.md +40 -0
- package/skills/implement-spec/agents/openai.yaml +5 -0
- package/skills/improve-codebase-architecture/SKILL.md +6 -7
- package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
- package/skills/pr/CREDITS.md +3 -0
- package/skills/pr/LICENSE +21 -0
- package/skills/pr/SKILL.md +170 -0
- package/skills/pr/agents/openai.yaml +3 -0
- package/skills/prototype/SKILL.md +0 -2
- package/skills/research/SKILL.md +0 -2
- package/skills/retro/LICENSE +21 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/tdd/SKILL.md +2 -4
- package/skills/teach/SKILL.md +3 -4
- package/skills/teach/agents/openai.yaml +1 -0
- package/skills/to-questionnaire/SKILL.md +1 -2
- package/skills/to-questionnaire/agents/openai.yaml +1 -0
- package/skills/to-spec/SKILL.md +1 -2
- package/skills/to-spec/agents/openai.yaml +1 -0
- package/skills/to-tickets/SKILL.md +3 -4
- package/skills/to-tickets/agents/openai.yaml +1 -0
- package/skills/triage/AGENT-BRIEF.md +207 -0
- package/skills/triage/LICENSE +21 -0
- package/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/skills/triage/SKILL.md +112 -0
- package/skills/triage/agents/openai.yaml +5 -0
- package/skills/wait-what/SKILL.md +2 -3
- package/skills/wait-what/agents/openai.yaml +1 -0
- package/skills/wayfinder/SKILL.md +5 -6
- package/skills/wayfinder/agents/openai.yaml +1 -0
- package/skills/wizard/LICENSE +21 -0
- package/skills/wizard/SKILL.md +44 -0
- package/skills/wizard/agents/openai.yaml +3 -0
- package/skills/wizard/template.sh +223 -0
- package/skills/writing-for-agents/SKILL.md +0 -2
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/dist/home.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { accessSync, chmodSync, constants, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync } from 'node:fs';
|
|
2
2
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { selectRelay } from './relay.js';
|
|
5
6
|
const ENROLMENT = 'credential.json';
|
|
6
7
|
const DISCONNECTED = 'disconnected.json';
|
|
7
8
|
const CONFIGURATION = 'kit.json';
|
|
8
9
|
const OWN_AGENT = 'own-agent.json';
|
|
10
|
+
const RESTART = 'restart';
|
|
11
|
+
let defaulted;
|
|
12
|
+
function writable(directory) {
|
|
13
|
+
try {
|
|
14
|
+
accessSync(directory, constants.W_OK | constants.X_OK);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function ownTemporaryHome() {
|
|
22
|
+
const home = join(tmpdir(), `house-kit-${process.getuid()}`);
|
|
23
|
+
try {
|
|
24
|
+
mkdirSync(home, { mode: 0o700 });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error.code !== 'EEXIST')
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const found = lstatSync(home);
|
|
31
|
+
if (found.isSymbolicLink())
|
|
32
|
+
throw new Error(`${home} is a symbolic link`);
|
|
33
|
+
if (!found.isDirectory())
|
|
34
|
+
throw new Error(`${home} is not a directory`);
|
|
35
|
+
if (found.uid !== process.getuid())
|
|
36
|
+
throw new Error(`${home} is not owned by this User`);
|
|
37
|
+
chmodSync(home, 0o700);
|
|
38
|
+
return home;
|
|
39
|
+
}
|
|
40
|
+
function defaultHome() {
|
|
41
|
+
const home = join(homedir(), '.house-kit');
|
|
42
|
+
return existsSync(home) || writable(homedir()) ? home : ownTemporaryHome();
|
|
43
|
+
}
|
|
9
44
|
export function kitHome() {
|
|
10
|
-
return process.env.HOUSE_KIT_HOME
|
|
45
|
+
return process.env.HOUSE_KIT_HOME || (defaulted ??= defaultHome());
|
|
11
46
|
}
|
|
12
47
|
export function workspaceRoot() {
|
|
13
48
|
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
|
@@ -32,8 +67,11 @@ export async function writeHome(name, value) {
|
|
|
32
67
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
33
68
|
await rename(temporary, join(home, name));
|
|
34
69
|
}
|
|
35
|
-
export function readEnrolment() {
|
|
36
|
-
|
|
70
|
+
export async function readEnrolment() {
|
|
71
|
+
const enrolment = await readHome(ENROLMENT);
|
|
72
|
+
if (enrolment !== null)
|
|
73
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || enrolment.relay);
|
|
74
|
+
return enrolment;
|
|
37
75
|
}
|
|
38
76
|
export async function writeEnrolment(enrolment) {
|
|
39
77
|
await writeHome(ENROLMENT, enrolment);
|
|
@@ -46,9 +84,42 @@ export async function forgetEnrolment({ house, environment }) {
|
|
|
46
84
|
await writeHome(DISCONNECTED, { house, environment });
|
|
47
85
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
48
86
|
}
|
|
87
|
+
export async function forgetRejected(rejected) {
|
|
88
|
+
const held = await readHome(ENROLMENT);
|
|
89
|
+
if (held?.credential !== rejected)
|
|
90
|
+
return;
|
|
91
|
+
await writeHome(DISCONNECTED, { house: held.house, environment: held.environment });
|
|
92
|
+
const enrolment = join(kitHome(), ENROLMENT);
|
|
93
|
+
const taken = `${enrolment}.${process.pid}`;
|
|
94
|
+
try {
|
|
95
|
+
renameSync(enrolment, taken);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error.code === 'ENOENT')
|
|
99
|
+
return;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
if (JSON.parse(readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
103
|
+
try {
|
|
104
|
+
linkSync(taken, enrolment);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error.code !== 'EEXIST')
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
rmSync(join(kitHome(), DISCONNECTED), { force: true });
|
|
111
|
+
}
|
|
112
|
+
rmSync(taken);
|
|
113
|
+
}
|
|
49
114
|
export function enrolled() {
|
|
50
115
|
return existsSync(join(kitHome(), ENROLMENT));
|
|
51
116
|
}
|
|
117
|
+
export function restartAsked() {
|
|
118
|
+
return existsSync(join(kitHome(), RESTART));
|
|
119
|
+
}
|
|
120
|
+
export function forgetRestart() {
|
|
121
|
+
return rm(join(kitHome(), RESTART), { force: true });
|
|
122
|
+
}
|
|
52
123
|
export function readOwnAgent() {
|
|
53
124
|
return readHome(OWN_AGENT);
|
|
54
125
|
}
|
package/dist/house-main.js
CHANGED
|
@@ -1,68 +1,105 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { request, setGlobalProxyFromEnv } from 'node:http';
|
|
5
|
-
import { basename, join } from 'node:path';
|
|
5
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
6
|
+
import { verified } from './files.js';
|
|
6
7
|
import { HOUSE_REF } from './git.js';
|
|
7
8
|
import { kitHome, readOwnAgent } from './home.js';
|
|
8
9
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
9
10
|
import { refusalOf } from './refusals.js';
|
|
10
|
-
import { relayed } from './relay.js';
|
|
11
|
-
import { parse } from 'yaml';
|
|
11
|
+
import { relayed, selectRelay } from './relay.js';
|
|
12
|
+
import { parse, stringify } from 'yaml';
|
|
12
13
|
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
13
14
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
14
15
|
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
15
16
|
const FETCH_USAGE = 'usage: house fetch';
|
|
16
17
|
const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
|
|
18
|
+
const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
|
|
19
|
+
const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
|
|
17
20
|
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
18
21
|
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
19
22
|
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
20
23
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
21
24
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
22
25
|
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
26
|
+
const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
|
|
23
27
|
const socketPath = process.env.HOUSE_BRIDGE;
|
|
24
|
-
|
|
28
|
+
const MEDIA_TYPES = new Map([
|
|
29
|
+
['avif', 'image/avif'],
|
|
30
|
+
['csv', 'text/csv'],
|
|
31
|
+
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
32
|
+
['gif', 'image/gif'],
|
|
33
|
+
['heic', 'image/heic'],
|
|
34
|
+
['html', 'text/html'],
|
|
35
|
+
['jpeg', 'image/jpeg'],
|
|
36
|
+
['jpg', 'image/jpeg'],
|
|
37
|
+
['json', 'application/json'],
|
|
38
|
+
['m4a', 'audio/mp4'],
|
|
39
|
+
['md', 'text/markdown'],
|
|
40
|
+
['mov', 'video/quicktime'],
|
|
41
|
+
['mp3', 'audio/mpeg'],
|
|
42
|
+
['mp4', 'video/mp4'],
|
|
43
|
+
['ogg', 'audio/ogg'],
|
|
44
|
+
['pdf', 'application/pdf'],
|
|
45
|
+
['png', 'image/png'],
|
|
46
|
+
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
47
|
+
['svg', 'image/svg+xml'],
|
|
48
|
+
['txt', 'text/plain'],
|
|
49
|
+
['wav', 'audio/wav'],
|
|
50
|
+
['webm', 'video/webm'],
|
|
51
|
+
['webp', 'image/webp'],
|
|
52
|
+
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
53
|
+
['zip', 'application/zip'],
|
|
54
|
+
]);
|
|
55
|
+
function refused(path, method, status, text, local) {
|
|
25
56
|
const refusal = refusalOf(text);
|
|
26
57
|
if (refusal !== null)
|
|
27
58
|
return refusal.text;
|
|
28
59
|
if (status === 401)
|
|
29
60
|
return REVOKED;
|
|
61
|
+
const act = method === 'GET' ? 'download' : 'upload';
|
|
30
62
|
if (URL.canParse(path))
|
|
31
|
-
return `the
|
|
32
|
-
if (status === 502 &&
|
|
63
|
+
return `the ${act} answered ${status}; ${act} the file again`;
|
|
64
|
+
if (status === 502 && local)
|
|
33
65
|
return text;
|
|
34
|
-
return `${path} answered ${status}`;
|
|
66
|
+
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
35
67
|
}
|
|
36
|
-
function
|
|
68
|
+
function unconfirmed(status) {
|
|
69
|
+
return `House answered ${status} ${UNCONFIRMED}`;
|
|
70
|
+
}
|
|
71
|
+
function exchanged(path, method, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
37
72
|
return new Promise((resolve, reject) => {
|
|
38
|
-
const sent = request({ socketPath: to, path, method
|
|
39
|
-
|
|
40
|
-
answer.
|
|
41
|
-
answer.on('data', (chunk) => {
|
|
42
|
-
text += chunk;
|
|
43
|
-
});
|
|
73
|
+
const sent = request({ socketPath: to, path, method, headers }, (answer) => {
|
|
74
|
+
const chunks = [];
|
|
75
|
+
answer.on('data', (chunk) => chunks.push(chunk));
|
|
44
76
|
answer.on('end', () => {
|
|
77
|
+
const bytes = Buffer.concat(chunks);
|
|
45
78
|
if (answer.statusCode === 200)
|
|
46
|
-
resolve(
|
|
79
|
+
resolve(bytes);
|
|
47
80
|
else
|
|
48
|
-
reject(new Error(refused(path, answer.statusCode,
|
|
81
|
+
reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
|
|
49
82
|
});
|
|
50
83
|
});
|
|
51
84
|
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
52
|
-
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
85
|
+
sent.end(body === undefined ? undefined : body instanceof Buffer ? body : JSON.stringify(body));
|
|
53
86
|
});
|
|
54
87
|
}
|
|
88
|
+
async function bridged(path, body, headers, to = socketPath) {
|
|
89
|
+
return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
|
|
90
|
+
}
|
|
55
91
|
async function direct(message) {
|
|
56
92
|
const ownAgent = await readOwnAgent();
|
|
57
93
|
if (ownAgent === null)
|
|
58
94
|
throw new Error(UNCONNECTED);
|
|
95
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
|
|
59
96
|
setGlobalProxyFromEnv();
|
|
60
97
|
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
61
98
|
throw new Error(UNREACHABLE);
|
|
62
99
|
});
|
|
63
100
|
if (answer.status === 200)
|
|
64
101
|
return answer.text;
|
|
65
|
-
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ??
|
|
102
|
+
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? unconfirmed(answer.status)));
|
|
66
103
|
}
|
|
67
104
|
async function mcp(method, params) {
|
|
68
105
|
const message = rpc(method, params);
|
|
@@ -84,41 +121,102 @@ async function localFile(path) {
|
|
|
84
121
|
: `${path} is not a readable file`);
|
|
85
122
|
}
|
|
86
123
|
}
|
|
87
|
-
async function
|
|
88
|
-
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
124
|
+
async function transferred(url, method, bytes, headers) {
|
|
89
125
|
if (socketPath !== undefined)
|
|
90
|
-
return
|
|
126
|
+
return exchanged(url, method, bytes, headers);
|
|
91
127
|
setGlobalProxyFromEnv();
|
|
92
|
-
const answer = await fetch(relayed(url), { method:
|
|
128
|
+
const answer = await fetch(relayed(url), { method, ...(headers === undefined ? {} : { headers }), ...(bytes === undefined ? {} : { body: bytes }) }).catch(() => {
|
|
93
129
|
throw new Error(UNREACHABLE);
|
|
94
130
|
});
|
|
95
|
-
const
|
|
131
|
+
const received = Buffer.from(await answer.arrayBuffer());
|
|
96
132
|
if (answer.status === 200)
|
|
97
|
-
return
|
|
98
|
-
throw new Error(refused(url, answer.status,
|
|
99
|
-
}
|
|
100
|
-
async function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
133
|
+
return received;
|
|
134
|
+
throw new Error(refused(url, method, answer.status, received.toString('utf8'), false));
|
|
135
|
+
}
|
|
136
|
+
async function sent(url, bytes, operation) {
|
|
137
|
+
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
138
|
+
return (await transferred(url, 'POST', bytes, headers)).toString('utf8');
|
|
139
|
+
}
|
|
140
|
+
async function download(args) {
|
|
141
|
+
const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
|
|
142
|
+
if (flags.has('--help'))
|
|
143
|
+
return DOWNLOAD_USAGE;
|
|
144
|
+
const { file, ...selected } = argumentsOf(argument);
|
|
145
|
+
if (typeof file !== 'string' || file === '')
|
|
146
|
+
throw new Error('download needs "file", the local file to write');
|
|
147
|
+
const inspected = parse(await called('inspect', selected));
|
|
148
|
+
if (typeof inspected?.download !== 'string')
|
|
149
|
+
throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
|
|
150
|
+
const bytes = verified(await transferred(inspected.download, 'GET'), String(inspected.sha256), String(selected.path));
|
|
151
|
+
const written = resolve(file);
|
|
152
|
+
await mkdir(dirname(written), { recursive: true });
|
|
153
|
+
await writeFile(written, bytes);
|
|
154
|
+
return written;
|
|
155
|
+
}
|
|
156
|
+
async function described(file) {
|
|
157
|
+
const bytes = await localFile(file);
|
|
158
|
+
const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
|
|
159
|
+
return {
|
|
160
|
+
bytes,
|
|
161
|
+
description: {
|
|
162
|
+
bytes: bytes.length,
|
|
163
|
+
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
164
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function upload({ file, ...destination }) {
|
|
169
|
+
if (typeof file !== 'string' || file === '')
|
|
170
|
+
throw new Error('upload needs "file", a local file');
|
|
171
|
+
const { bytes, description } = await described(file);
|
|
172
|
+
const answer = await called('upload', { ...destination, ...description });
|
|
173
|
+
const declared = parse(answer);
|
|
110
174
|
if (declared.upload === undefined)
|
|
111
|
-
return
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
175
|
+
return answer;
|
|
176
|
+
const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
|
|
177
|
+
return stringify(written, { lineWidth: 0 }).trimEnd();
|
|
178
|
+
}
|
|
179
|
+
async function appendRecord(args) {
|
|
180
|
+
const held = new Map();
|
|
181
|
+
const attachments = Array.isArray(args.attachments)
|
|
182
|
+
? await Promise.all(args.attachments.map(async (attachment) => {
|
|
183
|
+
if (typeof attachment !== 'string')
|
|
184
|
+
return attachment;
|
|
185
|
+
const { bytes, description } = await described(attachment);
|
|
186
|
+
held.set(description.sha256, bytes);
|
|
187
|
+
return { name: basename(attachment), ...description };
|
|
188
|
+
}))
|
|
189
|
+
: args.attachments;
|
|
190
|
+
const record = { ...args, attachments };
|
|
191
|
+
for (;;) {
|
|
192
|
+
const answer = await called('append_record', record);
|
|
193
|
+
const { upload } = parse(answer);
|
|
194
|
+
if (upload === undefined)
|
|
195
|
+
return answer;
|
|
196
|
+
for (const grant of upload)
|
|
197
|
+
await sent(grant.url, held.get(grant.sha256), grant.operation);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function unexpected(argument, usage) {
|
|
201
|
+
return new Error(`unexpected argument ${argument}; ${usage}`);
|
|
202
|
+
}
|
|
203
|
+
function accepted(args, flags, positionals, usage) {
|
|
204
|
+
const given = { flags: new Set(), positionals: [] };
|
|
205
|
+
for (const arg of args) {
|
|
206
|
+
if (flags.includes(arg))
|
|
207
|
+
given.flags.add(arg);
|
|
208
|
+
else if (!arg.startsWith('-') && given.positionals.length < positionals)
|
|
209
|
+
given.positionals.push(arg);
|
|
210
|
+
else
|
|
211
|
+
throw unexpected(arg, usage);
|
|
212
|
+
}
|
|
213
|
+
return given;
|
|
116
214
|
}
|
|
117
215
|
async function push(args) {
|
|
118
|
-
|
|
216
|
+
const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
|
|
217
|
+
if (flags.has('--help'))
|
|
119
218
|
return PUSH_USAGE;
|
|
120
|
-
const owner =
|
|
121
|
-
const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
219
|
+
const owner = flags.has('--owner');
|
|
122
220
|
if (owner && socketPath !== undefined)
|
|
123
221
|
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
124
222
|
if (!owner && socketPath === undefined)
|
|
@@ -129,7 +227,7 @@ async function push(args) {
|
|
|
129
227
|
return pushed.text;
|
|
130
228
|
}
|
|
131
229
|
async function fetched(args) {
|
|
132
|
-
if (args.
|
|
230
|
+
if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
|
|
133
231
|
return FETCH_USAGE;
|
|
134
232
|
const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
|
|
135
233
|
if (answer.refused)
|
|
@@ -150,28 +248,23 @@ function argumentsOf(argument) {
|
|
|
150
248
|
throw new Error(ARGUMENTS);
|
|
151
249
|
return parsed;
|
|
152
250
|
}
|
|
153
|
-
async function house(
|
|
154
|
-
|
|
155
|
-
|
|
251
|
+
async function house(args) {
|
|
252
|
+
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
253
|
+
if (verb === 'help' && argument !== undefined)
|
|
254
|
+
throw unexpected(argument, USAGE);
|
|
255
|
+
if (flags.has('--help') && argument !== undefined)
|
|
256
|
+
throw unexpected('--help', USAGE);
|
|
257
|
+
if (verb === undefined || verb === 'help') {
|
|
258
|
+
return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
156
259
|
}
|
|
157
|
-
if (
|
|
260
|
+
if (flags.has('--help')) {
|
|
158
261
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
159
262
|
if (tool === undefined)
|
|
160
263
|
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
161
264
|
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
162
265
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload needs "path", a local file') });
|
|
166
|
-
}
|
|
167
|
-
if (verb === 'append_record' && Array.isArray(args.attachments)) {
|
|
168
|
-
const attachments = [];
|
|
169
|
-
for (const path of args.attachments) {
|
|
170
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
171
|
-
}
|
|
172
|
-
args.attachments = attachments;
|
|
173
|
-
}
|
|
174
|
-
return called(verb, args);
|
|
266
|
+
const parsed = argumentsOf(argument);
|
|
267
|
+
return verb === 'upload' ? upload(parsed) : verb === 'append_record' ? appendRecord(parsed) : called(verb, parsed);
|
|
175
268
|
}
|
|
176
269
|
async function called(name, args) {
|
|
177
270
|
const result = await mcp('tools/call', { name, arguments: args });
|
|
@@ -181,7 +274,15 @@ async function called(name, args) {
|
|
|
181
274
|
return text;
|
|
182
275
|
}
|
|
183
276
|
const argv = process.argv.slice(2);
|
|
184
|
-
|
|
277
|
+
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
278
|
+
const rest = argv.filter((_arg, index) => index !== named);
|
|
279
|
+
(argv[named] === 'push'
|
|
280
|
+
? push(rest)
|
|
281
|
+
: argv[named] === 'fetch'
|
|
282
|
+
? fetched(rest)
|
|
283
|
+
: argv[named] === 'download'
|
|
284
|
+
? download(rest)
|
|
285
|
+
: house(argv)).then((text) => {
|
|
185
286
|
process.stdout.write(`${text}\n`);
|
|
186
287
|
if (argv[0] === 'shell')
|
|
187
288
|
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
package/dist/instructions.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { HOUSE_REF } from './git.js';
|
|
2
2
|
import { HOW_WE_WORK } from './skills.js';
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const SOURCE_LINE = "From House:";
|
|
4
|
+
const HOUSE_LINE = "Work with House through the `house` CLI: run `house --help`, and `house find_command` for House's guides and formats.";
|
|
5
|
+
const FILE_LINE = 'To give the User a file, upload it with `house upload` and link it; for an App, a Site or a website, follow `house find_command \'{"query":"app"}\'`. Never start a server.';
|
|
6
|
+
const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
|
|
6
7
|
const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
|
|
7
8
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
8
9
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
@@ -30,6 +31,6 @@ async function howWeWork(bridge) {
|
|
|
30
31
|
return document.replace(/\n$/, '');
|
|
31
32
|
}
|
|
32
33
|
export async function instructions(bridge, base, copies) {
|
|
33
|
-
const lines = [HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
34
|
+
const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
34
35
|
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
35
36
|
}
|
package/dist/kit-main.js
CHANGED
|
@@ -1,22 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setGlobalProxyFromEnv } from 'node:http';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
3
4
|
import { answerGitCredential } from './app-git.js';
|
|
5
|
+
import { chatgpt } from './chatgpt.js';
|
|
4
6
|
import { login } from './login.js';
|
|
5
7
|
import { logout } from './logout.js';
|
|
6
8
|
import { resident } from './resident.js';
|
|
9
|
+
const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
|
|
10
|
+
const COMMANDS = new Map([
|
|
11
|
+
[
|
|
12
|
+
'logout',
|
|
13
|
+
{
|
|
14
|
+
usage: 'usage: kit logout',
|
|
15
|
+
about: "disconnects this computer, stops House Kit and ends your own agent's connection",
|
|
16
|
+
operands: 0,
|
|
17
|
+
run: logout,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
'resident',
|
|
22
|
+
{
|
|
23
|
+
usage: 'usage: kit resident',
|
|
24
|
+
about: "keeps this Environment connected; House Kit's service runs it",
|
|
25
|
+
operands: 0,
|
|
26
|
+
run: resident,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
'git-credential',
|
|
31
|
+
{
|
|
32
|
+
usage: 'usage: kit git-credential <get|store|erase>',
|
|
33
|
+
about: "answers git with your own agent's House credential; git runs it",
|
|
34
|
+
operands: 1,
|
|
35
|
+
run: ([operation]) => answerGitCredential(operation),
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
]);
|
|
7
39
|
const [command, ...argv] = process.argv.slice(2);
|
|
8
40
|
setGlobalProxyFromEnv();
|
|
9
41
|
async function run() {
|
|
10
42
|
if (command === 'login')
|
|
11
43
|
return login(argv);
|
|
12
|
-
if (command === '
|
|
13
|
-
return
|
|
14
|
-
if (command === '
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
44
|
+
if (command === 'chatgpt')
|
|
45
|
+
return chatgpt(argv);
|
|
46
|
+
if (command === '--help') {
|
|
47
|
+
parseArgs({ args: argv });
|
|
48
|
+
process.stdout.write(USAGE);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const chosen = COMMANDS.get(command ?? '');
|
|
52
|
+
if (chosen === undefined) {
|
|
53
|
+
process.stderr.write(USAGE);
|
|
54
|
+
process.exitCode = 2;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
|
|
58
|
+
if (positionals.length > chosen.operands)
|
|
59
|
+
throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
|
|
60
|
+
if (values.help) {
|
|
61
|
+
process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return chosen.run(positionals);
|
|
20
65
|
}
|
|
21
66
|
run().catch((error) => {
|
|
22
67
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|