Skip to content

Commit 4615f08

Browse files
committed
fix: harden gh config discovery
1 parent 72b5cdd commit 4615f08

5 files changed

Lines changed: 91 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Docs: https://docs.openclaw.ai
6060
### Fixes
6161

6262
- Cron: keep long manual cron runs active in the task registry until completion, preventing transient `lost` markers before durable recovery reconciles. Fixes #78233. (#78243) Thanks @Feelw00.
63+
- Doctor/GitHub CLI: surface a `GH_CONFIG_DIR` hint when the GitHub skill is usable but `gh` auth lives under a different operator HOME than the agent process, without warning for disabled or filtered skills. Fixes #78063. (#78095) Thanks @tmimmanuel.
6364
- Gateway: clear speculative node wake state when APNs registration is missing, preventing unregistered or mistyped node IDs from retaining wake throttle entries. Fixes #68847. (#68848) Thanks @Feelw00.
6465
- Auto-reply: keep late follow-up queue drain finalizers from deleting a replacement queue registered after `/stop`, preventing immediate follow-up messages from being orphaned. Fixes #68838. (#68839) Thanks @Feelw00.
6566
- Feishu: make manual App ID/App Secret setup the default channel-binding path while keeping QR scan-to-create as an optional best-effort flow, and document the manual fallback for domestic Feishu mobile clients that do not react to the QR code. Fixes #80591. Thanks @wei-wei-zhao.

‎src/agents/skills/gh-config-discovery.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ describe("detectGhConfigDirMismatch", () => {
142142
});
143143
});
144144

