@chatroomcp/chatroom 0.2.2 → 0.2.3
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 +5 -3
- package/dist/native/linux/chatroom-computer-helper +0 -0
- package/dist/native/macos/ChatRoomComputerHelper.app/Contents/MacOS/chatroom-computer-helper +0 -0
- package/dist/native/windows/chatroom-computer-helper.exe +0 -0
- package/dist/plugins/web/http/workspace-api-router.js +36 -0
- package/dist/plugins/workspace/mcp.js +4 -1
- package/dist/plugins/workspace/metadata.d.ts +2 -0
- package/dist/plugins/workspace/metadata.js +20 -10
- package/dist/plugins/workspace/types.d.ts +5 -0
- package/dist/plugins/workspace/workspace-fs.d.ts +3 -0
- package/dist/plugins/workspace/workspace-fs.js +93 -4
- package/dist/plugins/workspace/workspace-service.d.ts +4 -0
- package/dist/plugins/workspace/workspace-service.js +71 -16
- package/dist/web/assets/index-CEzdY5mz.js +27 -0
- package/dist/web/assets/index-D_mpjwCG.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/index-DFKEvyzR.css +0 -1
- package/dist/web/assets/index-vzPPspuL.js +0 -26
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
English | <a href="./docs/README.zh-CN.md">简体中文</a> | <a href="https://doc.chatroomcp.com/">Documentation</a>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
|
-
ChatRoom is a local MCP runtime that lets ChatGPT work with projects
|
|
11
|
+
ChatRoom is a local MCP runtime that lets ChatGPT work with projects on your local device, run processes, or perform computer control. Its WebUI provides workspace browsing, Git repository and process management, computer control, ChatRoom Cloud management, and plugin-attributed operation logs.
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
@@ -20,6 +20,8 @@ chatroom init
|
|
|
20
20
|
chatroom serve
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
Windows users can also use [ChatRoom-Windows-Portable](https://github.com/dayearnew/ChatRoom-Windows-Portable) without configuring any dependencies themselves.
|
|
24
|
+
|
|
23
25
|
Default local endpoints:
|
|
24
26
|
|
|
25
27
|
```text
|
|
@@ -27,13 +29,13 @@ WebUI http://127.0.0.1:8765/
|
|
|
27
29
|
MCP http://127.0.0.1:8765/mcp
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
`chatroom init` creates
|
|
32
|
+
`chatroom init` creates the [configuration file](https://doc.chatroomcp.com/configuration) and uses `~/Projects` as the default allowed workspace root.
|
|
31
33
|
|
|
32
34
|
## Use with ChatGPT
|
|
33
35
|
|
|
34
36
|
ChatGPT connects to ChatRoom through its MCP endpoint. For remote access, either enable ChatRoom Cloud from the WebUI or expose ChatRoom through your own HTTPS ingress and configure the corresponding public URL.
|
|
35
37
|
|
|
36
|
-
Create a custom MCP app in ChatGPT Developer Mode, use the ChatRoom `/mcp` URL, and complete OAuth authorization with the `ownerToken`
|
|
38
|
+
Create a custom MCP app in ChatGPT Developer Mode, use the ChatRoom `/mcp` URL, and complete OAuth authorization with the `ownerToken` in the [configuration file](https://doc.chatroomcp.com/configuration).
|
|
37
39
|
|
|
38
40
|
See [Use ChatRoom with ChatGPT](https://doc.chatroomcp.com/chatgpt) for the current ChatGPT setup flow.
|
|
39
41
|
|
|
Binary file
|
package/dist/native/macos/ChatRoomComputerHelper.app/Contents/MacOS/chatroom-computer-helper
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
2
|
import { ChatRoomError } from "../../../core/errors/chatroom-error.js";
|
|
3
3
|
import { asyncRoute, requireString, } from "../../../presentation/http/http-utils.js";
|
|
4
|
+
const MAX_WRITE_BYTES = 1024 * 1024;
|
|
4
5
|
export function createWorkspaceApiRouter(application) {
|
|
5
6
|
const router = Router();
|
|
6
7
|
router.get("/workspaces", asyncRoute(async (_req, res) => {
|
|
7
8
|
res.json(await application.workspaces.list());
|
|
8
9
|
}));
|
|
10
|
+
router.post("/workspaces", asyncRoute(async (req, res) => {
|
|
11
|
+
const body = bodyRecord(req.body);
|
|
12
|
+
const parent = requireString(body.parent, "parent");
|
|
13
|
+
const name = requireString(body.name, "name");
|
|
14
|
+
res.json(await application.operations.run({
|
|
15
|
+
pluginId: "workspace",
|
|
16
|
+
source: "gui",
|
|
17
|
+
action: "create",
|
|
18
|
+
input: { parent, name },
|
|
19
|
+
}, () => application.workspaces.createProject(parent, name)));
|
|
20
|
+
}));
|
|
21
|
+
router.get("/workspace/roots", (_req, res) => {
|
|
22
|
+
res.json(application.workspaces.roots());
|
|
23
|
+
});
|
|
9
24
|
router.get("/workspace", asyncRoute(async (req, res) => {
|
|
10
25
|
res.json(await application.workspaces.info(requireString(req.query.root, "root")));
|
|
11
26
|
}));
|
|
@@ -20,6 +35,22 @@ export function createWorkspaceApiRouter(application) {
|
|
|
20
35
|
maxBytes: 2 * 1024 * 1024,
|
|
21
36
|
}));
|
|
22
37
|
}));
|
|
38
|
+
router.put("/workspace/file", asyncRoute(async (req, res) => {
|
|
39
|
+
const body = bodyRecord(req.body);
|
|
40
|
+
const fs = await application.workspaces.fs(requireString(body.root, "root"));
|
|
41
|
+
const filePath = requireString(body.path, "path");
|
|
42
|
+
if (typeof body.content !== "string")
|
|
43
|
+
throw new ChatRoomError("INVALID_INPUT", "content must be a string");
|
|
44
|
+
const bytes = Buffer.byteLength(body.content, "utf8");
|
|
45
|
+
if (bytes > MAX_WRITE_BYTES)
|
|
46
|
+
throw new ChatRoomError("INVALID_INPUT", `File content exceeds ${MAX_WRITE_BYTES} bytes`);
|
|
47
|
+
res.json(await application.operations.run({
|
|
48
|
+
pluginId: "workspace",
|
|
49
|
+
source: "gui",
|
|
50
|
+
action: "file.write",
|
|
51
|
+
input: { root: fs.root, path: filePath, bytes },
|
|
52
|
+
}, () => fs.write(filePath, body.content)));
|
|
53
|
+
}));
|
|
23
54
|
router.get("/workspace/file/image", asyncRoute(async (req, res) => {
|
|
24
55
|
const filePath = requireString(req.query.path, "path");
|
|
25
56
|
const mime = imageMime(filePath);
|
|
@@ -37,6 +68,11 @@ export function createWorkspaceApiRouter(application) {
|
|
|
37
68
|
}));
|
|
38
69
|
return router;
|
|
39
70
|
}
|
|
71
|
+
function bodyRecord(value) {
|
|
72
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
73
|
+
? value
|
|
74
|
+
: {};
|
|
75
|
+
}
|
|
40
76
|
function imageMime(filePath) {
|
|
41
77
|
switch (filePath.split(".").pop()?.toLowerCase()) {
|
|
42
78
|
case "png":
|
|
@@ -2,6 +2,9 @@ import { z } from "zod";
|
|
|
2
2
|
import { closedRead } from "../../mcp/server/tool-support.js";
|
|
3
3
|
const workspaceInfoSchema = z.object({
|
|
4
4
|
root: z.string(),
|
|
5
|
+
name: z.string(),
|
|
6
|
+
summary: z.string().nullable(),
|
|
7
|
+
presetPrompt: z.string().nullable(),
|
|
5
8
|
instructions: z.string().nullable(),
|
|
6
9
|
skills: z.array(z.object({
|
|
7
10
|
name: z.string(),
|
|
@@ -12,7 +15,7 @@ const workspaceInfoSchema = z.object({
|
|
|
12
15
|
export function registerWorkspaceTools(mcp, workspaces) {
|
|
13
16
|
mcp.registerTool("workspace_info", {
|
|
14
17
|
title: "Workspace info",
|
|
15
|
-
description: "Read
|
|
18
|
+
description: "Read the complete workspace context for a project, including its summary, preset prompt, project instructions, and skill metadata.",
|
|
16
19
|
inputSchema: z.object({ root: z.string() }),
|
|
17
20
|
outputSchema: workspaceInfoSchema,
|
|
18
21
|
annotations: closedRead,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { WorkspaceFs } from "./workspace-fs.js";
|
|
2
2
|
import type { WorkspaceSkill } from "./types.js";
|
|
3
|
+
export declare function readSummary(fs: WorkspaceFs): Promise<string | null>;
|
|
4
|
+
export declare function readPresetPrompt(fs: WorkspaceFs): Promise<string | null>;
|
|
3
5
|
export declare function readInstructions(fs: WorkspaceFs): Promise<string | null>;
|
|
4
6
|
export declare function readSkills(fs: WorkspaceFs): Promise<WorkspaceSkill[]>;
|
|
@@ -2,16 +2,15 @@ import path from "node:path";
|
|
|
2
2
|
import { ChatRoomError } from "../../core/errors/chatroom-error.js";
|
|
3
3
|
const SKILL_ROOTS = [".agents/skills", ".claude/skills", ".chatroom/skills"];
|
|
4
4
|
const MAX_METADATA_BYTES = 64 * 1024;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
5
|
+
const MAX_SUMMARY_BYTES = 8 * 1024;
|
|
6
|
+
export function readSummary(fs) {
|
|
7
|
+
return readOptionalText(fs, ".chatroom/summary.md", MAX_SUMMARY_BYTES);
|
|
8
|
+
}
|
|
9
|
+
export function readPresetPrompt(fs) {
|
|
10
|
+
return readOptionalText(fs, ".chatroom/prompt.md", MAX_METADATA_BYTES);
|
|
11
|
+
}
|
|
12
|
+
export function readInstructions(fs) {
|
|
13
|
+
return readOptionalText(fs, "AGENTS.md", MAX_METADATA_BYTES);
|
|
15
14
|
}
|
|
16
15
|
export async function readSkills(fs) {
|
|
17
16
|
const paths = [];
|
|
@@ -49,6 +48,17 @@ export async function readSkills(fs) {
|
|
|
49
48
|
}
|
|
50
49
|
}));
|
|
51
50
|
}
|
|
51
|
+
async function readOptionalText(fs, relativePath, maxBytes) {
|
|
52
|
+
try {
|
|
53
|
+
const content = (await fs.read(relativePath, { maxBytes })).content;
|
|
54
|
+
return content.trim() ? content : null;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof ChatRoomError && error.code === "NOT_FOUND")
|
|
58
|
+
return null;
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
52
62
|
function parseSkillFrontmatter(content) {
|
|
53
63
|
const lines = content
|
|
54
64
|
.replace(/^\uFEFF/, "")
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export interface WorkspaceEntry {
|
|
2
2
|
root: string;
|
|
3
|
+
name: string;
|
|
4
|
+
summary: string | null;
|
|
3
5
|
}
|
|
4
6
|
export interface WorkspaceSkill {
|
|
5
7
|
name: string;
|
|
@@ -8,6 +10,9 @@ export interface WorkspaceSkill {
|
|
|
8
10
|
}
|
|
9
11
|
export interface WorkspaceInfo {
|
|
10
12
|
root: string;
|
|
13
|
+
name: string;
|
|
14
|
+
summary: string | null;
|
|
15
|
+
presetPrompt: string | null;
|
|
11
16
|
instructions: string | null;
|
|
12
17
|
skills: WorkspaceSkill[];
|
|
13
18
|
}
|
|
@@ -17,9 +17,12 @@ export declare class WorkspaceFs {
|
|
|
17
17
|
bytes: number;
|
|
18
18
|
truncated: boolean;
|
|
19
19
|
}>;
|
|
20
|
+
write(relativePath: string, content: string): Promise<WorkspaceFile>;
|
|
20
21
|
list(relativePath?: string, options?: {
|
|
21
22
|
recursive?: boolean;
|
|
22
23
|
maxEntries?: number;
|
|
23
24
|
}): Promise<WorkspaceFile[]>;
|
|
25
|
+
private lexical;
|
|
26
|
+
private resolveWritable;
|
|
24
27
|
private resolveReadable;
|
|
25
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, open, readdir, realpath, rename, rm, stat, writeFile, } from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { ChatRoomError } from "../../core/errors/chatroom-error.js";
|
|
4
5
|
export class WorkspaceFs {
|
|
@@ -44,6 +45,44 @@ export class WorkspaceFs {
|
|
|
44
45
|
await handle.close();
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
async write(relativePath, content) {
|
|
49
|
+
if (typeof content !== "string")
|
|
50
|
+
throw new ChatRoomError("INVALID_INPUT", "File content must be a string");
|
|
51
|
+
const normalized = normalizeRelative(relativePath);
|
|
52
|
+
if (normalized === ".")
|
|
53
|
+
throw new ChatRoomError("INVALID_INPUT", "File path is required");
|
|
54
|
+
const target = await this.resolveWritable(normalized);
|
|
55
|
+
let mode = 0o644;
|
|
56
|
+
try {
|
|
57
|
+
const info = await lstat(target);
|
|
58
|
+
if (!info.isFile())
|
|
59
|
+
throw new ChatRoomError("INVALID_INPUT", `Not a file: ${relativePath}`);
|
|
60
|
+
mode = info.mode & 0o777;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof ChatRoomError)
|
|
64
|
+
throw error;
|
|
65
|
+
if (error.code !== "ENOENT")
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
const temporary = `${target}.chatroom-${randomUUID()}.tmp`;
|
|
69
|
+
try {
|
|
70
|
+
await writeFile(temporary, content, {
|
|
71
|
+
encoding: "utf8",
|
|
72
|
+
flag: "wx",
|
|
73
|
+
mode,
|
|
74
|
+
});
|
|
75
|
+
await rename(temporary, target);
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
path: normalized,
|
|
82
|
+
type: "file",
|
|
83
|
+
size: Buffer.byteLength(content, "utf8"),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
47
86
|
async list(relativePath = ".", options = {}) {
|
|
48
87
|
const start = await this.resolveReadable(relativePath);
|
|
49
88
|
if (!(await stat(start)).isDirectory())
|
|
@@ -73,11 +112,61 @@ export class WorkspaceFs {
|
|
|
73
112
|
await walk(start);
|
|
74
113
|
return output;
|
|
75
114
|
}
|
|
76
|
-
|
|
115
|
+
lexical(relativePath) {
|
|
77
116
|
const normalized = normalizeRelative(relativePath);
|
|
78
|
-
const
|
|
79
|
-
if (!inside(this.root,
|
|
117
|
+
const absolute = path.resolve(this.root, ...normalized.split("/"));
|
|
118
|
+
if (!inside(this.root, absolute))
|
|
80
119
|
throw new ChatRoomError("FORBIDDEN", "Path escapes workspace");
|
|
120
|
+
return absolute;
|
|
121
|
+
}
|
|
122
|
+
async resolveWritable(relativePath) {
|
|
123
|
+
const target = this.lexical(relativePath);
|
|
124
|
+
const relative = path.relative(this.root, target);
|
|
125
|
+
const parts = relative.split(path.sep).filter(Boolean);
|
|
126
|
+
let current = this.root;
|
|
127
|
+
for (let index = 0; index < parts.length - 1; index++) {
|
|
128
|
+
current = path.join(current, parts[index]);
|
|
129
|
+
let info;
|
|
130
|
+
try {
|
|
131
|
+
info = await lstat(current);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error.code !== "ENOENT")
|
|
135
|
+
throw error;
|
|
136
|
+
try {
|
|
137
|
+
await mkdir(current, { recursive: false, mode: 0o700 });
|
|
138
|
+
}
|
|
139
|
+
catch (mkdirError) {
|
|
140
|
+
if (mkdirError.code !== "EEXIST")
|
|
141
|
+
throw mkdirError;
|
|
142
|
+
}
|
|
143
|
+
info = await lstat(current);
|
|
144
|
+
}
|
|
145
|
+
if (info.isSymbolicLink())
|
|
146
|
+
throw new ChatRoomError("FORBIDDEN", `Writes through symlinked directories are not allowed: ${relativePath}`);
|
|
147
|
+
if (!info.isDirectory())
|
|
148
|
+
throw new ChatRoomError("INVALID_INPUT", `Parent is not a directory: ${parts[index]}`);
|
|
149
|
+
const canonical = await realpath(current);
|
|
150
|
+
if (!inside(this.root, canonical))
|
|
151
|
+
throw new ChatRoomError("FORBIDDEN", "Write path escapes workspace");
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const targetInfo = await lstat(target);
|
|
155
|
+
if (targetInfo.isSymbolicLink())
|
|
156
|
+
throw new ChatRoomError("FORBIDDEN", `Writes through symlinks are not allowed: ${relativePath}`);
|
|
157
|
+
if (!targetInfo.isFile())
|
|
158
|
+
throw new ChatRoomError("INVALID_INPUT", `Not a file: ${relativePath}`);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof ChatRoomError)
|
|
162
|
+
throw error;
|
|
163
|
+
if (error.code !== "ENOENT")
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
return target;
|
|
167
|
+
}
|
|
168
|
+
async resolveReadable(relativePath) {
|
|
169
|
+
const lexical = this.lexical(relativePath);
|
|
81
170
|
const canonical = await realpath(lexical).catch((error) => {
|
|
82
171
|
if (error.code === "ENOENT")
|
|
83
172
|
throw new ChatRoomError("NOT_FOUND", `Path does not exist: ${relativePath}`);
|
|
@@ -4,8 +4,12 @@ export declare class WorkspaceService {
|
|
|
4
4
|
private readonly allowedRoots;
|
|
5
5
|
private constructor();
|
|
6
6
|
static create(allowedRoots: string[]): Promise<WorkspaceService>;
|
|
7
|
+
roots(): string[];
|
|
7
8
|
list(): Promise<WorkspaceEntry[]>;
|
|
8
9
|
resolve(input: string): Promise<string>;
|
|
10
|
+
createProject(parentInput: string, nameInput: string): Promise<WorkspaceEntry>;
|
|
9
11
|
info(input: string): Promise<WorkspaceInfo>;
|
|
10
12
|
fs(input: string): Promise<WorkspaceFs>;
|
|
13
|
+
private isWorkspaceRoot;
|
|
14
|
+
private resolveAllowedRoot;
|
|
11
15
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { readdir, realpath, stat } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readdir, realpath, stat } from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { ChatRoomError } from "../../core/errors/chatroom-error.js";
|
|
5
|
-
import { readInstructions, readSkills } from "./metadata.js";
|
|
5
|
+
import { readInstructions, readPresetPrompt, readSkills, readSummary, } from "./metadata.js";
|
|
6
6
|
import { WorkspaceFs } from "./workspace-fs.js";
|
|
7
7
|
export class WorkspaceService {
|
|
8
8
|
allowedRoots;
|
|
@@ -20,6 +20,9 @@ export class WorkspaceService {
|
|
|
20
20
|
}));
|
|
21
21
|
return new WorkspaceService([...new Set(canonicalRoots)]);
|
|
22
22
|
}
|
|
23
|
+
roots() {
|
|
24
|
+
return [...this.allowedRoots];
|
|
25
|
+
}
|
|
23
26
|
async list() {
|
|
24
27
|
const roots = new Set();
|
|
25
28
|
for (const allowedRoot of this.allowedRoots) {
|
|
@@ -36,13 +39,20 @@ export class WorkspaceService {
|
|
|
36
39
|
entry.name.startsWith("."))
|
|
37
40
|
continue;
|
|
38
41
|
const candidate = await realpath(path.join(allowedRoot, entry.name)).catch(() => null);
|
|
39
|
-
if (candidate &&
|
|
42
|
+
if (candidate && this.isWorkspaceRoot(candidate))
|
|
40
43
|
roots.add(candidate);
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
|
-
return [...roots]
|
|
46
|
+
return Promise.all([...roots]
|
|
44
47
|
.sort((a, b) => a.localeCompare(b))
|
|
45
|
-
.map((root) =>
|
|
48
|
+
.map(async (root) => {
|
|
49
|
+
const fs = await WorkspaceFs.create(root);
|
|
50
|
+
return {
|
|
51
|
+
root,
|
|
52
|
+
name: path.basename(root),
|
|
53
|
+
summary: await readSummary(fs),
|
|
54
|
+
};
|
|
55
|
+
}));
|
|
46
56
|
}
|
|
47
57
|
async resolve(input) {
|
|
48
58
|
if (typeof input !== "string" || !input.trim())
|
|
@@ -52,22 +62,74 @@ export class WorkspaceService {
|
|
|
52
62
|
});
|
|
53
63
|
if (!(await stat(canonical)).isDirectory())
|
|
54
64
|
throw new ChatRoomError("INVALID_INPUT", `Workspace root is not a directory: ${input}`);
|
|
55
|
-
if (!this.
|
|
56
|
-
throw new ChatRoomError("FORBIDDEN", "Workspace
|
|
65
|
+
if (!this.isWorkspaceRoot(canonical))
|
|
66
|
+
throw new ChatRoomError("FORBIDDEN", "Workspace must be a direct child of a configured allowed root", { root: canonical });
|
|
57
67
|
return canonical;
|
|
58
68
|
}
|
|
69
|
+
async createProject(parentInput, nameInput) {
|
|
70
|
+
const parent = await this.resolveAllowedRoot(parentInput);
|
|
71
|
+
const name = validateProjectName(nameInput);
|
|
72
|
+
const target = path.join(parent, name);
|
|
73
|
+
try {
|
|
74
|
+
await mkdir(target, { recursive: false });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error.code === "EEXIST")
|
|
78
|
+
throw new ChatRoomError("CONFLICT", `Workspace already exists: ${target}`);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
await mkdir(path.join(target, ".chatroom"));
|
|
82
|
+
const root = await realpath(target);
|
|
83
|
+
return { root, name: path.basename(root), summary: null };
|
|
84
|
+
}
|
|
59
85
|
async info(input) {
|
|
60
86
|
const root = await this.resolve(input);
|
|
61
87
|
const fs = await WorkspaceFs.create(root);
|
|
62
|
-
const [instructions, skills] = await Promise.all([
|
|
88
|
+
const [summary, presetPrompt, instructions, skills] = await Promise.all([
|
|
89
|
+
readSummary(fs),
|
|
90
|
+
readPresetPrompt(fs),
|
|
63
91
|
readInstructions(fs),
|
|
64
92
|
readSkills(fs),
|
|
65
93
|
]);
|
|
66
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
root,
|
|
96
|
+
name: path.basename(root),
|
|
97
|
+
summary,
|
|
98
|
+
presetPrompt,
|
|
99
|
+
instructions,
|
|
100
|
+
skills,
|
|
101
|
+
};
|
|
67
102
|
}
|
|
68
103
|
async fs(input) {
|
|
69
104
|
return WorkspaceFs.create(await this.resolve(input));
|
|
70
105
|
}
|
|
106
|
+
isWorkspaceRoot(candidate) {
|
|
107
|
+
return this.allowedRoots.some((root) => path.dirname(candidate) === root);
|
|
108
|
+
}
|
|
109
|
+
async resolveAllowedRoot(input) {
|
|
110
|
+
if (typeof input !== "string" || !input.trim())
|
|
111
|
+
throw new ChatRoomError("INVALID_INPUT", "Allowed root is required");
|
|
112
|
+
const canonical = await realpath(expandHome(input)).catch(() => {
|
|
113
|
+
throw new ChatRoomError("NOT_FOUND", `Allowed root does not exist: ${input}`);
|
|
114
|
+
});
|
|
115
|
+
if (!this.allowedRoots.includes(canonical))
|
|
116
|
+
throw new ChatRoomError("FORBIDDEN", "Project can only be created directly under a configured allowed root");
|
|
117
|
+
return canonical;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function validateProjectName(input) {
|
|
121
|
+
if (typeof input !== "string")
|
|
122
|
+
throw new ChatRoomError("INVALID_INPUT", "Project name is required");
|
|
123
|
+
const name = input.trim();
|
|
124
|
+
if (!name ||
|
|
125
|
+
name === "." ||
|
|
126
|
+
name === ".." ||
|
|
127
|
+
name.startsWith(".") ||
|
|
128
|
+
name.includes("/") ||
|
|
129
|
+
name.includes("\\") ||
|
|
130
|
+
name.includes("\0"))
|
|
131
|
+
throw new ChatRoomError("INVALID_INPUT", "Invalid project name");
|
|
132
|
+
return name;
|
|
71
133
|
}
|
|
72
134
|
function expandHome(input) {
|
|
73
135
|
if (input === "~")
|
|
@@ -76,10 +138,3 @@ function expandHome(input) {
|
|
|
76
138
|
return path.join(os.homedir(), input.slice(2));
|
|
77
139
|
return path.resolve(input);
|
|
78
140
|
}
|
|
79
|
-
function inside(root, candidate) {
|
|
80
|
-
const relative = path.relative(root, candidate);
|
|
81
|
-
return (relative === "" ||
|
|
82
|
-
(!relative.startsWith(`..${path.sep}`) &&
|
|
83
|
-
relative !== ".." &&
|
|
84
|
-
!path.isAbsolute(relative)));
|
|
85
|
-
}
|