-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathAgentMode.ts
More file actions
90 lines (81 loc) · 2.8 KB
/
Copy pathAgentMode.ts
File metadata and controls
90 lines (81 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import type {AskForApproval, SandboxMode, SandboxPolicy} from "./app-server/v2";
import type {SessionMode, SessionModeState} from "@agentclientprotocol/sdk";
export class AgentMode {
readonly id: string;
readonly name: string;
readonly description: string;
readonly approvalPolicy: AskForApproval;
readonly sandboxPolicy: SandboxPolicy;
readonly sandboxMode: SandboxMode;
private constructor(id: string, name: string, description: string, approval: AskForApproval, sandbox: SandboxPolicy, sandboxMode: SandboxMode) {
this.id = id;
this.name = name;
this.description = description;
this.approvalPolicy = approval;
this.sandboxPolicy = sandbox;
this.sandboxMode = sandboxMode; // same as sandboxPolicy, need to look for
}
static readonly ReadOnly = new AgentMode(
"read-only",
"Read-only",
"Requires approval to edit files and run commands.",
"on-request",
{
"type": "readOnly",
"access": {"type": "fullAccess"}
},
"read-only"
);
static readonly Agent = new AgentMode(
"agent",
"Agent",
"Read and edit files, and run commands.",
"on-request",
{
type: "workspaceWrite",
writableRoots: [],
readOnlyAccess: {"type": "fullAccess"},
networkAccess: false,
excludeTmpdirEnvVar: false,
excludeSlashTmp: false
},
"workspace-write"
);
static readonly AgentFullAccess = new AgentMode(
"agent-full-access",
"Agent (full access)",
"Codex can edit files outside this workspace and run commands with network access. Exercise caution when using.",
"never",
{"type": "dangerFullAccess"},
"danger-full-access"
);
static DEFAULT_AGENT_MODE = AgentMode.Agent;
toSessionMode(): SessionMode {
return {
id: this.id,
name: this.name,
description: this.description,
};
}
toSessionModeState(): SessionModeState {
return {
availableModes: AgentMode.all().map(mode => mode.toSessionMode()),
currentModeId: this.id
};
}
static all(): AgentMode[] {
return [AgentMode.ReadOnly, AgentMode.Agent, AgentMode.AgentFullAccess];
}
static find(modeId: string): AgentMode | null {
const match = AgentMode.all().find(m => m.id === modeId);
return match ?? null;
}
static getInitialAgentMode(): AgentMode {
const predefinedAgentMode = process.env["INITIAL_AGENT_MODE"];
if (predefinedAgentMode) {
return AgentMode.find(predefinedAgentMode) ?? AgentMode.DEFAULT_AGENT_MODE;
} else {
return AgentMode.DEFAULT_AGENT_MODE;
}
}
}