@jjh32456/longlive 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +235 -0
- package/LICENSE +21 -0
- package/QUICKSTART.md +362 -0
- package/README.en.md +64 -0
- package/README.md +256 -2
- package/SPEC.md +211 -0
- package/build-info.json +1665 -0
- package/cordis.patch.yml +208 -0
- package/docs/A1-MIGRATION.md +75 -0
- package/docs/ANSWER-GUARD.md +92 -0
- package/docs/ARCHITECTURE.md +128 -0
- package/docs/AUTO-RECALL-WIRING.md +115 -0
- package/docs/AUTO-RECALL.md +237 -0
- package/docs/CONCEPTS.md +143 -0
- package/docs/CONFIG.md +839 -0
- package/docs/ERRORS.md +271 -0
- package/docs/FAQ.md +186 -0
- package/docs/FEATURES.md +579 -0
- package/docs/INDEX-FRESHNESS.md +21 -0
- package/docs/METRICS.md +244 -0
- package/docs/MIGRATION-1.6.0.md +220 -0
- package/docs/OPERATIONS.md +439 -0
- package/docs/PANEL-INTEGRATION.md +190 -0
- package/docs/PRIVACY.md +88 -0
- package/docs/QUICKSTART.md +155 -0
- package/docs/RAW-INDEX-POLICY.md +7 -0
- package/docs/README.en.md +48 -0
- package/docs/RESIDENT-WATCHER.md +90 -0
- package/docs/SESSION-WATCH.md +214 -0
- package/docs/TOOLS.md +184 -0
- package/docs/TROUBLESHOOTING.md +329 -0
- package/icon.svg +11 -0
- package/lib/client.js +436 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +163 -4
- package/runbook.md +343 -0
- package/scripts/archive-digest-build.mjs +668 -0
- package/scripts/auto-truncate-run.ps1 +752 -0
- package/scripts/backfill-auto-cards.mjs +98 -0
- package/scripts/edges-build.mjs +1003 -0
- package/scripts/index-maintain.mjs +39 -0
- package/scripts/index-reconcile.mjs +49 -0
- package/scripts/index-status.mjs +28 -0
- package/scripts/install-resident-watcher.ps1 +15 -0
- package/scripts/install-session-watch.ps1 +332 -0
- package/scripts/install-surgery-task.ps1 +174 -0
- package/scripts/lib/auto-truncate-run.ps1 +512 -0
- package/scripts/lib/session-watch-fixture.mjs +207 -0
- package/scripts/longlive-doctor.mjs +578 -0
- package/scripts/metrics-read.mjs +79 -0
- package/scripts/metrics-sample.mjs +215 -0
- package/scripts/migrate-180.mjs +163 -0
- package/scripts/migrate-200.mjs +8 -0
- package/scripts/migrate-a1-legacy.mjs +62 -0
- package/scripts/migrate-lifecycle.mjs +157 -0
- package/scripts/pack.mjs +392 -0
- package/scripts/recall-index-build.mjs +128 -0
- package/scripts/recall-links-build.mjs +420 -0
- package/scripts/rescore-cards.mjs +36 -0
- package/scripts/resident-watcher-status.ps1 +15 -0
- package/scripts/resident-watcher.ps1 +643 -0
- package/scripts/session-watch-drill.mjs +553 -0
- package/scripts/session-watch-status.ps1 +146 -0
- package/scripts/session-watch.mjs +1367 -0
- package/scripts/surgery-inspect.mjs +122 -0
- package/scripts/surgery-run.cmd +34 -0
- package/scripts/truncate-cli.mjs +279 -0
- package/scripts/unattended-surgery.ps1 +1019 -0
- package/scripts/uninstall-resident-watcher.ps1 +15 -0
- package/scripts/uninstall-session-watch.ps1 +192 -0
- package/scripts/verify-card-anchors.mjs +138 -0
- package/scripts/watch-loop.ps1 +916 -0
- package/src/actions/audit.js +125 -0
- package/src/actions/evidence.js +122 -0
- package/src/actions/fs.js +162 -0
- package/src/activity/index.js +873 -0
- package/src/activity/model.js +351 -0
- package/src/activity/store.js +786 -0
- package/src/activity/summary.js +180 -0
- package/src/activity/thinking.js +191 -0
- package/src/adapters/constants.js +11 -0
- package/src/adapters/engram/data/aliases.json +51 -0
- package/src/adapters/engram/data/policy.json +8 -0
- package/src/adapters/engram/data/routing-rules.json +546 -0
- package/src/adapters/engram/index.js +278 -0
- package/src/adapters/registry.js +315 -0
- package/src/answer/audit.js +238 -0
- package/src/answer/claim-guard.mjs +234 -0
- package/src/answer/evidence.js +30 -0
- package/src/answer/guard.js +1370 -0
- package/src/answer/index.js +1086 -0
- package/src/answer/query.js +111 -0
- package/src/answer/second-hop.mjs +101 -0
- package/src/auto-truncate-status.js +164 -0
- package/src/auto-truncate.js +1181 -0
- package/src/autoprocedure/candidate.js +342 -0
- package/src/autoprocedure/config.js +122 -0
- package/src/autoprocedure/evidence.js +345 -0
- package/src/autoprocedure/index.js +83 -0
- package/src/autoprocedure/ledger.js +329 -0
- package/src/autoprocedure/lint.js +232 -0
- package/src/autoprocedure/llm.js +409 -0
- package/src/autoprocedure/locks.js +102 -0
- package/src/autoprocedure/paths.js +39 -0
- package/src/autoprocedure/privacy.js +87 -0
- package/src/autoprocedure/rules.js +288 -0
- package/src/autoprocedure/runtime.js +718 -0
- package/src/autoprocedure/session-reader.js +328 -0
- package/src/backup.js +310 -0
- package/src/bus/bus.mjs +1446 -0
- package/src/codec.js +269 -0
- package/src/compaction/cut-engine.js +44 -0
- package/src/compaction/engine-core.js +1237 -0
- package/src/compaction/entry.js +228 -0
- package/src/compaction.js +230 -0
- package/src/conclusion.js +366 -0
- package/src/config.js +835 -0
- package/src/d6/runtime.js +517 -0
- package/src/d6/surface.js +181 -0
- package/src/deps.js +189 -0
- package/src/engine-status.js +141 -0
- package/src/features.js +1035 -0
- package/src/handoff/index.js +1077 -0
- package/src/handoff/model.js +1058 -0
- package/src/handoff/store.js +1233 -0
- package/src/heartbeat.js +385 -0
- package/src/home.js +16 -0
- package/src/host-version.js +280 -0
- package/src/hot-truncate-diag.js +98 -0
- package/src/identity/card-marker.js +281 -0
- package/src/identity/handover.js +845 -0
- package/src/identity/index.js +337 -0
- package/src/identity/inject-position.js +133 -0
- package/src/identity/writeback.js +344 -0
- package/src/identity.js +118 -0
- package/src/index.js +647 -0
- package/src/lifecycle/gap-clocks.js +364 -0
- package/src/lifecycle/index.js +269 -0
- package/src/lifecycle/proactive.js +1426 -0
- package/src/live-target.js +212 -0
- package/src/live.js +1603 -0
- package/src/log-rotation.js +153 -0
- package/src/memory/a1-migration.js +190 -0
- package/src/memory/activity-capture.js +229 -0
- package/src/memory/anchor-fallback.js +116 -0
- package/src/memory/anchors.js +194 -0
- package/src/memory/archive-cold-state.mjs +794 -0
- package/src/memory/archive-staging.mjs +305 -0
- package/src/memory/archive.mjs +415 -0
- package/src/memory/audit-records.js +222 -0
- package/src/memory/auto-cards.js +441 -0
- package/src/memory/capture-host.js +297 -0
- package/src/memory/capture.js +496 -0
- package/src/memory/card-anchors.js +203 -0
- package/src/memory/card-priority.js +110 -0
- package/src/memory/cards.js +425 -0
- package/src/memory/catchup.mjs +534 -0
- package/src/memory/conclusion-distill.js +381 -0
- package/src/memory/conclusion-drafts.js +243 -0
- package/src/memory/conflicts.js +1060 -0
- package/src/memory/consolidate.js +834 -0
- package/src/memory/decay.js +311 -0
- package/src/memory/distill.js +485 -0
- package/src/memory/event-index.js +1826 -0
- package/src/memory/evidence-chain.js +295 -0
- package/src/memory/evidence.js +213 -0
- package/src/memory/filter-runner.js +555 -0
- package/src/memory/filter.js +1035 -0
- package/src/memory/forget-v2.js +680 -0
- package/src/memory/forget.js +531 -0
- package/src/memory/frames-activation.js +249 -0
- package/src/memory/frontmatter.js +454 -0
- package/src/memory/fts-query.js +342 -0
- package/src/memory/governance.js +604 -0
- package/src/memory/index-freshness.js +234 -0
- package/src/memory/index.js +435 -0
- package/src/memory/l2-gate.js +169 -0
- package/src/memory/land.mjs +743 -0
- package/src/memory/lifecycle.js +235 -0
- package/src/memory/lock.js +121 -0
- package/src/memory/maintenance.js +1149 -0
- package/src/memory/manifest.js +245 -0
- package/src/memory/memory-health.mjs +607 -0
- package/src/memory/migrate-200.js +1681 -0
- package/src/memory/migrate-lifecycle.js +1808 -0
- package/src/memory/migrate.js +139 -0
- package/src/memory/paths.js +229 -0
- package/src/memory/procedure-candidate.mjs +377 -0
- package/src/memory/procedure.js +982 -0
- package/src/memory/prospective-memory.mjs +362 -0
- package/src/memory/provenance.js +119 -0
- package/src/memory/recall-feedback.mjs +406 -0
- package/src/memory/recall-v2.js +218 -0
- package/src/memory/recall.js +357 -0
- package/src/memory/reconcile.js +265 -0
- package/src/memory/records.js +433 -0
- package/src/memory/reinforce.js +281 -0
- package/src/memory/retention.js +162 -0
- package/src/memory/review.js +124 -0
- package/src/memory/state.js +279 -0
- package/src/memory/tiers.js +168 -0
- package/src/memory/topic-phrases.js +73 -0
- package/src/memory/trust.js +97 -0
- package/src/memory/turn-budget.mjs +290 -0
- package/src/memory/version-chain.js +264 -0
- package/src/memory/wake-bridge.mjs +2999 -0
- package/src/memory/wal.js +137 -0
- package/src/memory/working-frame.js +779 -0
- package/src/metrics/classify.mjs +191 -0
- package/src/metrics/estimate.mjs +108 -0
- package/src/metrics/index.mjs +204 -0
- package/src/metrics/measure.mjs +462 -0
- package/src/metrics/prestep-latency.mjs +307 -0
- package/src/metrics/store.mjs +264 -0
- package/src/original.js +294 -0
- package/src/policy/threshold-policy.js +224 -0
- package/src/policy-profile.js +463 -0
- package/src/recall/anaphora.mjs +87 -0
- package/src/recall/archive-config.mjs +130 -0
- package/src/recall/archive-fallback.mjs +390 -0
- package/src/recall/archive-search.mjs +428 -0
- package/src/recall/archive-state.mjs +588 -0
- package/src/recall/brain.mjs +501 -0
- package/src/recall/cards.mjs +202 -0
- package/src/recall/current-line.mjs +110 -0
- package/src/recall/edges.js +398 -0
- package/src/recall/embedding.mjs +698 -0
- package/src/recall/entities.mjs +112 -0
- package/src/recall/explain.mjs +443 -0
- package/src/recall/force-policy.mjs +138 -0
- package/src/recall/gate-log.mjs +280 -0
- package/src/recall/gate-metrics.mjs +191 -0
- package/src/recall/index.js +1337 -0
- package/src/recall/inject-order.mjs +279 -0
- package/src/recall/link-recall.mjs +183 -0
- package/src/recall/links.mjs +696 -0
- package/src/recall/privacy.mjs +208 -0
- package/src/recall/recall-core.mjs +810 -0
- package/src/recall/shared-visibility.js +302 -0
- package/src/recall/time-normalizer.mjs +196 -0
- package/src/recall/turn-budget-inject.mjs +154 -0
- package/src/retention/cold-gate.mjs +146 -0
- package/src/retention/config.js +163 -0
- package/src/retention/index.js +801 -0
- package/src/role/activation.js +191 -0
- package/src/role/attention.js +318 -0
- package/src/role/base.js +36 -0
- package/src/role/channels.js +423 -0
- package/src/role/index.js +425 -0
- package/src/role/interfaces.js +115 -0
- package/src/role/personality.js +370 -0
- package/src/role/readers.js +151 -0
- package/src/role/relationships.js +477 -0
- package/src/role/store.js +202 -0
- package/src/role/writeprotect.js +373 -0
- package/src/router/aliases.json +182 -0
- package/src/router/background/agent-runner.mjs +239 -0
- package/src/router/background/anchor.mjs +323 -0
- package/src/router/background/audit.mjs +337 -0
- package/src/router/background/budget-ledger.mjs +648 -0
- package/src/router/background/host-sim.mjs +451 -0
- package/src/router/background/index.mjs +81 -0
- package/src/router/background/memory.mjs +63 -0
- package/src/router/background/mock-llm.mjs +203 -0
- package/src/router/background/queue.mjs +224 -0
- package/src/router/background/retry.mjs +255 -0
- package/src/router/background/router.mjs +1459 -0
- package/src/router/background/stream.mjs +276 -0
- package/src/router/background/tool-policy.mjs +255 -0
- package/src/router/design-headings.json +221 -0
- package/src/router/face/config.mjs +155 -0
- package/src/router/face/context.mjs +284 -0
- package/src/router/face/face.mjs +466 -0
- package/src/router/face/identity.mjs +130 -0
- package/src/router/face/index.mjs +65 -0
- package/src/router/face/journal.mjs +119 -0
- package/src/router/face/llm.mjs +252 -0
- package/src/router/face/outbox.mjs +153 -0
- package/src/router/face/paths.mjs +54 -0
- package/src/router/judge.mjs +987 -0
- package/src/router/policies/generic.json +131 -0
- package/src/router/route.js +1766 -0
- package/src/router/router.mjs +535 -0
- package/src/router/routing-rules.json +816 -0
- package/src/router/run-sim.mjs +530 -0
- package/src/router/runtime.js +569 -0
- package/src/router/service/apply.mjs +1218 -0
- package/src/router/service/board.mjs +712 -0
- package/src/router/service/caller.mjs +131 -0
- package/src/router/service/config.mjs +361 -0
- package/src/router/service/context.mjs +314 -0
- package/src/router/service/hint.mjs +668 -0
- package/src/router/service/lease.mjs +494 -0
- package/src/router/service/live.mjs +251 -0
- package/src/router/service/lock.mjs +550 -0
- package/src/router/service/merge.mjs +255 -0
- package/src/router/service/model-resolve.mjs +350 -0
- package/src/router/service/paths.mjs +168 -0
- package/src/router/service/proposals.mjs +1461 -0
- package/src/router/service/queue.mjs +477 -0
- package/src/router/service/reconcile.mjs +271 -0
- package/src/router/service/service.mjs +2998 -0
- package/src/router/service/sources.mjs +352 -0
- package/src/router/service/status.mjs +520 -0
- package/src/router/service/store.mjs +476 -0
- package/src/router/service/ticklock.mjs +239 -0
- package/src/router/service/tokens.mjs +95 -0
- package/src/router/service/tools.mjs +248 -0
- package/src/router/service/wake.mjs +544 -0
- package/src/router/service/wal.mjs +685 -0
- package/src/router/shadow.mjs +821 -0
- package/src/surgery-recovery.js +1909 -0
- package/src/tool-output.js +485 -0
- package/src/tools.js +3262 -0
- package/src/truncate-visible.js +2416 -0
- package/src/truncate.js +999 -0
- package/src/ui/actions.js +1312 -0
- package/src/ui/flags.js +259 -0
- package/src/ui/panel-api.js +371 -0
- package/src/ui/panel-auth.js +251 -0
- package/src/ui/panel-integrity.js +243 -0
- package/src/ui/routes-readonly.js +759 -0
- package/src/ui/routes.js +284 -0
- package/src/util/append-store.js +368 -0
- package/src/util/local-day.js +30 -0
- package/src/util/redact.js +227 -0
- package/src/util/stale-locks.js +148 -0
- package/src/version.js +99 -0
- package/test/fixtures/pre-step-container.mjs +100 -0
- package/test/p1_probe.mjs +97 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#requires -Version 5.1
|
|
2
|
+
param(
|
|
3
|
+
[Parameter(ValueFromRemainingArguments = $true)]
|
|
4
|
+
[string[]]$RestArgs = @()
|
|
5
|
+
)
|
|
6
|
+
# Keep the historical $args contract: this script and its thin wrappers pass
|
|
7
|
+
# tokens such as --install / --status / --once through @args / $args.
|
|
8
|
+
$args = $RestArgs
|
|
9
|
+
|
|
10
|
+
# uninstall.ps1 - thin wrapper: same flags as resident-watcher.ps1 --uninstall
|
|
11
|
+
$ErrorActionPreference = 'Stop'
|
|
12
|
+
$cli = Join-Path $PSScriptRoot 'resident-watcher.ps1'
|
|
13
|
+
$ps = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
14
|
+
& $ps -NoProfile -ExecutionPolicy Bypass -File $cli --uninstall @args
|
|
15
|
+
exit $LASTEXITCODE
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#Requires -Version 5.1
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Uninstall the resident session watchdog scheduled task and its files.
|
|
5
|
+
|
|
6
|
+
.DESCRIPTION
|
|
7
|
+
Orderly shutdown:
|
|
8
|
+
1. write <memoryRoot>\.longlive\session-watch\stop.flag so the loop exits
|
|
9
|
+
after its current tick (it checks every 5 seconds),
|
|
10
|
+
2. stop and unregister the scheduled task (Stop/Unregister-ScheduledTask,
|
|
11
|
+
falling back to schtasks /End and /Delete),
|
|
12
|
+
3. if a recorded loop pid is still alive AND its command line contains
|
|
13
|
+
scripts\session-watch.mjs, stop that process; never kill by pid alone,
|
|
14
|
+
4. remove the install directory (receipts and state live under memoryRoot
|
|
15
|
+
and are deliberately kept).
|
|
16
|
+
|
|
17
|
+
This script changes Task Scheduler, which is a high-impact action on a real
|
|
18
|
+
machine. Dry-run it first:
|
|
19
|
+
powershell -NoProfile -File uninstall-session-watch.ps1 -DryRun
|
|
20
|
+
|
|
21
|
+
All paths used in task commands are ASCII-only; non-ASCII input is rejected.
|
|
22
|
+
|
|
23
|
+
.PARAMETER KeepFiles
|
|
24
|
+
Unregister and stop, but leave the install directory in place.
|
|
25
|
+
|
|
26
|
+
.PARAMETER ForceStop
|
|
27
|
+
If the loop does not exit within 15 seconds after stop.flag, stop the
|
|
28
|
+
recorded pid only when its command line matches the watcher script.
|
|
29
|
+
|
|
30
|
+
.PARAMETER ForceRemove
|
|
31
|
+
Allow removing a non-default install directory (still refuses a path whose
|
|
32
|
+
leaf is not dsh-session-watch).
|
|
33
|
+
#>
|
|
34
|
+
[CmdletBinding()]
|
|
35
|
+
param(
|
|
36
|
+
[string]$InstallDir = (Join-Path $env:LOCALAPPDATA 'dsh-session-watch'),
|
|
37
|
+
[string]$TaskName = 'DshSessionWatch',
|
|
38
|
+
[switch]$DryRun,
|
|
39
|
+
[switch]$KeepFiles,
|
|
40
|
+
[switch]$ForceStop,
|
|
41
|
+
[switch]$ForceRemove
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
$ErrorActionPreference = 'Stop'
|
|
45
|
+
|
|
46
|
+
function Fail([string]$Message) {
|
|
47
|
+
throw "uninstall-session-watch: $Message"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function Test-AsciiPath([string]$Value, [string]$Label) {
|
|
51
|
+
if ([string]::IsNullOrWhiteSpace($Value)) { Fail "$Label is empty" }
|
|
52
|
+
if ($Value -notmatch '^[\x20-\x7E]+$') { Fail "$Label must be pure ASCII, got: $Value" }
|
|
53
|
+
return $Value
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Resolve-FullPath([string]$Value, [string]$Base) {
|
|
57
|
+
if ([string]::IsNullOrWhiteSpace($Value)) { return '' }
|
|
58
|
+
if ([System.IO.Path]::IsPathRooted($Value)) { return [System.IO.Path]::GetFullPath($Value) }
|
|
59
|
+
return [System.IO.Path]::GetFullPath((Join-Path $Base $Value))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
$install = Resolve-FullPath $InstallDir (Get-Location).Path
|
|
63
|
+
[void](Test-AsciiPath $install 'InstallDir')
|
|
64
|
+
[void](Test-AsciiPath $TaskName 'TaskName')
|
|
65
|
+
|
|
66
|
+
$configPath = Join-Path $install 'session-watch.config.json'
|
|
67
|
+
$config = $null
|
|
68
|
+
if (Test-Path -LiteralPath $configPath -PathType Leaf) {
|
|
69
|
+
try { $config = Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json } catch { $config = $null }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
$memoryRoot = ''
|
|
73
|
+
$stopFlag = ''
|
|
74
|
+
$lockPath = ''
|
|
75
|
+
if ($config) {
|
|
76
|
+
$memoryRoot = [string]$config.memoryRoot
|
|
77
|
+
$stopFlag = [string]$config.stopFlag
|
|
78
|
+
$lockPath = [string]$config.lockPath
|
|
79
|
+
}
|
|
80
|
+
if (-not $memoryRoot -and $env:DSH_MEM) { $memoryRoot = $env:DSH_MEM }
|
|
81
|
+
if (-not $memoryRoot) {
|
|
82
|
+
$home = if ($env:DSH_HOME) { $env:DSH_HOME } else { Join-Path $env:USERPROFILE '.dsh' }
|
|
83
|
+
$memoryRoot = Join-Path $home 'longlive-memory'
|
|
84
|
+
}
|
|
85
|
+
if (-not $stopFlag) { $stopFlag = Join-Path $memoryRoot '.longlive\session-watch\stop.flag' }
|
|
86
|
+
if (-not $lockPath) { $lockPath = Join-Path $memoryRoot '.longlive\session-watch\watch.pid' }
|
|
87
|
+
|
|
88
|
+
$plan = [ordered]@{
|
|
89
|
+
ok = $true
|
|
90
|
+
dryRun = [bool]$DryRun
|
|
91
|
+
installDir = $install
|
|
92
|
+
taskName = $TaskName
|
|
93
|
+
memoryRoot = $memoryRoot
|
|
94
|
+
stopFlag = $stopFlag
|
|
95
|
+
lockPath = $lockPath
|
|
96
|
+
keepFiles = [bool]$KeepFiles
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ($DryRun) {
|
|
100
|
+
$plan['taskExists'] = [bool](Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue)
|
|
101
|
+
$plan['configExists'] = [bool](Test-Path -LiteralPath $configPath -PathType Leaf)
|
|
102
|
+
$plan['note'] = 'dry run: no flag written, no task changed, no file removed'
|
|
103
|
+
$plan | ConvertTo-Json -Depth 6
|
|
104
|
+
exit 0
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# --- 1. ask the loop to stop ----------------------------------------------------
|
|
108
|
+
$stopRequested = $false
|
|
109
|
+
if (Test-Path -LiteralPath (Split-Path -Parent $stopFlag)) {
|
|
110
|
+
[System.IO.File]::WriteAllText($stopFlag, (Get-Date).ToString('o') + [Environment]::NewLine,
|
|
111
|
+
(New-Object System.Text.UTF8Encoding($false)))
|
|
112
|
+
$stopRequested = $true
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# --- 2. stop and unregister the task -------------------------------------------
|
|
116
|
+
$taskStopped = $false
|
|
117
|
+
$taskRemoved = $false
|
|
118
|
+
$taskSeen = $false
|
|
119
|
+
try {
|
|
120
|
+
$task = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
|
|
121
|
+
if ($task) {
|
|
122
|
+
$taskSeen = $true
|
|
123
|
+
try { Stop-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue; $taskStopped = $true } catch { }
|
|
124
|
+
try {
|
|
125
|
+
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction Stop
|
|
126
|
+
$taskRemoved = $true
|
|
127
|
+
} catch {
|
|
128
|
+
& schtasks.exe /Delete /TN $TaskName /F 2>&1 | ForEach-Object { Write-Verbose $_ }
|
|
129
|
+
if ($LASTEXITCODE -eq 0) { $taskRemoved = $true }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
# Get-ScheduledTask can be unavailable; fall through to schtasks.
|
|
134
|
+
& schtasks.exe /Query /TN $TaskName 2>&1 | Out-Null
|
|
135
|
+
if ($LASTEXITCODE -eq 0) {
|
|
136
|
+
$taskSeen = $true
|
|
137
|
+
& schtasks.exe /End /TN $TaskName 2>&1 | ForEach-Object { Write-Verbose $_ }
|
|
138
|
+
if ($LASTEXITCODE -eq 0) { $taskStopped = $true }
|
|
139
|
+
& schtasks.exe /Delete /TN $TaskName /F 2>&1 | ForEach-Object { Write-Verbose $_ }
|
|
140
|
+
if ($LASTEXITCODE -eq 0) { $taskRemoved = $true }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# --- 3. wait for the loop, then only kill a verified watcher -------------------
|
|
145
|
+
$loopPid = $null
|
|
146
|
+
if (Test-Path -LiteralPath $lockPath -PathType Leaf) {
|
|
147
|
+
try { $loopPid = [int](Get-Content -LiteralPath $lockPath -Raw).Trim() } catch { $loopPid = $null }
|
|
148
|
+
}
|
|
149
|
+
$loopExited = $true
|
|
150
|
+
$forced = $false
|
|
151
|
+
if ($loopPid -and $loopPid -gt 0) {
|
|
152
|
+
$loopExited = $false
|
|
153
|
+
for ($i = 0; $i -lt 15; $i++) {
|
|
154
|
+
if (-not (Get-Process -Id $loopPid -ErrorAction SilentlyContinue)) { $loopExited = $true; break }
|
|
155
|
+
Start-Sleep -Seconds 1
|
|
156
|
+
}
|
|
157
|
+
if (-not $loopExited -and $ForceStop) {
|
|
158
|
+
$proc = Get-CimInstance Win32_Process -Filter "ProcessId = $loopPid" -ErrorAction SilentlyContinue
|
|
159
|
+
if ($proc -and $proc.CommandLine -and $proc.CommandLine -match 'session-watch\.mjs') {
|
|
160
|
+
Stop-Process -Id $loopPid -Force -ErrorAction Stop
|
|
161
|
+
$forced = $true
|
|
162
|
+
Start-Sleep -Seconds 1
|
|
163
|
+
$loopExited = -not [bool](Get-Process -Id $loopPid -ErrorAction SilentlyContinue)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# --- 4. remove install files (never memoryRoot evidence) -----------------------
|
|
169
|
+
$removedFiles = $false
|
|
170
|
+
if (-not $KeepFiles) {
|
|
171
|
+
$leaf = Split-Path -Leaf $install
|
|
172
|
+
if ($leaf -ne 'dsh-session-watch' -and -not $ForceRemove) {
|
|
173
|
+
Fail "refusing to remove ${install}: leaf is not dsh-session-watch (pass -ForceRemove)"
|
|
174
|
+
}
|
|
175
|
+
if (Test-Path -LiteralPath $install -PathType Container) {
|
|
176
|
+
Remove-Item -LiteralPath $install -Recurse -Force -ErrorAction Stop
|
|
177
|
+
$removedFiles = $true
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
$plan['stopRequested'] = $stopRequested
|
|
182
|
+
$plan['taskSeen'] = $taskSeen
|
|
183
|
+
$plan['taskStopped'] = $taskStopped
|
|
184
|
+
$plan['taskRemoved'] = $taskRemoved
|
|
185
|
+
$plan['loopPid'] = $loopPid
|
|
186
|
+
$plan['loopExited'] = $loopExited
|
|
187
|
+
$plan['forced'] = $forced
|
|
188
|
+
$plan['removedFiles'] = $removedFiles
|
|
189
|
+
if ($loopPid -and -not $loopExited) { $plan['ok'] = $false }
|
|
190
|
+
$plan['finishedAt'] = (Get-Date).ToString('o')
|
|
191
|
+
$plan | ConvertTo-Json -Depth 6
|
|
192
|
+
if ($plan['ok']) { exit 0 } else { exit 1 }
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// scripts/verify-card-anchors.mjs — 1.8.0 AutoCard anchor liveness check.
|
|
3
|
+
//
|
|
4
|
+
// node scripts/verify-card-anchors.mjs [--memory-root <dir>] [--sessions-root <dir>]
|
|
5
|
+
// [--all | --sample N] [--json] [--out <file>]
|
|
6
|
+
//
|
|
7
|
+
// Reads `.longlive/index/cards.jsonl`, loads the original L0 session for every
|
|
8
|
+
// card anchor, recomputes turnDigest, and labels each card live / stale / missing.
|
|
9
|
+
// Exit 1 when any card is not live (unless --allow-stale for inspection runs).
|
|
10
|
+
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
import { parseSession } from '../src/codec.js';
|
|
16
|
+
import { discoverSessionLogs, extractTurns } from '../src/memory/event-index.js';
|
|
17
|
+
import { readAutoCards, cardsPathOf } from '../src/memory/auto-cards.js';
|
|
18
|
+
|
|
19
|
+
function dshHome() {
|
|
20
|
+
const raw = process.env.DSH_HOME;
|
|
21
|
+
return typeof raw === 'string' && raw.trim() !== '' ? path.resolve(raw.trim()) : path.join(os.homedir(), '.dsh');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function defaultMemoryRoot() {
|
|
25
|
+
for (const envName of ['DSH_LONGLIVE_MEMORY_ROOT', 'DSH_MEM']) {
|
|
26
|
+
const value = process.env[envName];
|
|
27
|
+
if (typeof value === 'string' && value.trim() !== '') return path.resolve(value.trim());
|
|
28
|
+
}
|
|
29
|
+
return path.join(dshHome(), 'longlive-memory');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseArgs(argv) {
|
|
33
|
+
const out = { memoryRoot: '', sessionsRoot: '', sample: 0, json: false, out: '', allowStale: false };
|
|
34
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
35
|
+
const arg = argv[i];
|
|
36
|
+
const match = /^--([a-z-]+)(?:=(.*))?$/.exec(arg);
|
|
37
|
+
if (!match) continue;
|
|
38
|
+
const [, key, inline] = match;
|
|
39
|
+
const value = inline !== undefined ? inline : (argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[++i] : '');
|
|
40
|
+
if (key === 'memory-root') out.memoryRoot = value;
|
|
41
|
+
else if (key === 'sessions-root') out.sessionsRoot = value;
|
|
42
|
+
else if (key === 'sample') out.sample = Number.parseInt(value, 10) || 0;
|
|
43
|
+
else if (key === 'json') out.json = true;
|
|
44
|
+
else if (key === 'out') out.out = value;
|
|
45
|
+
else if (key === 'allow-stale') out.allowStale = true;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Discover session files without parsing them (avoid loading 900MB at once). */
|
|
51
|
+
function sessionFiles(sessionsRoot) {
|
|
52
|
+
const files = new Map();
|
|
53
|
+
for (const item of discoverSessionLogs([sessionsRoot])) files.set(item.sessionId, item.file);
|
|
54
|
+
return files;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function verifyCards({ memoryRoot, sessionsRoot } = {}) {
|
|
58
|
+
const root = path.resolve(String(memoryRoot ?? ''));
|
|
59
|
+
const cards = readAutoCards(root);
|
|
60
|
+
const files = sessionFiles(path.resolve(String(sessionsRoot ?? '')));
|
|
61
|
+
const items = [];
|
|
62
|
+
const bySession = new Map();
|
|
63
|
+
for (const card of cards) {
|
|
64
|
+
const ids = [card.sessionId, card.anchor?.sessionId].filter(Boolean);
|
|
65
|
+
const sessionId = ids[0];
|
|
66
|
+
if (!bySession.has(sessionId)) bySession.set(sessionId, []);
|
|
67
|
+
bySession.get(sessionId).push(card);
|
|
68
|
+
}
|
|
69
|
+
for (const [sessionId, group] of bySession) {
|
|
70
|
+
let parsed = null;
|
|
71
|
+
const file = files.get(sessionId);
|
|
72
|
+
if (file) {
|
|
73
|
+
try { parsed = parseSession(fs.readFileSync(file)); } catch { parsed = null; }
|
|
74
|
+
}
|
|
75
|
+
// Use the same per-turn extraction as the index builder; turnWindowOf would
|
|
76
|
+
// include preamble events differently and produce false stale digests.
|
|
77
|
+
const records = new Map();
|
|
78
|
+
if (parsed) {
|
|
79
|
+
try {
|
|
80
|
+
for (const record of extractTurns(parsed.header, parsed.events, parsed.frames, parsed.texts)) {
|
|
81
|
+
records.set(record.turn, record);
|
|
82
|
+
}
|
|
83
|
+
} catch { /* unreadable session => missing below */ }
|
|
84
|
+
}
|
|
85
|
+
for (const card of group) {
|
|
86
|
+
const record = records.get(card.turn);
|
|
87
|
+
if (!record) {
|
|
88
|
+
items.push({
|
|
89
|
+
cardId: card.cardId, eventId: card.eventId, sessionId: card.sessionId, turn: card.turn,
|
|
90
|
+
status: 'missing', code: parsed ? 'E_TURN_MISSING' : 'E_SESSION_MISSING',
|
|
91
|
+
expectedDigest: card.anchor.digest, actualDigest: null,
|
|
92
|
+
});
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const anchor = card.anchor;
|
|
96
|
+
const sameWindow = anchor.seqStart === record.seqStart && anchor.seqEnd === record.seqEnd;
|
|
97
|
+
const live = sameWindow && anchor.digest === record.digest;
|
|
98
|
+
items.push({
|
|
99
|
+
cardId: card.cardId, eventId: card.eventId, sessionId: card.sessionId, turn: card.turn,
|
|
100
|
+
status: live ? 'live' : 'stale',
|
|
101
|
+
code: live ? 'OK' : (sameWindow ? 'E_TURN_DIGEST_MISMATCH' : 'E_TURN_WINDOW_MISMATCH'),
|
|
102
|
+
expectedDigest: anchor.digest,
|
|
103
|
+
actualDigest: record.digest,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const counts = { total: items.length, live: 0, stale: 0, missing: 0 };
|
|
108
|
+
for (const item of items) counts[item.status] = (counts[item.status] ?? 0) + 1;
|
|
109
|
+
return { schema: 'card-anchors/v1', memoryRoot: root, cardsFile: cardsPathOf(root), sessions: files.size, counts, items };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === path.resolve(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1'));
|
|
113
|
+
if (isMain) {
|
|
114
|
+
const args = parseArgs(process.argv.slice(2));
|
|
115
|
+
const memoryRoot = args.memoryRoot !== '' ? args.memoryRoot : defaultMemoryRoot();
|
|
116
|
+
const sessionsRoot = args.sessionsRoot !== '' ? args.sessionsRoot : path.join(dshHome(), 'sessions');
|
|
117
|
+
const report = verifyCards({ memoryRoot, sessionsRoot });
|
|
118
|
+
let items = report.items;
|
|
119
|
+
if (args.sample > 0 && items.length > args.sample) {
|
|
120
|
+
items = [...items].sort((a, b) => a.cardId.localeCompare(b.cardId)).slice(0, args.sample);
|
|
121
|
+
}
|
|
122
|
+
const output = { ...report, items, sampled: args.sample > 0 && args.sample < report.items.length };
|
|
123
|
+
const body = args.json || args.out !== '';
|
|
124
|
+
if (body) {
|
|
125
|
+
const text = JSON.stringify(output, null, 2);
|
|
126
|
+
if (args.json) console.log(text);
|
|
127
|
+
if (args.out !== '') {
|
|
128
|
+
fs.mkdirSync(path.dirname(path.resolve(args.out)), { recursive: true });
|
|
129
|
+
fs.writeFileSync(path.resolve(args.out), `${text}\n`, 'utf8');
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
console.log(`[verify-card-anchors] total=${output.counts.total} live=${output.counts.live} stale=${output.counts.stale} missing=${output.counts.missing}`);
|
|
133
|
+
for (const item of items.filter((x) => x.status !== 'live').slice(0, 20)) {
|
|
134
|
+
console.log(` ${item.status} ${item.cardId} ${item.sessionId}#${item.turn} ${item.code}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if ((output.counts.stale > 0 || output.counts.missing > 0) && !args.allowStale) process.exitCode = 1;
|
|
138
|
+
}
|