Skip to content

Commit 54141e8

Browse files
n0mahdclaude
andcommitted
fix(web): don't show another environment's skills for an offline one
When the settings scope's environment was offline, the Skills page fell back to the primary environment (or the first one) and showed its skills as the picked project's, and could send that checkout's folder to the wrong server. The page now stays on the scope's own environment and says it is offline; only a scope that names no environment falls back to the primary one. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 09fbacb commit 54141e8

3 files changed

Lines changed: 86 additions & 6 deletions

File tree

‎apps/web/src/components/settings/SkillsSettings.logic.test.ts‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vite-plus/test";
2-
import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2+
import { EnvironmentId, ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
33
import type { ServerProvider, SkillAgentAccess, SkillListResult } from "@t3tools/contracts";
44

55
import {
@@ -13,6 +13,7 @@ import {
1313
matchesQuery,
1414
scriptFiles,
1515
skillBody,
16+
skillsEnvironment,
1617
unreadableNote,
1718
type Skill,
1819
type SkillAgent,
@@ -88,6 +89,52 @@ describe("ingestSkills", () => {
8889
});
8990
});
9091

92+
describe("skillsEnvironment", () => {
93+
const home = { environmentId: EnvironmentId.make("home") };
94+
const work = { environmentId: EnvironmentId.make("work") };
95+
const all = [home, work];
96+
97+
it("uses the scope's connected environment", () => {
98+
expect(
99+
skillsEnvironment({
100+
connected: work,
101+
scopeEnvironmentIds: [work.environmentId],
102+
environments: all,
103+
primaryId: home.environmentId,
104+
}),
105+
).toBe(work);
106+
});
107+
108+
it("keeps an offline scoped environment instead of showing the primary one's skills", () => {
109+
expect(
110+
skillsEnvironment({
111+
connected: null,
112+
scopeEnvironmentIds: [work.environmentId],
113+
environments: all,
114+
primaryId: home.environmentId,
115+
}),
116+
).toBe(work);
117+
});
118+
119+
it("has no environment when the scope names one that is gone", () => {
120+
expect(
121+
skillsEnvironment({
122+
connected: null,
123+
scopeEnvironmentIds: [EnvironmentId.make("gone")],
124+
environments: all,
125+
primaryId: home.environmentId,
126+
}),
127+
).toBeUndefined();
128+
});
129+
130+
it("falls back to the primary, then the first, when the scope names no environment", () => {
131+
const fallback = { connected: null, scopeEnvironmentIds: [], environments: all };
132+
expect(skillsEnvironment({ ...fallback, primaryId: work.environmentId })).toBe(work);
133+
expect(skillsEnvironment({ ...fallback, primaryId: null })).toBe(home);
134+
expect(skillsEnvironment({ ...fallback, environments: [], primaryId: null })).toBeUndefined();
135+
});
136+
});
137+
91138
describe("installedAgents", () => {
92139
const known = new Set(
93140
["claudeAgent", "claude_work", "codex", "cursor", "pi", "opencode"].map((id) =>

‎apps/web/src/components/settings/SkillsSettings.logic.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
EnvironmentId,
23
ProviderInstanceId,
34
ServerProvider,
45
SkillAgentAccess,
@@ -30,6 +31,31 @@ export type SkillsContext = {
3031
readonly installed: readonly SkillAgent[];
3132
};
3233

34+
/**
35+
* The environment the page reads skills from. The settings scope names it, connected or not: an
36+
* offline environment is reported as offline, never swapped for another one, whose skills would
37+
* be shown as the project's and which would be sent the project's folder. Only a scope that names
38+
* no environment falls back to the primary one, then the first.
39+
*/
40+
export function skillsEnvironment<T extends { readonly environmentId: EnvironmentId }>(input: {
41+
/** The scope's connected environment, when it has one. */
42+
readonly connected: T | null;
43+
readonly scopeEnvironmentIds: readonly EnvironmentId[];
44+
readonly environments: readonly T[];
45+
readonly primaryId: EnvironmentId | null;
46+
}): T | undefined {
47+
if (input.connected) return input.connected;
48+
if (input.scopeEnvironmentIds.length > 0) {
49+
return input.environments.find((item) =>
50+
input.scopeEnvironmentIds.includes(item.environmentId),
51+
);
52+
}
53+
return (
54+
input.environments.find((item) => item.environmentId === input.primaryId) ??
55+
input.environments[0]
56+
);
57+
}
58+
3359
export function ingestSkills(result: SkillListResult) {
3460
const skills = result.skills.map((entry): Skill => ({
3561
...entry,

‎apps/web/src/components/settings/SkillsSettings.tsx‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ingestSkills,
2222
installedAgents,
2323
matchesQuery,
24+
skillsEnvironment,
2425
unreadableNote,
2526
type Skill,
2627
type SkillsContext,
@@ -39,10 +40,12 @@ export function SkillsSettings() {
3940
const { environment: scopedEnvironment, scope } = useSettingsScope();
4041
const { environments } = useEnvironments();
4142
const primaryId = usePrimaryEnvironmentId();
42-
const environment =
43-
scopedEnvironment ??
44-
environments.find((item) => item.environmentId === primaryId) ??
45-
environments[0];
43+
const environment = skillsEnvironment({
44+
connected: scopedEnvironment,
45+
scopeEnvironmentIds: scope.environmentIds,
46+
environments,
47+
primaryId,
48+
});
4649
// The settings scope picker at the top of the page decides what this page shows.
4750
const project =
4851
scope.kind === "checkout"
@@ -69,7 +72,11 @@ export function SkillsSettings() {
6972
</div>
7073
</div>
7174
{!environment ? (
72-
<p className="text-sm text-muted-foreground">Connect an environment to see its skills.</p>
75+
<p className="text-sm text-muted-foreground">
76+
{scope.environmentIds.length > 0
77+
? "This environment isn't available."
78+
: "Connect an environment to see its skills."}
79+
</p>
7380
) : missingProject ? (
7481
<p className="text-sm text-muted-foreground">This project isn't on {environment.label}.</p>
7582
) : (

0 commit comments

Comments
 (0)