Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/powershell-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
run: |
./tests/Test-Source.ps1
./tests/Test-Workspaces.ps1
./tests/Test-SessionContext.ps1
./tests/Test-CatalogueBridge.ps1

validate-powershell-7:
Expand All @@ -30,4 +31,5 @@ jobs:
run: |
./tests/Test-Source.ps1
./tests/Test-Workspaces.ps1
./tests/Test-SessionContext.ps1
./tests/Test-CatalogueBridge.ps1
1 change: 1 addition & 0 deletions ProjectShell.Workspaces.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ function Start-ProfileLaunchable($Profile) {
Write-Host 'A standard profile launch cannot run from an elevated session.' -ForegroundColor Yellow
return
}
Set-ProjectShellLaunchContext $Profile
Invoke-SavedTool (Get-ProfileLaunchable $Profile) ([string]$Profile.StartDirectory)
}

Expand Down
13 changes: 13 additions & 0 deletions ProjectShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,25 @@ function Set-ProjectTitle([string]$Name) {
try { $Host.UI.RawUI.WindowTitle = $Name } catch { }
}

function Set-ProjectShellLaunchContext($entry) {
# Process-local handoff only. Descendant tools (for example GPB) can offer
# this saved starting folder as an editable default even after cd elsewhere.
# Do NOT persist a user/machine environment variable or disclose profiles.json.
$folder = [string]$entry.StartDirectory
if (-not (Test-Path -LiteralPath $folder -PathType Container)) {
throw ('ProjectShell configured starting folder is missing: ' + $folder)
}
$env:PROJECTSHELL_START_DIRECTORY = [IO.Path]::GetFullPath($folder)
}

