Skip to content

foryourhealth111-pixel/Vibe-Skills

Vibe Code Orchestrator (VCO) is a governed runtime entry that freezes requirements, bounds execution, and enforces verification and phase cleanup.

FileKindSize
SKILL.mdskill md17.2 KB
agents/templates/debugger.mdmarkdown323 B
agents/templates/planner.mdmarkdown313 B
agents/templates/reviewer.mdmarkdown331 B
agents/templates/security-reviewer.mdmarkdown341 B
references/change-proof-matrix.mdmarkdown2.6 KB
references/contributor-zone-decision-table.mdmarkdown2.2 KB
references/developer-entry-contract.mdmarkdown2.7 KB
references/fixtures/external-corpus/external-corpus-gate.jsonconfig8.6 KB
references/fixtures/external-corpus/prompt-signals.jsonconfig412.4 KB
references/fixtures/external-corpus/skill-keyword-index.backup.jsonconfig30.6 KB
references/fixtures/external-corpus/skill-keyword-index.candidate.jsonconfig26.5 KB
references/fixtures/external-corpus/vco-suggestions.jsonconfig16.6 KB
references/fixtures/migration-map.jsonconfig7.8 KB
references/fixtures/retro-compare/safety-gate/baseline-cer.jsonconfig294 B
references/fixtures/retro-compare/safety-gate/current-cer.jsonconfig1.1 KB
references/fixtures/retro-compare/safety-gate/delta.jsonconfig1.0 KB
references/fixtures/retro-compare/sample-run/baseline-cer.jsonconfig324 B
references/fixtures/retro-compare/sample-run/current-cer.jsonconfig1.2 KB
references/fixtures/retro-compare/sample-run/delta.jsonconfig1.0 KB
references/fixtures/retro-compare/smoke/baseline-smoke.jsonconfig266 B
references/fixtures/retro-compare/smoke/current-smoke.jsonconfig1.0 KB
references/fixtures/retro-compare/smoke/delta-smoke.jsonconfig1.0 KB
references/fixtures/runtime/vibe-sessions/20260413T131910Z-pr153-rabbit-review-fix/cleanup-receipt.jsonconfig1.3 KB
references/fixtures/runtime/vibe-sessions/20260413T131910Z-pr153-rabbit-review-fix/governance-capsule.jsonconfig408 B
references/fixtures/runtime/vibe-sessions/20260413T131910Z-pr153-rabbit-review-fix/intent-contract.jsonconfig2.2 KB
references/fixtures/runtime/vibe-sessions/20260413T131910Z-pr153-rabbit-review-fix/phase-plan-execute.jsonconfig2.4 KB
references/fixtures/runtime/vibe-sessions/20260413T131910Z-pr153-rabbit-review-fix/skeleton-receipt.jsonconfig722 B
references/fixtures/runtime/vibe-sessions/20260413T131910Z-pr153-rabbit-review-fix/stage-lineage.jsonconfig1.3 KB
references/fixtures/skills-audit/bio-science-problem/bio-science-problem-map.csvother9.2 KB
references/fixtures/skills-audit/bio-science-problem/bio-science-problem-map.jsonconfig18.1 KB
references/fixtures/verify/routing-stability/vibe-routing-stability-gate.jsonconfig24.4 KB
references/index.mdmarkdown1.3 KB
references/proof-bundles/claude-code-managed-closure-candidate/linux-managed-run-01-local-host/installed-runtime-outputs/runtime-freshness-receipt.jsonconfig262 B
references/proof-bundles/claude-code-managed-closure-candidate/manifest.jsonconfig2.6 KB
references/proof-bundles/linux-full-authoritative-candidate/linux-pwsh-run-01-wsl/installed-runtime-outputs/runtime-freshness-receipt.jsonconfig298 B
references/proof-bundles/linux-full-authoritative-candidate/linux-pwsh-run-02-docker/installed-runtime-outputs/runtime-freshness-receipt.jsonconfig298 B
references/proof-bundles/linux-full-authoritative-candidate/manifest.jsonconfig3.3 KB
references/proof-bundles/openclaw-runtime-core-preview-candidate/manifest.jsonconfig1.9 KB
references/release-ledger.jsonlother5.1 KB
scripts/README.mdmarkdown1.7 KB
scripts/bootstrap/one-shot-setup.ps1script797 B
scripts/bootstrap/one-shot-setup.shscript482 B
scripts/bootstrap/scaffold-claude-preview.ps1script875 B
scripts/bootstrap/scaffold-claude-preview.shexecutablescript866 B
scripts/bootstrap/sync-local-compat.ps1script2.6 KB
scripts/common/AntiProxyGoalDrift.ps1script15.1 KB
scripts/common/NodeLaunchWrapper.ps1script13.1 KB
scripts/common/ProcessLedger.ps1script27.1 KB
scripts/common/ProtectedDocumentCleanup.ps1script6.9 KB
scripts/common/README.mdmarkdown1.9 KB
scripts/common/Resolve-VgoAdapter.ps1script4.3 KB
scripts/common/adapter_registry_query.pyexecutablescript3.8 KB
scripts/common/python_helpers.shscript2.8 KB
scripts/common/resolve_vgo_adapter.pyexecutablescript2.4 KB
scripts/common/runtime_contracts.pyscript3.7 KB
scripts/common/vibe-governance-helpers.ps1script75.6 KB
scripts/common/vibe-wave-gate-runner.ps1script28.3 KB
scripts/governance/Invoke-NodeProcessAudit.ps1script3.6 KB
scripts/governance/Invoke-NodeZombieCleanup.ps1script3.7 KB
scripts/governance/README.mdmarkdown5.1 KB
scripts/governance/audit-upstream.ps1script22.7 KB
scripts/governance/export-repo-cleanliness-inventory.ps1script8.6 KB
scripts/governance/install-local-worktree-excludes.ps1script2.0 KB
scripts/governance/invoke-mem0-policy.ps1script1.0 KB
scripts/governance/invoke-openspec-governance.ps1script8.6 KB
scripts/governance/new-origin-record.ps1script3.3 KB
scripts/governance/phase-end-cleanup.ps1script10.7 KB
scripts/governance/publish-absorption-soft-rollout.ps1script3.2 KB
scripts/governance/publish-openspec-soft-rollout.ps1script9.3 KB
scripts/governance/release-cut.ps1script25.1 KB
scripts/governance/set-gsd-overlay-rollout.ps1script3.9 KB
scripts/governance/set-openspec-rollout.ps1script3.1 KB
scripts/governance/sync-bundled-vibe.ps1script20.3 KB
scripts/install/Install-VgoAdapter.ps1script2.0 KB
scripts/install/install_vgo_adapter.pyexecutablescript524 B
scripts/overlay/README.mdmarkdown885 B
scripts/overlay/suggest-browserops-provider.ps1script9.3 KB
scripts/overlay/suggest-overlays.ps1script17.3 KB
scripts/release/build_release_bundle.pyscript6.5 KB
scripts/research/README.mdmarkdown1.1 KB
scripts/research/build-eval-slicing-catalog.ps1script2.6 KB
scripts/research/build-watch-portfolio-review.ps1script3.5 KB
scripts/research/build-xl-operator-checklist.ps1script2.3 KB
scripts/research/extract-prompt-signals.ps1script6.7 KB
scripts/research/generate-vco-suggestions.ps1script9.7 KB
scripts/research/sync-mcp-catalog.ps1script3.5 KB
scripts/research/vibe-adaptive-train.ps1script10.1 KB
scripts/router/README.mdmarkdown1.8 KB
scripts/router/invoke-pack-route.pyscript428 B
scripts/router/modules/00-core-utils.ps1script14.6 KB
scripts/router/modules/01-openai-responses.ps1script17.9 KB
scripts/router/modules/10-observability.ps1script11.7 KB
scripts/router/modules/11-route-probe.ps1script20.7 KB
scripts/router/modules/12-heartbeat.ps1script19.9 KB
scripts/router/modules/19-custom-admission.ps1script16.3 KB
scripts/router/modules/20-routing-rules.ps1script1.7 KB
scripts/router/modules/21-capability-interview.ps1script11.8 KB
scripts/router/modules/22-intent-contract.ps1script18.2 KB
scripts/router/modules/30-openspec.ps1script8.3 KB
scripts/router/modules/31-gsd-overlay.ps1script5.5 KB
scripts/router/modules/32-prompt-overlay.ps1script8.0 KB
scripts/router/modules/33-memory-governance.ps1script5.5 KB
scripts/router/modules/34-data-scale-overlay.ps1script25.8 KB
scripts/router/modules/35-quality-debt-overlay.ps1script13.4 KB
scripts/router/modules/36-framework-interop-overlay.ps1script16.9 KB
scripts/router/modules/37-ml-lifecycle-overlay.ps1script22.4 KB
scripts/router/modules/38-python-clean-code-overlay.ps1script16.2 KB
scripts/router/modules/39-system-design-overlay.ps1script15.5 KB
scripts/router/modules/40-cuda-kernel-overlay.ps1script17.7 KB
scripts/router/modules/42-ai-rerank-overlay.ps1script14.0 KB
scripts/router/modules/43-retrieval-overlay.ps1script22.4 KB
scripts/router/modules/44-dialectic-team-gate.ps1script7.5 KB
scripts/router/modules/44-exploration-overlay.ps1script17.7 KB
scripts/router/modules/45-daily-dialectic-guard.ps1script6.6 KB
scripts/router/modules/47-closure-overlay.ps1script9.2 KB
scripts/router/modules/48-llm-acceleration-overlay.ps1script104.6 KB
scripts/router/modules/49-prompt-asset-boost.ps1script28.3 KB
scripts/router/resolve-pack-route.ps1script4.1 KB
scripts/router/runtime_neutral/custom_admission.pyscript349 B
scripts/router/runtime_neutral/router_contract.pyscript356 B
scripts/ruc-nlpir/preflight.ps1script5.3 KB
scripts/runtime/Freeze-RuntimeInputPacket.ps1script33.0 KB
scripts/runtime/Invoke-AntiProxyGoalDriftCompaction.ps1script551 B
scripts/runtime/Invoke-DeepInterview.ps1script1.1 KB
scripts/runtime/Invoke-PhaseCleanup.ps1script11.1 KB
scripts/runtime/Invoke-PlanExecute.ps1script13.7 KB
scripts/runtime/Invoke-SkeletonCheck.ps1script3.1 KB
scripts/runtime/Invoke-VibeCanonicalEntry.ps1script12.9 KB
scripts/runtime/VibeMemoryActivation.Common.ps1script41.3 KB
scripts/runtime/VibeMemoryBackends.Common.ps1script12.4 KB
scripts/runtime/VibeRuntime.Common.ps1script298.6 KB
scripts/runtime/VibeSkillRouting.Common.ps1script19.0 KB
scripts/runtime/VibeWorkspaceMemory.Common.ps1script6.9 KB
scripts/runtime/Write-RequirementDoc.ps1script23.7 KB
scripts/runtime/Write-XlPlan.ps1script32.3 KB
scripts/runtime/invoke-vibe-runtime.ps1script69.7 KB
scripts/runtime/memory_backend_driver.pyscript14.2 KB
scripts/runtime/skill_authority_driver.pyscript375 B
scripts/runtime/workspace_memory_driver.pyscript24.8 KB
scripts/setup/check-kvm-host-readiness.shscript3.4 KB
scripts/setup/check-windows-eval-iso-readiness.shexecutablescript2.2 KB
scripts/setup/check-windows-proof-vm-state.shexecutablescript2.0 KB
scripts/setup/export-codex-settings-sanitized.ps1script2.6 KB
scripts/setup/fetch-windows11-eval-iso.shexecutablescript4.1 KB
scripts/setup/install-local-vm-host.shexecutablescript1.6 KB
scripts/setup/persist-codex-openai-env.ps1script2.4 KB
scripts/setup/run-windows-proof-vm.shexecutablescript11.4 KB
scripts/setup/send-qmp-boot-keys.pyexecutablescript3.0 KB
scripts/setup/send-qmp-text.pyexecutablescript3.0 KB
scripts/setup/show-windows-proof-media-options.shexecutablescript1.6 KB
scripts/setup/stop-windows-proof-vm.shexecutablescript1.6 KB
scripts/setup/sync-codex-settings-to-user-env.ps1script2.6 KB
scripts/uninstall/Uninstall-VgoAdapter.ps1script1.4 KB
scripts/uninstall/uninstall_vgo_adapter.pyscript526 B
scripts/verify/README.mdmarkdown3.8 KB
scripts/verify/cer-compare.ps1script8.5 KB
scripts/verify/fixtures/README.mdmarkdown1.1 KB
scripts/verify/fixtures/document-cleanup-safety/README.mdmarkdown527 B
scripts/verify/fixtures/document-cleanup-safety/ambiguous-cn-set/metadata.jsonconfig101 B
scripts/verify/fixtures/document-cleanup-safety/ambiguous-cn-set/source/.tmp/docs/重庆市永川区技术预见与制度创新项目申报书1-修订版.docxbinary56 B
scripts/verify/fixtures/document-cleanup-safety/ambiguous-cn-set/source/.tmp/docs/重庆市永川区技术预见与制度创新项目申报书1-补充材料.pdfbinary56 B
scripts/verify/fixtures/document-cleanup-safety/ambiguous-cn-set/source/docs/重庆市永川区技术预见与制度创新项目申报书1-正式版.docxbinary36 B
scripts/verify/fixtures/document-cleanup-safety/mixed-office-assets/metadata.jsonconfig101 B
scripts/verify/fixtures/document-cleanup-safety/mixed-office-assets/source/.tmp/staging/budget-review.xlsxbinary59 B
scripts/verify/fixtures/document-cleanup-safety/mixed-office-assets/source/.tmp/staging/quarterly-review-deck.pptxbinary60 B
scripts/verify/fixtures/document-cleanup-safety/mixed-office-assets/source/docs/reference-manual.pdfbinary21 B
scripts/verify/fixtures/document-cleanup-safety/non-protected-control/metadata.jsonconfig101 B
scripts/verify/fixtures/document-cleanup-safety/non-protected-control/source/.tmp/control.txtmarkdown54 B
scripts/verify/fixtures/llm-acceleration.mock.jsonconfig1.0 KB
scripts/verify/fixtures/pilot-browserops.jsonconfig541 B
scripts/verify/fixtures/pilot-deep-extraction.jsonconfig731 B
scripts/verify/fixtures/pilot-desktopops.jsonconfig587 B
scripts/verify/fixtures/pilot-memory.jsonconfig575 B
scripts/verify/fixtures/pilot-prompt.jsonconfig525 B
scripts/verify/fixtures/process-health/external-node-protected-fixture.jsonconfig345 B
scripts/verify/fixtures/process-health/healthy-managed-fixture.jsonconfig1.1 KB
scripts/verify/fixtures/process-health/managed-completed-alive-fixture.jsonconfig1.2 KB
scripts/verify/fixtures/process-health/managed-stale-fixture.jsonconfig1.1 KB
scripts/verify/fixtures/process-health/no-node-processes-fixture.jsonconfig131 B
scripts/verify/fixtures/prompt-asset-boost.mock.jsonconfig1.2 KB
scripts/verify/gate-family-index.mdmarkdown2.5 KB
scripts/verify/lib/VibeOfflineSkillsAudit.Suites.ps1script11.8 KB
scripts/verify/lib/VibeOfflineSkillsAudit.ps1script12.2 KB
scripts/verify/lib/VibeRouteAudit.Suites.ps1script7.9 KB
scripts/verify/lib/VibeRouteAudit.ps1script5.2 KB
scripts/verify/live-document-gate.pyscript7.6 KB
scripts/verify/probe-scientific-packs.ps1script55.1 KB
scripts/verify/publish-proof.pyscript409 B
scripts/verify/runtime_neutral/README.mdmarkdown2.5 KB
scripts/verify/runtime_neutral/_bootstrap.pyscript321 B
scripts/verify/runtime_neutral/bio_science_pack_consolidation_audit.pyscript421 B
scripts/verify/runtime_neutral/bootstrap_doctor.pyscript494 B
scripts/verify/runtime_neutral/code_quality_pack_consolidation_audit.pyscript717 B
scripts/verify/runtime_neutral/coherence_gate.pyscript529 B
scripts/verify/runtime_neutral/freshness_gate.pyscript494 B
scripts/verify/runtime_neutral/global_pack_consolidation_audit.pyscript635 B
scripts/verify/runtime_neutral/ml_skills_pruning_audit.pyscript574 B
scripts/verify/runtime_neutral/opencode_preview_smoke.pyscript674 B
scripts/verify/runtime_neutral/release_notes_quality.pyscript701 B

