small tweaks to the file structure, and reorganization of the codebase.

preparations for session manager function implementations
This commit is contained in:
2026-07-28 17:54:02 +02:00
parent 8c0a7e7a6c
commit 7348d3723e
14 changed files with 32 additions and 36 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import type { ShellError } from "./errors";
import type { Result } from "./result"; import type { Result } from "./result";
import type { ShellState } from "./shell_state"; import type { ShellState } from "./shell_state";
import type { ShellError } from "./util/errors";
type CommandFn = (state: ShellState, flags: string[], args: string[]) => CommandOutput<ShellError>; type CommandFn = (state: ShellState, flags: string[], args: string[]) => CommandOutput<ShellError>;
+6 -6
View File
@@ -1,16 +1,16 @@
import type { CommandDescriptor, CommandOutput } from "@core/command"; import type { CommandDescriptor, CommandOutput } from "@core/command";
import type { FileSystem } from "@core/filesystem/filesystem";
import { createErrorResult, createSuccessResult } from "@core/result";
import { getCurrentSession } from "@core/session_manager";
import { ShellState, withCwd } from "@core/shell_state";
import { import {
type InvalidArgumentsError, type InvalidArgumentsError,
type PathResolutionError, type PathResolutionError,
type PermissionDeniedError, type PermissionDeniedError,
type ShellError, type ShellError,
} from "@core/errors"; } from "@core/util/errors";
import type { FileSystem } from "@core/filesystem/filesystem";
import { resolveInode, resolvePath } from "@core/path_resolver";
import { createErrorResult, createSuccessResult } from "@core/result";
import { getCurrentSession } from "@core/session";
import { ShellState, withCwd } from "@core/shell_state";
import { createImmutableBuffer } from "@core/util/immutable_buffer"; import { createImmutableBuffer } from "@core/util/immutable_buffer";
import { resolveInode, resolvePath } from "@core/util/path_resolver";
export const COMMAND_NAME = "cd"; export const COMMAND_NAME = "cd";
+1 -1
View File
@@ -1,7 +1,7 @@
import type { CommandDescriptor, CommandOutput } from "@core/command"; import type { CommandDescriptor, CommandOutput } from "@core/command";
import type { ShellError } from "@core/errors";
import type { ResultSuccess } from "@core/result"; import type { ResultSuccess } from "@core/result";
import type { ShellState } from "@core/shell_state"; import type { ShellState } from "@core/shell_state";
import type { ShellError } from "@core/util/errors";
import { createImmutableBuffer } from "@core/util/immutable_buffer"; import { createImmutableBuffer } from "@core/util/immutable_buffer";
export const COMMAND_NAME = "echo"; export const COMMAND_NAME = "echo";
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UserInfo } from "@core/user_info"; import type { UserInfo } from "@core/session_manager";
import { createImmutableBuffer, type ImmutableBuffer } from "@core/util/immutable_buffer"; import { createImmutableBuffer, type ImmutableBuffer } from "@core/util/immutable_buffer";
import { dnTraverseTree, upTraverseTree } from "@core/util/tree_traversal"; import { dnTraverseTree, upTraverseTree } from "@core/util/tree_traversal";
import type { import type {
+1 -1
View File
@@ -1,4 +1,4 @@
import { createShellError, type ShellError } from "./errors"; import { createShellError, type ShellError } from "./util/errors";
import { createImmutableBuffer, type ImmutableBuffer } from "./util/immutable_buffer"; import { createImmutableBuffer, type ImmutableBuffer } from "./util/immutable_buffer";
export interface ResultError<E extends ShellError> { export interface ResultError<E extends ShellError> {
@@ -1,6 +1,13 @@
import { type HistoryState } from "./history_state"; import { type HistoryState } from "./history_state";
import type { ShellState } from "./shell_state"; import type { ShellState } from "./shell_state";
import type { UserInfo } from "./user_info";
export interface UserInfo {
readonly username: string;
readonly uid: number;
readonly gid: number;
readonly group: readonly number[];
readonly home: number;
}
export interface SessionState { export interface SessionState {
readonly user: UserInfo; readonly user: UserInfo;
+2 -2
View File
@@ -1,7 +1,7 @@
import type { FileSystem } from "./filesystem/filesystem"; import type { FileSystem } from "./filesystem/filesystem";
import { addHistoryEntry } from "./history_state"; import { addHistoryEntry } from "./history_state";
import { createInitialSessionState, getCurrentSession, type SessionState } from "./session"; import type { UserInfo } from "./session_manager";
import type { UserInfo } from "./user_info"; import { createInitialSessionState, getCurrentSession, type SessionState } from "./session_manager";
export interface ShellState { export interface ShellState {
readonly filesystem: FileSystem; readonly filesystem: FileSystem;
-7
View File
@@ -1,7 +0,0 @@
export interface UserInfo {
readonly name: string;
readonly uid: number;
readonly gid: number;
readonly group: readonly number[];
readonly home: number;
}
@@ -43,8 +43,7 @@ const EXIT_CODE_MAP: Record<string, number> = {
DataFormatError: 65, DataFormatError: 65,
FileNotFound: 66, FileNotFound: 66,
UserNotFound: 67, UserNotFound: 67,
HostNotFound: 68, LoginError: 68,
ServiceUnavailable: 69,
InternalSoftwareError: 70, InternalSoftwareError: 70,
OperatingSystemError: 71, OperatingSystemError: 71,
SystemFileError: 72, SystemFileError: 72,
@@ -136,12 +135,9 @@ export interface UserNotFoundError extends ShellError {
username: string; username: string;
} }
// ===================== 4. NETWORK / HOST / SERVICE ERRORS (Exit: 68, 69) ===================== export interface LoginError extends ShellError {
errorType: "LoginError";
/** Specified host does not exist or is unreachable (Exit 68 - EX_NOHOST) */ user: number;
export interface HostNotFoundError extends ShellError {
errorType: "HostNotFound";
hostname: string;
} }
/** Required service is unavailable (Exit 69 - EX_UNAVAILABLE) */ /** Required service is unavailable (Exit 69 - EX_UNAVAILABLE) */
@@ -1,6 +1,6 @@
import type { NodeNotFoundError, NotADirectoryError } from "./filesystem/errors"; import type { NodeNotFoundError, NotADirectoryError } from "../filesystem/errors";
import type { FileSystem } from "./filesystem/filesystem"; import type { FileSystem } from "../filesystem/filesystem";
import { TreeNodeType, type DirectoryNode, type TreeNode } from "./filesystem/treenode"; import { TreeNodeType, type DirectoryNode, type TreeNode } from "../filesystem/treenode";
export function resolvePath(fs: FileSystem, cwd: number, path: string): number { export function resolvePath(fs: FileSystem, cwd: number, path: string): number {
const isAbsolute = path.startsWith("/"); const isAbsolute = path.startsWith("/");
+2 -2
View File
@@ -1,9 +1,9 @@
import { descriptor as cd } from "@core/commands/cd"; import { descriptor as cd } from "@core/commands/cd";
import type { PathResolutionError } from "@core/errors";
import type { ResultError, ResultSuccess } from "@core/result"; import type { ResultError, ResultSuccess } from "@core/result";
import { getCurrentSession } from "@core/session"; import { getCurrentSession } from "@core/session_manager";
import { createInitialShellState, withCwd, type ShellState } from "@core/shell_state"; import { createInitialShellState, withCwd, type ShellState } from "@core/shell_state";
import type { UserInfo } from "@core/user_info"; import type { UserInfo } from "@core/user_info";
import type { PathResolutionError } from "@core/util/errors";
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture"; import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
+1 -1
View File
@@ -1,4 +1,4 @@
import { resolveInode, resolvePath } from "@core/path_resolver"; import { resolveInode, resolvePath } from "@core/util/path_resolver";
import { expectNodeNotFoundError, expectNotADirectoryError } from "@tests/helpers/error_matchers"; import { expectNodeNotFoundError, expectNotADirectoryError } from "@tests/helpers/error_matchers";
import { buildTestFS } from "@tests/helpers/filesystems_fixture"; import { buildTestFS } from "@tests/helpers/filesystems_fixture";
import { depth7Tree } from "@tests/helpers/tree_fixture"; import { depth7Tree } from "@tests/helpers/tree_fixture";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createInitialSessionState } from "@core/session"; import { createInitialSessionState } from "@core/session_manager";
import type { UserInfo } from "@core/user_info"; import type { UserInfo } from "@core/user_info";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
+1 -1
View File
@@ -1,6 +1,6 @@
import { FileSystem } from "@core/filesystem/filesystem"; import { FileSystem } from "@core/filesystem/filesystem";
import { TreeNodeType, type DirectoryNode, type TreeNode } from "@core/filesystem/treenode"; import { TreeNodeType, type DirectoryNode, type TreeNode } from "@core/filesystem/treenode";
import { getCurrentSession } from "@core/session"; import { getCurrentSession } from "@core/session_manager";
import { createInitialShellState, withCwd, withEnv, withExitCode, withHistory } from "@core/shell_state"; import { createInitialShellState, withCwd, withEnv, withExitCode, withHistory } from "@core/shell_state";
import type { UserInfo } from "@core/user_info"; import type { UserInfo } from "@core/user_info";
import { expect, test } from "vitest"; import { expect, test } from "vitest";