Skip to content
Merged
67 changes: 47 additions & 20 deletions DEADCODE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,37 @@ These are the JS bundler subsystem — entirely unused.

## Phase 2: Near-Fully Dead Files (high value, some surgery)

These files are mostly dead and worth cleaning next:

- [ ] `pkg/workflow/script_registry.go` (11/13 dead) — keep only `GetActionPath`, `DefaultScriptRegistry`
- [ ] `pkg/workflow/artifact_manager.go` (14/16 dead) — remove 14 functions
- [ ] `pkg/constants/constants.go` (13/27 dead) — remove 13 constants
- [ ] `pkg/workflow/map_helpers.go` (5/7 dead) — remove 5 functions
- [ ] `pkg/workflow/js.go` (17/47 dead) — remove 17 JS bundle functions
- [ ] `pkg/workflow/compiler_types.go` (17/45 dead) — remove 17 types/methods
- [x] `pkg/workflow/script_registry.go` — rewritten minimal in batch 2 ✅
- [x] `pkg/workflow/compiler_types.go` — 7 dead `With*` option funcs + 3 getters removed in batch 3; **10 dead remain** (see batch 4)
- [x] `pkg/workflow/js.go` — 10 dead bundle/Get* funcs removed in batch 3; **7 dead remain** (see batch 4)
- [ ] `pkg/workflow/artifact_manager.go` — **14 dead** — but tests call many of these; skip or do last
- [ ] `pkg/constants/constants.go` — **13 dead** (all `String()`/`IsValid()` methods on type aliases) — safe to remove
- [ ] `pkg/workflow/map_helpers.go` — **5 dead** — check test callers before removing

---

## Phase 3: Partially Dead Files (1–6 dead per file)

Individual function removals across ~100 files. To be tackled after Phase 1 and 2.

High-count files to prioritize:
- `pkg/workflow/expression_builder.go` (9/27 dead)
- `pkg/workflow/validation_helpers.go` (6/10 dead)
- `pkg/cli/docker_images.go` (6/11 dead)
- `pkg/workflow/domains.go` (10/27 dead)
## Phase 3 / Batch 4 Targets (current dead count: 259)

Remaining high-value clusters from `deadcode ./cmd/... ./internal/tools/...`:

| File | Dead | Notes |
|------|------|-------|
| `pkg/workflow/artifact_manager.go` | 14 | Many test callers; do last |
| `pkg/constants/constants.go` | 13 | All `String()`/`IsValid()` on semantic types; safe |
| `pkg/workflow/domains.go` | 10 | Check callers |
| `pkg/workflow/compiler_types.go` | 10 | Remaining With*/Get* |
| `pkg/workflow/expression_builder.go` | 9 | Check callers |
| `pkg/workflow/js.go` | 7 | Remaining Get* stubs |
| `pkg/workflow/validation_helpers.go` | 6 | Check callers |
| `pkg/cli/docker_images.go` | 6 | Check callers |
| `pkg/workflow/permissions_factory.go` | 5 | Check callers |
| `pkg/workflow/map_helpers.go` | 5 | Check callers |
| `pkg/workflow/engine_helpers.go` | 5 | Check callers |
| `pkg/console/console.go` | 5 | Check callers |
| `pkg/workflow/safe_outputs_env.go` | 4 | Check callers |
| `pkg/workflow/expression_nodes.go` | 4 | Check callers |

**Long tail:** ~80 remaining files with 1–3 dead functions each.

---

Expand All @@ -151,9 +162,25 @@ Deleted 17 files, surgery on 6 test files. `go build ./...` + `go vet ./...` + `

Deferred `pkg/stringutil/paths.go` to Batch 2 — callers in bundler files still present.

#### Batch 2: Groups 1D + 1E (Workflow fully dead) — TODO
#### Batch 3: Phase 2 (Near-fully dead, high-value partial files) — TODO
#### Batch 4: Phase 3 (Individual function removals) — TODO
#### Batch 2: Groups 1D + 1E (Workflow fully dead) — COMPLETE ✅

Deleted 35 files (bundler subsystem + env_mirror, copilot_participant_steps, dependency_tracker,
markdown_unfencing, prompt_step, safe_output_builder, sh.go, stringutil/paths.go).
Rescued: `prompt_constants.go`, `setup_action_paths.go`. Rewrote `script_registry.go` minimal.
Surgery on 12 test files. ~7,856 lines deleted.

⚠️ **Lessons learned in batch 2:**
- `go vet ./...` misses integration tests — MUST also run `go vet -tags=integration ./...`
- `cmd/gh-aw-wasm/` has `//go:build js && wasm` — deadcode can't see it; `compiler_string_api.go` was wrongly deleted and restored
- Always check `cmd/gh-aw-wasm/main.go` before deleting `pkg/workflow` functions

#### Batch 3: Phase 2 partial (compiler_types + js.go) — COMPLETE ✅

Removed 7 dead `With*` option funcs + 3 dead getters from `compiler_types.go`.
Removed 10 dead Get*/bundle funcs from `js.go`.
~133 lines deleted. Dead count: 362 → 259.

#### Batch 4: Remaining Phase 2 + Phase 3 (individual removals) — TODO

---

Expand Down
37 changes: 0 additions & 37 deletions pkg/workflow/compiler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ func WithVersion(version string) CompilerOption {
return func(c *Compiler) { c.version = version }
}

// WithActionMode overrides the auto-detected action mode
func WithActionMode(mode ActionMode) CompilerOption {
return func(c *Compiler) { c.actionMode = mode }
}

