Skip to content

Commit c0d1557

Browse files
n0mahdclaude
andcommitted
fix(server): read and change instruction files under the filesystem scopes
Listing, reading and the git tracking check took the orchestration read scope, and writing, linking, sharing, adopting and deleting an instruction file took the operate scope, though they read and change files on the machine. They now take the filesystem read and write scopes that project file reads and writes take, and the Instructions page's controls follow the write grant through the same command permissions. The instruction MCP tools keep their own gate, like the skill tools: reads are open to any caller, and turning agents on or off needs a live full-access thread or a client above read-only. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 2fda96f commit c0d1557

4 files changed

Lines changed: 57 additions & 45 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ describe("RPC authorization scopes", () => {
8282
}
8383
});
8484

85-
it("lets a read-only client read instructions but not change them", () => {
85+
it("reads and changes instruction files under the filesystem scopes", () => {
8686
for (const method of [
8787
WS_METHODS.serverListInstructions,
8888
WS_METHODS.serverReadInstruction,
8989
WS_METHODS.serverInstructionsTracked,
9090
]) {
91-
expect(requiredScopeForRpcMethod(method)).toBe(AuthOrchestrationReadScope);
91+
expect(requiredScopeForRpcMethod(method)).toBe(AuthFilesystemReadScope);
9292
}
9393
for (const method of [
9494
WS_METHODS.serverWriteInstruction,
@@ -99,7 +99,7 @@ describe("RPC authorization scopes", () => {
9999
WS_METHODS.serverAdoptInstruction,
100100
WS_METHODS.serverDeleteInstruction,
101101
]) {
102-
expect(requiredScopeForRpcMethod(method)).toBe(AuthOrchestrationOperateScope);
102+
expect(requiredScopeForRpcMethod(method)).toBe(AuthFilesystemWriteScope);
103103
}
104104
});
105105

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ export const RPC_REQUIRED_SCOPES = {
6666
[WS_METHODS.serverGetSkill]: AuthFilesystemReadScope,
6767
// `git ls-files` in the project's folder.
6868
[WS_METHODS.serverSkillsTracked]: AuthFilesystemReadScope,
69-
[WS_METHODS.serverListInstructions]: AuthOrchestrationReadScope,
70-
[WS_METHODS.serverReadInstruction]: AuthOrchestrationReadScope,
71-
[WS_METHODS.serverInstructionsTracked]: AuthOrchestrationReadScope,
69+
// Instruction files are read like any other file of the machine.
70+
[WS_METHODS.serverListInstructions]: AuthFilesystemReadScope,
71+
[WS_METHODS.serverReadInstruction]: AuthFilesystemReadScope,
72+
[WS_METHODS.serverInstructionsTracked]: AuthFilesystemReadScope,
7273
[WS_METHODS.serverUpdateProvider]: AuthProvidersManageScope,
7374
[WS_METHODS.providerAuthStart]: AuthProvidersManageScope,
7475
[WS_METHODS.providerConsumeResetCredit]: AuthProvidersManageScope,

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

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -302,36 +302,46 @@ it.effect("needs the filesystem write grant to change skills, but not to list or
302302
),
303303
);
304304

305-
it.effect("needs the operate grant to change instructions, but not to list or read them", () =>
306-
Effect.scoped(
307-
Effect.gen(function* () {
308-
const registry = yield* setup;
309-
for (const method of [
310-
WS_METHODS.serverWriteInstruction,
311-
WS_METHODS.serverEnableInstruction,
312-
WS_METHODS.serverDisableInstruction,
313-
WS_METHODS.serverSetClaudeInstructionFiles,
314-
WS_METHODS.serverShareInstruction,
315-
WS_METHODS.serverAdoptInstruction,
316-
WS_METHODS.serverDeleteInstruction,
317-
]) {
318-
const change = createCommandPermissions(runtime, method);
319-
registry.set(sessions(env), AsyncResult.success(grant(false)));
320-
expect(registry.get(change.permissionAtom(env))).toBe(false);
321-
expect((yield* change.authorize(registry, env).pipe(Effect.flip)).requiredScope).toBe(
322-
AuthOrchestrationOperateScope,
323-
);
324-
registry.set(sessions(env), AsyncResult.success(grant(true)));
325-
expect(registry.get(change.permissionAtom(env))).toBe(true);
326-
yield* change.authorize(registry, env);
327-
}
328-
for (const method of [
329-
WS_METHODS.serverListInstructions,
330-
WS_METHODS.serverReadInstruction,
331-
WS_METHODS.serverInstructionsTracked,
332-
]) {
333-
expect(createCommandPermissions(runtime, method).requiredScopes()).toEqual([]);
334-
}
335-
}),
336-
),
305+
it.effect(
306+
"needs the filesystem write grant to change instructions, but not to list or read them",
307+
() =>
308+
Effect.scoped(
309+
Effect.gen(function* () {
310+
const registry = yield* setup;
311+
const writeGrant: AuthSessionState = {
312+
...grant(false),
313+
scopes: [AuthFilesystemWriteScope],
314+
permissions: [AuthFilesystemWriteScope],
315+
};
316+
for (const method of [
317+
WS_METHODS.serverWriteInstruction,
318+
WS_METHODS.serverEnableInstruction,
319+
WS_METHODS.serverDisableInstruction,
320+
WS_METHODS.serverSetClaudeInstructionFiles,
321+
WS_METHODS.serverShareInstruction,
322+
WS_METHODS.serverAdoptInstruction,
323+
WS_METHODS.serverDeleteInstruction,
324+
]) {
325+
const change = createCommandPermissions(runtime, method);
326+
// Being allowed to operate threads isn't enough to change files.
327+
for (const withoutWrite of [grant(false), grant(true)]) {
328+
registry.set(sessions(env), AsyncResult.success(withoutWrite));
329+
expect(registry.get(change.permissionAtom(env))).toBe(false);
330+
expect(
331+
(yield* change.authorize(registry, env).pipe(Effect.flip)).requiredPermission,
332+
).toBe(AuthFilesystemWriteScope);
333+
}
334+
registry.set(sessions(env), AsyncResult.success(writeGrant));
335+
expect(registry.get(change.permissionAtom(env))).toBe(true);
336+
yield* change.authorize(registry, env);
337+
}
338+
for (const method of [
339+
WS_METHODS.serverListInstructions,
340+
WS_METHODS.serverReadInstruction,
341+
WS_METHODS.serverInstructionsTracked,
342+
]) {
343+
expect(createCommandPermissions(runtime, method).requiredScopes()).toEqual([]);
344+
}
345+
}),
346+
),
337347
);

‎packages/contracts/src/clientRpcPermissions.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ export const CLIENT_GUARDED_RPC_SCOPES = {
4242
[WS_METHODS.serverPlaceSkills]: AuthFilesystemWriteScope,
4343
[WS_METHODS.serverDeleteSkills]: AuthFilesystemWriteScope,
4444

45-
[WS_METHODS.serverWriteInstruction]: AuthOrchestrationOperateScope,
46-
[WS_METHODS.serverEnableInstruction]: AuthOrchestrationOperateScope,
47-
[WS_METHODS.serverDisableInstruction]: AuthOrchestrationOperateScope,
48-
[WS_METHODS.serverSetClaudeInstructionFiles]: AuthOrchestrationOperateScope,
49-
[WS_METHODS.serverShareInstruction]: AuthOrchestrationOperateScope,
50-
[WS_METHODS.serverAdoptInstruction]: AuthOrchestrationOperateScope,
51-
[WS_METHODS.serverDeleteInstruction]: AuthOrchestrationOperateScope,
45+
// Instruction changes write, link, rename and delete the files agents read.
46+
[WS_METHODS.serverWriteInstruction]: AuthFilesystemWriteScope,
47+
[WS_METHODS.serverEnableInstruction]: AuthFilesystemWriteScope,
48+
[WS_METHODS.serverDisableInstruction]: AuthFilesystemWriteScope,
49+
[WS_METHODS.serverSetClaudeInstructionFiles]: AuthFilesystemWriteScope,
50+
[WS_METHODS.serverShareInstruction]: AuthFilesystemWriteScope,
51+
[WS_METHODS.serverAdoptInstruction]: AuthFilesystemWriteScope,
52+
[WS_METHODS.serverDeleteInstruction]: AuthFilesystemWriteScope,
5253

5354
[WS_METHODS.scheduledTasksUpsert]: AuthOrchestrationOperateScope,
5455
[WS_METHODS.scheduledTasksSetEnabled]: AuthOrchestrationOperateScope,

0 commit comments

Comments
 (0)