javascript-refactoring
Instructions for refactoring JavaScript code into separate files
Skill by az9713
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/az9713-javascript-refactoring
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/javascript-refactoring
What's inside
- Skill name
javascript-refactoring- Description
- Instructions for refactoring JavaScript code into separate files
- License
- MIT
- Instructions
- 482 lines in SKILL.md · view on GitHub
Agent Skills spec issues
- body: contains an absolute path from the author's machine
Files (1)
- SKILL.md
SKILL.md (first lines)
# JavaScript Code Refactoring Guide
This guide explains how to refactor JavaScript code into a separate `.cjs` file in the gh-aw repository. Follow these steps when extracting shared functionality or creating new JavaScript modules.
## Overview
The gh-aw project uses CommonJS modules (`.cjs` files) for JavaScript code that runs in GitHub Actions workflows. These files are:
- Embedded in the Go binary using `//go:embed` directives
- Bundled using a custom JavaScript bundler that inlines local `require()` calls
- Executed in GitHub Actions using `actions/github-script@v8`
### Top-Level Script Pattern
Top-level `.cjs` scripts (those that are executed directly in workflows) follow a specific pattern:
**✅ Correct Pattern - Export main, but don't call it:**
```javascript
async function main() {
// Script logic here
core.info("Running the script");
}
module.exports = { main };
```
**❌ Incorrect Pattern - Don't call main in the file:**
```javascript
async function main() {
// Script logic here
core.info("Running the script");
}
await main(); // ❌ Don't do this!
module.exports = { main };
```
**Why this pattern?**
- The bundler automatically injects `await main()` during inline execution in GitHub Actions
- This allows the script to be both imported (for testing) and executed (in workflows)
- It provides a clean separation between module definition and execution
- It enables better testing by allowing tests to import and call `main()` with mocks
**Examples of top-level scripts:**
- `create_issue.cjs` - Creates GitHub issues
- `add_comment.cjs` - Adds comments to issues/PRs
- `add_labels.cjs` - Adds labels to issues/PRs
- `update_project.cjs` - Updates GitHub Projects
All of these files export `main` but do not call it directly.
## Step 1: Create the New .cjs File
Create your new file in `/home/runner/work/gh-aw/gh-aw/pkg/workflow/js/` with a descriptive name:
**File naming convention:**
- Use snake_case for filenames (e.g., `sanitize_content.cjs`, `load_agent_output.cjs`)
- Use `.cjs` extension (CommonJS module)
- Choose names that clearly describe the module's purpose
**Example file structure:**
```javascript
// @ts-check
/// <reference types="@actions/github-script" />
/**
* Brief description of what this module does
*/
/**
* Function documentation
* @param {string} input - Description of parameter
* @returns {string} Description of return value
*/
function myFunction(input) {
// Implementation
return input;
}
// Export the function(s)
module.exports = {
myFunction,
};
```
**Key points:**
- Include `// @ts-check` for TypeScript checking
- Include `/// <reference types="@actions/github-script" />` for GitHub Actions types
- Use JSDoc comments for documentation
- Export functions using `module.exports = { ... }`
- Do NOT import `@actions/core` or `@actions/github` - these are available globally in GitHub Actions
## Step 2: Add Tests
Create a test file with the same base name plus `.test.cjs`:
**Example: `pkg/workflow/js/my_module.test.cjs`**
```javascript
import { describe, it, expect, beforeEach, vi } from "vitest";
// Mock the global objects that GitHub Actions provides
const mockCore = {
debug: vi.fn(),
info: vi.fn(),
warning: vi.fn(),
error: vi.fn(),
setFailed: vi.fn(),
setOutput: vi.fn(),
summary: {
addRaw: vi.fn().mockReturnThis(),
write: vi.fn().mockResolvedValue(),
},
};
// Set up global mocks before importing the module
global.core = mockCore;
describe("myFunction", () => {From az9713/gh-aw, MIT.
More from az9713/gh-aw
- 0.354score
github-pr-query
az9713
Query GitHub pull requests efficiently with jq argument support for filtering
SkillDFreshness: DClaude Code +9 - 0.354score
console-rendering
az9713
Instructions for using the struct tag-based console rendering system in Go
SkillDFreshness: DClaude Code +9 - 0.354score
github-issue-query
az9713
Query GitHub issues efficiently with jq argument support for filtering
SkillDFreshness: DClaude Code +9 - 0.354score
github-discussion-query
az9713
Query GitHub discussions efficiently with jq argument support for filtering
SkillDFreshness: DClaude Code +9 - 0.354score
github-script
az9713
Best practices for writing JavaScript code for GitHub Actions using github-script
SkillDFreshness: DClaude Code +9 - 0.354score
debugging-workflows
az9713
Guide for debugging GitHub Agentic Workflows - analyzing logs, auditing runs, and troubleshooting issues
SkillDFreshness: DClaude Code +9 - 0.352score
github-copilot-agent-tips-and-tricks
az9713
Tips and Tricks for Working with GitHub Copilot Agent PRs
SkillDFreshness: DClaude Code +9 - 0.352score
error-pattern-safety
az9713
Error Pattern Safety Guidelines for Agentic Engines
SkillDFreshness: DClaude Code +9 - 0.352score
gh-agent-session
az9713
GitHub CLI Agent Session Extension
SkillDFreshness: DClaude Code +9 - 0.352score
gh-agent-task
az9713
GitHub CLI Agent Task Extension
SkillDFreshness: DClaude Code +9 - 0.352score
github-mcp-server
az9713
GitHub MCP Server Documentation
SkillDFreshness: DClaude Code +9 - 0.352score
documentation
az9713
Documentation Brief description for SEO and navigation
SkillDFreshness: DClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Feb 14, 2026 (8 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/az9713/gh-aw
- Website
- github.com/github/gh-aw
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from az9713
- 0.461score
codex-first
az9713
Claude Code-only work routing: delegate implementation, fixing, exploratory subagents, rebasing, and PR merging/landing to Codex CLI while Claude specifies…
SkillBFreshness: BClaude Code +9 - 0.430score
offer-shaper
az9713
Convert a vague AI idea or buyer pain into a concrete paid offer with buyer, promise, deliverable, price, proof mechanism, and sales path.
SkillCFreshness: C★ 1Claude Code +9 - 0.430score
context-reset
az9713
Preserve durable project state before clearing or compacting context so Claude Code can reset without losing business, technical, and verification state.
SkillCFreshness: C★ 1Claude Code +9 - 0.430score
break-test
az9713
Red-team a project, automation, app, or offer by trying to break it technically, commercially, operationally, and in front of a buyer.
SkillCFreshness: C★ 1Claude Code +9 - 0.430score
council-session
az9713
Run the full Idea-to-Capital council loop across buyer, CFO, technical, distribution, verification, and packaging perspectives.
SkillCFreshness: C★ 1Claude Code +9 - 0.430score
opportunity-triage
az9713
Evaluate an AI project, automation, SaaS, content product, or service idea for buyer demand, profitability, speed to validation, and whether to build…
SkillCFreshness: C★ 1Claude Code +9
Cite this page
javascript-refactoring skill. Agent Mart. https://agentmart.dev/skills/az9713-javascript-refactoring (last updated 2026-10-24)