What is hJS?

hJS is a modern, JavaScript-inspired language built specifically for ComputerCraft:Tweaked and CraftOS. It compiles directly into clean, native Lua bytecode, giving you the ergonomics of JavaScript with zero performance penalties.

Why hJS? Standard Lua is 1-indexed, lacks native arrow functions and template literals, and has no official package manager for ComputerCraft. hJS fixes all of these while remaining 100% compatible with existing CraftOS computers and turtles.

In-Game Installation

Open any ComputerCraft computer or turtle in Minecraft and run the automated installer:

CraftOS Terminal
wget run https://cc.jeremyleonklink.de/hjs

This automatically installs:

  • /usr/bin/hjs — The compiler, runtime, and interactive REPL.
  • /usr/bin/hpm — The package manager connected directly to cc-hub.

Using the hJS CLI

The hjs command gives you complete control over script execution and compilation:

CommandDescription
hjsLaunches the interactive JavaScript REPL shell in CraftOS.
hjs run <script.hjs>Compiles and immediately executes an .hjs script.
hjs build <in.hjs> [out.lua]Compiles hJS source code into standalone, pure Lua 5.1/5.2 source file.
hjs edit <script.hjs>Opens the full-screen terminal editor with live syntax check and autocomplete.

In-Game Terminal Editor

hJS includes a full-featured terminal code editor built directly into CraftOS. Launch it via hjs edit <filename.hjs> or hjs editor <filename.hjs>.

ShortcutFunction
Ctrl + SSave the current buffer to disk.
Ctrl + RSave the buffer and run the script immediately inside CraftOS.
Ctrl + QExit the editor back to the CraftOS shell.
TabSmart autocomplete for hJS keywords, ComputerCraft APIs, and JavaScript built-ins.
Arrow KeysNavigate cursor with automatic vertical and horizontal viewport scrolling.
Real-Time Syntax Validation: The status bar at the bottom continuously runs the hJS parser in the background. It displays [✓ Syntax OK] when valid or flags errors with the line number and message (e.g., [✗ Syntax Error L14: Expected ')' ]) before you ever run the script.
Terminal Editor Usage
// Start the terminal editor in CraftOS:
hjs edit miner.hjs
// (or: hjs editor miner.hjs)

// Keyboard shortcuts:
// [Ctrl+S] Save current file
// [Ctrl+R] Save & execute script immediately
// [Ctrl+Q] Quit editor
// [Tab]    Smart auto-completion (keywords, CC APIs, global functions)

// Live syntax check:
// The bottom status bar validates code as you type!
// [✓ Syntax OK]   - Ready to run
// [✗ Syntax Error L12: Unexpected token] - Points directly to issue

Language Syntax & Variables

hJS supports ECMAScript variable declarations, arrow functions, and template strings:

syntax.hjs
let score = 100;
const MAX_SPEED = 50;

// Arrow functions
let multiply = (a, b) => a * b;
let double = x => x * 2;

// Template literals
let playerName = "Steve";
console.log(`Welcome back, ${playerName}! Score: ${score * 2}`);

// Control flow
if (score > 50) {
  console.log("High score achieved!");
} else {
  console.log("Keep trying!");
}

0-Indexed Arrays & Prototypes

Unlike Lua, all arrays in hJS are 0-indexed. They include built-in prototype methods modeled after standard JavaScript:

arrays.hjs
let items = ["cobblestone", "iron_ore", "gold_ore"];

// 0-indexing
console.log(items[0]); // "cobblestone"
console.log(items[2]); // "gold_ore"
console.log(items.length); // 3

// Array modification
items.push("diamond");
let lastItem = items.pop();

// Iteration & Higher-Order functions
let upper = items.map(name => name.toUpperCase());
let ores = items.filter(name => name.indexOf("ore") !== -1);

for (const ore of ores) {
  console.log(`Found ore: ${ore}`);
}

Standard Library

hJS provides standard web APIs mapped to CraftOS equivalents:

APIMethods / Usage
consoleconsole.log(...), console.warn(...), console.error(...), console.clear()
JSONJSON.stringify(obj), JSON.parse(str)
MathMath.floor, Math.ceil, Math.round, Math.random(), Math.max, Math.PI
Timerssleep(ms) (blocks without error), setTimeout(fn, ms)

Turtle Automation in hJS

The entire ComputerCraft turtle API is natively available in the global scope:

miner.hjs
// 3x3 Tunnel Miner in hJS
function digColumn() {
  turtle.dig();
  turtle.forward();
  turtle.digUp();
  turtle.digDown();
}

console.log(`Initial fuel: ${turtle.getFuelLevel()}`);

for (let step = 0; step < 10; step++) {
  digColumn();
  console.log(`Dug step ${step + 1}`);
}

console.log("Mining completed!");

Peripherals & Advanced Peripherals

In hJS, all tables returned by peripheral.wrap(...), peripheral.find(...), and other CC APIs are automatically transformed into native hJS objects and 0-indexed arrays with prototype methods (.filter(), .map(), .length, .indexOf(), etc.).

This provides seamless support for both standard ComputerCraft peripherals and popular addon mods like Advanced Peripherals (ME Bridge, Geo Scanner, Chat Box, Inventory Manager, Colony Integrator, Player Detector):

peripherals.hjs
// 1. Standard ComputerCraft Peripheral
let monitor = peripheral.wrap("top");
monitor.clear();
monitor.setCursorPos(1, 1);
monitor.write("hJS System Online");