scripts/runtime/VibeMemoryActivation.Common.ps1

View on GitHub
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

function Get-VibeMemoryArtifactsRoot {
    param(
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $path = Join-Path $SessionRoot 'memory-activation'
    New-Item -ItemType Directory -Path $path -Force | Out-Null
    return $path
}

function Get-VibeMemoryBudgetSpec {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Stage
    )

    $defaults = $Runtime.memory_retrieval_budget_policy.defaults
    $topK = [int]$defaults.top_k
    $maxTokens = [int]$defaults.max_tokens
    $maxCharsPerItem = [int]$defaults.max_chars_per_item

    if ($Runtime.memory_retrieval_budget_policy.stages.PSObject.Properties.Name -contains $Stage) {
        $stageBudget = $Runtime.memory_retrieval_budget_policy.stages.$Stage
        if ($null -ne $stageBudget.top_k) {
            $topK = [int]$stageBudget.top_k
        }
        if ($null -ne $stageBudget.max_tokens) {
            $maxTokens = [int]$stageBudget.max_tokens
        }
        if ($null -ne $stageBudget.max_chars_per_item) {
            $maxCharsPerItem = [int]$stageBudget.max_chars_per_item
        }
    }

    return [pscustomobject]@{
        top_k = $topK
        max_tokens = $maxTokens
        max_chars_per_item = $maxCharsPerItem
    }
}

