runspec-node 0.7.0 → 0.8.0
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/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +100 -9
- package/dist/cli.js.map +1 -1
- package/dist/inference.d.ts.map +1 -1
- package/dist/inference.js +7 -1
- package/dist/inference.js.map +1 -1
- package/dist/jump.d.ts +7 -0
- package/dist/jump.d.ts.map +1 -0
- package/dist/jump.js +246 -0
- package/dist/jump.js.map +1 -0
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +18 -0
- package/dist/loader.js.map +1 -1
- package/dist/models.d.ts +19 -6
- package/dist/models.d.ts.map +1 -1
- package/dist/parser.d.ts +1 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +31 -11
- package/dist/parser.js.map +1 -1
- package/dist/runspec.toml +81 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +116 -10
- package/src/inference.ts +4 -1
- package/src/jump.ts +243 -0
- package/src/loader.ts +20 -1
- package/src/models.ts +20 -6
- package/src/parser.ts +34 -11
- package/src/runspec.toml +81 -0
- package/src/types.ts +1 -0
- package/tests/test_cli_init.test.ts +5 -5
package/src/jump.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import type { ChildProcess } from 'child_process';
|
|
3
|
+
import * as readline from 'readline';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import type { JumpHostConfig } from './models';
|
|
6
|
+
|
|
7
|
+
const VALID_BIN_NAMES = new Set(['runspec', 'runspec.exe']);
|
|
8
|
+
|
|
9
|
+
export function resolveBinRaw(hostCfg: JumpHostConfig): string {
|
|
10
|
+
return hostCfg.bin ?? process.env['RUNSPEC_JUMP_BIN'] ?? 'runspec';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function resolveBin(hostCfg: JumpHostConfig): string {
|
|
14
|
+
const binPath = resolveBinRaw(hostCfg);
|
|
15
|
+
validateBinPath(binPath);
|
|
16
|
+
return binPath;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function validateBinPath(binPath: string): void {
|
|
20
|
+
const name = path.basename(binPath);
|
|
21
|
+
if (!VALID_BIN_NAMES.has(name)) {
|
|
22
|
+
process.stderr.write(
|
|
23
|
+
`✗ Jump-host \`bin\` must point at a runspec executable.\n` +
|
|
24
|
+
` Got: ${JSON.stringify(binPath)} (basename ${JSON.stringify(name)})\n` +
|
|
25
|
+
` Expected basename: 'runspec' (or 'runspec.exe' on Windows).\n` +
|
|
26
|
+
` This field is locked to the runspec CLI; it cannot be redirected.\n`,
|
|
27
|
+
);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function sshCmd(hostCfg: JumpHostConfig, binPath: string): string[] {
|
|
33
|
+
const cmd = ['ssh', '-o', 'BatchMode=yes'];
|
|
34
|
+
|
|
35
|
+
if (hostCfg.useSshConfig === false) {
|
|
36
|
+
cmd.push('-F', '/dev/null');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (hostCfg.port && hostCfg.port !== 22) {
|
|
40
|
+
cmd.push('-p', String(hostCfg.port));
|
|
41
|
+
}
|
|
42
|
+
if (hostCfg.sshKey) {
|
|
43
|
+
cmd.push('-i', hostCfg.sshKey);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const opt of hostCfg.sshOptions ?? []) {
|
|
47
|
+
cmd.push('-o', String(opt));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const target = hostCfg.user ? `${hostCfg.user}@${hostCfg.host}` : hostCfg.host;
|
|
51
|
+
cmd.push(target, binPath, 'serve');
|
|
52
|
+
return cmd;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface Session {
|
|
56
|
+
send: (msg: Record<string, unknown>) => void;
|
|
57
|
+
recv: () => Promise<Record<string, unknown>>;
|
|
58
|
+
close: () => void;
|
|
59
|
+
proc: ChildProcess;
|
|
60
|
+
binPath: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function openSession(hostCfg: JumpHostConfig, binPath: string): Session {
|
|
64
|
+
const cmd = sshCmd(hostCfg, binPath);
|
|
65
|
+
const proc = spawn(cmd[0], cmd.slice(1), { stdio: ['pipe', 'pipe', 'inherit'] });
|
|
66
|
+
|
|
67
|
+
proc.on('error', (err: NodeJS.ErrnoException) => {
|
|
68
|
+
if (err.code === 'ENOENT') {
|
|
69
|
+
process.stderr.write('✗ ssh not found — install OpenSSH\n');
|
|
70
|
+
} else {
|
|
71
|
+
process.stderr.write(`✗ Failed to launch ssh: ${err.message}\n`);
|
|
72
|
+
}
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const rl = readline.createInterface({ input: proc.stdout!, crlfDelay: Infinity });
|
|
77
|
+
const iter = rl[Symbol.asyncIterator]();
|
|
78
|
+
|
|
79
|
+
const send = (msg: Record<string, unknown>): void => {
|
|
80
|
+
proc.stdin!.write(JSON.stringify(msg) + '\n');
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const recv = async (): Promise<Record<string, unknown>> => {
|
|
84
|
+
const { value, done } = await iter.next();
|
|
85
|
+
if (done) {
|
|
86
|
+
await reportRemoteFailure(proc, binPath);
|
|
87
|
+
throw new Error('unreachable');
|
|
88
|
+
}
|
|
89
|
+
return JSON.parse(value as string) as Record<string, unknown>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const close = (): void => {
|
|
93
|
+
rl.close();
|
|
94
|
+
if (proc.stdin) proc.stdin.destroy();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return { send, recv, close, proc, binPath };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function reportRemoteFailure(proc: ChildProcess, binPath: string): Promise<never> {
|
|
101
|
+
const exitCode =
|
|
102
|
+
proc.exitCode ??
|
|
103
|
+
(await new Promise<number | null>((resolve) => {
|
|
104
|
+
const timer = setTimeout(() => resolve(null), 1000);
|
|
105
|
+
proc.once('exit', (code) => {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
resolve(code);
|
|
108
|
+
});
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
if (exitCode === 255) {
|
|
112
|
+
process.stderr.write('✗ SSH connection failed (see error above for details).\n');
|
|
113
|
+
} else if (exitCode !== null && exitCode !== 0) {
|
|
114
|
+
const prefix = `✗ Remote command failed (exit ${exitCode}) before the MCP handshake completed.\n`;
|
|
115
|
+
if (binPath.includes('/')) {
|
|
116
|
+
process.stderr.write(
|
|
117
|
+
prefix +
|
|
118
|
+
' If the error above doesn\'t explain it, verify the path exists on the remote:\n' +
|
|
119
|
+
` ${binPath}\n` +
|
|
120
|
+
' Common causes:\n' +
|
|
121
|
+
' - the venv path differs between local and remote\n' +
|
|
122
|
+
" - runspec isn't installed in that venv on the remote\n" +
|
|
123
|
+
' - typo in the bin / RUNSPEC_JUMP_BIN value\n',
|
|
124
|
+
);
|
|
125
|
+
} else {
|
|
126
|
+
process.stderr.write(
|
|
127
|
+
prefix +
|
|
128
|
+
` \`${binPath}\` is not on the remote shell's PATH.\n` +
|
|
129
|
+
' Fix: set `bin = "/full/path/to/runspec"` in [config.jump-hosts.<alias>],\n' +
|
|
130
|
+
' or export RUNSPEC_JUMP_BIN in your local shell.\n' +
|
|
131
|
+
" (SSH commands run in a non-login shell and don't source ~/.bashrc / ~/.profile.)\n",
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
process.stderr.write('✗ Remote MCP server closed stdout unexpectedly\n');
|
|
136
|
+
}
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function initialize(session: Session): Promise<void> {
|
|
141
|
+
session.send({
|
|
142
|
+
jsonrpc: '2.0',
|
|
143
|
+
id: 1,
|
|
144
|
+
method: 'initialize',
|
|
145
|
+
params: {
|
|
146
|
+
protocolVersion: '2024-11-05',
|
|
147
|
+
capabilities: {},
|
|
148
|
+
clientInfo: { name: 'runspec-jump', version: '1.0' },
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
await session.recv();
|
|
152
|
+
session.send({ jsonrpc: '2.0', method: 'notifications/initialized', params: {} });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function listTools(hostCfg: JumpHostConfig): Promise<Array<Record<string, unknown>>> {
|
|
156
|
+
const binPath = resolveBin(hostCfg);
|
|
157
|
+
const session = openSession(hostCfg, binPath);
|
|
158
|
+
try {
|
|
159
|
+
await initialize(session);
|
|
160
|
+
session.send({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} });
|
|
161
|
+
const resp = await session.recv();
|
|
162
|
+
return ((resp['result'] as Record<string, unknown>)?.['tools'] as Array<Record<string, unknown>>) ?? [];
|
|
163
|
+
} finally {
|
|
164
|
+
session.close();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function callTool(hostCfg: JumpHostConfig, toolName: string, toolArgv: string[]): Promise<void> {
|
|
169
|
+
const binPath = resolveBin(hostCfg);
|
|
170
|
+
const session = openSession(hostCfg, binPath);
|
|
171
|
+
try {
|
|
172
|
+
await initialize(session);
|
|
173
|
+
session.send({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} });
|
|
174
|
+
const toolsResp = await session.recv();
|
|
175
|
+
const tools =
|
|
176
|
+
((toolsResp['result'] as Record<string, unknown>)?.['tools'] as Array<Record<string, unknown>>) ?? [];
|
|
177
|
+
const schema = tools.find((t) => t['name'] === toolName);
|
|
178
|
+
if (!schema) {
|
|
179
|
+
process.stderr.write(`✗ Tool '${toolName}' not found on remote\n`);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const arguments_ = parseToolArgv(toolArgv, schema);
|
|
184
|
+
session.send({
|
|
185
|
+
jsonrpc: '2.0',
|
|
186
|
+
id: 3,
|
|
187
|
+
method: 'tools/call',
|
|
188
|
+
params: { name: toolName, arguments: arguments_ },
|
|
189
|
+
});
|
|
190
|
+
const callResp = await session.recv();
|
|
191
|
+
|
|
192
|
+
if ('error' in callResp) {
|
|
193
|
+
const err = callResp['error'] as Record<string, unknown>;
|
|
194
|
+
process.stderr.write(`✗ ${(err['message'] as string | undefined) ?? 'Remote error'}\n`);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const result = (callResp['result'] as Record<string, unknown>) ?? {};
|
|
199
|
+
for (const block of (result['content'] as Array<Record<string, unknown>>) ?? []) {
|
|
200
|
+
if (block['type'] === 'text') {
|
|
201
|
+
const text = block['text'] as string;
|
|
202
|
+
process.stdout.write(text);
|
|
203
|
+
if (!text.endsWith('\n')) process.stdout.write('\n');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (result['isError']) {
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
} finally {
|
|
211
|
+
session.close();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function parseToolArgv(argv: string[], schema: Record<string, unknown>): Record<string, unknown> {
|
|
216
|
+
const props =
|
|
217
|
+
((schema['inputSchema'] as Record<string, unknown>)?.['properties'] as Record<
|
|
218
|
+
string,
|
|
219
|
+
Record<string, unknown>
|
|
220
|
+
>) ?? {};
|
|
221
|
+
const result: Record<string, unknown> = {};
|
|
222
|
+
let i = 0;
|
|
223
|
+
while (i < argv.length) {
|
|
224
|
+
const token = argv[i];
|
|
225
|
+
if (!token.startsWith('--')) {
|
|
226
|
+
i++;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const argName = token.slice(2);
|
|
230
|
+
const prop = props[argName] ?? {};
|
|
231
|
+
if (prop['type'] === 'boolean') {
|
|
232
|
+
result[argName] = true;
|
|
233
|
+
i++;
|
|
234
|
+
} else if (i + 1 < argv.length) {
|
|
235
|
+
result[argName] = argv[i + 1];
|
|
236
|
+
i += 2;
|
|
237
|
+
} else {
|
|
238
|
+
process.stderr.write(`✗ --${argName} requires a value\n`);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
package/src/loader.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { parse as parseTOML } from 'smol-toml';
|
|
3
|
-
import type { RawConfig, RawSpec, ScriptSpec, ArgSpec, GroupSpec } from './models';
|
|
3
|
+
import type { RawConfig, RawSpec, ScriptSpec, ArgSpec, GroupSpec, JumpHostConfig } from './models';
|
|
4
4
|
|
|
5
5
|
export function loadRaw(configPath: string): RawSpec {
|
|
6
6
|
const content = fs.readFileSync(configPath, 'utf-8');
|
|
@@ -20,10 +20,28 @@ export function loadRaw(configPath: string): RawSpec {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function normaliseConfig(raw: Record<string, unknown>): RawConfig {
|
|
23
|
+
const rawHosts = (raw['jump-hosts'] ?? {}) as Record<string, Record<string, unknown>>;
|
|
24
|
+
const jumpHosts: Record<string, JumpHostConfig> = {};
|
|
25
|
+
for (const [name, cfg] of Object.entries(rawHosts)) {
|
|
26
|
+
jumpHosts[name] = normaliseJumpHost(cfg);
|
|
27
|
+
}
|
|
23
28
|
return {
|
|
24
29
|
autonomyDefault: (raw['autonomy-default'] as string | undefined) ?? 'confirm',
|
|
25
30
|
lang: raw['lang'] as string | undefined,
|
|
26
31
|
version: String(raw['version'] ?? '1'),
|
|
32
|
+
jumpHosts,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function normaliseJumpHost(raw: Record<string, unknown>): JumpHostConfig {
|
|
37
|
+
return {
|
|
38
|
+
host: raw['host'] as string,
|
|
39
|
+
user: raw['user'] as string | undefined,
|
|
40
|
+
port: raw['port'] as number | undefined,
|
|
41
|
+
sshKey: raw['ssh-key'] as string | undefined,
|
|
42
|
+
bin: raw['bin'] as string | undefined,
|
|
43
|
+
useSshConfig: raw['use-ssh-config'] as boolean | undefined,
|
|
44
|
+
sshOptions: raw['ssh-options'] as string[] | undefined,
|
|
27
45
|
};
|
|
28
46
|
}
|
|
29
47
|
|
|
@@ -67,6 +85,7 @@ function normaliseArg(name: string, raw: Record<string, unknown>): ArgSpec {
|
|
|
67
85
|
multiple: (raw['multiple'] as boolean | undefined) ?? false,
|
|
68
86
|
delimiter: raw['delimiter'] as string | undefined,
|
|
69
87
|
short: raw['short'] as string | undefined,
|
|
88
|
+
position: raw['position'] as number | undefined,
|
|
70
89
|
env: raw['env'] as string | undefined,
|
|
71
90
|
deprecated: raw['deprecated'] as string | undefined,
|
|
72
91
|
autonomy: raw['autonomy'] as string | undefined,
|
package/src/models.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
export interface JumpHostConfig {
|
|
2
|
+
host: string;
|
|
3
|
+
user?: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
sshKey?: string;
|
|
6
|
+
bin?: string;
|
|
7
|
+
useSshConfig?: boolean;
|
|
8
|
+
sshOptions?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
export interface RawConfig {
|
|
2
12
|
autonomyDefault: string;
|
|
3
13
|
lang?: string;
|
|
4
14
|
version: string;
|
|
15
|
+
jumpHosts: Record<string, JumpHostConfig>;
|
|
5
16
|
}
|
|
6
17
|
|
|
7
18
|
export interface ArgSpec {
|
|
@@ -15,6 +26,7 @@ export interface ArgSpec {
|
|
|
15
26
|
multiple?: boolean;
|
|
16
27
|
delimiter?: string;
|
|
17
28
|
short?: string;
|
|
29
|
+
position?: number;
|
|
18
30
|
env?: string;
|
|
19
31
|
deprecated?: string;
|
|
20
32
|
autonomy?: string;
|
|
@@ -51,10 +63,12 @@ export interface RawSpec {
|
|
|
51
63
|
|
|
52
64
|
export interface ParsedArgs {
|
|
53
65
|
[key: string]: unknown;
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
56
|
-
readonly
|
|
57
|
-
readonly
|
|
58
|
-
readonly
|
|
59
|
-
readonly
|
|
66
|
+
readonly __runspec_agent__: boolean;
|
|
67
|
+
readonly __runspec_script__: string;
|
|
68
|
+
readonly __runspec_command_path__: string[];
|
|
69
|
+
readonly __runspec_autonomy__: string;
|
|
70
|
+
readonly __runspec_source__: string;
|
|
71
|
+
readonly __runspec_spec__: ScriptSpec;
|
|
72
|
+
readonly runspec_command: string | undefined;
|
|
73
|
+
readonly runspec_command_path: string[];
|
|
60
74
|
}
|
package/src/parser.ts
CHANGED
|
@@ -11,12 +11,13 @@ export interface ParseOptions {
|
|
|
11
11
|
scriptName?: string;
|
|
12
12
|
argv?: string[];
|
|
13
13
|
cwd?: string;
|
|
14
|
+
configPath?: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export function parse(opts: ParseOptions = {}): ParsedArgs {
|
|
17
|
-
const { scriptName, argv: argvOverride, cwd } = opts;
|
|
18
|
+
const { scriptName, argv: argvOverride, cwd, configPath: configPathOverride } = opts;
|
|
18
19
|
|
|
19
|
-
const { configPath } = findConfig(cwd);
|
|
20
|
+
const { configPath } = configPathOverride ? { configPath: configPathOverride } : findConfig(cwd);
|
|
20
21
|
const raw = loadRaw(configPath);
|
|
21
22
|
const config = raw.config;
|
|
22
23
|
|
|
@@ -33,17 +34,17 @@ export function parse(opts: ParseOptions = {}): ParsedArgs {
|
|
|
33
34
|
|
|
34
35
|
let argv = argvOverride ?? process.argv.slice(2);
|
|
35
36
|
let activeScript = rawScript;
|
|
36
|
-
let
|
|
37
|
+
let commandPath: string[] = [];
|
|
37
38
|
|
|
38
39
|
const commands = rawScript.commands ?? {};
|
|
39
40
|
if (Object.keys(commands).length > 0 && argv.length > 0 && argv[0] in commands) {
|
|
40
|
-
|
|
41
|
+
commandPath = [argv[0]];
|
|
41
42
|
activeScript = commands[argv[0]];
|
|
42
43
|
argv = argv.slice(1);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (argv.includes('--help') || argv.includes('-h')) {
|
|
46
|
-
printHelp(name, activeScript,
|
|
47
|
+
printHelp(name, activeScript, commandPath.length > 0 ? commandPath[commandPath.length - 1] : undefined);
|
|
47
48
|
process.exit(0);
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -66,12 +67,14 @@ export function parse(opts: ParseOptions = {}): ParsedArgs {
|
|
|
66
67
|
|
|
67
68
|
return {
|
|
68
69
|
...coercedValues,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
__runspec_agent__: agent,
|
|
71
|
+
__runspec_script__: name,
|
|
72
|
+
__runspec_command_path__: commandPath,
|
|
73
|
+
__runspec_autonomy__: autonomy,
|
|
74
|
+
__runspec_source__: configPath,
|
|
75
|
+
__runspec_spec__: activeScript,
|
|
76
|
+
get runspec_command() { return commandPath.length > 0 ? commandPath[commandPath.length - 1] : undefined; },
|
|
77
|
+
get runspec_command_path() { return commandPath; },
|
|
75
78
|
} as ParsedArgs;
|
|
76
79
|
}
|
|
77
80
|
|
|
@@ -95,15 +98,29 @@ function parseArgv(argv: string[], argSpecs: Record<string, ArgSpec>): Record<st
|
|
|
95
98
|
if (spec.short) shortMap[spec.short] = norm;
|
|
96
99
|
}
|
|
97
100
|
|
|
101
|
+
// Positional args sorted by position index; rest arg (type='rest') collects post-'--' tokens
|
|
102
|
+
const positionalArgs = Object.entries(argSpecs)
|
|
103
|
+
.filter(([, s]) => s.position !== undefined)
|
|
104
|
+
.sort(([, a], [, b]) => (a.position ?? 0) - (b.position ?? 0))
|
|
105
|
+
.map(([name]) => name.replace(/-/g, '_'));
|
|
106
|
+
const restArgNorm = Object.entries(argSpecs).find(([, s]) => s.type === 'rest')?.[0]?.replace(/-/g, '_');
|
|
107
|
+
|
|
98
108
|
const result: Record<string, unknown> = {};
|
|
99
109
|
for (const name of Object.keys(argSpecs)) {
|
|
100
110
|
result[name.replace(/-/g, '_')] = undefined;
|
|
101
111
|
}
|
|
102
112
|
|
|
113
|
+
let positionalIndex = 0;
|
|
103
114
|
let i = 0;
|
|
104
115
|
while (i < argv.length) {
|
|
105
116
|
const token = argv[i];
|
|
106
117
|
|
|
118
|
+
// '--' separator: remaining tokens go to the rest arg
|
|
119
|
+
if (token === '--') {
|
|
120
|
+
if (restArgNorm !== undefined) result[restArgNorm] = argv.slice(i + 1);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
if (token.startsWith('--') && token.includes('=')) {
|
|
108
125
|
const eqIdx = token.indexOf('=');
|
|
109
126
|
const key = token.slice(0, eqIdx);
|
|
@@ -140,6 +157,12 @@ function parseArgv(argv: string[], argSpecs: Record<string, ArgSpec>): Record<st
|
|
|
140
157
|
continue;
|
|
141
158
|
}
|
|
142
159
|
|
|
160
|
+
// Unrecognized non-flag token: assign to next positional arg
|
|
161
|
+
if (!token.startsWith('-') && positionalIndex < positionalArgs.length) {
|
|
162
|
+
result[positionalArgs[positionalIndex]] = token;
|
|
163
|
+
positionalIndex++;
|
|
164
|
+
}
|
|
165
|
+
|
|
143
166
|
i++;
|
|
144
167
|
}
|
|
145
168
|
|
package/src/runspec.toml
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#:schema https://raw.githubusercontent.com/JasonFinestone/runspec/main/schema/runspec.schema.json
|
|
2
|
+
|
|
3
|
+
# runspec itself is a developer CLI, not an agent tool. Suppress autonomy
|
|
4
|
+
# inference so --help doesn't display a meaningless autonomy level on the
|
|
5
|
+
# top-level menu or on `serve` (which is a server, not an action).
|
|
6
|
+
[config]
|
|
7
|
+
autonomy-default = ""
|
|
8
|
+
|
|
9
|
+
[runspec]
|
|
10
|
+
description = "Interface specification for anything runnable"
|
|
11
|
+
|
|
12
|
+
examples = [
|
|
13
|
+
{cmd = "runspec init", description = "Scaffold a new runnable in this directory"},
|
|
14
|
+
{cmd = "runspec local", description = "Discover and validate runnables"},
|
|
15
|
+
{cmd = "runspec serve", description = "Start the MCP stdio server"},
|
|
16
|
+
{cmd = "runspec jump --list-jump-hosts", description = "List configured jump hosts"},
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[runspec.commands.init]
|
|
20
|
+
description = "Scaffold a new runnable — creates runspec.toml and a code stub"
|
|
21
|
+
autonomy = "confirm"
|
|
22
|
+
|
|
23
|
+
examples = [
|
|
24
|
+
{cmd = "runspec init", description = "Scaffold using current directory name"},
|
|
25
|
+
{cmd = "runspec init --name deploy", description = "Scaffold a runnable called 'deploy'"},
|
|
26
|
+
{cmd = "runspec init --example", description = "Generate worked example (clean + scan)"},
|
|
27
|
+
{cmd = "runspec init --example --write-project", description = "Also generate pyproject.toml in parent dir"},
|
|
28
|
+
{cmd = "runspec init --write-project --project-dir /tmp/myproject", description = "Write project files to a specific path"},
|
|
29
|
+
{cmd = "runspec init --name myapp --lang typescript", description = "Use TypeScript code stub"},
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[runspec.commands.init.args]
|
|
33
|
+
name = {type = "str", description = "Runnable name (defaults to package directory name)", short = "-n", required = false}
|
|
34
|
+
lang = {type = "choice", description = "Language for the generated code stub", options = ["python", "typescript", "javascript"], default = "python"}
|
|
35
|
+
example = {type = "flag", description = "Generate a worked example (clean + scan runnables)", short = "-e", default = false}
|
|
36
|
+
write-project = {type = "flag", description = "Generate pyproject.toml, __init__.py, .gitignore, and CLAUDE.md", short = "-w", default = false}
|
|
37
|
+
project-dir = {type = "str", description = "Where to write project files (default: parent directory)", short = "-d", required = false}
|
|
38
|
+
force = {type = "flag", description = "Override the cwd safety check (don't refuse when pyproject.toml is present in cwd)", default = false}
|
|
39
|
+
|
|
40
|
+
[runspec.commands.local]
|
|
41
|
+
description = "List installed runnables or emit their tool schemas"
|
|
42
|
+
autonomy = "autonomous"
|
|
43
|
+
output = "json"
|
|
44
|
+
|
|
45
|
+
examples = [
|
|
46
|
+
{cmd = "runspec local", description = "Discover runnables and validate setup"},
|
|
47
|
+
{cmd = "runspec local --format mcp", description = "Emit MCP tool schemas"},
|
|
48
|
+
{cmd = "runspec local --format mcp --runnable deploy", description = "Emit schema for one runnable"},
|
|
49
|
+
{cmd = "runspec local --format json", description = "Full spec as JSON"},
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[runspec.commands.local.args]
|
|
53
|
+
format = {type = "choice", description = "Output format", options = ["text", "json", "mcp", "openai", "anthropic"], short = "-f", default = "text"}
|
|
54
|
+
runnable = {type = "str", description = "Filter output to a single runnable by name", short = "-r", required = false}
|
|
55
|
+
|
|
56
|
+
[runspec.commands.serve]
|
|
57
|
+
description = "Start an MCP stdio server exposing all installed runnables as tools"
|
|
58
|
+
|
|
59
|
+
examples = [
|
|
60
|
+
{cmd = "runspec serve", description = "Serve all runspec-aware runnables installed in this venv"},
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
# No args — runnables are discovered via importlib.metadata. Install with
|
|
64
|
+
# `pip install -e .` to make a package visible.
|
|
65
|
+
|
|
66
|
+
[runspec.commands.jump]
|
|
67
|
+
description = "List jump hosts, list tools on a jump host, or run a tool via SSH+MCP"
|
|
68
|
+
autonomy = "confirm"
|
|
69
|
+
|
|
70
|
+
examples = [
|
|
71
|
+
{cmd = "runspec jump --list-jump-hosts", description = "List configured jump hosts"},
|
|
72
|
+
{cmd = "runspec jump myserver", description = "List tools available on myserver"},
|
|
73
|
+
{cmd = "runspec jump myserver deploy -- --env prod", description = "Run 'deploy' on myserver with --env prod"},
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
[runspec.commands.jump.args]
|
|
77
|
+
list-jump-hosts = {type = "flag", description = "List configured jump hosts from runspec.toml", short = "-l", default = false}
|
|
78
|
+
format = {type = "choice", description = "Output format when listing", options = ["text", "json"], short = "-f", default = "text"}
|
|
79
|
+
jump-host = {type = "str", description = "Jump host alias from [config.jump-hosts]", position = 1, required = false}
|
|
80
|
+
tool = {type = "str", description = "Tool to run on the jump host", position = 2, required = false}
|
|
81
|
+
tool-args = {type = "rest", description = "Args passed to the remote tool"}
|
package/src/types.ts
CHANGED
|
@@ -107,11 +107,11 @@ test('--example creates clean.ts and scan.ts by default', () => {
|
|
|
107
107
|
expect(fs.existsSync(path.join(dir, 'scan.ts'))).toBe(true);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
test('--example clean stub uses
|
|
110
|
+
test('--example clean stub uses __runspec_agent__ check', () => {
|
|
111
111
|
const dir = tmpDir();
|
|
112
112
|
runInit(dir, ['--example']);
|
|
113
113
|
const ts = fs.readFileSync(path.join(dir, 'clean.ts'), 'utf-8');
|
|
114
|
-
expect(ts).toContain('
|
|
114
|
+
expect(ts).toContain('__runspec_agent__');
|
|
115
115
|
expect(ts).toContain('delete');
|
|
116
116
|
});
|
|
117
117
|
|
|
@@ -186,10 +186,10 @@ test('emit command is no longer available', () => {
|
|
|
186
186
|
expect(stdout).toContain('Unknown command');
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
-
test('jump command
|
|
189
|
+
test('jump command requires a host name', () => {
|
|
190
190
|
const dir = tmpDir();
|
|
191
|
-
const {
|
|
192
|
-
expect(
|
|
191
|
+
const { stderr } = runCLI(dir, ['jump']);
|
|
192
|
+
expect(stderr).toContain('jump host name is required');
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
// ── help ──────────────────────────────────────────────────────────────────────
|