Skip to content
Open
18 changes: 18 additions & 0 deletions packages/core/src/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,28 @@
* under the License.
*/

import type { PermissionMode } from './permission.js';

export const COLLABORATION_MODES = ['agent', 'plan'] as const;

export type CollaborationMode = (typeof COLLABORATION_MODES)[number];

export function isCollaborationMode(value: unknown): value is CollaborationMode {
return typeof value === 'string' && (COLLABORATION_MODES as readonly string[]).includes(value);
}

/**
* The permission mode a session runs under once its collaboration mode is
* applied: Plan mode holds the session to read-only unless it is on Bypass.
*
* Lives here because both the model composer and tool dispatch have to reach
* the same answer; a second copy of the rule is a second authority.
*/
export function resolveCollaborationPermissionMode(input: {
readonly collaborationMode: CollaborationMode;
readonly permissionMode: PermissionMode;
}): PermissionMode {
return input.collaborationMode === 'plan' && input.permissionMode !== 'bypass'
? 'explore'
: input.permissionMode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ test('cancels managed approval owners and joiners with the canonical provider id
appendMessage: async () => undefined,
readExecutionBoundary: async () =>
createManagedExecutionBoundary(createWorkspaceWritePermissionProfile(), 0),
readPermissionMode: async () => 'ask',
newId: nextId(),
now: nextNow(),
getPermissionPauseTarget: () => null,
Expand Down
Loading