javascript-refactoring
Skill5.3k starsChanged 6 months agoMITView on GitHub
Split large JavaScript files into maintainable modules safely.
Trending
Quiet since March.thin dataabout the whole repository
Who's talking about github/gh-aw
- A Hacker News story“GitHub Agentic Workflows”Hacker News · Feb 11, 2026 · 2 points
- @kcieslak.io“We see that a lot in our OSSed AW repository which uses fully agentic development - github.com/github/gh-aw …”Bluesky · Mar 24, 2026 · 1 likes
- @github-trending.bsky.social“🚀 Skyrocketing! 🚀 (200+ new stars) 📦 github / gh-aw ⭐ 2,482 (+213) 🗒 Go GitHub Agentic Workflows”Bluesky · Feb 15, 2026
The biggest 3 of 3 mentions linking to the repository that our crawl found. Each line is their own headline.
In this repository108 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/src/content/docs/engines/claude.mdCLAUDE.md
- pkg/workflow/data/engines/claude.mdCLAUDE.md
- .squad/templates/copilot-instructions.mdCopilot instructions
- playwright-cliSkill
- agentic-workflowsSkill
- awf-release-integratorSkill
- checkout-credential-reviewSkill
- console-renderingSkill
- copilot-reviewSkill
- create-canvasSkill
- custom-agentsSkill
- custom-engine-implementationSkill
- debugging-workflowsSkill
- developer-code-organizationSkill
- developer-internalsSkill
- developer-releaseSkill
- developer-securitySkill
- developerSkill
- documentationSkill
- error-messagesSkill
- error-pattern-safetySkill
- error-recovery-patternsSkill
- gh-agent-sessionSkill
- gh-agent-taskSkill
- github-copilot-agent-tips-and-tricksSkill
- github-discussion-querySkill
- github-issue-querySkill
- github-labels-querySkill
- github-mcp-serverSkill
- github-pr-querySkill
- github-scriptSkill
- github-workflows-querySkill
- go-codemodSkill
- go-lintersSkill
- http-mcp-headersSkill
- jqschemaSkill
- messagesSkill
- npmSkill
- open-pull-requestSkill
- operational-value-designerSkill
- optimize-agentic-workflowSkill
- otel-queriesSkill
- pr-finisherSkill
- prompt-token-efficiencySkill
- pr-to-go-linterSkill
- reportingSkill
- resolve-merge-conflictsSkill
- restricted-tool-triageSkill
- review-agentic-workflowsSkill
- security-advisory-compat-enforcerSkill
- sergo-examplesSkill
- skillz-integrationSkill
- ssl-skill-normalizerSkill
- temporary-id-safe-outputSkill
- workflow-step-summariesSkill
- GitHub Agentic WorkflowsSkill
- {skill-name}Skill
- agent-collaborationSkill
- agent-conductSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 5 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Use this guide to split JavaScript into maintainable CommonJS modules in gh-aw without drifting into dead embedding patterns.
- Very specific: line 21
If you are refactoring a workflow utility, prefer the current action/module architecture over any older //go:embed pattern.
- Very specific: line 63
Use snake_case for filenames (for example sanitize_content.cjs, load_agent_output.cjs)
- Very specific: line 64
Use .cjs for CommonJS modules
- Distinctive: line 65
Keep the name aligned with the responsibility of the module
- Distinctive: line 93
Use JSDoc comments for documentation
- Very specific: line 95
Do not import @actions/core or @actions/github directly unless the module is running in an action context that explicitly expects it
- Very specific: line 99
Create a matching test beside the module using the same base name plus .test.cjs:
- Distinctive: line 134
Use Vitest for test execution
- Very specific: line 136
Use dynamic imports (await import()) to allow module setup at test time
- Very specific: line 147
Do not add a new //go:embed mapping just to ship a new runtime script.
- Distinctive: line 170
Run the relevant checks for the area you changed:
- Distinctive: line 182
Before committing your refactor:
- Very specific: line 201
When the JavaScript belongs to a single action, keep it under actions/<action-name>/src/ and regenerate the output bundle with make …
- Very specific: line 205
If the script is executed directly in a workflow, export main and omit the direct await main() call.
- Very specific: line 235
Do not audit coverage in actions/setup/js/ by matching foo.cjs to foo.test.cjs by basename.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JavaScript Code Refactoring Guide
Use this guide to split JavaScript into maintainable CommonJS modules in gh-aw without drifting into dead embedding patterns.
Overview
The current gh-aw architecture is action-centric:
- Shared JS modules live under
pkg/workflow/js/*.cjsandactions/setup/js/*.cjs - Action source files live under
actions/<action-name>/src/ - Generated action bundles are committed under
actions/<action-name>/index.js - Shipping is driven by the action build pipeline (
make actions-build,gh aw actions-build) and dependency maps such aspkg/cli/actions_build_command.go pkg/workflow/js.gois a stub; it no longer owns the runtime JavaScript shipping path for the main workflows
If you are refactoring a workflow utility, prefer the current action/module architecture over any older //go:embed pattern.
Top-Level Script Pattern
Top-level .cjs scripts executed directly in workflows follow this pattern:
✅ Correct Pattern - Export main, but don't call it:
async function main() {
// Script logic here
core.info("Running the script");
}
module.exports = { main };❌ Incorrect Pattern - Don't call main in the file:
async function main() {
// Script logic here
core.info("Running the script");
}
await main(); // ❌ Don't do this!
module.exports = { main };Why this pattern?
- The workflow bundler or action build step can wrap the script with
await main()at execution time - The module stays importable for tests while still being executable in GitHub Actions
- It makes unit testing easier and preserves a clean module boundary
Step 1: Put the code in the right source tree
Choose the correct location for the module before writing code:
- Shared workflow utilities:
pkg/workflow/js/ - Action-specific JavaScript:
actions/<action-name>/src/oractions/setup/js/ - Generated bundle output:
actions/<action-name>/index.js
File naming convention:
- Use snake_case for filenames (for example
sanitize_content.cjs,load_agent_output.cjs) - Use
.cjsfor CommonJS modules - Keep the name aligned with the responsibility of the module
Example file structure:
// @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) {
return input;
}
module.exports = {
myFunction,
};Key points:
- Include
// @ts-checkfor TypeScript checking - Include
/// <reference types="@actions/github-script" />when the module is used with GitHub Actions scripts - Use JSDoc comments for documentation
- Export functions via
module.exports = { ... } - Do not import
@actions/coreor@actions/githubdirectly unless the module is running in an action context that explicitly expects it
Step 2: Add tests next to the module
Create a matching test beside the module using the same base name plus .test.cjs:
Example: pkg/workflow/js/my_module.test.cjs
import { describe, it, expect, beforeEach, vi } from "vitest";
const mockCore = {
debug: vi.fn(),
info: vi.fn(),
warning: vi.fn(),
error: vi.fn(),
setFailed: vi.fn(),
setOutput: vi.fn(),
};
global.core = mockCore;
describe("myFunction", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("handles a normal input", async () => {
const { myFunction } = await import("./my_module.cjs");
expect(myFunction("test input")).toBe("expected output");
});
it("handles empty input", async () => {
const { myFunction } = await import("./my_module.cjs");
expect(myFunction("")).toBe("");
});
});Testing guidelines:
- Use Vitest for test execution
- Mock
coreandgithubglobals as needed - Use dynamic imports (
await import()) to allow module setup at test time - Clear mocks in
beforeEach - Cover success, failure, and edge cases
Run tests:
make test-jsStep 3: Wire the module into the actual build path
Do not add a new //go:embed mapping just to ship a new runtime script. The current repo ships JavaScript through the action-generation/build pipeline.
Use this checklist:
- Shared utility used by generated actions: update the relevant dependency mapping in
pkg/cli/actions_build_command.go - Action-specific source file: add the module under
actions/<action-name>/src/ - Generated action bundle: rebuild with
make actions-build - Shared workflow source for runtime modules: keep it under
pkg/workflow/js/and update the action or workflow definition that consumes it
Example design:
const { myFunction } = require("./my_module.cjs");
async function main() {
const result = myFunction("some input");
core.info(`Result: ${result}`);
}
module.exports = { main };Step 4: Validate the refactor
Run the relevant checks for the area you changed:
make fmt-cjs
make lint-cjs
make test-js
make test-unit
make actions-buildVerification Checklist
Before committing your refactor:
- New
.cjsfile created in the correct source directory - Matching
.test.cjsfile created - Tests pass with
make test-jsor the targeted Vitest suite - The module is wired through the real action/workflow build path
- No stale embedding instructions were added for the current action-based JS build flow
- Local
require()statements work correctly in other JS files - Code formatted with
make fmt-cjs - Relevant validation passes with
make lint-cjsormake test-unit
Common Patterns
Pattern 1: Shared Utility Module
Files like sanitize_content.cjs or load_agent_output.cjs are best kept under pkg/workflow/js/ or actions/setup/js/ and consumed by other JS modules via require().
Pattern 2: Action-specific file
When the JavaScript belongs to a single action, keep it under actions/<action-name>/src/ and regenerate the output bundle with make actions-build.
Pattern 3: Top-level workflow script
If the script is executed directly in a workflow, export main and omit the direct await main() call. The host build/runtime step handles execution.
Troubleshooting
Issue: changes are not showing up in generated actions
Cause: Action bundle was not rebuilt after editing the source file
Solution:
make actions-buildIssue: tests fail with core is not defined
Cause: Missing global mocks
Solution:
global.core = mockCore;Issue: the module is only used in one place
Cause: It was added to the wrong layer
Solution: Move it to the action-specific source tree instead of creating a broad workflow-level registry entry.
Test-Coverage Auditing
Do not audit coverage in actions/setup/js/ by matching foo.cjs to foo.test.cjs by basename. That approach overstates untested files because tests here load sources in three other ways:
- One test file per behavior, not per source:
create_discussion_labels.test.cjsandcreate_discussion_sanitization.test.cjsboth covercreate_discussion.cjs. - Cache-busting dynamic import:
parse_copilot_log.test.cjsusesawait import("./parse_copilot_log.cjs?" + Date.now())to get fresh module state per test. readFileSync+eval:collect_ndjson_output.test.cjsreads the script source withfs.readFileSync(scriptPath, "utf8")and runs it witheval(...).
Resolve require, import, and readFileSync targets from each test file (and their transitive requires) before reporting a source file as untested.
References
actions/README.md- current action-generation/build workflowpkg/cli/actions_build_command.go- action dependency mappingpkg/workflow/js/*.cjs- existing shared module patternsactions/setup/js/*.cjs- action runtime/source examples
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