// 2. Advanced Peripherals: ME Bridge
let me = peripheral.find("meBridge");
if (me) {
  // Return tables are automatically wrapped into 0-indexed hJS arrays!
  let items = me.listItems();
  let iron = items.filter(item => item.name.includes("iron_ingot"));

  console.log(`Iron items found: ${iron.length}`);
  if (iron.length > 0) {
    console.log(`Total amount in system: ${iron[0].amount}`);
  }
}

// 3. Advanced Peripherals: Geo Scanner & Chat Box
let geo = peripheral.find("geoScanner");
if (geo) {
  let scanData = geo.scan(8);
  let ores = scanData.filter(block => block.tags && block.tags.includes("forge:ores"));
  console.log(`Detected ${ores.length} ore veins nearby!`);
}

let chat = peripheral.find("chatBox");
if (chat) {
  chat.sendMessage("hJS automated miner deployed!", "Bot");
}

Dual Lua Bridge

Need to access a native Lua module or custom API? hJS offers direct zero-overhead bridging:

interop.hjs
// 1. Require native Lua modules
let vector = lua.require("vector");
let vec1 = vector.new(10, 20, 30);

// 2. Direct access to global Lua scope
let osVersion = os.version();
console.log(`OS: ${osVersion}`);

// 3. Inline Lua evaluation for complex tables
let customValue = lua.raw('return colors.combine(colors.red, colors.yellow)');

hpm — Package Manager for hJS

hpm is the package manager for ComputerCraft. It allows you to create projects with hpm.json and install libraries directly from the cc-hub cloud registry into hjs_modules/.

Initialize a project
hpm init
Install packages
hpm install <package-name>
# Example:
hpm install pathfinding
hpm install ui-toolkit
Import installed package in your code
// Automatically resolved from ./hjs_modules/pathfinding/index.hjs
import { findPath } from "pathfinding";
// OR CommonJS style:
const pathfinder = require("pathfinding");
Project Manifest (hpm.json)
{
  "name": "my-turtle-app",
  "version": "1.0.0",
  "description": "Autonomous tunnel miner bot",
  "main": "index.hjs",
  "scripts": {
    "start": "hjs run index.hjs",
    "build": "hjs build index.hjs dist.lua"
  },
  "dependencies": {
    "pathfinding": "latest"
  }
}

Publishing Packages & Libraries (npm for ComputerCraft)

Just like npm for Node.js, hpm allows anyone in the community to build, publish, and share reusable hJS libraries and modules for ComputerCraft and CraftOS.

1. Package Structure & Anatomy

A publishable package only needs two core files: an hpm.json manifest and an entry file (e.g. index.hjs):

hpm.json
{
  "name": "turtle-navigator",
  "version": "1.0.0",
  "description": "Smart A* pathfinding and obstacle avoidance for CC:Tweaked turtles",
  "main": "index.hjs",
  "author": "YourName",
  "license": "MIT",
  "keywords": ["turtle", "pathfinding", "navigation", "hjs"],
  "dependencies": {
    "vector-math": "latest"
  }
}
index.hjs (Library Code & Exports)
// index.hjs - Main library entry point
import { distance } from "vector-math";

/**
 * Autonomous pathfinding turtle navigator
 */
export class Navigator {
  constructor(fuelThreshold = 50) {
    this.fuelThreshold = fuelThreshold;
  }

  moveTo(targetX, targetY, targetZ) {
    console.log(`Navigating to ${targetX}, ${targetY}, ${targetZ}...`);
    if (turtle.getFuelLevel() < this.fuelThreshold) {
      console.warn("Low fuel alert! Refueling...");
      turtle.refuel(1);
    }
    // Pathfinding execution...
    return true;
  }
}

// Named export
export function createNavigator(minFuel) {
  return new Navigator(minFuel);
}

// Default export
export default Navigator;

2. How to Release & Publish

You can release your package to the worldwide cc-hub registry using either of two methods:

MethodWorkflow
Web Studio IDE (Recommended)Open the hJS Web Studio. Click + Save as Repository or ask the AI Assistant: "Create a repository turtle-navigator for me". Once authorized, commit your files. The repository is immediately published to the registry!
In-Game CLI (hpm publish)In your CraftOS computer or turtle terminal, authenticate using your cc-hub account token and run hpm publish.
In-Game CLI Publishing
# 1. Set your cc-hub account token
# (Find your API token in cc-hub Account Settings or in Web Studio)
echo "cchub_pat_your_secret_token" > .hub_token

# 2. Publish current directory to cc-hub registry
hpm publish

# With custom release commit message:
hpm publish -m "v1.0.1: Added obstacle avoidance"

3. How Others Install and Use Your Package

Once published, anyone across Minecraft servers, singleplayer worlds, or web emulators can install your library with a single command:

Consuming Installed Package
// In any other computer or turtle:
// 1. Install library
// hpm install turtle-navigator

// 2. Import in your hJS code
import Navigator, { createNavigator } from "turtle-navigator";

const bot = createNavigator(100);
bot.moveTo(128, 64, -250);
Automatic Dependency Resolution: When users run hpm install your-package, hpm automatically inspects your dependencies in hpm.json and recursively downloads all required packages into hjs_modules/.

Dependency Updates & Self-Upgrade

Keep your packages and hJS environment up to date with hpm update:

CommandAction
hpm updateChecks and updates all dependencies listed in hpm.json to latest versions.
hpm update <pkg>Updates only the specified package in hjs_modules/ and refreshes hpm.json.
hpm update --selfDownloads the latest version of hjs and hpm directly from cc-hub and replaces local binaries.
Update Commands
# 1. Update all project dependencies in hpm.json
hpm update

# 2. Update a specific package to latest version
hpm update pathfinding

# 3. In-game self-updater: update hJS runtime & hpm from cc-hub
hpm update --self
# (or: hpm update hjs / hpm update hpm)