function Get-VibeMemoryCanonicalOwners {
    param(
        [Parameter(Mandatory)] [object]$Runtime
    )

    $owners = $Runtime.memory_runtime_v3_policy.canonical_owners
    return [ordered]@{
        session = [string]$owners.session
        project_decision = switch ([string]$owners.project_decision) {
            'serena' { 'Serena' }
            default { [string]$owners.project_decision }
        }
        short_term_semantic = [string]$owners.short_term_semantic
        long_term_graph = switch ([string]$owners.long_term_graph) {
            'cognee' { 'Cognee' }
            default { [string]$owners.long_term_graph }
        }
    }
}

function Get-VibeMemoryStagePolicy {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Stage
    )

    foreach ($stagePolicy in @($Runtime.memory_stage_activation_policy.stages)) {
        if ([string]$stagePolicy.stage -eq $Stage) {
            return $stagePolicy
        }
    }

    throw "Missing memory stage policy for stage: $Stage"
}

function Get-VibeBoundedMemoryItems {
    param(
        [AllowEmptyCollection()] [string[]]$Items = @(),
        [Parameter(Mandatory)] [object]$Budget
    )

    $bounded = [System.Collections.Generic.List[string]]::new()
    $totalChars = 0
    $maxCharsTotal = [int]$Budget.max_tokens * 4
    foreach ($item in @($Items)) {
        if ([string]::IsNullOrWhiteSpace($item)) {
            continue
        }
        if ($bounded.Count -ge [int]$Budget.top_k) {
            break
        }

        $text = [string]$item
        if ($text.Length -gt [int]$Budget.max_chars_per_item) {
            $text = $text.Substring(0, [int]$Budget.max_chars_per_item).TrimEnd() + '...'
        }
        $remainingChars = $maxCharsTotal - $totalChars
        if ($remainingChars -le 0) {
            break
        }
        if ($text.Length -gt $remainingChars) {
            if ($remainingChars -le 3) {
                $text = $text.Substring(0, $remainingChars)
            } else {
                $text = $text.Substring(0, $remainingChars - 3).TrimEnd() + '...'
            }
        }
        if ([string]::IsNullOrWhiteSpace($text)) {
            break
        }
        $bounded.Add($text) | Out-Null
        $totalChars += $text.Length
    }
    return @($bounded)
}

function Get-VibeEstimatedTokenCount {
    param(
        [AllowEmptyCollection()] [string[]]$Items = @()
    )

    $charCount = 0
    foreach ($item in @($Items)) {
        $charCount += ([string]$item).Length
    }

    if ($charCount -le 0) {
        return 0
    }

    return [int][Math]::Ceiling($charCount / 4.0)
}

function Get-VibeMemoryReadActionObject {
    param(
        [Parameter(Mandatory)] [string]$Owner,
        [Parameter(Mandatory)] [object]$BackendResult
    )

    return [pscustomobject]@{
        owner = $Owner
        status = [string]$BackendResult.status
        item_count = [int]$BackendResult.item_count
        items = @($BackendResult.items)
        capsule_count = if ($BackendResult.PSObject.Properties.Name -contains 'capsule_count') { [int]$BackendResult.capsule_count } else { 0 }
        capsules = if ($BackendResult.PSObject.Properties.Name -contains 'capsules') { @($BackendResult.capsules) } else { @() }
        artifact_path = if ($BackendResult.artifact_path) { [string]$BackendResult.artifact_path } else { $null }
        project_key = if ($BackendResult.project_key) { [string]$BackendResult.project_key } else { $null }
        project_key_source = if ($BackendResult.project_key_source) { [string]$BackendResult.project_key_source } else { $null }
        workspace_memory_plane = if ($BackendResult.PSObject.Properties.Name -contains 'workspace_memory_plane') { $BackendResult.workspace_memory_plane } else { $null }
    }
}

