Skip to content

Replace lint-monster path literals with repository constants in CLI/workflow codepaths#41611

Merged
pelikhan merged 2 commits into
mainfrom
copilot/lint-monster-path-constants-cleanup
Jun 26, 2026
Merged

Replace lint-monster path literals with repository constants in CLI/workflow codepaths#41611
pelikhan merged 2 commits into
mainfrom
copilot/lint-monster-path-constants-cleanup

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This change addresses the lint-monster path-constants cleanup by removing hard-coded repository/runtime paths in the flagged files and switching to existing pkg/constants values. Scope is limited to direct literal-to-constant substitutions while preserving path semantics (including trailing-slash behavior).

  • Workflow/GitHub path constant adoption

    • pkg/cli/add_package_manifest.go
      • Replaced inline .github/... and .github/workflows... fragments with constants.GithubDir, constants.WorkflowsDir, and constants.WorkflowsDirSlash.
      • Updated source directory and prefix/root checks to use constants consistently.
    • pkg/cli/audit.go, pkg/cli/audit_comparison.go
      • Replaced .github/ workflow-name prefix checks with constants.GithubDir.
    • pkg/cli/experiments_command.go, pkg/cli/fetch.go
      • Replaced .github/workflows/ construction/fallback prefixes with constants.WorkflowsDirSlash.
  • AWF/runtime tmp-path constant adoption

    • pkg/cli/firewall_policy.go
      • Replaced /tmp/gh-aw/sandbox/firewall/audit label/path literal usage with constants.AWFAuditDir.
    • pkg/workflow/opencode_engine.go
      • Replaced /tmp/gh-aw/aw-prompts/prompt.txt in both command and env wiring with constants.AwPromptsFile.
  • Representative change

    // before
    promptArg := "\"$(cat /tmp/gh-aw/aw-prompts/prompt.txt)\""
    env := map[string]string{"GH_AW_PROMPT": "/tmp/gh-aw/aw-prompts/prompt.txt"}
    
    // after
    promptArg := fmt.Sprintf("\"$(cat %s)\"", constants.AwPromptsFile)
    env := map[string]string{"GH_AW_PROMPT": constants.AwPromptsFile}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Clean up hard-coded path constants in CLI Replace lint-monster path literals with repository constants in CLI/workflow codepaths Jun 26, 2026
Copilot AI requested a review from pelikhan June 26, 2026 05:54
@pelikhan
pelikhan marked this pull request as ready for review June 26, 2026 06:02
Copilot AI review requested due to automatic review settings June 26, 2026 06:02
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped. PR #41611 only modifies production Go files (pkg/cli/.go, pkg/workflow/.go) to replace lint-monster path literals with repository constants.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #41611 does not have the 'implementation' label and has only 23 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request removes hard-coded repository/runtime path literals in several CLI and workflow engine codepaths, replacing them with shared values from pkg/constants to keep path semantics consistent (including trailing-slash behavior) and reduce drift across the codebase.

Changes:

  • Swapped .github/ and .github/workflows/ string literals for constants.GithubDir, constants.WorkflowsDir, and constants.WorkflowsDirSlash in CLI prefix checks and remote-path construction.
  • Replaced AWF/runtime /tmp/gh-aw/... literals with constants.AWFAuditDir and constants.AwPromptsFile.
  • Updated package manifest path validation and root/prefix handling to use the shared constants.
Show a summary per file
File Description
pkg/cli/add_package_manifest.go Replaces .github/... and workflows path literals with constants.GithubDir / constants.WorkflowsDirSlash in include/path validation and scanning.
pkg/cli/audit.go Uses constants.GithubDir for workflow-name prefix detection when resolving display names.
pkg/cli/audit_comparison.go Uses constants.GithubDir for workflow-name prefix detection in baseline run selection.
pkg/cli/experiments_command.go Builds remote workflow content API paths using constants.WorkflowsDirSlash.
pkg/cli/fetch.go Uses constants.WorkflowsDirSlash for fallback remote workflow path prefixes.
pkg/cli/firewall_policy.go Uses constants.AWFAuditDir for the legacy artifact label/path suffix.
pkg/workflow/opencode_engine.go Uses constants.AwPromptsFile for the prompt file path in both command construction and env wiring.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Low

@github-actions github-actions Bot mentioned this pull request Jun 26, 2026
@pelikhan
pelikhan merged commit 865e468 into main Jun 26, 2026
75 of 86 checks passed
@pelikhan
pelikhan deleted the copilot/lint-monster-path-constants-cleanup branch June 26, 2026 06:14

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /improve-codebase-architecture, /zoom-out, and /tdd — approving with minor suggestions.

📋 Key Themes & Highlights

