Files
kandev/apps/backend/internal/scriptengine/placeholders.go
T
João Salavisa 75f1732421 feat: add GitHub token injection for remote executors and Docker session resume (#654)
* feat: add GitHub token injection for remote executors and Docker session resume

- Add global GitHub access token configuration (backend + frontend)
- Inject GitHub token into Docker and Sprites executors via env vars and Git credential helper
- Transition Docker executor from host mounting to repository cloning
- Implement Docker session resume (reconnect to existing containers after backend restart)
- Add shell validation using exec.LookPath in agentctl
- Add scriptengine providers for agent install and agentctl placeholders

* fix: format github-status.tsx with prettier

* fix: resolve lint issues (goconst, errcheck, file-length)

* fix: address code review findings

- Fix resolveGHCLIToken to check both GITHUB_TOKEN and GH_TOKEN guards
- Fix credential helper to use \\ fallback
- Change /bin/bash to /bin/sh in credential helper for Alpine compat
- Strip embedded token from .git/config after clone in prepare scripts
- Extract buildLaunchAgentRequest helpers to stay under 80-line limit
- Add tests for GitHubAuthProvider, injectTokenIntoURL, reconnect validation
- Add GH_TOKEN-only test case for resolveGHCLIToken

* refactor(executor): extract GitHub credential resolution to separate file

Move injectGitHubToken, injectGitHubTokenFromCLI, resolveRemoteCredentials,
resolveAuthSecrets, methodIDToEnvVar, resolveGHCLIToken, and detectGHToken
out of executor_execute.go (was 803 logical lines, over the 800-line limit
after merging main) into a new executor_credentials.go file. Also adds the
nil-guard on secretStore in resolveAuthSecrets that was flagged by review.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 22:15:50 +01:00

134 lines
4.8 KiB
Go

package scriptengine
// PlaceholderInfo describes an available placeholder for documentation/autocomplete.
type PlaceholderInfo struct {
Key string `json:"key"`
Description string `json:"description"`
Example string `json:"example"`
ExecutorTypes []string `json:"executor_types"`
}
// DefaultPlaceholders is the registry of all available script template placeholders.
var DefaultPlaceholders = []PlaceholderInfo{
{
Key: "repository.path",
Description: "Local repository path on the host machine",
Example: "/Users/dev/myapp",
ExecutorTypes: []string{"local", "worktree"},
},
{
Key: "repository.name",
Description: "Repository name",
Example: "myapp",
ExecutorTypes: []string{"local", "worktree", "local_docker", "remote_docker", "sprites"},
},
{
Key: "repository.clone_url",
Description: "HTTPS clone URL (with auth token injected if available)",
Example: "https://token@github.com/org/myapp.git",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "repository.ssh_url",
Description: "SSH clone URL",
Example: "git@github.com:org/myapp.git",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "repository.branch",
Description: "Target branch name",
Example: "main",
ExecutorTypes: []string{"local", "worktree", "local_docker", "remote_docker", "sprites"},
},
{
Key: "repository.setup_script",
Description: "Repository-level setup script (if configured in repo settings)",
Example: "npm install",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "git.user_name",
Description: "Git author name configured for remote executor",
Example: "Jane Developer",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "git.user_email",
Description: "Git author email configured for remote executor",
Example: "jane@example.com",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "git.identity_setup",
Description: "Expands to git config commands when name/email are provided",
Example: "git config --global user.name 'Jane Developer'",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "workspace.path",
Description: "Working directory for the current executor",
Example: "/workspace",
ExecutorTypes: []string{"local", "worktree", "local_docker", "remote_docker", "sprites"},
},
{
Key: "worktree.base_path",
Description: "Base directory where worktrees are stored",
Example: "/Users/dev/.kandev/worktrees",
ExecutorTypes: []string{"worktree"},
},
{
Key: "worktree.path",
Description: "Resolved worktree directory path for this session",
Example: "/Users/dev/.kandev/worktrees/fix-bug_ab12cd34",
ExecutorTypes: []string{"worktree"},
},
{
Key: "worktree.id",
Description: "Worktree ID for this session",
Example: "f4db4fa6-82f4-4d8d-b29c-6ffbd44f57de",
ExecutorTypes: []string{"worktree"},
},
{
Key: "worktree.branch",
Description: "Created/reused worktree branch name",
Example: "feature/fix-login-abc",
ExecutorTypes: []string{"worktree"},
},
{
Key: "worktree.base_branch",
Description: "Base branch used for worktree creation",
Example: "main",
ExecutorTypes: []string{"worktree"},
},
{
Key: "kandev.agents.install",
Description: "Pre-installs agent CLIs globally for all agents configured on the profile",
Example: "npm install -g @anthropic-ai/claude-code@2.1.50",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "kandev.agentctl.install",
Description: "Expands to full agentctl binary upload and install commands",
Example: "# (multi-line: upload binary, chmod, verify)",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "kandev.agentctl.start",
Description: "Expands to agentctl start command with configured flags",
Example: "agentctl --port 8765 --workspace /workspace &",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "kandev.agentctl.port",
Description: "Agentctl port number",
Example: "8765",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
{
Key: "github.auth_setup",
Description: "Expands to commands that configure gh CLI and git credential helper for GitHub token auth",
Example: "git config --global credential.https://github.com.helper '...'",
ExecutorTypes: []string{"local_docker", "remote_docker", "sprites"},
},
}