@agentshouse/kit 0.2.1-c073f4e9391b2 → 0.2.1-c0b2838a220ac
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 +7 -7
- package/dist/bootstrap.json +4 -4
- package/dist/clis.js +1 -1
- package/dist/copies.js +18 -8
- package/dist/files.js +7 -1
- package/dist/git.js +11 -8
- package/dist/home.js +36 -3
- package/dist/house-main.js +60 -26
- package/dist/login.js +2 -7
- package/dist/skills.js +11 -1
- package/dist/update.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ them out; running it again without the flag brings them back.
|
|
|
33
33
|
|
|
34
34
|
`kit login` opens or prints a link you confirm in any browser, on this computer
|
|
35
35
|
or another, continues on its own and keeps the Environment's credential in
|
|
36
|
-
`~/.house-kit`, or in
|
|
36
|
+
`$HOUSE_KIT_HOME` when it is set, else in `~/.house-kit`, or in `house-kit-<uid>` under the temporary directory when your home is read-only. `--environment <id>`
|
|
37
37
|
reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
|
|
38
38
|
only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
|
|
39
39
|
A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
|
|
@@ -44,15 +44,15 @@ computer, stops House Kit and ends your own agent's connection, so `house` and `
|
|
|
44
44
|
longer act as you here; a later `kit login` reconnects the same Environment.
|
|
45
45
|
In a container you do not control, such as ChatGPT's, `npm i -g @agentshouse/kit` and `kit chatgpt --key <key>` with a key made on Connections let `house <tool>` act as you, starting and configuring nothing else.
|
|
46
46
|
|
|
47
|
-
`kit resident` keeps the Environment connected and, as it connects, copies each
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
`kit resident` keeps the Environment connected and, as it connects, copies the text of each Room
|
|
48
|
+
you chose for it as a Git repository in the workspace's `local-copies`. `house fetch` records
|
|
49
|
+
House's changes on each copy's `refs/house/received`; rebase onto it, commit and run
|
|
50
|
+
`house push --owner` in the copy, through the install command in the container. An Agent runs
|
|
51
|
+
both, without `--owner`. `house upload` and `house download` move a Room's other files.
|
|
52
52
|
|
|
53
53
|
House Kit turns each audio file of your message to an Agent into text on this
|
|
54
54
|
computer before the Agent reads it. While transcription is on, the speech
|
|
55
|
-
engine and model use about 425 MB
|
|
55
|
+
engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
|
|
56
56
|
|
|
57
57
|
## License
|
|
58
58
|
|
package/dist/bootstrap.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-c0b2838a220ac",
|
|
4
4
|
"hosts": {
|
|
5
5
|
"macos": {
|
|
6
6
|
"asset": {
|
|
7
7
|
"name": "connect-linux.sh",
|
|
8
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
8
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c0b2838a220ac/connect-linux.sh"
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"linux": {
|
|
12
12
|
"asset": {
|
|
13
13
|
"name": "connect-linux.sh",
|
|
14
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
14
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c0b2838a220ac/connect-linux.sh"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"windows": {
|
|
18
18
|
"asset": {
|
|
19
19
|
"name": "connect-windows.ps1",
|
|
20
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
20
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c0b2838a220ac/connect-windows.ps1"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/clis.js
CHANGED
|
@@ -199,7 +199,7 @@ export async function installAdapter(kind, signal) {
|
|
|
199
199
|
const release = KIT_PACKAGE.peerDependencies[adapter.package];
|
|
200
200
|
if ((await installedAdapter(kind)) === release)
|
|
201
201
|
return null;
|
|
202
|
-
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
|
|
202
|
+
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--cache', join(kitHome(), 'npm-cache'), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
|
|
203
203
|
return ran.status === 0 ? null : failureOf(ran, 'npm');
|
|
204
204
|
}
|
|
205
205
|
export async function installCli(kind, signal) {
|
package/dist/copies.js
CHANGED
|
@@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
3
3
|
import { mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { finalRefusal, HouseRefusal, retrying } from './api.js';
|
|
6
|
-
import { blobId, blobText, git, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
|
|
6
|
+
import { blobId, blobText, git, isText, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
|
|
7
7
|
import { kitHome } from './home.js';
|
|
8
8
|
import { operationId } from './operation.js';
|
|
9
9
|
import { refusalOf } from './refusals.js';
|
|
@@ -29,6 +29,10 @@ const REBASED = new Set([
|
|
|
29
29
|
function rebaseFixes(refusal) {
|
|
30
30
|
return refusal.code === 'edit_conflict' && refusal.conflicts.some((code) => REBASED.has(code));
|
|
31
31
|
}
|
|
32
|
+
function textOnly(paths) {
|
|
33
|
+
const [named, them] = paths.length === 1 ? [`${paths[0]} is`, 'it'] : [`${paths.join(', ')} are`, 'them'];
|
|
34
|
+
return `${named} not text, and house push sends text only; remove ${them} from the commit and place ${them} with house upload`;
|
|
35
|
+
}
|
|
32
36
|
function short(commit) {
|
|
33
37
|
return commit.slice(0, 12);
|
|
34
38
|
}
|
|
@@ -572,7 +576,13 @@ export class LocalCopies {
|
|
|
572
576
|
const after = await tree(copy.repository, commit);
|
|
573
577
|
const moved = movedPaths(copy.moves, before, after);
|
|
574
578
|
const arrived = new Set(moved.values());
|
|
575
|
-
const
|
|
579
|
+
const binary = [];
|
|
580
|
+
for (const [path, entry] of after)
|
|
581
|
+
if (before.get(path) !== entry && !(await isText(copy.repository, entry)))
|
|
582
|
+
binary.push(path);
|
|
583
|
+
if (binary.length > 0)
|
|
584
|
+
throw new Error(textOnly(binary));
|
|
585
|
+
const text = (entry) => blobText(copy.repository, entry);
|
|
576
586
|
const changes = [];
|
|
577
587
|
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
578
588
|
if (arrived.has(path))
|
|
@@ -585,7 +595,7 @@ export class LocalCopies {
|
|
|
585
595
|
changes.push({ op: 'rename', path: `${root}/${path}`, to: `${root}/${to}`, base: known });
|
|
586
596
|
const moving = after.get(to);
|
|
587
597
|
if (moving !== prior) {
|
|
588
|
-
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving
|
|
598
|
+
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving) });
|
|
589
599
|
}
|
|
590
600
|
continue;
|
|
591
601
|
}
|
|
@@ -594,9 +604,9 @@ export class LocalCopies {
|
|
|
594
604
|
if (next === undefined)
|
|
595
605
|
changes.push({ op: 'remove', path: `${root}/${path}`, base: known });
|
|
596
606
|
else if (prior === undefined)
|
|
597
|
-
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next
|
|
607
|
+
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next) });
|
|
598
608
|
else
|
|
599
|
-
changes.push(...changed(`${root}/${path}`, path, known, await text(prior
|
|
609
|
+
changes.push(...changed(`${root}/${path}`, path, known, await text(prior), await text(next)));
|
|
600
610
|
}
|
|
601
611
|
return changes;
|
|
602
612
|
}
|
|
@@ -663,7 +673,7 @@ export class LocalCopies {
|
|
|
663
673
|
written.push({
|
|
664
674
|
path: `${root}/${path}`,
|
|
665
675
|
revision: entry === undefined ? null : (revisionAt(current, current.house, path) ?? null),
|
|
666
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
676
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
667
677
|
});
|
|
668
678
|
}
|
|
669
679
|
return this.finished(await this.save({ ...current, push: { ...push, state: 'accepted', written } }));
|
|
@@ -707,7 +717,7 @@ export class LocalCopies {
|
|
|
707
717
|
{
|
|
708
718
|
path: `${rootOf(copy.room_handle)}/${path}`,
|
|
709
719
|
revision: entry === undefined ? null : (revisionAt(copy, copy.house, path) ?? null),
|
|
710
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
720
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
711
721
|
},
|
|
712
722
|
];
|
|
713
723
|
}
|
|
@@ -752,7 +762,7 @@ export class LocalCopies {
|
|
|
752
762
|
async landed(repository, changes, house, selected) {
|
|
753
763
|
const text = async (path) => {
|
|
754
764
|
const entry = house.get(relative(path));
|
|
755
|
-
return entry === undefined ? undefined : blobText(repository, entry
|
|
765
|
+
return entry === undefined ? undefined : blobText(repository, entry);
|
|
756
766
|
};
|
|
757
767
|
for (const change of changes) {
|
|
758
768
|
const current = await text(change.path);
|
package/dist/files.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { HouseRefusal, retrying } from './api.js';
|
|
4
5
|
import { relayed } from './relay.js';
|
|
6
|
+
export function verified(bytes, sha256, name) {
|
|
7
|
+
if (createHash('sha256').update(bytes).digest('hex') !== sha256)
|
|
8
|
+
throw new Error(`${name} did not arrive whole; download it again`);
|
|
9
|
+
return bytes;
|
|
10
|
+
}
|
|
5
11
|
export async function placeFiles(house, directory, files, signal) {
|
|
6
12
|
const paths = [];
|
|
7
13
|
for (const file of files) {
|
|
@@ -16,7 +22,7 @@ export async function placeFiles(house, directory, files, signal) {
|
|
|
16
22
|
});
|
|
17
23
|
await mkdir(folder, { recursive: true });
|
|
18
24
|
const path = join(folder, file.name);
|
|
19
|
-
await writeFile(path, Buffer.from(await answer.arrayBuffer()));
|
|
25
|
+
await writeFile(path, verified(Buffer.from(await answer.arrayBuffer()), file.sha256, file.name));
|
|
20
26
|
paths.push(path);
|
|
21
27
|
}
|
|
22
28
|
return paths;
|
package/dist/git.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { isUtf8 } from 'node:buffer';
|
|
2
3
|
import { createHash } from 'node:crypto';
|
|
3
4
|
import { join } from 'node:path';
|
|
4
5
|
import { withoutProxy } from './clis.js';
|
|
@@ -48,14 +49,16 @@ export async function tree(repository, commit) {
|
|
|
48
49
|
}
|
|
49
50
|
return entries;
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const TEXT_MAX_BYTES = 16 * 1024 * 1024;
|
|
53
|
+
async function blob(repository, object) {
|
|
54
|
+
return (await run(repository, ['cat-file', 'blob', object])).stdout;
|
|
55
|
+
}
|
|
56
|
+
export async function blobText(repository, object) {
|
|
57
|
+
return (await blob(repository, object)).toString('utf8');
|
|
58
|
+
}
|
|
59
|
+
export async function isText(repository, object) {
|
|
60
|
+
const bytes = await blob(repository, object);
|
|
61
|
+
return bytes.length <= TEXT_MAX_BYTES && isUtf8(bytes) && !bytes.includes(0);
|
|
59
62
|
}
|
|
60
63
|
export function blobId(content) {
|
|
61
64
|
const bytes = Buffer.from(content, 'utf8');
|
package/dist/home.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync, linkSync, readFileSync, renameSync, rmSync } 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
5
|
import { selectRelay } from './relay.js';
|
|
6
6
|
const ENROLMENT = 'credential.json';
|
|
@@ -8,8 +8,41 @@ const DISCONNECTED = 'disconnected.json';
|
|
|
8
8
|
const CONFIGURATION = 'kit.json';
|
|
9
9
|
const OWN_AGENT = 'own-agent.json';
|
|
10
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
|
+
}
|
|
11
44
|
export function kitHome() {
|
|
12
|
-
return process.env.HOUSE_KIT_HOME
|
|
45
|
+
return process.env.HOUSE_KIT_HOME || (defaulted ??= defaultHome());
|
|
13
46
|
}
|
|
14
47
|
export function workspaceRoot() {
|
|
15
48
|
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
package/dist/house-main.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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 { extname, join } from 'node:path';
|
|
5
|
+
import { 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, readEnrolment, readOwnAgent } from './home.js';
|
|
8
9
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
@@ -14,12 +15,15 @@ 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([
|
|
25
29
|
['avif', 'image/avif'],
|
|
@@ -48,37 +52,42 @@ const MEDIA_TYPES = new Map([
|
|
|
48
52
|
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
49
53
|
['zip', 'application/zip'],
|
|
50
54
|
]);
|
|
51
|
-
function refused(path, status, text) {
|
|
55
|
+
function refused(path, method, status, text, local) {
|
|
52
56
|
const refusal = refusalOf(text);
|
|
53
57
|
if (refusal !== null)
|
|
54
58
|
return refusal.text;
|
|
55
59
|
if (status === 401)
|
|
56
60
|
return REVOKED;
|
|
61
|
+
const act = method === 'GET' ? 'download' : 'upload';
|
|
57
62
|
if (URL.canParse(path))
|
|
58
|
-
return `the
|
|
59
|
-
if (status === 502 &&
|
|
63
|
+
return `the ${act} answered ${status}; ${act} the file again`;
|
|
64
|
+
if (status === 502 && local)
|
|
60
65
|
return text;
|
|
61
|
-
return `${path} answered ${status}`;
|
|
66
|
+
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
62
67
|
}
|
|
63
|
-
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) {
|
|
64
72
|
return new Promise((resolve, reject) => {
|
|
65
|
-
const sent = request({ socketPath: to, path, method
|
|
66
|
-
|
|
67
|
-
answer.
|
|
68
|
-
answer.on('data', (chunk) => {
|
|
69
|
-
text += chunk;
|
|
70
|
-
});
|
|
73
|
+
const sent = request({ socketPath: to, path, method, headers }, (answer) => {
|
|
74
|
+
const chunks = [];
|
|
75
|
+
answer.on('data', (chunk) => chunks.push(chunk));
|
|
71
76
|
answer.on('end', () => {
|
|
77
|
+
const bytes = Buffer.concat(chunks);
|
|
72
78
|
if (answer.statusCode === 200)
|
|
73
|
-
resolve(
|
|
79
|
+
resolve(bytes);
|
|
74
80
|
else
|
|
75
|
-
reject(new Error(refused(path, answer.statusCode,
|
|
81
|
+
reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
|
|
76
82
|
});
|
|
77
83
|
});
|
|
78
84
|
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
79
|
-
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
85
|
+
sent.end(body === undefined ? undefined : body instanceof Buffer ? body : JSON.stringify(body));
|
|
80
86
|
});
|
|
81
87
|
}
|
|
88
|
+
async function bridged(path, body, headers, to = socketPath) {
|
|
89
|
+
return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
|
|
90
|
+
}
|
|
82
91
|
async function direct(message) {
|
|
83
92
|
const ownAgent = await readOwnAgent();
|
|
84
93
|
if (ownAgent === null)
|
|
@@ -90,7 +99,7 @@ async function direct(message) {
|
|
|
90
99
|
});
|
|
91
100
|
if (answer.status === 200)
|
|
92
101
|
return answer.text;
|
|
93
|
-
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)));
|
|
94
103
|
}
|
|
95
104
|
async function mcp(method, params) {
|
|
96
105
|
const message = rpc(method, params);
|
|
@@ -112,18 +121,37 @@ async function localFile(path) {
|
|
|
112
121
|
: `${path} is not a readable file`);
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
|
-
async function
|
|
116
|
-
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
124
|
+
async function transferred(url, method, bytes, headers) {
|
|
117
125
|
if (socketPath !== undefined)
|
|
118
|
-
return
|
|
126
|
+
return exchanged(url, method, bytes, headers);
|
|
119
127
|
setGlobalProxyFromEnv();
|
|
120
|
-
const answer = await fetch(relayed(url), { method:
|
|
128
|
+
const answer = await fetch(relayed(url), { method, ...(headers === undefined ? {} : { headers }), ...(bytes === undefined ? {} : { body: bytes }) }).catch(() => {
|
|
121
129
|
throw new Error(UNREACHABLE);
|
|
122
130
|
});
|
|
123
|
-
const
|
|
131
|
+
const received = Buffer.from(await answer.arrayBuffer());
|
|
124
132
|
if (answer.status === 200)
|
|
125
|
-
return
|
|
126
|
-
throw new Error(refused(url, answer.status,
|
|
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;
|
|
127
155
|
}
|
|
128
156
|
async function upload({ file, ...destination }) {
|
|
129
157
|
if (typeof file !== 'string' || file === '')
|
|
@@ -200,7 +228,7 @@ async function house(args) {
|
|
|
200
228
|
if (flags.has('--help') && argument !== undefined)
|
|
201
229
|
throw unexpected('--help', USAGE);
|
|
202
230
|
if (verb === undefined || verb === 'help') {
|
|
203
|
-
return [USAGE, 'help', PUSH, FETCH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
231
|
+
return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
204
232
|
}
|
|
205
233
|
if (flags.has('--help')) {
|
|
206
234
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
@@ -221,7 +249,13 @@ async function called(name, args) {
|
|
|
221
249
|
const argv = process.argv.slice(2);
|
|
222
250
|
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
223
251
|
const rest = argv.filter((_arg, index) => index !== named);
|
|
224
|
-
(argv[named] === 'push'
|
|
252
|
+
(argv[named] === 'push'
|
|
253
|
+
? push(rest)
|
|
254
|
+
: argv[named] === 'fetch'
|
|
255
|
+
? fetched(rest)
|
|
256
|
+
: argv[named] === 'download'
|
|
257
|
+
? download(rest)
|
|
258
|
+
: house(argv)).then((text) => {
|
|
225
259
|
process.stdout.write(`${text}\n`);
|
|
226
260
|
if (argv[0] === 'shell')
|
|
227
261
|
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
package/dist/login.js
CHANGED
|
@@ -96,12 +96,7 @@ export async function login(argv) {
|
|
|
96
96
|
open(started.start_url);
|
|
97
97
|
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
await placeSkillSet();
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
104
|
-
}
|
|
99
|
+
await placeSkillSet();
|
|
105
100
|
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
106
101
|
await writeEnrolment({
|
|
107
102
|
house,
|
|
@@ -117,7 +112,7 @@ export async function login(argv) {
|
|
|
117
112
|
await forgetOwnAgent();
|
|
118
113
|
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
119
114
|
}
|
|
120
|
-
await placeAppGit(ownAgent, await readOwnAgent());
|
|
115
|
+
await placeAppGit(ownAgent, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
121
116
|
try {
|
|
122
117
|
startService();
|
|
123
118
|
}
|
package/dist/skills.js
CHANGED
|
@@ -49,6 +49,14 @@ async function install() {
|
|
|
49
49
|
await writeHome(RECORD, { version: KIT_VERSION, names });
|
|
50
50
|
}
|
|
51
51
|
export async function placeSkillSet() {
|
|
52
|
+
try {
|
|
53
|
+
await replaceSkillSet();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function replaceSkillSet() {
|
|
52
60
|
const accepted = (await readConfiguration()).skills;
|
|
53
61
|
const installed = await readHome(RECORD);
|
|
54
62
|
if (accepted && installed?.version === KIT_VERSION)
|
|
@@ -63,7 +71,9 @@ export async function placeSkillSet() {
|
|
|
63
71
|
await rm(join(kitHome(), RECORD), { force: true });
|
|
64
72
|
}
|
|
65
73
|
export async function createHowWeWork(bridge) {
|
|
66
|
-
if ((await
|
|
74
|
+
if (!(await readConfiguration()).skills || (await readHome(RECORD))?.version === undefined)
|
|
75
|
+
return;
|
|
76
|
+
if (await present(join(kitHome(), CREATED)))
|
|
67
77
|
return;
|
|
68
78
|
const created = await bridge.tool('edit', { changes: [{ op: 'create', path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
|
|
69
79
|
if (created.isError === true) {
|
package/dist/update.js
CHANGED