145+
it("respects XDG_CONFIG_HOME before HOME on darwin", () => {
146+
const result = detectGhConfigDirMismatch(
147+
makeInput({
148+
platform: "darwin",
149+
env: { HOME: "/Users/agent", XDG_CONFIG_HOME: "/Users/agent/Library/XDG" },
150+
fileExists: fileSet("/Users/agent/Library/XDG/gh/hosts.yml"),
151+
}),
152+
);
153+
expect(result).toEqual({
154+
kind: "auth-discoverable",
155+
effectiveConfigDir: "/Users/agent/Library/XDG/gh",
156+
});
157+
});
158+
145159
it("uses HOME/.config/gh on darwin (matches gh's documented macOS lookup)", () => {
146160
const result = detectGhConfigDirMismatch(
147161
makeInput({
@@ -173,6 +187,37 @@ describe("detectGhConfigDirMismatch", () => {
173187
});
174188
});
175189

190+
it("respects XDG_CONFIG_HOME before APPDATA on win32", () => {
191+
const result = detectGhConfigDirMismatch(
192+
makeInput({
193+
platform: "win32",
194+
env: {
195+
XDG_CONFIG_HOME: "C:\\Users\\agent\\XDG",
196+
APPDATA: "C:\\Users\\agent\\AppData\\Roaming",
197+
},
198+
fileExists: fileSet("C:\\Users\\agent\\XDG\\gh\\hosts.yml"),
199+
}),
200+
);
201+
expect(result).toMatchObject({
202+
kind: "auth-discoverable",
203+
effectiveConfigDir: "C:\\Users\\agent\\XDG\\gh",
204+
});
205+
});
206+
207+
it("falls back to HOME/.config/gh on win32 when APPDATA and USERPROFILE are missing", () => {
208+
const result = detectGhConfigDirMismatch(
209+
makeInput({
210+
platform: "win32",
211+
env: { HOME: "C:\\Users\\agent" },
212+
fileExists: fileSet("C:\\Users\\agent\\.config\\gh\\hosts.yml"),
213+
}),
214+
);
215+
expect(result).toMatchObject({
216+
kind: "auth-discoverable",
217+
effectiveConfigDir: "C:\\Users\\agent\\.config\\gh",
218+
});
219+
});
220+
176221
it("respects an explicit candidateOperatorHomes list", () => {
177222
const result = detectGhConfigDirMismatch(
178223
makeInput({

‎src/agents/skills/gh-config-discovery.ts‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ export type GhConfigDiscoveryResult =
5555

5656
const HOSTS_FILE = "hosts.yml";
5757

58-
// gh config-dir lookup order, matching the documented behavior of `gh
59-
// help environment` for each platform. macOS uses Library/Application Support,
60-
// Windows uses %AppData%\GitHub CLI, Linux/other uses XDG_CONFIG_HOME or
61-
// $HOME/.config/gh.
58+
// gh config-dir lookup order, matching `gh help environment`.
6259
function resolveEffectiveGhConfigDir(input: GhConfigDiscoveryInput): string | undefined {
6360
const env = input.env;
6461
if (env.GH_CONFIG_DIR && env.GH_CONFIG_DIR.trim()) {
6562
return env.GH_CONFIG_DIR.trim();
6663
}
64+
const xdg = env.XDG_CONFIG_HOME?.trim();
65+
if (xdg) {
66+
return pathFor(input.platform).join(xdg, "gh");
67+
}
6768
if (input.platform === "win32") {
6869
const appData = env.APPDATA?.trim();
6970
if (appData) {
@@ -73,19 +74,6 @@ function resolveEffectiveGhConfigDir(input: GhConfigDiscoveryInput): string | un
7374
if (profile) {
7475
return pathFor(input.platform).join(profile, "AppData", "Roaming", "GitHub CLI");
7576
}
76-
return undefined;
77-
}
78-
if (input.platform === "darwin") {
79-
const home = env.HOME?.trim();
80-
if (!home) {
81-
return undefined;
82-
}
83-
return pathFor(input.platform).join(home, ".config", "gh");
84-
}
85-
// Linux and POSIX-like default
86-
const xdg = env.XDG_CONFIG_HOME?.trim();
87-
if (xdg) {
88-
return pathFor(input.platform).join(xdg, "gh");
8977
}
9078
const home = env.HOME?.trim();
9179
if (!home) {

‎src/commands/doctor-skills.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,40 @@ describe("doctor skills", () => {
124124
expect(describeGhConfigDirHintFromDiscovery([githubSkill], discovery)).toEqual([]);
125125
});
126126

127+
it("does not surface the GH_CONFIG_DIR hint when the github skill is disabled", () => {
128+
const githubSkill = createSkill({
129+
name: "github",
130+
skillKey: "github",
131+
eligible: false,
132+
disabled: true,
133+
missing: { bins: [], anyBins: [], env: [], config: [], os: [] },
134+
});
135+
const discovery: GhConfigDiscoveryInput = {
136+
platform: "linux",
137+
env: { HOME: "/agent/home" },
138+
fileExists: (p) => p === "/root/.config/gh/hosts.yml",
139+
};
140+
141+
expect(describeGhConfigDirHintFromDiscovery([githubSkill], discovery)).toEqual([]);
142+
});
143+
144+
it("does not surface the GH_CONFIG_DIR hint when the github skill is filtered out for the agent", () => {
145+
const githubSkill = createSkill({
146+
name: "github",
147+
skillKey: "github",
148+
eligible: true,
149+
blockedByAgentFilter: true,
150+
missing: { bins: [], anyBins: [], env: [], config: [], os: [] },
151+
});
152+
const discovery: GhConfigDiscoveryInput = {
153+
platform: "linux",
154+
env: { HOME: "/agent/home" },
155+
fileExists: (p) => p === "/root/.config/gh/hosts.yml",
156+
};
157+
158+
expect(describeGhConfigDirHintFromDiscovery([githubSkill], discovery)).toEqual([]);
159+
});
160+
127161
it("does not surface the GH_CONFIG_DIR hint when GH_CONFIG_DIR is already set", () => {
128162
const githubSkill = createSkill({
129163
name: "github",

‎src/commands/doctor-skills.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ export function describeGhConfigDirHintFromDiscovery(
7070
if (!githubSkill) {
7171
return [];
7272
}
73-
// The github skill only requires the `gh` binary; if it is not installed we
74-
// do not surface a config-dir hint (the bin install hint covers it).
75-
if (githubSkill.missing.bins.includes("gh")) {
73+
if (
74+
!githubSkill.eligible ||
75+
githubSkill.blockedByAgentFilter ||
76+
githubSkill.disabled ||
77+
githubSkill.blockedByAllowlist
78+
) {
7679
return [];
7780
}
7881
const result: GhConfigDiscoveryResult = detectGhConfigDirMismatch(discoveryInput);

0 commit comments

Comments
 (0)