From acabf8c4c65c92c1c626d545b2c0b11aea059d40 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Fri, 26 Sep 2025 09:47:45 -0700 Subject: [PATCH] State -> Session --- app/nose/bin/cat.ts | 2 +- app/nose/bin/edit.tsx | 2 +- app/nose/bin/load.ts | 2 +- app/nose/bin/ls.ts | 2 +- app/nose/bin/project.ts | 2 +- app/nose/bin/projects.ts | 2 +- app/src/{state.ts => session.ts} | 12 ++++++------ app/src/shell.ts | 16 ++++++++-------- 8 files changed, 20 insertions(+), 20 deletions(-) rename app/src/{state.ts => session.ts} (50%) diff --git a/app/nose/bin/cat.ts b/app/nose/bin/cat.ts index f330d2d..6c7b3d2 100644 --- a/app/nose/bin/cat.ts +++ b/app/nose/bin/cat.ts @@ -4,7 +4,7 @@ import { join, extname } from "path" import type { CommandOutput } from "app/src/shared/types" import { NOSE_WWW } from "app/src/config" -import { getState } from "app/src/state" +import { getState } from "@/session" import { appPath } from "app/src/webapp" import { isBinaryFile } from "app/src/utils" import { highlight } from "../lib/highlight" diff --git a/app/nose/bin/edit.tsx b/app/nose/bin/edit.tsx index e307794..c0707f5 100644 --- a/app/nose/bin/edit.tsx +++ b/app/nose/bin/edit.tsx @@ -4,7 +4,7 @@ import { join, extname } from "path" import type { CommandOutput } from "app/src/shared/types" import { NOSE_WWW } from "app/src/config" -import { getState } from "app/src/state" +import { getState } from "@/session" import { appPath } from "app/src/webapp" import { isBinaryFile } from "app/src/utils" import { countChar } from "app/src/shared/utils" diff --git a/app/nose/bin/load.ts b/app/nose/bin/load.ts index c91c179..ef0660c 100644 --- a/app/nose/bin/load.ts +++ b/app/nose/bin/load.ts @@ -1,5 +1,5 @@ import { apps } from "app/src/webapp" -import { getState } from "app/src/state" +import { getState } from "@/session" export default function (project: string) { const state = getState() diff --git a/app/nose/bin/ls.ts b/app/nose/bin/ls.ts index f0c1620..58ac326 100644 --- a/app/nose/bin/ls.ts +++ b/app/nose/bin/ls.ts @@ -1,6 +1,6 @@ import { readdirSync } from "fs" import { NOSE_WWW } from "app/src/config" -import { getState } from "app/src/state" +import { getState } from "@/session" import { appPath } from "app/src/webapp" export default function () { diff --git a/app/nose/bin/project.ts b/app/nose/bin/project.ts index 7a2562f..2537616 100644 --- a/app/nose/bin/project.ts +++ b/app/nose/bin/project.ts @@ -1,4 +1,4 @@ -import { getState } from "app/src/state" +import { getState } from "@/session" export default function () { const state = getState() diff --git a/app/nose/bin/projects.ts b/app/nose/bin/projects.ts index b76fb36..9d0ab99 100644 --- a/app/nose/bin/projects.ts +++ b/app/nose/bin/projects.ts @@ -1,5 +1,5 @@ import { apps } from "app/src/webapp" -import { getState } from "app/src/state" +import { getState } from "@/session" export default function () { const state = getState() diff --git a/app/src/state.ts b/app/src/session.ts similarity index 50% rename from app/src/state.ts rename to app/src/session.ts index 4f3c9fd..52f41d5 100644 --- a/app/src/state.ts +++ b/app/src/session.ts @@ -1,15 +1,15 @@ import { AsyncLocalStorage } from "async_hooks" -export type State = { - id?: string - session?: string +export type Session = { + taskId?: string + sessionId?: string project?: string } // Ensure "ALS" lives between bun's hot reloads -const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage } -export const ALS = g.__thread ??= new AsyncLocalStorage() +const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage } +export const ALS = g.__thread ??= new AsyncLocalStorage() -export function getState(): State | undefined { +export function getState(): Session | undefined { return ALS.getStore() } \ No newline at end of file diff --git a/app/src/shell.ts b/app/src/shell.ts index 1578d11..a92f2ea 100644 --- a/app/src/shell.ts +++ b/app/src/shell.ts @@ -3,12 +3,12 @@ import { join } from "path" import type { CommandResult, CommandOutput } from "./shared/types" -import type { State } from "./state" +import type { Session } from "./session" import { NOSE_SYS_BIN, NOSE_BIN } from "./config" import { isFile } from "./utils" -import { ALS } from "./state" +import { ALS } from "./session" -const sessions: Map = new Map() +const sessions: Map = new Map() export async function runCommand(session: string, id: string, input: string): Promise { const [cmd = "", ...args] = input.split(" ") @@ -56,13 +56,13 @@ function processExecOutput(output: string | any): ["ok" | "error", CommandOutput } } -function getState(session: string, id: string): State { - let state = sessions.get(session) +function getState(sessionId: string, taskId: string): Session { + let state = sessions.get(sessionId) if (!state) { - state = { session, project: "" } - sessions.set(session, state) + state = { sessionId: sessionId, project: "" } + sessions.set(sessionId, state) } - state.id = id + state.taskId = taskId return state }