javascript-refactoring
Instructions for refactoring JavaScript code into separate files
Skill by kaushal-waygood
Chalk Labs
Need help deploying javascript-refactoring?
Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.
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/kaushal-waygood-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: not checked yet.
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 kaushal-waygood/agentic-self-healing-ci, MIT.
More from kaushal-waygood/agentic-self-healing-ci
- 0.401score
gh-agent-session
kaushal-waygood
GitHub CLI Agent Session Extension
SkillDFreshness: DClaude Code +9 - 0.401score
gh-agent-task
kaushal-waygood
GitHub CLI Agent Task Extension
SkillDFreshness: DClaude Code +9 - 0.401score
github-mcp-server
kaushal-waygood
GitHub MCP Server Documentation
SkillDFreshness: DClaude Code +9 - 0.387score
Dictation Instructions
kaushal-waygood
Instructions for fixing speech-to-text errors and improving text quality in gh-aw documentation and workflows
SkillDFreshness: DClaude Code +9 - 0.208score
custom-agents
kaushal-waygood
No description from the publisher yet.
SkillDFreshness: DClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Dec 24, 2025 (10 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Website
- gh.io/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 kaushal-waygood
- 0.401score
gh-agent-session
kaushal-waygood
GitHub CLI Agent Session Extension
SkillDFreshness: DClaude Code +9 - 0.401score
gh-agent-task
kaushal-waygood
GitHub CLI Agent Task Extension
SkillDFreshness: DClaude Code +9 - 0.401score
github-mcp-server
kaushal-waygood
GitHub MCP Server Documentation
SkillDFreshness: DClaude Code +9 - 0.387score
Dictation Instructions
kaushal-waygood
Instructions for fixing speech-to-text errors and improving text quality in gh-aw documentation and workflows
SkillDFreshness: DClaude Code +9
Done for you
Rather not set it up yourself?
Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.
See how we build AI agents →Read the case studies
Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.
- launches shipped
- 50+
- launches shipped
- media placements
- 500+
- media placements
- founders on every account
- 2
- founders on every account
Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block
Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.
Get javascript-refactoring running in your business
Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.
Cite this page
javascript-refactoring skill. Agent Mart. https://agentmart.dev/skills/kaushal-waygood-javascript-refactoring (last updated 2026-10-24)