patchwork-os 1.1.0-beta.4 → 1.1.0-beta.4.canary.438

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.
@@ -1,158 +1,158 @@
1
- #Requires -Version 5.1
2
- <#
3
- .SYNOPSIS
4
- Windows orchestrator launcher — bridges multiple IDE windows simultaneously.
5
-
6
- .DESCRIPTION
7
- Starts the meta-bridge that coordinates multiple IDE windows. Each IDE window
8
- must already have the claude-ide-bridge extension running — this script
9
- connects to them all via the orchestrator mode.
10
-
11
- Run via npm:
12
- npm run start-orchestrator:win
13
-
14
- Or directly:
15
- pwsh -File scripts\start-orchestrator.ps1
16
- pwsh -File scripts\start-orchestrator.ps1 -Port 4746 -Verbose
17
-
18
- .PARAMETER Port
19
- Orchestrator port (default: 4746).
20
-
21
- .PARAMETER Notify
22
- ntfy.sh topic for push notifications (optional).
23
-
24
- .PARAMETER Verbose
25
- Enable verbose orchestrator logging.
26
- #>
27
- [CmdletBinding()]
28
- param(
29
- [int] $Port = 4746,
30
- [string]$Notify = "",
31
- [switch]$VerboseLogging
32
- )
33
-
34
- Set-StrictMode -Version Latest
35
- $ErrorActionPreference = "Stop"
36
-
37
- $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
38
- $BridgeDir = Split-Path -Parent $ScriptDir
39
-
40
- function Write-Status($msg) { Write-Host "[orchestrator] $msg" -ForegroundColor Cyan }
41
- function Write-Ok($msg) { Write-Host "[ok] $msg" -ForegroundColor Green }
42
- function Write-Warn($msg) { Write-Host "[warn] $msg" -ForegroundColor Yellow }
43
-
44
- function Send-Notify($msg) {
45
- if (-not $Notify) { return }
46
- try {
47
- Invoke-RestMethod -Uri "https://ntfy.sh/$Notify" -Method Post -Body $msg -TimeoutSec 5 | Out-Null
48
- } catch { Write-Warn "ntfy notification failed: $_" }
49
- }
50
-
51
- $Jobs = [System.Collections.Generic.List[System.Diagnostics.Process]]::new()
52
-
53
- function Stop-AllJobs {
54
- foreach ($p in $Jobs) {
55
- if (-not $p.HasExited) { try { $p.Kill($true) } catch { } }
56
- }
57
- }
58
-
59
- $null = Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { Stop-AllJobs }
60
-
61
- # ── Dependency check ──────────────────────────────────────────────────────────
62
- $claudeFound = $false
63
- try {
64
- $null = & where.exe claude 2>$null
65
- $claudeFound = $true
66
- } catch { }
67
-
68
- if (-not $claudeFound) {
69
- Write-Error "claude CLI not found on PATH. Install from https://docs.anthropic.com/en/docs/claude-code"
70
- exit 1
71
- }
72
-
73
- # ── Build orchestrator args ───────────────────────────────────────────────────
74
- $orchArgs = @("orchestrator", "--port", $Port)
75
- if ($VerboseLogging) { $orchArgs += "--verbose" }
76
-
77
- # Use dist/ (npm install) or fallback message
78
- $distIndex = Join-Path $BridgeDir "dist\index.js"
79
- if (-not (Test-Path $distIndex)) {
80
- Write-Error "dist/index.js not found. Run 'npm run build' first."
81
- exit 1
82
- }
83
-
84
- # ── Start orchestrator bridge ─────────────────────────────────────────────────
85
- Write-Status "Starting orchestrator bridge on port $Port..."
86
-
87
- $orchInfo = New-Object System.Diagnostics.ProcessStartInfo
88
- $orchInfo.FileName = "cmd.exe"
89
- $orchInfo.Arguments = "/c node `"$distIndex`" " + ($orchArgs -join " ")
90
- $orchInfo.UseShellExecute = $false
91
- $orchInfo.WorkingDirectory = $BridgeDir
92
- $orchProc = [System.Diagnostics.Process]::Start($orchInfo)
93
- $Jobs.Add($orchProc)
94
-
95
- # ── Wait for lock file ────────────────────────────────────────────────────────
96
- $ClaudeBase = if ($env:CLAUDE_CONFIG_DIR) { $env:CLAUDE_CONFIG_DIR } else { Join-Path $env:USERPROFILE ".claude" }
97
- $IdeDir = Join-Path $ClaudeBase "ide"
98
- $LockFile = Join-Path $IdeDir "$Port.lock"
99
- $Deadline = (Get-Date).AddSeconds(20)
100
-
101
- Write-Status "Waiting for orchestrator lock file..."
102
- while ((Get-Date) -lt $Deadline -and -not (Test-Path $LockFile)) {
103
- Start-Sleep -Milliseconds 200
104
- }
105
-
106
- if (-not (Test-Path $LockFile)) {
107
- Write-Error "Orchestrator lock file not written after 20s. Bridge may have failed to start."
108
- Stop-AllJobs
109
- exit 1
110
- }
111
-
112
- try {
113
- $lockContent = Get-Content $LockFile -Raw | ConvertFrom-Json
114
- $token = $lockContent.authToken
115
- } catch {
116
- $token = "(unknown)"
117
- }
118
-
119
- Write-Ok "Orchestrator ready on port $Port"
120
- Send-Notify "Orchestrator started on port $Port"
121
-
122
- # ── Start Claude --ide ────────────────────────────────────────────────────────
123
- Write-Status "Starting claude --ide (connects to orchestrator)..."
124
-
125
- $claudeEnv = [System.Collections.Generic.Dictionary[string,string]]::new()
126
- foreach ($entry in [System.Environment]::GetEnvironmentVariables().GetEnumerator()) {
127
- $claudeEnv[$entry.Key] = $entry.Value
128
- }
129
- $claudeEnv["CLAUDE_CODE_IDE_SKIP_VALID_CHECK"] = "true"
130
-
131
- $claudeInfo = New-Object System.Diagnostics.ProcessStartInfo
132
- $claudeInfo.FileName = "cmd.exe"
133
- $claudeInfo.Arguments = "/c claude --ide"
134
- $claudeInfo.UseShellExecute = $false
135
- foreach ($kv in $claudeEnv.GetEnumerator()) {
136
- $claudeInfo.EnvironmentVariables[$kv.Key] = $kv.Value
137
- }
138
- $claudeProc = [System.Diagnostics.Process]::Start($claudeInfo)
139
- $Jobs.Add($claudeProc)
140
-
141
- # ── Summary ───────────────────────────────────────────────────────────────────
142
- Write-Host ""
143
- Write-Ok "Orchestrator running. Press Ctrl+C to stop all processes."
144
- Write-Host " Orchestrator PID : $($orchProc.Id)"
145
- Write-Host " Claude PID : $($claudeProc.Id)"
146
- Write-Host " Port : $Port"
147
- Write-Host " Token : $($token.Substring(0, [Math]::Min(8, $token.Length)))..."
148
- Write-Host ""
149
- Write-Host "Each IDE window with the bridge extension running will be discovered"
150
- Write-Host "automatically. Type /ide in Claude Code to verify the connection."
151
- Write-Host ""
152
-
153
- try {
154
- $orchProc.WaitForExit()
155
- } finally {
156
- Write-Status "Orchestrator exited — stopping all processes..."
157
- Stop-AllJobs
158
- }
1
+ #Requires -Version 5.1
2
+ <#
3
+ .SYNOPSIS
4
+ Windows orchestrator launcher — bridges multiple IDE windows simultaneously.
5
+
6
+ .DESCRIPTION
7
+ Starts the meta-bridge that coordinates multiple IDE windows. Each IDE window
8
+ must already have the claude-ide-bridge extension running — this script
9
+ connects to them all via the orchestrator mode.
10
+
11
+ Run via npm:
12
+ npm run start-orchestrator:win
13
+
14
+ Or directly:
15
+ pwsh -File scripts\start-orchestrator.ps1
16
+ pwsh -File scripts\start-orchestrator.ps1 -Port 4746 -Verbose
17
+
18
+ .PARAMETER Port
19
+ Orchestrator port (default: 4746).
20
+
21
+ .PARAMETER Notify
22
+ ntfy.sh topic for push notifications (optional).
23
+
24
+ .PARAMETER Verbose
25
+ Enable verbose orchestrator logging.
26
+ #>
27
+ [CmdletBinding()]
28
+ param(
29
+ [int] $Port = 4746,
30
+ [string]$Notify = "",
31
+ [switch]$VerboseLogging
32
+ )
33
+
34
+ Set-StrictMode -Version Latest
35
+ $ErrorActionPreference = "Stop"
36
+
37
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
38
+ $BridgeDir = Split-Path -Parent $ScriptDir
39
+
40
+ function Write-Status($msg) { Write-Host "[orchestrator] $msg" -ForegroundColor Cyan }
41
+ function Write-Ok($msg) { Write-Host "[ok] $msg" -ForegroundColor Green }
42
+ function Write-Warn($msg) { Write-Host "[warn] $msg" -ForegroundColor Yellow }
43
+
44
+ function Send-Notify($msg) {
45
+ if (-not $Notify) { return }
46
+ try {
47
+ Invoke-RestMethod -Uri "https://ntfy.sh/$Notify" -Method Post -Body $msg -TimeoutSec 5 | Out-Null
48
+ } catch { Write-Warn "ntfy notification failed: $_" }
49
+ }
50
+
51
+ $Jobs = [System.Collections.Generic.List[System.Diagnostics.Process]]::new()
52
+
53
+ function Stop-AllJobs {
54
+ foreach ($p in $Jobs) {
55
+ if (-not $p.HasExited) { try { $p.Kill($true) } catch { } }
56
+ }
57
+ }
58
+
59
+ $null = Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { Stop-AllJobs }
60
+
61
+ # ── Dependency check ──────────────────────────────────────────────────────────
62
+ $claudeFound = $false
63
+ try {
64
+ $null = & where.exe claude 2>$null
65
+ $claudeFound = $true
66
+ } catch { }
67
+
68
+ if (-not $claudeFound) {
69
+ Write-Error "claude CLI not found on PATH. Install from https://docs.anthropic.com/en/docs/claude-code"
70
+ exit 1
71
+ }
72
+
73
+ # ── Build orchestrator args ───────────────────────────────────────────────────
74
+ $orchArgs = @("orchestrator", "--port", $Port)
75
+ if ($VerboseLogging) { $orchArgs += "--verbose" }
76
+
77
+ # Use dist/ (npm install) or fallback message
78
+ $distIndex = Join-Path $BridgeDir "dist\index.js"
79
+ if (-not (Test-Path $distIndex)) {
80
+ Write-Error "dist/index.js not found. Run 'npm run build' first."
81
+ exit 1
82
+ }
83
+
84
+ # ── Start orchestrator bridge ─────────────────────────────────────────────────
85
+ Write-Status "Starting orchestrator bridge on port $Port..."
86
+
87
+ $orchInfo = New-Object System.Diagnostics.ProcessStartInfo
88
+ $orchInfo.FileName = "cmd.exe"
89
+ $orchInfo.Arguments = "/c node `"$distIndex`" " + ($orchArgs -join " ")
90
+ $orchInfo.UseShellExecute = $false
91
+ $orchInfo.WorkingDirectory = $BridgeDir
92
+ $orchProc = [System.Diagnostics.Process]::Start($orchInfo)
93
+ $Jobs.Add($orchProc)
94
+
95
+ # ── Wait for lock file ────────────────────────────────────────────────────────
96
+ $ClaudeBase = if ($env:CLAUDE_CONFIG_DIR) { $env:CLAUDE_CONFIG_DIR } else { Join-Path $env:USERPROFILE ".claude" }
97
+ $IdeDir = Join-Path $ClaudeBase "ide"
98
+ $LockFile = Join-Path $IdeDir "$Port.lock"
99
+ $Deadline = (Get-Date).AddSeconds(20)
100
+
101
+ Write-Status "Waiting for orchestrator lock file..."
102
+ while ((Get-Date) -lt $Deadline -and -not (Test-Path $LockFile)) {
103
+ Start-Sleep -Milliseconds 200
104
+ }
105
+
106
+ if (-not (Test-Path $LockFile)) {
107
+ Write-Error "Orchestrator lock file not written after 20s. Bridge may have failed to start."
108
+ Stop-AllJobs
109
+ exit 1
110
+ }
111
+
112
+ try {
113
+ $lockContent = Get-Content $LockFile -Raw | ConvertFrom-Json
114
+ $token = $lockContent.authToken
115
+ } catch {
116
+ $token = "(unknown)"
117
+ }
118
+
119
+ Write-Ok "Orchestrator ready on port $Port"
120
+ Send-Notify "Orchestrator started on port $Port"
121
+
122
+ # ── Start Claude --ide ────────────────────────────────────────────────────────
123
+ Write-Status "Starting claude --ide (connects to orchestrator)..."
124
+
125
+ $claudeEnv = [System.Collections.Generic.Dictionary[string,string]]::new()
126
+ foreach ($entry in [System.Environment]::GetEnvironmentVariables().GetEnumerator()) {
127
+ $claudeEnv[$entry.Key] = $entry.Value
128
+ }
129
+ $claudeEnv["CLAUDE_CODE_IDE_SKIP_VALID_CHECK"] = "true"
130
+
131
+ $claudeInfo = New-Object System.Diagnostics.ProcessStartInfo
132
+ $claudeInfo.FileName = "cmd.exe"
133
+ $claudeInfo.Arguments = "/c claude --ide"
134
+ $claudeInfo.UseShellExecute = $false
135
+ foreach ($kv in $claudeEnv.GetEnumerator()) {
136
+ $claudeInfo.EnvironmentVariables[$kv.Key] = $kv.Value
137
+ }
138
+ $claudeProc = [System.Diagnostics.Process]::Start($claudeInfo)
139
+ $Jobs.Add($claudeProc)
140
+
141
+ # ── Summary ───────────────────────────────────────────────────────────────────
142
+ Write-Host ""
143
+ Write-Ok "Orchestrator running. Press Ctrl+C to stop all processes."
144
+ Write-Host " Orchestrator PID : $($orchProc.Id)"
145
+ Write-Host " Claude PID : $($claudeProc.Id)"
146
+ Write-Host " Port : $Port"
147
+ Write-Host " Token : $($token.Substring(0, [Math]::Min(8, $token.Length)))..."
148
+ Write-Host ""
149
+ Write-Host "Each IDE window with the bridge extension running will be discovered"
150
+ Write-Host "automatically. Type /ide in Claude Code to verify the connection."
151
+ Write-Host ""
152
+
153
+ try {
154
+ $orchProc.WaitForExit()
155
+ } finally {
156
+ Write-Status "Orchestrator exited — stopping all processes..."
157
+ Stop-AllJobs
158
+ }
@@ -1,78 +0,0 @@
1
- /**
2
- * kodama-structure-retest @1d — break-and-retest structure cell.
3
- *
4
- * FROZEN PARAMS (pre-registered off-repo BEFORE any result was computed, at
5
- * ~/.patchwork/qumo/kodama-structure-retest-spec.json; any change must bump
6
- * methodVersion and reset accrual to zero, and requires a fresh spec v2):
7
- *
8
- * FRACTAL_N = 2 swing confirmation window (reuses src/ta/swings.ts
9
- * isFractalHigh/isFractalLow — same definition as
10
- * ta-cycles-1, no new swing logic invented here)
11
- * BREAK_PCT = 0.005 close must clear the level by >=0.5% (close-based,
12
- * filters pure wicks; a close-through is the standard
13
- * textbook break definition)
14
- * RETEST_WINDOW_BARS = 10 bars after the break to look for a retest touch
15
- * RETEST_TOLERANCE_PCT = 0.003 retest bar's low/high must come within 0.3% of the
16
- * level (tighter than the 0.5% break threshold —
17
- * retest should return closer to the exact level)
18
- * OUTCOME_WINDOW_BARS = 10 bars the card races before push/unscorable
19
- * R_MULTIPLIER = 1.0 rRef = entry ± 1× stop-distance
20
- * UNIVERSE = ["BTCUSDT", "ETHUSDT"] — the only symbols cellBacktest.ts's
21
- * ALWAYS_LISTED survivorship guard currently permits; fixed
22
- * BEFORE looking at any results (see spec's sample.universeJustification)
23
- * METHOD_VERSION = "kodama-structure-retest-1d-v1"
24
- *
25
- * Hypothesis: a classic break-and-retest — price breaks a confirmed swing level,
26
- * retests it, and the retest bar's own close holds the continuation side — resolves
27
- * in the continuation direction at a rate greater than a matched-date random-direction
28
- * null, over a fixed 10-bar forward outcome window.
29
- *
30
- * Fire logic (single detect() call per bar-close, walking backward from the latest
31
- * closed bar to find the most recent unconsumed break+retest+hold sequence):
32
- * 1. Find the most recent confirmed swing (high or low) strictly before the
33
- * current bar, using detectSwings(candles, FRACTAL_N) on the visible slice.
34
- * 2. Scan forward from that swing for the first bar whose CLOSE breaks the level
35
- * by >= BREAK_PCT (close-based, direction depends on swing kind: a swing HIGH
36
- * broken upward = bullish break; a swing LOW broken downward = bearish break).
37
- * 3. Within RETEST_WINDOW_BARS bars after the break bar, find the first bar whose
38
- * [low, high] comes within RETEST_TOLERANCE_PCT of the level. That is the
39
- * retest bar.
40
- * 4. If the retest bar's own close holds the continuation side (bullish break:
41
- * close > level; bearish break: close < level) → HOLD, fire a card at that
42
- * bar's close. If it closes through the wrong side → FAIL, no signal for this
43
- * sequence (never re-tried).
44
- * 5. Only the LATEST closed bar in the visible slice may be the fire bar (walk-
45
- * forward discipline: detect() only ever asks "did the retest resolve exactly
46
- * on this last bar?").
47
- *
48
- * Look-ahead self-test: candles beyond the fire bar are mutated; the fire decision
49
- * on the slice ending at the fire bar must be unchanged. Run once at module import.
50
- */
51
- import type { Candle } from "../../types.js";
52
- import type { CellDetector, DetectResult } from "../accrualEmitter.js";
53
- import type { CellSpec } from "../cellBacktest.js";
54
- export declare const METHOD_VERSION = "kodama-structure-retest-1d-v1";
55
- export declare const PERMUTATION_SEED = 777;
56
- export declare const NULL_SEED = 4242;
57
- export declare const FRACTAL_N = 2;
58
- export declare const BREAK_PCT = 0.005;
59
- export declare const RETEST_WINDOW_BARS = 10;
60
- export declare const RETEST_TOLERANCE_PCT = 0.003;
61
- export declare const OUTCOME_WINDOW_BARS = 10;
62
- export declare const R_MULTIPLIER = 1;
63
- export declare const UNIVERSE: readonly ["BTCUSDT", "ETHUSDT"];
64
- /**
65
- * Run on the latest CLOSED candle (candles[n-1]). Returns false if no
66
- * break-and-retest-hold resolves exactly on this bar, or the card geometry
67
- * if it does.
68
- *
69
- * @param candles Chronological 1d candles; last element = latest closed bar.
70
- */
71
- export declare function detectStructureRetest(candles: Candle[]): DetectResult;
72
- export declare const structureRetestDetector: CellDetector;
73
- /**
74
- * FAMILY_N bumps from 2 -> 3 when this cell joins the battery (per this file's
75
- * own header + the pre-registered spec's familyNJustification).
76
- */
77
- export declare const FAMILY_N = 3;
78
- export declare const structureRetestSpec: CellSpec;