@agentshouse/kit 0.2.1-ce145e9aadbf6 → 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.
- package/README.md +46 -49
- package/dist/acp.js +101 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +252 -73
- package/dist/api.js +43 -6
- package/dist/app-git.js +48 -0
- package/dist/binaries.js +79 -0
- package/dist/bridge.js +62 -79
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +171 -102
- package/dist/codex-main.js +58 -0
- package/dist/connect.js +108 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +816 -335
- package/dist/copies.js +842 -309
- package/dist/earlier.js +263 -0
- package/dist/end.js +26 -0
- package/dist/events.js +793 -0
- package/dist/files.js +206 -18
- package/dist/git-main.js +24 -29
- package/dist/git.js +95 -18
- package/dist/grok.js +39 -0
- package/dist/home.js +134 -9
- package/dist/house-cli.js +282 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +7 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +133 -104
- package/dist/logout.js +15 -14
- package/dist/mcp.js +42 -3
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +43 -15
- package/dist/relay.js +33 -2
- package/dist/resident.js +161 -61
- package/dist/scope.js +214 -0
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +4 -3
- package/dist/settings.js +188 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +85 -33
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +131 -40
- package/dist/translate.js +19 -16
- package/dist/update.js +119 -100
- package/dist/wire.js +32 -0
- package/dist/work.js +353 -0
- package/dist/workspace.js +103 -0
- package/package.json +26 -21
- package/dist/authority-main.js +0 -22
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -4
- package/dist/stream.js +0 -47
- 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
package/dist/home.js
CHANGED
|
@@ -1,39 +1,118 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { chmodSync, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync } from 'node:fs';
|
|
2
3
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { selectRelay } from './relay.js';
|
|
5
7
|
const ENROLMENT = 'credential.json';
|
|
6
8
|
const DISCONNECTED = 'disconnected.json';
|
|
7
9
|
const CONFIGURATION = 'kit.json';
|
|
8
10
|
const OWN_AGENT = 'own-agent.json';
|
|
11
|
+
const EARLIER_PREFIXES = ['/kit-home/kit', '/opt/house-kit'];
|
|
12
|
+
function privateDirectory(path) {
|
|
13
|
+
try {
|
|
14
|
+
mkdirSync(path, { mode: 0o700 });
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code !== 'EEXIST')
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
const found = lstatSync(path);
|
|
21
|
+
if (found.isSymbolicLink())
|
|
22
|
+
throw new Error(`${path} is a symbolic link`);
|
|
23
|
+
if (!found.isDirectory())
|
|
24
|
+
throw new Error(`${path} is not a directory`);
|
|
25
|
+
if (found.uid !== process.geteuid())
|
|
26
|
+
throw new Error(`${path} is not owned by this User`);
|
|
27
|
+
chmodSync(path, 0o700);
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
export function oneFolder(account = homedir()) {
|
|
31
|
+
return join(account, '.agents', 'house');
|
|
32
|
+
}
|
|
33
|
+
export function desktopPrefix() {
|
|
34
|
+
return join(homedir(), '.local', 'share', 'house-kit');
|
|
35
|
+
}
|
|
36
|
+
export function earlierPrefix() {
|
|
37
|
+
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
38
|
+
if (prefix === undefined || prefix === '')
|
|
39
|
+
return null;
|
|
40
|
+
return [...EARLIER_PREFIXES, desktopPrefix()].includes(resolve(prefix)) ? resolve(prefix) : null;
|
|
41
|
+
}
|
|
42
|
+
export function awaitsTakeover() {
|
|
43
|
+
const prefix = earlierPrefix();
|
|
44
|
+
return prefix === EARLIER_PREFIXES[0] || (prefix === EARLIER_PREFIXES[1] && process.getuid() !== 0);
|
|
45
|
+
}
|
|
46
|
+
export function earlierHome() {
|
|
47
|
+
return process.env.HOUSE_KIT_HOME || join(homedir(), '.house-kit');
|
|
48
|
+
}
|
|
49
|
+
export function reinstall() {
|
|
50
|
+
if (!awaitsTakeover())
|
|
51
|
+
return undefined;
|
|
52
|
+
try {
|
|
53
|
+
return readFileSync(join(earlierHome(), 'placement'), 'utf8').trim() === 'windows' ? 'windows' : 'linux';
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT')
|
|
57
|
+
return 'linux';
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
9
61
|
export function kitHome() {
|
|
10
|
-
return
|
|
62
|
+
return earlierPrefix() === null ? oneFolder() : earlierHome();
|
|
63
|
+
}
|
|
64
|
+
export function socketDirectory() {
|
|
65
|
+
const sockets = privateDirectory(join(realpathSync('/tmp'), `hk-${process.geteuid()}`));
|
|
66
|
+
const home = kitHome();
|
|
67
|
+
const physical = existsSync(home) ? realpathSync(home) : resolve(home);
|
|
68
|
+
return privateDirectory(join(sockets, createHash('sha256').update(physical).digest('hex').slice(0, 12)));
|
|
69
|
+
}
|
|
70
|
+
export function ownerSocket() {
|
|
71
|
+
return join(socketDirectory(), 'owner.sock');
|
|
72
|
+
}
|
|
73
|
+
export function ownerLock() {
|
|
74
|
+
return join(socketDirectory(), 'owner.lock');
|
|
11
75
|
}
|
|
12
76
|
export function workspaceRoot() {
|
|
13
|
-
|
|
77
|
+
if (earlierPrefix() !== null)
|
|
78
|
+
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
|
79
|
+
return configuredWorkspace() ?? kitHome();
|
|
14
80
|
}
|
|
15
81
|
export function agentBase() {
|
|
16
82
|
return join(workspaceRoot(), 'agents');
|
|
17
83
|
}
|
|
84
|
+
function parsed(name, text) {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
throw new Error(`${name} in Kit home holds no JSON`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
18
92
|
export async function readHome(name) {
|
|
93
|
+
let text;
|
|
19
94
|
try {
|
|
20
|
-
|
|
95
|
+
text = await readFile(join(kitHome(), name), 'utf8');
|
|
21
96
|
}
|
|
22
97
|
catch (error) {
|
|
23
98
|
if (error.code === 'ENOENT')
|
|
24
99
|
return null;
|
|
25
100
|
throw error;
|
|
26
101
|
}
|
|
102
|
+
return parsed(name, text);
|
|
27
103
|
}
|
|
28
104
|
export async function writeHome(name, value) {
|
|
29
105
|
const home = kitHome();
|
|
30
106
|
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
31
|
-
const temporary = join(home, `${name}.${
|
|
107
|
+
const temporary = join(home, `${name}.${randomUUID()}`);
|
|
32
108
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
33
109
|
await rename(temporary, join(home, name));
|
|
34
110
|
}
|
|
35
|
-
export function readEnrolment() {
|
|
36
|
-
|
|
111
|
+
export async function readEnrolment() {
|
|
112
|
+
const enrolment = await readHome(ENROLMENT);
|
|
113
|
+
if (enrolment !== null)
|
|
114
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || enrolment.relay);
|
|
115
|
+
return enrolment;
|
|
37
116
|
}
|
|
38
117
|
export async function writeEnrolment(enrolment) {
|
|
39
118
|
await writeHome(ENROLMENT, enrolment);
|
|
@@ -42,10 +121,40 @@ export async function writeEnrolment(enrolment) {
|
|
|
42
121
|
export function readDisconnected() {
|
|
43
122
|
return readHome(DISCONNECTED);
|
|
44
123
|
}
|
|
124
|
+
export function forgetDisconnected() {
|
|
125
|
+
return rm(join(kitHome(), DISCONNECTED), { force: true });
|
|
126
|
+
}
|
|
45
127
|
export async function forgetEnrolment({ house, environment }) {
|
|
46
128
|
await writeHome(DISCONNECTED, { house, environment });
|
|
47
129
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
48
130
|
}
|
|
131
|
+
export async function forgetRejected(rejected) {
|
|
132
|
+
const held = await readHome(ENROLMENT);
|
|
133
|
+
if (held?.credential !== rejected)
|
|
134
|
+
return;
|
|
135
|
+
await writeHome(DISCONNECTED, { house: held.house, environment: held.environment });
|
|
136
|
+
const enrolment = join(kitHome(), ENROLMENT);
|
|
137
|
+
const taken = `${enrolment}.${process.pid}`;
|
|
138
|
+
try {
|
|
139
|
+
renameSync(enrolment, taken);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error.code === 'ENOENT')
|
|
143
|
+
return;
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
if (parsed(ENROLMENT, readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
147
|
+
try {
|
|
148
|
+
linkSync(taken, enrolment);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (error.code !== 'EEXIST')
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
rmSync(join(kitHome(), DISCONNECTED), { force: true });
|
|
155
|
+
}
|
|
156
|
+
rmSync(taken);
|
|
157
|
+
}
|
|
49
158
|
export function enrolled() {
|
|
50
159
|
return existsSync(join(kitHome(), ENROLMENT));
|
|
51
160
|
}
|
|
@@ -58,8 +167,24 @@ export function writeOwnAgent(ownAgent) {
|
|
|
58
167
|
export function forgetOwnAgent() {
|
|
59
168
|
return rm(join(kitHome(), OWN_AGENT), { force: true });
|
|
60
169
|
}
|
|
170
|
+
function configuredWorkspace() {
|
|
171
|
+
let text;
|
|
172
|
+
try {
|
|
173
|
+
text = readFileSync(join(kitHome(), CONFIGURATION), 'utf8');
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (error.code === 'ENOENT')
|
|
177
|
+
return undefined;
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
return parsed(CONFIGURATION, text).workspace;
|
|
181
|
+
}
|
|
61
182
|
export async function readConfiguration() {
|
|
62
|
-
|
|
183
|
+
const stored = await readHome(CONFIGURATION);
|
|
184
|
+
return { skills: stored?.skills !== false, workspace: stored?.workspace ?? kitHome() };
|
|
185
|
+
}
|
|
186
|
+
export async function storedConfiguration() {
|
|
187
|
+
return (await readHome(CONFIGURATION)) ?? {};
|
|
63
188
|
}
|
|
64
189
|
export function writeConfiguration(configuration) {
|
|
65
190
|
return writeHome(CONFIGURATION, configuration);
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { request } from 'node:http';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { text as textOf } from 'node:stream/consumers';
|
|
6
|
+
import { downloaded, fileInfo, fileRange, mediaTypeOf, opened, sentPart, storeRefusal, uploaded, } from './files.js';
|
|
7
|
+
import { HOUSE_REF } from './git.js';
|
|
8
|
+
import { ownerSocket } from './home.js';
|
|
9
|
+
import { ownAgentCall, rpc, unconfirmed, UNREACHABLE } from './mcp.js';
|
|
10
|
+
import { refusalOf } from './refusals.js';
|
|
11
|
+
import { parse } from 'yaml';
|
|
12
|
+
const USAGE = "usage: house <tool> ['<arguments as JSON>'], or house <tool> - to read them from stdin; house help <tool>: its arguments";
|
|
13
|
+
const HELP = 'help [tool]';
|
|
14
|
+
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
15
|
+
const PUSH = "push [commit]: sends the Local copy's committed changes to House; one commit and one push carry text and binary files alike";
|
|
16
|
+
const FETCH_USAGE = 'usage: house fetch';
|
|
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';
|
|
20
|
+
const UPLOAD_USAGE = `usage: house upload '{"file":"<local file>","room_ref":"r_…","path":"<path in the Room>"}', adding "base", the revision it replaces`;
|
|
21
|
+
const ARGUMENTS = `the arguments are one JSON object, in single quotes or on stdin after -, like house search '{"query":"invoice"}'`;
|
|
22
|
+
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
23
|
+
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
24
|
+
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
25
|
+
const socketPath = process.env.HOUSE_BRIDGE;
|
|
26
|
+
const WAY = {
|
|
27
|
+
...(socketPath === undefined ? {} : { socketPath }),
|
|
28
|
+
unreached: (error) => new Error(socketPath === undefined ? UNREACHABLE : error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED),
|
|
29
|
+
refused: (status) => storeRefusal('upload', status),
|
|
30
|
+
};
|
|
31
|
+
function refused(path, status, text, local) {
|
|
32
|
+
const refusal = refusalOf(text);
|
|
33
|
+
if (refusal !== null)
|
|
34
|
+
return refusal.text;
|
|
35
|
+
if (status === 401)
|
|
36
|
+
return REVOKED;
|
|
37
|
+
if (status === 502 && local)
|
|
38
|
+
return text;
|
|
39
|
+
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
40
|
+
}
|
|
41
|
+
function bridged(path, body, to = socketPath) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const sent = request({ socketPath: to, path, method: 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
|
|
44
|
+
const chunks = [];
|
|
45
|
+
answer.on('data', (chunk) => chunks.push(chunk));
|
|
46
|
+
answer.on('end', () => {
|
|
47
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
48
|
+
if (answer.statusCode === 200)
|
|
49
|
+
resolve(text);
|
|
50
|
+
else
|
|
51
|
+
reject(new Error(refused(path, answer.statusCode, text, answer.headers['content-type'] === undefined)));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
55
|
+
sent.end(JSON.stringify(body));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function mcp(method, params) {
|
|
59
|
+
const message = rpc(method, params);
|
|
60
|
+
const answer = JSON.parse(socketPath === undefined ? await ownAgentCall(message) : await bridged('/', message));
|
|
61
|
+
if (answer.error !== undefined)
|
|
62
|
+
throw new Error(answer.error.message);
|
|
63
|
+
return answer.result;
|
|
64
|
+
}
|
|
65
|
+
async function tools() {
|
|
66
|
+
return (await mcp('tools/list', {})).tools;
|
|
67
|
+
}
|
|
68
|
+
function unreadable(path, error) {
|
|
69
|
+
return new Error(error.code === 'EISDIR'
|
|
70
|
+
? `${path} is a folder; upload one file at a time`
|
|
71
|
+
: `${path} is not a readable file`);
|
|
72
|
+
}
|
|
73
|
+
async function download(args) {
|
|
74
|
+
const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
|
|
75
|
+
if (flags.has('--help'))
|
|
76
|
+
return DOWNLOAD_USAGE;
|
|
77
|
+
const { file, ...selected } = await argumentsOf(argument);
|
|
78
|
+
if (typeof file !== 'string' || file === '')
|
|
79
|
+
throw new Error('download needs "file", the local file to write');
|
|
80
|
+
const written = resolve(file);
|
|
81
|
+
await downloaded(async () => {
|
|
82
|
+
const file = fileInfo(await called('info', selected));
|
|
83
|
+
if (file === null)
|
|
84
|
+
throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
|
|
85
|
+
return file;
|
|
86
|
+
}, async (url) => {
|
|
87
|
+
const answer = await opened(url, 'GET', {}, WAY);
|
|
88
|
+
return { status: answer.statusCode, body: answer };
|
|
89
|
+
}, written, String(selected.path));
|
|
90
|
+
return written;
|
|
91
|
+
}
|
|
92
|
+
async function described(file) {
|
|
93
|
+
const digest = createHash('sha256');
|
|
94
|
+
let bytes = 0;
|
|
95
|
+
try {
|
|
96
|
+
for await (const chunk of createReadStream(file)) {
|
|
97
|
+
digest.update(chunk);
|
|
98
|
+
bytes += chunk.length;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw unreadable(file, error);
|
|
103
|
+
}
|
|
104
|
+
const mediaType = mediaTypeOf(file);
|
|
105
|
+
return { bytes, sha256: digest.digest('hex'), ...(mediaType === undefined ? {} : { media_type: mediaType }) };
|
|
106
|
+
}
|
|
107
|
+
async function finished(upload, room, partSha256) {
|
|
108
|
+
const text = await called('upload', { upload, room_ref: room, part_sha256: partSha256 });
|
|
109
|
+
const answer = parse(text);
|
|
110
|
+
return answer !== null && 'upload' in answer ? answer : { text };
|
|
111
|
+
}
|
|
112
|
+
async function upload({ file, ...destination }) {
|
|
113
|
+
if (typeof file !== 'string' || file === '')
|
|
114
|
+
throw new Error('upload needs "file", a local file');
|
|
115
|
+
const description = await described(file);
|
|
116
|
+
const answer = await called('upload', { ...destination, ...description });
|
|
117
|
+
const declared = parse(answer);
|
|
118
|
+
if (declared?.upload === undefined)
|
|
119
|
+
return answer;
|
|
120
|
+
const accepted = await uploaded(declared.upload, {
|
|
121
|
+
name: file,
|
|
122
|
+
bytes: description.bytes,
|
|
123
|
+
sha256: description.sha256,
|
|
124
|
+
read: (start, end) => fileRange(file, start, end, (error) => unreadable(file, error)),
|
|
125
|
+
send: (url, start, end, headers) => sentPart(url, file, start, end, headers, WAY),
|
|
126
|
+
finish: (id, partSha256) => finished(id, destination.room_ref, partSha256),
|
|
127
|
+
});
|
|
128
|
+
return accepted.text;
|
|
129
|
+
}
|
|
130
|
+
function unexpected(argument, usage) {
|
|
131
|
+
return new Error(`unexpected argument ${argument}; ${usage}`);
|
|
132
|
+
}
|
|
133
|
+
function accepted(args, flags, positionals, usage) {
|
|
134
|
+
const given = { flags: new Set(), positionals: [] };
|
|
135
|
+
for (const arg of args) {
|
|
136
|
+
if (flags.includes(arg))
|
|
137
|
+
given.flags.add(arg);
|
|
138
|
+
else if ((arg === '-' || !arg.startsWith('-')) && given.positionals.length < positionals)
|
|
139
|
+
given.positionals.push(arg);
|
|
140
|
+
else
|
|
141
|
+
throw unexpected(arg, usage);
|
|
142
|
+
}
|
|
143
|
+
return given;
|
|
144
|
+
}
|
|
145
|
+
async function push(args) {
|
|
146
|
+
const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
|
|
147
|
+
if (flags.has('--help'))
|
|
148
|
+
return `${PUSH_USAGE}\n${PUSH}`;
|
|
149
|
+
const owner = flags.has('--owner');
|
|
150
|
+
if (owner && socketPath !== undefined)
|
|
151
|
+
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
152
|
+
if (!owner && socketPath === undefined)
|
|
153
|
+
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
154
|
+
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, owner ? ownerSocket() : socketPath));
|
|
155
|
+
if (pushed.refused)
|
|
156
|
+
throw new Error(pushed.text);
|
|
157
|
+
return pushed.text;
|
|
158
|
+
}
|
|
159
|
+
async function fetched(args) {
|
|
160
|
+
if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
|
|
161
|
+
return FETCH_USAGE;
|
|
162
|
+
const answer = JSON.parse(await bridged('/git/fetch', {}, socketPath ?? ownerSocket()));
|
|
163
|
+
if (answer.refused)
|
|
164
|
+
throw new Error(answer.text);
|
|
165
|
+
return answer.text;
|
|
166
|
+
}
|
|
167
|
+
async function argumentsOf(argument) {
|
|
168
|
+
if (argument === undefined)
|
|
169
|
+
return {};
|
|
170
|
+
const given = argument === '-' ? await textOf(process.stdin) : argument;
|
|
171
|
+
let parsed;
|
|
172
|
+
try {
|
|
173
|
+
parsed = JSON.parse(given);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
throw new Error(ARGUMENTS);
|
|
177
|
+
}
|
|
178
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
179
|
+
throw new Error(ARGUMENTS);
|
|
180
|
+
return parsed;
|
|
181
|
+
}
|
|
182
|
+
// The schema a $ref points to inside the Tool's own inputSchema, or an empty one when it points elsewhere.
|
|
183
|
+
function resolved(schema, root) {
|
|
184
|
+
if (schema.$ref === undefined)
|
|
185
|
+
return schema;
|
|
186
|
+
if (!schema.$ref.startsWith('#'))
|
|
187
|
+
return {};
|
|
188
|
+
let found = root;
|
|
189
|
+
for (const key of schema.$ref.split('/').slice(1)) {
|
|
190
|
+
found = typeof found === 'object' && found !== null ? found[key.replaceAll('~1', '/').replaceAll('~0', '~')] : undefined;
|
|
191
|
+
}
|
|
192
|
+
return typeof found === 'object' && found !== null ? found : {};
|
|
193
|
+
}
|
|
194
|
+
// The schema a $ref resolves to, with that $ref added to the open ones, or null when it is open already,
|
|
195
|
+
// so a schema that holds itself is expanded once.
|
|
196
|
+
function expanded(schema, root, refs) {
|
|
197
|
+
if (schema.$ref === undefined)
|
|
198
|
+
return { schema, refs };
|
|
199
|
+
return refs.has(schema.$ref) ? null : { schema: resolved(schema, root), refs: new Set([...refs, schema.$ref]) };
|
|
200
|
+
}
|
|
201
|
+
// One line per argument: its name, its value when it has one or a few, whether it is required, and its
|
|
202
|
+
// description. When deep, the arguments its value holds follow it.
|
|
203
|
+
function argumentLines(schema, root, indent, deep, refs = new Set()) {
|
|
204
|
+
const required = new Set(schema.required ?? []);
|
|
205
|
+
return Object.entries(schema.properties ?? {}).flatMap(([name, property]) => {
|
|
206
|
+
const value = resolved(property, root);
|
|
207
|
+
const values = value.const !== undefined ? [value.const] : (value.enum ?? []);
|
|
208
|
+
const words = [name, ...(values.length === 0 ? [] : [values.map((one) => JSON.stringify(one)).join(' | ')]), ...(required.has(name) ? ['(required)'] : [])];
|
|
209
|
+
const description = property.description ?? value.description;
|
|
210
|
+
const line = `${indent}${words.join(' ')}${description === undefined ? '' : `: ${description}`}`;
|
|
211
|
+
return deep ? [line, ...held(property, root, `${indent} `, refs)] : [line];
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// The arguments a value holds: its own, its items', and those of each alternative of a oneOf or anyOf,
|
|
215
|
+
// each alternative a "- " entry when more than one has arguments.
|
|
216
|
+
function held(schema, root, indent, refs) {
|
|
217
|
+
const value = expanded(schema, root, refs);
|
|
218
|
+
if (value === null)
|
|
219
|
+
return [];
|
|
220
|
+
const alternatives = (value.schema.oneOf ?? value.schema.anyOf ?? [])
|
|
221
|
+
.map((alternative) => held(alternative, root, indent, value.refs))
|
|
222
|
+
.filter((lines) => lines.length > 0);
|
|
223
|
+
return [
|
|
224
|
+
...argumentLines(value.schema, root, indent, true, value.refs),
|
|
225
|
+
...(value.schema.items === undefined ? [] : held(value.schema.items, root, indent, value.refs)),
|
|
226
|
+
...(alternatives.length === 1
|
|
227
|
+
? alternatives[0]
|
|
228
|
+
: alternatives.flatMap((lines) => lines.map((line, index) => (index === 0 ? `${indent}- ${line.slice(indent.length)}` : ` ${line}`)))),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
function listed(tool) {
|
|
232
|
+
return tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`;
|
|
233
|
+
}
|
|
234
|
+
async function toolHelp(name) {
|
|
235
|
+
const tool = (await tools()).find((one) => one.name === name);
|
|
236
|
+
if (tool === undefined)
|
|
237
|
+
throw new Error(`${name} is no Tool; house find_command '{"query":"${name}"}' finds Commands`);
|
|
238
|
+
return [listed(tool), ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', true)].join('\n');
|
|
239
|
+
}
|
|
240
|
+
async function house(args) {
|
|
241
|
+
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
242
|
+
if (flags.has('--help') && argument !== undefined)
|
|
243
|
+
throw unexpected('--help', USAGE);
|
|
244
|
+
// house help <name> runs as house <name> --help, so both forms answer alike.
|
|
245
|
+
if (verb === 'help' && argument !== undefined)
|
|
246
|
+
return run([argument, '--help']);
|
|
247
|
+
if (verb === undefined || verb === 'help') {
|
|
248
|
+
const listing = (await tools()).flatMap((tool) => tool.description === undefined ? [tool.name, ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', false)] : [listed(tool)]);
|
|
249
|
+
return [USAGE, HELP, PUSH, FETCH, DOWNLOAD, ...listing].join('\n');
|
|
250
|
+
}
|
|
251
|
+
if (flags.has('--help'))
|
|
252
|
+
return verb === 'upload' ? UPLOAD_USAGE : toolHelp(verb);
|
|
253
|
+
const parsed = await argumentsOf(argument);
|
|
254
|
+
return verb === 'upload' ? upload(parsed) : called(verb, parsed);
|
|
255
|
+
}
|
|
256
|
+
async function called(name, args) {
|
|
257
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
258
|
+
const text = result.content.map((content) => content.text).join('\n');
|
|
259
|
+
if (result.isError === true)
|
|
260
|
+
throw new Error(text.replace(/\n+$/, ''));
|
|
261
|
+
return text;
|
|
262
|
+
}
|
|
263
|
+
function run(argv) {
|
|
264
|
+
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
265
|
+
const rest = argv.filter((_arg, index) => index !== named);
|
|
266
|
+
if (argv[named] === 'push')
|
|
267
|
+
return push(rest);
|
|
268
|
+
if (argv[named] === 'fetch')
|
|
269
|
+
return fetched(rest);
|
|
270
|
+
if (argv[named] === 'download')
|
|
271
|
+
return download(rest);
|
|
272
|
+
return house(argv);
|
|
273
|
+
}
|
|
274
|
+
const argv = process.argv.slice(2);
|
|
275
|
+
run(argv).then((text) => {
|
|
276
|
+
process.stdout.write(`${text}\n`);
|
|
277
|
+
if (argv[0] === 'shell')
|
|
278
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
279
|
+
}, (error) => {
|
|
280
|
+
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
281
|
+
process.exitCode = 1;
|
|
282
|
+
});
|
package/dist/house-main.js
CHANGED
|
@@ -1,162 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { kitHome, readOwnAgent } from './home.js';
|
|
7
|
-
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
8
|
-
import { refusalOf } from './refusals.js';
|
|
9
|
-
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
10
|
-
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
11
|
-
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
12
|
-
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
13
|
-
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
14
|
-
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
15
|
-
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
16
|
-
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
17
|
-
const socketPath = process.env.HOUSE_BRIDGE;
|
|
18
|
-
function refused(path, status, text) {
|
|
19
|
-
const refusal = refusalOf(text);
|
|
20
|
-
if (refusal !== null)
|
|
21
|
-
return refusal.text;
|
|
22
|
-
if (status === 401)
|
|
23
|
-
return REVOKED;
|
|
24
|
-
if (URL.canParse(path))
|
|
25
|
-
return `the upload answered ${status}; upload the file again`;
|
|
26
|
-
if (status === 502 && /^[A-Za-z]/.test(text))
|
|
27
|
-
return text;
|
|
28
|
-
return `${path} answered ${status}`;
|
|
29
|
-
}
|
|
30
|
-
function bridged(path, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
const sent = request({ socketPath: to, path, method: 'POST', headers }, (answer) => {
|
|
33
|
-
let text = '';
|
|
34
|
-
answer.setEncoding('utf8');
|
|
35
|
-
answer.on('data', (chunk) => {
|
|
36
|
-
text += chunk;
|
|
37
|
-
});
|
|
38
|
-
answer.on('end', () => {
|
|
39
|
-
if (answer.statusCode === 200)
|
|
40
|
-
resolve(text);
|
|
41
|
-
else
|
|
42
|
-
reject(new Error(refused(path, answer.statusCode, text)));
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
sent.on('error', () => reject(new Error(CLOSED)));
|
|
46
|
-
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async function direct(message) {
|
|
50
|
-
const ownAgent = await readOwnAgent();
|
|
51
|
-
if (ownAgent === null)
|
|
52
|
-
throw new Error(UNCONNECTED);
|
|
53
|
-
setGlobalProxyFromEnv();
|
|
54
|
-
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
55
|
-
throw new Error(UNREACHABLE);
|
|
56
|
-
});
|
|
57
|
-
if (answer.status === 200)
|
|
58
|
-
return answer.text;
|
|
59
|
-
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? `House answered ${answer.status}`));
|
|
60
|
-
}
|
|
61
|
-
async function mcp(method, params) {
|
|
62
|
-
const message = rpc(method, params);
|
|
63
|
-
const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
|
|
64
|
-
if (answer.error !== undefined)
|
|
65
|
-
throw new Error(answer.error.message);
|
|
66
|
-
return answer.result;
|
|
67
|
-
}
|
|
68
|
-
async function tools() {
|
|
69
|
-
return (await mcp('tools/list', {})).tools;
|
|
70
|
-
}
|
|
71
|
-
async function localFile(path) {
|
|
72
|
-
try {
|
|
73
|
-
return await readFile(path);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
throw new Error(error.code === 'EISDIR'
|
|
77
|
-
? `${path} is a folder; upload one file at a time`
|
|
78
|
-
: `${path} is not a readable file`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async function upload(path, roomRef, missing) {
|
|
82
|
-
if (typeof path !== 'string' || path === '')
|
|
83
|
-
throw new Error(missing);
|
|
84
|
-
const bytes = await localFile(path);
|
|
85
|
-
const declared = JSON.parse(await bridged('/kit/attachments/upload', {
|
|
86
|
-
...(roomRef === undefined ? {} : { room_ref: roomRef }),
|
|
87
|
-
name: basename(path),
|
|
88
|
-
bytes: bytes.length,
|
|
89
|
-
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
90
|
-
}));
|
|
91
|
-
if (declared.upload === undefined)
|
|
92
|
-
return declared.attachment;
|
|
93
|
-
const saved = JSON.parse(await bridged(declared.upload.url, bytes, {
|
|
94
|
-
'content-type': 'application/octet-stream',
|
|
95
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
96
|
-
}));
|
|
97
|
-
if (saved.upload_failure !== undefined)
|
|
98
|
-
throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
|
|
99
|
-
return saved.attachment;
|
|
100
|
-
}
|
|
101
|
-
async function push(args) {
|
|
102
|
-
if (args.includes('--help'))
|
|
103
|
-
return PUSH_USAGE;
|
|
104
|
-
const owner = args.includes('--owner');
|
|
105
|
-
const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
106
|
-
if (owner && socketPath !== undefined)
|
|
107
|
-
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
108
|
-
if (!owner && socketPath === undefined)
|
|
109
|
-
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
110
|
-
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
111
|
-
if (pushed.refused)
|
|
112
|
-
throw new Error(pushed.text);
|
|
113
|
-
return pushed.text;
|
|
114
|
-
}
|
|
115
|
-
function argumentsOf(argument) {
|
|
116
|
-
if (argument === undefined)
|
|
117
|
-
return {};
|
|
118
|
-
let parsed;
|
|
119
|
-
try {
|
|
120
|
-
parsed = JSON.parse(argument);
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
throw new Error(ARGUMENTS);
|
|
124
|
-
}
|
|
125
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
126
|
-
throw new Error(ARGUMENTS);
|
|
127
|
-
return parsed;
|
|
2
|
+
const [major = 0, minor = 0, patch = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
|
|
4
|
+
process.stderr.write(`house: the Kit needs Node 24.22.1 or newer; this is ${process.versions.node}\n`);
|
|
5
|
+
process.exitCode = 1;
|
|
128
6
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
132
|
-
}
|
|
133
|
-
if (argument === '--help') {
|
|
134
|
-
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
135
|
-
if (tool === undefined)
|
|
136
|
-
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
137
|
-
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
138
|
-
}
|
|
139
|
-
const args = argumentsOf(argument);
|
|
140
|
-
if (socketPath !== undefined && verb === 'upload_attachment') {
|
|
141
|
-
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload_attachment needs "path", a local file') });
|
|
142
|
-
}
|
|
143
|
-
if (socketPath !== undefined && verb === 'append_record' && Array.isArray(args.attachments)) {
|
|
144
|
-
const attachments = [];
|
|
145
|
-
for (const path of args.attachments) {
|
|
146
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
147
|
-
}
|
|
148
|
-
args.attachments = attachments;
|
|
149
|
-
}
|
|
150
|
-
const result = await mcp('tools/call', { name: verb, arguments: args });
|
|
151
|
-
const text = result.content.map((content) => content.text).join('\n');
|
|
152
|
-
if (result.isError === true)
|
|
153
|
-
throw new Error(text.replace(/\n+$/, ''));
|
|
154
|
-
return text;
|
|
7
|
+
else {
|
|
8
|
+
await import('./house-cli.js');
|
|
155
9
|
}
|
|
156
|
-
|
|
157
|
-
(argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
|
|
158
|
-
process.stdout.write(`${text}\n`);
|
|
159
|
-
}, (error) => {
|
|
160
|
-
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
161
|
-
process.exitCode = 1;
|
|
162
|
-
});
|
|
10
|
+
export {};
|
package/dist/instructions.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
const FILE_LINE = 'To give the User a file or a page, upload it with `house upload_attachment` and link it; never start a server.';
|
|
4
|
-
const READ_LINE = 'Before working in a Room, read `/rooms/private/rooms/<handle>/AGENTS.md`.';
|
|
5
|
-
const COPIES_LINE = 'House Local copies; commit, then `house push`:';
|
|
1
|
+
import { agentInstructions } from '@agentshouse/skills';
|
|
2
|
+
const OWNER_RULES = '/rooms/private/owner-rules.md';
|
|
6
3
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
7
4
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
8
5
|
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
@@ -10,9 +7,9 @@ function cutOf(lines) {
|
|
|
10
7
|
const cut = CUT.exec(lines[0] ?? '');
|
|
11
8
|
return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
|
|
12
9
|
}
|
|
13
|
-
async function
|
|
10
|
+
async function readOwnerRules(bridge) {
|
|
14
11
|
let document = '';
|
|
15
|
-
for (let command = `cat ${
|
|
12
|
+
for (let command = `cat ${OWNER_RULES}`; command !== undefined;) {
|
|
16
13
|
const read = await bridge.tool('shell', { command });
|
|
17
14
|
const text = read.content.map((content) => content.text).join('\n');
|
|
18
15
|
const lines = text.split('\n');
|
|
@@ -26,9 +23,8 @@ async function howWeWork(bridge) {
|
|
|
26
23
|
document += lines.slice(cut === null ? 0 : 1).join('\n');
|
|
27
24
|
command = cut?.[2];
|
|
28
25
|
}
|
|
29
|
-
return document
|
|
26
|
+
return document;
|
|
30
27
|
}
|
|
31
|
-
export async function instructions(bridge, base
|
|
32
|
-
|
|
33
|
-
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
28
|
+
export async function instructions(bridge, base) {
|
|
29
|
+
return [agentInstructions().join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
|
|
34
30
|
}
|