Key Themes

  • Pattern repetition: constants.GithubDir + packageSkillsDirectory/Agents is constructed 8 times — package-level vars would DRY this up.
  • Partial cleanup: "workflows/" and "agentic-workflows/" are still hardcoded literals alongside the now-constant WorkflowsDirSlash in isSupportedPackageInstallablePath.
  • Spec-test gap: AWFAuditDir has a spec-pin test; GithubDir, WorkflowsDirSlash, and AwPromptsFile do not — worth adding given they're now relied on across 7 files.

Positive Highlights

  • ✅ Correct use of WorkflowsDir vs WorkflowsDirSlash in every context — trailing-slash semantics are fully preserved.
  • ✅ Scope is appropriately tight: only the flagged literals, no collateral changes.
  • ✅ All substitutions are semantically equivalent; no behavioral drift.
  • AwPromptsFile adoption in opencode_engine.go is clean — both the CLI arg and the GH_AW_PROMPT env var are updated together.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 83.7 AIC · ⌖ 11.1 AIC · ⊞ 6.5K

func isSupportedSkillDirectoryPrefix(cleaned string) bool {
return strings.HasPrefix(cleaned, packageSkillsDirectory+"/") ||
strings.HasPrefix(cleaned, ".github/"+packageSkillsDirectory+"/")
strings.HasPrefix(cleaned, constants.GithubDir+packageSkillsDirectory+"/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/improve-codebase-architecture] The expressions constants.GithubDir + packageSkillsDirectory and constants.GithubDir + packageAgentsDirectory are now repeated 3–4 times each. Consider hoisting them into package-level vars to reduce silent coupling.

💡 Suggested refactor

Add two vars near the existing constants:

// Derived from constants.GithubDir; centralises the composition rule.
var githubSkillsDir = constants.GithubDir + packageSkillsDirectory // ".github/skills"
var githubAgentsDir = constants.GithubDir + packageAgentsDirectory // ".github/agents"

Then use githubSkillsDir / githubAgentsDir throughout isSupportedSkillDirectoryPrefix, skillDirectoryRoot, scanPackageSkillDirs, etc.

If GithubDir ever changes, there would be one correction point instead of eight.

return strings.HasPrefix(cleaned, "workflows/") ||
strings.HasPrefix(cleaned, "agentic-workflows/") ||
strings.HasPrefix(cleaned, ".github/workflows/")
strings.HasPrefix(cleaned, constants.WorkflowsDirSlash)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/zoom-out] Good — constants.WorkflowsDirSlash is now used correctly here. Two sibling prefixes on lines 757–758 ("workflows/" and "agentic-workflows/") are still raw string literals. The cleanup is consistent for .github/workflows/ but not for the alternate path roots.

💡 Options

Either:

  • Define const WorkflowsAltDir = "workflows/" and const AgenticWorkflowsDir = "agentic-workflows/" in pkg/constants so all three prefix checks are driven by constants, or
  • Add a // TODO: add constants for "workflows/" and "agentic-workflows/" alt paths comment to track the remaining cleanup.

The current mix of constants and literals at the same call site makes it easy to miss if one prefix needs updating.


env := map[string]string{
"GH_AW_PROMPT": "/tmp/gh-aw/aw-prompts/prompt.txt",
"GH_AW_PROMPT": constants.AwPromptsFile,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] AWFAuditDir has a spec-pin assertion in pkg/constants/spec_test.go that would catch a silent value change. AwPromptsFile, GithubDir, and WorkflowsDirSlash — all now load-bearing for path resolution in 7 files — lack equivalent assertions.

💡 Suggested additions to spec_test.go
assert.Equal(t, ".github/", constants.GithubDir,
    "GithubDir must carry trailing slash — callers depend on direct concatenation")
assert.Equal(t, ".github/workflows/", constants.WorkflowsDirSlash,
    "WorkflowsDirSlash must end with '/' for HasPrefix path checks")
assert.Equal(t, "/tmp/gh-aw/aw-prompts/prompt.txt", constants.AwPromptsFile,
    "AwPromptsFile is wired into GH_AW_PROMPT and the opencode CLI arg")

This mirrors the existing AWFAuditDir test and ensures any accidental constant change surfaces immediately rather than failing silently in runtime path logic.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All constant substitutions are semantically correct — values match their replaced literals exactly, imports are present where needed, and no functional behavior changes. Two non-blocking observations logged as inline comments.

Findings summary

Medium: AWFAuditDir semantic mismatch (firewall_policy.go:468)

AWFAuditDir is an absolute-path constant (/tmp/gh-aw/sandbox/firewall/audit). The label agentBase+constants.AWFAuditDir produces the right string only because the constant begins with /. The constant documents a runtime filesystem path, not an artifact-internal label fragment — these are different concepts that happen to share the same string value. If the constant ever changes to not start with /, the label silently computes wrong.

Low: fmt.Sprintf for constant-only shell command construction (opencode_engine.go:122)

fmt.Sprintf("\"\"", constants.AwPromptsFile) is unnecessary — AwPromptsFile is a compile-time constant. More importantly, %s inside $(cat ...) is a shell-injection pattern: if this is later extended to use a mutable path, the risk becomes real. Simple concatenation makes the static nature explicit.

Sub-agent note

The grumpy-coder first-pass agent did not complete within the timeout; second-pass analysis was performed independently.

🔎 Code quality review by PR Code Quality Reviewer · 143.7 AIC · ⌖ 7.04 AIC · ⊞ 5.2K

// Old artifact structure (/tmp/gh-aw/ prefix preserved inside the artifact):
// <agentDir>/tmp/gh-aw/sandbox/firewall/audit/
checkDir(filepath.Join(agentDir, "tmp", "gh-aw", "sandbox", "firewall", "audit"), agentBase+"/tmp/gh-aw/sandbox/firewall/audit")
checkDir(filepath.Join(agentDir, "tmp", "gh-aw", "sandbox", "firewall", "audit"), agentBase+constants.AWFAuditDir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic mismatch: AWFAuditDir (absolute path) used as a relative label suffix — the label is correct only because the constant starts with /, which is incidental and fragile.

💡 Details

AWFAuditDir = "/tmp/gh-aw/sandbox/firewall/audit" is documented as an absolute runtime filesystem path. Here it serves as a string suffix in a display label:

agentBase + constants.AWFAuditDir   // → "<base>/tmp/gh-aw/sandbox/firewall/audit"

This produces the right output only because the constant starts with /, acting as a path separator. If AWFAuditDir is ever reorganized or changed to not start with /, this label silently computes a wrong string with no compile-time warning.

The old literal "/tmp/gh-aw/sandbox/firewall/audit" was unambiguous as an artifact-structure label. Consider keeping the literal in this context (artifact label ≠ live filesystem path), or introducing a dedicated constant for the artifact-internal path suffix.


openCodeArgs = append(openCodeArgs, "--print-logs", "--log-level", "DEBUG")
promptArg := "\"$(cat /tmp/gh-aw/aw-prompts/prompt.txt)\""
promptArg := fmt.Sprintf("\"$(cat %s)\"", constants.AwPromptsFile)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Sprintf is unnecessary for a constant-only substitution and sets a fragile shell-command pattern — simple concatenation avoids both the allocation and the implicit %s-in-shell-command footgun.

💡 Details

constants.AwPromptsFile is a compile-time constant, so fmt.Sprintf("\"\"", constants.AwPromptsFile) is equivalent to a string literal. The %s format verb here is problematic as a pattern: "" is a shell command template, and %s in shell context is a shell-injection point if the argument is ever made mutable.

The original literal was unambiguous — it was obviously a static string. The new form looks like it was designed to accept a variable path, which it wasn't.

Prefer:

promptArg := `""`

Or, if the escape-heavy form is needed for readability:

promptArg := "\"\""`

This makes the static nature explicit and removes the fmt import dependency for this callsite.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @copilot-swe-agent 👋 — nice work on the lint-monster path-constants cleanup! The scope is tight and the literal-to-constant substitutions read cleanly across all seven files.

One thing that would strengthen this before merge:

  • Add or verify test coverage — no test files were touched in this diff. While the substitutions are semantically equivalent, a quick scan of the existing test suite for these paths would confirm nothing regressed. If tests already exercise these code paths indirectly (e.g. via isSupportedPackageInstallablePath, isSupportedSkillDirectoryPrefix, detectFirewallAuditArtifacts, GetExecutionSteps), a note in the PR body confirming that would also help reviewers.

If you'd like a hand, you can assign this prompt to your coding agent:

Audit the test files for the following functions changed in PR #41611 and add missing unit-test coverage where none exists:
- isSupportedPackageInstallablePath (pkg/cli/add_package_manifest.go)
- isSupportedSkillDirectoryPrefix / skillDirectoryRoot / isSupportedAgentDirectoryPrefix / agentDirectoryRoot (pkg/cli/add_package_manifest.go)
- fetchWorkflowRunMetadata and findPreviousSuccessfulWorkflowRuns (pkg/cli/audit.go, pkg/cli/audit_comparison.go)
- GetExecutionSteps for OpenCodeEngine (pkg/workflow/opencode_engine.go)

For each function, verify the relevant test file exercises the .github/ and /tmp/gh-aw/ path branches that were converted to constants. Add table-driven tests for any branch not currently covered. Do not change production code.

Generated by ✅ Contribution Check · 313.5 AIC · ⌖ 31.5 AIC · ⊞ 6K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants