Skip to content

Commit 6dd68c6

Browse files
n0mahdclaude
andcommitted
fix(server): change skills under the filesystem write scope, and check tracking's folder
Turning skills on or off, moving them and deleting them make and remove links, write the agents' own settings files and move and delete skill folders, but took the orchestration operate scope. They now take the filesystem write scope, as writing a project file does, and the Skills page's switches follow it, since they read the same grant. The git tracking check ran `git ls-files` in any absolute folder it was given. It now takes the filesystem read scope, and the skill catalog's lookup that it goes through refuses a folder that isn't a registered project's workspace root, like the list and a single skill do. The skills MCP tools keep their own gate: reads are open to any caller, and changes need a live full-access thread or a client approved above read-only, which is stricter than the scope. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 071268a commit 6dd68c6

8 files changed

Lines changed: 70 additions & 30 deletions

File tree

‎apps/server/src/auth/RpcAuthorization.test.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AuthEnvironmentMaintainScope,
33
AuthDiagnosticsReadScope,
44
AuthFilesystemReadScope,
5+
AuthFilesystemWriteScope,
56
AuthProvidersManageScope,
67
AuthSettingsWriteScope,
78
DEFAULT_SERVER_SETTINGS,
@@ -60,23 +61,24 @@ describe("RPC authorization scopes", () => {
6061
}
6162
});
6263

63-
it("reads skill folders and SKILL.md text under the filesystem read scope", () => {
64-
for (const method of [WS_METHODS.serverListSkills, WS_METHODS.serverGetSkill]) {
64+
it("reads skill folders, SKILL.md text and git tracking under the filesystem read scope", () => {
65+
for (const method of [
66+
WS_METHODS.serverListSkills,
67+
WS_METHODS.serverGetSkill,
68+
WS_METHODS.serverSkillsTracked,
69+
]) {
6570
expect(requiredScopeForRpcMethod(method)).toBe(AuthFilesystemReadScope);
6671
}
67-
expect(requiredScopeForRpcMethod(WS_METHODS.serverSkillsTracked)).toBe(
68-
AuthOrchestrationReadScope,
69-
);
7072
});
7173

72-
it("doesn't let a read-only client change which agents use skills", () => {
74+
it("changes skills, which writes links, settings files and folders, under filesystem write", () => {
7375
for (const method of [
7476
WS_METHODS.serverEnableSkills,
7577
WS_METHODS.serverDisableSkills,
7678
WS_METHODS.serverPlaceSkills,
7779
WS_METHODS.serverDeleteSkills,
7880
]) {
79-
expect(requiredScopeForRpcMethod(method)).toBe(AuthOrchestrationOperateScope);
81+
expect(requiredScopeForRpcMethod(method)).toBe(AuthFilesystemWriteScope);
8082
}
8183
});
8284

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export const RPC_REQUIRED_SCOPES = {
6464
// reads take, not the orchestration read scope that thread readers hold.
6565
[WS_METHODS.serverListSkills]: AuthFilesystemReadScope,
6666
[WS_METHODS.serverGetSkill]: AuthFilesystemReadScope,
67-
[WS_METHODS.serverSkillsTracked]: AuthOrchestrationReadScope,
67+
// `git ls-files` in the project's folder.
68+
[WS_METHODS.serverSkillsTracked]: AuthFilesystemReadScope,
6869
[WS_METHODS.serverUpdateProvider]: AuthProvidersManageScope,
6970
[WS_METHODS.providerAuthStart]: AuthProvidersManageScope,
7071
[WS_METHODS.providerConsumeResetCredit]: AuthProvidersManageScope,

‎apps/server/src/skills/SkillCatalog.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ export class SkillCatalog extends Context.Service<
251251
readonly get: (input: SkillGetInput) => Effect.Effect<SkillGetResult, SkillRequestError>;
252252
/**
253253
* Every skill in the agents' folders with this scope and name, as the folders hold it now.
254-
* A project skill needs `cwd`. Nothing is written.
254+
* A project skill needs `cwd`, which must be a registered project's workspace root like the
255+
* one `list` takes. Nothing is written.
255256
*/
256257
readonly resolve: (input: {
257258
readonly cwd?: string | undefined;
258259
readonly skills: ReadonlyArray<{ readonly scope: SkillScope; readonly name: string }>;
259-
}) => Effect.Effect<ReadonlyArray<ResolvedSkill>>;
260+
}) => Effect.Effect<ReadonlyArray<ResolvedSkill>, SkillRequestError>;
260261
}
261262
>()("t3/skills/SkillCatalog") {}
262263

@@ -420,10 +421,6 @@ const make = Effect.gen(function* () {
420421
return cwd;
421422
});
422423

423-
/** A project's folder as `resolve` takes it: a relative one names no project. */
424-
const absoluteCwd = (cwd: string | undefined) =>
425-
cwd !== undefined && path.isAbsolute(cwd) ? cwd : undefined;
426-
427424
/** A global folder as shown to the user: `~/...` under the home directory, else its path. */
428425
const globalLabel = (directory: string) => {
429426
const relative = path.relative(homeDirectory, directory);
@@ -898,7 +895,7 @@ const make = Effect.gen(function* () {
898895

899896
const resolve: SkillCatalog["Service"]["resolve"] = Effect.fn("SkillCatalog.resolve")(
900897
function* (input) {
901-
const cwd = absoluteCwd(input.cwd);
898+
const cwd = yield* requireProject(input.cwd);
902899
const wanted = input.skills.filter(
903900
(skill) => isSkillFolderName(skill.name) && (skill.scope === "global" || cwd !== undefined),
904901
);

‎apps/server/src/skills/SkillTracking.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { describe, expect, it } from "@effect/vitest";
33
import {
44
ProjectId,
5+
SkillRequestError,
56
type Project,
67
type SkillRef,
78
type SkillScope,
@@ -212,6 +213,30 @@ it.layer(NodeServices.layer, { excludeTestServices: true })("SkillTracking", (it
212213
}),
213214
);
214215

216+
it.effect("refuses a folder that isn't a registered project, without running git", () =>
217+
Effect.gen(function* () {
218+
const { home, project } = yield* makeMachine;
219+
yield* git(project, ["init"]);
220+
yield* git(project, ["add", "."]);
221+
yield* git(project, ["commit", "-m", "everything"]);
222+
const skills = [
223+
{ scope: "project", name: "verify", home: ".agents/skills/verify" },
224+
] as const;
225+
const refused = yield* onMachine(
226+
home,
227+
({ tracking }) => tracking.tracked({ cwd: project, skills }).pipe(Effect.flip),
228+
[],
229+
);
230+
expect(refused).toEqual(new SkillRequestError({ reason: "projectNotRegistered" }));
231+
232+
// The same folder is read once it is a project.
233+
const result = yield* onMachine(home, ({ tracking }) =>
234+
tracking.tracked({ cwd: project, skills }),
235+
);
236+
expect(result.tracked).toEqual(["verify"]);
237+
}),
238+
);
239+
215240
it.effect("tracks nothing outside a git repository", () =>
216241
Effect.gen(function* () {
217242
const { home, project } = yield* makeMachine;

‎apps/server/src/skills/SkillTracking.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @module SkillTracking
1010
*/
11-
import type { SkillTrackedInput, SkillTrackedResult } from "@t3tools/contracts";
11+
import type { SkillRequestError, SkillTrackedInput, SkillTrackedResult } from "@t3tools/contracts";
1212
import * as Context from "effect/Context";
1313
import * as Effect from "effect/Effect";
1414
import * as FileSystem from "effect/FileSystem";
@@ -27,9 +27,12 @@ export class SkillTracking extends Context.Service<
2727
* The names of the project skills among `skills` whose SKILL.md git tracks. A skill that
2828
* isn't where the client said, isn't a project skill, sits outside the repository, or whose
2929
* folder is only reached through a link counts as not tracked, and so does every skill when
30-
* git fails.
30+
* git fails. The folder must be a registered project's workspace root, or the request is
31+
* refused before git runs.
3132
*/
32-
readonly tracked: (input: SkillTrackedInput) => Effect.Effect<SkillTrackedResult>;
33+
readonly tracked: (
34+
input: SkillTrackedInput,
35+
) => Effect.Effect<SkillTrackedResult, SkillRequestError>;
3336
}
3437
>()("t3/skills/SkillTracking") {}
3538

‎packages/client-runtime/src/state/commandPermissions.test.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { RpcSession } from "../rpc/session.ts";
77
import { describe, expect, it } from "@effect/vitest";
88
import { vi } from "vite-plus/test";
99
import {
10+
AuthFilesystemWriteScope,
1011
AuthOrchestrationOperateScope,
1112
AuthSourceControlWriteScope,
1213
ThreadId,
@@ -262,23 +263,31 @@ it.effect("rejects protected unary and streamed RPCs outside a guarded command",
262263
}),
263264
);
264265

265-
it.effect("needs the operate grant to change skills, but not to list or read them", () =>
266+
it.effect("needs the filesystem write grant to change skills, but not to list or read them", () =>
266267
Effect.scoped(
267268
Effect.gen(function* () {
268269
const registry = yield* setup;
270+
const writeGrant: AuthSessionState = {
271+
...grant(false),
272+
scopes: [AuthFilesystemWriteScope],
273+
permissions: [AuthFilesystemWriteScope],
274+
};
269275
for (const method of [
270276
WS_METHODS.serverEnableSkills,
271277
WS_METHODS.serverDisableSkills,
272278
WS_METHODS.serverPlaceSkills,
273279
WS_METHODS.serverDeleteSkills,
274280
]) {
275281
const change = createCommandPermissions(runtime, method);
276-
registry.set(sessions(env), AsyncResult.success(grant(false)));
277-
expect(registry.get(change.permissionAtom(env))).toBe(false);
278-
expect((yield* change.authorize(registry, env).pipe(Effect.flip)).requiredScope).toBe(
279-
AuthOrchestrationOperateScope,
280-
);
281-
registry.set(sessions(env), AsyncResult.success(grant(true)));
282+
// Being allowed to operate threads isn't enough to change files.
283+
for (const withoutWrite of [grant(false), grant(true)]) {
284+
registry.set(sessions(env), AsyncResult.success(withoutWrite));
285+
expect(registry.get(change.permissionAtom(env))).toBe(false);
286+
expect(
287+
(yield* change.authorize(registry, env).pipe(Effect.flip)).requiredPermission,
288+
).toBe(AuthFilesystemWriteScope);
289+
}
290+
registry.set(sessions(env), AsyncResult.success(writeGrant));
282291
expect(registry.get(change.permissionAtom(env))).toBe(true);
283292
yield* change.authorize(registry, env);
284293
}

‎packages/contracts/src/clientRpcPermissions.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Schema from "effect/Schema";
22
import { GitPreparePullRequestThreadInput } from "./git.ts";
33
import {
4+
AuthFilesystemWriteScope,
45
AuthOrchestrationOperateScope,
56
AuthSourceControlWriteScope,
67
type AuthEnvironmentScope,
@@ -34,10 +35,12 @@ export const CLIENT_GUARDED_RPC_SCOPES = {
3435
[WS_METHODS.vcsSwitchRef]: AuthSourceControlWriteScope,
3536
[WS_METHODS.vcsInit]: AuthSourceControlWriteScope,
3637

37-
[WS_METHODS.serverEnableSkills]: AuthOrchestrationOperateScope,
38-
[WS_METHODS.serverDisableSkills]: AuthOrchestrationOperateScope,
39-
[WS_METHODS.serverPlaceSkills]: AuthOrchestrationOperateScope,
40-
[WS_METHODS.serverDeleteSkills]: AuthOrchestrationOperateScope,
38+
// Skill changes create and remove links, write the agents' settings files, and move and delete
39+
// skill folders, so they take the scope the other file writes take.
40+
[WS_METHODS.serverEnableSkills]: AuthFilesystemWriteScope,
41+
[WS_METHODS.serverDisableSkills]: AuthFilesystemWriteScope,
42+
[WS_METHODS.serverPlaceSkills]: AuthFilesystemWriteScope,
43+
[WS_METHODS.serverDeleteSkills]: AuthFilesystemWriteScope,
4144

4245
[WS_METHODS.scheduledTasksUpsert]: AuthOrchestrationOperateScope,
4346
[WS_METHODS.scheduledTasksSetEnabled]: AuthOrchestrationOperateScope,

‎packages/contracts/src/rpc.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ const WsServerDeleteSkillsRpc = Rpc.make(WS_METHODS.serverDeleteSkills, {
651651
const WsServerSkillsTrackedRpc = Rpc.make(WS_METHODS.serverSkillsTracked, {
652652
payload: SkillTrackedInput,
653653
success: SkillTrackedResult,
654-
error: EnvironmentAuthorizationError,
654+
error: Schema.Union([SkillRequestError, EnvironmentAuthorizationError]),
655655
});
656656

657657
const WsServerRefreshProvidersRpc = Rpc.make(WS_METHODS.serverRefreshProviders, {

0 commit comments

Comments
 (0)