function Get-VibeMemoryWriteActionObject {
    param(
        [Parameter(Mandatory)] [string]$Owner,
        [Parameter(Mandatory)] [object]$BackendResult
    )

    return [pscustomobject]@{
        owner = $Owner
        status = [string]$BackendResult.status
        item_count = [int]$BackendResult.item_count
        items = @($BackendResult.items)
        artifact_path = if ($BackendResult.artifact_path) { [string]$BackendResult.artifact_path } else { $null }
        project_key = if ($BackendResult.project_key) { [string]$BackendResult.project_key } else { $null }
        project_key_source = if ($BackendResult.project_key_source) { [string]$BackendResult.project_key_source } else { $null }
        store_path = if ($BackendResult.store_path) { [string]$BackendResult.store_path } else { $null }
        workspace_memory_plane = if ($BackendResult.PSObject.Properties.Name -contains 'workspace_memory_plane') { $BackendResult.workspace_memory_plane } else { $null }
    }
}

function Get-VibeLaneSearchPayload {
    param(
        [Parameter(Mandatory)] [string]$LaneId,
        [Parameter(Mandatory)] [string]$Stage,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [object]$Budget
    )

    return [pscustomobject]@{
        lane = $LaneId
        stage = $Stage
        task = $Task
        top_k = [int]$Budget.top_k
        max_chars_per_item = [int]$Budget.max_chars_per_item
        keywords = @()
        project_key_source = $null
    }
}

function Get-VibeSearchKeywords {
    param(
        [AllowEmptyString()] [string]$Task = '',
        [AllowEmptyCollection()] [string[]]$ExtraTokens = @()
    )

    $tokens = [System.Collections.Generic.List[string]]::new()
    foreach ($match in [regex]::Matches($Task.ToLowerInvariant(), '[a-z0-9_/-]{3,}')) {
        $value = [string]$match.Value
        if (-not [string]::IsNullOrWhiteSpace($value)) {
            $tokens.Add($value) | Out-Null
        }
    }
    foreach ($token in @($ExtraTokens)) {
        if (-not [string]::IsNullOrWhiteSpace([string]$token)) {
            $tokens.Add([string]$token) | Out-Null
        }
    }
    return @($tokens | Select-Object -Unique | Select-Object -First 12)
}

function Get-VibeCogneeReadAction {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Stage,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $budget = Get-VibeMemoryBudgetSpec -Runtime $Runtime -Stage $Stage
    $payload = Get-VibeLaneSearchPayload -LaneId 'cognee' -Stage $Stage -Task $Task -Budget $budget
    $payload.keywords = @(Get-VibeSearchKeywords -Task $Task)
    $result = Invoke-VibeMemoryBackendAction -Runtime $Runtime -LaneId 'cognee' -Action 'read' -Payload $payload -SessionRoot $SessionRoot
    return Get-VibeMemoryReadActionObject -Owner 'Cognee' -BackendResult $result
}

function Get-VibeSerenaReadAction {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Stage,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $budget = Get-VibeMemoryBudgetSpec -Runtime $Runtime -Stage $Stage
    $payload = Get-VibeLaneSearchPayload -LaneId 'serena' -Stage $Stage -Task $Task -Budget $budget
    $payload.keywords = @(Get-VibeSearchKeywords -Task $Task)
    $result = Invoke-VibeMemoryBackendAction -Runtime $Runtime -LaneId 'serena' -Action 'read' -Payload $payload -SessionRoot $SessionRoot
    return Get-VibeMemoryReadActionObject -Owner 'Serena' -BackendResult $result
}

function Get-VibeRufloReadAction {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [Parameter(Mandatory)] [string]$Grade
    )

    if ($Grade -ne 'XL') {
        return [pscustomobject]@{
            owner = 'ruflo'
            status = 'out_of_scope_serial_lane'
            item_count = 0
            items = @()
            artifact_path = $null
        }
    }

    $budget = Get-VibeMemoryBudgetSpec -Runtime $Runtime -Stage 'plan_execute'
    $payload = Get-VibeLaneSearchPayload -LaneId 'ruflo' -Stage 'plan_execute' -Task $Task -Budget $budget
    $payload.keywords = @(Get-VibeSearchKeywords -Task $Task -ExtraTokens @('handoff', 'milestone', 'xl'))
    $result = Invoke-VibeMemoryBackendAction -Runtime $Runtime -LaneId 'ruflo' -Action 'read' -Payload $payload -SessionRoot $SessionRoot
    return Get-VibeMemoryReadActionObject -Owner 'ruflo' -BackendResult $result
}

function Get-VibeMemoryDisclosureLevel {
    param(
        [AllowNull()] [object]$Runtime = $null,
        [Parameter(Mandatory)] [string]$Stage
    )

    if (
        $null -ne $Runtime -and
        $Runtime.PSObject.Properties.Name -contains 'memory_disclosure_policy' -and
        $null -ne $Runtime.memory_disclosure_policy -and
        $Runtime.memory_disclosure_policy.PSObject.Properties.Name -contains 'stages' -and
        $null -ne $Runtime.memory_disclosure_policy.stages -and
        $Runtime.memory_disclosure_policy.stages.PSObject.Properties.Name -contains $Stage
    ) {
        $stagePolicy = $Runtime.memory_disclosure_policy.stages.$Stage
        if ($null -ne $stagePolicy -and $stagePolicy.PSObject.Properties.Name -contains 'level' -and -not [string]::IsNullOrWhiteSpace([string]$stagePolicy.level)) {
            return [string]$stagePolicy.level
        }
    }

    switch ($Stage) {
        'skeleton_check' { return 'minimal' }
        'deep_interview' { return 'bounded_context' }
        'requirement_doc' { return 'decision_focused' }
        'xl_plan' { return 'decision_and_relation_focused' }
        'plan_execute' { return 'execution_relevant' }
        'phase_cleanup' { return 'closure' }
        default { return 'minimal' }
    }
}

function Get-VibeStableShortHash {
    param(
        [Parameter(Mandatory)] [string]$Text
    )

    $bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
    $sha256 = [System.Security.Cryptography.SHA256]::Create()
    try {
        $hashBytes = $sha256.ComputeHash($bytes)
    } finally {
        $sha256.Dispose()
    }

    $hex = [System.BitConverter]::ToString($hashBytes).Replace('-', '').ToLowerInvariant()
    return $hex.Substring(0, 16)
}

function ConvertTo-VibeMemoryTimestampString {
    param(
        [AllowNull()] [object]$Value
    )

    if ($null -eq $Value) {
        return $null
    }

    if ($Value -is [datetime]) {
        return $Value.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
    }

    $text = [string]$Value
    if ([string]::IsNullOrWhiteSpace($text)) {
        return $null
    }

    $parsed = [datetime]::MinValue
    if ([datetime]::TryParse($text, [ref]$parsed)) {
        return $parsed.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
    }

    return $text
}

