@agentshouse/kit 0.1.0-alpha.25 → 0.1.0-alpha.27
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 +172 -158
- package/bin/connect-linux.sh +15 -4
- package/bin/kit.js +48 -46
- package/bootstrap.json +3 -3
- package/package.json +1 -1
- package/src/adapter-mcp.js +23 -1
- package/src/bridge.js +4 -0
- package/src/configuration.js +13 -209
- package/src/connector-login.js +3 -84
- package/src/contract.js +4 -0
- package/src/delivery.js +4 -7
- package/src/directory.js +6 -26
- package/src/google/calendar.js +39 -45
- package/src/google/drive.js +61 -186
- package/src/google/entries.js +346 -0
- package/src/google/gateway.js +3 -6
- package/src/google/gmail.js +33 -23
- package/src/google/oauth.js +106 -66
- package/src/google/source.js +21 -23
- package/src/house.js +43 -5
- package/src/how-we-work.md +25 -0
- package/src/kit-work-stream.js +1 -1
- package/src/launcher.js +11 -4
- package/src/mcp.js +5 -0
- package/src/setup.js +8 -14
- package/src/skill-set/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/src/skill-set/ask-matt/SKILL.md +91 -0
- package/src/skill-set/ask-matt/agents/openai.yaml +4 -0
- package/src/skill-set/code-review/LICENSE +21 -0
- package/src/skill-set/code-review/SKILL.md +89 -0
- package/src/skill-set/code-review/agents/openai.yaml +3 -0
- package/src/skill-set/codebase-design/DEEPENING.md +37 -0
- package/src/skill-set/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/src/skill-set/codebase-design/LICENSE +21 -0
- package/src/skill-set/codebase-design/SKILL.md +116 -0
- package/src/skill-set/codebase-design/agents/openai.yaml +3 -0
- package/src/skill-set/diagnosing-bugs/LICENSE +21 -0
- package/src/skill-set/diagnosing-bugs/SKILL.md +140 -0
- package/src/skill-set/diagnosing-bugs/agents/openai.yaml +3 -0
- package/src/skill-set/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/src/skill-set/domain-modeling/ADR-FORMAT.md +47 -0
- package/src/skill-set/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/src/skill-set/domain-modeling/LICENSE +21 -0
- package/src/skill-set/domain-modeling/SKILL.md +76 -0
- package/src/skill-set/domain-modeling/agents/openai.yaml +3 -0
- package/src/skill-set/grill-me/LICENSE +21 -0
- package/src/skill-set/grill-me/SKILL.md +8 -0
- package/src/skill-set/grill-me/agents/openai.yaml +4 -0
- package/src/skill-set/grill-with-docs/LICENSE +21 -0
- package/src/skill-set/grill-with-docs/SKILL.md +8 -0
- package/src/skill-set/grill-with-docs/agents/openai.yaml +4 -0
- package/src/skill-set/grilling/LICENSE +21 -0
- package/src/{starter-set → skill-set}/grilling/SKILL.md +1 -1
- package/src/skill-set/handoff/LICENSE +21 -0
- package/src/skill-set/handoff/SKILL.md +17 -0
- package/src/skill-set/handoff/agents/openai.yaml +4 -0
- package/src/skill-set/implement/LICENSE +21 -0
- package/src/skill-set/implement/SKILL.md +16 -0
- package/src/skill-set/implement/agents/openai.yaml +4 -0
- package/src/skill-set/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/src/skill-set/improve-codebase-architecture/LICENSE +21 -0
- package/src/skill-set/improve-codebase-architecture/SKILL.md +72 -0
- package/src/skill-set/improve-codebase-architecture/agents/openai.yaml +4 -0
- package/src/skill-set/prototype/LICENSE +21 -0
- package/src/skill-set/prototype/LOGIC.md +67 -0
- package/src/skill-set/prototype/SKILL.md +28 -0
- package/src/skill-set/prototype/UI.md +112 -0
- package/src/skill-set/prototype/agents/openai.yaml +3 -0
- package/src/skill-set/research/LICENSE +21 -0
- package/src/skill-set/research/SKILL.md +14 -0
- package/src/skill-set/research/agents/openai.yaml +3 -0
- package/src/skill-set/resolving-merge-conflicts/LICENSE +21 -0
- package/src/skill-set/resolving-merge-conflicts/SKILL.md +16 -0
- package/src/skill-set/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/src/skill-set/tdd/LICENSE +21 -0
- package/src/skill-set/tdd/SKILL.md +40 -0
- package/src/skill-set/tdd/agents/openai.yaml +3 -0
- package/src/skill-set/tdd/mocking.md +59 -0
- package/src/skill-set/tdd/tests.md +77 -0
- package/src/skill-set/teach/GLOSSARY-FORMAT.md +35 -0
- package/src/skill-set/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/src/skill-set/teach/LICENSE +21 -0
- package/src/skill-set/teach/MISSION-FORMAT.md +31 -0
- package/src/skill-set/teach/RESOURCES-FORMAT.md +32 -0
- package/src/skill-set/teach/SKILL.md +141 -0
- package/src/skill-set/teach/agents/openai.yaml +4 -0
- package/src/skill-set/to-questionnaire/LICENSE +21 -0
- package/src/skill-set/to-questionnaire/SKILL.md +55 -0
- package/src/skill-set/to-questionnaire/agents/openai.yaml +4 -0
- package/src/skill-set/to-spec/LICENSE +21 -0
- package/src/skill-set/to-spec/SKILL.md +76 -0
- package/src/skill-set/to-spec/agents/openai.yaml +4 -0
- package/src/skill-set/to-tickets/LICENSE +21 -0
- package/src/skill-set/to-tickets/SKILL.md +106 -0
- package/src/skill-set/to-tickets/agents/openai.yaml +4 -0
- package/src/skill-set/wait-what/LICENSE +21 -0
- package/src/skill-set/wait-what/SKILL.md +8 -0
- package/src/skill-set/wait-what/agents/openai.yaml +4 -0
- package/src/skill-set/wayfinder/LICENSE +21 -0
- package/src/skill-set/wayfinder/SKILL.md +129 -0
- package/src/skill-set/wayfinder/agents/openai.yaml +4 -0
- package/src/skill-set/writing-for-agents/LICENSE +21 -0
- package/src/skill-set/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/src/skill-set/writing-for-agents/SKILL.md +83 -0
- package/src/skill-set/writing-for-agents/agents/openai.yaml +3 -0
- package/src/skill-set.js +85 -0
- package/src/source.js +51 -26
- package/src/state.js +19 -1
- package/src/tasks.js +72 -0
- package/src/worker.js +46 -68
- package/src/working-copy.js +1 -15
- package/src/google/declared.js +0 -146
- package/src/google/id.js +0 -1
- package/src/instance/google.js +0 -1
- package/src/starter-set.js +0 -17
- /package/src/{starter-set/grilling → skill-set/ask-matt}/LICENSE +0 -0
- /package/src/{starter-set → skill-set}/grilling/agents/openai.yaml +0 -0
package/src/google/oauth.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createHash, randomBytes, randomInt } from "node:crypto";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
2
|
+
import { readFile, rm } from "node:fs/promises";
|
|
4
3
|
import { KitRefusal } from "../refusal.js";
|
|
5
|
-
import { writeNote } from "../state.js";
|
|
4
|
+
import { notePath, writeNote } from "../state.js";
|
|
5
|
+
import { exclusively } from "../tasks.js";
|
|
6
|
+
|
|
7
|
+
export const GOOGLE_SOURCES = "google";
|
|
6
8
|
|
|
7
9
|
export const GOOGLE_SCOPES = Object.freeze({
|
|
8
10
|
gmail: "https://www.googleapis.com/auth/gmail.readonly",
|
|
@@ -12,26 +14,30 @@ export const GOOGLE_SCOPES = Object.freeze({
|
|
|
12
14
|
|
|
13
15
|
const AUTHORIZATION_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
14
16
|
const TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
|
|
17
|
+
const REVOCATION_ENDPOINT = "https://oauth2.googleapis.com/revoke";
|
|
15
18
|
const REFRESH_MARGIN_MS = 60_000;
|
|
16
19
|
const LOOPBACK_PORT_FLOOR = 49152;
|
|
17
20
|
const LOOPBACK_PORT_SPAN = 16384;
|
|
18
21
|
|
|
19
|
-
function credentialPath(directory,
|
|
20
|
-
return
|
|
22
|
+
function credentialPath(directory, account) {
|
|
23
|
+
return notePath(directory, GOOGLE_SOURCES, account, "credentials");
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
async function
|
|
24
|
-
const path = credentialPath(directory,
|
|
26
|
+
async function rawAccount(directory, account) {
|
|
27
|
+
const path = credentialPath(directory, account);
|
|
25
28
|
let document;
|
|
26
29
|
try {
|
|
27
30
|
document = JSON.parse(await readFile(path, "utf8"));
|
|
28
31
|
} catch (error) {
|
|
29
32
|
if (error.code === "ENOENT") return null;
|
|
30
|
-
throw new KitRefusal("google_authorization_unreadable",
|
|
33
|
+
throw new KitRefusal("google_authorization_unreadable", account);
|
|
31
34
|
}
|
|
32
35
|
if (
|
|
33
36
|
typeof document !== "object" ||
|
|
34
37
|
document === null ||
|
|
38
|
+
typeof document.client?.id !== "string" ||
|
|
39
|
+
typeof document.client.secret !== "string" ||
|
|
40
|
+
(document.email !== null && typeof document.email !== "string") ||
|
|
35
41
|
!Array.isArray(document.grants) ||
|
|
36
42
|
document.grants.some(
|
|
37
43
|
(grant) =>
|
|
@@ -46,21 +52,27 @@ async function rawAuthorization(directory, instance) {
|
|
|
46
52
|
grant.scopes.some((scope) => typeof scope !== "string"),
|
|
47
53
|
)
|
|
48
54
|
) {
|
|
49
|
-
throw new KitRefusal("google_authorization_unreadable",
|
|
55
|
+
throw new KitRefusal("google_authorization_unreadable", account);
|
|
50
56
|
}
|
|
51
57
|
return document;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
function updateAccount(directory, account, change) {
|
|
61
|
+
return exclusively(credentialPath(directory, account), async () => {
|
|
62
|
+
const stored = await rawAccount(directory, account);
|
|
63
|
+
const changed = change(stored);
|
|
64
|
+
if (changed !== null) await writeNote(credentialPath(directory, account), changed);
|
|
65
|
+
});
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
export async function
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
68
|
+
export async function googleAccount(directory, account) {
|
|
69
|
+
const stored = await rawAccount(directory, account);
|
|
70
|
+
if (stored === null) return null;
|
|
61
71
|
return {
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
client: { id: stored.client.id, secret: stored.client.secret },
|
|
73
|
+
email: stored.email,
|
|
74
|
+
scopes: [...new Set(stored.grants.flatMap((grant) => grant.scopes))].sort(),
|
|
75
|
+
grants: stored.grants.map((grant) => ({
|
|
64
76
|
accessToken: grant.access_token,
|
|
65
77
|
refreshToken: grant.refresh_token,
|
|
66
78
|
expiresAt: grant.expires_at,
|
|
@@ -69,6 +81,15 @@ export async function googleAuthorization(directory, instance) {
|
|
|
69
81
|
};
|
|
70
82
|
}
|
|
71
83
|
|
|
84
|
+
export async function googleSignedIn(directory, account, service) {
|
|
85
|
+
const stored = await rawAccount(directory, account);
|
|
86
|
+
return stored?.grants.some((grant) => grant.scopes.includes(GOOGLE_SCOPES[service])) === true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function recordGoogleEmail(directory, account, email) {
|
|
90
|
+
return updateAccount(directory, account, (stored) => (stored === null ? null : { ...stored, email }));
|
|
91
|
+
}
|
|
92
|
+
|
|
72
93
|
function requiredScopesOf(value) {
|
|
73
94
|
if (
|
|
74
95
|
!Array.isArray(value) ||
|
|
@@ -80,19 +101,51 @@ function requiredScopesOf(value) {
|
|
|
80
101
|
return value;
|
|
81
102
|
}
|
|
82
103
|
|
|
83
|
-
export async function revokeGoogleAuthorization(directory,
|
|
104
|
+
export async function revokeGoogleAuthorization(directory, account, scopes) {
|
|
84
105
|
const requiredScopes = requiredScopesOf(scopes);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
await updateAccount(directory, account, (stored) =>
|
|
107
|
+
stored === null
|
|
108
|
+
? null
|
|
109
|
+
: {
|
|
110
|
+
...stored,
|
|
111
|
+
grants: stored.grants
|
|
112
|
+
.map((grant) => ({
|
|
113
|
+
...grant,
|
|
114
|
+
scopes: grant.scopes.filter((scope) => !requiredScopes.includes(scope)),
|
|
115
|
+
}))
|
|
116
|
+
.filter((grant) => grant.scopes.length > 0),
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function revokedAtProvider(fetcher, token) {
|
|
122
|
+
let response;
|
|
123
|
+
try {
|
|
124
|
+
response = await fetcher(REVOCATION_ENDPOINT, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
127
|
+
body: new URLSearchParams({ token }).toString(),
|
|
94
128
|
});
|
|
129
|
+
} catch {
|
|
130
|
+
throw new KitRefusal("google_provider_unavailable");
|
|
95
131
|
}
|
|
132
|
+
if (response.status !== 200 && response.status !== 400) {
|
|
133
|
+
throw new KitRefusal("google_provider_unavailable");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function forgetGoogleAccount(directory, account, kept, dependencies = {}) {
|
|
138
|
+
const stored = await rawAccount(directory, account);
|
|
139
|
+
if (stored === null) return;
|
|
140
|
+
const others = await Promise.all(kept.map((other) => rawAccount(directory, other)));
|
|
141
|
+
if (stored.email === null || !others.some((held) => held?.email === stored.email)) {
|
|
142
|
+
for (const grant of stored.grants) {
|
|
143
|
+
await revokedAtProvider(dependencies.fetch ?? fetch, grant.refresh_token);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
await exclusively(credentialPath(directory, account), () =>
|
|
147
|
+
rm(credentialPath(directory, account), { force: true }),
|
|
148
|
+
);
|
|
96
149
|
}
|
|
97
150
|
|
|
98
151
|
function oauthValue() {
|
|
@@ -167,26 +220,9 @@ async function tokenRequest(fetcher, body) {
|
|
|
167
220
|
return answer;
|
|
168
221
|
}
|
|
169
222
|
|
|
170
|
-
function configuredClient(client) {
|
|
171
|
-
if (
|
|
172
|
-
typeof client?.id !== "string" ||
|
|
173
|
-
client.id.length === 0 ||
|
|
174
|
-
typeof client.secret !== "string" ||
|
|
175
|
-
client.secret.length === 0
|
|
176
|
-
) {
|
|
177
|
-
throw new KitRefusal("google_oauth_client_unconfigured");
|
|
178
|
-
}
|
|
179
|
-
return client;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
223
|
export async function authorizeGoogle(options, dependencies = {}) {
|
|
183
|
-
const client =
|
|
184
|
-
const stored = await rawAuthorization(options.directory, options.instance);
|
|
224
|
+
const { client } = options;
|
|
185
225
|
const scopes = [...new Set(options.scopes)];
|
|
186
|
-
const covered = stored?.grants.some((grant) =>
|
|
187
|
-
scopes.every((scope) => grant.scopes.includes(scope)),
|
|
188
|
-
);
|
|
189
|
-
if (covered === true) return { status: "skipped", requestedScopes: [] };
|
|
190
226
|
const verifier = oauthValue();
|
|
191
227
|
const state = oauthValue();
|
|
192
228
|
const redirectUri = loopbackRedirect(dependencies.loopbackPort);
|
|
@@ -215,10 +251,11 @@ export async function authorizeGoogle(options, dependencies = {}) {
|
|
|
215
251
|
}
|
|
216
252
|
const grantedScopes = [...new Set(returnedScopes.length === 0 ? scopes : returnedScopes)].sort();
|
|
217
253
|
const key = grantedScopes.join("\n");
|
|
218
|
-
|
|
219
|
-
|
|
254
|
+
await updateAccount(options.directory, options.account, (stored) => ({
|
|
255
|
+
client: { id: client.id, secret: client.secret },
|
|
256
|
+
email: stored?.email ?? null,
|
|
220
257
|
grants: [
|
|
221
|
-
...grants,
|
|
258
|
+
...(stored?.grants ?? []).filter((grant) => [...grant.scopes].sort().join("\n") !== key),
|
|
222
259
|
{
|
|
223
260
|
access_token: token.access_token,
|
|
224
261
|
refresh_token: refreshToken,
|
|
@@ -226,48 +263,51 @@ export async function authorizeGoogle(options, dependencies = {}) {
|
|
|
226
263
|
scopes: grantedScopes,
|
|
227
264
|
},
|
|
228
265
|
],
|
|
229
|
-
});
|
|
230
|
-
return { status: "ready", requestedScopes: scopes };
|
|
266
|
+
}));
|
|
231
267
|
}
|
|
232
268
|
|
|
233
269
|
export async function googleAccessToken(options, dependencies = {}) {
|
|
234
|
-
const stored = await
|
|
270
|
+
const stored = await rawAccount(options.directory, options.account);
|
|
235
271
|
const requiredScopes = requiredScopesOf(options.requiredScopes);
|
|
236
272
|
const grant = stored?.grants
|
|
237
273
|
.filter((candidate) => requiredScopes.every((scope) => candidate.scopes.includes(scope)))
|
|
238
274
|
.sort((left, right) => left.scopes.length - right.scopes.length)[0];
|
|
239
275
|
if (grant === undefined) {
|
|
240
|
-
throw new KitRefusal("google_authorization_required", options.
|
|
276
|
+
throw new KitRefusal("google_authorization_required", options.account);
|
|
241
277
|
}
|
|
242
278
|
const now = dependencies.now?.() ?? new Date();
|
|
243
279
|
if (options.forceRefresh !== true && Date.parse(grant.expires_at) - now.getTime() > REFRESH_MARGIN_MS) {
|
|
244
280
|
return grant.access_token;
|
|
245
281
|
}
|
|
246
|
-
const client = configuredClient(options.client);
|
|
247
282
|
let token;
|
|
248
283
|
try {
|
|
249
284
|
token = await tokenRequest(dependencies.fetch ?? fetch, {
|
|
250
|
-
client_id: client.id,
|
|
251
|
-
client_secret: client.secret,
|
|
285
|
+
client_id: stored.client.id,
|
|
286
|
+
client_secret: stored.client.secret,
|
|
252
287
|
refresh_token: grant.refresh_token,
|
|
253
288
|
grant_type: "refresh_token",
|
|
254
289
|
});
|
|
255
290
|
} catch (error) {
|
|
256
291
|
if (error instanceof KitRefusal && error.code === "google_authority_revoked") {
|
|
257
|
-
await revokeGoogleAuthorization(options.directory, options.
|
|
292
|
+
await revokeGoogleAuthorization(options.directory, options.account, grant.scopes);
|
|
258
293
|
}
|
|
259
294
|
throw error;
|
|
260
295
|
}
|
|
261
|
-
await
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
296
|
+
await updateAccount(options.directory, options.account, (current) =>
|
|
297
|
+
current === null
|
|
298
|
+
? null
|
|
299
|
+
: {
|
|
300
|
+
...current,
|
|
301
|
+
grants: current.grants.map((candidate) =>
|
|
302
|
+
candidate.refresh_token === grant.refresh_token
|
|
303
|
+
? {
|
|
304
|
+
...candidate,
|
|
305
|
+
access_token: token.access_token,
|
|
306
|
+
expires_at: new Date(now.getTime() + token.expires_in * 1000).toISOString(),
|
|
307
|
+
}
|
|
308
|
+
: candidate,
|
|
309
|
+
),
|
|
310
|
+
},
|
|
311
|
+
);
|
|
272
312
|
return token.access_token;
|
|
273
313
|
}
|
package/src/google/source.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { declaredPage } from "./declared.js";
|
|
1
|
+
import { calendarEmail, calendarPage } from "./calendar.js";
|
|
2
|
+
import { driveEmail, drivePage } from "./drive.js";
|
|
3
|
+
import { gmailEmail, gmailPage } from "./gmail.js";
|
|
4
|
+
import { googleAccount, recordGoogleEmail } from "./oauth.js";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new KitRefusal("google_service_unsupported", options.service.service);
|
|
6
|
+
const SERVICES = {
|
|
7
|
+
gmail: { page: gmailPage, email: gmailEmail },
|
|
8
|
+
calendar: { page: calendarPage, email: calendarEmail },
|
|
9
|
+
drive: { page: drivePage, email: driveEmail },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function googlePage(options, dependencies = {}) {
|
|
13
|
+
return SERVICES[options.service].page(options, dependencies);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function recordAccountEmail(context, google) {
|
|
17
|
+
if ((await googleAccount(context.directory, google.account))?.email !== null) return;
|
|
18
|
+
const email = await SERVICES[google.service].email(
|
|
19
|
+
{ directory: context.directory, account: google.account, signal: context.signal },
|
|
20
|
+
context.dependencies,
|
|
21
|
+
);
|
|
22
|
+
await recordGoogleEmail(context.directory, google.account, email);
|
|
25
23
|
}
|
package/src/house.js
CHANGED
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
KIT_SESSIONS_REPORT_PATH,
|
|
25
25
|
KIT_SETUP_ACQUIRE_PATH,
|
|
26
26
|
KIT_SETUP_REPORT_PATH,
|
|
27
|
+
KIT_SOURCES_DESIRED_PATH,
|
|
28
|
+
KIT_SOURCES_REPORT_PATH,
|
|
27
29
|
KIT_WORKSPACES_ACQUIRE_PATH,
|
|
28
30
|
LEASE_RENEWAL_MARGIN_MS,
|
|
29
31
|
MCP_PROTOCOL_VERSION,
|
|
@@ -172,7 +174,7 @@ async function residentRelay(session, request, signal, draining) {
|
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
export async function serveResident(session, directory, signal, drain, push) {
|
|
177
|
+
export async function serveResident(session, directory, signal, drain, push, capture) {
|
|
176
178
|
const socket = residentSocket(directory);
|
|
177
179
|
await mkdir(dirname(socket), { recursive: true, mode: 0o700 });
|
|
178
180
|
await rm(socket, { force: true });
|
|
@@ -231,9 +233,14 @@ export async function serveResident(session, directory, signal, drain, push) {
|
|
|
231
233
|
relayed.set(request.id, cancelled);
|
|
232
234
|
const relaySignal = AbortSignal.any([signal, cancelled.signal]);
|
|
233
235
|
const answered =
|
|
234
|
-
request.push
|
|
235
|
-
?
|
|
236
|
-
:
|
|
236
|
+
request.push !== undefined
|
|
237
|
+
? push(request.push, relaySignal).then((pushed) => ({ pushed }))
|
|
238
|
+
: request.capture !== undefined
|
|
239
|
+
? capture(request.capture, relaySignal).then(
|
|
240
|
+
(captured) => ({ captured }),
|
|
241
|
+
(error) => ({ refused: error?.code ?? "kit_resident_unavailable" }),
|
|
242
|
+
)
|
|
243
|
+
: residentRelay(session, request, relaySignal, draining);
|
|
237
244
|
void answered.then((answer) => {
|
|
238
245
|
relayed.delete(request.id);
|
|
239
246
|
if (!connection.destroyed) writeFrame(connection, { id: request.id, ...answer });
|
|
@@ -330,6 +337,12 @@ async function residentDelegation(directory, fetcher) {
|
|
|
330
337
|
if (answer.pushed === undefined) throw new KitRefusal("kit_resident_unavailable");
|
|
331
338
|
return answer.pushed;
|
|
332
339
|
}
|
|
340
|
+
async function capture(source, signal) {
|
|
341
|
+
const answer = await exchange({ capture: source }, signal);
|
|
342
|
+
if (answer.refused !== undefined) throw new KitRefusal(answer.refused);
|
|
343
|
+
if (answer.captured === undefined) throw new KitRefusal("kit_resident_unavailable");
|
|
344
|
+
return answer.captured;
|
|
345
|
+
}
|
|
333
346
|
async function delegated(url, init = {}) {
|
|
334
347
|
const { authorization, ...headers } = init.headers ?? {};
|
|
335
348
|
if (authorization !== RESIDENT) return fetcher(url, init);
|
|
@@ -352,7 +365,7 @@ async function residentDelegation(directory, fetcher) {
|
|
|
352
365
|
headers: answer.type === null ? {} : { "content-type": answer.type },
|
|
353
366
|
});
|
|
354
367
|
}
|
|
355
|
-
return { connection, fetch: delegated, push };
|
|
368
|
+
return { connection, fetch: delegated, push, capture };
|
|
356
369
|
}
|
|
357
370
|
|
|
358
371
|
export async function openSession(options, dependencies = {}) {
|
|
@@ -372,6 +385,7 @@ export async function openSession(options, dependencies = {}) {
|
|
|
372
385
|
if (resident !== null) {
|
|
373
386
|
session.resident = resident.connection;
|
|
374
387
|
session.push = resident.push;
|
|
388
|
+
session.capture = resident.capture;
|
|
375
389
|
session.dependencies = { ...dependencies, fetch: resident.fetch };
|
|
376
390
|
return session;
|
|
377
391
|
}
|
|
@@ -695,6 +709,30 @@ export async function desiredAgents(session, signal = session.signal) {
|
|
|
695
709
|
return answer.agents;
|
|
696
710
|
}
|
|
697
711
|
|
|
712
|
+
export async function desiredSources(session, signal = session.signal) {
|
|
713
|
+
const answer = await houseRequest(
|
|
714
|
+
session.house,
|
|
715
|
+
await heldControl(session, signal),
|
|
716
|
+
KIT_SOURCES_DESIRED_PATH,
|
|
717
|
+
{},
|
|
718
|
+
session.dependencies,
|
|
719
|
+
signal,
|
|
720
|
+
);
|
|
721
|
+
if (!Array.isArray(answer?.sources)) throw new KitRefusal("kit_sources_rejected");
|
|
722
|
+
return answer.sources;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export async function reportSources(session, sources, signal = session.signal) {
|
|
726
|
+
return houseRequest(
|
|
727
|
+
session.house,
|
|
728
|
+
await heldControl(session, signal),
|
|
729
|
+
KIT_SOURCES_REPORT_PATH,
|
|
730
|
+
{ sources },
|
|
731
|
+
session.dependencies,
|
|
732
|
+
signal,
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
|
|
698
736
|
const HOUSE_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
699
737
|
|
|
700
738
|
export async function acquireSetup(session, signal = session.signal) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# How we work
|
|
2
|
+
|
|
3
|
+
A Room is where information people share is kept; it is not the place for
|
|
4
|
+
private information. Work goes into the Room it belongs to, or the First Room
|
|
5
|
+
when none is named. Read and write Rooms with the `house` CLI.
|
|
6
|
+
|
|
7
|
+
The skills are already set up; never run `setup-matt-pocock-skills`.
|
|
8
|
+
|
|
9
|
+
## Where skill output goes
|
|
10
|
+
|
|
11
|
+
- Glossary (`CONTEXT.md`): `library/glossary.md`
|
|
12
|
+
- Decisions (ADRs): `library/decisions/NNNN-<slug>.md`
|
|
13
|
+
- Plan (spec): `library/projects/<name>/plan.md`
|
|
14
|
+
- Tasks (tickets): `library/projects/<name>/tasks/NN-<slug>.md`, with a
|
|
15
|
+
`Status:` line (`needs-triage`, `needs-info`, `ready-for-agent`,
|
|
16
|
+
`ready-for-human`, `wontfix`), a `Blocked by:` line and comments under
|
|
17
|
+
`## Comments`
|
|
18
|
+
- Map (Wayfinding): `library/projects/<name>/map.md`, its tasks under
|
|
19
|
+
`tasks/` with `Type:`, `Status: claimed|resolved` and `Blocked by:` lines
|
|
20
|
+
- Research: `library/research/<slug>.md`
|
|
21
|
+
- Questionnaires: `library/questionnaires/<slug>.md`
|
|
22
|
+
- Learning: `library/learning/<topic>/`
|
|
23
|
+
- Files a person should open, such as HTML pages, are uploaded to the Room and
|
|
24
|
+
linked from the document they belong to; a prototype is one HTML file with
|
|
25
|
+
every variant on one page.
|
package/src/kit-work-stream.js
CHANGED
|
@@ -5,7 +5,7 @@ import { heldControl } from "./house.js";
|
|
|
5
5
|
import { KitRefusal } from "./refusal.js";
|
|
6
6
|
|
|
7
7
|
const PROTOCOL = "house.kit.stream.1";
|
|
8
|
-
const WATCHED_SUBJECTS = ["agents", "working_copy"];
|
|
8
|
+
const WATCHED_SUBJECTS = ["agents", "working_copy", "sources"];
|
|
9
9
|
|
|
10
10
|
function streamAddress(house) {
|
|
11
11
|
const url = new URL("/kit/stream", house);
|
package/src/launcher.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
commandHouseCreateHowWeWork,
|
|
4
|
+
commandHouseHowWeWork,
|
|
5
|
+
commandHouseInstructions,
|
|
6
|
+
} from "./adapter-mcp.js";
|
|
3
7
|
import {
|
|
4
8
|
compiledContract,
|
|
5
9
|
initializeCommandAdapter,
|
|
@@ -129,8 +133,11 @@ async function configureSession(acp, contract, sessionId, adapter) {
|
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
|
|
132
|
-
async function sessionOpening(bridge,
|
|
133
|
-
|
|
136
|
+
async function sessionOpening(channel, bridge, start) {
|
|
137
|
+
if (start.create_how_we_work === true && (await commandHouseCreateHowWeWork(bridge))) {
|
|
138
|
+
channel.send({ type: "how_we_work" });
|
|
139
|
+
}
|
|
140
|
+
const parts = [HOUSE_CLI_LINE, start.base_instructions, await commandHouseHowWeWork(bridge)];
|
|
134
141
|
return [{ type: "text", text: parts.filter((part) => part.trim() !== "").join("\n\n") }];
|
|
135
142
|
}
|
|
136
143
|
|
|
@@ -185,7 +192,7 @@ async function runTurn(channel, start, bridge, turn) {
|
|
|
185
192
|
const instructions = await commandHouseInstructions(bridge);
|
|
186
193
|
let providerSessionId = start.provider_session ?? null;
|
|
187
194
|
const opening =
|
|
188
|
-
providerSessionId === null ? await sessionOpening(bridge, start
|
|
195
|
+
providerSessionId === null ? await sessionOpening(channel, bridge, start) : [];
|
|
189
196
|
const setup = { cwd: start.working_directory, mcpServers: [] };
|
|
190
197
|
if (providerSessionId === null) {
|
|
191
198
|
providerSessionId = openedSession(await acp.request("session/new", setup));
|
package/src/mcp.js
CHANGED
|
@@ -82,3 +82,8 @@ export function answerYaml(text) {
|
|
|
82
82
|
return null;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
export function editRefusal(text) {
|
|
87
|
+
const conflicts = answerYaml(text.slice(text.indexOf("\n") + 1))?.conflicts;
|
|
88
|
+
return { code: text.split(":")[0].trim(), conflicts: Array.isArray(conflicts) ? conflicts : null };
|
|
89
|
+
}
|
package/src/setup.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
updateDeclaredAgent,
|
|
7
7
|
} from "./agents.js";
|
|
8
8
|
import { readConfiguration } from "./configuration.js";
|
|
9
|
-
import {
|
|
9
|
+
import { customAuthorizationStatus } from "./custom/authorization.js";
|
|
10
10
|
import { GUIDED_LOGIN_TIMEOUT_MS } from "./contract.js";
|
|
11
11
|
import { launchBase, prepareLaunchBase } from "./directory.js";
|
|
12
12
|
import {
|
|
@@ -45,24 +45,14 @@ function agentModule(context, kind) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function connectorModule(context, instance) {
|
|
48
|
-
const gateway = connectorLogin(instance, context.dependencies);
|
|
49
48
|
return {
|
|
50
49
|
category: "connector",
|
|
51
50
|
name: instance.id,
|
|
52
51
|
login: { integration: instance.preset, instance: instance.id, service: instance.id },
|
|
53
52
|
install: null,
|
|
54
53
|
signedIn: () =>
|
|
55
|
-
|
|
56
|
-
guided:
|
|
57
|
-
gateway.guided === undefined
|
|
58
|
-
? null
|
|
59
|
-
: ({ present, signal }) =>
|
|
60
|
-
gateway.guided(instance, {
|
|
61
|
-
directory: context.directory,
|
|
62
|
-
dependencies: context.dependencies,
|
|
63
|
-
present,
|
|
64
|
-
signal,
|
|
65
|
-
}),
|
|
54
|
+
customAuthorizationStatus(instance, { directory: context.directory, signal: context.signal }),
|
|
55
|
+
guided: null,
|
|
66
56
|
};
|
|
67
57
|
}
|
|
68
58
|
|
|
@@ -144,8 +134,12 @@ async function setUpModule(context, module, install = true) {
|
|
|
144
134
|
return summary("ready");
|
|
145
135
|
}
|
|
146
136
|
|
|
137
|
+
export function signInModule(context, module) {
|
|
138
|
+
return setUpModule(context, module, false);
|
|
139
|
+
}
|
|
140
|
+
|
|
147
141
|
export function signInWantedAgent(context, kind) {
|
|
148
|
-
return
|
|
142
|
+
return signInModule(context, agentModule(context, kind));
|
|
149
143
|
}
|
|
150
144
|
|
|
151
145
|
export async function runSetup(context, request) {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Phase boundaries
|
|
2
|
+
|
|
3
|
+
A **phase** is a chunk of work inside a session: the grilling, the implementation, the QA. The definition is fuzzy on purpose: a phase ends when you think *"ok, we're done with that"*.
|
|
4
|
+
|
|
5
|
+
The **phase boundary** is the gap between two phases, and it is the only place this decision belongs. Mid-phase there is no decision to make: continue, or split the work that's left into subagents. Compacting mid-phase makes the agent lose the thread.
|
|
6
|
+
|
|
7
|
+
## The five options
|
|
8
|
+
|
|
9
|
+
| Option | What it does |
|
|
10
|
+
| ------------ | --------------------------------------------------------------- |
|
|
11
|
+
| **Continue** | Stay in the session. No context switch at all. |
|
|
12
|
+
| **`/clear`** | Empty the context window and start from nothing. |
|
|
13
|
+
| **`/handoff`** | Write a portable markdown file and seed a session anywhere with it. |
|
|
14
|
+
| **Subagent** | Send the task to its own context window and get a report back. |
|
|
15
|
+
| **`/compact`** | Compress this context and seed a fresh session with the summary. |
|
|
16
|
+
|
|
17
|
+
## The tree
|
|
18
|
+
|
|
19
|
+
Work top to bottom at the boundary. The first **yes** wins.
|
|
20
|
+
|
|
21
|
+
**1. Can you continue in this session?** Two things make the answer yes: the next phase needs this phase as a **primary source**, or you have enough [smart zone](https://www.aihero.dev/ai-coding-dictionary/smart-zone) left (~150k tokens) for the next phase to fit. Grilling → implementation is the standard yes: the implementation wants the reasoning verbatim, not a summary of it. Continue costs nothing and loses nothing, so rule it out before anything else.
|
|
22
|
+
|
|
23
|
+
**2. Is the context irrelevant to what comes next?** Is everything in this session (the exploration, the decisions, the dead ends) disposable? If so, **`/clear`**. It is the cheapest move on the board: it takes no time and hands back the whole window. `/clear` also isn't terminal: the old session stays resumable.
|
|
24
|
+
|
|
25
|
+
The cost of getting this wrong is one-way. Clear a *relevant* context and you lose the **why** behind what you built, and no amount of reading the diff back gets it returned.
|
|
26
|
+
|
|
27
|
+
**3. Do you need to hand off?** `/handoff` is narrow. You need it only when you are:
|
|
28
|
+
|
|
29
|
+
- swapping to a **new harness** (Claude → Codex),
|
|
30
|
+
- moving to a **new directory** or repo,
|
|
31
|
+
- sending the work to a **colleague**,
|
|
32
|
+
- or forking a side task you found **mid-phase** without derailing what you're doing.
|
|
33
|
+
|
|
34
|
+
That list is the whole clause. What `/handoff` buys is **portability**: a file that travels. If nothing is travelling, you don't need it.
|
|
35
|
+
|
|
36
|
+
**4. Can the task be done AFK?** Is it scoped tightly enough to run with you away from the keyboard, no steering? Then send it to a **subagent** and leave this session untouched. Automated review is the standard case: the agent reads the diff and reports, and you aren't needed while it does.
|
|
37
|
+
|
|
38
|
+
**5. Otherwise, `/compact`.** Relevant context, same harness, same directory, and you need to stay in the loop: this is where the tree lands, and it lands here often. Pass it an instruction (`/compact we're going to QA this area`) so the summary keeps what the next phase needs.
|
|
39
|
+
|
|
40
|
+
`/compact` is the **default, not the first reach**. It sits at the bottom because the four questions above it are all cheaper or more precise. The failure mode when people start here is a fresh session that is confidently wrong about a decision the summary flattened.
|
|
41
|
+
|
|
42
|
+
## Primary and secondary sources
|
|
43
|
+
|
|
44
|
+
Every move except **Continue** turns a **primary source** into a **secondary source**: the session as it happened, replaced by a summary of it. The trade is always the same shape:
|
|
45
|
+
|
|
46
|
+
| Source | Information | Noise | Room to move |
|
|
47
|
+
| --------------------------------- | ----------- | ----- | ------------ |
|
|
48
|
+
| Primary (Continue) | Full | Lots | Little |
|
|
49
|
+
| Secondary (`/compact`, `/handoff`) | Lossy | Less | Lots |
|
|
50
|
+
|
|
51
|
+
This is why question 1 comes first. You only pay the lossiness when staying costs more than it saves.
|
|
52
|
+
|
|
53
|
+
## These are judgement calls
|
|
54
|
+
|
|
55
|
+
The questions are not objective: each has taste in it, and the same boundary can go two ways on two days. The value is in asking them **in order**, at the boundary rather than in the middle of the work.
|