@agentshouse/kit 0.2.1-ccb257fa8a318 → 0.2.1-ccffb3f637815
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 +27 -31
- package/dist/acp.js +17 -10
- package/dist/afk.js +17 -0
- package/dist/agents.js +121 -52
- package/dist/api.js +11 -6
- package/dist/binaries.js +89 -0
- package/dist/bridge.js +28 -27
- package/dist/building.js +7 -3
- package/dist/calls.js +18 -1
- package/dist/chunks.js +49 -0
- package/dist/clis.js +52 -63
- package/dist/connect.js +108 -0
- package/dist/connection.js +24 -20
- package/dist/content.js +106 -0
- package/dist/conversations.js +255 -134
- package/dist/copies.js +748 -248
- package/dist/earlier.js +263 -0
- package/dist/end.js +9 -6
- package/dist/events.js +549 -281
- package/dist/files.js +77 -11
- package/dist/git-main.js +24 -29
- package/dist/git.js +87 -12
- package/dist/grok.js +39 -0
- package/dist/home.js +80 -29
- package/dist/house-cli.js +106 -123
- 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/mcp.js +38 -3
- package/dist/old-references.js +27 -0
- package/dist/owner.js +46 -0
- package/dist/placement.js +9 -23
- package/dist/refusals.js +37 -21
- package/dist/resident.js +107 -72
- package/dist/scope.js +12 -4
- package/dist/scripts.js +59 -11
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +188 -0
- package/dist/sign-in.js +49 -4
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +5 -2
- package/dist/translate.js +18 -11
- package/dist/update.js +115 -160
- package/dist/wire.js +19 -9
- package/dist/work.js +27 -2
- package/dist/workspace.js +103 -0
- package/package.json +13 -8
- package/dist/authority-main.js +0 -22
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -55
package/dist/connection.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { KIT_CONNECTION_PATH, KIT_CONNECTION_PROTOCOL_PREFIX, KIT_WIRE, } from '@agentshouse/kit-wire';
|
|
1
2
|
import { subscribe } from 'node:diagnostics_channel';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
4
|
import { HouseRefusal, retryDelay } from './api.js';
|
|
3
5
|
import { end, REPLACED, signInAgain } from './end.js';
|
|
4
6
|
import { readEnrolment } from './home.js';
|
|
5
7
|
import { relayed } from './relay.js';
|
|
6
8
|
import { Silence } from './silence.js';
|
|
7
|
-
import { endUnserved,
|
|
8
|
-
const
|
|
9
|
-
const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
|
|
9
|
+
import { endUnserved, unserved } from './wire.js';
|
|
10
|
+
const SUBPROTOCOL = `${KIT_CONNECTION_PROTOCOL_PREFIX}${KIT_WIRE}`;
|
|
10
11
|
const REFUSAL_HEADER = 'x-house-refusal';
|
|
11
12
|
// House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
|
|
12
13
|
export const CONNECTION_SILENCE_MS = 60_000;
|
|
14
|
+
// A stopping Kit waits up to two seconds for House to answer its close, so what it sent last reaches House and a House that does not answer holds no stop.
|
|
15
|
+
const CLOSE_ANSWER_MS = 2_000;
|
|
13
16
|
function connectionUrl(house) {
|
|
14
|
-
const url = new URL(
|
|
17
|
+
const url = new URL(KIT_CONNECTION_PATH, house);
|
|
15
18
|
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
16
19
|
return url;
|
|
17
20
|
}
|
|
@@ -25,18 +28,18 @@ function header(headers, name) {
|
|
|
25
28
|
let refused = null;
|
|
26
29
|
subscribe('undici:request:headers', (message) => {
|
|
27
30
|
const { request, response } = message;
|
|
28
|
-
if (!request.path.endsWith(
|
|
31
|
+
if (!request.path.endsWith(KIT_CONNECTION_PATH))
|
|
29
32
|
return;
|
|
30
|
-
refused = new HouseRefusal(
|
|
33
|
+
refused = new HouseRefusal(KIT_CONNECTION_PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
|
|
31
34
|
});
|
|
32
35
|
export function holdConnection(handlers) {
|
|
33
36
|
let connection = null;
|
|
34
37
|
let socket = null;
|
|
35
|
-
let paused = false;
|
|
36
38
|
let failures = 0;
|
|
39
|
+
let stopping = false;
|
|
37
40
|
const connect = async () => {
|
|
38
41
|
const { house, credential } = (await readEnrolment());
|
|
39
|
-
if (
|
|
42
|
+
if (socket !== null || unserved() || stopping)
|
|
40
43
|
return;
|
|
41
44
|
refused = null;
|
|
42
45
|
const opening = new WebSocket(relayed(connectionUrl(house)), {
|
|
@@ -55,6 +58,8 @@ export function holdConnection(handlers) {
|
|
|
55
58
|
connection = null;
|
|
56
59
|
handlers.closed();
|
|
57
60
|
process.stderr.write(`kit: connection closed ${event.code} ${event.reason}\n`);
|
|
61
|
+
if (stopping)
|
|
62
|
+
return;
|
|
58
63
|
if (event.reason === 'replaced')
|
|
59
64
|
end(REPLACED);
|
|
60
65
|
if (event.reason === 'credential_rejected' || refused?.status === 401) {
|
|
@@ -65,8 +70,6 @@ export function holdConnection(handlers) {
|
|
|
65
70
|
endUnserved(refused.text);
|
|
66
71
|
if (!opened && refused !== null)
|
|
67
72
|
process.stderr.write(`kit: ${refused.message}\n`);
|
|
68
|
-
if (paused)
|
|
69
|
-
return;
|
|
70
73
|
// A closed connection reopens in one to three seconds, spread so Kit processes one restart closed return apart; an opening House refused or left unanswered backs off on the jittered curve, retryable or not, since a resident outlives a House deploy.
|
|
71
74
|
setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
|
|
72
75
|
};
|
|
@@ -91,26 +94,27 @@ export function holdConnection(handlers) {
|
|
|
91
94
|
if (arrived.type === 'input')
|
|
92
95
|
handlers.call(arrived);
|
|
93
96
|
else if (arrived.type !== 'beat')
|
|
94
|
-
handlers.
|
|
97
|
+
handlers.oneWayCall(arrived);
|
|
95
98
|
};
|
|
96
99
|
opening.onerror = () => undefined;
|
|
97
100
|
opening.onclose = closed;
|
|
98
101
|
};
|
|
99
102
|
void connect();
|
|
100
103
|
return {
|
|
101
|
-
send(
|
|
104
|
+
send(oneWayCall) {
|
|
102
105
|
if (connection === null || connection.readyState !== WebSocket.OPEN)
|
|
103
106
|
return false;
|
|
104
|
-
connection.send(JSON.stringify(
|
|
107
|
+
connection.send(JSON.stringify(oneWayCall));
|
|
105
108
|
return true;
|
|
106
109
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
socket
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
close() {
|
|
111
|
+
stopping = true;
|
|
112
|
+
const open = socket;
|
|
113
|
+
if (open === null)
|
|
114
|
+
return Promise.resolve();
|
|
115
|
+
const answered = new Promise((resolve) => open.addEventListener('close', () => resolve(), { once: true }));
|
|
116
|
+
open.close();
|
|
117
|
+
return Promise.race([answered, delay(CLOSE_ANSWER_MS)]);
|
|
114
118
|
},
|
|
115
119
|
};
|
|
116
120
|
}
|
package/dist/content.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { applied } from '@agentshouse/session-content';
|
|
2
|
+
function filesOf(files) {
|
|
3
|
+
const held = new Map();
|
|
4
|
+
for (const { path, added, removed } of files) {
|
|
5
|
+
const before = held.get(path);
|
|
6
|
+
held.set(path, { added: (before?.added ?? 0) + added, removed: (before?.removed ?? 0) + removed });
|
|
7
|
+
}
|
|
8
|
+
return held;
|
|
9
|
+
}
|
|
10
|
+
function none() {
|
|
11
|
+
return { type: 'counts', commands: 0, edited: 0, other: 0, added: 0, removed: 0, failed: 0 };
|
|
12
|
+
}
|
|
13
|
+
export class Content {
|
|
14
|
+
parts = [];
|
|
15
|
+
emit;
|
|
16
|
+
calls = new Map();
|
|
17
|
+
writing = null;
|
|
18
|
+
stretch = null;
|
|
19
|
+
constructor(emit) {
|
|
20
|
+
this.emit = emit;
|
|
21
|
+
}
|
|
22
|
+
holds(key) {
|
|
23
|
+
return this.calls.has(key);
|
|
24
|
+
}
|
|
25
|
+
write(id, text) {
|
|
26
|
+
if (text === '')
|
|
27
|
+
return;
|
|
28
|
+
if (this.writing !== null && this.writing.id === id) {
|
|
29
|
+
this.apply({ op: 'append', index: this.writing.index, text });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.stretch = null;
|
|
33
|
+
this.writing = { id, index: this.started({ type: 'text', text }) };
|
|
34
|
+
}
|
|
35
|
+
add(part) {
|
|
36
|
+
this.writing = null;
|
|
37
|
+
this.started(part);
|
|
38
|
+
}
|
|
39
|
+
arrived(part) {
|
|
40
|
+
this.started(part);
|
|
41
|
+
}
|
|
42
|
+
call(key, parent, called) {
|
|
43
|
+
const held = this.calls.get(key);
|
|
44
|
+
if (held !== undefined) {
|
|
45
|
+
held.files = filesOf(called.files);
|
|
46
|
+
held.failed = called.failed;
|
|
47
|
+
this.settle(this.tally());
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (parent !== null && !this.calls.has(parent))
|
|
51
|
+
return;
|
|
52
|
+
if (parent === null)
|
|
53
|
+
this.writing = null;
|
|
54
|
+
const stretch = parent === null ? this.stretch : this.calls.get(parent).stretch;
|
|
55
|
+
const at = stretch ?? this.parts.length;
|
|
56
|
+
this.calls.set(key, { stretch: at, kind: called.kind, files: filesOf(called.files), failed: called.failed });
|
|
57
|
+
const tallied = this.tally();
|
|
58
|
+
if (stretch === null)
|
|
59
|
+
this.stretch = this.started(tallied.get(at));
|
|
60
|
+
this.settle(tallied);
|
|
61
|
+
}
|
|
62
|
+
operations() {
|
|
63
|
+
return this.parts.map((part, index) => ({ op: 'start', index, part }));
|
|
64
|
+
}
|
|
65
|
+
tally() {
|
|
66
|
+
const stretches = new Map();
|
|
67
|
+
const first = new Set();
|
|
68
|
+
for (const call of this.calls.values()) {
|
|
69
|
+
const counts = stretches.get(call.stretch) ?? none();
|
|
70
|
+
stretches.set(call.stretch, counts);
|
|
71
|
+
if (call.kind === 'command')
|
|
72
|
+
counts.commands += 1;
|
|
73
|
+
if (call.kind === 'other')
|
|
74
|
+
counts.other += 1;
|
|
75
|
+
if (call.failed)
|
|
76
|
+
counts.failed += 1;
|
|
77
|
+
if (call.kind !== 'edit')
|
|
78
|
+
continue;
|
|
79
|
+
if (call.files.size === 0)
|
|
80
|
+
counts.edited += 1;
|
|
81
|
+
for (const [path, lines] of call.files) {
|
|
82
|
+
if (!first.has(path))
|
|
83
|
+
counts.edited += 1;
|
|
84
|
+
first.add(path);
|
|
85
|
+
counts.added += lines.added;
|
|
86
|
+
counts.removed += lines.removed;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return stretches;
|
|
90
|
+
}
|
|
91
|
+
settle(tallied) {
|
|
92
|
+
for (const [index, counts] of tallied) {
|
|
93
|
+
if (JSON.stringify(counts) !== JSON.stringify(this.parts[index]))
|
|
94
|
+
this.apply({ op: 'set', index, part: counts });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
started(part) {
|
|
98
|
+
const index = this.parts.length;
|
|
99
|
+
this.apply({ op: 'start', index, part });
|
|
100
|
+
return index;
|
|
101
|
+
}
|
|
102
|
+
apply(operation) {
|
|
103
|
+
this.parts = applied(this.parts, operation);
|
|
104
|
+
this.emit(operation);
|
|
105
|
+
}
|
|
106
|
+
}
|