@agentshouse/kit 0.2.1-cf268dff1869b → 0.2.1-cf2c570b41f24
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 +18 -25
- package/dist/acp.js +12 -9
- package/dist/afk.js +17 -0
- package/dist/agents.js +72 -26
- package/dist/api.js +18 -4
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +99 -44
- package/dist/calls.js +18 -1
- package/dist/chunks.js +54 -0
- package/dist/clis.js +33 -15
- package/dist/connect.js +121 -0
- package/dist/connection.js +25 -10
- package/dist/content.js +106 -0
- package/dist/conversations.js +251 -158
- package/dist/copies.js +1260 -599
- package/dist/earlier.js +273 -0
- package/dist/end.js +6 -9
- package/dist/events.js +544 -297
- package/dist/files.js +77 -11
- package/dist/git.js +0 -70
- package/dist/grok.js +39 -0
- package/dist/home.js +86 -22
- package/dist/house-cli.js +145 -162
- package/dist/instructions.js +2 -4
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +14 -4
- package/dist/login.js +34 -20
- package/dist/logout.js +2 -2
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +43 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +0 -6
- package/dist/refusals.js +50 -23
- package/dist/resident.js +117 -76
- package/dist/scripts.js +79 -15
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +49 -4
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +5 -2
- package/dist/update.js +31 -22
- package/dist/wire.js +2 -10
- package/dist/work.js +27 -2
- package/dist/workspace.js +113 -0
- package/package.json +12 -8
- package/dist/authority-main.js +0 -22
- package/dist/chatgpt.js +0 -32
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/git-main.js +0 -153
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -55
- package/dist/translate.js +0 -45
package/dist/kit-cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
import { answerGitCredential } from './app-git.js';
|
|
3
|
-
import {
|
|
3
|
+
import { connect } from './connect.js';
|
|
4
4
|
import { login } from './login.js';
|
|
5
5
|
import { logout } from './logout.js';
|
|
6
6
|
import { proxyUnlessRelayed } from './relay.js';
|
|
7
7
|
import { resident } from './resident.js';
|
|
8
|
-
|
|
8
|
+
import { kitSettings, SETTINGS_USAGE } from './settings.js';
|
|
9
|
+
const USAGE = 'usage: kit <connect|login|logout|resident|settings>\n';
|
|
9
10
|
const COMMANDS = new Map([
|
|
10
11
|
[
|
|
11
12
|
'logout',
|
|
@@ -25,6 +26,15 @@ const COMMANDS = new Map([
|
|
|
25
26
|
run: resident,
|
|
26
27
|
},
|
|
27
28
|
],
|
|
29
|
+
[
|
|
30
|
+
'settings',
|
|
31
|
+
{
|
|
32
|
+
usage: SETTINGS_USAGE,
|
|
33
|
+
about: "prints Kit's settings, or changes whether Kit places House's Skills or where its workspace is",
|
|
34
|
+
operands: 2,
|
|
35
|
+
run: kitSettings,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
28
38
|
[
|
|
29
39
|
'git-credential',
|
|
30
40
|
{
|
|
@@ -38,10 +48,10 @@ const COMMANDS = new Map([
|
|
|
38
48
|
const [command, ...argv] = process.argv.slice(2);
|
|
39
49
|
proxyUnlessRelayed();
|
|
40
50
|
async function run() {
|
|
51
|
+
if (command === 'connect')
|
|
52
|
+
return connect(argv);
|
|
41
53
|
if (command === 'login')
|
|
42
54
|
return login(argv);
|
|
43
|
-
if (command === 'chatgpt')
|
|
44
|
-
return chatgpt(argv);
|
|
45
55
|
if (command === '--help') {
|
|
46
56
|
parseArgs({ args: argv });
|
|
47
57
|
process.stdout.write(USAGE);
|
package/dist/login.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KIT_LOGIN_PATHS, } from '@agentshouse/kit-wire';
|
|
1
2
|
import { spawn } from 'node:child_process';
|
|
2
3
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
4
|
import { parseArgs } from 'node:util';
|
|
@@ -8,19 +9,25 @@ import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, re
|
|
|
8
9
|
import { callHouse, rpc } from './mcp.js';
|
|
9
10
|
import { refusalOf } from './refusals.js';
|
|
10
11
|
import { selectRelay } from './relay.js';
|
|
11
|
-
import { startService } from './
|
|
12
|
+
import { startService } from './supervisor.js';
|
|
12
13
|
import { placeSkillSet } from './skills.js';
|
|
13
14
|
import { endUnserved } from './wire.js';
|
|
14
15
|
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
15
16
|
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
16
17
|
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
17
18
|
const POLL_INTERVAL_MS = 2000;
|
|
19
|
+
function startLogin(house, request) {
|
|
20
|
+
return post(house, KIT_LOGIN_PATHS.start, request);
|
|
21
|
+
}
|
|
22
|
+
function pollLogin(house, request) {
|
|
23
|
+
return post(house, KIT_LOGIN_PATHS.poll, request);
|
|
24
|
+
}
|
|
18
25
|
function open(link) {
|
|
19
26
|
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
20
27
|
.on('error', () => undefined)
|
|
21
28
|
.unref();
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
async function accepted(house, credential) {
|
|
24
31
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
25
32
|
if (checked.status === 200)
|
|
26
33
|
return true;
|
|
@@ -70,6 +77,21 @@ export async function login(argv) {
|
|
|
70
77
|
process.stdout.write(USAGE);
|
|
71
78
|
return;
|
|
72
79
|
}
|
|
80
|
+
const house = await enrol(values);
|
|
81
|
+
await placeConnection(house);
|
|
82
|
+
try {
|
|
83
|
+
startService();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function placeConnection(house) {
|
|
90
|
+
await placeSkillSet(house);
|
|
91
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
92
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
93
|
+
}
|
|
94
|
+
export async function enrol(values) {
|
|
73
95
|
if (values.code !== undefined && values.rooms !== undefined)
|
|
74
96
|
throw new Error('--code cannot be used with --rooms');
|
|
75
97
|
if (values.code !== undefined && values['no-private'])
|
|
@@ -84,23 +106,23 @@ export async function login(argv) {
|
|
|
84
106
|
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
85
107
|
selectRelay(relay);
|
|
86
108
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
109
|
+
const remembered = values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
110
|
+
const environment = values.environment ?? remembered;
|
|
111
|
+
if (environment !== undefined && rooms.rooms !== undefined) {
|
|
112
|
+
throw new Error(`Environment ${environment} keeps its Rooms; change them on its page in House`);
|
|
113
|
+
}
|
|
90
114
|
const ownAgent = await readOwnAgent();
|
|
91
115
|
let held = false;
|
|
92
116
|
let named = environment;
|
|
93
117
|
let exchanged;
|
|
94
118
|
if (values.code !== undefined) {
|
|
95
|
-
exchanged = await
|
|
119
|
+
exchanged = await pollLogin(house, { code: values.code });
|
|
96
120
|
}
|
|
97
121
|
else {
|
|
98
122
|
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
99
123
|
const verifier = randomBytes(32).toString('base64url');
|
|
100
|
-
const start = () => retrying(() =>
|
|
101
|
-
...(named === undefined
|
|
102
|
-
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
103
|
-
: { act: 'existing_environment', environment_id: named }),
|
|
124
|
+
const start = () => retrying(() => startLogin(house, {
|
|
125
|
+
...(named === undefined ? { act: 'new_environment' } : { act: 'existing_environment', environment_id: named }),
|
|
104
126
|
...rooms,
|
|
105
127
|
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
106
128
|
...(held ? {} : { headless: true }),
|
|
@@ -119,10 +141,8 @@ export async function login(argv) {
|
|
|
119
141
|
}
|
|
120
142
|
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
121
143
|
open(started.start_url);
|
|
122
|
-
exchanged = await retrying(() =>
|
|
144
|
+
exchanged = await retrying(() => pollLogin(house, { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
123
145
|
}
|
|
124
|
-
await placeSkillSet(house);
|
|
125
|
-
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
126
146
|
const relayRecord = relay === undefined ? {} : { relay };
|
|
127
147
|
await writeEnrolment({
|
|
128
148
|
house,
|
|
@@ -141,11 +161,5 @@ export async function login(argv) {
|
|
|
141
161
|
else if (held && ownAgent !== null) {
|
|
142
162
|
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
143
163
|
}
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
startService();
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
process.stderr.write(`kit: ${error.message}\n`);
|
|
150
|
-
}
|
|
164
|
+
return house;
|
|
151
165
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { HouseRefusal,
|
|
1
|
+
import { HouseRefusal, kitAct } from './api.js';
|
|
2
2
|
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
3
3
|
export async function logout() {
|
|
4
4
|
const enrolled = await readEnrolment();
|
|
5
5
|
if (enrolled !== null) {
|
|
6
6
|
try {
|
|
7
|
-
await
|
|
7
|
+
await kitAct(enrolled.house, 'kits/log-out', {}, enrolled.credential);
|
|
8
8
|
}
|
|
9
9
|
catch (error) {
|
|
10
10
|
if (!(error instanceof HouseRefusal && error.status === 401))
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
export const MANIFEST = '.house';
|
|
6
|
+
const UNREAD = '.git';
|
|
7
|
+
const MARKER = /^(?:<{7}|={7}|>{7})(?: .*)?$/m;
|
|
8
|
+
export function digest(bytes) {
|
|
9
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
10
|
+
}
|
|
11
|
+
export async function fileDigest(file) {
|
|
12
|
+
const hash = createHash('sha256');
|
|
13
|
+
let bytes = 0;
|
|
14
|
+
for await (const chunk of createReadStream(file)) {
|
|
15
|
+
hash.update(chunk);
|
|
16
|
+
bytes += chunk.length;
|
|
17
|
+
}
|
|
18
|
+
return { sha256: hash.digest('hex'), bytes };
|
|
19
|
+
}
|
|
20
|
+
export async function hashed(file) {
|
|
21
|
+
try {
|
|
22
|
+
return await fileDigest(file);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code === 'ENOENT' || error.code === 'EISDIR')
|
|
26
|
+
return null;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function holding(repository, name, sha256) {
|
|
31
|
+
return (await hashed(join(repository, name)))?.sha256 === sha256;
|
|
32
|
+
}
|
|
33
|
+
export async function readManifest(repository) {
|
|
34
|
+
return JSON.parse(await readFile(join(repository, MANIFEST), 'utf8'));
|
|
35
|
+
}
|
|
36
|
+
export async function placed(staging, target, content) {
|
|
37
|
+
const temporary = `${staging}${randomUUID()}`;
|
|
38
|
+
await writeFile(temporary, content);
|
|
39
|
+
await mkdir(dirname(target), { recursive: true });
|
|
40
|
+
await rename(temporary, target);
|
|
41
|
+
}
|
|
42
|
+
export async function writeManifest(repository, staging, manifest) {
|
|
43
|
+
const files = Object.fromEntries(Object.entries(manifest.files).sort(([left], [right]) => (left < right ? -1 : 1)));
|
|
44
|
+
await placed(staging, join(repository, MANIFEST), `${JSON.stringify({ room_ref: manifest.room_ref, files })}\n`);
|
|
45
|
+
}
|
|
46
|
+
export async function removed(repository, name) {
|
|
47
|
+
await rm(join(repository, name), { force: true });
|
|
48
|
+
for (let folder = dirname(name); folder !== '.'; folder = dirname(folder)) {
|
|
49
|
+
if (!(await rmdir(join(repository, folder)).then(() => true, () => false)))
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export async function scanned(repository) {
|
|
54
|
+
const present = new Map();
|
|
55
|
+
const walk = async (folder) => {
|
|
56
|
+
for (const entry of await readdir(join(repository, folder), { withFileTypes: true })) {
|
|
57
|
+
const name = folder === '' ? entry.name : `${folder}/${entry.name}`;
|
|
58
|
+
if (folder === '' && (entry.name === MANIFEST || entry.name === UNREAD))
|
|
59
|
+
continue;
|
|
60
|
+
if (entry.isDirectory())
|
|
61
|
+
await walk(name);
|
|
62
|
+
else if (entry.isFile()) {
|
|
63
|
+
const file = await hashed(join(repository, name));
|
|
64
|
+
if (file !== null)
|
|
65
|
+
present.set(name.normalize('NFC'), { name, ...file });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
await walk('');
|
|
70
|
+
return present;
|
|
71
|
+
}
|
|
72
|
+
export async function marked(repository, name) {
|
|
73
|
+
const text = await readFile(join(repository, name), 'utf8').catch(() => null);
|
|
74
|
+
return text !== null && MARKER.test(text);
|
|
75
|
+
}
|
package/dist/mcp.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { KIT_WIRE, KIT_WIRE_HEADER } from '@agentshouse/kit-wire';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { KIT_RELEASE } from './clis.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { readOwnAgent } from './home.js';
|
|
5
|
+
import { refusalOf, retryable } from './refusals.js';
|
|
6
|
+
import { relayed, selectRelay } from './relay.js';
|
|
5
7
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
6
8
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
9
|
+
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
10
|
+
export const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
11
|
+
const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
|
|
7
12
|
export class Unsettled extends Error {
|
|
8
13
|
}
|
|
9
14
|
export function rpc(method, params) {
|
|
10
15
|
return { jsonrpc: '2.0', id: randomUUID(), method, params };
|
|
11
16
|
}
|
|
12
|
-
export function mcpBody(message, operation) {
|
|
17
|
+
export function mcpBody(message, { operation = null, named = {} } = {}) {
|
|
13
18
|
return JSON.stringify({
|
|
14
19
|
...message,
|
|
15
20
|
params: {
|
|
@@ -18,12 +23,13 @@ export function mcpBody(message, operation) {
|
|
|
18
23
|
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
19
24
|
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
20
25
|
'io.modelcontextprotocol/clientCapabilities': {},
|
|
26
|
+
...named,
|
|
21
27
|
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
22
28
|
},
|
|
23
29
|
},
|
|
24
30
|
});
|
|
25
31
|
}
|
|
26
|
-
export async function callHouse(origin, credential, message,
|
|
32
|
+
export async function callHouse(origin, credential, message, sending = {}) {
|
|
27
33
|
const tool = message.method === 'tools/call' ? String(message.params.name) : null;
|
|
28
34
|
const answer = await fetch(relayed(new URL('/', origin)), {
|
|
29
35
|
method: 'POST',
|
|
@@ -34,10 +40,40 @@ export async function callHouse(origin, credential, message, operation = null, s
|
|
|
34
40
|
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
35
41
|
'mcp-method': message.method,
|
|
36
42
|
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
37
|
-
[KIT_WIRE_HEADER]:
|
|
43
|
+
[KIT_WIRE_HEADER]: KIT_WIRE,
|
|
38
44
|
},
|
|
39
|
-
body: mcpBody(message,
|
|
40
|
-
signal,
|
|
45
|
+
body: mcpBody(message, sending),
|
|
46
|
+
signal: sending.signal,
|
|
41
47
|
});
|
|
42
48
|
return { status: answer.status, text: await answer.text() };
|
|
43
49
|
}
|
|
50
|
+
export function unconfirmed(status) {
|
|
51
|
+
return `House answered ${status} ${UNCONFIRMED}`;
|
|
52
|
+
}
|
|
53
|
+
export async function ownAgentCall(message) {
|
|
54
|
+
const ownAgent = await readOwnAgent();
|
|
55
|
+
if (ownAgent === null)
|
|
56
|
+
throw new Error(UNCONNECTED);
|
|
57
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
|
|
58
|
+
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
59
|
+
throw new Unsettled(UNREACHABLE);
|
|
60
|
+
});
|
|
61
|
+
if (answer.status === 200)
|
|
62
|
+
return answer.text;
|
|
63
|
+
if (answer.status === 401)
|
|
64
|
+
throw new Error(DISCONNECTED);
|
|
65
|
+
const refusal = refusalOf(answer.text)?.text ?? unconfirmed(answer.status);
|
|
66
|
+
throw retryable(answer.text) === false ? new Error(refusal) : new Unsettled(refusal);
|
|
67
|
+
}
|
|
68
|
+
export function refusalIn(text, status) {
|
|
69
|
+
return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [], detail: {} };
|
|
70
|
+
}
|
|
71
|
+
export function toolAnswer(forwarded) {
|
|
72
|
+
if (forwarded.status !== 200)
|
|
73
|
+
return { refused: refusalIn(forwarded.text, forwarded.status) };
|
|
74
|
+
const answer = JSON.parse(forwarded.text);
|
|
75
|
+
if (answer.error !== undefined)
|
|
76
|
+
return { refused: refusalIn(answer.error.message, forwarded.status) };
|
|
77
|
+
const text = answer.result.content.map((content) => content.text).join('\n');
|
|
78
|
+
return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
|
|
79
|
+
}
|
package/dist/owner.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { request } from 'node:http';
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
import { received } from './bridge.js';
|
|
4
|
+
import { kitHome, ownerLock, ownerSocket } from './home.js';
|
|
5
|
+
function claimed(lock) {
|
|
6
|
+
try {
|
|
7
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.errcode === 5)
|
|
12
|
+
return false;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function askOwner(path, body) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const sent = request({ socketPath: ownerSocket(), path, method: body === undefined ? 'GET' : 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
|
|
19
|
+
received(answer).then((text) => {
|
|
20
|
+
if (answer.statusCode === 200)
|
|
21
|
+
resolve(JSON.parse(text));
|
|
22
|
+
else
|
|
23
|
+
reject(new Error(text));
|
|
24
|
+
}, reject);
|
|
25
|
+
});
|
|
26
|
+
sent.on('error', (error) => {
|
|
27
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
28
|
+
resolve(null);
|
|
29
|
+
else
|
|
30
|
+
reject(error);
|
|
31
|
+
});
|
|
32
|
+
sent.end(body === undefined ? undefined : JSON.stringify(body));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function holdOwner() {
|
|
36
|
+
const lock = new DatabaseSync(ownerLock());
|
|
37
|
+
if (claimed(lock))
|
|
38
|
+
return lock;
|
|
39
|
+
lock.close();
|
|
40
|
+
const running = (await askOwner('/resident'))?.pid ?? null;
|
|
41
|
+
throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
|
|
42
|
+
}
|
|
43
|
+
export async function runningRelease() {
|
|
44
|
+
const running = await askOwner('/resident');
|
|
45
|
+
return running === null ? null : (running.release ?? '');
|
|
46
|
+
}
|
package/dist/placement.js
CHANGED
|
@@ -14,12 +14,6 @@ function recorded(name) {
|
|
|
14
14
|
export function installCommand() {
|
|
15
15
|
return recorded('install-command');
|
|
16
16
|
}
|
|
17
|
-
export function machine() {
|
|
18
|
-
const placed = recorded('placement');
|
|
19
|
-
if (placed === 'container' || placed === 'server' || placed === 'windows')
|
|
20
|
-
return placed;
|
|
21
|
-
return process.platform === 'darwin' ? 'macos' : 'linux';
|
|
22
|
-
}
|
|
23
17
|
export function placedPrefix() {
|
|
24
18
|
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
25
19
|
if (prefix === undefined || prefix === '')
|
package/dist/refusals.js
CHANGED
|
@@ -1,53 +1,80 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
2
|
const HEAD = /^([a-z][a-z0-9_]*): \S/;
|
|
3
|
-
|
|
3
|
+
const PUSH_STOPS = new Set(['limit_reached', 'cap_reached']);
|
|
4
|
+
function detailOf(text) {
|
|
4
5
|
let parsed;
|
|
5
6
|
try {
|
|
6
|
-
parsed = parse(
|
|
7
|
+
parsed = parse(text);
|
|
7
8
|
}
|
|
8
9
|
catch {
|
|
9
|
-
return
|
|
10
|
+
return {};
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
13
|
+
}
|
|
14
|
+
function conflictsOf(detail) {
|
|
15
|
+
if (!Array.isArray(detail.conflicts))
|
|
13
16
|
return [];
|
|
14
|
-
return conflicts.flatMap((conflict) => typeof conflict?.code === 'string'
|
|
17
|
+
return detail.conflicts.flatMap((conflict) => typeof conflict?.code === 'string'
|
|
18
|
+
? [
|
|
19
|
+
{
|
|
20
|
+
code: conflict.code,
|
|
21
|
+
path: typeof conflict.path === 'string' ? conflict.path : '',
|
|
22
|
+
...(typeof conflict.revision === 'string' ? { revision: conflict.revision } : {}),
|
|
23
|
+
...(typeof conflict.content === 'string' ? { content: conflict.content } : {}),
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
: []);
|
|
15
27
|
}
|
|
16
28
|
function spoken(text) {
|
|
17
29
|
const head = HEAD.exec(text);
|
|
18
30
|
if (head === null)
|
|
19
31
|
return null;
|
|
20
32
|
const said = text.replace(/\n+$/, '');
|
|
21
|
-
const
|
|
22
|
-
|
|
33
|
+
const line = said.indexOf('\n');
|
|
34
|
+
const detail = line === -1 ? {} : detailOf(said.slice(line + 1));
|
|
35
|
+
return { code: head[1], text: said, conflicts: conflictsOf(detail), detail };
|
|
23
36
|
}
|
|
24
|
-
export function
|
|
25
|
-
|
|
37
|
+
export function stopsPush(refusal) {
|
|
38
|
+
return refusal !== null && PUSH_STOPS.has(refusal.code) && refusal.retryable === true;
|
|
39
|
+
}
|
|
40
|
+
export function firstLine(refusal) {
|
|
41
|
+
return refusal.text.split('\n')[0];
|
|
42
|
+
}
|
|
43
|
+
function parsed(text) {
|
|
26
44
|
try {
|
|
27
|
-
body
|
|
45
|
+
return { body: JSON.parse(text) };
|
|
28
46
|
}
|
|
29
47
|
catch {
|
|
30
48
|
return null;
|
|
31
49
|
}
|
|
50
|
+
}
|
|
51
|
+
function errorIn(body) {
|
|
32
52
|
const error = body?.error;
|
|
53
|
+
return typeof error === 'object' && error !== null ? error : null;
|
|
54
|
+
}
|
|
55
|
+
function verdictOf(error) {
|
|
33
56
|
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
34
57
|
return typeof verdict === 'boolean' ? verdict : null;
|
|
35
58
|
}
|
|
59
|
+
export function retryable(text) {
|
|
60
|
+
const answer = parsed(text);
|
|
61
|
+
return answer === null ? null : verdictOf(errorIn(answer.body));
|
|
62
|
+
}
|
|
36
63
|
export function refusalOf(text) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body = JSON.parse(text);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
64
|
+
const answer = parsed(text);
|
|
65
|
+
if (answer === null)
|
|
42
66
|
return spoken(text);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof error !== 'object' || error === null)
|
|
67
|
+
const error = errorIn(answer.body);
|
|
68
|
+
if (error === null)
|
|
46
69
|
return null;
|
|
47
|
-
const { code, message, data } = error;
|
|
70
|
+
const { code, message, data, retryable: _retryable, ...fields } = error;
|
|
71
|
+
const verdict = verdictOf(error);
|
|
72
|
+
const judged = verdict === null ? {} : { retryable: verdict };
|
|
48
73
|
const said = typeof message === 'string' ? spoken(message) : null;
|
|
49
|
-
if (said !== null)
|
|
50
|
-
|
|
74
|
+
if (said !== null) {
|
|
75
|
+
const detail = { ...said.detail, ...fields };
|
|
76
|
+
return { ...said, detail, conflicts: conflictsOf(detail), ...judged };
|
|
77
|
+
}
|
|
51
78
|
const named = typeof code === 'string' ? code : typeof data?.code === 'string' ? data.code : null;
|
|
52
|
-
return named === null ? null : { code: named, text: named, conflicts: [] };
|
|
79
|
+
return named === null ? null : { code: named, text: named, conflicts: [], detail: {}, ...judged };
|
|
53
80
|
}
|