@astralos/cli 0.1.4 → 0.1.6
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 +36 -0
- package/dist/astral.js +278 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,42 @@ Use `astral --help` or `astral <command> --help` for command details.
|
|
|
40
40
|
names and flags. For example, `code.list_repos` becomes `astral code list-repos`.
|
|
41
41
|
Group help includes catalog commands when you are signed in.
|
|
42
42
|
|
|
43
|
+
## Code
|
|
44
|
+
|
|
45
|
+
`astral code` works on Astral repos and on GitHub repos that the workspace's
|
|
46
|
+
GitHub App grant reaches. It finds the repo from the git remote of the current
|
|
47
|
+
folder, or from `-R owner/repo`.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
astral code setup-git # plain git uses Astral for github.com
|
|
51
|
+
git clone https://github.com/owner/repo
|
|
52
|
+
astral code pr create --fill # GitHub: runs gh with a 1-hour token
|
|
53
|
+
astral code pr list
|
|
54
|
+
astral code repo view owner/repo
|
|
55
|
+
astral code repo clone my-astral-repo
|
|
56
|
+
astral code repo view my-astral-repo
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For a GitHub repo, `astral code pr|repo|issue|run|search|api|release|workflow|label|browse`
|
|
60
|
+
runs the real `gh` with your arguments unchanged. The CLI gets a GitHub token for
|
|
61
|
+
that one repo, and only the `gh` process sees it (`GH_TOKEN`). The token ends
|
|
62
|
+
after 1 hour and is never printed or saved. Push access needs manage access to
|
|
63
|
+
the repo; read commands use a read-only token. A token never reaches more than
|
|
64
|
+
one repo: `astral code search` needs `--repo owner/repo`, and
|
|
65
|
+
`astral code list-repos` lists the workspace repos instead of `repo list`.
|
|
66
|
+
|
|
67
|
+
For an Astral repo, `repo clone` and `repo view` work. Astral repos have no pull
|
|
68
|
+
requests. Use `astral code clone`, then `astral code push` or plain `git push`
|
|
69
|
+
in the clone.
|
|
70
|
+
|
|
71
|
+
`astral code setup-git` makes git ask `astral code credential` for github.com.
|
|
72
|
+
Plain `git clone`, `fetch`, and `push` then use the same one-repo token.
|
|
73
|
+
|
|
74
|
+
Limit: the git credential protocol does not tell the helper if git fetches or
|
|
75
|
+
pushes. So for plain git, the helper always asks for the push password or
|
|
76
|
+
token first (one repo, short-lived). Without push access it gets a read one:
|
|
77
|
+
a clone or fetch works, and a push fails with a permission error.
|
|
78
|
+
|
|
43
79
|
## Agent instructions
|
|
44
80
|
|
|
45
81
|
`astral agent-setup` prints a marked AGENTS.md snippet. It needs no sign-in.
|
package/dist/astral.js
CHANGED
|
@@ -10246,6 +10246,14 @@ var EXIT_FOR_ERROR = {
|
|
|
10246
10246
|
};
|
|
10247
10247
|
var exitCodeFor = (type) => EXIT_FOR_ERROR[type] ?? EXIT.failure;
|
|
10248
10248
|
|
|
10249
|
+
class CommandExit extends Error {
|
|
10250
|
+
exitCode;
|
|
10251
|
+
constructor(exitCode) {
|
|
10252
|
+
super(`Command exited with ${exitCode}.`);
|
|
10253
|
+
this.exitCode = exitCode;
|
|
10254
|
+
}
|
|
10255
|
+
}
|
|
10256
|
+
|
|
10249
10257
|
class CliError extends Error {
|
|
10250
10258
|
error;
|
|
10251
10259
|
constructor(error) {
|
|
@@ -10267,7 +10275,7 @@ var ASTRAL_APPROVAL_HEADER = "Astral-Approval";
|
|
|
10267
10275
|
// package.json
|
|
10268
10276
|
var package_default = {
|
|
10269
10277
|
name: "@astralos/cli",
|
|
10270
|
-
version: "0.1.
|
|
10278
|
+
version: "0.1.6",
|
|
10271
10279
|
license: "MIT",
|
|
10272
10280
|
description: "The Astral command line. Every Astral tool, from a terminal or an agent.",
|
|
10273
10281
|
publishConfig: {
|
|
@@ -10885,6 +10893,22 @@ var parseCredentialRequest = (text) => {
|
|
|
10885
10893
|
return fields;
|
|
10886
10894
|
};
|
|
10887
10895
|
|
|
10896
|
+
// src/github.ts
|
|
10897
|
+
var CREDENTIAL_TOOLS = new Set(["code.github_read_token", "code.github_write_token"]);
|
|
10898
|
+
var githubRepo = (value) => {
|
|
10899
|
+
const match = value.match(/^(?:https?:\/\/github\.com\/|ssh:\/\/(?:git@)?github\.com\/|git@github\.com:)?([^/\s:]+)\/([^/\s?#]+)\/?$/i);
|
|
10900
|
+
return match ? `${match[1]}/${match[2].replace(/\.git$/i, "")}` : null;
|
|
10901
|
+
};
|
|
10902
|
+
var githubCredentials = async (params) => {
|
|
10903
|
+
const { client, read, repo } = params;
|
|
10904
|
+
const { credentials } = await client.call({
|
|
10905
|
+
method: "POST",
|
|
10906
|
+
path: `/api/v1/tools/code.github_${read ? "read" : "write"}_token`,
|
|
10907
|
+
json: { repo }
|
|
10908
|
+
});
|
|
10909
|
+
return credentials;
|
|
10910
|
+
};
|
|
10911
|
+
|
|
10888
10912
|
// src/commands/code-git.ts
|
|
10889
10913
|
var depsOf = (runtime) => ({
|
|
10890
10914
|
git: runtime.git ?? runGit,
|
|
@@ -10902,6 +10926,15 @@ var URL_ENV = "ASTRAL_GIT_URL";
|
|
|
10902
10926
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10903
10927
|
var toolPath = (name) => `/api/v1/tools/${encodeURIComponent(name)}`;
|
|
10904
10928
|
var readCredentials = async (client, id) => (await client.call({ method: "POST", path: toolPath("code.git_read_credentials"), json: { id } })).credentials;
|
|
10929
|
+
var helperRepoCredentials = async (client, id) => {
|
|
10930
|
+
try {
|
|
10931
|
+
return (await client.call({ method: "POST", path: toolPath("code.git_write_credentials"), json: { id } })).credentials;
|
|
10932
|
+
} catch (error) {
|
|
10933
|
+
if (!(error instanceof CliError) || error.error.type !== "permission_denied")
|
|
10934
|
+
throw error;
|
|
10935
|
+
return readCredentials(client, id);
|
|
10936
|
+
}
|
|
10937
|
+
};
|
|
10905
10938
|
var resolveRepo = async (client, ref) => {
|
|
10906
10939
|
if (UUID.test(ref))
|
|
10907
10940
|
return { id: ref, name: ref, kind: "astral" };
|
|
@@ -10947,29 +10980,33 @@ var credentialEnv = (credentials) => ({
|
|
|
10947
10980
|
[URL_ENV]: credentials.url,
|
|
10948
10981
|
GIT_TERMINAL_PROMPT: "0"
|
|
10949
10982
|
});
|
|
10983
|
+
var cloneRepo = async (params) => {
|
|
10984
|
+
const { runtime, globals, ref, dir } = params;
|
|
10985
|
+
const deps = depsOf(runtime);
|
|
10986
|
+
const client = clientFor(runtime, globals);
|
|
10987
|
+
const repo = await resolveRepo(client, ref);
|
|
10988
|
+
const credentials = await readCredentials(client, repo.id);
|
|
10989
|
+
const target = dir ?? (repo.name === repo.id ? repo.id : repo.name);
|
|
10990
|
+
const config = cloneConfig({ url: credentials.url, repoId: repo.id, profile: client.context.profile, self: deps.self() });
|
|
10991
|
+
const result = await deps.git({
|
|
10992
|
+
args: ["clone", ...config, credentials.url, target],
|
|
10993
|
+
env: { ...runtime.env, ...credentialEnv(credentials) },
|
|
10994
|
+
stdio: "inherit"
|
|
10995
|
+
});
|
|
10996
|
+
if (result.status !== 0)
|
|
10997
|
+
throw cliError("upstream_error", `git clone exited with ${result.status}.`, { git_exit: result.status });
|
|
10998
|
+
emit({
|
|
10999
|
+
runtime,
|
|
11000
|
+
globals,
|
|
11001
|
+
data: { repo_id: repo.id, dir: target, url: credentials.url, default_branch: credentials.default_branch },
|
|
11002
|
+
human: (data) => `Cloned ${repo.name} into ${data.dir}. \`astral code push\` pushes to it.`
|
|
11003
|
+
});
|
|
11004
|
+
};
|
|
10950
11005
|
var registerCodeGit = (program, runtime) => {
|
|
10951
11006
|
const deps = depsOf(runtime);
|
|
10952
11007
|
const code = program.commands.find((command) => command.name() === "code") ?? program.command("code").description("Astral repos: clone, push, and the code tools");
|
|
10953
11008
|
code.command("clone <repo> [dir]").description("clone an Astral repo (id or name) and set up git credentials for it").action(async (ref, dir, _options, command) => {
|
|
10954
|
-
|
|
10955
|
-
const client = clientFor(runtime, globals);
|
|
10956
|
-
const repo = await resolveRepo(client, ref);
|
|
10957
|
-
const credentials = await readCredentials(client, repo.id);
|
|
10958
|
-
const target = dir ?? (repo.name === repo.id ? repo.id : repo.name);
|
|
10959
|
-
const config = cloneConfig({ url: credentials.url, repoId: repo.id, profile: client.context.profile, self: deps.self() });
|
|
10960
|
-
const result = await deps.git({
|
|
10961
|
-
args: ["clone", ...config, credentials.url, target],
|
|
10962
|
-
env: { ...runtime.env, ...credentialEnv(credentials) },
|
|
10963
|
-
stdio: "inherit"
|
|
10964
|
-
});
|
|
10965
|
-
if (result.status !== 0)
|
|
10966
|
-
throw cliError("upstream_error", `git clone exited with ${result.status}.`, { git_exit: result.status });
|
|
10967
|
-
emit({
|
|
10968
|
-
runtime,
|
|
10969
|
-
globals,
|
|
10970
|
-
data: { repo_id: repo.id, dir: target, url: credentials.url, default_branch: credentials.default_branch },
|
|
10971
|
-
human: (data) => `Cloned ${repo.name} into ${data.dir}. \`astral code push\` pushes to it.`
|
|
10972
|
-
});
|
|
11009
|
+
await cloneRepo({ runtime, globals: globalsOf(command), ref, dir });
|
|
10973
11010
|
});
|
|
10974
11011
|
code.command("push [git-args...]").description("push to the Astral repo of this clone; args go to git push").allowUnknownOption().option("--repo <id>", "the repo id (default: git config astral.repoId)").option("--no-wait", "if a call needs approval, exit 10 with the link instead of waiting").action(async (args, options, command) => {
|
|
10975
11012
|
const globals = globalsOf(command);
|
|
@@ -10994,11 +11031,52 @@ var registerCodeGit = (program, runtime) => {
|
|
|
10994
11031
|
throw cliError("upstream_error", `git push exited with ${result.status}.`, { git_exit: result.status });
|
|
10995
11032
|
emit({ runtime, globals, data: { repo_id: repoId, pushed: true }, human: () => "Pushed." });
|
|
10996
11033
|
});
|
|
11034
|
+
code.command("setup-git").description("set up the GitHub credential helper for plain git").action(async (_options, command) => {
|
|
11035
|
+
const globals = globalsOf(command);
|
|
11036
|
+
const profile = globals.profile ? ["--profile", globals.profile] : [];
|
|
11037
|
+
const helper = `!${[...deps.self(), ...profile, "code", "credential"].map(shellQuote).join(" ")}`;
|
|
11038
|
+
const key = "credential.https://github.com.helper";
|
|
11039
|
+
for (const args of [
|
|
11040
|
+
["config", "--global", "--replace-all", key, ""],
|
|
11041
|
+
["config", "--global", "--add", key, helper],
|
|
11042
|
+
["config", "--global", "--replace-all", "credential.https://github.com.useHttpPath", "true"]
|
|
11043
|
+
]) {
|
|
11044
|
+
const result = await deps.git({ args, stdio: "pipe" });
|
|
11045
|
+
if (result.status !== 0)
|
|
11046
|
+
throw cliError("upstream_error", `git config exited with ${result.status}.`);
|
|
11047
|
+
}
|
|
11048
|
+
emit({ runtime, globals, data: { helper, useHttpPath: true }, human: () => `Set ${key} to an empty helper, then ${helper}.
|
|
11049
|
+
Set credential.https://github.com.useHttpPath=true.` });
|
|
11050
|
+
});
|
|
10997
11051
|
code.command("credential <operation>").description("git credential helper (git runs it; you do not)").option("--repo <id>", "the repo id").action(async (operation, options, command) => {
|
|
10998
11052
|
if (operation !== "get")
|
|
10999
11053
|
return;
|
|
11000
11054
|
const request = parseCredentialRequest(await deps.readStdin());
|
|
11001
11055
|
const globals = globalsOf(command);
|
|
11056
|
+
if (!options.repo && !Object.entries(runtime.env).some(([key, value]) => key.startsWith("ASTRAL_GIT_") && value !== undefined)) {
|
|
11057
|
+
if (request.protocol !== "https" || request.host?.toLowerCase() !== "github.com" || !request.path)
|
|
11058
|
+
return;
|
|
11059
|
+
const repo = githubRepo(request.path);
|
|
11060
|
+
if (!repo)
|
|
11061
|
+
return;
|
|
11062
|
+
const client = clientFor(runtime, globals);
|
|
11063
|
+
let credentials;
|
|
11064
|
+
try {
|
|
11065
|
+
credentials = await githubCredentials({ client, read: false, repo });
|
|
11066
|
+
} catch (error) {
|
|
11067
|
+
if (!(error instanceof CliError) || error.error.type !== "permission_denied")
|
|
11068
|
+
throw error;
|
|
11069
|
+
credentials = await githubCredentials({ client, read: true, repo });
|
|
11070
|
+
}
|
|
11071
|
+
const lines = ["username=x-access-token", `password=${credentials.token}`];
|
|
11072
|
+
const expiry = Date.parse(credentials.expires_at);
|
|
11073
|
+
if (Number.isFinite(expiry))
|
|
11074
|
+
lines.push(`password_expiry_utc=${Math.floor(expiry / 1000)}`);
|
|
11075
|
+
runtime.stdout(`${lines.join(`
|
|
11076
|
+
`)}
|
|
11077
|
+
`);
|
|
11078
|
+
return;
|
|
11079
|
+
}
|
|
11002
11080
|
const credentials = await helperCredentials(runtime, globals, options.repo);
|
|
11003
11081
|
if (!credentials || !matchesRemote(request, credentials.url))
|
|
11004
11082
|
return;
|
|
@@ -11020,7 +11098,174 @@ var helperCredentials = async (runtime, globals, repoId) => {
|
|
|
11020
11098
|
}
|
|
11021
11099
|
if (!repoId)
|
|
11022
11100
|
return null;
|
|
11023
|
-
return
|
|
11101
|
+
return helperRepoCredentials(clientFor(runtime, globals), repoId);
|
|
11102
|
+
};
|
|
11103
|
+
|
|
11104
|
+
// src/gh.ts
|
|
11105
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
11106
|
+
var runGh = ({ args, env, stdio }) => new Promise((resolve, reject) => {
|
|
11107
|
+
const child = spawn2("gh", args, { env: { ...process.env, ...env }, stdio });
|
|
11108
|
+
child.on("error", (error) => {
|
|
11109
|
+
reject(cliError("upstream_error", error.code === "ENOENT" ? "The gh binary is missing. Install GitHub CLI to use this command." : "Could not start gh."));
|
|
11110
|
+
});
|
|
11111
|
+
child.on("close", (code) => resolve(code ?? 1));
|
|
11112
|
+
});
|
|
11113
|
+
|
|
11114
|
+
// src/commands/code-gh.ts
|
|
11115
|
+
var GH_COMMANDS = ["pr", "repo", "issue", "run", "search", "api", "release", "workflow", "label", "browse"];
|
|
11116
|
+
var flagValues = (args, names) => {
|
|
11117
|
+
const values = [];
|
|
11118
|
+
for (let index = 0;index < args.length; index++) {
|
|
11119
|
+
const arg = args[index];
|
|
11120
|
+
if (arg === "--")
|
|
11121
|
+
break;
|
|
11122
|
+
for (const name of names) {
|
|
11123
|
+
if (arg === name && args[index + 1])
|
|
11124
|
+
values.push(args[index + 1]);
|
|
11125
|
+
else if (name.startsWith("--") && arg.startsWith(`${name}=`))
|
|
11126
|
+
values.push(arg.slice(name.length + 1));
|
|
11127
|
+
else if (!name.startsWith("--") && arg.startsWith(name) && arg.length > name.length)
|
|
11128
|
+
values.push(arg.slice(name.length));
|
|
11129
|
+
}
|
|
11130
|
+
}
|
|
11131
|
+
return values;
|
|
11132
|
+
};
|
|
11133
|
+
var flag = (args, names) => flagValues(args, names)[0];
|
|
11134
|
+
var repoPositionals = (args) => {
|
|
11135
|
+
const values = [];
|
|
11136
|
+
const options = ["-R", "--repo", "--owner", "--json", "--jq", "-q", "--template", "-t", "--limit", "-L"];
|
|
11137
|
+
for (let index = 2;index < args.length; index++) {
|
|
11138
|
+
const arg = args[index];
|
|
11139
|
+
if (arg === "--")
|
|
11140
|
+
break;
|
|
11141
|
+
if (options.includes(arg))
|
|
11142
|
+
index++;
|
|
11143
|
+
else if (!arg.startsWith("-"))
|
|
11144
|
+
values.push(arg);
|
|
11145
|
+
}
|
|
11146
|
+
return values;
|
|
11147
|
+
};
|
|
11148
|
+
var urlRepo = (args) => {
|
|
11149
|
+
const endpoint = args[0] === "api" ? args[1]?.match(/^\/?repos\/([^/{}]+)\/([^/?#{}]+)/) : null;
|
|
11150
|
+
if (endpoint)
|
|
11151
|
+
return `${endpoint[1]}/${endpoint[2]}`;
|
|
11152
|
+
for (const arg of repoPositionals(args)) {
|
|
11153
|
+
const match = arg.match(/^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/?#]+)/i);
|
|
11154
|
+
if (match)
|
|
11155
|
+
return `${match[1]}/${match[2].replace(/\.git$/i, "")}`;
|
|
11156
|
+
}
|
|
11157
|
+
return null;
|
|
11158
|
+
};
|
|
11159
|
+
var detectRepo = async (params) => {
|
|
11160
|
+
const { args, runtime } = params;
|
|
11161
|
+
const explicit = flag(args, ["-R", "--repo"]);
|
|
11162
|
+
if (explicit)
|
|
11163
|
+
return explicit;
|
|
11164
|
+
if (args[0] === "repo" && ["view", "clone"].includes(args[1] ?? "")) {
|
|
11165
|
+
const positional = repoPositionals(args)[0];
|
|
11166
|
+
if (positional)
|
|
11167
|
+
return positional;
|
|
11168
|
+
}
|
|
11169
|
+
const url = urlRepo(args);
|
|
11170
|
+
if (url)
|
|
11171
|
+
return url;
|
|
11172
|
+
const envRepo = runtime.env.GH_REPO?.trim().replace(/^github\.com\//i, "");
|
|
11173
|
+
if (envRepo)
|
|
11174
|
+
return envRepo;
|
|
11175
|
+
const git = runtime.git ?? runGit;
|
|
11176
|
+
const config = await git({ args: ["config", "--get", "astral.repoId"], stdio: "pipe" });
|
|
11177
|
+
if (config.status === 0 && config.stdout.trim())
|
|
11178
|
+
return config.stdout.trim();
|
|
11179
|
+
let remote = await git({ args: ["remote", "get-url", "origin"], stdio: "pipe" });
|
|
11180
|
+
if (remote.status !== 0 || !remote.stdout.trim()) {
|
|
11181
|
+
const remotes = await git({ args: ["remote"], stdio: "pipe" });
|
|
11182
|
+
const first = remotes.stdout.trim().split(`
|
|
11183
|
+
`)[0];
|
|
11184
|
+
if (remotes.status !== 0 || !first)
|
|
11185
|
+
return null;
|
|
11186
|
+
remote = await git({ args: ["remote", "get-url", first], stdio: "pipe" });
|
|
11187
|
+
}
|
|
11188
|
+
if (remote.status !== 0 || !/^(?:https?:\/\/github\.com\/|ssh:\/\/(?:git@)?github\.com\/|git@github\.com:)/i.test(remote.stdout.trim()))
|
|
11189
|
+
return null;
|
|
11190
|
+
return githubRepo(remote.stdout.trim());
|
|
11191
|
+
};
|
|
11192
|
+
var isReadCommand = (args) => {
|
|
11193
|
+
const [command, action] = args;
|
|
11194
|
+
if (command === "browse" || command === "search")
|
|
11195
|
+
return true;
|
|
11196
|
+
if (command === "api") {
|
|
11197
|
+
if (flagValues(args, ["-X", "--method"]).some((method) => method.toUpperCase() !== "GET"))
|
|
11198
|
+
return false;
|
|
11199
|
+
return !args.some((arg) => /^(?:-[fF].*|--(?:field|raw-field|input)(?:=|$))/.test(arg));
|
|
11200
|
+
}
|
|
11201
|
+
const reads = {
|
|
11202
|
+
pr: ["list", "view", "diff", "checks", "status"],
|
|
11203
|
+
issue: ["list", "view", "status"],
|
|
11204
|
+
repo: ["view", "clone", "list"],
|
|
11205
|
+
run: ["list", "view", "watch", "download"],
|
|
11206
|
+
release: ["list", "view", "download"],
|
|
11207
|
+
workflow: ["list", "view"],
|
|
11208
|
+
label: ["list"]
|
|
11209
|
+
};
|
|
11210
|
+
return reads[command ?? ""]?.includes(action ?? "") ?? false;
|
|
11211
|
+
};
|
|
11212
|
+
var astralCommand = async (params) => {
|
|
11213
|
+
const { args, ref, runtime, command } = params;
|
|
11214
|
+
const globals = globalsOf(command);
|
|
11215
|
+
if (args[0] === "repo" && args[1] === "clone") {
|
|
11216
|
+
const positionals = repoPositionals(args);
|
|
11217
|
+
const dir = positionals[flag(args, ["-R", "--repo"]) ? 0 : 1];
|
|
11218
|
+
await cloneRepo({ runtime, globals: { ...globals, json: globals.json || args.includes("--json") }, ref, dir });
|
|
11219
|
+
return;
|
|
11220
|
+
}
|
|
11221
|
+
if (args[0] === "repo" && args[1] === "view") {
|
|
11222
|
+
const client = clientFor(runtime, globals);
|
|
11223
|
+
const repo = await resolveRepo(client, ref);
|
|
11224
|
+
const data = await client.call({ method: "POST", path: "/api/v1/tools/code.get_repo", json: { id: repo.id } });
|
|
11225
|
+
emit({
|
|
11226
|
+
runtime,
|
|
11227
|
+
globals: { ...globals, json: globals.json || args.includes("--json") },
|
|
11228
|
+
data,
|
|
11229
|
+
human: ({ repo: detail }) => [
|
|
11230
|
+
`Name: ${detail.name}`,
|
|
11231
|
+
`Kind: ${detail.kind}`,
|
|
11232
|
+
`Default branch: ${detail.default_branch}`,
|
|
11233
|
+
`Description: ${detail.description ?? "-"}`,
|
|
11234
|
+
`URL: ${detail.html_url ?? "-"}`
|
|
11235
|
+
].join(`
|
|
11236
|
+
`)
|
|
11237
|
+
});
|
|
11238
|
+
return;
|
|
11239
|
+
}
|
|
11240
|
+
throw cliError("invalid_input", "Astral repos do not support this command. Supported commands: astral code repo clone, astral code repo view, astral code clone, astral code push, and plain git with the credential helper. Astral repos have no pull requests.");
|
|
11241
|
+
};
|
|
11242
|
+
var registerCodeGh = (program, runtime) => {
|
|
11243
|
+
const code = program.commands.find((command) => command.name() === "code");
|
|
11244
|
+
code.enablePositionalOptions();
|
|
11245
|
+
for (const name of GH_COMMANDS) {
|
|
11246
|
+
code.command(`${name} [args...]`).description(`${name} for GitHub repos (args go to gh)`).allowUnknownOption().passThroughOptions().helpOption(false).action(async (_args, _options, command) => {
|
|
11247
|
+
const args = [...code.args];
|
|
11248
|
+
const globals = globalsOf(command);
|
|
11249
|
+
if (name === "repo" && args[1] === "list") {
|
|
11250
|
+
throw cliError("invalid_input", "A GitHub token here reaches one repo. List the workspace repos with astral code list-repos.");
|
|
11251
|
+
}
|
|
11252
|
+
if (name === "search" && !flag(args, ["-R", "--repo"])) {
|
|
11253
|
+
throw cliError("invalid_input", "A GitHub token here reaches one repo. Name it with --repo owner/repo.");
|
|
11254
|
+
}
|
|
11255
|
+
const ref = await detectRepo({ args, runtime });
|
|
11256
|
+
if (!ref)
|
|
11257
|
+
throw cliError("invalid_input", "Run this in a clone, or name the repo with -R owner/repo.");
|
|
11258
|
+
const repo = githubRepo(ref);
|
|
11259
|
+
if (ref.includes("/") && !repo)
|
|
11260
|
+
throw cliError("invalid_input", "Use a GitHub repo in the form owner/repo or a github.com URL.");
|
|
11261
|
+
if (!repo)
|
|
11262
|
+
return astralCommand({ args, ref, runtime, command });
|
|
11263
|
+
const credentials = await githubCredentials({ client: clientFor(runtime, globals), read: isReadCommand(args), repo });
|
|
11264
|
+
const status = await (runtime.gh ?? runGh)({ args, env: { ...process.env, ...runtime.env, GH_REPO: repo, GH_TOKEN: credentials.token }, stdio: "inherit" });
|
|
11265
|
+
if (status !== 0)
|
|
11266
|
+
throw new CommandExit(status);
|
|
11267
|
+
});
|
|
11268
|
+
}
|
|
11024
11269
|
};
|
|
11025
11270
|
|
|
11026
11271
|
// src/catalog.ts
|
|
@@ -11133,6 +11378,8 @@ var registerCall = (parent, runtime) => {
|
|
|
11133
11378
|
parent.command("call <app.tool>").description("call a tool with JSON input").option("--input <json>", "input as a JSON object").option("--input-file <path>", "read JSON from a file, or - for stdin").action(async (name, options, command) => {
|
|
11134
11379
|
if (!/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/.test(name))
|
|
11135
11380
|
throw cliError("invalid_input", "Use a tool name in app.tool form.");
|
|
11381
|
+
if (CREDENTIAL_TOOLS.has(name))
|
|
11382
|
+
throw cliError("invalid_input", `${name} returns a raw token, so it cannot be called here. Use astral code gh commands or plain git with the credential helper.`);
|
|
11136
11383
|
const globals = globalsOf(command);
|
|
11137
11384
|
const data = await callWithApproval({
|
|
11138
11385
|
client: clientFor(runtime, globals),
|
|
@@ -11236,6 +11483,8 @@ var registerTool = (command, tool, runtime) => {
|
|
|
11236
11483
|
var findCommand = (program, name) => program.commands.find((command) => command.name() === name || command.aliases().includes(name));
|
|
11237
11484
|
var addGeneratedCommands = (program, runtime, catalog) => {
|
|
11238
11485
|
for (const tool of catalog.tools) {
|
|
11486
|
+
if (CREDENTIAL_TOOLS.has(tool.name))
|
|
11487
|
+
continue;
|
|
11239
11488
|
let app = findCommand(program, tool.app);
|
|
11240
11489
|
if (app && app.commands.length === 0)
|
|
11241
11490
|
continue;
|
|
@@ -19580,6 +19829,8 @@ class StdioServerTransport {
|
|
|
19580
19829
|
var mcpToolMap = (tools) => {
|
|
19581
19830
|
const mapped = new Map;
|
|
19582
19831
|
for (const tool of tools) {
|
|
19832
|
+
if (CREDENTIAL_TOOLS.has(tool.name))
|
|
19833
|
+
continue;
|
|
19583
19834
|
const base = `${tool.app}__${tool.tool}`;
|
|
19584
19835
|
let name = base;
|
|
19585
19836
|
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(name) || mapped.has(name)) {
|
|
@@ -19952,6 +20203,7 @@ var buildProgram = async (runtime) => {
|
|
|
19952
20203
|
registerMcp(program, runtime);
|
|
19953
20204
|
registerWorkspace(program, runtime);
|
|
19954
20205
|
registerCodeGit(program, runtime);
|
|
20206
|
+
registerCodeGh(program, runtime);
|
|
19955
20207
|
registerTools(program, runtime);
|
|
19956
20208
|
registerProject(program, runtime);
|
|
19957
20209
|
registerSitesLogs(program, runtime);
|
|
@@ -19962,6 +20214,9 @@ var run = async (argv, runtime) => {
|
|
|
19962
20214
|
let errorRuntime = runtime;
|
|
19963
20215
|
try {
|
|
19964
20216
|
const program = await buildProgram(runtime);
|
|
20217
|
+
program.enablePositionalOptions();
|
|
20218
|
+
const { operands, unknown } = program.parseOptions(argv);
|
|
20219
|
+
program.enablePositionalOptions(operands[0] === "code" && GH_COMMANDS.includes(unknown[0] ?? ""));
|
|
19965
20220
|
program.hook("preAction", (_command, action) => {
|
|
19966
20221
|
if (action.name() === "mcp")
|
|
19967
20222
|
errorRuntime = { ...runtime, stdout: runtime.stderr };
|
|
@@ -19970,6 +20225,8 @@ var run = async (argv, runtime) => {
|
|
|
19970
20225
|
await program.parseAsync(argv, { from: "user" });
|
|
19971
20226
|
return EXIT.ok;
|
|
19972
20227
|
} catch (error) {
|
|
20228
|
+
if (error instanceof CommandExit)
|
|
20229
|
+
return error.exitCode;
|
|
19973
20230
|
if (error instanceof CommanderError) {
|
|
19974
20231
|
return error.exitCode === 0 ? EXIT.ok : EXIT.invalid_input;
|
|
19975
20232
|
}
|