Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: remove type duplication and fix path traversal in workspace files
Gener7f2f73045e2d
diff --git a/src/cli/daemon/client.ts b/src/cli/daemon/client.tsindex 98164767a..eee1eba46 100644--- a/src/cli/daemon/client.ts+++ b/src/cli/daemon/client.ts@@ -1,9 +1,11 @@import {PollResponseSchema,RegisterResponseSchema,+ type FileRequestItem,type PollResponse,type RegisterResponse,type TaskApi,+ type WorkspaceFileReport,} from "@alook/shared";export class DaemonClient {@@ -85,7 +87,7 @@ export class DaemonClient {evicted: boolean;pending_update?: { version: string };pending_rescan?: boolean;- file_requests?: { id: string; agent_id: string; request_type: string; path: string }[];+ file_requests?: FileRequestItem[];}> {const raw = await this.request<unknown>("POST",@@ -199,17 +201,7 @@ export class DaemonClient {);}- reportFileData(- token: string,- body: {- request_id: string;- entries?: { name: string; path: string; isDirectory: boolean; size: number; modifiedAt: string }[];- content?: string | null;- isBinary?: boolean;- error?: string;- path: string;- },- ) {+ reportFileData(token: string, body: WorkspaceFileReport) {return this.request("POST","/api/daemon/workspace/report",diff --git a/src/cli/daemon/workspace-files.ts b/src/cli/daemon/workspace-files.tsindex dd612560f..0e8720557 100644--- a/src/cli/daemon/workspace-files.ts+++ b/src/cli/daemon/workspace-files.ts@@ -1,5 +1,6 @@import { readdir, stat, readFile } from "fs/promises";import { join, resolve, extname, relative } from "path";+import type { WorkspaceFileEntry } from "@alook/shared";const SKIP_DIRS = new Set([".git", "node_modules", ".next", ".wrangler", "__pycache__", ".venv"]);@@ -13,18 +14,10 @@ const TEXT_EXTENSIONS = new Set([const MAX_FILE_SIZE = 1_048_576; // 1MB-export interface FileEntry {- name: string;- path: string;- isDirectory: boolean;- size: number;- modifiedAt: string;-}-export async function readDirectoryTree(dirPath: string,basePath: string,-): Promise<FileEntry[]> {+): Promise<WorkspaceFileEntry[]> {let entries;try {entries = await readdir(dirPath, { withFileTypes: true });@@ -38,7 +31,7 @@ export async function readDirectoryTree(return a.name.localeCompare(b.name);});- const results: FileEntry[] = [];+ const results: WorkspaceFileEntry[] = [];for (const entry of entries) {if (entry.name.startsWith(".") && entry.name !== ".context_timeline") continue;if (SKIP_DIRS.has(entry.name)) continue;@@ -80,6 +73,6 @@ export async function readFileContent(export function validatePath(agentWorkdir: string, requestedPath: string): string | null {const resolved = resolve(agentWorkdir, requestedPath);- if (!resolved.startsWith(agentWorkdir)) return null;+ if (resolved !== agentWorkdir && !resolved.startsWith(agentWorkdir + "/")) return null;return resolved;}diff --git a/src/shared/src/index.ts b/src/shared/src/index.tsindex 93e48b726..c8fe96466 100644--- a/src/shared/src/index.ts+++ b/src/shared/src/index.ts@@ -20,7 +20,6 @@ export type {MeetingSession,Channel,WsMessage,- WorkspaceFileEntry,WorkspaceFileResult,} from "./types";@@ -159,6 +158,7 @@ export type {UpdateEmailAccountRequest,TestEmailConnectionRequest,FileRequestItem,+ WorkspaceFileEntry,WorkspaceFileBrowseRequest,WorkspaceFileReport,} from "./schemas";diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.tsindex 33af6cd62..428c29fc2 100644--- a/src/shared/src/schemas.ts+++ b/src/shared/src/schemas.ts@@ -554,6 +554,7 @@ export const WorkspaceFileEntrySchema = z.object({size: z.number(),modifiedAt: z.string(),});+export type WorkspaceFileEntry = z.infer<typeof WorkspaceFileEntrySchema>;export const WorkspaceFileReportSchema = z.object({request_id: z.string().min(1),diff --git a/src/shared/src/types.ts b/src/shared/src/types.tsindex 1b0f8a55e..46a231630 100644--- a/src/shared/src/types.ts+++ b/src/shared/src/types.ts@@ -1,4 +1,4 @@-import type { TaskApi } from "./schemas";+import type { TaskApi, WorkspaceFileEntry } from "./schemas";export type EmailDirection = "inbound" | "outbound";@@ -238,14 +238,6 @@ export type WsMessage =| { type: "followup.dispatch_failed"; conversationId: string; messageId: string; error: string }| { type: "workspace.files"; agentId: string; requestId: string; requestType: "tree" | "read"; result: WorkspaceFileResult }-export interface WorkspaceFileEntry {- name: string;- path: string;- isDirectory: boolean;- size: number;- modifiedAt: string;-}-export interface WorkspaceFileResult {entries?: WorkspaceFileEntry[];content?: string | null;diff --git a/src/web/src/app/(app)/w/[slug]/agents/[id]/files/page.tsx b/src/web/src/app/(app)/w/[slug]/agents/[id]/files/page.tsxindex 2f9964947..f6b93aeeb 100644--- a/src/web/src/app/(app)/w/[slug]/agents/[id]/files/page.tsx+++ b/src/web/src/app/(app)/w/[slug]/agents/[id]/files/page.tsx@@ -72,7 +72,7 @@ export default function AgentFilesPage() {}, []);const setNodeLoading = useCallback((path: string, loading: boolean) => {- setRootNodes((prev) => setLoadingRecursive(prev, path, loading));+ setRootNodes((prev) => updateNodeRecursive(prev, path, (n) => ({ ...n, loading })));}, []);// --- Request helpers ---@@ -156,7 +156,7 @@ export default function AgentFilesPage() {return;}- setRootNodes((prev) => updateNodesRecursive(prev, path, childNodes));+ setRootNodes((prev) => updateNodeRecursive(prev, path, (n) => ({ ...n, children: childNodes, loading: false, expanded: true })));},[],);@@ -202,7 +202,7 @@ export default function AgentFilesPage() {(path: string, node: TreeNode) => {if (node.expanded) {// Collapse- setRootNodes((prev) => toggleExpandRecursive(prev, path, false));+ setRootNodes((prev) => updateNodeRecursive(prev, path, (n) => ({ ...n, expanded: false })));return;}// Expand: load if needed@@ -210,7 +210,7 @@ export default function AgentFilesPage() {setNodeLoading(path, true);requestTree(path);}- setRootNodes((prev) => toggleExpandRecursive(prev, path, true));+ setRootNodes((prev) => updateNodeRecursive(prev, path, (n) => ({ ...n, expanded: true })));},[requestTree, setNodeLoading],);@@ -459,39 +459,17 @@ function TreeNodeRow({);}-// --- Recursive tree update helpers ---+// --- Recursive tree update helper ----function updateNodesRecursive(nodes: TreeNode[], targetPath: string, children: TreeNode[]): TreeNode[] {+function updateNodeRecursive(+ nodes: TreeNode[],+ targetPath: string,+ updater: (node: TreeNode) => TreeNode,+): TreeNode[] {return nodes.map((node) => {- if (node.entry.path === targetPath) {- return { ...node, children, loading: false, expanded: true };- }- if (node.children && targetPath.startsWith(node.entry.path + "/")) {- return { ...node, children: updateNodesRecursive(node.children, targetPath, children) };- }- return node;- });-}--function setLoadingRecursive(nodes: TreeNode[], targetPath: string, loading: boolean): TreeNode[] {- return nodes.map((node) => {- if (node.entry.path === targetPath) {- return { ...node, loading };- }- if (node.children && targetPath.startsWith(node.entry.path + "/")) {- return { ...node, children: setLoadingRecursive(node.children, targetPath, loading) };- }- return node;- });-}--function toggleExpandRecursive(nodes: TreeNode[], targetPath: string, expanded: boolean): TreeNode[] {- return nodes.map((node) => {- if (node.entry.path === targetPath) {- return { ...node, expanded };- }+ if (node.entry.path === targetPath) return updater(node);if (node.children && targetPath.startsWith(node.entry.path + "/")) {- return { ...node, children: toggleExpandRecursive(node.children, targetPath, expanded) };+ return { ...node, children: updateNodeRecursive(node.children, targetPath, updater) };}return node;});diff --git a/src/web/src/app/api/daemon/tasks/poll/route.ts b/src/web/src/app/api/daemon/tasks/poll/route.tsindex 98e8f9a67..6d482d4ea 100644--- a/src/web/src/app/api/daemon/tasks/poll/route.ts+++ b/src/web/src/app/api/daemon/tasks/poll/route.ts@@ -1,6 +1,6 @@import { NextRequest } from "next/server";import { getCloudflareContext } from "@opennextjs/cloudflare";-import { queries, PollRequestSchema, semverGte } from "@alook/shared";+import { queries, PollRequestSchema, semverGte, type FileRequestItem } from "@alook/shared";import { getDb } from "@/lib/db"import { withAuth } from "@/lib/middleware/auth";import { writeJSON, writeError, parseBody } from "@/lib/middleware/helpers";@@ -176,7 +176,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {}// 7. Pending file browse requests + cleanup- let fileRequests: { id: string; agent_id: string; request_type: string; path: string }[] | undefined;+ let fileRequests: FileRequestItem[] | undefined;try {await queries.workspaceFileRequest.expireStale(db, ctx.workspaceId);const pending = await queries.workspaceFileRequest.getPendingByWorkspace(db, ctx.workspaceId);@@ -184,7 +184,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {fileRequests = pending.map((r) => ({id: r.id,agent_id: r.agentId,- request_type: r.requestType,+ request_type: r.requestType as "tree" | "read",path: r.path,}));await queries.workspaceFileRequest.markDispatched(db, pending.map((r) => r.id));@@ -197,6 +197,6 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {tasks,...(pendingUpdate && { pending_update: pendingUpdate }),...(pendingRescan && { pending_rescan: pendingRescan }),- ...(fileRequests && fileRequests.length > 0 && { file_requests: fileRequests }),+ ...(fileRequests && { file_requests: fileRequests }),});});