From 26e79690f8e6aa4991e527b1424810afc29e4cfd Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 25 Apr 2025 11:33:16 +0800 Subject: [PATCH] feat: add pwd handling to session and update related components --- app/src/components/FileNode.vue | 2 +- app/src/components/game/TreeChart.vue | 2 +- app/src/store/session.ts | 4 ++++ app/src/types.ts | 3 +-- packages/container/cli.js | 7 +++++++ packages/file-graph/fileGraph.ts | 1 + packages/game/schema/command.ts | 1 + 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/components/FileNode.vue b/app/src/components/FileNode.vue index 3744fdf..a4508e5 100644 --- a/app/src/components/FileNode.vue +++ b/app/src/components/FileNode.vue @@ -23,7 +23,7 @@ function nodeClass() { diff --git a/app/src/store/session.ts b/app/src/store/session.ts index b70d66c..2cdc8dc 100644 --- a/app/src/store/session.ts +++ b/app/src/store/session.ts @@ -51,6 +51,7 @@ const useSession = defineStore('session', { this.session = { ...session, graph: new FileGraph(session.graph), + pwd: '/home/commander', } term.reset() await socket.connect(this.session) @@ -105,6 +106,9 @@ const useSession = defineStore('session', { socket.on('graph', (event: FileGraphUpdateEvent) => { if (!this.session) return this.session.graph.handleEvent(event) + if (event.pwd) { + this.session.pwd = event.pwd + } }) socket.on('update', (update: SessionUpdate) => { this.newUpdate(update) diff --git a/app/src/types.ts b/app/src/types.ts index da2d02c..72192f7 100644 --- a/app/src/types.ts +++ b/app/src/types.ts @@ -18,8 +18,7 @@ export interface Session { _id: string status: string graph: FileGraph - // pwd: string - // hints: string[][] + pwd: string tasks: ITask[] responses: IResponse[] } diff --git a/packages/container/cli.js b/packages/container/cli.js index 3f303af..ead7a5b 100644 --- a/packages/container/cli.js +++ b/packages/container/cli.js @@ -32,6 +32,13 @@ async function readOrNone(file) { const commandListeners = { ls: [discoverFiles], + cd: [changeDirectory], +} + +function changeDirectory() { + return { + pwd: process.cwd(), + } } async function handleCommand(command) { diff --git a/packages/file-graph/fileGraph.ts b/packages/file-graph/fileGraph.ts index 4f77de2..37ad9b9 100644 --- a/packages/file-graph/fileGraph.ts +++ b/packages/file-graph/fileGraph.ts @@ -5,6 +5,7 @@ export interface FileGraphUpdateEvent { add?: FileObject[] remove?: FileObject[] discover?: FileObject[] + pwd?: string } export default class FileGraph extends FileNode { diff --git a/packages/game/schema/command.ts b/packages/game/schema/command.ts index 02231d2..4068d8b 100644 --- a/packages/game/schema/command.ts +++ b/packages/game/schema/command.ts @@ -8,6 +8,7 @@ const fileSchema = z.object({ export const commandParamsSchema = z.object({ discover: fileSchema.array().optional(), + pwd: z.string().optional(), }) export type ICommandParams = z.infer