function Get-VibeActionCapsuleCandidates {
    param(
        [Parameter(Mandatory)] [object]$Action,
        [Parameter(Mandatory)] [string]$Stage
    )

    $artifactPath = if ($Action.PSObject.Properties.Name -contains 'artifact_path' -and -not [string]::IsNullOrWhiteSpace([string]$Action.artifact_path)) {
        [string]$Action.artifact_path
    } else {
        $null
    }
    $actionItems = @($Action.items)
    $backendCapsules = if ($Action.PSObject.Properties.Name -contains 'capsules') { @($Action.capsules) } else { @() }
    $candidates = [System.Collections.Generic.List[object]]::new()

    if (@($backendCapsules).Count -gt 0) {
        for ($index = 0; $index -lt @($backendCapsules).Count; $index++) {
            $backendCapsule = $backendCapsules[$index]
            $summaryLines = [System.Collections.Generic.List[string]]::new()
            $primaryLine = $null
            if ($index -lt $actionItems.Count -and -not [string]::IsNullOrWhiteSpace([string]$actionItems[$index])) {
                $primaryLine = [string]$actionItems[$index]
            } elseif (-not [string]::IsNullOrWhiteSpace([string]$backendCapsule.summary)) {
                $primaryLine = [string]$backendCapsule.summary
            } else {
                $primaryLine = ('{0} memory capsule' -f [string]$Action.owner)
            }
            $summaryLines.Add($primaryLine) | Out-Null

            $backendSummary = [string]$backendCapsule.summary
            if (-not [string]::IsNullOrWhiteSpace($backendSummary) -and $backendSummary -ne $primaryLine -and $summaryLines.Count -lt 3) {
                $summaryLines.Add($backendSummary) | Out-Null
            }

            $title = [string]$primaryLine
            if ($title.Length -gt 140) {
                $title = $title.Substring(0, 140).TrimEnd() + '...'
            }

            $capsuleId = if (-not [string]::IsNullOrWhiteSpace([string]$backendCapsule.capsule_id)) {
                [string]$backendCapsule.capsule_id
            } else {
                Get-VibeStableShortHash -Text ('{0}|{1}|{2}' -f $Stage, [string]$Action.owner, $title)
            }

            $candidates.Add([pscustomobject]@{
                capsule_id = $capsuleId
                owner = if (-not [string]::IsNullOrWhiteSpace([string]$backendCapsule.owner)) { [string]$backendCapsule.owner } else { [string]$Action.owner }
                lane = if (-not [string]::IsNullOrWhiteSpace([string]$backendCapsule.lane)) { [string]$backendCapsule.lane } else { $null }
                kind = if (-not [string]::IsNullOrWhiteSpace([string]$backendCapsule.kind)) { [string]$backendCapsule.kind } else { $null }
                updated_at = ConvertTo-VibeMemoryTimestampString -Value $backendCapsule.updated_at
                title = $title
                why_now = ('Matched {0} memory for {1}.' -f [string]$Action.owner, $Stage)
                expansion_ref = if ($artifactPath) { ('{0}#{1}' -f $artifactPath, $capsuleId) } else { ('inline:{0}' -f $capsuleId) }
                summary_lines = @($summaryLines)
            }) | Out-Null
        }
        return @($candidates)
    }

    $summaryLines = [System.Collections.Generic.List[string]]::new()
    foreach ($item in $actionItems) {
        $text = [string]$item
        if ([string]::IsNullOrWhiteSpace($text)) {
            continue
        }
        if ($summaryLines.Count -ge 3) {
            break
        }
        $summaryLines.Add($text) | Out-Null
    }

    if ($summaryLines.Count -eq 0) {
        return @()
    }

    $title = [string]$summaryLines[0]
    if ($title.Length -gt 140) {
        $title = $title.Substring(0, 140).TrimEnd() + '...'
    }

    $capsuleId = Get-VibeStableShortHash -Text ('{0}|{1}|{2}' -f $Stage, [string]$Action.owner, $title)
    $candidates.Add([pscustomobject]@{
        capsule_id = $capsuleId
        owner = [string]$Action.owner
        lane = $null
        kind = 'fallback_digest'
        updated_at = $null
        title = $title
        why_now = ('Matched {0} memory for {1}.' -f [string]$Action.owner, $Stage)
        expansion_ref = if ($artifactPath) { ('{0}#{1}' -f $artifactPath, $capsuleId) } else { ('inline:{0}' -f $capsuleId) }
        summary_lines = @($summaryLines)
    }) | Out-Null
    return @($candidates)
}

function New-VibeSelectedMemoryCapsules {
    param(
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$ReadActions,
        [Parameter(Mandatory)] [string]$Stage,
        [Parameter(Mandatory)] [object]$Budget
    )

    $capsules = [System.Collections.Generic.List[object]]::new()
    $candidateGroups = @()
    foreach ($action in @($ReadActions)) {
        $group = @(Get-VibeActionCapsuleCandidates -Action $action -Stage $Stage)
        if (@($group).Count -gt 0) {
            $candidateGroups += ,$group
        }
    }

    $round = 0
    while ($capsules.Count -lt [int]$Budget.top_k) {
        $addedInRound = $false
        foreach ($group in @($candidateGroups)) {
            if ($round -lt @($group).Count) {
                $capsules.Add($group[$round]) | Out-Null
                $addedInRound = $true
                if ($capsules.Count -ge [int]$Budget.top_k) {
                    break
                }
            }
        }

        if (-not $addedInRound) {
            break
        }

        $round++
    }

    return @($capsules)
}

function New-VibeProgressiveDisclosureContextPack {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$ReadActions,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [Parameter(Mandatory)] [string]$Stage,
        [Parameter(Mandatory)] [string]$ArtifactName,
        [AllowEmptyString()] [string]$SourceStage = ''
    )

    $budget = Get-VibeMemoryBudgetSpec -Runtime $Runtime -Stage $Stage
    $candidateCapsules = @(New-VibeSelectedMemoryCapsules -ReadActions $ReadActions -Stage $Stage -Budget $budget)
    $selectedCapsules = [System.Collections.Generic.List[object]]::new()
    $boundedItems = @()
    foreach ($capsule in @($candidateCapsules)) {
        $candidateItems = @($boundedItems)
        foreach ($line in @($capsule.summary_lines)) {
            if (-not [string]::IsNullOrWhiteSpace([string]$line)) {
                $candidateItems += [string]$line
            }
        }

        $nextBoundedItems = @(Get-VibeBoundedMemoryItems -Items $candidateItems -Budget $budget)
        if ((@($nextBoundedItems) -join "`n") -eq (@($boundedItems) -join "`n")) {
            continue
        }

        $selectedCapsules.Add($capsule) | Out-Null
        $boundedItems = @($nextBoundedItems)
    }

    $estimatedTokens = Get-VibeEstimatedTokenCount -Items @($boundedItems)
    $artifactPath = Join-Path (Get-VibeMemoryArtifactsRoot -SessionRoot $SessionRoot) $ArtifactName
    $artifact = [pscustomobject]@{
        stage = $Stage
        source_stage = if ([string]::IsNullOrWhiteSpace($SourceStage)) { $null } else { $SourceStage }
        owner = 'state_store'
        disclosure_level = Get-VibeMemoryDisclosureLevel -Runtime $Runtime -Stage $Stage
        generated_at = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
        capsule_count = @($selectedCapsules).Count
        selected_capsules = @($selectedCapsules)
        items = @($boundedItems)
        estimated_tokens = $estimatedTokens
        budget = $budget
    }
    Write-VibeJsonArtifact -Path $artifactPath -Value $artifact

    return [pscustomobject]@{
        context_path = $artifactPath
        disclosure_level = [string]$artifact.disclosure_level
        capsule_count = @($selectedCapsules).Count
        selected_capsules = @($selectedCapsules)
        injected_item_count = @($boundedItems).Count
        estimated_tokens = $estimatedTokens
        budget = $budget
        items = @($boundedItems)
    }
}