// WithSkipValidation configures whether to skip schema validation
func WithSkipValidation(skip bool) CompilerOption {
return func(c *Compiler) { c.skipValidation = skip }
Expand Down Expand Up @@ -67,23 +62,6 @@ func WithWorkflowIdentifier(identifier string) CompilerOption {
return func(c *Compiler) { c.workflowIdentifier = identifier }
}

// WithRepositorySlug sets the repository slug for schedule scattering
func WithRepositorySlug(slug string) CompilerOption {
return func(c *Compiler) { c.repositorySlug = slug }
}

// WithGitRoot sets the git repository root directory for action cache path
func WithGitRoot(gitRoot string) CompilerOption {
return func(c *Compiler) { c.gitRoot = gitRoot }
}

// WithInlinePrompt configures whether to inline markdown content directly in the compiled YAML
// instead of using runtime-import macros. This is required for Wasm/browser builds where
// the filesystem is unavailable at runtime.
func WithInlinePrompt(inline bool) CompilerOption {
return func(c *Compiler) { c.inlinePrompt = inline }
}

// FileTracker interface for tracking files created during compilation
type FileTracker interface {
TrackCreated(filePath string)
Expand All @@ -99,11 +77,6 @@ func SetDefaultVersion(version string) {
defaultVersion = version
}

// GetDefaultVersion returns the default version
func GetDefaultVersion() string {
return defaultVersion
}

// Compiler handles converting markdown workflows to GitHub Actions YAML
type Compiler struct {
verbose bool
Expand Down Expand Up @@ -281,21 +254,11 @@ func (c *Compiler) SetWorkflowIdentifier(identifier string) {
c.workflowIdentifier = identifier
}

// GetWorkflowIdentifier returns the current workflow identifier
func (c *Compiler) GetWorkflowIdentifier() string {
return c.workflowIdentifier
}

// SetRepositorySlug sets the repository slug for schedule scattering
func (c *Compiler) SetRepositorySlug(slug string) {
c.repositorySlug = slug
}

// GetRepositorySlug returns the repository slug
func (c *Compiler) GetRepositorySlug() string {
return c.repositorySlug
}

// GetScheduleWarnings returns all accumulated schedule warnings for this compiler instance
func (c *Compiler) GetScheduleWarnings() []string {
return c.scheduleWarnings
Expand Down
96 changes: 0 additions & 96 deletions pkg/workflow/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ func GetLogParserBootstrap() string {
return ""
}

func GetSafeOutputsMCPServerScript() string {
return ""
}

func GetSafeOutputsToolsJSON() string {
return safeOutputsToolsJSONContent
}
Expand All @@ -121,10 +117,6 @@ func GetMCPLoggerScript() string {
return ""
}

func GetSafeInputsMCPServerScript() string {
return ""
}

func GetSafeInputsMCPServerHTTPScript() string {
return ""
}
Expand All @@ -133,14 +125,6 @@ func GetSafeInputsConfigLoaderScript() string {
return ""
}

func GetSafeInputsToolFactoryScript() string {
return ""
}

func GetSafeInputsBootstrapScript() string {
return ""
}

func GetSafeInputsValidationScript() string {
return ""
}
Expand All @@ -153,26 +137,6 @@ func GetMCPHandlerPythonScript() string {
return ""
}

func GetSafeOutputsConfigScript() string {
return ""
}

func GetSafeOutputsAppendScript() string {
return ""
}

func GetSafeOutputsHandlersScript() string {
return ""
}

func GetSafeOutputsToolsLoaderScript() string {
return ""
}

func GetSafeOutputsBootstrapScript() string {
return ""
}

// Helper functions for formatting JavaScript in YAML

func removeJavaScriptComments(code string) string {
Expand Down Expand Up @@ -543,64 +507,4 @@ func WriteJavaScriptToYAML(yaml *strings.Builder, script string) {
}
}

// WriteJavaScriptToYAMLPreservingComments writes a JavaScript script with proper indentation to a strings.Builder
// while preserving JSDoc and inline comments, but removing TypeScript-specific comments.
// Used for security-sensitive scripts like redact_secrets.
func WriteJavaScriptToYAMLPreservingComments(yaml *strings.Builder, script string) {
// Validate that script is not empty - this helps catch errors where getter functions
// return empty strings after embedded scripts were removed
if strings.TrimSpace(script) == "" {
jsLog.Print("WARNING: Attempted to write empty JavaScript script to YAML (preserving comments)")
return
}

scriptLines := strings.Split(script, "\n")
previousLineWasEmpty := false
hasWrittenContent := false // Track if we've written any content yet

for i, line := range scriptLines {
trimmed := strings.TrimSpace(line)

// Skip TypeScript-specific comments
if strings.HasPrefix(trimmed, "// @ts-") || strings.HasPrefix(trimmed, "/// <reference") {
continue
}

// Handle empty lines
if trimmed == "" {
// Don't add blank lines at the beginning of the script
if !hasWrittenContent {
continue
}

// Look ahead to see if the next non-empty line is a JSDoc comment or function
shouldKeepBlankLine := false
for j := i + 1; j < len(scriptLines); j++ {
nextTrimmed := strings.TrimSpace(scriptLines[j])
if nextTrimmed == "" {
continue
}
// Keep blank line if followed by JSDoc or function/const/async
if strings.HasPrefix(nextTrimmed, "/**") ||
strings.HasPrefix(nextTrimmed, "function ") ||
strings.HasPrefix(nextTrimmed, "async function") ||
strings.HasPrefix(nextTrimmed, "await main(") {
shouldKeepBlankLine = true
}
break
}

if shouldKeepBlankLine && !previousLineWasEmpty {
fmt.Fprintf(yaml, "\n")
previousLineWasEmpty = true
}
continue
}

fmt.Fprintf(yaml, " %s\n", line)
previousLineWasEmpty = false
hasWrittenContent = true
}
}

// GetLogParserScript returns the JavaScript content for a log parser by name
Loading