effect-patterns-platform
Demonstrates terminal I/O management for Effect-TS CLI applications, covering prompts, buffering, and encoding.
Install
mkdir -p .claude/skills/effect-patterns-platform && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/7772" && unzip -o skill.zip -d .claude/skills/effect-patterns-platform && rm skill.zipInstalls to .claude/skills/effect-patterns-platform
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Effect-TS patterns for Platform. Use when working with platform in Effect-TS applications.Key capabilities
- →Read and write to the terminal
- →Manage interactive CLI prompts
- →Handle cross-platform character encoding
- →Perform buffered I/O operations
- →Read passwords without echoing
How it works
The skill provides a Terminal module that wraps standard I/O operations to ensure safe buffering, character encoding, and structured interaction. It replaces direct console logging with managed terminal methods to prevent interleaved output and security vulnerabilities.
Inputs & outputs
When to use effect-patterns-platform
- →Build interactive CLI prompts
- →Read and write to the terminal
- →Format CLI application output
About this skill
Effect-TS Patterns: Platform
This skill provides 6 curated Effect-TS patterns for platform. Use this skill when working on tasks related to:
- platform
- Best practices in Effect-TS applications
- Real-world patterns and solutions
🟢 Beginner Patterns
Platform Pattern 4: Interactive Terminal I/O
Rule: Use Terminal for user input/output in CLI applications, providing proper buffering and cross-platform character encoding.
Good Example:
This example demonstrates building an interactive CLI application.
import { Terminal, Effect } from "@effect/platform";
interface UserInput {
readonly name: string;
readonly email: string;
readonly age: number;
}
const program = Effect.gen(function* () {
console.log(`\n[INTERACTIVE CLI] User Information Form\n`);
// Example 1: Simple prompts
yield* Terminal.writeLine(`=== User Setup ===`);
yield* Terminal.writeLine(``);
yield* Terminal.write(`What is your name? `);
const name = yield* Terminal.readLine();
yield* Terminal.write(`What is your email? `);
const email = yield* Terminal.readLine();
yield* Terminal.write(`What is your age? `);
const ageStr = yield* Terminal.readLine();
const age = parseInt(ageStr);
// Example 2: Display collected information
yield* Terminal.writeLine(``);
yield* Terminal.writeLine(`=== Summary ===`);
yield* Terminal.writeLine(`Name: ${name}`);
yield* Terminal.writeLine(`Email: ${email}`);
yield* Terminal.writeLine(`Age: ${age}`);
// Example 3: Confirmation
yield* Terminal.writeLine(``);
yield* Terminal.write(`Confirm information? (yes/no) `);
const confirm = yield* Terminal.readLine();
if (confirm.toLowerCase() === "yes") {
yield* Terminal.writeLine(`✓ Information saved`);
} else {
yield* Terminal.writeLine(`✗ Cancelled`);
}
});
Effect.runPromise(program);
Rationale:
Terminal operations:
- readLine: Read single line of user input
- readPassword: Read input without echoing (passwords)
- writeLine: Write line with newline
- write: Write without newline
- clearScreen: Clear terminal
Pattern: Terminal.readLine().pipe(...)
Direct stdin/stdout causes issues:
- No buffering: Interleaved output in concurrent context
- Encoding issues: Special characters corrupted
- Password echo: Security vulnerability
- No type safety: String manipulation error-prone
Terminal enables:
- Buffered I/O: Safe concurrent output
- Encoding handling: UTF-8 and special chars
- Password input: No echo mode
- Structured interaction: Prompts and validation
Real-world example: CLI setup wizard
- Direct: console.log mixed with readline, no error handling
- With Terminal: Structured input, validation, formatted output
Platform Pattern 2: Filesystem Operations
Rule: Use FileSystem module for safe, resource-managed file operations with proper error handling and cleanup.
Good Example:
This example demonstrates reading, writing, and manipulating files.
import { FileSystem, Effect, Stream } from "@effect/platform";
import * as fs from "fs/promises";
const program = Effect.gen(function* () {
console.log(`\n[FILESYSTEM] Demonstrating file operations\n`);
// Example 1: Write a file
console.log(`[1] Writing file:\n`);
const content = `Hello, Effect-TS!\nThis is a test file.\nCreated at ${new Date().toISOString()}`;
yield* FileSystem.writeFileUtf8("test.txt", content);
yield* Effect.log(`✓ File written: test.txt`);
// Example 2: Read the file
console.log(`\n[2] Reading file:\n`);
const readContent = yield* FileSystem.readFileUtf8("test.txt");
console.log(readContent);
// Example 3: Get file stats
console.log(`\n[3] File stats:\n`);
const stats = yield* FileSystem.stat("test.txt").pipe(
Effect.flatMap((stat) =>
Effect.succeed({
size: stat.size,
isFile: stat.isFile(),
modified: stat.mtimeMs,
})
)
);
console.log(` Size: ${stats.size} bytes`);
console.log(` Is file: ${stats.isFile}`);
console.log(` Modified: ${new Date(stats.modified).toISOString()}`);
// Example 4: Create directory and write multiple files
console.log(`\n[4] Creating directory and files:\n`);
yield* FileSystem.mkdir("test-dir");
yield* Effect.all(
Array.from({ length: 3 }, (_, i) =>
FileSystem.writeFileUtf8(
`test-dir/file-${i + 1}.txt`,
`Content of file ${i + 1}`
)
)
);
yield* Effect.log(`✓ Created directory with 3 files`);
// Example 5: List directory contents
console.log(`\n[5] Listing directory:\n`);
const entries = yield* FileSystem.readDirectory("test-dir");
entries.forEach((entry) => {
console.log(` - ${entry}`);
});
// Example 6: Append to file
console.log(`\n[6] Appending to file:\n`);
const appendContent = `\nAppended line at ${new Date().toISOString()}`;
yield* FileSystem.appendFileUtf8("test.txt", appendContent);
const finalContent = yield* FileSystem.readFileUtf8("test.txt");
console.log(`File now has ${finalContent.split("\n").length} lines`);
// Example 7: Clean up
console.log(`\n[7] Cleaning up:\n`);
yield* Effect.all(
Array.from({ length: 3 }, (_, i) =>
FileSystem.remove(`test-dir/file-${i + 1}.txt`)
)
);
yield* FileSystem.remove("test-dir");
yield* FileSystem.remove("test.txt");
yield* Effect.log(`✓ Cleanup complete`);
});
Effect.runPromise(program);
Rationale:
FileSystem operations:
- read: Read file as string
- readDirectory: List files in directory
- write: Write string to file
- remove: Delete file or directory
- stat: Get file metadata
Pattern: FileSystem.read(path).pipe(...)
Direct file operations without FileSystem create issues:
- Resource leaks: Files not closed on errors
- No error context: Missing file names in errors
- Blocking: No async/await integration
- Cross-platform: Path handling differences
FileSystem enables:
- Resource safety: Automatic cleanup
- Error context: Full error messages
- Async integration: Effect-native
- Cross-platform: Handles path separators
Real-world example: Process log files
- Direct: Open file, read, close, handle exceptions manually
- With FileSystem:
FileSystem.read(path).pipe(...)
🟡 Intermediate Patterns
Platform Pattern 3: Persistent Key-Value Storage
Rule: Use KeyValueStore for simple persistent storage of key-value pairs, enabling lightweight caching and session management.
Good Example:
This example demonstrates storing and retrieving persistent data.
import { KeyValueStore, Effect } from "@effect/platform";
interface UserSession {
readonly userId: string;
readonly token: string;
readonly expiresAt: number;
}
const program = Effect.gen(function* () {
console.log(`\n[KEYVALUESTORE] Persistent storage example\n`);
const store = yield* KeyValueStore.KeyValueStore;
// Example 1: Store session data
console.log(`[1] Storing session:\n`);
const session: UserSession = {
userId: "user-123",
token: "token-abc-def",
expiresAt: Date.now() + 3600000, // 1 hour
};
yield* store.set("session:user-123", JSON.stringify(session));
yield* Effect.log(`✓ Session stored`);
// Example 2: Retrieve stored data
console.log(`\n[2] Retrieving session:\n`);
const stored = yield* store.get("session:user-123");
if (stored._tag === "Some") {
const retrievedSession = JSON.parse(stored.value) as UserSession;
console.log(` User ID: ${retrievedSession.userId}`);
console.log(` Token: ${retrievedSession.token}`);
console.log(
` Expires: ${new Date(retrievedSession.expiresAt).toISOString()}`
);
}
// Example 3: Check if key exists
console.log(`\n[3] Checking keys:\n`);
const hasSession = yield* store.has("session:user-123");
const hasOther = yield* store.has("session:user-999");
console.log(` Has session:user-123: ${hasSession}`);
console.log(` Has session:user-999: ${hasOther}`);
// Example 4: Store multiple cache entries
console.log(`\n[4] Caching API responses:\n`);
const apiResponses = [
{ endpoint: "/api/users", data: [{ id: 1, name: "Alice" }] },
{ endpoint: "/api/posts", data: [{ id: 1, title: "First Post" }] },
{ endpoint: "/api/comments", data: [] },
];
yield* Effect.all(
apiResponses.map((item) =>
store.set(
`cache:${item.endpoint}`,
JSON.stringify(item.data)
)
)
);
yield* Effect.log(`✓ Cached ${apiResponses.length} endpoints`);
// Example 5: Retrieve cache with expiration
console.log(`\n[5] Checking cached data:\n`);
for (const item of apiResponses) {
const cached = yield* store.get(`cache:${item.endpoint}`);
if (cached._tag === "Some") {
const data = JSON.parse(cached.value);
console.log(
` ${item.endpoint}: ${Array.isArray(data) ? data.length : 1} items`
);
}
}
// Example 6: Remove specific entry
console.log(`\n[6] Removing entry:\n`);
yield* store.remove("cache:/api/comments");
const removed = yield* store.has("cache:/api/comments");
console.log(` Exists after removal: ${removed}`);
// Example 7: Iterate and count entries
console.log(`\n[7] Counting entries:\n`);
const allKeys = yield* store.entries.pipe(
Effect.map((entries) => entries.length)
);
console.log(` Total entries: ${allKeys}`);
});
Effect.runPromise(program);
Rationale:
KeyValueStore operations:
- set: Store key-value pair
- get: Retrieve value by key
- remove: Delete key
- has: Check if key exists
- clear: Remove all entries
Pattern: KeyValueStore.set(key, value).pipe(...)
Without persistent storage, transient data is lost:
- Session data: Lost on restart
- Caches: Rebuilt from scratch
- Configuration: Hardcoded or file-based
- State: Scat
Content truncated.
When not to use it
- →Direct stdin/stdout manipulation without buffering
- →Non-CLI application contexts
Limitations
- →Requires Effect-TS application context
- →Not suitable for non-CLI environments
How it compares
Unlike direct console usage, this approach provides structured, type-safe, and resource-managed terminal interactions that handle concurrency and encoding automatically.
Compared to similar skills
effect-patterns-platform side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| effect-patterns-platform (this skill) | 1 | 7mo | Review | Beginner |
| drizzle | 238 | 2mo | No flags | Intermediate |
| zustand | 113 | 2mo | No flags | Intermediate |
| motion-canvas | 58 | 6mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by PaulJPhilp
View all by PaulJPhilp →You might also like
drizzle
lobehub
Drizzle ORM schema and database guide. Use when working with database schemas (src/database/schemas/*), defining tables, creating migrations, or database model code. Triggers on Drizzle schema definition, database migrations, or ORM usage questions.
zustand
lobehub
Zustand state management guide. Use when working with store code (src/store/**), implementing actions, managing state, or creating slices. Triggers on Zustand store development, state management questions, or action implementation.
motion-canvas
davila7
Complete production-ready guide for Motion Canvas with ESM/CommonJS workarounds, full setup templates, and troubleshooting for programmatic video creation using TypeScript
turborepo
vercel
Turborepo monorepo build system guidance. Triggers on: turbo.json, task pipelines, dependsOn, caching, remote cache, the "turbo" CLI, --filter, --affected, CI optimization, environment variables, internal packages, monorepo structure/best practices, and boundaries. Use when user: configures tasks/workflows/pipelines, creates packages, sets up monorepo, shares code between apps, runs changed/affected packages, debugs cache, or has apps/packages directories.
shadcn-ui-setup
maneeshanif
Install and configure Shadcn/ui component library with Radix UI primitives, Aceternity UI effects, set up components, and manage the component registry. Use when adding Shadcn/ui to a Next.js project or installing specific UI components for Phase 2.
angular
sickn33
Modern Angular (v20+) expert with deep knowledge of Signals, Standalone Components, Zoneless applications, SSR/Hydration, and reactive patterns. Use PROACTIVELY for Angular development, component architecture, state management, performance optimization, and migration to modern patterns.