function Invoke-ProjectTask($entry) {
Set-ProjectTitle $entry.Name
if (-not (Test-Path -LiteralPath $entry.StartDirectory -PathType Container)) {
Write-Host ('Missing starting folder: ' + $entry.StartDirectory) -ForegroundColor Red
return
}
Set-Location -LiteralPath $entry.StartDirectory
Set-ProjectShellLaunchContext $entry
Write-Host ''
Write-Host '============================================================' -ForegroundColor Cyan
Write-Host (' ' + $entry.Name) -ForegroundColor Cyan
Expand Down Expand Up @@ -947,6 +959,7 @@ function Invoke-ProjectTask($entry) {
function Show-OpenProjectMenu([string]$Id) {
while ($true) {
$entry = Get-ProfileById $Id
Set-ProjectShellLaunchContext $entry
Set-ProjectTitle $entry.Name
Write-Host ''
Write-Host (' ' + $entry.Name + ' | SESSION MENU') -ForegroundColor Cyan
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ ProjectShell keeps your settings on your own computer:
| Optional Catalogue location and generated broker requests | `%LOCALAPPDATA%\ProjectShell\catalogue-integration.json` and `dependency-requests\` |
| Created project shortcuts | The Windows desktop folder chosen during installation |

When a ProjectShell project session starts, it now exports the profile's saved `StartDirectory` as the **process-local** environment variable `PROJECTSHELL_START_DIRECTORY`. Child applications such as GitHub Package Builder can use this as an editable default even if you change the working directory. It is **not** a system-wide or persistent environment setting, and ProjectShell does not expose private profile JSON to applications. Older ProjectShell versions still set the initial working directory, which applications may use as a fallback.

Updating ProjectShell keeps your saved profiles, workspace registry, and startup commands in place. These personal files aren't meant to go in the public GitHub repository. **Don't upload your profiles, settings, logs, backups, or personal `.lnk` files**, since they may reveal local folders or commands.

## If a shortcut isn't working
Expand Down
50 changes: 50 additions & 0 deletions tests/Test-SessionContext.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Test only the process-local ProjectShell starting-folder handoff, not UI/install.
$ErrorActionPreference = 'Stop'
$sourcePath = Join-Path (Split-Path -Parent $PSScriptRoot) 'ProjectShell.ps1'
$tokens = $null
$errors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile(
$sourcePath, [ref]$tokens, [ref]$errors
)
if ($errors.Count -ne 0) { throw 'Cannot parse ProjectShell source.' }
$fn = $ast.Find({
param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
$node.Name -eq 'Set-ProjectShellLaunchContext'
}, $true)
if (-not $fn) { throw 'ProjectShell session-context function is absent.' }

# Import only this one function, avoiding loading profiles or invoking the manager.
. ([scriptblock]::Create($fn.Extent.Text))
$key = 'PROJECTSHELL_START_DIRECTORY'
$before = [Environment]::GetEnvironmentVariable($key, 'Process')
$userBefore = [Environment]::GetEnvironmentVariable($key, 'User')
$machineBefore = [Environment]::GetEnvironmentVariable($key, 'Machine')

try {
$target = Split-Path -Parent $PSScriptRoot
Set-ProjectShellLaunchContext ([pscustomobject]@{ StartDirectory = $target })
$actual = [Environment]::GetEnvironmentVariable($key, 'Process')
if ([IO.Path]::GetFullPath($actual).TrimEnd('\') -ne [IO.Path]::GetFullPath($target).TrimEnd('\')) {
throw 'Process-local starting-folder handoff does not match the saved profile.'
}
$nonexistent = Join-Path $target ('No-Such-ProjectShell-Folder-' + [guid]::NewGuid().ToString('N'))
try {
Set-ProjectShellLaunchContext ([pscustomobject]@{ StartDirectory = $nonexistent })
throw 'Invalid starting folder did not fail closed.'
}
catch {
if ($_.Exception.Message -match 'Invalid starting folder did not fail closed') { throw }
}
if ([Environment]::GetEnvironmentVariable($key, 'Process') -ne $actual) {
throw 'Invalid folder unexpectedly changed the existing process context.'
}
if ([Environment]::GetEnvironmentVariable($key, 'User') -ne $userBefore -or
[Environment]::GetEnvironmentVariable($key, 'Machine') -ne $machineBefore) {
throw 'Profile handoff wrote persistent User/Machine environment variables.'
}
Write-Host 'PROJECTSHELL_PROCESS_STARTDIRECTORY_HANDOFF_PASSED' -ForegroundColor Green
}
finally {
[Environment]::SetEnvironmentVariable($key, $before, 'Process')
}
1 change: 1 addition & 0 deletions tests/Test-Source.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $checks = @(
@{ Name='Catalogue preview only'; Pass=($catalogue.Contains('schema_version=1') -and $catalogue.Contains('dependency-request') -and -not $catalogue.Contains('--interactive-apply') -and -not $catalogue.Contains('Start-Process')) },
@{ Name='Workspace module installed'; Pass=($installer.Contains('ProjectShell.Workspaces.ps1') -and $app.Contains('. $script:WorkspaceModule')) },
@{ Name='Session tool launch and update menu'; Pass=($app.Contains('Start-ProfileLaunchable $entry') -and $app.Contains('Set-ProfileLaunchable $entry')) },
@{ Name='Process-local ProjectShell folder handoff'; Pass=($app.Contains('function Set-ProjectShellLaunchContext') -and $app.Contains('$env:PROJECTSHELL_START_DIRECTORY') -and $app.Contains('Set-ProjectShellLaunchContext $entry') -and $workspace.Contains('Set-ProjectShellLaunchContext $Profile')) },
@{ Name='Workspace source transfer approval'; Pass=($workspace.Contains('Assert-CopiedFolder') -and $workspace.Contains('Confirm original deletion after verifying copied content?')) },
@{ Name='Tools stored independently from app'; Pass=($workspace.Contains('workspaces.json') -and $workspace.Contains('Save-WorkspaceStore')) },
@{ Name='Installers never auto-run'; Pass=($workspace.Contains('not executed') -and $workspace.Contains('Invoke-SavedTool')) }
Expand Down
Loading