@codetelemetry/connect 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +8 -1
- package/dist/bootstrap.d.ts +28 -0
- package/dist/bootstrap.js +585 -0
- package/dist/bootstrapGitHub.d.ts +21 -0
- package/dist/bootstrapGitHub.js +157 -0
- package/dist/cli.js +58 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -0
- package/dist/graderArtifact.d.ts +14 -0
- package/dist/graderArtifact.js +94 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/repositoryHook.d.ts +1 -0
- package/dist/repositoryHook.js +31 -0
- package/dist/workspaces.d.ts +44 -0
- package/dist/workspaces.js +366 -0
- package/package.json +1 -1
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
5
|
+
import { buildOtelSection } from "./codexConfig.js";
|
|
6
|
+
import { repositoryHookSource, quotedCommand, REPOSITORY_HOOK_FILE } from "./repositoryHook.js";
|
|
7
|
+
import { looksLikeKey } from "./keys.js";
|
|
8
|
+
export const WORKSPACE_MCP_PACKAGE = "@codetelemetry/mcp@0.4.0";
|
|
9
|
+
export const MAX_WORKSPACE_BYTES = 64 * 1024;
|
|
10
|
+
export const MAX_WORKSPACES = 64;
|
|
11
|
+
export function workspaceName(value) {
|
|
12
|
+
if (typeof value !== "string" ||
|
|
13
|
+
looksLikeKey(value) ||
|
|
14
|
+
!/^[a-z][a-z0-9_-]{0,63}$/.test(value))
|
|
15
|
+
throw new Error("Workspace name must be 1–64 lowercase letters, digits, underscores or hyphens, starting with a letter.");
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
export function workspaceOrigin(value) {
|
|
19
|
+
if (typeof value !== "string" || value.length > 2048)
|
|
20
|
+
throw new Error("Invalid workspace service origin.");
|
|
21
|
+
const url = new URL(value);
|
|
22
|
+
if (url.username ||
|
|
23
|
+
url.password ||
|
|
24
|
+
url.search ||
|
|
25
|
+
url.hash ||
|
|
26
|
+
url.pathname !== "/" ||
|
|
27
|
+
(url.protocol !== "https:" &&
|
|
28
|
+
!(url.protocol === "http:" &&
|
|
29
|
+
["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))))
|
|
30
|
+
throw new Error("Workspace endpoints require an HTTPS origin (HTTP is allowed on loopback).");
|
|
31
|
+
return url.origin;
|
|
32
|
+
}
|
|
33
|
+
export function workspaceScope(value) {
|
|
34
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
35
|
+
throw new Error("Invalid workspace scope.");
|
|
36
|
+
const s = value;
|
|
37
|
+
if ([s.tenantId, s.billingAccountId].some((v) => typeof v !== "string" || !v || v.length > 256) ||
|
|
38
|
+
(s.teamId !== null &&
|
|
39
|
+
(typeof s.teamId !== "string" ||
|
|
40
|
+
!/^tm_[a-zA-Z0-9_-]{1,128}$/.test(s.teamId))))
|
|
41
|
+
throw new Error("Invalid workspace scope.");
|
|
42
|
+
return {
|
|
43
|
+
tenantId: s.tenantId,
|
|
44
|
+
teamId: s.teamId,
|
|
45
|
+
billingAccountId: s.billingAccountId,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function bindingOf(value) {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
50
|
+
throw new Error("Invalid workspace context.");
|
|
51
|
+
const v = value;
|
|
52
|
+
if (v.version !== 1)
|
|
53
|
+
throw new Error("Unsupported workspace context version; upgrade CodeTelemetry.");
|
|
54
|
+
return {
|
|
55
|
+
version: 1,
|
|
56
|
+
name: workspaceName(v.name),
|
|
57
|
+
apiBase: workspaceOrigin(v.apiBase),
|
|
58
|
+
scope: workspaceScope(v.scope),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function sameWorkspace(a, b) {
|
|
62
|
+
return (a.name === b.name &&
|
|
63
|
+
a.apiBase === b.apiBase &&
|
|
64
|
+
a.scope.tenantId === b.scope.tenantId &&
|
|
65
|
+
a.scope.teamId === b.scope.teamId &&
|
|
66
|
+
a.scope.billingAccountId === b.scope.billingAccountId);
|
|
67
|
+
}
|
|
68
|
+
export function workspaceHome() {
|
|
69
|
+
const dir = process.env.CODETELEMETRY_CONTEXT_HOME ||
|
|
70
|
+
path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"), "codetelemetry", "workspaces");
|
|
71
|
+
if (!path.isAbsolute(dir))
|
|
72
|
+
throw new Error("CODETELEMETRY_CONTEXT_HOME must be absolute.");
|
|
73
|
+
return path.resolve(dir);
|
|
74
|
+
}
|
|
75
|
+
function noLinks(file) {
|
|
76
|
+
let current = path.parse(file).root;
|
|
77
|
+
for (const segment of path
|
|
78
|
+
.resolve(file)
|
|
79
|
+
.slice(current.length)
|
|
80
|
+
.split(path.sep)) {
|
|
81
|
+
current = path.join(current, segment);
|
|
82
|
+
try {
|
|
83
|
+
if (fs.lstatSync(current).isSymbolicLink())
|
|
84
|
+
throw new Error("Workspace paths cannot contain symbolic links.");
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error.code !== "ENOENT")
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export function readWorkspaceFile(file, privateFile = true) {
|
|
93
|
+
noLinks(file);
|
|
94
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
|
|
95
|
+
try {
|
|
96
|
+
const st = fs.fstatSync(fd);
|
|
97
|
+
if (!st.isFile() ||
|
|
98
|
+
st.size > MAX_WORKSPACE_BYTES ||
|
|
99
|
+
(privateFile &&
|
|
100
|
+
process.platform !== "win32" &&
|
|
101
|
+
((st.mode & 0o077) !== 0 || st.uid !== process.getuid?.())))
|
|
102
|
+
throw new Error("Workspace state must be an owned private regular file of at most 64 KiB.");
|
|
103
|
+
const bytes = Buffer.alloc(MAX_WORKSPACE_BYTES + 1);
|
|
104
|
+
const count = fs.readSync(fd, bytes, 0, bytes.length, 0);
|
|
105
|
+
if (count > MAX_WORKSPACE_BYTES)
|
|
106
|
+
throw new Error("Workspace state exceeds 64 KiB.");
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(bytes.subarray(0, count).toString("utf8"));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
throw new Error("Invalid workspace JSON; inspect the private state file.");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
fs.closeSync(fd);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function writeWorkspaceText(file, data) {
|
|
119
|
+
if (Buffer.byteLength(data) > MAX_WORKSPACE_BYTES)
|
|
120
|
+
throw new Error("Workspace state exceeds 64 KiB.");
|
|
121
|
+
noLinks(file);
|
|
122
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
123
|
+
noLinks(file);
|
|
124
|
+
if (fs.existsSync(file) && !fs.lstatSync(file).isFile())
|
|
125
|
+
throw new Error("Workspace state must be a regular file.");
|
|
126
|
+
const tmp = `${file}.${randomBytes(12).toString("hex")}.tmp`;
|
|
127
|
+
const fd = fs.openSync(tmp, "wx", 0o600);
|
|
128
|
+
try {
|
|
129
|
+
fs.writeFileSync(fd, data);
|
|
130
|
+
fs.fsyncSync(fd);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
fs.closeSync(fd);
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
fs.renameSync(tmp, file);
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
fs.rmSync(tmp, { force: true });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function writeWorkspaceFile(file, value) {
|
|
143
|
+
writeWorkspaceText(file, JSON.stringify(value, null, 2) + "\n");
|
|
144
|
+
}
|
|
145
|
+
export function codexWorkspaceProfilePath(name) {
|
|
146
|
+
return path.join(process.env.CODEX_HOME || path.join(os.homedir(), ".codex"), `codetelemetry-${workspaceName(name)}.config.toml`);
|
|
147
|
+
}
|
|
148
|
+
export function writeCodexWorkspaceProfile(context, options = {}) {
|
|
149
|
+
const profilePath = codexWorkspaceProfilePath(context.name), marker = `# CodeTelemetry workspace ${context.name}\n`;
|
|
150
|
+
upgradeLegacyCodexObserver(path.dirname(profilePath));
|
|
151
|
+
if (fs.existsSync(profilePath)) {
|
|
152
|
+
noLinks(profilePath);
|
|
153
|
+
const st = fs.lstatSync(profilePath);
|
|
154
|
+
if (!st.isFile() ||
|
|
155
|
+
st.size > MAX_WORKSPACE_BYTES ||
|
|
156
|
+
!fs.readFileSync(profilePath, "utf8").startsWith(marker))
|
|
157
|
+
throw new Error("The Codex workspace profile is not managed by CodeTelemetry; choose a different context name.");
|
|
158
|
+
}
|
|
159
|
+
let text = marker +
|
|
160
|
+
buildOtelSection(context.ingestKey, context.ingestEndpoint, options.enrich === true) +
|
|
161
|
+
"\n";
|
|
162
|
+
if (!options.enrich)
|
|
163
|
+
text = text.replace("[otel]\n", "[otel]\nlog_user_prompt = false\n");
|
|
164
|
+
if (options.repositoryObservation) {
|
|
165
|
+
const hookPath = path.join(workspaceHome(), `${context.name}.hook.cjs`);
|
|
166
|
+
writeWorkspaceText(hookPath, repositoryHookSource({ codexConfigPath: profilePath, workspaceName: context.name }));
|
|
167
|
+
for (const event of ["SessionStart", "UserPromptSubmit", "PostToolUse"])
|
|
168
|
+
text += `\n[[hooks.${event}]]\n[[hooks.${event}.hooks]]\ntype = "command"\ncommand = ${JSON.stringify(quotedCommand(hookPath))}\ntimeout = 3\n`;
|
|
169
|
+
}
|
|
170
|
+
const basePath = path.join(path.dirname(profilePath), "config.toml");
|
|
171
|
+
let base = "";
|
|
172
|
+
if (fs.existsSync(basePath)) {
|
|
173
|
+
if (fs.statSync(basePath).size > 1024 * 1024)
|
|
174
|
+
throw new Error("Base Codex configuration exceeds 1 MiB.");
|
|
175
|
+
base = fs.readFileSync(basePath, "utf8");
|
|
176
|
+
}
|
|
177
|
+
if (/^\s*\[\s*["']?mcp_servers["']?\s*\.\s*["']?codetelemetry["']?\s*\]\s*(?:#.*)?$/m.test(base) ||
|
|
178
|
+
/^\s*mcp_servers\s*\.\s*codetelemetry\s*\.\s*(?:command|url)\s*=/m.test(base))
|
|
179
|
+
text += "\n[mcp_servers.codetelemetry]\nenabled = false\n";
|
|
180
|
+
text += `\n[mcp_servers.codetelemetry_workspace]\ncommand = "npx"\nargs = ["-y", "--package=${WORKSPACE_MCP_PACKAGE}", "codetelemetry-mcp"]\n\n[mcp_servers.codetelemetry_workspace.env]\nCODETELEMETRY_WORKSPACE = ${JSON.stringify(context.name)}\nCODETELEMETRY_CONTEXT_HOME = ${JSON.stringify(workspaceHome())}\n`;
|
|
181
|
+
writeWorkspaceText(profilePath, text);
|
|
182
|
+
return { path: profilePath };
|
|
183
|
+
}
|
|
184
|
+
function upgradeLegacyCodexObserver(codexHome) {
|
|
185
|
+
const file = path.join(codexHome, REPOSITORY_HOOK_FILE);
|
|
186
|
+
if (!fs.existsSync(file))
|
|
187
|
+
return;
|
|
188
|
+
noLinks(file);
|
|
189
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
|
|
190
|
+
let source;
|
|
191
|
+
try {
|
|
192
|
+
const st = fs.fstatSync(fd);
|
|
193
|
+
if (!st.isFile() || st.size > MAX_WORKSPACE_BYTES ||
|
|
194
|
+
(process.platform !== "win32" && (st.uid !== process.getuid?.() || (st.mode & 0o077) !== 0)))
|
|
195
|
+
throw new Error("Existing CodeTelemetry observer must be an owned private regular file.");
|
|
196
|
+
const bytes = Buffer.alloc(MAX_WORKSPACE_BYTES + 1);
|
|
197
|
+
const count = fs.readSync(fd, bytes, 0, bytes.length, 0);
|
|
198
|
+
if (count > MAX_WORKSPACE_BYTES)
|
|
199
|
+
throw new Error("Existing CodeTelemetry observer exceeds 64 KiB.");
|
|
200
|
+
source = bytes.subarray(0, count).toString("utf8");
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
fs.closeSync(fd);
|
|
204
|
+
}
|
|
205
|
+
const configPath = path.join(codexHome, "config.toml");
|
|
206
|
+
const updated = repositoryHookSource({ codexConfigPath: configPath });
|
|
207
|
+
if (source === updated)
|
|
208
|
+
return;
|
|
209
|
+
const declaration = `const codexConfigPath = ${JSON.stringify(configPath)};`;
|
|
210
|
+
const fingerprint = createHash("sha256").update(source.replace(declaration, 'const codexConfigPath = "";')).digest("hex");
|
|
211
|
+
const recognized = new Set([
|
|
212
|
+
"69dd5ad120636379875fc411bcaaa096defe475944d24a6e899dc9796472ab2d",
|
|
213
|
+
"65eaa30f6c565b0298137986bbe4e94d0435f8fedc2574fa284e7979a5fa9ef4",
|
|
214
|
+
]);
|
|
215
|
+
if (!source.includes(declaration) || !recognized.has(fingerprint))
|
|
216
|
+
throw new Error("Existing CodeTelemetry observer differs from a recognized client release. Review or update that helper before configuring a workspace; its global hook definitions were preserved.");
|
|
217
|
+
writeWorkspaceText(file, updated);
|
|
218
|
+
}
|
|
219
|
+
export function workspaceEntries() {
|
|
220
|
+
noLinks(workspaceHome());
|
|
221
|
+
if (!fs.existsSync(workspaceHome()))
|
|
222
|
+
return [];
|
|
223
|
+
const dir = fs.opendirSync(workspaceHome()), names = [];
|
|
224
|
+
try {
|
|
225
|
+
let entry;
|
|
226
|
+
while ((entry = dir.readSync()) !== null) {
|
|
227
|
+
names.push(entry.name);
|
|
228
|
+
if (names.length > MAX_WORKSPACES * 3)
|
|
229
|
+
throw new Error("Workspace store exceeds its entry bound.");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
dir.closeSync();
|
|
234
|
+
}
|
|
235
|
+
return names;
|
|
236
|
+
}
|
|
237
|
+
export function workspaceLock(name) {
|
|
238
|
+
if (name !== ".store")
|
|
239
|
+
workspaceName(name);
|
|
240
|
+
noLinks(workspaceHome());
|
|
241
|
+
fs.mkdirSync(workspaceHome(), { recursive: true, mode: 0o700 });
|
|
242
|
+
workspaceEntries();
|
|
243
|
+
const file = path.join(workspaceHome(), `${name}.lock`);
|
|
244
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
245
|
+
try {
|
|
246
|
+
const fd = fs.openSync(file, "wx", 0o600);
|
|
247
|
+
try {
|
|
248
|
+
fs.writeFileSync(fd, JSON.stringify({ pid: process.pid }));
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
fs.closeSync(fd);
|
|
252
|
+
}
|
|
253
|
+
return () => fs.unlinkSync(file);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
if (error.code !== "EEXIST")
|
|
257
|
+
throw error;
|
|
258
|
+
const owner = readWorkspaceFile(file);
|
|
259
|
+
if (!Number.isSafeInteger(owner.pid) || owner.pid <= 0)
|
|
260
|
+
throw new Error("Workspace lock needs inspection.");
|
|
261
|
+
try {
|
|
262
|
+
process.kill(owner.pid, 0);
|
|
263
|
+
}
|
|
264
|
+
catch (e) {
|
|
265
|
+
if (e.code === "ESRCH") {
|
|
266
|
+
fs.unlinkSync(file);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
throw new Error("Another process is using this workspace; resume when it finishes.");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
throw new Error("Workspace lock changed; retry.");
|
|
274
|
+
}
|
|
275
|
+
export function contextPath(name) {
|
|
276
|
+
return path.join(workspaceHome(), `${workspaceName(name)}.json`);
|
|
277
|
+
}
|
|
278
|
+
export function loadWorkspace(name) {
|
|
279
|
+
const raw = readWorkspaceFile(contextPath(name));
|
|
280
|
+
const binding = bindingOf(raw);
|
|
281
|
+
if (binding.name !== name || !looksLikeKey(raw.ingestKey))
|
|
282
|
+
throw new Error("Workspace context has invalid identity or credentials.");
|
|
283
|
+
if (raw.clientConfig &&
|
|
284
|
+
(!["claude", "codex"].includes(raw.clientConfig.client) ||
|
|
285
|
+
typeof raw.clientConfig.path !== "string" ||
|
|
286
|
+
!path.isAbsolute(raw.clientConfig.path) ||
|
|
287
|
+
typeof raw.clientConfig.enrich !== "boolean" ||
|
|
288
|
+
typeof raw.clientConfig.repositoryObservation !== "boolean"))
|
|
289
|
+
throw new Error("Invalid workspace client configuration.");
|
|
290
|
+
return {
|
|
291
|
+
...binding,
|
|
292
|
+
ingestEndpoint: workspaceOrigin(raw.ingestEndpoint),
|
|
293
|
+
ingestKey: raw.ingestKey,
|
|
294
|
+
...(raw.clientConfig ? { clientConfig: raw.clientConfig } : {}),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export function saveWorkspace(context) {
|
|
298
|
+
const release = workspaceLock(".store");
|
|
299
|
+
try {
|
|
300
|
+
let checked = {
|
|
301
|
+
...bindingOf(context),
|
|
302
|
+
ingestEndpoint: workspaceOrigin(context.ingestEndpoint),
|
|
303
|
+
ingestKey: context.ingestKey,
|
|
304
|
+
...(context.clientConfig ? { clientConfig: context.clientConfig } : {}),
|
|
305
|
+
};
|
|
306
|
+
if (!looksLikeKey(checked.ingestKey))
|
|
307
|
+
throw new Error("Invalid workspace credential.");
|
|
308
|
+
const file = contextPath(checked.name);
|
|
309
|
+
if (fs.existsSync(file)) {
|
|
310
|
+
const existing = loadWorkspace(checked.name);
|
|
311
|
+
if (!sameWorkspace(existing, checked))
|
|
312
|
+
throw new Error("Workspace identity changed; use a new context name.");
|
|
313
|
+
if (!checked.clientConfig && existing.clientConfig)
|
|
314
|
+
checked = { ...checked, clientConfig: existing.clientConfig };
|
|
315
|
+
}
|
|
316
|
+
fs.mkdirSync(workspaceHome(), { recursive: true, mode: 0o700 });
|
|
317
|
+
noLinks(workspaceHome());
|
|
318
|
+
if (!fs.existsSync(file) &&
|
|
319
|
+
workspaceEntries().filter((n) => /^[a-z][a-z0-9_-]{0,63}\.json$/.test(n))
|
|
320
|
+
.length >= MAX_WORKSPACES)
|
|
321
|
+
throw new Error("Workspace store is full; remove unused contexts before continuing.");
|
|
322
|
+
writeWorkspaceFile(file, checked);
|
|
323
|
+
}
|
|
324
|
+
finally {
|
|
325
|
+
release();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
export function listWorkspaces() {
|
|
329
|
+
if (!fs.existsSync(workspaceHome()))
|
|
330
|
+
return [];
|
|
331
|
+
noLinks(workspaceHome());
|
|
332
|
+
const names = workspaceEntries();
|
|
333
|
+
if (names.length > MAX_WORKSPACES * 3)
|
|
334
|
+
throw new Error("Workspace store exceeds its entry bound.");
|
|
335
|
+
const files = names.filter((n) => /^[a-z][a-z0-9_-]{0,63}\.json$/.test(n));
|
|
336
|
+
if (files.length > MAX_WORKSPACES)
|
|
337
|
+
throw new Error("Workspace store exceeds 64 contexts.");
|
|
338
|
+
return files
|
|
339
|
+
.sort()
|
|
340
|
+
.map((file) => bindingOf(loadWorkspace(file.slice(0, -5))));
|
|
341
|
+
}
|
|
342
|
+
export function findWorkspaceBinding(start = process.cwd()) {
|
|
343
|
+
let dir = path.resolve(start);
|
|
344
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
345
|
+
const file = path.join(dir, ".codetelemetry", "workspace.json");
|
|
346
|
+
if (fs.existsSync(file))
|
|
347
|
+
return bindingOf(readWorkspaceFile(file, false));
|
|
348
|
+
if (fs.existsSync(path.join(dir, ".git")) || path.dirname(dir) === dir)
|
|
349
|
+
return null;
|
|
350
|
+
dir = path.dirname(dir);
|
|
351
|
+
}
|
|
352
|
+
throw new Error("Workspace binding search exceeded 64 parents.");
|
|
353
|
+
}
|
|
354
|
+
export function bindWorkspace(repositoryPath, context) {
|
|
355
|
+
const root = fs.realpathSync(repositoryPath);
|
|
356
|
+
if (!fs.statSync(root).isDirectory() ||
|
|
357
|
+
root === os.homedir() ||
|
|
358
|
+
root === path.parse(root).root)
|
|
359
|
+
throw new Error("Choose a repository directory.");
|
|
360
|
+
const file = path.join(root, ".codetelemetry", "workspace.json");
|
|
361
|
+
if (fs.existsSync(file) &&
|
|
362
|
+
!sameWorkspace(bindingOf(readWorkspaceFile(file, false)), context))
|
|
363
|
+
throw new Error("Repository is bound to another workspace; remove its binding explicitly before switching.");
|
|
364
|
+
writeWorkspaceFile(file, bindingOf(context));
|
|
365
|
+
return file;
|
|
366
|
+
}
|