# Synopsis: Commits active state to long-term memory.
# Description: Appends active project milestones and goals to long_term_context.md.

$BaseDir = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
$StateFile = Join-Path $BaseDir "Config\active_state.json"
$LongTerm = Join-Path $BaseDir "Memory\long_term_context.md"

if (!(Test-Path $LongTerm)) {
    Set-Content -Path $LongTerm -Value "# AgentOS Long-Term Context Log`n" -Encoding UTF8
}

if (Test-Path $StateFile) {
    $State = Get-Content $StateFile -Raw | ConvertFrom-Json
    $Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
    
    $Entry = "## Session Archive: $Timestamp`n"
    $Entry += "**Project:** $($State.current_project)`n"
    $Entry += "**Goal:** $($State.current_goal)`n"
    $Entry += "**Last Action:** $($State.last_action)`n"
    $Entry += "**Blockers:** $($State.blockers)`n`n"
    
    Add-Content -Path $LongTerm -Value $Entry -Encoding UTF8
    Write-Output "SUCCESS: Session state successfully committed to long-term memory."
} else {
    Write-Output "ERROR: active_state.json not found. Cannot commit memory."
}

