gh-axi 0.1.5 → 0.1.8
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 +8 -1
- package/dist/src/cli.js +27 -40
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/home.d.ts +0 -6
- package/dist/src/commands/home.js +0 -23
- package/dist/src/commands/home.js.map +1 -1
- package/dist/src/errors.d.ts +1 -1
- package/dist/src/errors.js +25 -20
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks.js +93 -47
- package/dist/src/hooks.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<a href="https://www.npmjs.com/package/gh-axi"><img alt="npm" src="https://img.shields.io/npm/v/gh-axi?style=flat-square" /></a>
|
|
5
|
+
<a href="https://github.com/kunchenguid/gh-axi/actions/workflows/ci.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/kunchenguid/gh-axi/ci.yml?style=flat-square&label=ci" /></a>
|
|
6
|
+
<a href="https://github.com/kunchenguid/gh-axi/actions/workflows/release-please.yml"><img alt="Release" src="https://img.shields.io/github/actions/workflow/status/kunchenguid/gh-axi/release-please.yml?style=flat-square&label=release" /></a>
|
|
7
|
+
<a href="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-blue?style=flat-square"><img alt="Platform" src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-blue?style=flat-square" /></a>
|
|
5
8
|
<a href="https://x.com/kunchenguid"><img alt="X" src="https://img.shields.io/badge/X-@kunchenguid-black?style=flat-square" /></a>
|
|
6
|
-
<a href="https://discord.gg/
|
|
9
|
+
<a href="https://discord.gg/Wsy2NpnZDu"><img alt="Discord" src="https://img.shields.io/discord/1439901831038763092?style=flat-square&label=discord" /></a>
|
|
7
10
|
</p>
|
|
8
11
|
|
|
9
12
|
GitHub CLI for agents — designed with [AXI](https://github.com/kunchenguid/axi) (Agent eXperience Interface).
|
|
@@ -19,6 +22,10 @@ npm install -g gh-axi
|
|
|
19
22
|
|
|
20
23
|
Requires Node 20+ and [`gh`](https://cli.github.com/) authenticated via `gh auth login`.
|
|
21
24
|
|
|
25
|
+
Running `gh-axi` also installs or repairs Claude Code and Codex `SessionStart`
|
|
26
|
+
hooks. Those hooks now invoke `gh-axi` directly; legacy `--session-start`
|
|
27
|
+
invocations are still accepted as a no-op for backward compatibility.
|
|
28
|
+
|
|
22
29
|
## Usage
|
|
23
30
|
|
|
24
31
|
```bash
|
package/dist/src/cli.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { resolveRepo } from
|
|
2
|
-
import { AxiError, exitCodeForError } from
|
|
3
|
-
import { renderError } from
|
|
4
|
-
import { ensureHooks } from
|
|
5
|
-
import { homeCommand
|
|
6
|
-
import { issueCommand, ISSUE_HELP } from
|
|
7
|
-
import { prCommand, PR_HELP } from
|
|
8
|
-
import { runCommand, RUN_HELP } from
|
|
9
|
-
import { workflowCommand, WORKFLOW_HELP } from
|
|
10
|
-
import { releaseCommand, RELEASE_HELP } from
|
|
11
|
-
import { repoCommand, REPO_HELP } from
|
|
12
|
-
import { labelCommand, LABEL_HELP } from
|
|
13
|
-
import { searchCommand, SEARCH_HELP } from
|
|
14
|
-
import { apiCommand, API_HELP } from
|
|
1
|
+
import { resolveRepo } from "./context.js";
|
|
2
|
+
import { AxiError, exitCodeForError } from "./errors.js";
|
|
3
|
+
import { renderError } from "./toon.js";
|
|
4
|
+
import { ensureHooks } from "./hooks.js";
|
|
5
|
+
import { homeCommand } from "./commands/home.js";
|
|
6
|
+
import { issueCommand, ISSUE_HELP } from "./commands/issue.js";
|
|
7
|
+
import { prCommand, PR_HELP } from "./commands/pr.js";
|
|
8
|
+
import { runCommand, RUN_HELP } from "./commands/run.js";
|
|
9
|
+
import { workflowCommand, WORKFLOW_HELP } from "./commands/workflow.js";
|
|
10
|
+
import { releaseCommand, RELEASE_HELP } from "./commands/release.js";
|
|
11
|
+
import { repoCommand, REPO_HELP } from "./commands/repo.js";
|
|
12
|
+
import { labelCommand, LABEL_HELP } from "./commands/label.js";
|
|
13
|
+
import { searchCommand, SEARCH_HELP } from "./commands/search.js";
|
|
14
|
+
import { apiCommand, API_HELP } from "./commands/api.js";
|
|
15
15
|
export const TOP_HELP = `usage: gh-axi [command] [flags]
|
|
16
16
|
commands[10]:
|
|
17
17
|
(none)=dashboard, issue, pr, run, workflow, release, repo, label, search, api
|
|
@@ -52,21 +52,19 @@ export async function main(argv) {
|
|
|
52
52
|
let repoFlag;
|
|
53
53
|
// Extract --repo / -R
|
|
54
54
|
for (let i = 0; i < args.length; i++) {
|
|
55
|
-
if ((args[i] ===
|
|
55
|
+
if ((args[i] === "--repo" || args[i] === "-R") && i + 1 < args.length) {
|
|
56
56
|
repoFlag = args[i + 1];
|
|
57
57
|
args.splice(i, 2);
|
|
58
58
|
i--;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
const sessionIdx = args.indexOf('--session-start');
|
|
61
|
+
// Strip deprecated --session-start (kept as backward-compatible no-op)
|
|
62
|
+
const sessionIdx = args.indexOf("--session-start");
|
|
64
63
|
if (sessionIdx !== -1) {
|
|
65
|
-
sessionStart = true;
|
|
66
64
|
args.splice(sessionIdx, 1);
|
|
67
65
|
}
|
|
68
66
|
// Top-level --help
|
|
69
|
-
if (args.includes(
|
|
67
|
+
if (args.includes("--help") && args.length === 1) {
|
|
70
68
|
process.stdout.write(TOP_HELP);
|
|
71
69
|
return;
|
|
72
70
|
}
|
|
@@ -74,25 +72,14 @@ export async function main(argv) {
|
|
|
74
72
|
const command = args[0];
|
|
75
73
|
if (!command) {
|
|
76
74
|
// No command = home dashboard
|
|
77
|
-
if (args.includes(
|
|
75
|
+
if (args.includes("--help")) {
|
|
78
76
|
process.stdout.write(TOP_HELP);
|
|
79
77
|
return;
|
|
80
78
|
}
|
|
81
|
-
if (sessionStart) {
|
|
82
|
-
const ctx = resolveRepo(repoFlag);
|
|
83
|
-
try {
|
|
84
|
-
const output = await sessionStartCommand(ctx);
|
|
85
|
-
process.stdout.write(output + '\n');
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
writeError(err);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
79
|
const ctx = resolveRepo(repoFlag);
|
|
93
80
|
try {
|
|
94
81
|
const output = await homeCommand(args.slice(1), ctx);
|
|
95
|
-
process.stdout.write(output +
|
|
82
|
+
process.stdout.write(output + "\n");
|
|
96
83
|
}
|
|
97
84
|
catch (err) {
|
|
98
85
|
writeError(err);
|
|
@@ -100,7 +87,7 @@ export async function main(argv) {
|
|
|
100
87
|
return;
|
|
101
88
|
}
|
|
102
89
|
// Command-level --help
|
|
103
|
-
if (args.includes(
|
|
90
|
+
if (args.includes("--help")) {
|
|
104
91
|
const help = COMMAND_HELP[command];
|
|
105
92
|
if (help) {
|
|
106
93
|
process.stdout.write(help);
|
|
@@ -109,16 +96,16 @@ export async function main(argv) {
|
|
|
109
96
|
}
|
|
110
97
|
const handler = COMMANDS[command];
|
|
111
98
|
if (!handler) {
|
|
112
|
-
process.stdout.write(renderError(`Unknown command: ${command}`,
|
|
113
|
-
|
|
114
|
-
]) +
|
|
99
|
+
process.stdout.write(renderError(`Unknown command: ${command}`, "VALIDATION_ERROR", [
|
|
100
|
+
"Run `gh-axi --help` to see available commands",
|
|
101
|
+
]) + "\n");
|
|
115
102
|
process.exitCode = 2;
|
|
116
103
|
return;
|
|
117
104
|
}
|
|
118
105
|
const ctx = resolveRepo(repoFlag);
|
|
119
106
|
try {
|
|
120
107
|
const output = await handler(args.slice(1), ctx);
|
|
121
|
-
process.stdout.write(output +
|
|
108
|
+
process.stdout.write(output + "\n");
|
|
122
109
|
}
|
|
123
110
|
catch (err) {
|
|
124
111
|
writeError(err);
|
|
@@ -126,11 +113,11 @@ export async function main(argv) {
|
|
|
126
113
|
}
|
|
127
114
|
function writeError(err) {
|
|
128
115
|
if (err instanceof AxiError) {
|
|
129
|
-
process.stdout.write(renderError(err.message, err.code, err.suggestions) +
|
|
116
|
+
process.stdout.write(renderError(err.message, err.code, err.suggestions) + "\n");
|
|
130
117
|
}
|
|
131
118
|
else {
|
|
132
119
|
const message = err instanceof Error ? err.message : String(err);
|
|
133
|
-
process.stdout.write(renderError(message,
|
|
120
|
+
process.stdout.write(renderError(message, "UNKNOWN") + "\n");
|
|
134
121
|
}
|
|
135
122
|
process.exitCode = exitCodeForError(err);
|
|
136
123
|
}
|
package/dist/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,QAAQ,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I,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,CAC3D,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import type { RepoContext } from "../context.js";
|
|
2
2
|
export declare const HOME_HELP = "";
|
|
3
3
|
export declare function homeCommand(_args: string[], ctx?: RepoContext): Promise<string>;
|
|
4
|
-
/**
|
|
5
|
-
* Compact session-start dashboard — minimal repo context for agent session init.
|
|
6
|
-
* Skips bin/description, help suggestions, and verbose count lines.
|
|
7
|
-
* Uses compact schemas with fewer fields per entity.
|
|
8
|
-
*/
|
|
9
|
-
export declare function sessionStartCommand(ctx?: RepoContext): Promise<string>;
|
|
@@ -20,9 +20,6 @@ const prSchema = [
|
|
|
20
20
|
REVIEW_REQUIRED: "required",
|
|
21
21
|
}, "none", "review"),
|
|
22
22
|
];
|
|
23
|
-
/* Compact schemas for session-start — fewer fields for minimal token usage */
|
|
24
|
-
const compactIssueSchema = [field("number"), field("title")];
|
|
25
|
-
const compactPrSchema = [field("number"), field("title")];
|
|
26
23
|
export async function homeCommand(_args, ctx) {
|
|
27
24
|
// Run queries in parallel
|
|
28
25
|
const [issues, prs] = await Promise.all([
|
|
@@ -66,24 +63,4 @@ export async function homeCommand(_args, ctx) {
|
|
|
66
63
|
blocks.push(renderHelp([...hints, ...suggestions]));
|
|
67
64
|
return renderOutput(blocks);
|
|
68
65
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Compact session-start dashboard — minimal repo context for agent session init.
|
|
71
|
-
* Skips bin/description, help suggestions, and verbose count lines.
|
|
72
|
-
* Uses compact schemas with fewer fields per entity.
|
|
73
|
-
*/
|
|
74
|
-
export async function sessionStartCommand(ctx) {
|
|
75
|
-
const [issues, prs] = await Promise.all([
|
|
76
|
-
ghJson(["issue", "list", "--json", "number,title", "--limit", "3"], ctx).catch(() => []),
|
|
77
|
-
ghJson(["pr", "list", "--json", "number,title", "--limit", "3"], ctx).catch(() => []),
|
|
78
|
-
]);
|
|
79
|
-
const blocks = [];
|
|
80
|
-
if (ctx) {
|
|
81
|
-
blocks.push(encode({ repo: ctx.nwo }));
|
|
82
|
-
}
|
|
83
|
-
blocks.push(issues.length
|
|
84
|
-
? renderList("issues", issues, compactIssueSchema)
|
|
85
|
-
: "issues: 0 open");
|
|
86
|
-
blocks.push(prs.length ? renderList("prs", prs, compactPrSchema) : "prs: 0 open");
|
|
87
|
-
return renderOutput(blocks);
|
|
88
|
-
}
|
|
89
66
|
//# sourceMappingURL=home.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"home.js","sourceRoot":"","sources":["../../../src/commands/home.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,UAAU,EACV,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,MAAM,WAAW,GAAe;IAC9B,KAAK,CAAC,QAAQ,CAAC;IACf,KAAK,CAAC,OAAO,CAAC;IACd,KAAK,CAAC,OAAO,CAAC;IACd,KAAK,CAAC,QAAQ,EAAE,OAA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AgB,CACrB,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IAE3E,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;IAC5D,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACzE,MAAM,WAAW,GAAG,cAAc,CAAC;QACjC,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG;KACV,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAEpD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ErrorCode =
|
|
1
|
+
export type ErrorCode = "REPO_NOT_FOUND" | "NOT_FOUND" | "AUTH_REQUIRED" | "FORBIDDEN" | "VALIDATION_ERROR" | "GH_NOT_INSTALLED" | "UNKNOWN";
|
|
2
2
|
export declare class AxiError extends Error {
|
|
3
3
|
readonly code: ErrorCode;
|
|
4
4
|
readonly suggestions: string[];
|
package/dist/src/errors.js
CHANGED
|
@@ -5,66 +5,71 @@ export class AxiError extends Error {
|
|
|
5
5
|
super(message);
|
|
6
6
|
this.code = code;
|
|
7
7
|
this.suggestions = suggestions;
|
|
8
|
-
this.name =
|
|
8
|
+
this.name = "AxiError";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
const patterns = [
|
|
12
12
|
{
|
|
13
13
|
pattern: /Could not resolve to a Repository with the name '([^']+)'/,
|
|
14
|
-
code:
|
|
14
|
+
code: "REPO_NOT_FOUND",
|
|
15
15
|
message: (m) => `Repository "${m[1]}" not found`,
|
|
16
|
-
suggestions: () => [
|
|
16
|
+
suggestions: () => ["Run `gh-axi repo list` to see your repositories"],
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
pattern: /Could not resolve to an? .+? with the number of (\d+)/,
|
|
20
|
-
code:
|
|
20
|
+
code: "NOT_FOUND",
|
|
21
21
|
message: (m) => `Item #${m[1]} does not exist in this repository`,
|
|
22
22
|
suggestions: () => [],
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
pattern: /issue (\d+) not found/i,
|
|
26
|
-
code:
|
|
26
|
+
code: "NOT_FOUND",
|
|
27
27
|
message: (m) => `Issue #${m[1]} does not exist`,
|
|
28
28
|
suggestions: () => [],
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
pattern: /pull request (\d+) not found/i,
|
|
32
|
-
code:
|
|
32
|
+
code: "NOT_FOUND",
|
|
33
33
|
message: (m) => `Pull request #${m[1]} does not exist`,
|
|
34
34
|
suggestions: () => [],
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
pattern: /release with tag "([^"]+)" not found/i,
|
|
38
|
-
code:
|
|
38
|
+
code: "NOT_FOUND",
|
|
39
39
|
message: (m) => `Release "${m[1]}" not found`,
|
|
40
|
-
suggestions: () => [
|
|
40
|
+
suggestions: () => [
|
|
41
|
+
`Run \`gh-axi release list\` to see available releases`,
|
|
42
|
+
],
|
|
41
43
|
},
|
|
42
44
|
{
|
|
43
45
|
pattern: /run (\d+) not found/i,
|
|
44
|
-
code:
|
|
46
|
+
code: "NOT_FOUND",
|
|
45
47
|
message: (m) => `Run ${m[1]} not found`,
|
|
46
48
|
suggestions: () => [`Run \`gh-axi run list\` to see recent runs`],
|
|
47
49
|
},
|
|
48
50
|
{
|
|
49
51
|
pattern: /gh auth login/,
|
|
50
|
-
code:
|
|
51
|
-
message: () =>
|
|
52
|
+
code: "AUTH_REQUIRED",
|
|
53
|
+
message: () => "GitHub auth required — run `gh auth login` first",
|
|
52
54
|
},
|
|
53
55
|
{
|
|
54
56
|
pattern: /HTTP 403/,
|
|
55
|
-
code:
|
|
56
|
-
message: () =>
|
|
57
|
+
code: "FORBIDDEN",
|
|
58
|
+
message: () => "Insufficient permissions for this action",
|
|
57
59
|
},
|
|
58
60
|
{
|
|
59
61
|
pattern: /HTTP 422/,
|
|
60
|
-
code:
|
|
62
|
+
code: "VALIDATION_ERROR",
|
|
61
63
|
message: (_m, stderr) => {
|
|
62
64
|
// Try to extract a meaningful message from the 422 body
|
|
63
65
|
const msgMatch = stderr.match(/"message"\s*:\s*"([^"]+)"/);
|
|
64
|
-
return msgMatch ? msgMatch[1] :
|
|
66
|
+
return msgMatch ? msgMatch[1] : "Validation error";
|
|
65
67
|
},
|
|
66
68
|
},
|
|
67
69
|
];
|
|
70
|
+
function firstErrorLine(stderr) {
|
|
71
|
+
return stderr.trim().split("\n")[0] ?? "";
|
|
72
|
+
}
|
|
68
73
|
export function mapGhError(stderr, exitCode) {
|
|
69
74
|
for (const { pattern, code, message, suggestions } of patterns) {
|
|
70
75
|
const match = stderr.match(pattern);
|
|
@@ -73,19 +78,19 @@ export function mapGhError(stderr, exitCode) {
|
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
// Generic not-found for any 404-like message
|
|
76
|
-
if (
|
|
77
|
-
return new AxiError(stderr
|
|
81
|
+
if (/not found/i.test(stderr)) {
|
|
82
|
+
return new AxiError(firstErrorLine(stderr), "NOT_FOUND");
|
|
78
83
|
}
|
|
79
|
-
return new AxiError(stderr
|
|
84
|
+
return new AxiError(firstErrorLine(stderr) || `gh exited with code ${exitCode}`, "UNKNOWN");
|
|
80
85
|
}
|
|
81
86
|
/** Map an error to the appropriate process exit code: 2 for usage errors, 1 for everything else. */
|
|
82
87
|
export function exitCodeForError(err) {
|
|
83
|
-
if (err instanceof AxiError && err.code ===
|
|
88
|
+
if (err instanceof AxiError && err.code === "VALIDATION_ERROR") {
|
|
84
89
|
return 2;
|
|
85
90
|
}
|
|
86
91
|
return 1;
|
|
87
92
|
}
|
|
88
93
|
export function ghNotInstalledError() {
|
|
89
|
-
return new AxiError(
|
|
94
|
+
return new AxiError("gh CLI is not installed — see https://cli.github.com", "GH_NOT_INSTALLED");
|
|
90
95
|
}
|
|
91
96
|
//# sourceMappingURL=errors.js.map
|
package/dist/src/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IACA;IAHlB,YACE,OAAe,EACC,IAAe,EACf,cAAwB,EAAE;QAE1C,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAW;QACf,gBAAW,GAAX,WAAW,CAAe;QAG1C,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AASD,MAAM,QAAQ,GAAmB;IAC/B;QACE,OAAO,EAAE,2DAA2D;QACpE,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,aAAa;QAChD,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,iDAAiD,CAAC;KACvE;IACD;QACE,OAAO,EAAE,uDAAuD;QAChE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,oCAAoC;QACjE,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE;KACtB;IACD;QACE,OAAO,EAAE,wBAAwB;QACjC,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,iBAAiB;QAC/C,WAAW,EAAE,GAAG,E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-fatal — errors log to stderr and never throw.
|
|
5
5
|
*/
|
|
6
|
-
import { existsSync, readFileSync, writeFileSync } from
|
|
7
|
-
import { homedir } from
|
|
8
|
-
import { join } from
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
9
|
/** Marker used to identify our hook entries in config files. */
|
|
10
|
-
const HOOK_ID =
|
|
10
|
+
const HOOK_ID = "gh-axi";
|
|
11
11
|
function getExePath() {
|
|
12
12
|
return process.argv[1];
|
|
13
13
|
}
|
|
14
|
+
function ensureHookCollection(config) {
|
|
15
|
+
if (!config.hooks) {
|
|
16
|
+
config.hooks = {};
|
|
17
|
+
}
|
|
18
|
+
return config.hooks;
|
|
19
|
+
}
|
|
20
|
+
function ensureSessionStartBlocks(hooks) {
|
|
21
|
+
if (!Array.isArray(hooks.SessionStart)) {
|
|
22
|
+
hooks.SessionStart = [];
|
|
23
|
+
}
|
|
24
|
+
return hooks.SessionStart;
|
|
25
|
+
}
|
|
26
|
+
function isManagedHook(hook) {
|
|
27
|
+
return typeof hook?.command === "string" && hook.command.includes(HOOK_ID);
|
|
28
|
+
}
|
|
29
|
+
function createMatcherBlock(command) {
|
|
30
|
+
return {
|
|
31
|
+
matcher: "",
|
|
32
|
+
hooks: [
|
|
33
|
+
{
|
|
34
|
+
type: "command",
|
|
35
|
+
command,
|
|
36
|
+
timeout: 10,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
14
41
|
// ---------------------------------------------------------------------------
|
|
15
42
|
// Claude Code hooks: ~/.claude/settings.json
|
|
16
43
|
// ---------------------------------------------------------------------------
|
|
17
44
|
function ensureClaudeHook(exePath) {
|
|
18
|
-
const claudeDir = join(homedir(),
|
|
45
|
+
const claudeDir = join(homedir(), ".claude");
|
|
19
46
|
if (!existsSync(claudeDir))
|
|
20
47
|
return;
|
|
21
|
-
const settingsPath = join(claudeDir,
|
|
48
|
+
const settingsPath = join(claudeDir, "settings.json");
|
|
22
49
|
let settings = {};
|
|
23
50
|
if (existsSync(settingsPath)) {
|
|
24
|
-
const raw = readFileSync(settingsPath,
|
|
51
|
+
const raw = readFileSync(settingsPath, "utf-8");
|
|
25
52
|
settings = JSON.parse(raw);
|
|
26
53
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (!Array.isArray(settings.hooks.SessionStart)) {
|
|
31
|
-
settings.hooks.SessionStart = [];
|
|
32
|
-
}
|
|
33
|
-
const matcherBlocks = settings.hooks.SessionStart;
|
|
34
|
-
const hookCommand = `${exePath} --session-start`;
|
|
54
|
+
const matcherBlocks = ensureSessionStartBlocks(ensureHookCollection(settings));
|
|
55
|
+
const hookCommand = exePath;
|
|
35
56
|
// Find existing gh-axi matcher block (by looking for gh-axi in any nested hook command)
|
|
36
|
-
const existingIdx = matcherBlocks.findIndex((block) => Array.isArray(block.hooks) &&
|
|
37
|
-
|
|
38
|
-
const matcherBlock = {
|
|
39
|
-
matcher: '',
|
|
40
|
-
hooks: [
|
|
41
|
-
{
|
|
42
|
-
type: 'command',
|
|
43
|
-
command: hookCommand,
|
|
44
|
-
timeout: 10,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
};
|
|
57
|
+
const existingIdx = matcherBlocks.findIndex((block) => Array.isArray(block.hooks) && block.hooks.some(isManagedHook));
|
|
58
|
+
const matcherBlock = createMatcherBlock(hookCommand);
|
|
48
59
|
if (existingIdx >= 0) {
|
|
49
60
|
// Check if command is already correct
|
|
50
|
-
const existingHook = matcherBlocks[existingIdx].hooks?.find(
|
|
61
|
+
const existingHook = matcherBlocks[existingIdx].hooks?.find(isManagedHook);
|
|
51
62
|
if (existingHook?.command === hookCommand) {
|
|
52
63
|
return; // no-op
|
|
53
64
|
}
|
|
@@ -57,42 +68,77 @@ function ensureClaudeHook(exePath) {
|
|
|
57
68
|
else {
|
|
58
69
|
matcherBlocks.push(matcherBlock);
|
|
59
70
|
}
|
|
60
|
-
writeFileSync(settingsPath, JSON.stringify(settings, null, 2),
|
|
71
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
61
72
|
}
|
|
62
73
|
// ---------------------------------------------------------------------------
|
|
63
74
|
// Codex hooks: ~/.codex/hooks.json
|
|
75
|
+
// Uses `hooks.SessionStart` matcher blocks and migrates legacy
|
|
76
|
+
// `hooks.session_start` entries when present.
|
|
64
77
|
// ---------------------------------------------------------------------------
|
|
65
78
|
function ensureCodexHook(exePath) {
|
|
66
|
-
const codexDir = join(homedir(),
|
|
79
|
+
const codexDir = join(homedir(), ".codex");
|
|
67
80
|
if (!existsSync(codexDir))
|
|
68
81
|
return;
|
|
69
|
-
const hooksPath = join(codexDir,
|
|
82
|
+
const hooksPath = join(codexDir, "hooks.json");
|
|
70
83
|
let config = {};
|
|
71
84
|
if (existsSync(hooksPath)) {
|
|
72
|
-
const raw = readFileSync(hooksPath,
|
|
85
|
+
const raw = readFileSync(hooksPath, "utf-8");
|
|
73
86
|
config = JSON.parse(raw);
|
|
74
87
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if
|
|
79
|
-
|
|
88
|
+
const hooks = ensureHookCollection(config);
|
|
89
|
+
let changed = false;
|
|
90
|
+
const hookCommand = exePath;
|
|
91
|
+
// Migrate our legacy lowercase key if present.
|
|
92
|
+
if (Array.isArray(hooks.session_start)) {
|
|
93
|
+
const filteredLegacyHooks = hooks.session_start.filter((hook) => !isManagedHook(hook));
|
|
94
|
+
if (filteredLegacyHooks.length !== hooks.session_start.length) {
|
|
95
|
+
changed = true;
|
|
96
|
+
}
|
|
97
|
+
if (filteredLegacyHooks.length > 0) {
|
|
98
|
+
hooks.session_start = filteredLegacyHooks;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
delete hooks.session_start;
|
|
102
|
+
}
|
|
80
103
|
}
|
|
81
|
-
const
|
|
82
|
-
const existingIdx =
|
|
83
|
-
const
|
|
84
|
-
command: exePath,
|
|
85
|
-
};
|
|
104
|
+
const matcherBlocks = ensureSessionStartBlocks(hooks);
|
|
105
|
+
const existingIdx = matcherBlocks.findIndex((block) => Array.isArray(block.hooks) && block.hooks.some(isManagedHook));
|
|
106
|
+
const matcherBlock = createMatcherBlock(hookCommand);
|
|
86
107
|
if (existingIdx >= 0) {
|
|
87
|
-
|
|
88
|
-
|
|
108
|
+
const existingBlock = matcherBlocks[existingIdx];
|
|
109
|
+
const existingHook = existingBlock.hooks?.find(isManagedHook);
|
|
110
|
+
const matcher = existingBlock?.matcher;
|
|
111
|
+
const matcherIsMatchAll = matcher === "" || matcher === "*" || matcher == null;
|
|
112
|
+
if (existingHook?.command === hookCommand &&
|
|
113
|
+
matcherIsMatchAll &&
|
|
114
|
+
existingHook?.type === "command") {
|
|
115
|
+
if (!changed)
|
|
116
|
+
return; // no-op
|
|
117
|
+
}
|
|
118
|
+
else if (existingHook) {
|
|
119
|
+
existingHook.command = hookCommand;
|
|
120
|
+
existingHook.type = "command";
|
|
121
|
+
changed = true;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (!Array.isArray(existingBlock.hooks)) {
|
|
125
|
+
existingBlock.hooks = [];
|
|
126
|
+
}
|
|
127
|
+
existingBlock.hooks.push({
|
|
128
|
+
type: "command",
|
|
129
|
+
command: hookCommand,
|
|
130
|
+
timeout: 10,
|
|
131
|
+
});
|
|
132
|
+
changed = true;
|
|
89
133
|
}
|
|
90
|
-
hooks[existingIdx] = hookEntry;
|
|
91
134
|
}
|
|
92
135
|
else {
|
|
93
|
-
|
|
136
|
+
matcherBlocks.push(matcherBlock);
|
|
137
|
+
changed = true;
|
|
94
138
|
}
|
|
95
|
-
|
|
139
|
+
if (!changed)
|
|
140
|
+
return;
|
|
141
|
+
writeFileSync(hooksPath, JSON.stringify(config, null, 2), "utf-8");
|
|
96
142
|
}
|
|
97
143
|
// ---------------------------------------------------------------------------
|
|
98
144
|
// Public API
|
package/dist/src/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,gEAAgE;AAChE,MAAM,OAAO,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,gEAAgE;AAChE,MAAM,OAAO,GAAG,QAAQ,CAAC;AAuBzB,SAAS,UAAU;IACjB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAkB;IAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAqB;IACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,OAAO,KAAK,CAAC,YAAY,CAAC;AAC5B,CAAC;AAED,SAAS,aAAa,CAAC,IAA6B;IAClD,OAAO,OAAO,IAAI,EAAE,OAAO,KAAK,QAAQ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,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uCAAuC,GAAG,IAAI,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gh-axi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "AXI-compliant gh CLI wrapper — token-efficient TOON output, contextual suggestions, idempotent mutations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -41,9 +41,14 @@
|
|
|
41
41
|
"@toon-format/toon": "^2.1.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
+
"@eslint/js": "^10.0.1",
|
|
44
45
|
"@types/node": "^22.0.0",
|
|
46
|
+
"eslint": "^10.1.0",
|
|
47
|
+
"globals": "^17.4.0",
|
|
48
|
+
"prettier": "^3.8.1",
|
|
45
49
|
"tsx": "^4.0.0",
|
|
46
50
|
"typescript": "^5.7.0",
|
|
51
|
+
"typescript-eslint": "^8.58.0",
|
|
47
52
|
"vitest": "^3.0.0"
|
|
48
53
|
}
|
|
49
54
|
}
|