Welcome to Chapter 4! In the previous chapter, Precondition Verification, we looked at the "Sensors" that check if the system is ready (like checking if the user is logged in).
Now, we need to look at the most important part of your project: The Code itself.
Imagine you are working on a feature. You change 5 files on your laptop, but you haven't saved them to Git (committed) yet. You hit the "Run Remotely" button.
Here is the nightmare scenario:
To prevent this, our system needs Git Context Awareness. It needs to look at your local folder and ask: "Is the user's code actually ready to be synced?"
We can think of preparing your code for a remote session like Mailing a Package. There are three questions we must answer before the mailman takes it.
First, do you even have a box? You can't mail loose items.
git init).checkIsInGitRepo()Is the box taped shut? If you have files that are modified but not committed, your box is "open." Contents might fall out or get lost during the trip.
git status shows no modified files.checkIsGitClean()Does the box have a destination label?
origin).checkHasGitRemote()Let's look at how we check these states using our helper functions.
This is the most basic check. It simply looks for a .git folder.
import { checkIsInGitRepo } from 'remote/preconditions'
// Returns TRUE if we are inside a Git project
const hasBox = checkIsInGitRepo()
if (!hasBox) {
console.log("You must initialize Git first!")
}
This is crucial for data safety. We usually block remote sessions if the user has "dirty" (uncommitted) files, because we can't guarantee those changes will make it to the server safely.
import { checkIsGitClean } from 'remote/preconditions'
async function validateSafety() {
// Returns TRUE only if all changes are committed
const isSealed = await checkIsGitClean()
if (!isSealed) {
console.log("Please commit your changes first.")
}
}
Finally, we check if there is a link to GitHub.
import { checkHasGitRemote } from 'remote/preconditions'
async function checkDestination() {
// Returns TRUE if 'origin' exists
const hasAddress = await checkHasGitRemote()
return hasAddress
}
How does the system actually know these things? It acts like a wrapper around the standard git command line tools you use every day.
When you call checkIsGitClean, the system has a conversation with the underlying OS.
Let's peek under the hood at remote/preconditions.ts.
We use a helper getIsClean. Notice the option ignoreUntracked: true. This is a friendly setting: if you have a new file you haven't added yet, we generally don't stop you. We only care about modified files that track changes.
// File: remote/preconditions.ts
export async function checkIsGitClean(): Promise<boolean> {
// check if there are modifications to tracked files
const isClean = await getIsClean({ ignoreUntracked: true })
return isClean
}
This function is synchronous (no async) because it just looks at the file path string to see if it can find a root folder.
// File: remote/preconditions.ts
export function checkIsInGitRepo(): boolean {
// findGitRoot searches up the folder tree for .git/
return findGitRoot(getCwd()) !== null
}
This check is smarter. It tries to detect details. If it finds details (like "owner: anthropics", "repo: claude"), it proves a remote exists.
// File: remote/preconditions.ts
export async function checkHasGitRemote(): Promise<boolean> {
// Try to parse the .git/config file
const repository = await detectCurrentRepository()
// If we found data, we have a remote!
return repository !== null
}
In Session Eligibility Gatekeeper, we saw the "Bouncer." Now you understand exactly what the Bouncer is looking for when it asks about Git.
!checkIsInGitRepo(): Stop. We can't track code without Git.!checkIsGitClean(): Warning. "You have uncommitted changes."!checkHasGitRemote(): Logic branching.In this chapter, we learned:
checkIsGitClean to ensure the user has saved their work before teleporting.
Now we know the code is safe and ready. But waitβjust because the code exists on GitHub (checkHasGitRemote is true), does that mean we are allowed to download it?
We need to check our permissions.
Next Chapter: GitHub Repository Access
Generated by Code IQ