@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-ce46b2b55463f
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 +46 -49
- package/dist/acp.js +101 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +252 -73
- package/dist/api.js +43 -6
- package/dist/app-git.js +48 -0
- package/dist/binaries.js +79 -0
- package/dist/bridge.js +62 -79
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +171 -102
- package/dist/codex-main.js +58 -0
- package/dist/connect.js +108 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +816 -335
- package/dist/copies.js +842 -309
- package/dist/earlier.js +263 -0
- package/dist/end.js +26 -0
- package/dist/events.js +793 -0
- package/dist/files.js +206 -18
- package/dist/git-main.js +24 -29
- package/dist/git.js +95 -18
- package/dist/grok.js +39 -0
- package/dist/home.js +134 -9
- package/dist/house-cli.js +282 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +7 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +133 -104
- package/dist/logout.js +15 -14
- package/dist/mcp.js +42 -3
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +43 -15
- package/dist/relay.js +33 -2
- package/dist/resident.js +161 -61
- package/dist/scope.js +214 -0
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +4 -3
- package/dist/settings.js +188 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +85 -33
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +131 -40
- package/dist/translate.js +19 -16
- package/dist/update.js +119 -100
- package/dist/wire.js +32 -0
- package/dist/work.js +353 -0
- package/dist/workspace.js +103 -0
- package/package.json +26 -21
- package/dist/authority-main.js +0 -22
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -4
- package/dist/stream.js +0 -47
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/settings.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { access, mkdir, readdir, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { house } from './api.js';
|
|
5
|
+
import { earlierPrefix, enrolled, kitHome, readDisconnected, oneFolder, readConfiguration, readEnrolment, readHome, storedConfiguration, workspaceRoot, writeConfiguration, writeHome, } from './home.js';
|
|
6
|
+
import { askOwner, holdOwner } from './owner.js';
|
|
7
|
+
import { placeSkillSet } from './skills.js';
|
|
8
|
+
import { followRoot, merged, present, within } from './workspace.js';
|
|
9
|
+
const FOLDERS = ['agents', 'local-copies'];
|
|
10
|
+
const RECORDS = join('local-copies', 'rooms');
|
|
11
|
+
const MOVE = 'workspace-move.json';
|
|
12
|
+
const WORKING = 'an Agent is working; change the workspace once its turn ends';
|
|
13
|
+
const LOGGED_OUT = "Kit is logged out, so it cannot tell which Agents' folders their owners chose; run kit login, then change its workspace";
|
|
14
|
+
export const SETTINGS_USAGE = 'usage: kit settings [skills on|off | workspace <absolute path>]';
|
|
15
|
+
export async function enrolledRoutes() {
|
|
16
|
+
if (enrolled())
|
|
17
|
+
return (await house.act('agents/desired/list', {})).routes;
|
|
18
|
+
return (await readDisconnected()) === null ? [] : null;
|
|
19
|
+
}
|
|
20
|
+
const IDLE = { working: () => false, end: () => undefined, routes: enrolledRoutes };
|
|
21
|
+
export async function heldSettings() {
|
|
22
|
+
return { skills: (await readConfiguration()).skills, workspace: workspaceRoot() };
|
|
23
|
+
}
|
|
24
|
+
function records() {
|
|
25
|
+
return join(kitHome(), RECORDS);
|
|
26
|
+
}
|
|
27
|
+
function placing(kept) {
|
|
28
|
+
return (source, entry) => {
|
|
29
|
+
if ((dirname(source) === records() && entry.isFile()) || kept.includes(source))
|
|
30
|
+
return 'stays';
|
|
31
|
+
return [records(), ...kept].some((folder) => within(folder, source)) ? 'opens' : 'moves';
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function causeOf(error) {
|
|
35
|
+
return error instanceof Error ? error.message : String(error);
|
|
36
|
+
}
|
|
37
|
+
async function recordsOnly(folder) {
|
|
38
|
+
const entries = await readdir(folder);
|
|
39
|
+
if (entries.some((name) => name !== 'rooms'))
|
|
40
|
+
return false;
|
|
41
|
+
if (entries.length === 0)
|
|
42
|
+
return true;
|
|
43
|
+
return (await readdir(join(folder, 'rooms'), { withFileTypes: true })).every((entry) => entry.isFile());
|
|
44
|
+
}
|
|
45
|
+
async function writable(root) {
|
|
46
|
+
for (let at = root;; at = dirname(at)) {
|
|
47
|
+
const found = await stat(at).catch((error) => {
|
|
48
|
+
if (error.code === 'ENOENT')
|
|
49
|
+
return null;
|
|
50
|
+
throw error;
|
|
51
|
+
});
|
|
52
|
+
if (found !== null) {
|
|
53
|
+
return found.isDirectory() && access(at, constants.W_OK | constants.X_OK).then(() => true, () => false);
|
|
54
|
+
}
|
|
55
|
+
if (dirname(at) === at)
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function refusedRoot(from, to) {
|
|
60
|
+
for (const name of FOLDERS) {
|
|
61
|
+
const moving = join(from, name);
|
|
62
|
+
if (within(to, moving))
|
|
63
|
+
return `${to} is inside ${moving}, which the change moves`;
|
|
64
|
+
}
|
|
65
|
+
if (!(await writable(to)))
|
|
66
|
+
return `this account cannot write ${to}`;
|
|
67
|
+
for (const name of FOLDERS) {
|
|
68
|
+
const held = join(to, name);
|
|
69
|
+
if ((await present(held)) === null)
|
|
70
|
+
continue;
|
|
71
|
+
if (name === 'local-copies' && to === kitHome() && (await recordsOnly(held)))
|
|
72
|
+
continue;
|
|
73
|
+
return `${to} already holds ${held}`;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async function forward({ from, to, kept = [] }) {
|
|
78
|
+
await mkdir(to, { recursive: true, mode: 0o700 });
|
|
79
|
+
for (const name of FOLDERS)
|
|
80
|
+
await merged(join(from, name), join(to, name), placing(kept));
|
|
81
|
+
await followRoot(records(), from, to, kept);
|
|
82
|
+
await writeConfiguration({ ...(await storedConfiguration()), workspace: to });
|
|
83
|
+
await rm(join(kitHome(), MOVE), { force: true });
|
|
84
|
+
}
|
|
85
|
+
async function backward({ from, to, kept = [] }) {
|
|
86
|
+
for (const name of FOLDERS)
|
|
87
|
+
await merged(join(to, name), join(from, name), placing([]));
|
|
88
|
+
await followRoot(records(), to, from, kept);
|
|
89
|
+
await rm(join(kitHome(), MOVE), { force: true });
|
|
90
|
+
}
|
|
91
|
+
async function finished(move) {
|
|
92
|
+
try {
|
|
93
|
+
await forward(move);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const cause = causeOf(error);
|
|
98
|
+
try {
|
|
99
|
+
await backward(move);
|
|
100
|
+
return cause;
|
|
101
|
+
}
|
|
102
|
+
catch (again) {
|
|
103
|
+
return `${cause}; its folders could not all go back to ${move.from} (${causeOf(again)}), so Kit moves them again when it next starts`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export async function resumeWorkspaceMove() {
|
|
108
|
+
const move = await readHome(MOVE);
|
|
109
|
+
if (move === null)
|
|
110
|
+
return;
|
|
111
|
+
process.stderr.write(`kit: moving the workspace ${move.from} to ${move.to}, as a change that did not finish asked\n`);
|
|
112
|
+
const failure = await finished(move);
|
|
113
|
+
if (failure !== null)
|
|
114
|
+
process.stderr.write(`kit: the workspace could not be moved to ${move.to}: ${failure}\n`);
|
|
115
|
+
}
|
|
116
|
+
async function changeSkills(on) {
|
|
117
|
+
const stored = await storedConfiguration();
|
|
118
|
+
await writeConfiguration({ ...stored, skills: on });
|
|
119
|
+
const enrolment = await readEnrolment();
|
|
120
|
+
if (enrolment !== null)
|
|
121
|
+
await placeSkillSet(enrolment.house);
|
|
122
|
+
}
|
|
123
|
+
export async function applySettings(change, kit) {
|
|
124
|
+
const from = workspaceRoot();
|
|
125
|
+
let move = null;
|
|
126
|
+
if (change.workspace !== undefined) {
|
|
127
|
+
if (earlierPrefix() !== null) {
|
|
128
|
+
return { refused: `Kit runs where an earlier install placed it; its workspace changes once Kit moves into ${oneFolder()}`, ended: false };
|
|
129
|
+
}
|
|
130
|
+
if (!isAbsolute(change.workspace))
|
|
131
|
+
return { refused: `${change.workspace} is not an absolute path`, ended: false };
|
|
132
|
+
const to = resolve(change.workspace);
|
|
133
|
+
if (to !== from) {
|
|
134
|
+
const refused = await refusedRoot(from, to);
|
|
135
|
+
if (refused !== null)
|
|
136
|
+
return { refused, ended: false };
|
|
137
|
+
const routes = await kit.routes();
|
|
138
|
+
if (routes === null)
|
|
139
|
+
return { refused: LOGGED_OUT, ended: false };
|
|
140
|
+
const agents = join(from, 'agents');
|
|
141
|
+
const copies = join(from, 'local-copies');
|
|
142
|
+
const kept = routes
|
|
143
|
+
.filter(({ agent_id, working_directory }) => resolve(working_directory) !== join(agents, agent_id))
|
|
144
|
+
.map(({ working_directory }) => resolve(working_directory))
|
|
145
|
+
.filter((folder) => folder.startsWith(`${agents}/`) || folder.startsWith(`${copies}/`));
|
|
146
|
+
move = { from, to, kept };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (move !== null) {
|
|
150
|
+
if (kit.working())
|
|
151
|
+
return { refused: WORKING, ended: false };
|
|
152
|
+
kit.end();
|
|
153
|
+
await writeHome(MOVE, move);
|
|
154
|
+
const failure = await finished(move);
|
|
155
|
+
if (failure !== null)
|
|
156
|
+
return { refused: `the workspace could not be moved to ${move.to}: ${failure}`, ended: true };
|
|
157
|
+
}
|
|
158
|
+
if (change.skills !== undefined)
|
|
159
|
+
await changeSkills(change.skills);
|
|
160
|
+
return { settings: await heldSettings(), moved: move !== null };
|
|
161
|
+
}
|
|
162
|
+
function changeOf(operands) {
|
|
163
|
+
const [name, value, ...rest] = operands;
|
|
164
|
+
if (name === undefined)
|
|
165
|
+
return null;
|
|
166
|
+
if (rest.length === 0 && name === 'skills' && (value === 'on' || value === 'off'))
|
|
167
|
+
return { skills: value === 'on' };
|
|
168
|
+
if (rest.length === 0 && name === 'workspace' && value !== undefined)
|
|
169
|
+
return { workspace: value };
|
|
170
|
+
throw new Error(SETTINGS_USAGE);
|
|
171
|
+
}
|
|
172
|
+
async function appliedHere(change) {
|
|
173
|
+
const lock = await holdOwner();
|
|
174
|
+
try {
|
|
175
|
+
await resumeWorkspaceMove();
|
|
176
|
+
return await applySettings(change, IDLE);
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
lock.close();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export async function kitSettings(operands) {
|
|
183
|
+
const change = changeOf(operands);
|
|
184
|
+
const answer = change === null ? { settings: await heldSettings(), moved: false } : ((await askOwner('/settings', change)) ?? (await appliedHere(change)));
|
|
185
|
+
if ('refused' in answer)
|
|
186
|
+
throw new Error(answer.refused);
|
|
187
|
+
process.stdout.write(`skills ${answer.settings.skills ? 'on' : 'off'}\nworkspace ${answer.settings.workspace}\n`);
|
|
188
|
+
}
|
package/dist/shell.js
ADDED
package/dist/sign-in.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { CLIS, cliEnvironment } from './clis.js';
|
|
4
|
+
import { killTree } from './scope.js';
|
|
5
5
|
import { holdSecretInput } from './secret-input.js';
|
|
6
6
|
const ESCAPE = /\u001b\[[\d;]*m/g;
|
|
7
7
|
const LINK = /https:\/\/\S+/;
|
|
@@ -9,53 +9,104 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
|
|
|
9
9
|
function causeOf(error) {
|
|
10
10
|
return error instanceof Error ? error.message : String(error);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function keySteps(name) {
|
|
13
|
+
return [
|
|
14
|
+
{ kind: 'collect', label: 'API key', name: 'key' },
|
|
15
|
+
{
|
|
16
|
+
kind: 'collect',
|
|
17
|
+
label: 'Endpoint, for another provider',
|
|
18
|
+
name: 'endpoint',
|
|
19
|
+
description: `Leave Endpoint empty for ${name}’s own. Both stay on this computer.`,
|
|
20
|
+
optional: true,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
function endpointOf(given) {
|
|
25
|
+
const endpoint = given.trim();
|
|
26
|
+
if (endpoint === '')
|
|
27
|
+
return null;
|
|
28
|
+
let protocol;
|
|
29
|
+
try {
|
|
30
|
+
protocol = new URL(endpoint).protocol;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
protocol = '';
|
|
34
|
+
}
|
|
35
|
+
if (protocol !== 'https:' && protocol !== 'http:')
|
|
36
|
+
throw new Error('the endpoint is no http or https address');
|
|
37
|
+
return endpoint;
|
|
38
|
+
}
|
|
39
|
+
function endOf(signal) {
|
|
40
|
+
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
14
41
|
}
|
|
15
42
|
export class SignIns {
|
|
16
43
|
house;
|
|
17
44
|
agents;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
constructor(house, agents, changed) {
|
|
45
|
+
calls;
|
|
46
|
+
constructor(house, agents, calls) {
|
|
21
47
|
this.house = house;
|
|
22
48
|
this.agents = agents;
|
|
23
|
-
this.
|
|
49
|
+
this.calls = calls;
|
|
24
50
|
}
|
|
25
|
-
|
|
26
|
-
|
|
51
|
+
start(call) {
|
|
52
|
+
void this.calls.carry(call.input_id, () => this.signIn(call));
|
|
27
53
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
async signIn(call) {
|
|
55
|
+
const ending = new AbortController();
|
|
56
|
+
// House stops waiting for a sign-in ten minutes after it wrote it and sends the seconds left, so its install and login end with the page.
|
|
57
|
+
const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
|
|
58
|
+
const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
if (ended)
|
|
61
|
+
process.stderr.write(`kit: the ${call.cli} sign-in reached the end House set for it\n`);
|
|
62
|
+
return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
|
|
63
|
+
}
|
|
64
|
+
async signedIn(call, signal) {
|
|
65
|
+
await (call.api_key === true ? this.keyed(call, signal) : this.login(call, signal));
|
|
66
|
+
if (!signal.aborted)
|
|
67
|
+
await this.agents.recheck(call.cli, signal);
|
|
68
|
+
return false;
|
|
42
69
|
}
|
|
43
|
-
async
|
|
70
|
+
async keyed(call, signal) {
|
|
71
|
+
const { name, key } = CLIS[call.cli];
|
|
72
|
+
let secret = '';
|
|
73
|
+
try {
|
|
74
|
+
const cli = await this.agents.located(call.cli, signal);
|
|
75
|
+
const given = await holdSecretInput(this.house, call.input_id, keySteps(name), () => !signal.aborted);
|
|
76
|
+
if (given === null || signal.aborted)
|
|
77
|
+
return;
|
|
78
|
+
secret = given.key.trim();
|
|
79
|
+
await key.write(secret, endpointOf(given.endpoint), cli, signal);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const cause = secret === '' ? causeOf(error) : causeOf(error).replaceAll(secret, 'the key');
|
|
83
|
+
if (!signal.aborted)
|
|
84
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${cause}\n`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async login(call, signal) {
|
|
44
88
|
let cli;
|
|
89
|
+
let env;
|
|
45
90
|
try {
|
|
46
|
-
cli = await this.agents.located(
|
|
91
|
+
cli = await this.agents.located(call.cli, signal);
|
|
92
|
+
env = await cliEnvironment(call.cli);
|
|
47
93
|
}
|
|
48
94
|
catch (error) {
|
|
49
|
-
|
|
95
|
+
if (!signal.aborted)
|
|
96
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
|
|
50
97
|
return;
|
|
51
98
|
}
|
|
52
|
-
|
|
99
|
+
if (signal.aborted)
|
|
100
|
+
return;
|
|
101
|
+
const login = CLIS[call.cli].login;
|
|
53
102
|
const child = spawn(cli, login.args, {
|
|
54
103
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
55
104
|
detached: true,
|
|
56
|
-
env
|
|
105
|
+
env,
|
|
57
106
|
});
|
|
58
107
|
const running = () => child.exitCode === null && child.signalCode === null;
|
|
108
|
+
const stop = () => killTree(child);
|
|
109
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
59
110
|
let link;
|
|
60
111
|
let code;
|
|
61
112
|
let last = '';
|
|
@@ -79,7 +130,7 @@ export class SignIns {
|
|
|
79
130
|
return;
|
|
80
131
|
held = true;
|
|
81
132
|
const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
|
|
82
|
-
void holdSecretInput(this.house,
|
|
133
|
+
void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
|
|
83
134
|
if (!running())
|
|
84
135
|
return;
|
|
85
136
|
if (content === null)
|
|
@@ -92,9 +143,10 @@ export class SignIns {
|
|
|
92
143
|
createInterface({ input: output }).on('line', read);
|
|
93
144
|
const failed = await new Promise((resolve) => {
|
|
94
145
|
child.on('error', (error) => resolve(error.message));
|
|
95
|
-
child.on('close', (status,
|
|
146
|
+
child.on('close', (status, killed) => resolve(status === 0 ? null : `exited with ${status ?? killed}${last ? `: ${last}` : ''}`));
|
|
96
147
|
});
|
|
97
|
-
|
|
98
|
-
|
|
148
|
+
signal.removeEventListener('abort', stop);
|
|
149
|
+
if (failed !== null && !signal.aborted)
|
|
150
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
|
|
99
151
|
}
|
|
100
152
|
}
|
package/dist/silence.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const SYSTEM_CLOCK = {
|
|
2
|
+
later: (delay, callback) => setTimeout(callback, delay),
|
|
3
|
+
clear: (timer) => clearTimeout(timer),
|
|
4
|
+
};
|
|
5
|
+
export class Silence {
|
|
6
|
+
timer = null;
|
|
7
|
+
interval;
|
|
8
|
+
silent;
|
|
9
|
+
clock;
|
|
10
|
+
constructor(interval, silent, clock = SYSTEM_CLOCK) {
|
|
11
|
+
this.interval = interval;
|
|
12
|
+
this.silent = silent;
|
|
13
|
+
this.clock = clock;
|
|
14
|
+
}
|
|
15
|
+
heard() {
|
|
16
|
+
this.stop();
|
|
17
|
+
this.timer = this.clock.later(this.interval, () => {
|
|
18
|
+
this.timer = null;
|
|
19
|
+
this.silent();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
stop() {
|
|
23
|
+
if (this.timer === null)
|
|
24
|
+
return;
|
|
25
|
+
this.clock.clear(this.timer);
|
|
26
|
+
this.timer = null;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/skills.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cp, lstat, mkdir, readdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { cp, lstat, mkdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
3
2
|
import { homedir } from 'node:os';
|
|
4
3
|
import { join, relative } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { GUIDE, listSkills } from '@agentshouse/skills';
|
|
5
|
+
import { parse } from 'yaml';
|
|
6
|
+
import { KIT_RELEASE } from './clis.js';
|
|
7
7
|
import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
|
|
8
|
-
import { refusalOf } from './refusals.js';
|
|
9
|
-
export const HOW_WE_WORK = '/rooms/private/how-we-work.md';
|
|
10
|
-
const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
|
|
11
|
-
const HOW_WE_WORK_TEXT = readFileSync(new URL('../how-we-work.md', import.meta.url), 'utf8');
|
|
12
8
|
const RECORD = 'skill-set.json';
|
|
13
|
-
const
|
|
14
|
-
const
|
|
9
|
+
const ENTRY = 'SKILL.md';
|
|
10
|
+
const FRONTMATTER = /^---\n([\s\S]*?)\n---\n/u;
|
|
11
|
+
const ORIGIN = '<origin>';
|
|
15
12
|
function skillsDirectory() {
|
|
16
13
|
return join(homedir(), '.agents', 'skills');
|
|
17
14
|
}
|
|
@@ -29,50 +26,67 @@ async function present(path) {
|
|
|
29
26
|
throw error;
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
function skillName(text) {
|
|
30
|
+
const front = FRONTMATTER.exec(text);
|
|
31
|
+
const fields = (front === null ? null : parse(front[1]));
|
|
32
|
+
return typeof fields?.name === 'string' && typeof fields.description === 'string' ? fields.name : undefined;
|
|
33
|
+
}
|
|
34
|
+
function skillSet(origin) {
|
|
35
|
+
const upstream = listSkills().map(({ name, directory }) => ({
|
|
36
|
+
name,
|
|
37
|
+
place: (destination) => cp(directory, destination, { recursive: true }),
|
|
38
|
+
}));
|
|
39
|
+
const pages = GUIDE.flatMap(({ text }) => {
|
|
40
|
+
const name = skillName(text);
|
|
41
|
+
if (name === undefined)
|
|
42
|
+
return [];
|
|
43
|
+
const place = async (destination) => {
|
|
44
|
+
await mkdir(destination);
|
|
45
|
+
await writeFile(join(destination, ENTRY), text.replaceAll(ORIGIN, origin));
|
|
46
|
+
};
|
|
47
|
+
return [{ name, place }];
|
|
48
|
+
});
|
|
49
|
+
return [...upstream, ...pages].sort((left, right) => (left.name < right.name ? -1 : 1));
|
|
50
|
+
}
|
|
51
|
+
async function install(origin) {
|
|
52
|
+
const placed = [];
|
|
53
|
+
for (const skill of skillSet(origin)) {
|
|
54
|
+
if (!(await present(join(skillsDirectory(), skill.name))) && !(await present(join(claudeDirectory(), skill.name)))) {
|
|
55
|
+
placed.push(skill);
|
|
37
56
|
}
|
|
38
57
|
}
|
|
58
|
+
const names = placed.map((skill) => skill.name);
|
|
39
59
|
await writeHome(RECORD, { names });
|
|
40
60
|
await mkdir(skillsDirectory(), { recursive: true });
|
|
41
61
|
await mkdir(claudeDirectory(), { recursive: true });
|
|
42
62
|
const skills = await realpath(skillsDirectory());
|
|
43
63
|
const claude = await realpath(claudeDirectory());
|
|
44
|
-
for (const name of
|
|
45
|
-
await
|
|
64
|
+
for (const { name, place } of placed) {
|
|
65
|
+
await place(join(skillsDirectory(), name));
|
|
46
66
|
if (claude !== skills)
|
|
47
67
|
await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
|
|
48
68
|
}
|
|
49
|
-
await writeHome(RECORD, { version:
|
|
69
|
+
await writeHome(RECORD, { version: KIT_RELEASE, origin, names });
|
|
70
|
+
}
|
|
71
|
+
export async function placeSkillSet(origin) {
|
|
72
|
+
try {
|
|
73
|
+
await replaceSkillSet(origin);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
77
|
+
}
|
|
50
78
|
}
|
|
51
|
-
|
|
79
|
+
async function replaceSkillSet(origin) {
|
|
52
80
|
const accepted = (await readConfiguration()).skills;
|
|
53
81
|
const installed = await readHome(RECORD);
|
|
54
|
-
if (accepted && installed?.version ===
|
|
82
|
+
if (accepted && installed?.version === KIT_RELEASE && installed.origin === origin)
|
|
55
83
|
return;
|
|
56
84
|
for (const name of installed?.names ?? []) {
|
|
57
85
|
await rm(join(claudeDirectory(), name), { recursive: true, force: true });
|
|
58
86
|
await rm(join(skillsDirectory(), name), { recursive: true, force: true });
|
|
59
87
|
}
|
|
60
88
|
if (accepted)
|
|
61
|
-
await install();
|
|
89
|
+
await install(origin);
|
|
62
90
|
else
|
|
63
91
|
await rm(join(kitHome(), RECORD), { force: true });
|
|
64
92
|
}
|
|
65
|
-
export async function createHowWeWork(bridge) {
|
|
66
|
-
if ((await readHome(RECORD)) === null || (await present(join(kitHome(), CREATED))))
|
|
67
|
-
return;
|
|
68
|
-
const created = await bridge.tool('edit', { changes: [{ op: 'create', path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
|
|
69
|
-
if (created.isError === true) {
|
|
70
|
-
const text = created.content.map((content) => content.text).join('\n');
|
|
71
|
-
const refusal = refusalOf(text);
|
|
72
|
-
if (UNWRITABLE.has(refusal?.code ?? ''))
|
|
73
|
-
return;
|
|
74
|
-
if (refusal?.code !== 'edit_conflict' || !refusal.conflicts.includes('path_exists'))
|
|
75
|
-
throw new Error(text);
|
|
76
|
-
}
|
|
77
|
-
await writeFile(join(kitHome(), CREATED), '');
|
|
78
|
-
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
|
+
import { oneFolder } from './home.js';
|
|
8
|
+
const SERVICE = 'house-kit';
|
|
9
|
+
const UNIT = `${SERVICE}.service`;
|
|
10
|
+
// launchctl, loginctl and systemctl answer at once and lingering starts the account's service manager within a second, so ten seconds only bound a stuck one.
|
|
11
|
+
const MANAGER_MS = 10_000;
|
|
12
|
+
// The service manager lingering starts answers within a second, so a check every tenth of a second starts Kit as soon as it does.
|
|
13
|
+
const MANAGER_CHECK_MS = 100;
|
|
14
|
+
// A Kit that failed restarts after five seconds, back soon without spinning on a failure that repeats; a Kit that ended itself stays stopped.
|
|
15
|
+
const RESTART_SECONDS = 5;
|
|
16
|
+
export function userUnit() {
|
|
17
|
+
return join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'systemd', 'user', UNIT);
|
|
18
|
+
}
|
|
19
|
+
export function launchAgent() {
|
|
20
|
+
return join(homedir(), 'Library', 'LaunchAgents', `${SERVICE}.plist`);
|
|
21
|
+
}
|
|
22
|
+
export function launcher() {
|
|
23
|
+
return join(oneFolder(), 'bin', 'kit');
|
|
24
|
+
}
|
|
25
|
+
export function systemd() {
|
|
26
|
+
return existsSync('/run/systemd/system');
|
|
27
|
+
}
|
|
28
|
+
function userBus() {
|
|
29
|
+
if (process.env.XDG_RUNTIME_DIR)
|
|
30
|
+
return process.env;
|
|
31
|
+
return { ...process.env, XDG_RUNTIME_DIR: `/run/user/${process.getuid()}` };
|
|
32
|
+
}
|
|
33
|
+
export function manage(command, args) {
|
|
34
|
+
return spawnSync(command, args, { encoding: 'utf8', timeout: MANAGER_MS, env: command === 'systemctl' ? userBus() : process.env });
|
|
35
|
+
}
|
|
36
|
+
export function required(command, args, failed) {
|
|
37
|
+
const ran = manage(command, args);
|
|
38
|
+
if (ran.status === 0)
|
|
39
|
+
return;
|
|
40
|
+
const cause = ran.error?.message ?? (ran.stderr.trim() || `${command} exited with ${ran.status ?? 'a signal'}`);
|
|
41
|
+
throw new Error(`${failed}: ${cause}`);
|
|
42
|
+
}
|
|
43
|
+
function unitWord(text) {
|
|
44
|
+
return `"${text.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('%', '%%')}"`;
|
|
45
|
+
}
|
|
46
|
+
function xmlText(text) {
|
|
47
|
+
return text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
48
|
+
}
|
|
49
|
+
function unitText() {
|
|
50
|
+
return `[Unit]
|
|
51
|
+
Description=Kit
|
|
52
|
+
|
|
53
|
+
[Service]
|
|
54
|
+
ExecStart=${unitWord(launcher())} resident
|
|
55
|
+
Restart=on-failure
|
|
56
|
+
RestartSec=${RESTART_SECONDS}
|
|
57
|
+
Delegate=yes
|
|
58
|
+
OOMPolicy=continue
|
|
59
|
+
|
|
60
|
+
[Install]
|
|
61
|
+
WantedBy=default.target
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
function plistText() {
|
|
65
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
66
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
67
|
+
<plist version="1.0">
|
|
68
|
+
<dict>
|
|
69
|
+
\t<key>Label</key>
|
|
70
|
+
\t<string>${SERVICE}</string>
|
|
71
|
+
\t<key>ProgramArguments</key>
|
|
72
|
+
\t<array>
|
|
73
|
+
\t\t<string>${xmlText(launcher())}</string>
|
|
74
|
+
\t\t<string>resident</string>
|
|
75
|
+
\t</array>
|
|
76
|
+
\t<key>RunAtLoad</key>
|
|
77
|
+
\t<true/>
|
|
78
|
+
\t<key>KeepAlive</key>
|
|
79
|
+
\t<dict>
|
|
80
|
+
\t\t<key>SuccessfulExit</key>
|
|
81
|
+
\t\t<false/>
|
|
82
|
+
\t</dict>
|
|
83
|
+
\t<key>ProcessType</key>
|
|
84
|
+
\t<string>Interactive</string>
|
|
85
|
+
\t<key>StandardErrorPath</key>
|
|
86
|
+
\t<string>${xmlText(join(oneFolder(), 'kit.log'))}</string>
|
|
87
|
+
</dict>
|
|
88
|
+
</plist>
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
async function define(path, text) {
|
|
92
|
+
if ((await readFile(path, 'utf8').catch(() => null)) === text)
|
|
93
|
+
return false;
|
|
94
|
+
await mkdir(dirname(path), { recursive: true });
|
|
95
|
+
await writeFile(`${path}.new`, text);
|
|
96
|
+
await rename(`${path}.new`, path);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
export function defineSupervisor() {
|
|
100
|
+
return process.platform === 'darwin' ? define(launchAgent(), plistText()) : define(userUnit(), unitText());
|
|
101
|
+
}
|
|
102
|
+
export async function linger() {
|
|
103
|
+
required('loginctl', ['enable-linger', String(process.getuid())], 'lingering could not be turned on for this account');
|
|
104
|
+
if (process.getuid() === 0)
|
|
105
|
+
required('systemctl', ['start', 'user@0.service'], "root's service manager could not be started");
|
|
106
|
+
const stuck = Date.now() + MANAGER_MS;
|
|
107
|
+
while (manage('systemctl', ['--user', 'show-environment']).status !== 0) {
|
|
108
|
+
if (Date.now() >= stuck) {
|
|
109
|
+
throw new Error(`this account's service manager did not start within ${MANAGER_MS / 1000} seconds; restart this computer, then run this command again`);
|
|
110
|
+
}
|
|
111
|
+
await delay(MANAGER_CHECK_MS);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function macos() {
|
|
115
|
+
const target = `gui/${process.getuid()}`;
|
|
116
|
+
return { target, service: `${target}/${SERVICE}` };
|
|
117
|
+
}
|
|
118
|
+
export async function supervise(changed, restart) {
|
|
119
|
+
if (process.platform === 'darwin') {
|
|
120
|
+
const { target, service } = macos();
|
|
121
|
+
const printed = manage('launchctl', ['print', service]);
|
|
122
|
+
const loaded = printed.status === 0;
|
|
123
|
+
if (loaded && changed)
|
|
124
|
+
required('launchctl', ['bootout', service], 'the Kit service could not be stopped');
|
|
125
|
+
if (!loaded || changed) {
|
|
126
|
+
manage('launchctl', ['enable', service]);
|
|
127
|
+
required('launchctl', ['bootstrap', target, launchAgent()], 'the Kit service could not be started');
|
|
128
|
+
}
|
|
129
|
+
else if (restart) {
|
|
130
|
+
required('launchctl', ['kickstart', '-k', service], 'the Kit service could not be restarted');
|
|
131
|
+
}
|
|
132
|
+
else if (!/^\tstate = running$/m.test(printed.stdout)) {
|
|
133
|
+
required('launchctl', ['kickstart', service], 'the Kit service could not be started');
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await linger();
|
|
138
|
+
if (changed)
|
|
139
|
+
required('systemctl', ['--user', 'daemon-reload'], 'systemd could not read the Kit service');
|
|
140
|
+
required('systemctl', ['--user', '--quiet', 'enable', UNIT], 'the Kit service could not be enabled');
|
|
141
|
+
if (manage('systemctl', ['--user', '--quiet', 'is-active', UNIT]).status !== 0) {
|
|
142
|
+
required('systemctl', ['--user', 'start', UNIT], 'the Kit service could not be started');
|
|
143
|
+
}
|
|
144
|
+
else if (changed || restart) {
|
|
145
|
+
required('systemctl', ['--user', 'restart', UNIT], 'the Kit service could not be restarted');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export function startService() {
|
|
149
|
+
if (process.platform === 'darwin') {
|
|
150
|
+
const { service } = macos();
|
|
151
|
+
const printed = manage('launchctl', ['print', service]);
|
|
152
|
+
if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
|
|
153
|
+
return false;
|
|
154
|
+
required('launchctl', ['kickstart', service], 'the Kit service could not be started');
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
if (manage('systemctl', ['--user', '--quiet', 'is-enabled', UNIT]).status !== 0)
|
|
158
|
+
return false;
|
|
159
|
+
if (manage('systemctl', ['--user', '--quiet', 'is-active', UNIT]).status === 0)
|
|
160
|
+
return false;
|
|
161
|
+
required('systemctl', ['--user', 'start', UNIT], 'the Kit service could not be started');
|
|
162
|
+
return true;
|
|
163
|
+
}
|