teamroom 0.1.1 → 0.2.1
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/README.md +149 -70
- package/dist/cli/index.js +202 -106
- package/dist/cli/index.js.map +1 -1
- package/dist/client/agents-md.d.ts +14 -0
- package/dist/client/agents-md.js +53 -0
- package/dist/client/agents-md.js.map +1 -0
- package/dist/client/api-client.d.ts +4 -0
- package/dist/client/backend.d.ts +60 -0
- package/dist/client/backend.js +103 -0
- package/dist/client/backend.js.map +1 -0
- package/dist/client/claude-events.d.ts +18 -0
- package/dist/client/claude-events.js +172 -0
- package/dist/client/claude-events.js.map +1 -0
- package/dist/client/claude-hook.d.ts +19 -12
- package/dist/client/claude-hook.js +90 -48
- package/dist/client/claude-hook.js.map +1 -1
- package/dist/client/config.d.ts +13 -4
- package/dist/client/config.js +25 -6
- package/dist/client/config.js.map +1 -1
- package/dist/client/doctor.js +60 -7
- package/dist/client/doctor.js.map +1 -1
- package/dist/client/git.d.ts +0 -2
- package/dist/client/git.js +2 -6
- package/dist/client/git.js.map +1 -1
- package/dist/client/ignore.d.ts +12 -0
- package/dist/client/ignore.js +96 -0
- package/dist/client/ignore.js.map +1 -0
- package/dist/client/invite-link.d.ts +3 -1
- package/dist/client/invite-link.js +19 -4
- package/dist/client/invite-link.js.map +1 -1
- package/dist/client/mcp-config.d.ts +39 -6
- package/dist/client/mcp-config.js +81 -26
- package/dist/client/mcp-config.js.map +1 -1
- package/dist/client/workspace.d.ts +34 -7
- package/dist/client/workspace.js +81 -39
- package/dist/client/workspace.js.map +1 -1
- package/dist/core/agents.d.ts +6 -0
- package/dist/core/agents.js +7 -0
- package/dist/core/agents.js.map +1 -1
- package/dist/core/overlap.d.ts +12 -3
- package/dist/core/overlap.js +51 -8
- package/dist/core/overlap.js.map +1 -1
- package/dist/core/room.d.ts +3 -1
- package/dist/core/room.js +37 -1
- package/dist/core/room.js.map +1 -1
- package/dist/core/schemas.d.ts +9 -0
- package/dist/core/schemas.js +10 -2
- package/dist/core/schemas.js.map +1 -1
- package/dist/core/types.d.ts +7 -1
- package/dist/dashboard/Dashboard.d.ts +2 -1
- package/dist/dashboard/Dashboard.js +3 -3
- package/dist/dashboard/Dashboard.js.map +1 -1
- package/dist/dashboard/model.d.ts +10 -3
- package/dist/dashboard/model.js +38 -7
- package/dist/dashboard/model.js.map +1 -1
- package/dist/dashboard/run.js +2 -2
- package/dist/dashboard/run.js.map +1 -1
- package/dist/mcp/auto-report.d.ts +43 -0
- package/dist/mcp/auto-report.js +118 -0
- package/dist/mcp/auto-report.js.map +1 -0
- package/dist/mcp/server.d.ts +18 -4
- package/dist/mcp/server.js +44 -29
- package/dist/mcp/server.js.map +1 -1
- package/dist/server/app.js +7 -9
- package/dist/server/app.js.map +1 -1
- package/dist/store/file-store.js +1 -1
- package/dist/store/file-store.js.map +1 -1
- package/package.json +9 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents-md.js","sourceRoot":"","sources":["../../src/client/agents-md.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAC9C,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;2HAOyF,CAAC;AAI5H,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB;IACpD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,GAAG,WAAW,KAAK,kBAAkB,KAAK,SAAS,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,YAAY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AAC,WAAW,CAAC,IAAI,KAAK,CAAC;AACnG,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,IAAY;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACzE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -21,6 +21,7 @@ declare const createdRoomSchema: z.ZodObject<{
|
|
|
21
21
|
commit: "commit";
|
|
22
22
|
edit: "edit";
|
|
23
23
|
note: "note";
|
|
24
|
+
presence: "presence";
|
|
24
25
|
wip: "wip";
|
|
25
26
|
}>;
|
|
26
27
|
source: z.ZodEnum<{
|
|
@@ -29,6 +30,7 @@ declare const createdRoomSchema: z.ZodObject<{
|
|
|
29
30
|
human: "human";
|
|
30
31
|
}>;
|
|
31
32
|
agent: z.ZodOptional<z.ZodString>;
|
|
33
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
32
34
|
text: z.ZodString;
|
|
33
35
|
branch: z.ZodOptional<z.ZodString>;
|
|
34
36
|
commit: z.ZodOptional<z.ZodString>;
|
|
@@ -62,6 +64,7 @@ declare const joinedRoomSchema: z.ZodObject<{
|
|
|
62
64
|
commit: "commit";
|
|
63
65
|
edit: "edit";
|
|
64
66
|
note: "note";
|
|
67
|
+
presence: "presence";
|
|
65
68
|
wip: "wip";
|
|
66
69
|
}>;
|
|
67
70
|
source: z.ZodEnum<{
|
|
@@ -70,6 +73,7 @@ declare const joinedRoomSchema: z.ZodObject<{
|
|
|
70
73
|
human: "human";
|
|
71
74
|
}>;
|
|
72
75
|
agent: z.ZodOptional<z.ZodString>;
|
|
76
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
73
77
|
text: z.ZodString;
|
|
74
78
|
branch: z.ZodOptional<z.ZodString>;
|
|
75
79
|
commit: z.ZodOptional<z.ZodString>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PostActivityRequest } from "../core/schemas.js";
|
|
2
|
+
import type { Activity, FileOverlap, RoomView } from "../core/types.js";
|
|
3
|
+
import type { ApiClient } from "./api-client.js";
|
|
4
|
+
/**
|
|
5
|
+
* - `local`: every checkout of this repo on this machine, through a file in the git common dir. No server.
|
|
6
|
+
* - `shared`: a room on a teamroom server, so teammates on other machines are included.
|
|
7
|
+
*/
|
|
8
|
+
export type BackendMode = "local" | "shared";
|
|
9
|
+
export interface OverlapQuery {
|
|
10
|
+
files: string[];
|
|
11
|
+
session?: string;
|
|
12
|
+
sinceHours?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Where a workspace reads and writes activity. Commands never need to know which one they got. */
|
|
15
|
+
export interface RoomBackend {
|
|
16
|
+
readonly mode: BackendMode;
|
|
17
|
+
getRoom(limit?: number): Promise<{
|
|
18
|
+
room: RoomView;
|
|
19
|
+
me: string;
|
|
20
|
+
}>;
|
|
21
|
+
postActivity(input: PostActivityRequest): Promise<Activity>;
|
|
22
|
+
findOverlaps(query: OverlapQuery): Promise<FileOverlap[]>;
|
|
23
|
+
}
|
|
24
|
+
export declare class SharedBackend implements RoomBackend {
|
|
25
|
+
private readonly client;
|
|
26
|
+
private readonly roomId;
|
|
27
|
+
readonly mode = "shared";
|
|
28
|
+
constructor(client: ApiClient, roomId: string);
|
|
29
|
+
getRoom(limit?: number): Promise<{
|
|
30
|
+
room: RoomView;
|
|
31
|
+
me: string;
|
|
32
|
+
}>;
|
|
33
|
+
postActivity(input: PostActivityRequest): Promise<Activity>;
|
|
34
|
+
findOverlaps(query: OverlapQuery): Promise<FileOverlap[]>;
|
|
35
|
+
}
|
|
36
|
+
/** Fixed, because a repo has exactly one local room. Matches the room id pattern the store validates. */
|
|
37
|
+
export declare const LOCAL_ROOM_ID = "room_worktrees-shared";
|
|
38
|
+
export declare const LOCAL_STORE_DIR = "teamroom";
|
|
39
|
+
export declare function localStoreDir(gitCommonDir: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Keeps the room in the git common dir, which every worktree of the repo
|
|
42
|
+
* shares, so parallel agents on one machine see each other with no server,
|
|
43
|
+
* account or network. The file store's lock makes concurrent hooks safe.
|
|
44
|
+
*/
|
|
45
|
+
export declare class LocalBackend implements RoomBackend {
|
|
46
|
+
private readonly member;
|
|
47
|
+
private readonly roomName;
|
|
48
|
+
readonly mode = "local";
|
|
49
|
+
private readonly store;
|
|
50
|
+
constructor(gitCommonDir: string, member: string, roomName: string);
|
|
51
|
+
getRoom(limit?: number): Promise<{
|
|
52
|
+
room: RoomView;
|
|
53
|
+
me: string;
|
|
54
|
+
}>;
|
|
55
|
+
postActivity(input: PostActivityRequest): Promise<Activity>;
|
|
56
|
+
findOverlaps(query: OverlapQuery): Promise<FileOverlap[]>;
|
|
57
|
+
private emptyRoom;
|
|
58
|
+
/** Creates the room on first write. Two hooks racing to create it both end up updating the same one. */
|
|
59
|
+
private mutate;
|
|
60
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { findOverlaps } from "../core/overlap.js";
|
|
3
|
+
import { addMember, appendActivity, createRoom, DEFAULT_ACTIVITY_LIMIT, toRoomView } from "../core/room.js";
|
|
4
|
+
import { overlapRequestSchema, postActivityRequestSchema } from "../core/schemas.js";
|
|
5
|
+
import { FileRoomStore } from "../store/file-store.js";
|
|
6
|
+
import { RoomAlreadyExistsError, RoomNotFoundError } from "../store/store.js";
|
|
7
|
+
export class SharedBackend {
|
|
8
|
+
client;
|
|
9
|
+
roomId;
|
|
10
|
+
mode = "shared";
|
|
11
|
+
constructor(client, roomId) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.roomId = roomId;
|
|
14
|
+
}
|
|
15
|
+
async getRoom(limit) {
|
|
16
|
+
return this.client.getRoom(this.roomId, limit);
|
|
17
|
+
}
|
|
18
|
+
async postActivity(input) {
|
|
19
|
+
return this.client.postActivity(this.roomId, input);
|
|
20
|
+
}
|
|
21
|
+
async findOverlaps(query) {
|
|
22
|
+
return this.client.findOverlaps(this.roomId, query);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Fixed, because a repo has exactly one local room. Matches the room id pattern the store validates. */
|
|
26
|
+
export const LOCAL_ROOM_ID = "room_worktrees-shared";
|
|
27
|
+
export const LOCAL_STORE_DIR = "teamroom";
|
|
28
|
+
export function localStoreDir(gitCommonDir) {
|
|
29
|
+
return path.join(gitCommonDir, LOCAL_STORE_DIR);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Keeps the room in the git common dir, which every worktree of the repo
|
|
33
|
+
* shares, so parallel agents on one machine see each other with no server,
|
|
34
|
+
* account or network. The file store's lock makes concurrent hooks safe.
|
|
35
|
+
*/
|
|
36
|
+
export class LocalBackend {
|
|
37
|
+
member;
|
|
38
|
+
roomName;
|
|
39
|
+
mode = "local";
|
|
40
|
+
store;
|
|
41
|
+
constructor(gitCommonDir, member, roomName) {
|
|
42
|
+
this.member = member;
|
|
43
|
+
this.roomName = roomName;
|
|
44
|
+
this.store = new FileRoomStore(localStoreDir(gitCommonDir));
|
|
45
|
+
}
|
|
46
|
+
async getRoom(limit = DEFAULT_ACTIVITY_LIMIT) {
|
|
47
|
+
const room = (await this.store.get(LOCAL_ROOM_ID)) ?? this.emptyRoom();
|
|
48
|
+
return { room: toRoomView(withMember(room, this.member), limit), me: this.member };
|
|
49
|
+
}
|
|
50
|
+
async postActivity(input) {
|
|
51
|
+
const parsed = postActivityRequestSchema.parse(input);
|
|
52
|
+
let created;
|
|
53
|
+
await this.mutate((room) => {
|
|
54
|
+
const result = appendActivity(withMember(room, this.member), this.member, parsed);
|
|
55
|
+
created = result.entry;
|
|
56
|
+
return result.room;
|
|
57
|
+
});
|
|
58
|
+
if (!created)
|
|
59
|
+
throw new Error("The activity was not recorded.");
|
|
60
|
+
return created;
|
|
61
|
+
}
|
|
62
|
+
async findOverlaps(query) {
|
|
63
|
+
const parsed = overlapRequestSchema.parse(query);
|
|
64
|
+
const room = await this.store.get(LOCAL_ROOM_ID);
|
|
65
|
+
if (!room)
|
|
66
|
+
return [];
|
|
67
|
+
return findOverlaps({
|
|
68
|
+
activity: room.activity,
|
|
69
|
+
files: parsed.files,
|
|
70
|
+
member: this.member,
|
|
71
|
+
session: parsed.session,
|
|
72
|
+
sinceHours: parsed.sinceHours,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
emptyRoom() {
|
|
76
|
+
return { ...createRoom(this.roomName, this.member).room, id: LOCAL_ROOM_ID };
|
|
77
|
+
}
|
|
78
|
+
/** Creates the room on first write. Two hooks racing to create it both end up updating the same one. */
|
|
79
|
+
async mutate(change) {
|
|
80
|
+
try {
|
|
81
|
+
return await this.store.update(LOCAL_ROOM_ID, change);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (!(error instanceof RoomNotFoundError))
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
await this.store.create(this.emptyRoom());
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (!(error instanceof RoomAlreadyExistsError))
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
return this.store.update(LOCAL_ROOM_ID, change);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** A local room has no invites: whoever writes from this machine is a member. */
|
|
98
|
+
function withMember(room, member) {
|
|
99
|
+
if (room.members.some((existing) => existing.name === member))
|
|
100
|
+
return room;
|
|
101
|
+
return addMember(room, member).room;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/client/backend.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC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AAO,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Workspace } from "./workspace.js";
|
|
2
|
+
export declare const CLAUDE_AGENT_ID = "claude-code";
|
|
3
|
+
export type ClaudeHookPayload = {
|
|
4
|
+
event: "SessionStart";
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
cwd?: string;
|
|
7
|
+
} | {
|
|
8
|
+
event: "PreToolUse" | "PostToolUse";
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
tool: string;
|
|
12
|
+
file: string;
|
|
13
|
+
};
|
|
14
|
+
/** Returns what teamroom cares about in a hook payload, or null when it is none of its business. */
|
|
15
|
+
export declare function parseClaudeHookPayload(rawPayload: string): ClaudeHookPayload | null;
|
|
16
|
+
/** What the hook prints on stdout. Claude Code reads it as JSON; an empty string means "carry on". */
|
|
17
|
+
export type HookOutput = string;
|
|
18
|
+
export declare function handleClaudeHook(payload: ClaudeHookPayload, workspace: Workspace): Promise<HookOutput>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { overlapSignature } from "../core/overlap.js";
|
|
6
|
+
import { buildDashboard } from "../dashboard/model.js";
|
|
7
|
+
import { localStoreDir } from "./backend.js";
|
|
8
|
+
import { CLAUDE_EDIT_TOOLS } from "./claude-hook.js";
|
|
9
|
+
import { checkOverlap, formatAge, formatOverlaps, isOutsideRepo, reportEdit, toRepoPath, } from "./workspace.js";
|
|
10
|
+
export const CLAUDE_AGENT_ID = "claude-code";
|
|
11
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
12
|
+
/** Sessions quieter than this are old news, not something a new session needs to hear about. */
|
|
13
|
+
const BRIEFING_WINDOW_MS = 24 * HOUR_MS;
|
|
14
|
+
const BRIEFING_MAX_SESSIONS = 8;
|
|
15
|
+
const BRIEFING_MAX_FILES = 8;
|
|
16
|
+
const BRIEFING_ACTIVITY_LIMIT = 300;
|
|
17
|
+
const WARNING_STATE_DIR = "claude-warnings";
|
|
18
|
+
/** Warning state is per Claude session. Files older than this belong to sessions long gone. */
|
|
19
|
+
const WARNING_STATE_MAX_AGE_MS = 7 * 24 * HOUR_MS;
|
|
20
|
+
const payloadSchema = z.object({
|
|
21
|
+
// Older installs only registered PostToolUse, whose payloads are handled the same way.
|
|
22
|
+
hook_event_name: z.string().default("PostToolUse"),
|
|
23
|
+
session_id: z.string().optional(),
|
|
24
|
+
cwd: z.string().optional(),
|
|
25
|
+
tool_name: z.string().optional(),
|
|
26
|
+
tool_input: z
|
|
27
|
+
.object({
|
|
28
|
+
file_path: z.string().optional(),
|
|
29
|
+
notebook_path: z.string().optional(),
|
|
30
|
+
})
|
|
31
|
+
.loose()
|
|
32
|
+
.optional(),
|
|
33
|
+
});
|
|
34
|
+
/** Returns what teamroom cares about in a hook payload, or null when it is none of its business. */
|
|
35
|
+
export function parseClaudeHookPayload(rawPayload) {
|
|
36
|
+
let json;
|
|
37
|
+
try {
|
|
38
|
+
json = JSON.parse(rawPayload);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const parsed = payloadSchema.safeParse(json);
|
|
44
|
+
if (!parsed.success)
|
|
45
|
+
return null;
|
|
46
|
+
const { hook_event_name: event, session_id: sessionId, cwd, tool_name: tool, tool_input: input } = parsed.data;
|
|
47
|
+
if (event === "SessionStart")
|
|
48
|
+
return { event, sessionId, cwd };
|
|
49
|
+
if (event !== "PreToolUse" && event !== "PostToolUse")
|
|
50
|
+
return null;
|
|
51
|
+
if (!tool || !CLAUDE_EDIT_TOOLS.includes(tool))
|
|
52
|
+
return null;
|
|
53
|
+
const file = input?.file_path ?? input?.notebook_path;
|
|
54
|
+
return file ? { event, sessionId, cwd, tool, file } : null;
|
|
55
|
+
}
|
|
56
|
+
export async function handleClaudeHook(payload, workspace) {
|
|
57
|
+
switch (payload.event) {
|
|
58
|
+
case "SessionStart":
|
|
59
|
+
return sessionBriefing(workspace);
|
|
60
|
+
case "PreToolUse":
|
|
61
|
+
return guardEdit(workspace, payload.file, payload.sessionId);
|
|
62
|
+
case "PostToolUse":
|
|
63
|
+
await reportEdit(workspace, { file: payload.file, agent: CLAUDE_AGENT_ID });
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Tells a new Claude session who else is working in the repo and on what, so
|
|
69
|
+
* it can plan around them before it touches anything.
|
|
70
|
+
*/
|
|
71
|
+
async function sessionBriefing(workspace) {
|
|
72
|
+
const { room, me } = await workspace.backend.getRoom(BRIEFING_ACTIVITY_LIMIT);
|
|
73
|
+
const now = new Date();
|
|
74
|
+
const others = buildDashboard(room, me, now, workspace.isIgnored)
|
|
75
|
+
.members.flatMap((member) => member.sessions)
|
|
76
|
+
.filter((session) => !(session.member === workspace.member && session.session === workspace.session))
|
|
77
|
+
.filter((session) => now.getTime() - Date.parse(session.lastSeen) <= BRIEFING_WINDOW_MS)
|
|
78
|
+
.filter((session) => session.files.length > 0)
|
|
79
|
+
.slice(0, BRIEFING_MAX_SESSIONS);
|
|
80
|
+
const lines = [
|
|
81
|
+
"teamroom is on in this repo: other checkouts and their agents share what they are changing.",
|
|
82
|
+
'When you start a task, announce your plan and the files you expect to touch with the `teamroom_post_note` tool (or `teamroom note "<plan>" --files a.ts,b.ts`).',
|
|
83
|
+
];
|
|
84
|
+
if (others.length === 0) {
|
|
85
|
+
lines.push("No other session is changing files right now.");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
lines.push("", `Other sessions changing files right now (${others.length}):`, ...others.map(describeSession));
|
|
89
|
+
lines.push("", "Avoid these files unless the task needs them. If it does, tell the user who else is in them before editing.");
|
|
90
|
+
}
|
|
91
|
+
return JSON.stringify({ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: lines.join("\n") } });
|
|
92
|
+
}
|
|
93
|
+
function describeSession(session) {
|
|
94
|
+
const where = [session.session, session.branch && `on ${session.branch}`].filter(Boolean).join(" ");
|
|
95
|
+
const shown = session.files.slice(0, BRIEFING_MAX_FILES).join(", ");
|
|
96
|
+
const more = session.files.length > BRIEFING_MAX_FILES ? ` (+${session.files.length - BRIEFING_MAX_FILES} more)` : "";
|
|
97
|
+
return `- ${session.member} in ${where}, ${formatAge(session.lastSeen)}: ${session.doing}\n files: ${shown}${more}`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Pauses an edit once when another session is changing the same file, with
|
|
101
|
+
* the details, so Claude can tell the user or adjust. Retrying the same edit
|
|
102
|
+
* goes through: teamroom informs, it never blocks work for good. Someone new
|
|
103
|
+
* in the file, or a new plan for it, pauses again; more edits from the same
|
|
104
|
+
* session do not.
|
|
105
|
+
*/
|
|
106
|
+
async function guardEdit(workspace, file, claudeSessionId) {
|
|
107
|
+
const repoPath = toRepoPath(workspace, file);
|
|
108
|
+
if (isOutsideRepo(repoPath) || workspace.isIgnored(repoPath))
|
|
109
|
+
return "";
|
|
110
|
+
const { overlaps } = await checkOverlap(workspace, { files: [repoPath] });
|
|
111
|
+
if (overlaps.length === 0)
|
|
112
|
+
return "";
|
|
113
|
+
const signature = overlapSignature(overlaps.flatMap((overlap) => overlap.touchedBy));
|
|
114
|
+
const state = new WarningState(workspace.commonDir, claudeSessionId);
|
|
115
|
+
if ((await state.lastWarned(repoPath)) === signature)
|
|
116
|
+
return "";
|
|
117
|
+
await state.remember(repoPath, signature);
|
|
118
|
+
const reason = [
|
|
119
|
+
`teamroom: ${repoPath} is also being changed in another checkout:`,
|
|
120
|
+
formatOverlaps(overlaps),
|
|
121
|
+
"",
|
|
122
|
+
"This edit was paused once so you can decide. If it is still the right move, retry the same edit and it will go through.",
|
|
123
|
+
"Otherwise tell the user who else is in this file, or do other parts of the task first.",
|
|
124
|
+
].join("\n");
|
|
125
|
+
return JSON.stringify({
|
|
126
|
+
hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: reason },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** Which overlaps a Claude session was already told about, one small file per session. */
|
|
130
|
+
class WarningState {
|
|
131
|
+
file;
|
|
132
|
+
constructor(gitCommonDir, claudeSessionId) {
|
|
133
|
+
const dir = path.join(localStoreDir(gitCommonDir), WARNING_STATE_DIR);
|
|
134
|
+
// Without a session id there is nothing to remember against, so every overlap pauses.
|
|
135
|
+
this.file = claudeSessionId
|
|
136
|
+
? path.join(dir, `${createHash("sha256").update(claudeSessionId).digest("hex").slice(0, 32)}.json`)
|
|
137
|
+
: undefined;
|
|
138
|
+
}
|
|
139
|
+
async lastWarned(repoPath) {
|
|
140
|
+
return (await this.read())[repoPath];
|
|
141
|
+
}
|
|
142
|
+
async remember(repoPath, signature) {
|
|
143
|
+
if (!this.file)
|
|
144
|
+
return;
|
|
145
|
+
const next = { ...(await this.read()), [repoPath]: signature };
|
|
146
|
+
await fs.mkdir(path.dirname(this.file), { recursive: true });
|
|
147
|
+
await fs.writeFile(this.file, JSON.stringify(next), { encoding: "utf8", mode: 0o600 });
|
|
148
|
+
await pruneOldStates(path.dirname(this.file));
|
|
149
|
+
}
|
|
150
|
+
async read() {
|
|
151
|
+
if (!this.file)
|
|
152
|
+
return {};
|
|
153
|
+
try {
|
|
154
|
+
const parsed = JSON.parse(await fs.readFile(this.file, "utf8"));
|
|
155
|
+
return z.record(z.string(), z.string()).parse(parsed);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function pruneOldStates(dir) {
|
|
163
|
+
const cutoff = Date.now() - WARNING_STATE_MAX_AGE_MS;
|
|
164
|
+
const names = await fs.readdir(dir).catch(() => []);
|
|
165
|
+
await Promise.all(names.map(async (name) => {
|
|
166
|
+
const file = path.join(dir, name);
|
|
167
|
+
const stats = await fs.stat(file).catch(() => undefined);
|
|
168
|
+
if (stats && stats.mtimeMs < cutoff)
|
|
169
|
+
await fs.rm(file, { force: true });
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=claude-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-events.js","sourceRoot":"","sources":["../../src/client/claude-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAuB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,YAAY,EACZ,SAAS,EACT,cAAc,EACd,aAAa,EACb,UAAU,EACV,UAAU,GAEX,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAE7C,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/B,gGAAgG;AAChG,MAAM,kBAAkB,GAAG,EAAE,GAAG,OAAO,CAAC;AACxC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,+FAA+F;AAC/F,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC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C,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,GAAG,MAAM;YAAE,MAAM,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code runs
|
|
3
|
-
*
|
|
2
|
+
* Claude Code runs hooks at fixed points and writes a JSON payload to the
|
|
3
|
+
* hook's stdin. teamroom registers one command for three of them:
|
|
4
|
+
* - SessionStart: tell the new session what other sessions are changing.
|
|
5
|
+
* - PreToolUse on edits: pause an edit once when someone else is in that file.
|
|
6
|
+
* - PostToolUse on edits: share the edited file right away.
|
|
4
7
|
* https://code.claude.com/docs/en/hooks
|
|
5
8
|
*/
|
|
6
9
|
export declare const CLAUDE_EDIT_TOOLS: readonly ["Edit", "Write", "MultiEdit", "NotebookEdit"];
|
|
7
10
|
export declare const CLAUDE_HOOK_MATCHER: string;
|
|
11
|
+
export declare const CLAUDE_HOOK_EVENTS: readonly ["SessionStart", "PreToolUse", "PostToolUse"];
|
|
12
|
+
export type ClaudeHookEvent = (typeof CLAUDE_HOOK_EVENTS)[number];
|
|
8
13
|
export declare const CLAUDE_SETTINGS_FILE: string;
|
|
9
14
|
/**
|
|
10
15
|
* Prefers the exact CLI that installed the hook, since an npx or local install
|
|
@@ -15,26 +20,28 @@ export declare function claudeHookCommand(cli?: {
|
|
|
15
20
|
node: string;
|
|
16
21
|
script: string;
|
|
17
22
|
}): string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function parseClaudeEdit(rawPayload: string): ClaudeEdit | null;
|
|
23
|
+
/**
|
|
24
|
+
* teamroom's own tools only read the room or post a short note, so asking
|
|
25
|
+
* before each call just teaches people to click through, and headless runs
|
|
26
|
+
* deny them outright. Nothing else is pre-approved.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CLAUDE_ALLOWED_TOOLS: string[];
|
|
25
29
|
export type ClaudeHookChange = "installed" | "unchanged" | "removed" | "absent";
|
|
26
30
|
/**
|
|
27
|
-
* Adds the
|
|
31
|
+
* Adds the teamroom hooks to `.claude/settings.local.json`, which Claude Code
|
|
28
32
|
* treats as personal and does not commit. Other settings and hooks are kept.
|
|
29
33
|
*/
|
|
30
|
-
export declare function
|
|
34
|
+
export declare function installClaudeHooks(repoRoot: string, cli?: {
|
|
31
35
|
node: string;
|
|
32
36
|
script: string;
|
|
33
37
|
}): Promise<{
|
|
34
38
|
change: ClaudeHookChange;
|
|
35
39
|
file: string;
|
|
36
40
|
}>;
|
|
37
|
-
export declare function
|
|
41
|
+
export declare function rememberClaudeHooksWanted(storeDir: string, wanted: boolean): Promise<void>;
|
|
42
|
+
export declare function claudeHooksWanted(storeDir: string): Promise<boolean>;
|
|
43
|
+
export declare function claudeHooksInstalled(repoRoot: string): Promise<ClaudeHookEvent[]>;
|
|
44
|
+
export declare function uninstallClaudeHooks(repoRoot: string): Promise<{
|
|
38
45
|
change: ClaudeHookChange;
|
|
39
46
|
file: string;
|
|
40
47
|
}>;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { z } from "zod";
|
|
4
3
|
/**
|
|
5
|
-
* Claude Code runs
|
|
6
|
-
*
|
|
4
|
+
* Claude Code runs hooks at fixed points and writes a JSON payload to the
|
|
5
|
+
* hook's stdin. teamroom registers one command for three of them:
|
|
6
|
+
* - SessionStart: tell the new session what other sessions are changing.
|
|
7
|
+
* - PreToolUse on edits: pause an edit once when someone else is in that file.
|
|
8
|
+
* - PostToolUse on edits: share the edited file right away.
|
|
7
9
|
* https://code.claude.com/docs/en/hooks
|
|
8
10
|
*/
|
|
9
11
|
export const CLAUDE_EDIT_TOOLS = ["Edit", "Write", "MultiEdit", "NotebookEdit"];
|
|
10
12
|
export const CLAUDE_HOOK_MATCHER = CLAUDE_EDIT_TOOLS.join("|");
|
|
13
|
+
export const CLAUDE_HOOK_EVENTS = ["SessionStart", "PreToolUse", "PostToolUse"];
|
|
11
14
|
export const CLAUDE_SETTINGS_FILE = path.join(".claude", "settings.local.json");
|
|
12
15
|
const CLAUDE_HOOK_TIMEOUT_SECONDS = 10;
|
|
13
16
|
const HOOK_MARKER = "teamroom claude-hook";
|
|
@@ -27,35 +30,14 @@ export function claudeHookCommand(cli) {
|
|
|
27
30
|
function shellQuote(value) {
|
|
28
31
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.loose()
|
|
39
|
-
.optional(),
|
|
40
|
-
});
|
|
41
|
-
/** Returns the edited file from a PostToolUse payload, or null when the payload is not a file edit. */
|
|
42
|
-
export function parseClaudeEdit(rawPayload) {
|
|
43
|
-
let json;
|
|
44
|
-
try {
|
|
45
|
-
json = JSON.parse(rawPayload);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
const parsed = payloadSchema.safeParse(json);
|
|
51
|
-
if (!parsed.success)
|
|
52
|
-
return null;
|
|
53
|
-
const { cwd, tool_name: tool, tool_input: input } = parsed.data;
|
|
54
|
-
if (!CLAUDE_EDIT_TOOLS.includes(tool))
|
|
55
|
-
return null;
|
|
56
|
-
const file = input?.file_path ?? input?.notebook_path;
|
|
57
|
-
return file ? { cwd, tool, file } : null;
|
|
58
|
-
}
|
|
33
|
+
/**
|
|
34
|
+
* teamroom's own tools only read the room or post a short note, so asking
|
|
35
|
+
* before each call just teaches people to click through, and headless runs
|
|
36
|
+
* deny them outright. Nothing else is pre-approved.
|
|
37
|
+
*/
|
|
38
|
+
export const CLAUDE_ALLOWED_TOOLS = ["mcp__teamroom", "Bash(teamroom check:*)", "Bash(teamroom note:*)"];
|
|
39
|
+
/** Marks, in the shared git dir, that this repo wants Claude Code hooks, so new worktrees get them too. */
|
|
40
|
+
const CLAUDE_WANTED_FILE = "claude-hooks-wanted";
|
|
59
41
|
function isTeamroomGroup(group) {
|
|
60
42
|
return group.hooks?.some((hook) => hook.command?.includes(HOOK_MARKER)) ?? false;
|
|
61
43
|
}
|
|
@@ -83,39 +65,99 @@ async function writeSettings(file, settings) {
|
|
|
83
65
|
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
84
66
|
await fs.writeFile(file, `${JSON.stringify(settings, null, 2)}\n`, "utf8");
|
|
85
67
|
}
|
|
68
|
+
function wantedGroup(event, command) {
|
|
69
|
+
const hooks = [{ type: "command", command, timeout: CLAUDE_HOOK_TIMEOUT_SECONDS }];
|
|
70
|
+
// SessionStart has no tool to match, so it runs for every session start.
|
|
71
|
+
return event === "SessionStart" ? { hooks } : { matcher: CLAUDE_HOOK_MATCHER, hooks };
|
|
72
|
+
}
|
|
86
73
|
/**
|
|
87
|
-
* Adds the
|
|
74
|
+
* Adds the teamroom hooks to `.claude/settings.local.json`, which Claude Code
|
|
88
75
|
* treats as personal and does not commit. Other settings and hooks are kept.
|
|
89
76
|
*/
|
|
90
|
-
export async function
|
|
77
|
+
export async function installClaudeHooks(repoRoot, cli) {
|
|
91
78
|
const file = path.join(repoRoot, CLAUDE_SETTINGS_FILE);
|
|
92
79
|
const settings = await readSettings(file);
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
const command = claudeHookCommand(cli);
|
|
81
|
+
const hooks = { ...settings.hooks };
|
|
82
|
+
let changed = false;
|
|
83
|
+
for (const event of CLAUDE_HOOK_EVENTS) {
|
|
84
|
+
const groups = hooks[event] ?? [];
|
|
85
|
+
const wanted = wantedGroup(event, command);
|
|
86
|
+
const existing = groups.filter(isTeamroomGroup);
|
|
87
|
+
if (existing.length === 1 && JSON.stringify(existing[0]) === JSON.stringify(wanted))
|
|
88
|
+
continue;
|
|
89
|
+
hooks[event] = [...groups.filter((group) => !isTeamroomGroup(group)), wanted];
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
const allow = settings.permissions?.allow ?? [];
|
|
93
|
+
const missing = CLAUDE_ALLOWED_TOOLS.filter((rule) => !allow.includes(rule));
|
|
94
|
+
if (missing.length > 0) {
|
|
95
|
+
settings.permissions = { ...settings.permissions, allow: [...allow, ...missing] };
|
|
96
|
+
changed = true;
|
|
97
|
+
}
|
|
98
|
+
if (!changed)
|
|
100
99
|
return { change: "unchanged", file };
|
|
101
|
-
settings.hooks =
|
|
100
|
+
settings.hooks = hooks;
|
|
102
101
|
await writeSettings(file, settings);
|
|
103
102
|
return { change: "installed", file };
|
|
104
103
|
}
|
|
105
|
-
export async function
|
|
104
|
+
export async function rememberClaudeHooksWanted(storeDir, wanted) {
|
|
105
|
+
const file = path.join(storeDir, CLAUDE_WANTED_FILE);
|
|
106
|
+
if (!wanted) {
|
|
107
|
+
await fs.rm(file, { force: true });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
await fs.mkdir(storeDir, { recursive: true });
|
|
111
|
+
await fs.writeFile(file, "", "utf8");
|
|
112
|
+
}
|
|
113
|
+
export async function claudeHooksWanted(storeDir) {
|
|
114
|
+
try {
|
|
115
|
+
await fs.access(path.join(storeDir, CLAUDE_WANTED_FILE));
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export async function claudeHooksInstalled(repoRoot) {
|
|
123
|
+
const settings = await readSettings(path.join(repoRoot, CLAUDE_SETTINGS_FILE)).catch(() => ({}));
|
|
124
|
+
return CLAUDE_HOOK_EVENTS.filter((event) => settings.hooks?.[event]?.some(isTeamroomGroup));
|
|
125
|
+
}
|
|
126
|
+
export async function uninstallClaudeHooks(repoRoot) {
|
|
106
127
|
const file = path.join(repoRoot, CLAUDE_SETTINGS_FILE);
|
|
107
128
|
const settings = await readSettings(file);
|
|
108
|
-
const
|
|
109
|
-
|
|
129
|
+
const hooks = { ...settings.hooks };
|
|
130
|
+
let removed = false;
|
|
131
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
132
|
+
if (!groups?.some(isTeamroomGroup))
|
|
133
|
+
continue;
|
|
134
|
+
removed = true;
|
|
135
|
+
const remaining = groups.filter((group) => !isTeamroomGroup(group));
|
|
136
|
+
if (remaining.length > 0)
|
|
137
|
+
hooks[event] = remaining;
|
|
138
|
+
else
|
|
139
|
+
delete hooks[event];
|
|
140
|
+
}
|
|
141
|
+
if (!removed)
|
|
110
142
|
return { change: "absent", file };
|
|
111
|
-
const remaining = groups.filter((group) => !isTeamroomGroup(group));
|
|
112
|
-
const { PostToolUse: _removed, ...otherEvents } = settings.hooks ?? {};
|
|
113
|
-
const hooks = remaining.length > 0 ? { ...otherEvents, PostToolUse: remaining } : otherEvents;
|
|
114
143
|
if (Object.keys(hooks).length > 0)
|
|
115
144
|
settings.hooks = hooks;
|
|
116
145
|
else
|
|
117
146
|
delete settings.hooks;
|
|
147
|
+
removeAllowedTools(settings);
|
|
118
148
|
await writeSettings(file, settings);
|
|
119
149
|
return { change: "removed", file };
|
|
120
150
|
}
|
|
151
|
+
function removeAllowedTools(settings) {
|
|
152
|
+
const allow = settings.permissions?.allow;
|
|
153
|
+
if (!settings.permissions || !allow)
|
|
154
|
+
return;
|
|
155
|
+
const remaining = allow.filter((rule) => !CLAUDE_ALLOWED_TOOLS.includes(rule));
|
|
156
|
+
const { allow: _removed, ...otherPermissions } = settings.permissions;
|
|
157
|
+
const permissions = remaining.length > 0 ? { ...otherPermissions, allow: remaining } : otherPermissions;
|
|
158
|
+
if (Object.keys(permissions).length > 0)
|
|
159
|
+
settings.permissions = permissions;
|
|
160
|
+
else
|
|
161
|
+
delete settings.permissions;
|
|
162
|
+
}
|
|
121
163
|
//# sourceMappingURL=claude-hook.js.map
|