function New-VibePlanMemoryContextPack {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$ReadActions,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [string]$Stage = 'xl_plan',
        [string]$ArtifactName = 'plan-context-pack.json'
    )

    return New-VibeProgressiveDisclosureContextPack `
        -Runtime $Runtime `
        -ReadActions $ReadActions `
        -SessionRoot $SessionRoot `
        -Stage $Stage `
        -ArtifactName $ArtifactName
}

function Get-VibeDecisionCandidates {
    param(
        [Parameter(Mandatory)] [string]$RequirementDocPath,
        [Parameter(Mandatory)] [string]$ExecutionPlanPath,
        [AllowEmptyString()] [string]$Task = ''
    )

    $texts = @()
    foreach ($path in @($RequirementDocPath, $ExecutionPlanPath)) {
        if (Test-Path -LiteralPath $path) {
            $texts += @(Get-Content -LiteralPath $path -Encoding UTF8)
        }
    }
    if (-not [string]::IsNullOrWhiteSpace($Task)) {
        $texts += $Task
    }

    $candidates = [System.Collections.Generic.List[object]]::new()
    foreach ($line in @($texts)) {
        $trimmed = ([string]$line).Trim()
        if ([string]::IsNullOrWhiteSpace($trimmed)) {
            continue
        }
        if ($trimmed -match '(?i)approved decision|decision record|adr-|## decision') {
            $summary = $trimmed -replace '^[#\-\*\s]+', ''
            $keywords = Get-VibeSearchKeywords -Task $summary
            $candidates.Add([pscustomobject]@{
                summary = $summary
                evidence_paths = @($RequirementDocPath, $ExecutionPlanPath)
                keywords = @($keywords)
            }) | Out-Null
        }
    }
    return @($candidates | Select-Object -Unique -First 3)
}

function Get-VibeCogneeRelationCandidates {
    param(
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$RequirementDocPath,
        [Parameter(Mandatory)] [string]$ExecutionPlanPath,
        [Parameter(Mandatory)] [string]$ExecutionManifestPath
    )

    $taskSlug = ConvertTo-VibeSlug -Text $Task
    $keywords = Get-VibeSearchKeywords -Task $Task -ExtraTokens @($taskSlug)
    return @(
        [pscustomobject]@{
            source = $taskSlug
            relation = 'specified_by'
            target = [System.IO.Path]::GetFileName($RequirementDocPath)
            evidence_paths = @($RequirementDocPath)
            keywords = @($keywords)
        },
        [pscustomobject]@{
            source = $taskSlug
            relation = 'planned_in'
            target = [System.IO.Path]::GetFileName($ExecutionPlanPath)
            evidence_paths = @($ExecutionPlanPath)
            keywords = @($keywords)
        },
        [pscustomobject]@{
            source = $taskSlug
            relation = 'executed_as'
            target = [System.IO.Path]::GetFileName($ExecutionManifestPath)
            evidence_paths = @($ExecutionManifestPath)
            keywords = @($keywords)
        }
    )
}

function Get-VibeRufloCardCandidates {
    param(
        [Parameter(Mandatory)] [string]$ExecutionManifestPath,
        [Parameter(Mandatory)] [string]$RunId,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$Grade
    )

    if ($Grade -ne 'XL') {
        return @()
    }

    $manifest = Get-Content -LiteralPath $ExecutionManifestPath -Raw -Encoding UTF8 | ConvertFrom-Json
    $summary = 'XL module handoff for {0}: completed {1} units with {2} failures and {3} blocks.' -f $RunId, [int]$manifest.completed_unit_count, [int]$manifest.failed_unit_count, [int]$manifest.blocked_unit_count
    return @(
        [pscustomobject]@{
            scope = 'xl'
            summary = $summary
            items = @(
                ('execution_status:{0}' -f [string]$manifest.status),
                ('workflow_level:{0}' -f [string]$manifest.module_handoff.workflow_level),
                ('module_handoff_status:{0}' -f [string]$manifest.module_handoff.status)
            )
            evidence_paths = @($ExecutionManifestPath)
            keywords = @(Get-VibeSearchKeywords -Task $Task -ExtraTokens @('xl', 'handoff', 'milestone'))
        }
    )
}

function New-VibeSkeletonMemoryDigest {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [object]$Skeleton,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $budget = Get-VibeMemoryBudgetSpec -Runtime $Runtime -Stage 'skeleton_check'
    $receipt = $Skeleton.receipt
    $missingPaths = @($receipt.required_paths | Where-Object { -not [bool]$_.exists } | ForEach-Object { [string]$_.path })
    $requirementDocs = @($receipt.existing_requirement_docs | Select-Object -First 5)
    $planDocs = @($receipt.existing_plan_docs | Select-Object -First 5)

    $items = @()
    $items += ('Task focus: {0}' -f $Task)
    $items += ('Git branch: {0}' -f [string]$receipt.git_branch)
    if (@($missingPaths).Count -gt 0) {
        $items += 'Missing runtime prerequisites: ' + (@($missingPaths) -join ', ')
    } else {
        $items += 'All required governed runtime prerequisite paths are present.'
    }
    if (@($requirementDocs).Count -gt 0) {
        $items += 'Existing requirement docs: ' + (@($requirementDocs) -join ', ')
    } else {
        $items += 'Existing requirement docs: none'
    }
    if (@($planDocs).Count -gt 0) {
        $items += 'Existing plan docs: ' + (@($planDocs) -join ', ')
    } else {
        $items += 'Existing plan docs: none'
    }

    $boundedItems = Get-VibeBoundedMemoryItems -Items $items -Budget $budget
    $artifactPath = Join-Path (Get-VibeMemoryArtifactsRoot -SessionRoot $SessionRoot) 'skeleton-local-digest.json'
    $artifact = [pscustomobject]@{
        stage = 'skeleton_check'
        owner = 'state_store'
        status = 'fallback_local_digest'
        generated_at = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
        source_receipt_path = [string]$Skeleton.receipt_path
        items = @($boundedItems)
        budget = $budget
    }
    Write-VibeJsonArtifact -Path $artifactPath -Value $artifact

    return [pscustomobject]@{
        owner = 'state_store'
        status = 'fallback_local_digest'
        item_count = @($boundedItems).Count
        items = @($boundedItems)
        artifact_path = $artifactPath
        budget = $budget
    }
}

function Get-VibeDeepInterviewMemoryReadAction {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $stagePolicy = Get-VibeMemoryStagePolicy -Runtime $Runtime -Stage 'deep_interview'
    $readAction = Get-VibeSerenaReadAction -Runtime $Runtime -Stage 'deep_interview' -Task $Task -SessionRoot $SessionRoot
    if ($readAction.status -eq 'memory_backend_ready') {
        $readAction.status = [string]@($stagePolicy.read_actions)[0].status_if_missing_project_key
    }
    if ($readAction.status -eq 'backend_read_empty' -and -not $readAction.project_key_source) {
        $readAction.status = [string]@($stagePolicy.read_actions)[0].status_if_missing_project_key
    }
    if ($readAction.PSObject.Properties.Name -contains 'project_key_source') {
        $readAction | Add-Member -NotePropertyName project_key_env -NotePropertyValue $readAction.project_key_source -Force
    }
    return $readAction
}

function New-VibeRequirementContextPack {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$ReadActions,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    return New-VibeProgressiveDisclosureContextPack `
        -Runtime $Runtime `
        -ReadActions $ReadActions `
        -SessionRoot $SessionRoot `
        -Stage 'requirement_doc' `
        -ArtifactName 'requirement-context-pack.json' `
        -SourceStage 'bounded_memory_recall'
}

function New-VibeExecutionMemoryWriteAction {
    param(
        [Parameter(Mandatory)] [string]$ExecutionManifestPath,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$RunId,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$Grade
    )

    $manifest = Get-Content -LiteralPath $ExecutionManifestPath -Raw -Encoding UTF8 | ConvertFrom-Json
    $items = @(
        ('Execution status: {0}' -f [string]$manifest.status),
        ('Module handoff status: {0}' -f [string]$manifest.module_handoff.status)
    )
    $artifactPath = Join-Path (Get-VibeMemoryArtifactsRoot -SessionRoot $SessionRoot) 'execution-handoff-card.json'
    $artifact = [pscustomobject]@{
        stage = 'plan_execute'
        owner = 'state_store'
        status = 'fallback_local_artifact'
        generated_at = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
        source_execution_manifest = $ExecutionManifestPath
        items = @($items)
    }
    Write-VibeJsonArtifact -Path $artifactPath -Value $artifact

    return [pscustomobject]@{
        owner = 'state_store'
        status = 'fallback_local_artifact'
        item_count = @($items).Count
        items = @($items)
        artifact_path = $artifactPath
    }
}

function New-VibeRufloExecutionWriteAction {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$ExecutionManifestPath,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [Parameter(Mandatory)] [string]$RunId,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$Grade
    )

    if ($Grade -ne 'XL') {
        return [pscustomobject]@{
            owner = 'ruflo'
            status = 'out_of_scope_serial_lane'
            item_count = 0
            items = @()
            artifact_path = $null
            store_path = $null
        }
    }

    $cards = Get-VibeRufloCardCandidates -ExecutionManifestPath $ExecutionManifestPath -RunId $RunId -Task $Task -Grade $Grade
    $payload = [pscustomobject]@{
        run_id = $RunId
        task = $Task
        cards = @($cards)
    }
    $result = Invoke-VibeMemoryBackendAction -Runtime $Runtime -LaneId 'ruflo' -Action 'write' -Payload $payload -SessionRoot $SessionRoot
    return Get-VibeMemoryWriteActionObject -Owner 'ruflo' -BackendResult $result
}

function Get-VibeCleanupDecisionWriteAction {
    param(
        [Parameter(Mandatory)] [string]$RequirementDocPath,
        [Parameter(Mandatory)] [string]$ExecutionPlanPath,
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [AllowEmptyString()] [string]$Task = ''
    )

    $requirementText = if (Test-Path -LiteralPath $RequirementDocPath) {
        Get-Content -LiteralPath $RequirementDocPath -Raw -Encoding UTF8
    } else {
        ''
    }
    $planText = if (Test-Path -LiteralPath $ExecutionPlanPath) {
        Get-Content -LiteralPath $ExecutionPlanPath -Raw -Encoding UTF8
    } else {
        ''
    }
    $decisions = Get-VibeDecisionCandidates -RequirementDocPath $RequirementDocPath -ExecutionPlanPath $ExecutionPlanPath -Task $Task
    if (@($decisions).Count -eq 0) {
        return [pscustomobject]@{
            owner = 'Serena'
            status = 'guarded_no_write'
            item_count = 0
            items = @()
            artifact_path = $null
            reason = 'no explicit approved decision markers detected in frozen requirement/plan surfaces'
        }
    }

    $payload = [pscustomobject]@{
        decisions = @($decisions)
    }
    $result = Invoke-VibeMemoryBackendAction -Runtime $Runtime -LaneId 'serena' -Action 'write' -Payload $payload -SessionRoot $SessionRoot
    $writeAction = Get-VibeMemoryWriteActionObject -Owner 'Serena' -BackendResult $result
    $writeAction | Add-Member -NotePropertyName reason -NotePropertyValue 'explicit decision markers detected' -Force
    return $writeAction
}

function Get-VibeCogneeCleanupWriteAction {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$Task,
        [Parameter(Mandatory)] [string]$RequirementDocPath,
        [Parameter(Mandatory)] [string]$ExecutionPlanPath,
        [Parameter(Mandatory)] [string]$ExecutionManifestPath,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $relations = Get-VibeCogneeRelationCandidates `
        -Task $Task `
        -RequirementDocPath $RequirementDocPath `
        -ExecutionPlanPath $ExecutionPlanPath `
        -ExecutionManifestPath $ExecutionManifestPath
    $payload = [pscustomobject]@{
        task = $Task
        relations = @($relations)
    }
    $result = Invoke-VibeMemoryBackendAction -Runtime $Runtime -LaneId 'cognee' -Action 'write' -Payload $payload -SessionRoot $SessionRoot
    return Get-VibeMemoryWriteActionObject -Owner 'Cognee' -BackendResult $result
}

function New-VibeCleanupMemoryFold {
    param(
        [Parameter(Mandatory)] [string]$RequirementDocPath,
        [Parameter(Mandatory)] [string]$ExecutionPlanPath,
        [Parameter(Mandatory)] [string]$ExecutionManifestPath,
        [Parameter(Mandatory)] [string]$CleanupReceiptPath,
        [Parameter(Mandatory)] [string]$SessionRoot
    )

    $manifest = Get-Content -LiteralPath $ExecutionManifestPath -Raw -Encoding UTF8 | ConvertFrom-Json
    $fold = [pscustomobject]@{
        stage = 'phase_cleanup'
        fold_kind = 'deepagent_memory_fold_local'
        generated_at = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
        working_memory = @(
            ('Requirement doc: {0}' -f $RequirementDocPath),
            ('Execution plan: {0}' -f $ExecutionPlanPath),
            ('Runtime status: {0}' -f [string]$manifest.status)
        )
        tool_memory = @(
            ('Execution manifest: {0}' -f $ExecutionManifestPath),
            ('Cleanup receipt: {0}' -f $CleanupReceiptPath)
        )
        evidence_anchors = @(
            $RequirementDocPath,
            $ExecutionPlanPath,
            $ExecutionManifestPath,
            $CleanupReceiptPath
        )
    }
    $artifactPath = Join-Path (Get-VibeMemoryArtifactsRoot -SessionRoot $SessionRoot) 'phase-cleanup-memory-fold.json'
    Write-VibeJsonArtifact -Path $artifactPath -Value $fold

    return [pscustomobject]@{
        owner = 'state_store'
        status = 'generated_local_fold'
        item_count = @($fold.working_memory).Count + @($fold.tool_memory).Count
        items = @($fold.working_memory + $fold.tool_memory)
        artifact_path = $artifactPath
    }
}

function New-VibeMemoryActivationReport {
    param(
        [Parameter(Mandatory)] [object]$Runtime,
        [Parameter(Mandatory)] [string]$RunId,
        [Parameter(Mandatory)] [string]$SessionRoot,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$SkeletonReadActions,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$DeepInterviewReadActions,
        [Parameter(Mandatory)] [object]$RequirementContextPack,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$XlPlanReadActions,
        [Parameter(Mandatory)] [object]$PlanContextPack,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$PlanExecuteReadActions,
        [Parameter(Mandatory)] [object]$PlanExecuteContextPack,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$PlanExecuteWriteActions,
        [Parameter(Mandatory)] [AllowEmptyCollection()] [object[]]$CleanupWriteActions,
        [Parameter(Mandatory)] [object]$CleanupFoldAction
    )

    $stages = @(
        [pscustomobject]@{
            stage = 'skeleton_check'
            read_actions = @($SkeletonReadActions)
            context_injection = $null
            write_actions = @()
        },
        [pscustomobject]@{
            stage = 'deep_interview'
            read_actions = @($DeepInterviewReadActions)
            context_injection = $null
            write_actions = @()
        },
        [pscustomobject]@{
            stage = 'requirement_doc'
            read_actions = @()
            context_injection = [pscustomobject]@{
                injected_item_count = [int]$RequirementContextPack.injected_item_count
                estimated_tokens = [int]$RequirementContextPack.estimated_tokens
                budget = $RequirementContextPack.budget
                artifact_path = [string]$RequirementContextPack.context_path
                disclosure_level = [string]$RequirementContextPack.disclosure_level
                capsule_count = [int]$RequirementContextPack.capsule_count
                selected_capsules = @($RequirementContextPack.selected_capsules)
            }
            write_actions = @()
        },
        [pscustomobject]@{
            stage = 'xl_plan'
            read_actions = @($XlPlanReadActions)
            context_injection = [pscustomobject]@{
                injected_item_count = [int]$PlanContextPack.injected_item_count
                estimated_tokens = [int]$PlanContextPack.estimated_tokens
                budget = $PlanContextPack.budget
                artifact_path = [string]$PlanContextPack.context_path
                disclosure_level = [string]$PlanContextPack.disclosure_level
                capsule_count = [int]$PlanContextPack.capsule_count
                selected_capsules = @($PlanContextPack.selected_capsules)
            }
            write_actions = @()
        },
        [pscustomobject]@{
            stage = 'plan_execute'
            read_actions = @($PlanExecuteReadActions)
            context_injection = [pscustomobject]@{
                injected_item_count = [int]$PlanExecuteContextPack.injected_item_count
                estimated_tokens = [int]$PlanExecuteContextPack.estimated_tokens
                budget = $PlanExecuteContextPack.budget
                artifact_path = [string]$PlanExecuteContextPack.context_path
                disclosure_level = [string]$PlanExecuteContextPack.disclosure_level
                capsule_count = [int]$PlanExecuteContextPack.capsule_count
                selected_capsules = @($PlanExecuteContextPack.selected_capsules)
            }
            write_actions = @($PlanExecuteWriteActions)
        },
        [pscustomobject]@{
            stage = 'phase_cleanup'
            read_actions = @()
            context_injection = $null
            write_actions = @(
                if (@($CleanupWriteActions).Count -gt 0) { $CleanupWriteActions[0] }
                $CleanupFoldAction
                if (@($CleanupWriteActions).Count -gt 1) { @($CleanupWriteActions | Select-Object -Skip 1) }
            )
        }
    )

    $artifactPaths = [System.Collections.Generic.List[string]]::new()
    $fallbackEventCount = 0
    $budgetGuardRespected = $true
    foreach ($stage in @($stages)) {
        foreach ($readAction in @($stage.read_actions)) {
            if ($readAction.PSObject.Properties.Name -contains 'artifact_path' -and -not [string]::IsNullOrWhiteSpace([string]$readAction.artifact_path)) {
                $artifactPaths.Add([string]$readAction.artifact_path) | Out-Null
            }
            if ([string]$readAction.status -match 'fallback|deferred|guarded|generated') {
                $fallbackEventCount += 1
            }
            if ($readAction.PSObject.Properties.Name -contains 'budget' -and $readAction.PSObject.Properties.Name -contains 'items') {
                if (@($readAction.items).Count -gt [int]$readAction.budget.top_k) {
                    $budgetGuardRespected = $false
                }
            }
        }

        if ($null -ne $stage.context_injection) {
            if (-not [string]::IsNullOrWhiteSpace([string]$stage.context_injection.artifact_path)) {
                $artifactPaths.Add([string]$stage.context_injection.artifact_path) | Out-Null
            }
            if ([int]$stage.context_injection.estimated_tokens -gt [int]$stage.context_injection.budget.max_tokens) {
                $budgetGuardRespected = $false
            }
        }

        foreach ($writeAction in @($stage.write_actions)) {
            if ($writeAction.PSObject.Properties.Name -contains 'artifact_path' -and -not [string]::IsNullOrWhiteSpace([string]$writeAction.artifact_path)) {
                $artifactPaths.Add([string]$writeAction.artifact_path) | Out-Null
            }
            if ([string]$writeAction.status -match 'fallback|deferred|guarded|generated') {
                $fallbackEventCount += 1
            }
        }
    }

    $owners = Get-VibeMemoryCanonicalOwners -Runtime $Runtime
    $report = [pscustomobject]@{
        run_id = $RunId
        generated_at = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
        policy = [pscustomobject]@{
            mode = [string]$Runtime.memory_runtime_v3_policy.mode
            routing_contract = [string]$Runtime.memory_runtime_v3_policy.routing_contract
            canonical_owners = [pscustomobject]$owners
        }
        stages = @($stages)
        summary = [pscustomobject]@{
            stage_count = @($stages).Count
            fallback_event_count = $fallbackEventCount
            artifact_count = @($artifactPaths | Select-Object -Unique).Count
            budget_guard_respected = [bool]$budgetGuardRespected
        }
    }

    $reportPath = Join-Path (Get-VibeMemoryArtifactsRoot -SessionRoot $SessionRoot) 'memory-activation-report.json'
    $markdownPath = Join-Path (Get-VibeMemoryArtifactsRoot -SessionRoot $SessionRoot) 'memory-activation-report.md'
    Write-VibeJsonArtifact -Path $reportPath -Value $report
    Write-VibeMarkdownArtifact -Path $markdownPath -Lines @(
        '# Memory Activation Report',
        '',
        ('- run_id: `{0}`' -f $RunId),
        ('- mode: `{0}`' -f [string]$Runtime.memory_runtime_v3_policy.mode),
        ('- routing_contract: `{0}`' -f [string]$Runtime.memory_runtime_v3_policy.routing_contract),
        ('- fallback_event_count: `{0}`' -f [int]$report.summary.fallback_event_count),
        ('- artifact_count: `{0}`' -f [int]$report.summary.artifact_count),
        ('- budget_guard_respected: `{0}`' -f [bool]$report.summary.budget_guard_respected),
        ''
    )

    return [pscustomobject]@{
        report = $report
        report_path = $reportPath
        markdown_path = $markdownPath
    }
}
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall