Add seed-fake-jsonl.ps1 verification helper and README
This commit is contained in:
parent
0e8a87fbc5
commit
c1ef514697
2 changed files with 196 additions and 0 deletions
83
scripts/seed-fake-jsonl.ps1
Normal file
83
scripts/seed-fake-jsonl.ps1
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# Verification helper: append a synthetic assistant line to a JSONL under one
|
||||
# of the resolved roots, so the watcher/poll can be exercised without running
|
||||
# a real Claude Code session.
|
||||
#
|
||||
# Usage (from PowerShell on the Windows host):
|
||||
# .\scripts\seed-fake-jsonl.ps1
|
||||
# .\scripts\seed-fake-jsonl.ps1 -InputTokens 5000 -OutputTokens 1500 -Model claude-sonnet-4-6
|
||||
# .\scripts\seed-fake-jsonl.ps1 -OffsetHours -6 # back-date by 6h to test block boundary
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $Distro = $null, # null → first distro found
|
||||
[string] $Model = "claude-opus-4-7",
|
||||
[int] $InputTokens = 100,
|
||||
[int] $OutputTokens = 500,
|
||||
[int] $CacheCreate = 0,
|
||||
[int] $CacheRead = 0,
|
||||
[double] $OffsetHours = 0, # back/forward date the timestamp
|
||||
[string] $Path = $null # explicit JSONL path; overrides discovery
|
||||
)
|
||||
|
||||
function Find-RootJsonl {
|
||||
param([string] $Distro)
|
||||
|
||||
if ($Path) { return $Path }
|
||||
|
||||
$candidates = @()
|
||||
|
||||
# Native first.
|
||||
$native = Join-Path $env:USERPROFILE ".claude\projects"
|
||||
if (Test-Path $native) { $candidates += $native }
|
||||
|
||||
# WSL.
|
||||
if (-not $Distro) {
|
||||
$distros = (& wsl.exe -l -q) | Where-Object { $_ -and $_.Trim() }
|
||||
if ($distros) { $Distro = $distros[0].Trim() }
|
||||
}
|
||||
if ($Distro) {
|
||||
$homeDir = "\\wsl$\$Distro\home"
|
||||
if (Test-Path $homeDir) {
|
||||
Get-ChildItem $homeDir -Directory | ForEach-Object {
|
||||
$p = Join-Path $_.FullName ".claude\projects"
|
||||
if (Test-Path $p) { $candidates += $p }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $candidates) { throw "No .claude/projects found (native or WSL)." }
|
||||
|
||||
$root = $candidates[0]
|
||||
Write-Host "Using root: $root"
|
||||
|
||||
# Use a dedicated synthetic project dir so we don't pollute real transcripts.
|
||||
$project = Join-Path $root "-fake-claude-usage-widget"
|
||||
New-Item -ItemType Directory -Force -Path $project | Out-Null
|
||||
return Join-Path $project "synthetic.jsonl"
|
||||
}
|
||||
|
||||
$target = Find-RootJsonl -Distro $Distro
|
||||
$ts = (Get-Date).ToUniversalTime().AddHours($OffsetHours).ToString("o")
|
||||
$uuid = [guid]::NewGuid().ToString()
|
||||
$reqId = "req_" + ([guid]::NewGuid().ToString("N").Substring(0, 16))
|
||||
|
||||
$line = @{
|
||||
type = "assistant"
|
||||
timestamp = $ts
|
||||
sessionId = $uuid
|
||||
requestId = $reqId
|
||||
uuid = $uuid
|
||||
message = @{
|
||||
model = $Model
|
||||
usage = @{
|
||||
input_tokens = $InputTokens
|
||||
output_tokens = $OutputTokens
|
||||
cache_creation_input_tokens = $CacheCreate
|
||||
cache_read_input_tokens = $CacheRead
|
||||
}
|
||||
}
|
||||
} | ConvertTo-Json -Compress -Depth 6
|
||||
|
||||
Add-Content -Path $target -Value $line -Encoding UTF8
|
||||
Write-Host "Appended to $target"
|
||||
Write-Host $line
|
||||
Loading…
Add table
Add a link
Reference in a new issue