(repoType: 'git' | 'sl')
| 22 | ] |
| 23 | |
| 24 | function getPromptContent(repoType: 'git' | 'sl'): string { |
| 25 | const { commit: commitAttribution } = getAttributionTexts() |
| 26 | |
| 27 | let prefix = '' |
| 28 | if (isInternalBuild() && isUndercover()) { |
| 29 | prefix = getUndercoverInstructions() + '\n' |
| 30 | } |
| 31 | |
| 32 | const isGit = repoType === 'git' |
| 33 | const statusCmd = isGit ? 'git status' : 'sl status' |
| 34 | const diffCmd = isGit ? 'git diff HEAD' : 'sl diff' |
| 35 | const branchCmd = isGit ? 'git branch --show-current' : 'sl book' |
| 36 | const logCmd = isGit ? 'git log --oneline -10' : `sl log -l 10 -T '{node|short} {desc|firstline}'` |
| 37 | const overviewCmd = isGit ? logCmd : 'sl smartlog' |
| 38 | const overviewLabel = isGit ? 'Recent commits' : 'Commit graph' |
| 39 | const extraLogLine = isGit ? '' : `\n- Recent commits: !\`${logCmd}\`` |
| 40 | const scmSafety = isGit ? 'Git Safety Protocol' : 'Sl Safety Protocol' |
| 41 | const configWarning = isGit ? 'NEVER update the git config' : 'NEVER update the sl config' |
| 42 | const amendWarning = isGit ? 'NEVER use git commit --amend' : 'NEVER use sl commit --amend' |
| 43 | const interactiveWarning = isGit |
| 44 | ? 'Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported' |
| 45 | : 'Never use sl commands with the -i flag (like sl rebase -i or sl add -i) since they require interactive input which is not supported' |
| 46 | const commitCmd = isGit ? 'git commit' : 'sl commit' |
| 47 | const stageInstruction = isGit |
| 48 | ? 'Stage relevant files and create the commit using HEREDOC syntax:' |
| 49 | : 'Sapling has no staging area — all modifications to tracked files are automatically included by `sl commit`. Only use `sl add` for previously untracked files. Create the commit using HEREDOC syntax:' |
| 50 | |
| 51 | return `${prefix}## Context |
| 52 | |
| 53 | - Current ${repoType} status: !\`${statusCmd}\` |
| 54 | - Current ${repoType} diff: !\`${diffCmd}\` |
| 55 | - Current ${isGit ? 'branch' : 'bookmark'}: !\`${branchCmd}\` |
| 56 | - ${overviewLabel}: !\`${overviewCmd}\`${extraLogLine} |
| 57 | |
| 58 | ## ${scmSafety} |
| 59 | |
| 60 | - ${configWarning} |
| 61 | - NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it |
| 62 | - CRITICAL: ALWAYS create NEW commits. ${amendWarning}, unless the user explicitly requests it |
| 63 | - Do not commit files that likely contain secrets (.env, credentials.json, etc). Warn the user if they specifically request to commit those files |
| 64 | - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit |
| 65 | - ${interactiveWarning} |
| 66 | |
| 67 | ## Your task |
| 68 | |
| 69 | Based on the above changes, create a single ${repoType} commit: |
| 70 | |
| 71 | 1. Analyze all changes and draft a commit message: |
| 72 | - Look at the recent commits above to follow this repository's commit message style |
| 73 | - Summarize the nature of the changes (new feature, enhancement, bug fix, refactoring, test, docs, etc.) |
| 74 | - Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.) |
| 75 | - Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what" |
| 76 | |
| 77 | 2. ${stageInstruction} |
| 78 | \`\`\` |
| 79 | ${commitCmd} -m "$(cat <<'EOF' |
| 80 | Commit message here.${commitAttribution ? `\n\n${commitAttribution}` : ''} |
| 81 | EOF |
no test coverage detected