session-peer 0.1.0 → 0.2.1
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/CONTRIBUTING.md +11 -1
- package/PARITY.md +416 -0
- package/README.ja.md +80 -91
- package/README.ko.md +81 -165
- package/README.md +80 -174
- package/README.zh-CN.md +76 -91
- package/RELEASING.md +130 -7
- package/SECURITY.md +3 -2
- package/UNICODE-LICENSE.txt +39 -0
- package/VALIDATION.md +251 -16
- package/dist/casefold.d.ts +2 -0
- package/dist/casefold.js +9 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +87 -30
- package/dist/diagnostics.d.ts +21 -0
- package/dist/diagnostics.js +231 -0
- package/dist/discovery.d.ts +22 -1
- package/dist/discovery.js +199 -50
- package/dist/help.d.ts +1 -0
- package/dist/help.js +50 -0
- package/dist/output.d.ts +2 -0
- package/dist/output.js +43 -0
- package/dist/process.d.ts +1 -0
- package/dist/process.js +14 -2
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +11 -2
- package/dist/send.d.ts +8 -0
- package/dist/send.js +38 -18
- package/dist/windows.d.ts +2 -0
- package/dist/windows.js +30 -3
- package/dist/writer.d.ts +34 -3
- package/dist/writer.js +140 -69
- package/docs/api.md +30 -0
- package/docs/guide.ja.md +208 -0
- package/docs/guide.ko.md +294 -0
- package/docs/guide.md +324 -0
- package/docs/guide.zh-CN.md +204 -0
- package/package.json +6 -3
package/dist/cli.js
CHANGED
|
@@ -1,46 +1,76 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { doctor } from './diagnostics.js';
|
|
3
|
+
import { help } from './help.js';
|
|
4
|
+
import { renderOutput } from './output.js';
|
|
2
5
|
import { hostname } from 'node:os';
|
|
3
6
|
import { lstatSync } from 'node:fs';
|
|
4
|
-
import {
|
|
7
|
+
import { listing, Refusal } from './discovery.js';
|
|
5
8
|
import { executable, run, UnknownOutcome } from './process.js';
|
|
6
|
-
import { checkMessage, send } from './send.js';
|
|
9
|
+
import { checkMessage, send, CodexUnknownOutcome } from './send.js';
|
|
10
|
+
import { HomeRefusal } from './writer.js';
|
|
7
11
|
import { envelope, host, reply, VERSION, VERSION_LINE } from './protocol.js';
|
|
12
|
+
const FLAGS = ['--json', '--all', '--dry-run', '--no-from', '--no-reply-to', '--no-update-notice', '--allow-inactive-codex-home'];
|
|
13
|
+
const VALUES = ['--agent', '--codex-home', '--codex-bin', '--output-format', '--to', '--message', '-m', '--host', '--remote-bin', '--remote-platform', '--ssh-control-path', '--reply-address'];
|
|
8
14
|
export function parse(args) {
|
|
9
15
|
const command = args[0];
|
|
10
|
-
if (command !== 'list' && command !== 'send')
|
|
16
|
+
if (command !== 'list' && command !== 'send' && command !== 'doctor')
|
|
11
17
|
throw new Refusal('unsupported_command');
|
|
12
18
|
const values = new Map(), flags = new Set();
|
|
19
|
+
let positional;
|
|
20
|
+
let terminated = false;
|
|
13
21
|
for (let i = 1; i < args.length; i++) {
|
|
14
22
|
const token = args[i];
|
|
23
|
+
if (token === '--' && !terminated) {
|
|
24
|
+
terminated = true;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (terminated || !token.startsWith('-') || token === '-') {
|
|
28
|
+
if (command !== 'send' || positional !== undefined)
|
|
29
|
+
throw new Refusal('invalid_positional_message');
|
|
30
|
+
positional = token;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
15
33
|
const split = token.indexOf('=');
|
|
16
34
|
const key = split > 0 ? token.slice(0, split) : token;
|
|
17
|
-
if (
|
|
35
|
+
if (FLAGS.includes(key)) {
|
|
18
36
|
if (flags.has(key) || split > 0)
|
|
19
37
|
throw new Refusal('invalid_option');
|
|
20
38
|
flags.add(key);
|
|
21
39
|
}
|
|
22
|
-
else if (
|
|
40
|
+
else if (VALUES.includes(key)) {
|
|
23
41
|
const name = key === '-m' ? '--message' : key;
|
|
24
42
|
const value = split > 0 ? token.slice(split + 1) : args[++i];
|
|
25
|
-
|
|
43
|
+
// A separate value that is itself an option name is a missing value, as in
|
|
44
|
+
// argparse; `--message=--dry-run` or stdin still send such text literally.
|
|
45
|
+
const option = split > 0 ? '' : (value ?? '').split('=')[0];
|
|
46
|
+
if (value === undefined || values.has(name) || [...FLAGS, ...VALUES, '--help', '-h', '--version', '--stdio-request'].includes(option))
|
|
26
47
|
throw new Refusal('invalid_option');
|
|
27
48
|
values.set(name, value);
|
|
28
49
|
}
|
|
29
50
|
else
|
|
30
51
|
throw new Refusal('unsupported_option');
|
|
31
52
|
}
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
if (positional !== undefined) {
|
|
54
|
+
if (values.has('--message'))
|
|
55
|
+
throw new Refusal('conflicting_message_sources');
|
|
56
|
+
values.set('--message', positional);
|
|
57
|
+
}
|
|
58
|
+
if (values.has('--output-format') && !['json', 'text'].includes(values.get('--output-format')))
|
|
35
59
|
throw new Refusal('unsupported_output_format');
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (values.
|
|
60
|
+
if (flags.has('--json') && values.get('--output-format') === 'text')
|
|
61
|
+
throw new Refusal('conflicting_output_options');
|
|
62
|
+
if (!flags.has('--json') && !values.has('--output-format'))
|
|
63
|
+
throw new Refusal('json_output_required');
|
|
64
|
+
if (command === 'list' || command === 'doctor') {
|
|
65
|
+
if (values.has('--agent') && !['claude', 'codex'].includes(values.get('--agent')))
|
|
66
|
+
throw new Refusal('unsupported_agent');
|
|
67
|
+
if (values.has('--codex-home') && !values.get('--codex-home'))
|
|
68
|
+
throw new Refusal('invalid_codex_home');
|
|
69
|
+
if (values.get('--agent') === 'claude' && values.has('--codex-home'))
|
|
42
70
|
throw new Refusal('inapplicable_option');
|
|
43
|
-
if (['--to', '--message', '--
|
|
71
|
+
if (['--to', '--message', '--reply-address', ...(command === 'list' ? ['--codex-bin'] : [])].some(k => values.has(k)) || ['--dry-run', '--no-from', '--no-reply-to', '--allow-inactive-codex-home'].some(k => flags.has(k)))
|
|
72
|
+
throw new Refusal('inapplicable_option');
|
|
73
|
+
if (command === 'doctor' && (flags.has('--all') || (values.get('--agent') === 'claude' && values.has('--codex-bin'))))
|
|
44
74
|
throw new Refusal('inapplicable_option');
|
|
45
75
|
}
|
|
46
76
|
else {
|
|
@@ -59,6 +89,14 @@ export function parse(args) {
|
|
|
59
89
|
values.set('--to', route.to);
|
|
60
90
|
}
|
|
61
91
|
}
|
|
92
|
+
if (command === 'send' && flags.has('--allow-inactive-codex-home')) {
|
|
93
|
+
if (!values.get('--to').startsWith('codex:'))
|
|
94
|
+
throw new Refusal('inapplicable_option');
|
|
95
|
+
if (!values.get('--codex-home'))
|
|
96
|
+
throw new Refusal('inactive_opt_in_requires_explicit_home');
|
|
97
|
+
}
|
|
98
|
+
if (values.has('--codex-home') && !values.get('--codex-home'))
|
|
99
|
+
throw new Refusal('invalid_codex_home');
|
|
62
100
|
if (values.has('--host'))
|
|
63
101
|
host(values.get('--host'));
|
|
64
102
|
if (values.has('--ssh-control-path')) {
|
|
@@ -107,6 +145,9 @@ export function sshPreflightFailure(result, expected) {
|
|
|
107
145
|
return 'ssh_preflight_timeout';
|
|
108
146
|
if (!result.spawned)
|
|
109
147
|
return 'ssh_unavailable';
|
|
148
|
+
// A verified version is success even when login scripts write to stderr.
|
|
149
|
+
if (result.code === 0 && result.stdout.trim() === expected)
|
|
150
|
+
return undefined;
|
|
110
151
|
const detail = result.stderr;
|
|
111
152
|
if (/host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED|no [^\n]*host key is known/i.test(detail))
|
|
112
153
|
return 'ssh_host_key_untrusted';
|
|
@@ -130,7 +171,8 @@ async function remote(options, message) {
|
|
|
130
171
|
const invoke = (flag) => {
|
|
131
172
|
if (!windows)
|
|
132
173
|
return `${quote(binary)} ${flag}`;
|
|
133
|
-
|
|
174
|
+
// PowerShell also closes single-quoted strings on U+2018-U+201B.
|
|
175
|
+
const code = `& '${binary.replace(/['\u2018-\u201b]/g, '$&$&')}' ${flag}`;
|
|
134
176
|
return `powershell.exe -NoProfile -NonInteractive -EncodedCommand ${Buffer.from(code, 'utf16le').toString('base64')}`;
|
|
135
177
|
};
|
|
136
178
|
const ssh = executable('ssh');
|
|
@@ -148,8 +190,10 @@ async function remote(options, message) {
|
|
|
148
190
|
args.push('--all');
|
|
149
191
|
if (flags.has('--dry-run'))
|
|
150
192
|
args.push('--dry-run');
|
|
193
|
+
if (flags.has('--allow-inactive-codex-home'))
|
|
194
|
+
args.push('--allow-inactive-codex-home');
|
|
151
195
|
if (command === 'send')
|
|
152
|
-
args.push(
|
|
196
|
+
args.push(`--message=${message}`, '--no-from', '--no-reply-to');
|
|
153
197
|
const done = await run(ssh, [...base, invoke('--stdio-request')], {
|
|
154
198
|
timeout: 90000, input: JSON.stringify({ schemaVersion: 1, args })
|
|
155
199
|
});
|
|
@@ -167,14 +211,17 @@ async function remote(options, message) {
|
|
|
167
211
|
if (!value || value.schemaVersion !== 1 || value.command !== command || typeof value.ok !== 'boolean' || typeof value.host !== 'string' ||
|
|
168
212
|
![0, 1, 2].includes(done.code ?? -1) || (value.ok !== (done.code === 0)))
|
|
169
213
|
return uncertain();
|
|
214
|
+
if (command === 'doctor' && value.ok && (value.diagnosticCompleted !== true || typeof value.ready !== 'boolean' || value.implementation !== 'typescript' || !value.agents || typeof value.agents !== 'object' || Array.isArray(value.agents)))
|
|
215
|
+
return uncertain();
|
|
170
216
|
const expectedStatus = flags.has('--dry-run') ? 'validated' : values.get('--to')?.startsWith('codex:') ? 'queued' : 'posted';
|
|
171
217
|
if (command === 'send' && (value.consumptionConfirmed !== false ||
|
|
172
218
|
(value.ok && (value.submitted !== !flags.has('--dry-run') || value.status !== expectedStatus)) ||
|
|
173
219
|
(!value.ok && !((value.submitted === false && value.status === 'refused') || (value.submitted === null && value.status === 'unknown')))))
|
|
174
220
|
return uncertain();
|
|
175
|
-
return { ...value, host: target, sshHost: target };
|
|
221
|
+
return { value: { ...value, host: target, sshHost: target }, exitCode: done.code };
|
|
176
222
|
}
|
|
177
223
|
let command = 'unknown';
|
|
224
|
+
let format = 'json';
|
|
178
225
|
try {
|
|
179
226
|
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
180
227
|
if (!((major === 22 && minor >= 13) || major === 24))
|
|
@@ -184,8 +231,9 @@ try {
|
|
|
184
231
|
let args = process.argv.slice(2);
|
|
185
232
|
if (args.length === 1 && args[0] === '--version')
|
|
186
233
|
console.log(VERSION_LINE);
|
|
187
|
-
else if (args.length === 1 && ['--help', '-h'].includes(args[0]))
|
|
188
|
-
|
|
234
|
+
else if ((args.length === 1 && ['--help', '-h'].includes(args[0])) ||
|
|
235
|
+
(args.length === 2 && ['list', 'send', 'doctor'].includes(args[0]) && ['--help', '-h'].includes(args[1])))
|
|
236
|
+
console.log(help(args.length === 2 ? args[0] : undefined));
|
|
189
237
|
else {
|
|
190
238
|
const wire = args.length === 1 && args[0] === '--stdio-request';
|
|
191
239
|
if (wire) {
|
|
@@ -201,8 +249,11 @@ try {
|
|
|
201
249
|
throw new Refusal('invalid_remote_request');
|
|
202
250
|
args = record.args;
|
|
203
251
|
}
|
|
204
|
-
command = ['list', 'send'].includes(args[0] ?? '') ? args[0] : 'unknown';
|
|
252
|
+
command = ['list', 'send', 'doctor'].includes(args[0] ?? '') ? args[0] : 'unknown';
|
|
205
253
|
const options = parse(args);
|
|
254
|
+
format = !wire && options.values.get('--output-format') === 'text' ? 'text' : 'json';
|
|
255
|
+
if (wire && options.values.get('--output-format') === 'text')
|
|
256
|
+
throw new Refusal('remote_json_required');
|
|
206
257
|
if (wire && (options.values.has('--host') || options.values.has('--remote-bin') || options.values.has('--remote-platform') || options.values.has('--ssh-control-path')))
|
|
207
258
|
throw new Refusal('nested_transport_forbidden');
|
|
208
259
|
let message;
|
|
@@ -213,25 +264,31 @@ try {
|
|
|
213
264
|
throw new Refusal('remote_message_required');
|
|
214
265
|
message = await input();
|
|
215
266
|
}
|
|
267
|
+
checkMessage(message);
|
|
216
268
|
message = envelope(message, options.flags.has('--no-from'), options.values.get('--reply-address'));
|
|
217
269
|
checkMessage(message, options.values.get('--to').startsWith('codex:'));
|
|
218
270
|
}
|
|
219
|
-
let result;
|
|
271
|
+
let result, exitCode;
|
|
272
|
+
// Propagate the verified remote exit code so SSH and local refusals match.
|
|
220
273
|
if (options.values.has('--host'))
|
|
221
|
-
result = await remote(options, message);
|
|
274
|
+
({ value: result, exitCode } = await remote(options, message));
|
|
222
275
|
else if (command === 'send')
|
|
223
|
-
result = await send({ to: options.values.get('--to'), home: options.values.get('--codex-home'), codexBin: options.values.get('--codex-bin'), message: message, dryRun: options.flags.has('--dry-run') });
|
|
276
|
+
result = await send({ to: options.values.get('--to'), home: options.values.get('--codex-home'), codexBin: options.values.get('--codex-bin'), message: message, dryRun: options.flags.has('--dry-run'), allowInactive: options.flags.has('--allow-inactive-codex-home') });
|
|
277
|
+
else if (command === 'doctor')
|
|
278
|
+
result = await doctor(options.values.get('--agent'), options.values.get('--codex-home'), options.values.get('--codex-bin'));
|
|
224
279
|
else
|
|
225
|
-
result = options.values.get('--agent')
|
|
226
|
-
console.log(
|
|
227
|
-
process.exitCode = result.ok === false ? 1 : 0;
|
|
280
|
+
result = await listing(options.values.get('--agent'), options.values.get('--codex-home'), options.flags.has('--all'));
|
|
281
|
+
console.log(renderOutput({ schemaVersion: 1, host: hostname(), command, ok: result.ok !== false, version: VERSION, referenceVersion: '1.0.2', ...result }, format));
|
|
282
|
+
process.exitCode = exitCode ?? (result.ok === false ? 1 : 0);
|
|
228
283
|
}
|
|
229
284
|
}
|
|
230
285
|
catch (error) {
|
|
231
286
|
const unknown = error instanceof UnknownOutcome;
|
|
232
287
|
const failure = error instanceof Refusal ? error : new Refusal('operation_failed', 1);
|
|
233
|
-
|
|
288
|
+
const homeResolution = error instanceof HomeRefusal || error instanceof CodexUnknownOutcome ? error.codexHomeResolution : undefined;
|
|
289
|
+
console.log(renderOutput({ schemaVersion: 1, host: hostname(), command, ok: false,
|
|
234
290
|
error: unknown ? 'outcome_unknown' : failure.code, status: unknown ? 'unknown' : 'refused',
|
|
235
|
-
submitted: unknown ? null : false, consumptionConfirmed: false, retryAllowed: false
|
|
291
|
+
submitted: unknown ? null : false, consumptionConfirmed: false, retryAllowed: false,
|
|
292
|
+
...(homeResolution === undefined ? {} : { codexHomeResolution: homeResolution }) }, format));
|
|
236
293
|
process.exitCode = unknown ? 1 : failure.exitCode;
|
|
237
294
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type Check = {
|
|
2
|
+
status: string;
|
|
3
|
+
code: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare const capabilities: {
|
|
7
|
+
list: boolean;
|
|
8
|
+
send: boolean;
|
|
9
|
+
doctor: boolean;
|
|
10
|
+
wake: boolean;
|
|
11
|
+
wait: boolean;
|
|
12
|
+
ack: boolean;
|
|
13
|
+
consumptionConfirmation: boolean;
|
|
14
|
+
transports: string[];
|
|
15
|
+
agents: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function diagnoseCodex(home?: string, binary?: string): Promise<Record<string, unknown>>;
|
|
18
|
+
export declare function diagnoseClaude(): Record<string, unknown>;
|
|
19
|
+
export declare function doctor(agent?: 'claude' | 'codex', home?: string, binary?: string): Promise<Record<string, unknown>>;
|
|
20
|
+
export declare function inspectSkills(home?: string): Check[];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Diagnostics inspect bounded metadata only. Never probe/connect to an inbox,
|
|
2
|
+
// acquire a writer lock, execute an agent binary, or write configuration.
|
|
3
|
+
import { accessSync, constants, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { delimiter, isAbsolute, join } from 'node:path';
|
|
6
|
+
import { canonical, listingCandidates, sqliteHome } from './discovery.js';
|
|
7
|
+
import { batchShim } from './process.js';
|
|
8
|
+
import { windowsProcessStart } from './windows.js';
|
|
9
|
+
const failure = (error, missing, unknown) => {
|
|
10
|
+
const code = error.code;
|
|
11
|
+
return code === 'ENOENT' || code === 'ENOTDIR' ? { status: 'missing', code: missing } :
|
|
12
|
+
code === 'EACCES' || code === 'EPERM' ? { status: 'permission_denied', code: 'permission_denied' } :
|
|
13
|
+
{ status: 'unknown', code: unknown };
|
|
14
|
+
};
|
|
15
|
+
export const capabilities = {
|
|
16
|
+
list: true, send: true, doctor: true, wake: false, wait: false, ack: false,
|
|
17
|
+
consumptionConfirmation: false, transports: ['local', 'ssh'], agents: ['claude', 'codex']
|
|
18
|
+
};
|
|
19
|
+
function tool(name) {
|
|
20
|
+
const names = process.platform === 'win32' && !/\.(?:exe|cmd|bat)$/i.test(name) ? [name + '.exe', name + '.cmd', name] : [name];
|
|
21
|
+
const paths = isAbsolute(name) ? [name] : name.includes('/') || name.includes('\\') ? [] :
|
|
22
|
+
(process.env.PATH ?? '').split(delimiter).filter(Boolean).flatMap(path => names.map(base => join(path, base)));
|
|
23
|
+
let diagnostic = { status: 'missing', code: 'executable_unavailable', executed: false };
|
|
24
|
+
for (const path of paths) {
|
|
25
|
+
try {
|
|
26
|
+
if (!statSync(path).isFile())
|
|
27
|
+
continue;
|
|
28
|
+
accessSync(path, constants.X_OK);
|
|
29
|
+
if (batchShim(path))
|
|
30
|
+
return { status: 'unsupported', code: 'executable_unsupported', path, executed: false };
|
|
31
|
+
return { status: 'available', code: 'executable_found', path, executed: false };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const found = failure(error, 'executable_unavailable', 'executable_inspection_unknown');
|
|
35
|
+
if (found.status !== 'missing')
|
|
36
|
+
diagnostic = { ...found, executed: false };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return diagnostic;
|
|
40
|
+
}
|
|
41
|
+
async function codexHome(file) {
|
|
42
|
+
try {
|
|
43
|
+
if (!statSync(file).isFile())
|
|
44
|
+
return { status: 'unsupported', code: 'state_db_not_regular' };
|
|
45
|
+
accessSync(file, constants.R_OK);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return failure(error, 'state_db_missing', 'state_db_unreadable');
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const { DatabaseSync } = await import('node:sqlite');
|
|
52
|
+
const db = new DatabaseSync(file, { readOnly: true });
|
|
53
|
+
try {
|
|
54
|
+
db.exec('PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=3000');
|
|
55
|
+
const columns = new Set(db.prepare('PRAGMA table_info(threads)').all().map(row => row.name));
|
|
56
|
+
const missingColumns = ['id', 'title', 'cwd', 'updated_at', 'archived', 'rollout_path'].filter(name => !columns.has(name));
|
|
57
|
+
if (missingColumns.length)
|
|
58
|
+
return { status: 'unsupported', code: 'unsupported_threads_schema', missingColumns };
|
|
59
|
+
const count = db.prepare('SELECT COUNT(*) AS count FROM threads').get().count;
|
|
60
|
+
return { status: 'available', code: 'state_db_readable', sessionCount: count };
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
db.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return failure(error, 'state_db_missing', 'state_db_unreadable');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export async function diagnoseCodex(home, binary) {
|
|
71
|
+
const inventory = listingCandidates(home);
|
|
72
|
+
const homes = [];
|
|
73
|
+
for (const item of inventory.homes) {
|
|
74
|
+
const storage = sqliteHome(item.codexHome);
|
|
75
|
+
homes.push({ ...item, ...(storage === 'configured' ? { status: 'unsupported', code: 'unsupported_codex_sqlite_home' } :
|
|
76
|
+
storage === 'unknown' ? { status: 'unknown', code: 'codex_config_unreadable' } : await codexHome(item.stateDb)) });
|
|
77
|
+
}
|
|
78
|
+
const agentTool = tool(binary ?? 'codex');
|
|
79
|
+
const complete = inventory.errors.length === 0 && homes.every(item => item.status === 'available' || (!item.required && item.status === 'missing'));
|
|
80
|
+
const ready = complete && homes.some(item => item.status === 'available') && agentTool.status === 'available';
|
|
81
|
+
return { ready, status: ready ? 'available' : 'unavailable', tool: agentTool, homes,
|
|
82
|
+
errors: inventory.errors, verification: 'read_only_metadata', writerVerified: false,
|
|
83
|
+
sendAuthorized: false };
|
|
84
|
+
}
|
|
85
|
+
export function diagnoseClaude() {
|
|
86
|
+
const directory = join(process.env.CLAUDE_CONFIG_DIR || process.env.ANTHROPIC_CONFIG_DIR || join(homedir(), '.claude'), 'sessions');
|
|
87
|
+
const result = { sessionsDir: directory, records: 0, invalidRecords: 0, aliveSessions: 0,
|
|
88
|
+
availableInboxes: 0, staleRecords: 0, unknownInspections: 0, permissionFailures: 0 };
|
|
89
|
+
let entries;
|
|
90
|
+
try {
|
|
91
|
+
if (!statSync(directory).isDirectory())
|
|
92
|
+
return { ...result, ready: false, status: 'unsupported', code: 'sessions_path_not_directory' };
|
|
93
|
+
entries = readdirSync(directory).sort();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return { ...result, ready: false, ...failure(error, 'sessions_dir_missing', 'sessions_dir_unreadable') };
|
|
97
|
+
}
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
if (!/^[0-9]+\.json$/.test(entry))
|
|
100
|
+
continue;
|
|
101
|
+
let record;
|
|
102
|
+
try {
|
|
103
|
+
const path = join(directory, entry), info = statSync(path);
|
|
104
|
+
if (!info.isFile() || info.size > 65536) {
|
|
105
|
+
result.invalidRecords++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
109
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
110
|
+
result.invalidRecords++;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
record = value;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (['EACCES', 'EPERM'].includes(error.code ?? ''))
|
|
117
|
+
result.permissionFailures++;
|
|
118
|
+
else if (error instanceof SyntaxError)
|
|
119
|
+
result.invalidRecords++;
|
|
120
|
+
else
|
|
121
|
+
result.unknownInspections++;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const pid = record.pid;
|
|
125
|
+
if (typeof pid !== 'number' || !Number.isSafeInteger(pid) || pid <= 1 || pid > 2147483647) {
|
|
126
|
+
result.invalidRecords++;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
result.records++;
|
|
130
|
+
if (pid !== Number(entry.slice(0, -5))) {
|
|
131
|
+
result.staleRecords++;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
let live = false;
|
|
135
|
+
if (process.platform === 'win32') {
|
|
136
|
+
const ticks = windowsProcessStart(pid);
|
|
137
|
+
if (ticks === undefined || typeof record.startedAt !== 'number' || !Number.isSafeInteger(record.startedAt) || record.startedAt <= 0) {
|
|
138
|
+
result.unknownInspections++;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
live = Number((ticks - 116444736000000000n) / 10000n) <= record.startedAt + 2000;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
try {
|
|
145
|
+
process.kill(pid, 0);
|
|
146
|
+
live = true;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (error.code !== 'ESRCH') {
|
|
150
|
+
result.unknownInspections++;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!live) {
|
|
156
|
+
result.staleRecords++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
result.aliveSessions++;
|
|
160
|
+
const socket = typeof record.messagingSocketPath === 'string' ? record.messagingSocketPath : '';
|
|
161
|
+
if (process.platform === 'win32') {
|
|
162
|
+
// A named pipe advertisement is not proof that the pipe exists or accepts connections.
|
|
163
|
+
if (/^\\\\\.\\pipe\\[^\r\n]+$/i.test(socket))
|
|
164
|
+
result.availableInboxes++;
|
|
165
|
+
}
|
|
166
|
+
else if (socket) {
|
|
167
|
+
try {
|
|
168
|
+
if (statSync(socket).isSocket())
|
|
169
|
+
result.availableInboxes++;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (!['ENOENT', 'ENOTDIR'].includes(error.code ?? '')) {
|
|
173
|
+
result.unknownInspections++;
|
|
174
|
+
if (['EACCES', 'EPERM'].includes(error.code ?? ''))
|
|
175
|
+
result.permissionFailures++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const ready = result.availableInboxes > 0 && result.permissionFailures === 0 && result.unknownInspections === 0;
|
|
181
|
+
const code = result.permissionFailures ? 'permission_denied' : result.unknownInspections ? 'inspection_unknown' :
|
|
182
|
+
result.availableInboxes ? 'inbox_advertised' : result.aliveSessions ? 'inbox_unavailable' : 'no_live_sessions';
|
|
183
|
+
return { ...result, ready, status: ready ? 'available' : 'unavailable', code,
|
|
184
|
+
verification: process.platform === 'win32' ? 'process_and_pipe_advertisement' : 'process_and_filesystem',
|
|
185
|
+
inboxConnected: false, sendAuthorized: false };
|
|
186
|
+
}
|
|
187
|
+
export async function doctor(agent, home, binary) {
|
|
188
|
+
const agents = {};
|
|
189
|
+
if (!agent || agent === 'claude')
|
|
190
|
+
agents.claude = diagnoseClaude();
|
|
191
|
+
if (!agent || agent === 'codex')
|
|
192
|
+
agents.codex = await diagnoseCodex(home, binary);
|
|
193
|
+
return { ok: true, ready: Object.values(agents).every(item => item.ready === true), agents,
|
|
194
|
+
implementation: 'typescript', skills: inspectSkills(home), capabilities, diagnosticCompleted: true, consumptionConfirmed: false };
|
|
195
|
+
}
|
|
196
|
+
// Inspect only named skill entrypoints; interpret frontmatter, never instructions or references.
|
|
197
|
+
export function inspectSkills(home) {
|
|
198
|
+
const paths = new Set([join(homedir(), '.agents/skills/session-peer-ts/SKILL.md'),
|
|
199
|
+
join(home || process.env.CODEX_HOME || join(homedir(), '.codex'), 'skills/session-peer-ts/SKILL.md')]);
|
|
200
|
+
return [...paths].map(path => {
|
|
201
|
+
try {
|
|
202
|
+
path = canonical(path);
|
|
203
|
+
if (!statSync(path).isFile() || statSync(path).size > 65536)
|
|
204
|
+
return { path, status: 'unknown', code: 'skill_metadata_unreadable' };
|
|
205
|
+
const text = readFileSync(path, 'utf8');
|
|
206
|
+
const front = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text)?.[1];
|
|
207
|
+
if (!front)
|
|
208
|
+
return { path, status: 'unknown', code: 'skill_metadata_missing' };
|
|
209
|
+
const lines = front.split(/\r?\n/);
|
|
210
|
+
const sections = lines.map((line, index) => /^metadata: *(?:#.*)?$/.test(line) ? index : -1).filter(index => index >= 0);
|
|
211
|
+
if (sections.length !== 1)
|
|
212
|
+
return { path, status: 'unknown', code: 'skill_metadata_missing' };
|
|
213
|
+
const start = sections[0] + 1;
|
|
214
|
+
let end = start;
|
|
215
|
+
while (end < lines.length && (/^ /.test(lines[end]) || /^ *(?:#.*)?$/.test(lines[end])))
|
|
216
|
+
end++;
|
|
217
|
+
const fields = lines.slice(start, end).map(line => /^ ([a-z-]+): *(?:"([^"\r\n]*)"|'([^'\r\n]*)'|([^#"'\r\n]*?)) *(?:#.*)?$/.exec(line));
|
|
218
|
+
const field = (key) => {
|
|
219
|
+
const values = fields.filter(match => match?.[1] === key).map(match => (match[2] ?? match[3] ?? match[4]).trim());
|
|
220
|
+
return values.length === 1 ? values[0] : undefined;
|
|
221
|
+
};
|
|
222
|
+
const implementation = field('runtime-implementation'), minimum = field('runtime-min-version');
|
|
223
|
+
const policy = field('runtime-capability-policy');
|
|
224
|
+
const compatible = implementation === 'typescript' && minimum === '0.1.0' && policy === 'probe-help' && field('version') === '0.1.0' && field('runtime-full-version') === '0.1.0';
|
|
225
|
+
return { path, status: compatible ? 'compatible' : 'incompatible', code: compatible ? 'skill_contract_compatible' : 'skill_contract_mismatch', verification: 'metadata_only' };
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
return { path, ...failure(error, 'skill_missing', 'skill_metadata_unreadable') };
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -4,7 +4,28 @@ export declare class Refusal extends Error {
|
|
|
4
4
|
readonly exitCode: number;
|
|
5
5
|
constructor(code: string, exitCode?: number);
|
|
6
6
|
}
|
|
7
|
+
export declare function sqliteHome(home: string): 'default' | 'configured' | 'unknown';
|
|
7
8
|
export declare function canonical(path: string): string;
|
|
8
9
|
export declare function claude(all: boolean): Row;
|
|
9
|
-
export declare function
|
|
10
|
+
export declare function configuredHomePaths(): string[];
|
|
11
|
+
export declare function orcaHomePaths(): string[];
|
|
12
|
+
type Candidate = {
|
|
13
|
+
codexHome: string;
|
|
14
|
+
stateDb: string;
|
|
15
|
+
sources: string[];
|
|
16
|
+
required: boolean;
|
|
17
|
+
};
|
|
18
|
+
type Listing = {
|
|
19
|
+
sessions: Row[];
|
|
20
|
+
discovery: Record<string, Row>;
|
|
21
|
+
ok?: boolean;
|
|
22
|
+
codexHome?: string;
|
|
23
|
+
error?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function listingCandidates(explicit?: string): {
|
|
26
|
+
homes: Candidate[];
|
|
27
|
+
errors: Row[];
|
|
28
|
+
};
|
|
29
|
+
export declare function codex(path: string | undefined, all: boolean): Promise<Listing>;
|
|
30
|
+
export declare function listing(agent: 'claude' | 'codex' | undefined, home: string | undefined, all: boolean): Promise<Listing>;
|
|
10
31
|
export {};
|