golem-file-io-scala

Implements filesystem read and write operations in Scala Golem agents via node:fs.

1.5k|212|Updated Nov 24, 2023
One-click install
npx skills add https://github.com/golemcloud/golem --skill golem-file-io-scala
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-file-io-scala
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/scala/golem-file-io-scala
Command: npx skills add https://github.com/golemcloud/golem --skill golem-file-io-scala

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Scala Golem agents compile to JavaScript via Scala.js and run in a QuickJS-based WASM runtime, so standard JVM file I/O (java.io.File, java.nio.file) does not work. This Skill shows how to perform filesystem operations correctly using the node:fs module through Scala.js interop.

Core Features & Use Cases

  • Scala.js Facade for node:fs: Define @JSImport facades for readFileSync, writeFileSync, appendFileSync, existsSync, readdirSync, and mkdirSync.
  • Wizer-Safe Initialization: Use lazy val to defer node:fs imports past the build-time pre-initialization phase, avoiding runtime failures.
  • Text and Binary File Handling: Read UTF-8 text files and binary files as Uint8Array, write and append files, and list directories.
  • Use Case: Build a Golem agent that reads a provisioned config file at /data/config.json and appends log entries to /tmp/agent.log across invocations with durable per-agent storage.

Quick Start

Show me how to read a text file and append to a log file from my Scala Golem agent using node:fs.

Frequently Asked Questions about golem-file-io-scala

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I read and write files in a Scala Golem agent?

Define a Scala.js facade with @JSImport("node:fs", JSImport.Namespace) exposing readFileSync, writeFileSync, and appendFileSync. Call these methods inside your agent implementation to read text or binary files and write output.

Why does java.io.File not work in Scala Golem agents?

Scala Golem agents compile to JavaScript via Scala.js and run in a QuickJS-based WASM runtime, so JVM APIs like java.io.File and java.nio.file are unavailable. Filesystem access must go through the node:fs module using Scala.js interop.

Why does node:fs import fail during Golem agent initialization?

WASI modules like node:fs are unavailable during the build-time wizer pre-initialization phase. Use lazy val or defer node:fs access to method bodies so the import happens at runtime instead of during pre-initialization.

Can I write to files provisioned into a Golem agent?

Only files provisioned with read-write permission, or files in non-provisioned paths, can be written. Files added with read-only permission cannot be modified, so write outputs to paths like /tmp instead.

Are file changes persistent across Golem agent invocations?

Yes, each agent instance has its own isolated filesystem, and file changes persist across invocations as durable state. Files written by one invocation remain available to later invocations of the same agent.