teamroom 0.1.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/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +420 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/api-client.d.ts +122 -0
- package/dist/client/api-client.js +185 -0
- package/dist/client/api-client.js.map +1 -0
- package/dist/client/claude-hook.d.ts +40 -0
- package/dist/client/claude-hook.js +121 -0
- package/dist/client/claude-hook.js.map +1 -0
- package/dist/client/config.d.ts +25 -0
- package/dist/client/config.js +71 -0
- package/dist/client/config.js.map +1 -0
- package/dist/client/doctor.d.ts +20 -0
- package/dist/client/doctor.js +129 -0
- package/dist/client/doctor.js.map +1 -0
- package/dist/client/errors.d.ts +26 -0
- package/dist/client/errors.js +49 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/git.d.ts +42 -0
- package/dist/client/git.js +126 -0
- package/dist/client/git.js.map +1 -0
- package/dist/client/hooks.d.ts +21 -0
- package/dist/client/hooks.js +100 -0
- package/dist/client/hooks.js.map +1 -0
- package/dist/client/invite-link.d.ts +16 -0
- package/dist/client/invite-link.js +51 -0
- package/dist/client/invite-link.js.map +1 -0
- package/dist/client/mcp-config.d.ts +12 -0
- package/dist/client/mcp-config.js +52 -0
- package/dist/client/mcp-config.js.map +1 -0
- package/dist/client/workspace.d.ts +58 -0
- package/dist/client/workspace.js +157 -0
- package/dist/client/workspace.js.map +1 -0
- package/dist/core/agents.d.ts +6 -0
- package/dist/core/agents.js +34 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/overlap.d.ts +21 -0
- package/dist/core/overlap.js +75 -0
- package/dist/core/overlap.js.map +1 -0
- package/dist/core/room.d.ts +34 -0
- package/dist/core/room.js +105 -0
- package/dist/core/room.js.map +1 -0
- package/dist/core/schemas.d.ts +136 -0
- package/dist/core/schemas.js +98 -0
- package/dist/core/schemas.js.map +1 -0
- package/dist/core/secrets.d.ts +5 -0
- package/dist/core/secrets.js +23 -0
- package/dist/core/secrets.js.map +1 -0
- package/dist/core/types.d.ts +69 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dashboard/Dashboard.d.ts +9 -0
- package/dist/dashboard/Dashboard.js +53 -0
- package/dist/dashboard/Dashboard.js.map +1 -0
- package/dist/dashboard/Header.d.ts +6 -0
- package/dist/dashboard/Header.js +22 -0
- package/dist/dashboard/Header.js.map +1 -0
- package/dist/dashboard/HotFiles.d.ts +6 -0
- package/dist/dashboard/HotFiles.js +11 -0
- package/dist/dashboard/HotFiles.js.map +1 -0
- package/dist/dashboard/MemberList.d.ts +9 -0
- package/dist/dashboard/MemberList.js +30 -0
- package/dist/dashboard/MemberList.js.map +1 -0
- package/dist/dashboard/RecentActivity.d.ts +7 -0
- package/dist/dashboard/RecentActivity.js +11 -0
- package/dist/dashboard/RecentActivity.js.map +1 -0
- package/dist/dashboard/SessionDetail.d.ts +8 -0
- package/dist/dashboard/SessionDetail.js +20 -0
- package/dist/dashboard/SessionDetail.js.map +1 -0
- package/dist/dashboard/StatusBar.d.ts +7 -0
- package/dist/dashboard/StatusBar.js +8 -0
- package/dist/dashboard/StatusBar.js.map +1 -0
- package/dist/dashboard/model.d.ts +69 -0
- package/dist/dashboard/model.js +136 -0
- package/dist/dashboard/model.js.map +1 -0
- package/dist/dashboard/run.d.ts +2 -0
- package/dist/dashboard/run.js +15 -0
- package/dist/dashboard/run.js.map +1 -0
- package/dist/dashboard/theme.d.ts +14 -0
- package/dist/dashboard/theme.js +15 -0
- package/dist/dashboard/theme.js.map +1 -0
- package/dist/dashboard/useRoomPolling.d.ts +18 -0
- package/dist/dashboard/useRoomPolling.js +48 -0
- package/dist/dashboard/useRoomPolling.js.map +1 -0
- package/dist/mcp/server.d.ts +34 -0
- package/dist/mcp/server.js +215 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/server/app.d.ts +37 -0
- package/dist/server/app.js +285 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/logger.d.ts +5 -0
- package/dist/server/logger.js +6 -0
- package/dist/server/logger.js.map +1 -0
- package/dist/server/rate-limit.d.ts +18 -0
- package/dist/server/rate-limit.js +40 -0
- package/dist/server/rate-limit.js.map +1 -0
- package/dist/server/serve.d.ts +39 -0
- package/dist/server/serve.js +87 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/store/file-store.d.ts +21 -0
- package/dist/store/file-store.js +122 -0
- package/dist/store/file-store.js.map +1 -0
- package/dist/store/memory-store.d.ts +9 -0
- package/dist/store/memory-store.js +23 -0
- package/dist/store/memory-store.js.map +1 -0
- package/dist/store/store.d.ts +22 -0
- package/dist/store/store.js +25 -0
- package/dist/store/store.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { ApiClient } from "./api-client.js";
|
|
4
|
+
import { loadConfig } from "./config.js";
|
|
5
|
+
import { describeError } from "./errors.js";
|
|
6
|
+
import { Git } from "./git.js";
|
|
7
|
+
import { HOOK_NAMES, installedHooks } from "./hooks.js";
|
|
8
|
+
import { mcpConfigHasTeamroom } from "./mcp-config.js";
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
10
|
+
const COMMAND_LOOKUP_TIMEOUT_MS = 2_000;
|
|
11
|
+
/**
|
|
12
|
+
* Runs every check it can instead of stopping at the first failure, so one
|
|
13
|
+
* run shows the whole picture. Later checks are skipped only when they
|
|
14
|
+
* cannot mean anything, such as token checks without a config.
|
|
15
|
+
*/
|
|
16
|
+
export async function runDoctor(cwd, options = {}) {
|
|
17
|
+
const env = options.env ?? process.env;
|
|
18
|
+
const commandOnPath = options.commandOnPath ?? isCommandOnPath;
|
|
19
|
+
const checks = [];
|
|
20
|
+
const git = new Git(cwd);
|
|
21
|
+
let repoRoot;
|
|
22
|
+
let commonDir;
|
|
23
|
+
try {
|
|
24
|
+
[repoRoot, commonDir] = await Promise.all([git.repoRoot(), git.commonDir()]);
|
|
25
|
+
checks.push({ name: "Git repository", status: "ok", detail: repoRoot });
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
checks.push({ name: "Git repository", status: "fail", detail: describeError(error), fix: "cd into your repo" });
|
|
29
|
+
return checks;
|
|
30
|
+
}
|
|
31
|
+
const onPath = await commandOnPath("teamroom");
|
|
32
|
+
checks.push(onPath
|
|
33
|
+
? { name: "teamroom on PATH", status: "ok", detail: "Agents and hooks can launch it." }
|
|
34
|
+
: {
|
|
35
|
+
name: "teamroom on PATH",
|
|
36
|
+
status: "warn",
|
|
37
|
+
detail: "MCP configs and teammates' hooks call `teamroom` by name.",
|
|
38
|
+
fix: "npm install --global teamroom",
|
|
39
|
+
});
|
|
40
|
+
const hooks = await installedHooks(await git.hooksDir());
|
|
41
|
+
const missingHooks = HOOK_NAMES.filter((name) => !hooks.includes(name));
|
|
42
|
+
checks.push(missingHooks.length === 0
|
|
43
|
+
? { name: "Git hooks", status: "ok", detail: "Commits, checkouts, merges and rebases are reported." }
|
|
44
|
+
: {
|
|
45
|
+
name: "Git hooks",
|
|
46
|
+
status: "warn",
|
|
47
|
+
detail: `Missing: ${missingHooks.join(", ")}. Your work is only shared when you run \`teamroom report\`.`,
|
|
48
|
+
fix: "teamroom hooks install",
|
|
49
|
+
});
|
|
50
|
+
const hasMcp = await mcpConfigHasTeamroom(repoRoot).catch(() => false);
|
|
51
|
+
checks.push(hasMcp
|
|
52
|
+
? { name: "Agent setup", status: "ok", detail: ".mcp.json lists the teamroom server." }
|
|
53
|
+
: {
|
|
54
|
+
name: "Agent setup",
|
|
55
|
+
status: "warn",
|
|
56
|
+
detail: "Claude Code will not see the teamroom tools in this repo.",
|
|
57
|
+
fix: "teamroom agents install",
|
|
58
|
+
});
|
|
59
|
+
const baseRef = await git.defaultBranchRef();
|
|
60
|
+
checks.push(baseRef
|
|
61
|
+
? { name: "Default branch", status: "ok", detail: `Pending changes are measured against ${baseRef}.` }
|
|
62
|
+
: {
|
|
63
|
+
name: "Default branch",
|
|
64
|
+
status: "warn",
|
|
65
|
+
detail: "No origin/main, origin/master, main or master. Only uncommitted changes are shared.",
|
|
66
|
+
fix: "git fetch origin",
|
|
67
|
+
});
|
|
68
|
+
let config;
|
|
69
|
+
try {
|
|
70
|
+
config = await loadConfig(commonDir, env);
|
|
71
|
+
checks.push({ name: "Membership", status: "ok", detail: `${config.member} in ${config.roomId}` });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
checks.push({
|
|
75
|
+
name: "Membership",
|
|
76
|
+
status: "fail",
|
|
77
|
+
detail: describeError(error),
|
|
78
|
+
fix: "teamroom join '<invite link>'",
|
|
79
|
+
});
|
|
80
|
+
return checks;
|
|
81
|
+
}
|
|
82
|
+
const client = new ApiClient({ server: config.server, token: config.token, maxAttempts: 1 });
|
|
83
|
+
try {
|
|
84
|
+
await client.health();
|
|
85
|
+
checks.push({ name: "Server", status: "ok", detail: `${config.server} is up.` });
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
checks.push({
|
|
89
|
+
name: "Server",
|
|
90
|
+
status: "fail",
|
|
91
|
+
detail: describeError(error),
|
|
92
|
+
fix: "Check the URL, your network, or ask whoever runs the server.",
|
|
93
|
+
});
|
|
94
|
+
return checks;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const { room } = await client.getRoom(config.roomId, 1);
|
|
98
|
+
checks.push({ name: "Token", status: "ok", detail: `Accepted by "${room.name}".` });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
checks.push({
|
|
102
|
+
name: "Token",
|
|
103
|
+
status: "fail",
|
|
104
|
+
detail: describeError(error),
|
|
105
|
+
fix: "You may have been removed or your token rotated. Ask for a new invite link and join again.",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return checks;
|
|
109
|
+
}
|
|
110
|
+
export function formatDoctor(checks) {
|
|
111
|
+
const symbols = { ok: "✓", warn: "!", fail: "✗" };
|
|
112
|
+
return checks
|
|
113
|
+
.map((check) => {
|
|
114
|
+
const line = `${symbols[check.status]} ${check.name}: ${check.detail}`;
|
|
115
|
+
return check.fix && check.status !== "ok" ? `${line}\n fix: ${check.fix}` : line;
|
|
116
|
+
})
|
|
117
|
+
.join("\n");
|
|
118
|
+
}
|
|
119
|
+
async function isCommandOnPath(command) {
|
|
120
|
+
const lookup = process.platform === "win32" ? "where" : "which";
|
|
121
|
+
try {
|
|
122
|
+
await execFileAsync(lookup, [command], { timeout: COMMAND_LOOKUP_TIMEOUT_MS });
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/client/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC1C,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAiBxC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,OAAO,GAAkB,EAAE;IACtE,MAA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AM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The server answered with an error envelope `{ error: { code, message, requestId } }`. */
|
|
2
|
+
export declare class ApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly requestId?: string | undefined;
|
|
6
|
+
constructor(status: number, code: string, message: string, requestId?: string | undefined);
|
|
7
|
+
}
|
|
8
|
+
/** The server could not be reached, timed out, or returned something that is not a teamroom response. */
|
|
9
|
+
export declare class NetworkError extends Error {
|
|
10
|
+
constructor(message: string, options?: {
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** Local setup is missing or broken: not a git repo, no room joined, unreadable config. */
|
|
15
|
+
export declare class ConfigError extends Error {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class GitError extends Error {
|
|
19
|
+
constructor(message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export declare class UsageError extends Error {
|
|
24
|
+
constructor(message: string);
|
|
25
|
+
}
|
|
26
|
+
export declare function describeError(error: unknown): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The server answered with an error envelope `{ error: { code, message, requestId } }`. */
|
|
2
|
+
export class ApiError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
requestId;
|
|
6
|
+
constructor(status, code, message, requestId) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.requestId = requestId;
|
|
11
|
+
this.name = "ApiError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The server could not be reached, timed out, or returned something that is not a teamroom response. */
|
|
15
|
+
export class NetworkError extends Error {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = "NetworkError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Local setup is missing or broken: not a git repo, no room joined, unreadable config. */
|
|
22
|
+
export class ConfigError extends Error {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "ConfigError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class GitError extends Error {
|
|
29
|
+
constructor(message, options) {
|
|
30
|
+
super(message, options);
|
|
31
|
+
this.name = "GitError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class UsageError extends Error {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "UsageError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function describeError(error) {
|
|
41
|
+
if (error instanceof ApiError) {
|
|
42
|
+
const reference = error.requestId ? ` (request ${error.requestId})` : "";
|
|
43
|
+
return `${error.message}${reference}`;
|
|
44
|
+
}
|
|
45
|
+
if (error instanceof Error)
|
|
46
|
+
return error.message;
|
|
47
|
+
return String(error);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEf,MAAM;IACN,IAAI;IAEJ,SAAS;IAJ3B,YACkB,MAAc,EACd,IAAY,EAC5B,OAAe,EACC,SAAkB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;sBALC,MAAM;oBACN,IAAI;yBAEJ,SAAS;QAGzB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,yGAAyG;AACzG,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,2FAA2F;AAC3F,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,OAAO,GAAG,KAAK,CAAC,OAAO,GAAG,SAAS,EAAE,CAAC;IACxC,CAAC;IACD,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface GitResult {
|
|
2
|
+
stdout: string;
|
|
3
|
+
exitCode: number;
|
|
4
|
+
}
|
|
5
|
+
export type GitRunner = (args: string[], cwd: string) => Promise<GitResult>;
|
|
6
|
+
export declare const runGit: GitRunner;
|
|
7
|
+
export interface WorkingState {
|
|
8
|
+
branch?: string;
|
|
9
|
+
commit?: string;
|
|
10
|
+
/** The ref the changes are measured against, such as origin/main. */
|
|
11
|
+
baseRef?: string;
|
|
12
|
+
/** Files changed on this branch plus uncommitted and untracked files, relative to the repo root. */
|
|
13
|
+
files: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class Git {
|
|
16
|
+
private readonly cwd;
|
|
17
|
+
private readonly run;
|
|
18
|
+
constructor(cwd: string, run?: GitRunner);
|
|
19
|
+
repoRoot(): Promise<string>;
|
|
20
|
+
/** Shared by every worktree of the repo, so one config serves them all. */
|
|
21
|
+
commonDir(): Promise<string>;
|
|
22
|
+
hooksDir(): Promise<string>;
|
|
23
|
+
userName(): Promise<string | undefined>;
|
|
24
|
+
currentBranch(): Promise<string | undefined>;
|
|
25
|
+
headCommit(): Promise<string | undefined>;
|
|
26
|
+
defaultBranchRef(): Promise<string | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Everything this checkout would bring to the default branch: commits since
|
|
29
|
+
* the merge-base, staged and unstaged edits, and untracked files.
|
|
30
|
+
*/
|
|
31
|
+
workingState(): Promise<WorkingState>;
|
|
32
|
+
/** True when `commit` is already part of `ref`. Unknown commits count as not merged. */
|
|
33
|
+
isMergedInto(commit: string, ref: string): Promise<boolean>;
|
|
34
|
+
private lines;
|
|
35
|
+
private optional;
|
|
36
|
+
private required;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Identifies one checkout of one member, so two agents in two worktrees of the
|
|
40
|
+
* same person still warn each other. Readable prefix, hashed suffix for uniqueness.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sessionForRepoRoot(repoRoot: string): string;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { GitError } from "./errors.js";
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
const GIT_TIMEOUT_MS = 10_000;
|
|
8
|
+
const GIT_MAX_BUFFER_BYTES = 16 * 1024 * 1024;
|
|
9
|
+
const SESSION_HASH_LENGTH = 6;
|
|
10
|
+
const SESSION_PREFIX_MAX_LENGTH = 60;
|
|
11
|
+
const DEFAULT_BRANCH_CANDIDATES = ["origin/main", "origin/master", "main", "master"];
|
|
12
|
+
export const runGit = async (args, cwd) => {
|
|
13
|
+
try {
|
|
14
|
+
const { stdout } = await execFileAsync("git", args, {
|
|
15
|
+
cwd,
|
|
16
|
+
timeout: GIT_TIMEOUT_MS,
|
|
17
|
+
maxBuffer: GIT_MAX_BUFFER_BYTES,
|
|
18
|
+
encoding: "utf8",
|
|
19
|
+
});
|
|
20
|
+
return { stdout, exitCode: 0 };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const failure = error;
|
|
24
|
+
if (failure.code === "ENOENT")
|
|
25
|
+
throw new GitError("git is not installed or not on PATH.", { cause: error });
|
|
26
|
+
if (typeof failure.code === "number")
|
|
27
|
+
return { stdout: failure.stdout ?? "", exitCode: failure.code };
|
|
28
|
+
throw new GitError(`git ${args[0] ?? ""} failed: ${failure.message}`, { cause: error });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export class Git {
|
|
32
|
+
cwd;
|
|
33
|
+
run;
|
|
34
|
+
constructor(cwd, run = runGit) {
|
|
35
|
+
this.cwd = cwd;
|
|
36
|
+
this.run = run;
|
|
37
|
+
}
|
|
38
|
+
async repoRoot() {
|
|
39
|
+
return this.required(["rev-parse", "--show-toplevel"], "This is not a git repository.");
|
|
40
|
+
}
|
|
41
|
+
/** Shared by every worktree of the repo, so one config serves them all. */
|
|
42
|
+
async commonDir() {
|
|
43
|
+
const dir = await this.required(["rev-parse", "--git-common-dir"], "This is not a git repository.");
|
|
44
|
+
return path.resolve(this.cwd, dir);
|
|
45
|
+
}
|
|
46
|
+
async hooksDir() {
|
|
47
|
+
const dir = await this.required(["rev-parse", "--git-path", "hooks"], "This is not a git repository.");
|
|
48
|
+
return path.resolve(this.cwd, dir);
|
|
49
|
+
}
|
|
50
|
+
async userName() {
|
|
51
|
+
return (await this.optional(["config", "user.name"])) || undefined;
|
|
52
|
+
}
|
|
53
|
+
async currentBranch() {
|
|
54
|
+
const branch = await this.optional(["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
55
|
+
return branch || undefined;
|
|
56
|
+
}
|
|
57
|
+
async headCommit() {
|
|
58
|
+
return (await this.optional(["rev-parse", "--verify", "--quiet", "HEAD"])) || undefined;
|
|
59
|
+
}
|
|
60
|
+
async defaultBranchRef() {
|
|
61
|
+
const originHead = await this.optional(["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"]);
|
|
62
|
+
const candidates = originHead ? [originHead, ...DEFAULT_BRANCH_CANDIDATES] : DEFAULT_BRANCH_CANDIDATES;
|
|
63
|
+
for (const candidate of candidates) {
|
|
64
|
+
const exists = await this.run(["rev-parse", "--verify", "--quiet", `${candidate}^{commit}`], this.cwd);
|
|
65
|
+
if (exists.exitCode === 0)
|
|
66
|
+
return candidate;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Everything this checkout would bring to the default branch: commits since
|
|
72
|
+
* the merge-base, staged and unstaged edits, and untracked files.
|
|
73
|
+
*/
|
|
74
|
+
async workingState() {
|
|
75
|
+
const [branch, commit, baseRef] = await Promise.all([
|
|
76
|
+
this.currentBranch(),
|
|
77
|
+
this.headCommit(),
|
|
78
|
+
this.defaultBranchRef(),
|
|
79
|
+
]);
|
|
80
|
+
const mergeBase = baseRef && commit ? await this.optional(["merge-base", "HEAD", baseRef]) : "";
|
|
81
|
+
// Paths must be relative to the repo root whatever the cwd or diff.relative setting.
|
|
82
|
+
const diffBase = ["diff", "--name-only", "--no-relative", "-z"];
|
|
83
|
+
const [changed, staged, untracked] = await Promise.all([
|
|
84
|
+
commit ? this.lines([...diffBase, mergeBase || "HEAD"]) : Promise.resolve([]),
|
|
85
|
+
this.lines([...diffBase, "--cached"]),
|
|
86
|
+
this.lines(["ls-files", "--others", "--exclude-standard", "--full-name", "-z"]),
|
|
87
|
+
]);
|
|
88
|
+
const files = [...new Set([...changed, ...staged, ...untracked])].sort();
|
|
89
|
+
return { branch, commit, baseRef: mergeBase ? baseRef : undefined, files };
|
|
90
|
+
}
|
|
91
|
+
/** True when `commit` is already part of `ref`. Unknown commits count as not merged. */
|
|
92
|
+
async isMergedInto(commit, ref) {
|
|
93
|
+
const result = await this.run(["merge-base", "--is-ancestor", commit, ref], this.cwd);
|
|
94
|
+
return result.exitCode === 0;
|
|
95
|
+
}
|
|
96
|
+
async lines(args) {
|
|
97
|
+
const result = await this.run(args, this.cwd);
|
|
98
|
+
if (result.exitCode !== 0)
|
|
99
|
+
return [];
|
|
100
|
+
return result.stdout.split("\0").filter((line) => line.length > 0);
|
|
101
|
+
}
|
|
102
|
+
async optional(args) {
|
|
103
|
+
const result = await this.run(args, this.cwd);
|
|
104
|
+
return result.exitCode === 0 ? result.stdout.trim() : "";
|
|
105
|
+
}
|
|
106
|
+
async required(args, message) {
|
|
107
|
+
const result = await this.run(args, this.cwd);
|
|
108
|
+
const value = result.stdout.trim();
|
|
109
|
+
if (result.exitCode !== 0 || !value)
|
|
110
|
+
throw new GitError(message);
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Identifies one checkout of one member, so two agents in two worktrees of the
|
|
116
|
+
* same person still warn each other. Readable prefix, hashed suffix for uniqueness.
|
|
117
|
+
*/
|
|
118
|
+
export function sessionForRepoRoot(repoRoot) {
|
|
119
|
+
const readable = path
|
|
120
|
+
.basename(repoRoot)
|
|
121
|
+
.replace(/[^A-Za-z0-9._-]/g, "-")
|
|
122
|
+
.slice(0, SESSION_PREFIX_MAX_LENGTH) || "repo";
|
|
123
|
+
const suffix = createHash("sha256").update(repoRoot).digest("hex").slice(0, SESSION_HASH_LENGTH);
|
|
124
|
+
return `${readable}-${suffix}`;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=git.js.map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UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;IACjG,OAAO,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Every point where a checkout's pending changes shift: new commit, branch switch, pull or merge. */
|
|
2
|
+
export declare const HOOK_NAMES: readonly ["post-commit", "post-checkout", "post-merge", "post-rewrite"];
|
|
3
|
+
/** How the hook should launch teamroom when the CLI that installed it still exists on disk. */
|
|
4
|
+
export interface CliLocation {
|
|
5
|
+
node: string;
|
|
6
|
+
script: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Runs in the background and never fails the git command: a teammate without
|
|
10
|
+
* teamroom installed, or an unreachable server, must not block their commits.
|
|
11
|
+
* Prefers the exact CLI that installed the hook, since a local or npx install
|
|
12
|
+
* is not on PATH, and falls back to a global `teamroom`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hookBlock(cli?: CliLocation): string;
|
|
15
|
+
export type HookChange = "installed" | "updated" | "unchanged" | "removed" | "absent";
|
|
16
|
+
/** Appends a marked block, so hooks the repo already has keep working. Re-running refreshes the block. */
|
|
17
|
+
export declare function installHooks(hooksDir: string, cli?: CliLocation): Promise<Record<string, HookChange>>;
|
|
18
|
+
/** Removes only the teamroom block, and the file too when nothing else is left in it. */
|
|
19
|
+
export declare function uninstallHooks(hooksDir: string): Promise<Record<string, HookChange>>;
|
|
20
|
+
export declare function installedHooks(hooksDir: string): Promise<string[]>;
|
|
21
|
+
export declare function removeBlock(content: string): string;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/** Every point where a checkout's pending changes shift: new commit, branch switch, pull or merge. */
|
|
4
|
+
export const HOOK_NAMES = ["post-commit", "post-checkout", "post-merge", "post-rewrite"];
|
|
5
|
+
const BLOCK_START = "# >>> teamroom >>>";
|
|
6
|
+
const BLOCK_END = "# <<< teamroom <<<";
|
|
7
|
+
const SHEBANG = "#!/bin/sh";
|
|
8
|
+
const EXECUTABLE_MODE = 0o755;
|
|
9
|
+
/**
|
|
10
|
+
* Runs in the background and never fails the git command: a teammate without
|
|
11
|
+
* teamroom installed, or an unreachable server, must not block their commits.
|
|
12
|
+
* Prefers the exact CLI that installed the hook, since a local or npx install
|
|
13
|
+
* is not on PATH, and falls back to a global `teamroom`.
|
|
14
|
+
*/
|
|
15
|
+
export function hookBlock(cli) {
|
|
16
|
+
const report = "report --source hook --quiet";
|
|
17
|
+
const pinned = cli
|
|
18
|
+
? [
|
|
19
|
+
`TEAMROOM_NODE=${shellQuote(cli.node)}`,
|
|
20
|
+
`TEAMROOM_SCRIPT=${shellQuote(cli.script)}`,
|
|
21
|
+
'if [ -x "$TEAMROOM_NODE" ] && [ -f "$TEAMROOM_SCRIPT" ]; then',
|
|
22
|
+
` ("$TEAMROOM_NODE" "$TEAMROOM_SCRIPT" ${report} >/dev/null 2>&1 &)`,
|
|
23
|
+
"elif command -v teamroom >/dev/null 2>&1; then",
|
|
24
|
+
]
|
|
25
|
+
: ["if command -v teamroom >/dev/null 2>&1; then"];
|
|
26
|
+
return [BLOCK_START, ...pinned, ` (teamroom ${report} >/dev/null 2>&1 &)`, "fi", BLOCK_END].join("\n");
|
|
27
|
+
}
|
|
28
|
+
function shellQuote(value) {
|
|
29
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
30
|
+
}
|
|
31
|
+
/** Appends a marked block, so hooks the repo already has keep working. Re-running refreshes the block. */
|
|
32
|
+
export async function installHooks(hooksDir, cli) {
|
|
33
|
+
const block = hookBlock(cli);
|
|
34
|
+
await fs.mkdir(hooksDir, { recursive: true });
|
|
35
|
+
const changes = {};
|
|
36
|
+
for (const name of HOOK_NAMES) {
|
|
37
|
+
const file = path.join(hooksDir, name);
|
|
38
|
+
const existing = await readIfExists(file);
|
|
39
|
+
const hadBlock = existing?.includes(BLOCK_START) ?? false;
|
|
40
|
+
const base = existing === undefined ? SHEBANG : removeBlock(existing).trimEnd() || SHEBANG;
|
|
41
|
+
const content = base === SHEBANG ? `${SHEBANG}\n${block}\n` : `${base}\n\n${block}\n`;
|
|
42
|
+
if (content === existing) {
|
|
43
|
+
changes[name] = "unchanged";
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
await fs.writeFile(file, content, "utf8");
|
|
47
|
+
await fs.chmod(file, EXECUTABLE_MODE);
|
|
48
|
+
changes[name] = hadBlock ? "updated" : "installed";
|
|
49
|
+
}
|
|
50
|
+
return changes;
|
|
51
|
+
}
|
|
52
|
+
/** Removes only the teamroom block, and the file too when nothing else is left in it. */
|
|
53
|
+
export async function uninstallHooks(hooksDir) {
|
|
54
|
+
const changes = {};
|
|
55
|
+
for (const name of HOOK_NAMES) {
|
|
56
|
+
const file = path.join(hooksDir, name);
|
|
57
|
+
const existing = await readIfExists(file);
|
|
58
|
+
if (existing === undefined || !existing.includes(BLOCK_START)) {
|
|
59
|
+
changes[name] = "absent";
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const remaining = removeBlock(existing);
|
|
63
|
+
if (remaining.trim() === "" || remaining.trim() === SHEBANG) {
|
|
64
|
+
await fs.rm(file);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
await fs.writeFile(file, remaining, "utf8");
|
|
68
|
+
}
|
|
69
|
+
changes[name] = "removed";
|
|
70
|
+
}
|
|
71
|
+
return changes;
|
|
72
|
+
}
|
|
73
|
+
export async function installedHooks(hooksDir) {
|
|
74
|
+
const found = [];
|
|
75
|
+
for (const name of HOOK_NAMES) {
|
|
76
|
+
if ((await readIfExists(path.join(hooksDir, name)))?.includes(BLOCK_START))
|
|
77
|
+
found.push(name);
|
|
78
|
+
}
|
|
79
|
+
return found;
|
|
80
|
+
}
|
|
81
|
+
export function removeBlock(content) {
|
|
82
|
+
const start = content.indexOf(BLOCK_START);
|
|
83
|
+
const end = content.indexOf(BLOCK_END, start);
|
|
84
|
+
if (start === -1 || end === -1)
|
|
85
|
+
return content;
|
|
86
|
+
const before = content.slice(0, start).trimEnd();
|
|
87
|
+
const after = content.slice(end + BLOCK_END.length).trim();
|
|
88
|
+
return `${[before, after].filter(Boolean).join("\n\n")}\n`;
|
|
89
|
+
}
|
|
90
|
+
async function readIfExists(file) {
|
|
91
|
+
try {
|
|
92
|
+
return await fs.readFile(file, "utf8");
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.code === "ENOENT")
|
|
96
|
+
return undefined;
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/client/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,sGAAsG;AACtG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,CAAU,CAAC;AAElG,MAAM,WAAW,GAAG,oBAAoB,CAAC;AACzC,MAAM,SAAS,GAAG,oBAAoB,CAAC;AACvC,MAAM,OAAO,GAAG,WAAW,CAAC;AAC5B,MAAM,eAAe,GAAG,KAAK,CAAC;AAQ9B;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,GAAiB;IACzC,MAAM,MAAM,GAAG,8BAA8B,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG;QAChB,CAAC,CAAC;YACE,iBAAiB,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACvC,mBAAmB,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC3C,+DAA+D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,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface InviteLink {
|
|
2
|
+
server: string;
|
|
3
|
+
roomId: string;
|
|
4
|
+
inviteCode: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Accepts `localhost:8787` or `https://teamroom.example.com/`, returns a URL
|
|
8
|
+
* without a trailing slash so paths can be appended safely.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeServerUrl(input: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* The invite code lives in the fragment, which browsers never send, so it
|
|
13
|
+
* stays out of server and proxy access logs if someone opens the link.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatInviteLink({ server, roomId, inviteCode }: InviteLink): string;
|
|
16
|
+
export declare function parseInviteLink(link: string): InviteLink;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ROOM_ID_PATTERN } from "../core/schemas.js";
|
|
2
|
+
import { UsageError } from "./errors.js";
|
|
3
|
+
const JOIN_SEGMENT = "/join/";
|
|
4
|
+
const DEFAULT_SCHEME = "http://";
|
|
5
|
+
/**
|
|
6
|
+
* Accepts `localhost:8787` or `https://teamroom.example.com/`, returns a URL
|
|
7
|
+
* without a trailing slash so paths can be appended safely.
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeServerUrl(input) {
|
|
10
|
+
const trimmed = input.trim();
|
|
11
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `${DEFAULT_SCHEME}${trimmed}`;
|
|
12
|
+
let url;
|
|
13
|
+
try {
|
|
14
|
+
url = new URL(withScheme);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new UsageError(`"${input}" is not a valid server URL.`);
|
|
18
|
+
}
|
|
19
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
20
|
+
throw new UsageError("The server URL must start with http:// or https://.");
|
|
21
|
+
}
|
|
22
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The invite code lives in the fragment, which browsers never send, so it
|
|
26
|
+
* stays out of server and proxy access logs if someone opens the link.
|
|
27
|
+
*/
|
|
28
|
+
export function formatInviteLink({ server, roomId, inviteCode }) {
|
|
29
|
+
return `${normalizeServerUrl(server)}${JOIN_SEGMENT}${roomId}#${inviteCode}`;
|
|
30
|
+
}
|
|
31
|
+
export function parseInviteLink(link) {
|
|
32
|
+
const invalid = new UsageError("That does not look like a teamroom invite link. It should look like https://server/join/room_...#tri_...");
|
|
33
|
+
let url;
|
|
34
|
+
try {
|
|
35
|
+
url = new URL(link.trim());
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw invalid;
|
|
39
|
+
}
|
|
40
|
+
const joinAt = url.pathname.lastIndexOf(JOIN_SEGMENT);
|
|
41
|
+
const roomId = joinAt === -1 ? "" : url.pathname.slice(joinAt + JOIN_SEGMENT.length);
|
|
42
|
+
const inviteCode = decodeURIComponent(url.hash.slice(1));
|
|
43
|
+
if (!ROOM_ID_PATTERN.test(roomId) || !inviteCode)
|
|
44
|
+
throw invalid;
|
|
45
|
+
return {
|
|
46
|
+
server: normalizeServerUrl(`${url.origin}${url.pathname.slice(0, joinAt)}`),
|
|
47
|
+
roomId,
|
|
48
|
+
inviteCode,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=invite-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invite-link.js","sourceRoot":"","sources":["../../src/client/invite-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAC9B,MAAM,cAAc,GAAG,SAAS,CAAC;AAQjC;;;GAGG;AACH,MAAM,UAAU,kBAA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AY,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACrF,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU;QAAE,MAAM,OAAO,CAAC;IAChE,OAAO;QACL,MAAM,EAAE,kBAAkB,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;QAC3E,MAAM;QACN,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Project-scoped MCP config read by Claude Code. Meant to be committed so the whole team gets it. */
|
|
2
|
+
export declare const MCP_CONFIG_FILE = ".mcp.json";
|
|
3
|
+
export declare const MCP_SERVER_NAME = "teamroom";
|
|
4
|
+
export declare const CODEX_SNIPPET = "[mcp_servers.teamroom]\ncommand = \"teamroom\"\nargs = [\"mcp\"]";
|
|
5
|
+
export declare const AGENT_INSTRUCTION: string;
|
|
6
|
+
export type McpConfigChange = "created" | "added" | "unchanged";
|
|
7
|
+
/** Adds the teamroom server to `.mcp.json`, keeping every other server and setting already there. */
|
|
8
|
+
export declare function installMcpConfig(repoRoot: string): Promise<{
|
|
9
|
+
file: string;
|
|
10
|
+
change: McpConfigChange;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function mcpConfigHasTeamroom(repoRoot: string): Promise<boolean>;
|