@agentshouse/kit 0.2.1-ca18b01951c3b → 0.2.1-caf8b8e5a324f
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 +14 -14
- package/dist/agents.js +16 -3
- package/dist/api.js +1 -1
- package/dist/app-git.js +10 -26
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +2 -5
- package/dist/chatgpt.js +4 -1
- package/dist/clis.js +9 -0
- package/dist/conversations.js +69 -22
- package/dist/copies.js +50 -25
- package/dist/end.js +3 -2
- package/dist/events.js +3 -0
- package/dist/git.js +2 -3
- package/dist/home.js +27 -13
- package/dist/house-cli.js +291 -0
- package/dist/house-main.js +7 -289
- package/dist/instructions.js +2 -1
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -67
- package/dist/login.js +14 -5
- package/dist/logout.js +0 -2
- package/dist/placement.js +2 -20
- package/dist/resident.js +51 -10
- package/dist/stream.js +1 -1
- package/dist/work.js +3 -5
- package/package.json +1 -1
package/dist/resident.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { once } from 'node:events';
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { createServer } from 'node:http';
|
|
4
|
+
import { createServer, get } from 'node:http';
|
|
5
5
|
import { dirname, extname, join } from 'node:path';
|
|
6
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { Agents } from './agents.js';
|
|
8
9
|
import { house } from './api.js';
|
|
@@ -10,7 +11,7 @@ import { received } from './bridge.js';
|
|
|
10
11
|
import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
|
|
11
12
|
import { LocalCopies } from './copies.js';
|
|
12
13
|
import { restart } from './end.js';
|
|
13
|
-
import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
|
|
14
|
+
import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
|
|
14
15
|
import { killDescendants } from './scope.js';
|
|
15
16
|
import { quoted } from './shell.js';
|
|
16
17
|
import { SignIns } from './sign-in.js';
|
|
@@ -29,13 +30,32 @@ async function installShim(path, module) {
|
|
|
29
30
|
await mkdir(dirname(path), { recursive: true });
|
|
30
31
|
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
31
32
|
}
|
|
33
|
+
function claimed(lock) {
|
|
34
|
+
try {
|
|
35
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error.errcode === 5)
|
|
40
|
+
return false;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
32
44
|
async function serveOwner(copies) {
|
|
33
|
-
const
|
|
34
|
-
|
|
45
|
+
const lock = new DatabaseSync(ownerLock());
|
|
46
|
+
if (!claimed(lock)) {
|
|
47
|
+
lock.close();
|
|
48
|
+
const running = await runningResident();
|
|
49
|
+
throw new Error(`${running === null ? 'another Kit' : `Kit ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another here`);
|
|
50
|
+
}
|
|
35
51
|
const server = createServer(async (request, response) => {
|
|
36
52
|
try {
|
|
37
53
|
const text = await received(request);
|
|
38
54
|
let answered;
|
|
55
|
+
if (request.url === '/resident') {
|
|
56
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
39
59
|
if (request.url === '/git/fetch') {
|
|
40
60
|
answered = await copies.fetch();
|
|
41
61
|
}
|
|
@@ -53,9 +73,23 @@ async function serveOwner(copies) {
|
|
|
53
73
|
response.writeHead(502).end(error instanceof Error ? error.message : String(error));
|
|
54
74
|
}
|
|
55
75
|
});
|
|
56
|
-
server.
|
|
76
|
+
server.on('close', () => lock.close());
|
|
77
|
+
await rm(ownerSocket(), { force: true });
|
|
78
|
+
server.listen(ownerSocket());
|
|
57
79
|
await once(server, 'listening');
|
|
58
80
|
}
|
|
81
|
+
function runningResident() {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
get({ socketPath: ownerSocket(), path: '/resident' }, (answer) => {
|
|
84
|
+
received(answer).then((text) => resolve(JSON.parse(text).pid), reject);
|
|
85
|
+
}).on('error', (error) => {
|
|
86
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
87
|
+
resolve(null);
|
|
88
|
+
else
|
|
89
|
+
reject(error);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
59
93
|
function connected() {
|
|
60
94
|
return new Promise((resolve) => {
|
|
61
95
|
const watcher = watch(kitHome(), () => {
|
|
@@ -72,7 +106,7 @@ function connected() {
|
|
|
72
106
|
resolve();
|
|
73
107
|
});
|
|
74
108
|
}
|
|
75
|
-
|
|
109
|
+
async function started() {
|
|
76
110
|
await connected();
|
|
77
111
|
await forgetRestart();
|
|
78
112
|
watch(kitHome(), () => {
|
|
@@ -83,13 +117,20 @@ export async function resident() {
|
|
|
83
117
|
});
|
|
84
118
|
await placeSkillSet();
|
|
85
119
|
await mkdir(agentBase(), { recursive: true });
|
|
86
|
-
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
87
|
-
const agents = new Agents(house, () => changed());
|
|
88
|
-
const copies = new LocalCopies(house);
|
|
89
|
-
await copies.load();
|
|
90
120
|
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
91
121
|
await installShim(codexLauncher(), 'codex-main');
|
|
122
|
+
}
|
|
123
|
+
export async function resident() {
|
|
124
|
+
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
125
|
+
const copies = new LocalCopies(house);
|
|
126
|
+
await copies.load();
|
|
92
127
|
await serveOwner(copies);
|
|
128
|
+
await started().catch((error) => {
|
|
129
|
+
report(error);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
|
132
|
+
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
133
|
+
const agents = new Agents(house, () => changed());
|
|
93
134
|
let stream = null;
|
|
94
135
|
let reported = false;
|
|
95
136
|
const idle = () => conversations.idle() && signIns.idle() && agents.idle();
|
package/dist/stream.js
CHANGED
|
@@ -81,7 +81,7 @@ export function holdStream(handlers) {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
if (refused !== null && tooOld(refused.text))
|
|
84
|
-
updateRequired(
|
|
84
|
+
updateRequired();
|
|
85
85
|
if (finalRefusal(refused))
|
|
86
86
|
end(refused.message);
|
|
87
87
|
// A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused as retryable or left unanswered backs off on the jittered curve.
|
package/dist/work.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { once } from 'node:events';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
-
import {
|
|
4
|
+
import { rm } from 'node:fs/promises';
|
|
5
5
|
import { createServer } from 'node:net';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { RUNNING_JOB } from './events.js';
|
|
8
|
-
import { kitHome } from './home.js';
|
|
8
|
+
import { kitHome, socketDirectory } from './home.js';
|
|
9
9
|
const ENDED_TASK = new Set(['completed', 'failed', 'killed']);
|
|
10
10
|
const SCHEDULING = new Set(['CronCreate', 'CronDelete', 'ScheduleWakeup']);
|
|
11
11
|
const QUEUE_LIST = 'house-kit-queue-';
|
|
@@ -194,9 +194,7 @@ class CodexWork extends Work {
|
|
|
194
194
|
proving = -1;
|
|
195
195
|
proven = -1;
|
|
196
196
|
async open(cli) {
|
|
197
|
-
|
|
198
|
-
await mkdir(sockets, { recursive: true, mode: 0o700 });
|
|
199
|
-
this.path = join(sockets, `${randomUUID()}.sock`);
|
|
197
|
+
this.path = join(socketDirectory(), `${randomUUID()}.sock`);
|
|
200
198
|
this.server = createServer((socket) => this.connected(socket));
|
|
201
199
|
this.server.listen(this.path);
|
|
202
200
|
await once(this.server, 'listening');
|