@agentshouse/kit 0.2.1-cdc381ebf021f → 0.2.1-cdc3937dea52e
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 +4 -0
- package/dist/acp.js +2 -3
- package/dist/agents.js +22 -11
- package/dist/clis.js +17 -7
- package/dist/conversations.js +3 -3
- package/dist/copies.js +1 -0
- package/dist/files.js +6 -6
- package/dist/git-main.js +24 -29
- package/dist/home.js +15 -4
- package/dist/house-cli.js +13 -10
- package/dist/keys.js +238 -0
- package/dist/sign-in.js +49 -4
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ your conversations: a running conversation keeps its version and the next one ru
|
|
|
23
23
|
the oldest release Kit is built for still runs, though its conversations may fail: Kit tells House its version, that
|
|
24
24
|
oldest release and its update command. Kit also gives every Agent on the Environment the agent skills of
|
|
25
25
|
`@agentshouse/skills`, at the version each Kit release installs, unless its `skills` setting is off.
|
|
26
|
+
An API key you give a CLI on House's page, with an endpoint for another provider, goes into that CLI's own settings on
|
|
27
|
+
this computer, where you use the CLI too: Claude Code's `settings.json`, or Codex's login and `config.toml`. Grok Build
|
|
28
|
+
has no setting for a key that serves all its models, so Kit keeps its key in `~/.agents/house/grok-key.json` and sets
|
|
29
|
+
it, with the endpoint, as `XAI_API_KEY` and `GROK_MODELS_BASE_URL` on the Grok Build it runs, never on yours.
|
|
26
30
|
|
|
27
31
|
## Commands
|
|
28
32
|
|
package/dist/acp.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ndJsonStream, PROTOCOL_VERSION, RequestError, } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { Readable, Writable } from 'node:stream';
|
|
4
|
-
import { CLIS, KIT_RELEASE, adapterCommand } from './clis.js';
|
|
5
|
-
import { childEnvironment } from './relay.js';
|
|
4
|
+
import { CLIS, KIT_RELEASE, adapterCommand, cliEnvironment } from './clis.js';
|
|
6
5
|
import { killTree } from './scope.js';
|
|
7
6
|
import { Silence } from './silence.js';
|
|
8
7
|
const RETIRED = 'the CLI was retired';
|
|
@@ -19,7 +18,7 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
|
|
|
19
18
|
const [command, args] = scope?.command(...started) ?? started;
|
|
20
19
|
const child = spawn(command, args, {
|
|
21
20
|
cwd,
|
|
22
|
-
env: { ...
|
|
21
|
+
env: { ...(await cliEnvironment(kind)), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
|
|
23
22
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
24
23
|
detached: true,
|
|
25
24
|
});
|
package/dist/agents.js
CHANGED
|
@@ -3,7 +3,7 @@ import { KIT_WIRE } from '@agentshouse/kit-wire';
|
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
5
|
import { signedOut, startAdapter } from './acp.js';
|
|
6
|
-
import { CLIS, KIT_RELEASE, below, installCli, locate, run, updateCli, versionOf } from './clis.js';
|
|
6
|
+
import { CLIS, KIT_RELEASE, below, cliEnvironment, installCli, locate, run, updateCli, versionOf } from './clis.js';
|
|
7
7
|
import { agentBase, kitHome, reinstall } from './home.js';
|
|
8
8
|
import { heldSettings } from './settings.js';
|
|
9
9
|
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
@@ -97,11 +97,16 @@ function ended(signal) {
|
|
|
97
97
|
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
function keyedOf({ api_key, provider }) {
|
|
101
|
+
return { ...(api_key === undefined ? {} : { api_key }), ...(provider === undefined ? {} : { provider }) };
|
|
102
|
+
}
|
|
100
103
|
async function offer(kind, cli, known, signal) {
|
|
101
|
-
const probe = CLIS[kind]
|
|
104
|
+
const { signedIn: probe, key } = CLIS[kind];
|
|
105
|
+
const keyed = await key.read();
|
|
102
106
|
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
103
|
-
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
104
|
-
return SIGNED_OUT;
|
|
107
|
+
if ('command' in probe && !keyed.api_key && (await run(cli, probe.command, 30_000, false, signal, await cliEnvironment(kind))).status !== 0) {
|
|
108
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
109
|
+
}
|
|
105
110
|
let adapter;
|
|
106
111
|
try {
|
|
107
112
|
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
|
|
@@ -109,17 +114,21 @@ async function offer(kind, cli, known, signal) {
|
|
|
109
114
|
if ('initializeMeta' in probe) {
|
|
110
115
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
111
116
|
if (typeof method !== 'string' || method.length === 0)
|
|
112
|
-
return SIGNED_OUT;
|
|
117
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
118
|
+
if (method === probe.apiKey)
|
|
119
|
+
keyed.api_key = true;
|
|
113
120
|
}
|
|
114
|
-
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
121
|
+
return { signed_in: true, ...keyed, ...(await models(kind, adapter, known.models)) };
|
|
115
122
|
}
|
|
116
123
|
catch (error) {
|
|
117
124
|
if (!signal?.aborted)
|
|
118
125
|
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
119
126
|
if (signedOut(error))
|
|
120
|
-
return SIGNED_OUT;
|
|
127
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
128
|
+
const unread = adapter === undefined && 'initializeMeta' in probe;
|
|
121
129
|
return {
|
|
122
|
-
signed_in:
|
|
130
|
+
signed_in: unread ? known.signed_in : true,
|
|
131
|
+
...keyedOf({ api_key: unread ? known.api_key : keyed.api_key, provider: keyed.provider }),
|
|
123
132
|
models: known.models,
|
|
124
133
|
default_model: known.default_model,
|
|
125
134
|
default_effort: known.default_effort,
|
|
@@ -139,6 +148,7 @@ function reported(kind, reading) {
|
|
|
139
148
|
failure: reading.failure,
|
|
140
149
|
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
141
150
|
signed_in: reading.signed_in,
|
|
151
|
+
...keyedOf(reading),
|
|
142
152
|
models: reading.models,
|
|
143
153
|
modes: reading.modes,
|
|
144
154
|
full_access: CLIS[kind].fullAccess,
|
|
@@ -251,6 +261,7 @@ export class Agents {
|
|
|
251
261
|
release,
|
|
252
262
|
failure: null,
|
|
253
263
|
signed_in: kept.signed_in,
|
|
264
|
+
...keyedOf(kept),
|
|
254
265
|
models: kept.models,
|
|
255
266
|
default_model: kept.default_model,
|
|
256
267
|
default_effort: kept.default_effort,
|
|
@@ -262,7 +273,7 @@ export class Agents {
|
|
|
262
273
|
.then((offered) => {
|
|
263
274
|
const current = this.readings.get(kind);
|
|
264
275
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
265
|
-
this.update(kind, {
|
|
276
|
+
this.update(kind, { release, failure: current.failure, ...offered });
|
|
266
277
|
})
|
|
267
278
|
.catch(logged);
|
|
268
279
|
return cli;
|
|
@@ -346,7 +357,7 @@ export class Agents {
|
|
|
346
357
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
347
358
|
return { release: null, failure, ...SIGNED_OUT };
|
|
348
359
|
}
|
|
349
|
-
const release = await versionOf(cli, signal);
|
|
360
|
+
const release = await versionOf(kind, cli, signal);
|
|
350
361
|
if (release === null)
|
|
351
362
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
352
363
|
return { cli, release };
|
|
@@ -381,7 +392,7 @@ export class Agents {
|
|
|
381
392
|
}
|
|
382
393
|
async readVersion(kind) {
|
|
383
394
|
const cli = await locate(kind);
|
|
384
|
-
const release = cli === null ? null : await versionOf(cli);
|
|
395
|
+
const release = cli === null ? null : await versionOf(kind, cli);
|
|
385
396
|
const current = this.readings.get(kind);
|
|
386
397
|
if (release === null || !current?.release || current.release === release)
|
|
387
398
|
return;
|
package/dist/clis.js
CHANGED
|
@@ -2,8 +2,9 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { constants, readFileSync } from 'node:fs';
|
|
4
4
|
import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
5
|
-
import {
|
|
5
|
+
import { userInfo } from 'node:os';
|
|
6
6
|
import { delimiter, dirname, isAbsolute, join } from 'node:path';
|
|
7
|
+
import { CLAUDE_KEY, CODEX_KEY, GROK_KEY, codexHome } from './keys.js';
|
|
7
8
|
import { releaseDirectory } from './placement.js';
|
|
8
9
|
import { childEnvironment } from './relay.js';
|
|
9
10
|
const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
|
|
@@ -50,7 +51,7 @@ async function listedHouses(file) {
|
|
|
50
51
|
}
|
|
51
52
|
export async function allowHouseInCodex(path) {
|
|
52
53
|
const candidates = [...new Set(path.split(delimiter).filter((directory) => isAbsolute(directory)))].map((directory) => join(directory, 'house'));
|
|
53
|
-
const rules = join(
|
|
54
|
+
const rules = join(codexHome(), 'rules');
|
|
54
55
|
const file = join(rules, 'house.rules');
|
|
55
56
|
const houses = [];
|
|
56
57
|
for (const house of [...(await listedHouses(file)), ...candidates]) {
|
|
@@ -79,6 +80,7 @@ function bridgeInClaudeSandbox(bridge) {
|
|
|
79
80
|
}
|
|
80
81
|
export const CLIS = {
|
|
81
82
|
'codex-acp': {
|
|
83
|
+
name: 'Codex',
|
|
82
84
|
bin: 'codex',
|
|
83
85
|
minimum: '0.165.0',
|
|
84
86
|
install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
|
|
@@ -100,9 +102,11 @@ export const CLIS = {
|
|
|
100
102
|
questionFields: codexQuestionFields,
|
|
101
103
|
signedIn: { command: ['login', 'status'] },
|
|
102
104
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
105
|
+
key: CODEX_KEY,
|
|
103
106
|
air: ['asyncTasks', 'nativeSubagentSessions'],
|
|
104
107
|
},
|
|
105
108
|
'claude-agent-acp': {
|
|
109
|
+
name: 'Claude Code',
|
|
106
110
|
bin: 'claude',
|
|
107
111
|
minimum: '2.1.316',
|
|
108
112
|
install: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
@@ -130,9 +134,11 @@ export const CLIS = {
|
|
|
130
134
|
questionFields: claudeQuestionFields,
|
|
131
135
|
signedIn: { command: ['auth', 'status'] },
|
|
132
136
|
login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
|
|
137
|
+
key: CLAUDE_KEY,
|
|
133
138
|
air: ['asyncTasks', 'sessionFailure'],
|
|
134
139
|
},
|
|
135
140
|
'grok-build': {
|
|
141
|
+
name: 'Grok Build',
|
|
136
142
|
bin: 'grok',
|
|
137
143
|
minimum: '1.0.46',
|
|
138
144
|
install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
|
|
@@ -144,8 +150,9 @@ export const CLIS = {
|
|
|
144
150
|
unknownSession: (error) => answered(error).data?.code === 'FS_NOT_FOUND',
|
|
145
151
|
allowHouse: nothing,
|
|
146
152
|
questionFields: () => [],
|
|
147
|
-
signedIn: { initializeMeta: 'defaultAuthMethodId' },
|
|
153
|
+
signedIn: { initializeMeta: 'defaultAuthMethodId', apiKey: 'xai.api_key' },
|
|
148
154
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
155
|
+
key: GROK_KEY,
|
|
149
156
|
air: ['asyncTasks'],
|
|
150
157
|
},
|
|
151
158
|
};
|
|
@@ -160,12 +167,15 @@ const CAUSE_CHARACTERS = 4000;
|
|
|
160
167
|
export function adapterCommand(kind) {
|
|
161
168
|
return join(releaseDirectory(KIT_RELEASE), 'adapters', kind, 'node_modules', '.bin', CLIS[kind].adapter.bin);
|
|
162
169
|
}
|
|
163
|
-
export function
|
|
170
|
+
export async function cliEnvironment(kind) {
|
|
171
|
+
return { ...childEnvironment(), ...(await CLIS[kind].key.environment?.()) };
|
|
172
|
+
}
|
|
173
|
+
export function run(command, args, timeoutMs, detached = false, signal, env = childEnvironment()) {
|
|
164
174
|
return new Promise((resolve) => {
|
|
165
175
|
const child = spawn(command, args, {
|
|
166
176
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
167
177
|
timeout: timeoutMs,
|
|
168
|
-
env
|
|
178
|
+
env,
|
|
169
179
|
detached,
|
|
170
180
|
signal: detached ? undefined : signal,
|
|
171
181
|
});
|
|
@@ -242,8 +252,8 @@ export async function writeCodexRule() {
|
|
|
242
252
|
throw new Error(`Codex's rule for house could not be written: ${error.message}`);
|
|
243
253
|
});
|
|
244
254
|
}
|
|
245
|
-
export async function versionOf(path, signal) {
|
|
246
|
-
return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal)).stdout)?.[0] ?? null;
|
|
255
|
+
export async function versionOf(kind, path, signal) {
|
|
256
|
+
return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal, await cliEnvironment(kind))).stdout)?.[0] ?? null;
|
|
247
257
|
}
|
|
248
258
|
function numbers(version) {
|
|
249
259
|
return version.split(/[.-]/, 3).map(Number);
|
package/dist/conversations.js
CHANGED
|
@@ -10,7 +10,7 @@ import { openBridge } from './bridge.js';
|
|
|
10
10
|
import { CLIS } from './clis.js';
|
|
11
11
|
import { Content } from './content.js';
|
|
12
12
|
import { answeredFailure, readerFor } from './events.js';
|
|
13
|
-
import {
|
|
13
|
+
import { fileInfo, linkedPaths, storeRefusal, uploaded } from './files.js';
|
|
14
14
|
import { grokPlanAnswer, grokPlanForm, grokQuestionAnswer, grokQuestionForm } from './grok.js';
|
|
15
15
|
import { agentBase } from './home.js';
|
|
16
16
|
import { instructions } from './instructions.js';
|
|
@@ -136,7 +136,7 @@ function refusal(conversation, error) {
|
|
|
136
136
|
function audioOf(result) {
|
|
137
137
|
if (result.isError === true)
|
|
138
138
|
return null;
|
|
139
|
-
const file =
|
|
139
|
+
const file = fileInfo(result.content.map((content) => content.text).join('\n'));
|
|
140
140
|
return file?.media_type?.startsWith('audio/') === true ? file : null;
|
|
141
141
|
}
|
|
142
142
|
function marker(bridge) {
|
|
@@ -578,7 +578,7 @@ export class Conversations {
|
|
|
578
578
|
const blocks = [];
|
|
579
579
|
try {
|
|
580
580
|
const bridge = await step(unbridged, unlessAborted(this.bridged(conversation), killed));
|
|
581
|
-
const read = async (path) => audioOf(await step(unbridged, unlessAborted(bridge.tool('
|
|
581
|
+
const read = async (path) => audioOf(await step(unbridged, unlessAborted(bridge.tool('info', { path }), signal)));
|
|
582
582
|
for (const path of paths) {
|
|
583
583
|
let answered = await read(path);
|
|
584
584
|
if (answered === null)
|
package/dist/copies.js
CHANGED
|
@@ -473,6 +473,7 @@ export class LocalCopies {
|
|
|
473
473
|
let copy;
|
|
474
474
|
try {
|
|
475
475
|
await git(staging, ['init', '-q', '-b', BRANCH]);
|
|
476
|
+
await git(staging, ['config', 'core.precomposeUnicode', 'true']);
|
|
476
477
|
const read = await whole(join(staging, '.git', STAGED_CHUNKS));
|
|
477
478
|
const readOnly = await readOnlyFiles(staging, []);
|
|
478
479
|
const { house, revisions } = await importedWhole(staging, scope, read.texts, { message: `House ${rootOf(handle)}`, from: null }, readOnly);
|
package/dist/files.js
CHANGED
|
@@ -14,17 +14,17 @@ const LINK = /\]\((\/rooms\/[^/)\s]+\/[^)\s]+)\)/gu;
|
|
|
14
14
|
export function linkedPaths(text) {
|
|
15
15
|
return [...new Set(Array.from(text.matchAll(LINK), (link) => link[1]))];
|
|
16
16
|
}
|
|
17
|
-
export function
|
|
17
|
+
export function fileInfo(answer) {
|
|
18
18
|
const document = parseDocument(answer);
|
|
19
19
|
if (document.errors.length > 0)
|
|
20
20
|
return null;
|
|
21
|
-
const
|
|
22
|
-
if (typeof
|
|
21
|
+
const details = document.toJS();
|
|
22
|
+
if (typeof details?.download !== 'string')
|
|
23
23
|
return null;
|
|
24
24
|
return {
|
|
25
|
-
download:
|
|
26
|
-
sha256: String(
|
|
27
|
-
media_type: typeof
|
|
25
|
+
download: details.download,
|
|
26
|
+
sha256: String(details.sha256),
|
|
27
|
+
media_type: typeof details.media_type === 'string' ? details.media_type : null,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
export function paused(milliseconds) {
|
package/dist/git-main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
-
import { accessSync, constants, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { accessSync, constants, mkdtempSync, realpathSync, rmSync, statSync } from 'node:fs';
|
|
4
4
|
import { request } from 'node:http';
|
|
5
5
|
import { constants as system } from 'node:os';
|
|
6
6
|
import { delimiter, dirname, join } from 'node:path';
|
|
@@ -52,11 +52,12 @@ function nativeGit() {
|
|
|
52
52
|
}
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
|
-
function captured(git, args) {
|
|
55
|
+
function captured(git, args, { input, index } = {}) {
|
|
56
56
|
const ran = spawnSync(git, args, {
|
|
57
|
-
|
|
57
|
+
input,
|
|
58
|
+
stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'ignore'],
|
|
58
59
|
maxBuffer: Infinity,
|
|
59
|
-
env: { ...process.env, LC_ALL: 'C' },
|
|
60
|
+
env: { ...process.env, LC_ALL: 'C', ...(index === undefined ? {} : { GIT_INDEX_FILE: index }) },
|
|
60
61
|
});
|
|
61
62
|
return ran.status === 0 ? ran.stdout.toString('utf8') : null;
|
|
62
63
|
}
|
|
@@ -78,30 +79,25 @@ function delegated(git, args) {
|
|
|
78
79
|
child.once('close', (status, signal) => settle({ status, signal }));
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
function merged(git, copy, common) {
|
|
83
|
+
const staged = (captured(git, [...copy, 'ls-files', '--stage', '-z']) ?? '').split('\0');
|
|
84
|
+
const input = staged.filter((entry) => /^\d+ [0-9a-f]+ 0\t/.test(entry)).map((entry) => `${entry}\0`).join('');
|
|
85
|
+
const scratch = mkdtempSync(join(common, 'house-index-'));
|
|
86
|
+
try {
|
|
87
|
+
const index = join(scratch, 'index');
|
|
88
|
+
captured(git, [...copy, 'update-index', '-z', '--index-info'], { input, index });
|
|
89
|
+
return captured(git, [...copy, 'write-tree'], { index })?.trim();
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
87
93
|
}
|
|
88
|
-
return entries;
|
|
89
94
|
}
|
|
90
|
-
function moved(
|
|
95
|
+
function moved(git, copy, before) {
|
|
96
|
+
const renames = ['diff-index', '--cached', '-z', '--name-status', '--find-renames=100%', '--diff-filter=R', before];
|
|
97
|
+
const fields = (captured(git, [...copy, ...renames]) ?? '').split('\0');
|
|
91
98
|
const moves = [];
|
|
92
|
-
for (
|
|
93
|
-
|
|
94
|
-
continue;
|
|
95
|
-
const renaming = line.slice('Renaming '.length);
|
|
96
|
-
for (let at = renaming.indexOf(' to '); at >= 0; at = renaming.indexOf(' to ', at + 1)) {
|
|
97
|
-
const from = renaming.slice(0, at);
|
|
98
|
-
const to = renaming.slice(at + 4);
|
|
99
|
-
if (before.has(from) && !after.has(from) && after.get(to) === before.get(from)) {
|
|
100
|
-
moves.push({ from, to });
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
99
|
+
for (let at = 0; at + 2 < fields.length; at += 3)
|
|
100
|
+
moves.push({ from: fields[at + 1], to: fields[at + 2] });
|
|
105
101
|
return moves;
|
|
106
102
|
}
|
|
107
103
|
function reported(socketPath, body) {
|
|
@@ -128,11 +124,10 @@ async function observed(git, args) {
|
|
|
128
124
|
if (common === undefined || worktree === undefined || !dirname(common).startsWith(`${localCopies()}/`)) {
|
|
129
125
|
return delegated(git, args);
|
|
130
126
|
}
|
|
131
|
-
const
|
|
132
|
-
const before = name === 'mv' ?
|
|
133
|
-
const planned = name === 'mv' ? (captured(git, [...globals, 'mv', '--dry-run', ...args.slice(index + 1)]) ?? '') : '';
|
|
127
|
+
const copy = [...globals, '-C', worktree];
|
|
128
|
+
const before = name === 'mv' ? merged(git, copy, common) : undefined;
|
|
134
129
|
const outcome = await delegated(git, args);
|
|
135
|
-
const moves = before !==
|
|
130
|
+
const moves = before !== undefined && outcome.status === 0 ? moved(git, copy, before) : [];
|
|
136
131
|
await reported(bridge, { common, worktree, moves });
|
|
137
132
|
return outcome;
|
|
138
133
|
}
|
package/dist/home.js
CHANGED
|
@@ -81,15 +81,25 @@ export function workspaceRoot() {
|
|
|
81
81
|
export function agentBase() {
|
|
82
82
|
return join(workspaceRoot(), 'agents');
|
|
83
83
|
}
|
|
84
|
+
function parsed(name, text) {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
throw new Error(`${name} in Kit home holds no JSON`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
84
92
|
export async function readHome(name) {
|
|
93
|
+
let text;
|
|
85
94
|
try {
|
|
86
|
-
|
|
95
|
+
text = await readFile(join(kitHome(), name), 'utf8');
|
|
87
96
|
}
|
|
88
97
|
catch (error) {
|
|
89
98
|
if (error.code === 'ENOENT')
|
|
90
99
|
return null;
|
|
91
100
|
throw error;
|
|
92
101
|
}
|
|
102
|
+
return parsed(name, text);
|
|
93
103
|
}
|
|
94
104
|
export async function writeHome(name, value) {
|
|
95
105
|
const home = kitHome();
|
|
@@ -133,7 +143,7 @@ export async function forgetRejected(rejected) {
|
|
|
133
143
|
return;
|
|
134
144
|
throw error;
|
|
135
145
|
}
|
|
136
|
-
if (
|
|
146
|
+
if (parsed(ENROLMENT, readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
137
147
|
try {
|
|
138
148
|
linkSync(taken, enrolment);
|
|
139
149
|
}
|
|
@@ -158,15 +168,16 @@ export function forgetOwnAgent() {
|
|
|
158
168
|
return rm(join(kitHome(), OWN_AGENT), { force: true });
|
|
159
169
|
}
|
|
160
170
|
function configuredWorkspace() {
|
|
171
|
+
let text;
|
|
161
172
|
try {
|
|
162
|
-
|
|
163
|
-
return workspace;
|
|
173
|
+
text = readFileSync(join(kitHome(), CONFIGURATION), 'utf8');
|
|
164
174
|
}
|
|
165
175
|
catch (error) {
|
|
166
176
|
if (error.code === 'ENOENT')
|
|
167
177
|
return undefined;
|
|
168
178
|
throw error;
|
|
169
179
|
}
|
|
180
|
+
return parsed(CONFIGURATION, text).workspace;
|
|
170
181
|
}
|
|
171
182
|
export async function readConfiguration() {
|
|
172
183
|
const stored = await readHome(CONFIGURATION);
|
package/dist/house-cli.js
CHANGED
|
@@ -4,15 +4,16 @@ import { request } from 'node:http';
|
|
|
4
4
|
import { request as httpsRequest } from 'node:https';
|
|
5
5
|
import { extname, join, resolve } from 'node:path';
|
|
6
6
|
import { Readable } from 'node:stream';
|
|
7
|
+
import { text as textOf } from 'node:stream/consumers';
|
|
7
8
|
import { pipeline } from 'node:stream/promises';
|
|
8
|
-
import { downloaded,
|
|
9
|
+
import { downloaded, fileInfo, storeRefusal, uploaded } from './files.js';
|
|
9
10
|
import { HOUSE_REF } from './git.js';
|
|
10
11
|
import { ownerSocket, readOwnAgent } from './home.js';
|
|
11
12
|
import { callHouse, rpc, UNREACHABLE, Unsettled } from './mcp.js';
|
|
12
13
|
import { refusalOf, retryable } from './refusals.js';
|
|
13
14
|
import { proxyUnlessRelayed, relayed, selectRelay } from './relay.js';
|
|
14
15
|
import { parse } from 'yaml';
|
|
15
|
-
const USAGE = "usage: house <tool> ['<arguments as JSON>']; house help <tool>: its arguments";
|
|
16
|
+
const USAGE = "usage: house <tool> ['<arguments as JSON>'], or house <tool> - to read them from stdin; house help <tool>: its arguments";
|
|
16
17
|
const HELP = 'help [tool]';
|
|
17
18
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
18
19
|
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
@@ -20,7 +21,8 @@ const FETCH_USAGE = 'usage: house fetch';
|
|
|
20
21
|
const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
|
|
21
22
|
const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
|
|
22
23
|
const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
|
|
23
|
-
const
|
|
24
|
+
const UPLOAD_USAGE = `usage: house upload '{"file":"<local file>","room_ref":"r_…","path":"<path in the Room>"}', adding "base", the revision it replaces`;
|
|
25
|
+
const ARGUMENTS = `the arguments are one JSON object, in single quotes or on stdin after -, like house search '{"query":"invoice"}'`;
|
|
24
26
|
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
25
27
|
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
26
28
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
@@ -152,12 +154,12 @@ async function download(args) {
|
|
|
152
154
|
const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
|
|
153
155
|
if (flags.has('--help'))
|
|
154
156
|
return DOWNLOAD_USAGE;
|
|
155
|
-
const { file, ...selected } = argumentsOf(argument);
|
|
157
|
+
const { file, ...selected } = await argumentsOf(argument);
|
|
156
158
|
if (typeof file !== 'string' || file === '')
|
|
157
159
|
throw new Error('download needs "file", the local file to write');
|
|
158
160
|
const written = resolve(file);
|
|
159
161
|
await downloaded(async () => {
|
|
160
|
-
const file =
|
|
162
|
+
const file = fileInfo(await called('info', selected));
|
|
161
163
|
if (file === null)
|
|
162
164
|
throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
|
|
163
165
|
return file;
|
|
@@ -213,7 +215,7 @@ function accepted(args, flags, positionals, usage) {
|
|
|
213
215
|
for (const arg of args) {
|
|
214
216
|
if (flags.includes(arg))
|
|
215
217
|
given.flags.add(arg);
|
|
216
|
-
else if (!arg.startsWith('-') && given.positionals.length < positionals)
|
|
218
|
+
else if ((arg === '-' || !arg.startsWith('-')) && given.positionals.length < positionals)
|
|
217
219
|
given.positionals.push(arg);
|
|
218
220
|
else
|
|
219
221
|
throw unexpected(arg, usage);
|
|
@@ -242,12 +244,13 @@ async function fetched(args) {
|
|
|
242
244
|
throw new Error(answer.text);
|
|
243
245
|
return answer.text;
|
|
244
246
|
}
|
|
245
|
-
function argumentsOf(argument) {
|
|
247
|
+
async function argumentsOf(argument) {
|
|
246
248
|
if (argument === undefined)
|
|
247
249
|
return {};
|
|
250
|
+
const given = argument === '-' ? await textOf(process.stdin) : argument;
|
|
248
251
|
let parsed;
|
|
249
252
|
try {
|
|
250
|
-
parsed = JSON.parse(
|
|
253
|
+
parsed = JSON.parse(given);
|
|
251
254
|
}
|
|
252
255
|
catch {
|
|
253
256
|
throw new Error(ARGUMENTS);
|
|
@@ -326,8 +329,8 @@ async function house(args) {
|
|
|
326
329
|
return [USAGE, HELP, PUSH, FETCH, DOWNLOAD, ...listing].join('\n');
|
|
327
330
|
}
|
|
328
331
|
if (flags.has('--help'))
|
|
329
|
-
return toolHelp(verb);
|
|
330
|
-
const parsed = argumentsOf(argument);
|
|
332
|
+
return verb === 'upload' ? UPLOAD_USAGE : toolHelp(verb);
|
|
333
|
+
const parsed = await argumentsOf(argument);
|
|
331
334
|
return verb === 'upload' ? upload(parsed) : called(verb, parsed);
|
|
332
335
|
}
|
|
333
336
|
async function called(name, args) {
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { mkdir, readFile, realpath, rename, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
7
|
+
import { parse } from 'smol-toml';
|
|
8
|
+
import { readHome, writeHome } from './home.js';
|
|
9
|
+
import { childEnvironment } from './relay.js';
|
|
10
|
+
function table(value) {
|
|
11
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
12
|
+
}
|
|
13
|
+
function filled(value) {
|
|
14
|
+
return typeof value === 'string' && value !== '';
|
|
15
|
+
}
|
|
16
|
+
function hostOf(endpoint) {
|
|
17
|
+
if (typeof endpoint !== 'string')
|
|
18
|
+
return undefined;
|
|
19
|
+
try {
|
|
20
|
+
return new URL(endpoint).host || undefined;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function keyed(apiKey, endpoint, maker) {
|
|
27
|
+
const host = hostOf(endpoint);
|
|
28
|
+
return { ...(apiKey ? { api_key: true } : {}), ...(host === undefined || host === maker ? {} : { provider: host }) };
|
|
29
|
+
}
|
|
30
|
+
function quietly(read) {
|
|
31
|
+
return () => read().catch(() => ({}));
|
|
32
|
+
}
|
|
33
|
+
async function readText(file) {
|
|
34
|
+
try {
|
|
35
|
+
return await readFile(file, 'utf8');
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === 'ENOENT')
|
|
39
|
+
return null;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function replaceFile(file, text) {
|
|
44
|
+
const target = await realpath(file).catch(() => file);
|
|
45
|
+
await mkdir(dirname(target), { recursive: true });
|
|
46
|
+
const temporary = `${target}.${randomUUID()}`;
|
|
47
|
+
await writeFile(temporary, text, { mode: 0o600 });
|
|
48
|
+
await rename(temporary, target);
|
|
49
|
+
}
|
|
50
|
+
async function jsonSettings(file) {
|
|
51
|
+
const text = await readText(file);
|
|
52
|
+
if (text === null)
|
|
53
|
+
return {};
|
|
54
|
+
let settings;
|
|
55
|
+
try {
|
|
56
|
+
settings = JSON.parse(text);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
settings = null;
|
|
60
|
+
}
|
|
61
|
+
if (typeof settings !== 'object' || settings === null || Array.isArray(settings))
|
|
62
|
+
throw new Error(`${file} holds no JSON object`);
|
|
63
|
+
return settings;
|
|
64
|
+
}
|
|
65
|
+
async function tomlSettings(file) {
|
|
66
|
+
return parse((await readText(file)) ?? '');
|
|
67
|
+
}
|
|
68
|
+
const BARE_KEY = /^[A-Za-z0-9_-]+$/;
|
|
69
|
+
function header(line, at) {
|
|
70
|
+
const trimmed = line.trim();
|
|
71
|
+
if (!trimmed.startsWith('['))
|
|
72
|
+
return null;
|
|
73
|
+
let value;
|
|
74
|
+
try {
|
|
75
|
+
value = parse(trimmed);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const path = [];
|
|
81
|
+
while (!Array.isArray(value)) {
|
|
82
|
+
const [name, ...more] = Object.keys(table(value));
|
|
83
|
+
if (name === undefined || more.length > 0)
|
|
84
|
+
return { at, path };
|
|
85
|
+
path.push(name);
|
|
86
|
+
value = table(value)[name];
|
|
87
|
+
}
|
|
88
|
+
return { at, path: [...path, '[]'] };
|
|
89
|
+
}
|
|
90
|
+
function editLines(lines, { table: path, key, value, kept }) {
|
|
91
|
+
const headers = lines.flatMap((line, at) => header(line, at) ?? []);
|
|
92
|
+
const found = path.length === 0 ? { at: -1, path } : headers.find((one) => isDeepStrictEqual(one.path, path));
|
|
93
|
+
const assignment = `${key} = ${JSON.stringify(value)}`;
|
|
94
|
+
if (found === undefined) {
|
|
95
|
+
if (value === null)
|
|
96
|
+
return lines;
|
|
97
|
+
const kept = lines.at(-1) === '' ? lines.slice(0, -1) : lines;
|
|
98
|
+
return [...kept, ...(kept.length === 0 ? [] : ['']), `[${path.map((name) => (BARE_KEY.test(name) ? name : JSON.stringify(name))).join('.')}]`, assignment, ''];
|
|
99
|
+
}
|
|
100
|
+
const end = headers.find((one) => one.at > found.at)?.at ?? lines.length;
|
|
101
|
+
const assigned = new RegExp(`^\\s*${key}\\s*=`);
|
|
102
|
+
const current = lines.findIndex((line, at) => at > found.at && at < end && assigned.test(line));
|
|
103
|
+
if (current !== -1 && kept)
|
|
104
|
+
return lines;
|
|
105
|
+
if (current !== -1)
|
|
106
|
+
return value === null ? lines.toSpliced(current, 1) : lines.toSpliced(current, 1, assignment);
|
|
107
|
+
if (value === null)
|
|
108
|
+
return lines;
|
|
109
|
+
const last = lines.findLastIndex((line, at) => at > found.at && at < end && line.trim() !== '');
|
|
110
|
+
return lines.toSpliced(Math.max(last, found.at) + 1, 0, assignment);
|
|
111
|
+
}
|
|
112
|
+
function editSettings(settings, { table: path, key, value, kept }) {
|
|
113
|
+
let at = settings;
|
|
114
|
+
for (const name of path) {
|
|
115
|
+
if (typeof at[name] !== 'object' || at[name] === null)
|
|
116
|
+
at[name] = Object.create(null);
|
|
117
|
+
at = at[name];
|
|
118
|
+
}
|
|
119
|
+
if (kept && key in at)
|
|
120
|
+
return;
|
|
121
|
+
if (value === null)
|
|
122
|
+
delete at[key];
|
|
123
|
+
else
|
|
124
|
+
at[key] = value;
|
|
125
|
+
}
|
|
126
|
+
async function editToml(file, edits) {
|
|
127
|
+
const text = (await readText(file)) ?? '';
|
|
128
|
+
let expected;
|
|
129
|
+
try {
|
|
130
|
+
expected = parse(text);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
throw new Error(`${file} is not TOML`);
|
|
134
|
+
}
|
|
135
|
+
for (const edit of edits)
|
|
136
|
+
editSettings(expected, edit);
|
|
137
|
+
const edited = edits.reduce(editLines, text === '' ? [] : text.split('\n')).join('\n');
|
|
138
|
+
let written;
|
|
139
|
+
try {
|
|
140
|
+
written = parse(edited);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
written = null;
|
|
144
|
+
}
|
|
145
|
+
if (!isDeepStrictEqual(written, expected))
|
|
146
|
+
throw new Error(`${file} could not take the key without changing its other settings`);
|
|
147
|
+
if (edited === text)
|
|
148
|
+
return async () => undefined;
|
|
149
|
+
return () => replaceFile(file, edited.endsWith('\n') ? edited : `${edited}\n`);
|
|
150
|
+
}
|
|
151
|
+
function claudeSettings() {
|
|
152
|
+
return join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'), 'settings.json');
|
|
153
|
+
}
|
|
154
|
+
export const CLAUDE_KEY = {
|
|
155
|
+
read: quietly(async () => {
|
|
156
|
+
const env = table((await jsonSettings(claudeSettings())).env);
|
|
157
|
+
return keyed(filled(env.ANTHROPIC_API_KEY) || filled(env.ANTHROPIC_AUTH_TOKEN), env.ANTHROPIC_BASE_URL, 'api.anthropic.com');
|
|
158
|
+
}),
|
|
159
|
+
write: async (key, endpoint) => {
|
|
160
|
+
const file = claudeSettings();
|
|
161
|
+
const settings = await jsonSettings(file);
|
|
162
|
+
const { ANTHROPIC_API_KEY: _key, ANTHROPIC_AUTH_TOKEN: _token, ANTHROPIC_BASE_URL: _endpoint, ...env } = table(settings.env);
|
|
163
|
+
const written = endpoint === null
|
|
164
|
+
? { ...env, ANTHROPIC_API_KEY: key }
|
|
165
|
+
: { ...env, ANTHROPIC_AUTH_TOKEN: key, ANTHROPIC_API_KEY: '', ANTHROPIC_BASE_URL: endpoint };
|
|
166
|
+
await replaceFile(file, `${JSON.stringify({ ...settings, env: written }, undefined, 2)}\n`);
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
const CODEX_PROVIDER = 'model_provider';
|
|
170
|
+
export function codexHome() {
|
|
171
|
+
return process.env.CODEX_HOME || join(homedir(), '.codex');
|
|
172
|
+
}
|
|
173
|
+
function codexLogin(cli, key, signal) {
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
const child = spawn(cli, ['login', '--with-api-key'], { stdio: ['pipe', 'ignore', 'pipe'], env: childEnvironment(), signal });
|
|
176
|
+
let output = '';
|
|
177
|
+
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
178
|
+
output = (output + chunk).slice(-4000);
|
|
179
|
+
});
|
|
180
|
+
child.on('error', reject);
|
|
181
|
+
child.on('close', (status) => {
|
|
182
|
+
const last = output.trim().split('\n').at(-1) ?? '';
|
|
183
|
+
if (status === 0)
|
|
184
|
+
resolve();
|
|
185
|
+
else
|
|
186
|
+
reject(new Error(`codex login --with-api-key exited with ${status ?? 'a signal'}${last === '' ? '' : `: ${last}`}`));
|
|
187
|
+
});
|
|
188
|
+
child.stdin.end(key);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
export const CODEX_KEY = {
|
|
192
|
+
read: quietly(async () => {
|
|
193
|
+
const config = await tomlSettings(join(codexHome(), 'config.toml'));
|
|
194
|
+
const id = config[CODEX_PROVIDER];
|
|
195
|
+
if (typeof id === 'string' && id !== 'openai') {
|
|
196
|
+
const provider = table(table(config.model_providers)[id]);
|
|
197
|
+
const fromEnvironment = typeof provider.env_key === 'string' && filled(process.env[provider.env_key]);
|
|
198
|
+
return keyed(filled(provider.experimental_bearer_token) || fromEnvironment, provider.base_url, 'api.openai.com');
|
|
199
|
+
}
|
|
200
|
+
const auth = table(JSON.parse((await readText(join(codexHome(), 'auth.json'))) ?? '{}'));
|
|
201
|
+
return keyed(filled(auth.OPENAI_API_KEY) && (auth.tokens === undefined || auth.tokens === null), undefined, 'api.openai.com');
|
|
202
|
+
}),
|
|
203
|
+
write: async (key, endpoint, cli, signal) => {
|
|
204
|
+
const file = join(codexHome(), 'config.toml');
|
|
205
|
+
if (endpoint === null) {
|
|
206
|
+
const write = await editToml(file, [{ table: [], key: CODEX_PROVIDER, value: null }]);
|
|
207
|
+
await codexLogin(cli, key, signal);
|
|
208
|
+
await write();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const host = new URL(endpoint).host;
|
|
212
|
+
const provider = ['model_providers', host];
|
|
213
|
+
const write = await editToml(file, [
|
|
214
|
+
{ table: [], key: CODEX_PROVIDER, value: host },
|
|
215
|
+
{ table: provider, key: 'name', value: host, kept: true },
|
|
216
|
+
{ table: provider, key: 'base_url', value: endpoint },
|
|
217
|
+
{ table: provider, key: 'experimental_bearer_token', value: key },
|
|
218
|
+
]);
|
|
219
|
+
await write();
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
const GROK_HELD_KEY = 'grok-key.json';
|
|
223
|
+
export const GROK_KEY = {
|
|
224
|
+
read: quietly(async () => {
|
|
225
|
+
const held = await readHome(GROK_HELD_KEY);
|
|
226
|
+
if (held?.endpoint !== undefined)
|
|
227
|
+
return keyed(true, held.endpoint, 'api.x.ai');
|
|
228
|
+
const config = await tomlSettings(join(process.env.GROK_HOME || join(homedir(), '.grok'), 'config.toml'));
|
|
229
|
+
return keyed(held !== null, table(config.endpoints).models_base_url, 'api.x.ai');
|
|
230
|
+
}),
|
|
231
|
+
write: (key, endpoint) => writeHome(GROK_HELD_KEY, { key, ...(endpoint === null ? {} : { endpoint }) }),
|
|
232
|
+
environment: async () => {
|
|
233
|
+
const held = await readHome(GROK_HELD_KEY);
|
|
234
|
+
if (held === null)
|
|
235
|
+
return {};
|
|
236
|
+
return { XAI_API_KEY: held.key, ...(held.endpoint === undefined ? {} : { GROK_MODELS_BASE_URL: held.endpoint }) };
|
|
237
|
+
},
|
|
238
|
+
};
|
package/dist/sign-in.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
|
-
import { CLIS } from './clis.js';
|
|
4
|
-
import { childEnvironment } from './relay.js';
|
|
3
|
+
import { CLIS, cliEnvironment } from './clis.js';
|
|
5
4
|
import { killTree } from './scope.js';
|
|
6
5
|
import { holdSecretInput } from './secret-input.js';
|
|
7
6
|
const ESCAPE = /\u001b\[[\d;]*m/g;
|
|
@@ -10,6 +9,33 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
|
|
|
10
9
|
function causeOf(error) {
|
|
11
10
|
return error instanceof Error ? error.message : String(error);
|
|
12
11
|
}
|
|
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
|
+
}
|
|
13
39
|
function endOf(signal) {
|
|
14
40
|
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
15
41
|
}
|
|
@@ -36,15 +62,34 @@ export class SignIns {
|
|
|
36
62
|
return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
|
|
37
63
|
}
|
|
38
64
|
async signedIn(call, signal) {
|
|
39
|
-
await this.login(call, signal);
|
|
65
|
+
await (call.api_key === true ? this.keyed(call, signal) : this.login(call, signal));
|
|
40
66
|
if (!signal.aborted)
|
|
41
67
|
await this.agents.recheck(call.cli, signal);
|
|
42
68
|
return false;
|
|
43
69
|
}
|
|
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
|
+
}
|
|
44
87
|
async login(call, signal) {
|
|
45
88
|
let cli;
|
|
89
|
+
let env;
|
|
46
90
|
try {
|
|
47
91
|
cli = await this.agents.located(call.cli, signal);
|
|
92
|
+
env = await cliEnvironment(call.cli);
|
|
48
93
|
}
|
|
49
94
|
catch (error) {
|
|
50
95
|
if (!signal.aborted)
|
|
@@ -57,7 +102,7 @@ export class SignIns {
|
|
|
57
102
|
const child = spawn(cli, login.args, {
|
|
58
103
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
59
104
|
detached: true,
|
|
60
|
-
env
|
|
105
|
+
env,
|
|
61
106
|
});
|
|
62
107
|
const running = () => child.exitCode === null && child.signalCode === null;
|
|
63
108
|
const stop = () => killTree(child);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/kit",
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-cdc3937dea52e",
|
|
4
4
|
"description": "Kit connects an Environment to agents.house.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,12 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@agentclientprotocol/sdk": "2.4.0",
|
|
28
|
-
"@agentshouse/kit-wire": "0.1.0-
|
|
28
|
+
"@agentshouse/kit-wire": "0.1.0-ca55846695d8c",
|
|
29
29
|
"@agentshouse/mdmodel": "0.1.0-cd6a8e5bc7efc",
|
|
30
30
|
"@agentshouse/session-content": "0.1.0-c560e48c9bea3",
|
|
31
|
-
"@agentshouse/skills": "0.1.0-
|
|
31
|
+
"@agentshouse/skills": "0.1.0-c0286f9b00d01",
|
|
32
32
|
"@lydell/node-pty": "1.2.0-beta.15",
|
|
33
33
|
"micromark": "4.0.2",
|
|
34
|
+
"smol-toml": "1.9.1",
|
|
34
35
|
"yaml": "2.9.1"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|