MCPcopy Create free account
hub / github.com/anus-dev/ANUS / isWorkspaceTrusted

Function isWorkspaceTrusted

packages/cli/src/config/trustedFolders.ts:114–168  ·  view source on GitHub ↗
(settings: Settings)

Source from the content-addressed store, hash-verified

112}
113
114export function isWorkspaceTrusted(settings: Settings): boolean | undefined {
115 const folderTrustFeature = settings.folderTrustFeature ?? false;
116 const folderTrustSetting = settings.folderTrust ?? true;
117 const folderTrustEnabled = folderTrustFeature && folderTrustSetting;
118
119 if (!folderTrustEnabled) {
120 return true;
121 }
122
123 const { rules, errors } = loadTrustedFolders();
124
125 if (errors.length > 0) {
126 for (const error of errors) {
127 console.error(
128 `Error loading trusted folders config from ${error.path}: ${error.message}`,
129 );
130 }
131 }
132
133 const trustedPaths: string[] = [];
134 const untrustedPaths: string[] = [];
135
136 for (const rule of rules) {
137 switch (rule.trustLevel) {
138 case TrustLevel.TRUST_FOLDER:
139 trustedPaths.push(rule.path);
140 break;
141 case TrustLevel.TRUST_PARENT:
142 trustedPaths.push(path.dirname(rule.path));
143 break;
144 case TrustLevel.DO_NOT_TRUST:
145 untrustedPaths.push(rule.path);
146 break;
147 default:
148 // Do nothing for unknown trust levels.
149 break;
150 }
151 }
152
153 const cwd = process.cwd();
154
155 for (const trustedPath of trustedPaths) {
156 if (isWithinRoot(cwd, trustedPath)) {
157 return true;
158 }
159 }
160
161 for (const untrustedPath of untrustedPaths) {
162 if (path.normalize(cwd) === path.normalize(untrustedPath)) {
163 return false;
164 }
165 }
166
167 return undefined;
168}

Callers 3

useFolderTrustFunction · 0.85
loadCliConfigFunction · 0.85

Calls 2

loadTrustedFoldersFunction · 0.85
isWithinRootFunction · 0.85

Tested by

no test coverage detected