Prompt utilisé pour régénérer cette page :
Page: Laboratory Console — Interactive Virtual Filesystem Terminal
Category: internal
Description: "Experimental filesystem proof of concept"
Icon: console
Tags: ["lib", "console", "terminal"]
No status field in front matter.
Front matter (index.md):
---
title: "Laboratory Console"
description: "Experimental filesystem proof of concept"
icon: "console"
tags: ["lib", "console", "terminal"]
---
HTML structure (index.md body):
Single element: <section class="container visual full console"></section>
This empty section is populated dynamically by default.js.
Directory structure:
- index.md — page content (single empty section)
- default.js — entry point
- _console.lib.js — main console controller
- _screen.lib.js — screen output manager
- _history.lib.js — command history with localStorage persistence
- _bus.lib.js — pub/sub event bus
- _virtual_machine.lib.js — virtual filesystem environment
- _console.scss — console layout styles
- _prompt.scss — input prompt styles
- commands/ directory with 24 command modules (*.lib.js each)
=== default.js (entry point) ===
Imports: ./_console.lib.js (as "console")
Main function (async):
- Selects section.container from DOM
- Injects HTML: div.screen + div.input containing span.prompt (">" entity) + input[type=text][autofocus]
- Gets references to screenEl (.screen), inputEl (input), promptEl (.input > .prompt)
- Calls await console.init(screenEl, inputEl, promptEl)
- Self-invokes: main()
=== _console.lib.js (main controller) ===
Imports: ./_command.lib.js, ./_screen.lib.js, ./_history.lib.js, /_lib/panic_v3.js
Module state: _inputPrompt (HTMLElement), _historyIndex (-1 = current), _inputBuffer (string)
_motd(container): displays "Console v1.0 © Cylian" + filesystem concept explanation + "Type help/man" hint. Uses innerHTML with <br/> joins.
_parse(input): tokenizes trimmed input by whitespace. First token = command. Remaining tokens: if starts with "-", strips dashes, splits on "=" for kwargs; else positional args array. Returns [cmd, args[], kwargs{}].
_init(container, input, inputPrompt): initializes screen + command engine. Binds keydown on input:
- Enter: execute _prompt(input.value), clear input, reset history index/buffer
- ArrowUp: save current input if index=-1, navigate history up via history.get(index+1)
- ArrowDown: navigate down, restore _inputBuffer at index 0
- Ctrl+C: clear input
- Ctrl+L: screen.clear()
Click on container.parentElement: handle [data-cmd] links (execute command), focus input if no selection.
Displays MOTD with success class, runs "cd" to go home. Logs "ready".
_prompt(text): creates new screen line (prompt + output), parses text, adds to history if non-empty, sets prompt text to "{command.prompt()}{text}", executes command.run(), adds success/error class, updates _inputPrompt text, scrolls bottom.
Exports frozen: { init, prompt }.
=== _screen.lib.js ===
Imports: /_lib/panic_v3.js
_container: stores screen element reference.
_init(container): sets _container.
_get(): creates div.line containing div.prompt + div.output, prepends to _container. Returns {prompt, output}.
_scrollBottom(): smooth scrolls window to document bottom.
_clear(): empties _container innerHTML.
Exports frozen: { init, get, clear, scrollBottom }.
=== _history.lib.js ===
STORAGE_KEY: 'console.history', MAX_HISTORY: 100
_history array, loaded from localStorage on module init.
_load(): JSON.parse from localStorage, fallback to [].
_save(): JSON.stringify to localStorage.
_get(n): returns _history[length - 1 - n], null if out of bounds. 0 = most recent.
_push(command): appends, trims to MAX_HISTORY, saves.
_all(): returns shallow copy.
Exports frozen: { get, push, all }.
=== _bus.lib.js ===
Simple pub/sub. _subscribers Map of event -> Set of callbacks.
_register(event, callback): adds to set.
_registerOnce(event, callback): wraps in auto-unregister wrapper.
_unregister(event, callback): removes from set.
_fire(event, data): iterates callbacks sequentially (await each).
Exports frozen: { register, registerOnce, unregister, fire }.
=== _virtual_machine.lib.js ===
Imports: /_lib/panic_v3.js
CONFIG_PATH exported: '/_api/console/default.json'
_machine object: loaded from JSON config via fetch.
_uuid(): generates UUID v4 with Math.random.
_init(path): fetches JSON config into _machine.
Volume operations (all on _machine.volume — inode-based filesystem):
_volume_resolve(path): resolves path string to inode. Absolute paths start from _machine.root, relative from _machine.cwd. Splits by "/" and traverses node.children.
_volume_node(inode): returns node object or null.
_volume_make(parentInode, name, options): creates new node. Validates name (no dots/slashes), checks parent exists + update permission, checks no name collision. Generates UUID inode. Creates node with stat (name, access, type, size, length, parent, mtime) + url + children (with "." and ".." entries). Increments parent length.
_volume_read(inode): checks read permission. If internal link (stat.internal.isLink), fetches URL. Otherwise returns fake Response with node.content.
_volume_copy(srcInode, dstParentInode, dstName): recursive copy. Checks read+traverse on source, update on dest parent. Deep copies children. Updates lengths.
_volume_rename(srcParent, srcName, dstParent, dstName): moves node between parents. Updates stat.name, stat.parent, children[".."], removes from source, adds to dest.
_volume_remove(parentInode, name): recursive delete. Checks update permission on parent. Recursively removes children. Deletes from volume and parent.
_volume_write(inode, content): checks write permission. Sets content, size, mtime, clears isLink.
_volume_allowed(inode, mode): checks access string for mode char (r/t/w/u/x) for current user.
Env operations: _env_get(key), _env_set(key, value), _env_all() — read/write _machine.env.
CWD operations: _cwd_get(), _cwd_set(inode) — updates _machine.cwd + env.CWD + env.PROMPT.
_volume_fullpath(inode): builds full path from parent + name.
Exports frozen nested: { init, volume:{resolve,node,make,copy,rename,remove,read,write,allowed,fullpath}, env:{get,set,all}, cwd:{get,set} }.
Permission model: access string per user like "rtwu-" where r=read, t=traverse, w=write, u=update(create/delete children), x=execute. "-" = denied.
=== Command modules (commands/*.lib.js) ===
Each exports frozen { run: _run }. Signature: _run(vm, container, args, kwargs).
Most have _usage(container) helper for invalid args.
Filesystem commands:
- cat.lib.js: reads file content via vm.volume.read(), displays response text. Usage: cat <path>.
- cd.lib.js: changes directory. No args = home (vm.env.get('HOME')). Checks traverse permission.
- pwd.lib.js: prints vm.env.get('CWD').
- ls.lib.js: lists directory. Supports -l (long), -a (show . and ..), -f/--forest (tree), --long. Formats table with name, access, type, size, mtime. Uses HTML table output.
- touch.lib.js: creates new node via vm.volume.make(). Usage: touch <name>.
- cp.lib.js: copies file/node via vm.volume.copy(). Resolves source + dest parent. Usage: cp <src> <dst>.
- mv.lib.js: moves/renames via vm.volume.rename(). Usage: mv <src> <dst>.
- rm.lib.js: removes via vm.volume.remove(). Usage: rm <path>.
- stat.lib.js: displays full node stats (name, type, size, access, parent, mtime). Usage: stat <path>.
I/O commands:
- echo.lib.js: prints args joined by spaces. Handles key=value pairs.
- write.lib.js: writes content to file via vm.volume.write(). Usage: write <path> <content...>.
System commands:
- id.lib.js: displays vm.env.get('USER').
- env.lib.js: displays all environment variables as key=value list in HTML table.
- hostname.lib.js: displays window.location.hostname.
- version.lib.js: displays vm.env.get('VERSION').
- date.lib.js: displays current date/time via toLocaleString().
Utility commands:
- help.lib.js: lists all commands with descriptions in HTML table. Includes data-cmd attributes for clickable commands.
- man.lib.js: loads command module dynamically, displays its manual/description.
- history.lib.js: imports ../_history.lib.js, displays numbered command list.
- clear.lib.js: imports ../_screen.lib.js, calls screen.clear().
- sleep.lib.js: waits 10 seconds, shows a dot each second.
- fortune.lib.js: picks random quote from 15 hardcoded tech quotes.
- open.lib.js: opens node URL in new window via window.open(). Imports /_lib/panic_v3.js.
Debug commands:
- crash.lib.js: waits 1 second then throws intentional error.
=== _console.scss ===
Variables: $console-spacing: 3px, $console-border-width: 3px, $console-cell-gap: 1em.
section.container.console: monospace font family, grid layout (1fr auto rows, 1fr column).
table: full width, collapsed borders, td nowrap + vertical-align top + padding-right gap.
.screen: grid-row 1, flex column-reverse (newest at bottom), .windowed has overflow-y auto.
.line: padding, .output has left border (3px solid primary), success=green border, error=danger border.
.input: grid-row 2, padding.
[data-cmd]: secondary color, pointer cursor, hover orange transition.
=== _prompt.scss ===
.input: flex row, align baseline, full width.
.prompt: line-height 1.
input: flex 1, transparent background, no border, inherit color/font, no outline/shadow.
Page entièrement générée et maintenue par IA, sans intervention humaine.