@try-works/dsh-recursive-mode 0.1.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.
Files changed (88) hide show
  1. package/cordis.patch.yml +12 -0
  2. package/lib/bootstrap.d.ts +35 -0
  3. package/lib/client/board.d.ts +10 -0
  4. package/lib/client/contract.d.ts +51 -0
  5. package/lib/client/derive.d.ts +92 -0
  6. package/lib/client/index.d.ts +21 -0
  7. package/lib/client/inspector.d.ts +10 -0
  8. package/lib/client/node.d.ts +71 -0
  9. package/lib/client/settings.d.ts +6 -0
  10. package/lib/client/slots.d.ts +7 -0
  11. package/lib/client/strip.d.ts +7 -0
  12. package/lib/client.d.ts +10 -0
  13. package/lib/client.js +490 -0
  14. package/lib/closeout.d.ts +23 -0
  15. package/lib/commands.d.ts +51 -0
  16. package/lib/delegation.d.ts +92 -0
  17. package/lib/enforcement.d.ts +53 -0
  18. package/lib/events.d.ts +173 -0
  19. package/lib/handoff.d.ts +51 -0
  20. package/lib/index.d.ts +40 -0
  21. package/lib/lifecycle.d.ts +107 -0
  22. package/lib/lock.d.ts +92 -0
  23. package/lib/policy.d.ts +12 -0
  24. package/lib/projection.d.ts +29 -0
  25. package/lib/recursive_closeout.tool.d.ts +8 -0
  26. package/lib/recursive_init.tool.d.ts +2 -0
  27. package/lib/recursive_lint.tool.d.ts +2 -0
  28. package/lib/recursive_lock.tool.d.ts +2 -0
  29. package/lib/recursive_scratch.tool.d.ts +7 -0
  30. package/lib/recursive_status.tool.d.ts +2 -0
  31. package/lib/review.d.ts +39 -0
  32. package/lib/router.d.ts +77 -0
  33. package/lib/run.d.ts +29 -0
  34. package/lib/runtime.d.ts +241 -0
  35. package/lib/scratch.d.ts +18 -0
  36. package/lib/status.d.ts +19 -0
  37. package/lib/types.d.ts +104 -0
  38. package/lib/workspace.d.ts +50 -0
  39. package/package.json +119 -0
  40. package/preset/recursive/agent.cordis.yml +282 -0
  41. package/preset/recursive/preset.yml +3 -0
  42. package/scripts/install-recursive-mode.ps1 +956 -0
  43. package/scripts/install-recursive-mode.py +750 -0
  44. package/scripts/lint-recursive-run.py +2868 -0
  45. package/scripts/recursive-closeout.py +541 -0
  46. package/scripts/recursive-init.py +356 -0
  47. package/scripts/recursive-lock.py +302 -0
  48. package/scripts/recursive-status.py +2124 -0
  49. package/scripts/recursive_phase_rules.py +367 -0
  50. package/scripts/recursive_router_lib.py +2282 -0
  51. package/scripts/test-recursive-mode-smoke.ts +204 -0
  52. package/scripts/verify-locks.py +353 -0
  53. package/src/bootstrap.ts +118 -0
  54. package/src/client/board.tsx +61 -0
  55. package/src/client/contract.ts +58 -0
  56. package/src/client/derive.ts +241 -0
  57. package/src/client/index.ts +28 -0
  58. package/src/client/inspector.tsx +49 -0
  59. package/src/client/node.ts +156 -0
  60. package/src/client/settings.tsx +18 -0
  61. package/src/client/slots.ts +67 -0
  62. package/src/client/strip.tsx +28 -0
  63. package/src/client.ts +11 -0
  64. package/src/closeout.ts +183 -0
  65. package/src/commands.ts +142 -0
  66. package/src/delegation.ts +306 -0
  67. package/src/enforcement.ts +180 -0
  68. package/src/events.ts +173 -0
  69. package/src/handoff.ts +165 -0
  70. package/src/index.ts +283 -0
  71. package/src/lifecycle.ts +235 -0
  72. package/src/lock.ts +369 -0
  73. package/src/policy.ts +56 -0
  74. package/src/projection.ts +237 -0
  75. package/src/recursive_closeout.tool.ts +35 -0
  76. package/src/recursive_init.tool.ts +28 -0
  77. package/src/recursive_lint.tool.ts +29 -0
  78. package/src/recursive_lock.tool.ts +33 -0
  79. package/src/recursive_scratch.tool.ts +42 -0
  80. package/src/recursive_status.tool.ts +24 -0
  81. package/src/review.ts +178 -0
  82. package/src/router.ts +197 -0
  83. package/src/run.ts +85 -0
  84. package/src/runtime.ts +564 -0
  85. package/src/scratch.ts +85 -0
  86. package/src/status.ts +194 -0
  87. package/src/types.ts +112 -0
  88. package/src/workspace.ts +67 -0
@@ -0,0 +1,956 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [string]$RepoRoot = (Get-Location).Path,
4
+ [switch]$SkipRecursiveUpdate
5
+ )
6
+
7
+ Set-StrictMode -Version Latest
8
+ $ErrorActionPreference = "Stop"
9
+
10
+ # Shared behavior with install-recursive-mode.py:
11
+ # - bootstraps the canonical .recursive control-plane layout
12
+ # - upserts stable assistant-memory pointers into .cursorrules, CLAUDE.md, and .github/copilot-instructions.md
13
+ # - bootstraps training memory under .recursive/memory/training/
14
+ # - copies the packaged runtime scripts into .recursive/scripts/
15
+
16
+ function Write-Utf8NoBom {
17
+ param(
18
+ [Parameter(Mandatory = $true)][string]$Path,
19
+ [Parameter(Mandatory = $true)][AllowEmptyString()][string]$Content
20
+ )
21
+
22
+ $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
23
+ [System.IO.File]::WriteAllText($Path, $Content, $utf8NoBom)
24
+ }
25
+
26
+ function Ensure-Directory {
27
+ param([Parameter(Mandatory = $true)][string]$Path)
28
+
29
+ if (-not (Test-Path -LiteralPath $Path)) {
30
+ New-Item -Path $Path -ItemType Directory -Force | Out-Null
31
+ Write-Output "[OK] Created directory: $Path"
32
+ } else {
33
+ Write-Output "[OK] Directory exists: $Path"
34
+ }
35
+ }
36
+
37
+ function Ensure-File {
38
+ param(
39
+ [Parameter(Mandatory = $true)][string]$Path,
40
+ [Parameter(Mandatory = $true)][AllowEmptyString()][string]$Content
41
+ )
42
+
43
+ if (-not (Test-Path -LiteralPath $Path)) {
44
+ $parent = Split-Path -Path $Path -Parent
45
+ if ($parent) {
46
+ Ensure-Directory -Path $parent
47
+ }
48
+ Write-Utf8NoBom -Path $Path -Content $Content
49
+ Write-Output "[OK] Created file: $Path"
50
+ } else {
51
+ Write-Output "[OK] File exists: $Path"
52
+ }
53
+ }
54
+
55
+ function Ensure-GitIgnoreLine {
56
+ param(
57
+ [Parameter(Mandatory = $true)][string]$RepoRoot,
58
+ [Parameter(Mandatory = $true)][string]$Line
59
+ )
60
+
61
+ $gitIgnorePath = Join-Path $RepoRoot ".gitignore"
62
+ $normalizedLine = $Line.Trim()
63
+ $existing = ""
64
+ if (Test-Path -LiteralPath $gitIgnorePath) {
65
+ $existing = Get-Content -LiteralPath $gitIgnorePath -Raw -Encoding UTF8
66
+ if ($null -eq $existing) {
67
+ $existing = ""
68
+ }
69
+ }
70
+
71
+ $existingLines = if ($existing) { $existing -split "`r?`n" } else { @() }
72
+ foreach ($candidate in $existingLines) {
73
+ if ($candidate.Trim() -eq $normalizedLine) {
74
+ Write-Output "[OK] File already up to date: $gitIgnorePath"
75
+ return
76
+ }
77
+ }
78
+
79
+ $updated = $existing
80
+ if ($updated -and -not $updated.EndsWith("`n")) {
81
+ $updated += "`n"
82
+ }
83
+ $updated += "$normalizedLine`n"
84
+ Write-Utf8NoBom -Path $gitIgnorePath -Content $updated
85
+ if ($existing) {
86
+ Write-Output "[OK] Updated file: $gitIgnorePath"
87
+ } else {
88
+ Write-Output "[OK] Created file: $gitIgnorePath"
89
+ }
90
+ }
91
+
92
+ function Resolve-CanonicalWorkflowPath {
93
+ param([Parameter(Mandatory = $true)][string]$SkillRoot)
94
+
95
+ $candidates = @(
96
+ (Join-Path (Join-Path $SkillRoot ".recursive") "RECURSIVE.md"),
97
+ (Join-Path (Join-Path $SkillRoot "references") "bootstrap\RECURSIVE.md")
98
+ )
99
+
100
+ foreach ($candidate in $candidates) {
101
+ if (Test-Path -LiteralPath $candidate) {
102
+ Write-Host "[INFO] Using canonical workflow template: $candidate"
103
+ return $candidate
104
+ }
105
+ }
106
+
107
+ throw ("Missing canonical workflow template. Expected one of: " + ($candidates -join ", "))
108
+ }
109
+
110
+ function Upsert-MarkedBlock {
111
+ param(
112
+ [Parameter(Mandatory = $true)][string]$FilePath,
113
+ [Parameter(Mandatory = $true)][string]$StartMarker,
114
+ [Parameter(Mandatory = $true)][string]$EndMarker,
115
+ [Parameter(Mandatory = $true)][string]$BlockBody
116
+ )
117
+
118
+ $existing = ""
119
+ if (Test-Path -LiteralPath $FilePath) {
120
+ $existing = Get-Content -LiteralPath $FilePath -Raw -Encoding UTF8
121
+ if ($null -eq $existing) {
122
+ $existing = ""
123
+ }
124
+ }
125
+
126
+ $block = "$StartMarker`r`n$BlockBody`r`n$EndMarker"
127
+ $pattern = "(?s)$([regex]::Escape($StartMarker)).*?$([regex]::Escape($EndMarker))"
128
+
129
+ if ([regex]::IsMatch($existing, $pattern)) {
130
+ $updated = [regex]::Replace(
131
+ $existing,
132
+ $pattern,
133
+ [System.Text.RegularExpressions.MatchEvaluator] { param($m) $block }
134
+ )
135
+ } elseif ([string]::IsNullOrWhiteSpace($existing)) {
136
+ $updated = "$block`r`n"
137
+ } else {
138
+ $trimmed = $existing.TrimEnd("`r", "`n")
139
+ $updated = "$trimmed`r`n`r`n$block`r`n"
140
+ }
141
+
142
+ if ($updated -ne $existing) {
143
+ Write-Utf8NoBom -Path $FilePath -Content $updated
144
+ Write-Output "[OK] Updated file: $FilePath"
145
+ } else {
146
+ Write-Output "[OK] File already up to date: $FilePath"
147
+ }
148
+ }
149
+
150
+ function Get-NormalizedPlainOrWrappedContent {
151
+ param(
152
+ [Parameter(Mandatory = $true)][AllowEmptyString()][string]$Content,
153
+ [Parameter(Mandatory = $true)][string]$StartMarker,
154
+ [Parameter(Mandatory = $true)][string]$EndMarker
155
+ )
156
+
157
+ $startIndex = $Content.IndexOf($StartMarker, [System.StringComparison]::Ordinal)
158
+ $endIndex = $Content.LastIndexOf($EndMarker, [System.StringComparison]::Ordinal)
159
+ if ($startIndex -lt 0 -or $endIndex -lt 0 -or $endIndex -lt $startIndex) {
160
+ return $Content.TrimEnd("`r", "`n")
161
+ }
162
+
163
+ $prefix = $Content.Substring(0, $startIndex).TrimEnd("`r", "`n")
164
+ if (-not [string]::IsNullOrWhiteSpace($prefix)) {
165
+ return $prefix
166
+ }
167
+
168
+ $bodyStart = $startIndex + $StartMarker.Length
169
+ return $Content.Substring($bodyStart, $endIndex - $bodyStart).Trim("`r", "`n")
170
+ }
171
+
172
+ function Sync-PlainFile {
173
+ param(
174
+ [Parameter(Mandatory = $true)][string]$Path,
175
+ [Parameter(Mandatory = $true)][AllowEmptyString()][string]$Content
176
+ )
177
+
178
+ $normalized = $Content.TrimEnd("`r", "`n") + "`n"
179
+ $existing = ""
180
+ if (Test-Path -LiteralPath $Path) {
181
+ $existing = Get-Content -LiteralPath $Path -Raw -Encoding UTF8
182
+ if ($null -eq $existing) {
183
+ $existing = ""
184
+ }
185
+ }
186
+
187
+ if ($existing -ne $normalized) {
188
+ Write-Utf8NoBom -Path $Path -Content $normalized
189
+ Write-Output "[OK] Updated file: $Path"
190
+ } else {
191
+ Write-Output "[OK] File already up to date: $Path"
192
+ }
193
+ }
194
+
195
+ function Upsert-OrMigrateCanonical {
196
+ param(
197
+ [Parameter(Mandatory = $true)][string]$FilePath,
198
+ [Parameter(Mandatory = $true)][string]$StartMarker,
199
+ [Parameter(Mandatory = $true)][string]$EndMarker,
200
+ [Parameter(Mandatory = $true)][string]$BlockBody
201
+ )
202
+
203
+ $existing = ""
204
+ if (Test-Path -LiteralPath $FilePath) {
205
+ $existing = Get-Content -LiteralPath $FilePath -Raw -Encoding UTF8
206
+ if ($null -eq $existing) { $existing = "" }
207
+ }
208
+
209
+ $block = "$StartMarker`r`n$BlockBody`r`n$EndMarker"
210
+ $pattern = "(?s)$([regex]::Escape($StartMarker)).*?$([regex]::Escape($EndMarker))"
211
+
212
+ if ([regex]::IsMatch($existing, $pattern)) {
213
+ $updated = [regex]::Replace(
214
+ $existing,
215
+ $pattern,
216
+ [System.Text.RegularExpressions.MatchEvaluator] { param($m) $block }
217
+ )
218
+ } elseif ([string]::IsNullOrWhiteSpace($existing)) {
219
+ $updated = "$block`r`n"
220
+ } elseif ($existing.TrimEnd("`r", "`n") -eq $BlockBody.TrimEnd("`r", "`n")) {
221
+ # Plain-installed canonical content — wrap in markers without duplication.
222
+ $updated = "$block`r`n"
223
+ } else {
224
+ $trimmed = $existing.TrimEnd("`r", "`n")
225
+ $updated = "$trimmed`r`n`r`n$block`r`n"
226
+ }
227
+
228
+ if ($updated -ne $existing) {
229
+ Write-Utf8NoBom -Path $FilePath -Content $updated
230
+ Write-Output "[OK] Updated file: $FilePath"
231
+ } else {
232
+ Write-Output "[OK] File already up to date: $FilePath"
233
+ }
234
+ }
235
+
236
+ function Get-RecursiveRouterPolicyJson {
237
+ @'
238
+ {
239
+ "version": 1,
240
+ "defaults": {
241
+ "when_role_unconfigured": "ask",
242
+ "when_cli_unavailable": "fallback-local",
243
+ "when_model_unknown": "ask",
244
+ "allow_auto_assign_if_single_cli": false,
245
+ "probe_timeout_ms": 50000,
246
+ "invoke_timeout_ms": 180000
247
+ },
248
+ "role_routes": {
249
+ "orchestrator": {
250
+ "enabled": true,
251
+ "mode": "local-only",
252
+ "cli": null,
253
+ "model": null,
254
+ "fallback": "local-controller"
255
+ },
256
+ "analyst": {
257
+ "enabled": true,
258
+ "mode": "external-cli",
259
+ "cli": null,
260
+ "model": null,
261
+ "fallback": "self-audit"
262
+ },
263
+ "planner": {
264
+ "enabled": true,
265
+ "mode": "external-cli",
266
+ "cli": null,
267
+ "model": null,
268
+ "fallback": "self-audit"
269
+ },
270
+ "implementer": {
271
+ "enabled": false,
272
+ "mode": "external-cli",
273
+ "cli": null,
274
+ "model": null,
275
+ "fallback": "local-controller"
276
+ },
277
+ "code-reviewer": {
278
+ "enabled": true,
279
+ "mode": "external-cli",
280
+ "cli": null,
281
+ "model": null,
282
+ "fallback": "self-audit"
283
+ },
284
+ "tester": {
285
+ "enabled": true,
286
+ "mode": "external-cli",
287
+ "cli": null,
288
+ "model": null,
289
+ "fallback": "self-audit"
290
+ },
291
+ "memory-auditor": {
292
+ "enabled": true,
293
+ "mode": "external-cli",
294
+ "cli": null,
295
+ "model": null,
296
+ "fallback": "self-audit"
297
+ }
298
+ },
299
+ "cli_overrides": {},
300
+ "custom_clis": []
301
+ }
302
+ '@
303
+ }
304
+
305
+ function Ensure-RouterConfigScaffold {
306
+ param([Parameter(Mandatory = $true)][string]$RepoRoot)
307
+
308
+ $configRoot = Join-Path (Join-Path $RepoRoot ".recursive") "config"
309
+ $policyPath = Join-Path $configRoot "recursive-router.json"
310
+ $discoveryPath = Join-Path $configRoot "recursive-router-discovered.json"
311
+ $legacyPolicyPath = Join-Path $configRoot "recursive-router-cli.json"
312
+ $legacyDiscoveryPath = Join-Path $configRoot "recursive-router-cli-discovered.json"
313
+
314
+ Ensure-Directory -Path $configRoot
315
+ if (Test-Path -LiteralPath $policyPath) {
316
+ try {
317
+ $null = (Get-Content -LiteralPath $policyPath -Raw -Encoding UTF8) | ConvertFrom-Json
318
+ } catch {
319
+ throw "Existing routing policy is invalid JSON and will not be overwritten: $policyPath"
320
+ }
321
+ } elseif (Test-Path -LiteralPath $legacyPolicyPath) {
322
+ try {
323
+ $legacyPolicyRaw = Get-Content -LiteralPath $legacyPolicyPath -Raw -Encoding UTF8
324
+ $null = $legacyPolicyRaw | ConvertFrom-Json
325
+ } catch {
326
+ throw "Existing legacy routing policy is invalid JSON and will not be migrated: $legacyPolicyPath"
327
+ }
328
+ Write-Utf8NoBom -Path $policyPath -Content $legacyPolicyRaw
329
+ Remove-Item -LiteralPath $legacyPolicyPath -Force
330
+ Write-Output "[OK] Migrated legacy router policy: $policyPath"
331
+ } else {
332
+ Write-Utf8NoBom -Path $policyPath -Content (Get-RecursiveRouterPolicyJson)
333
+ Write-Output "[OK] Created file: $policyPath"
334
+ }
335
+
336
+ if ((-not (Test-Path -LiteralPath $discoveryPath)) -and (Test-Path -LiteralPath $legacyDiscoveryPath)) {
337
+ Move-Item -LiteralPath $legacyDiscoveryPath -Destination $discoveryPath -Force
338
+ Write-Output "[OK] Migrated legacy router discovery: $discoveryPath"
339
+ }
340
+ }
341
+
342
+ function Get-MemoryRouterBody {
343
+ @'
344
+ ## Memory Router
345
+
346
+ This file is the durable memory router for the repository.
347
+ It is not a knowledge dump. Store durable memory in sharded docs under `domains/`, `patterns/`, `incidents/`, `episodes/`, `training/`, `skills/`, or `archive/`.
348
+
349
+ Control-plane docs are not memory docs:
350
+ - `/.recursive/RECURSIVE.md`
351
+ - `/.recursive/STATE.md`
352
+ - `/.recursive/DECISIONS.md`
353
+ - `/.codex/AGENTS.md`
354
+ - `/AGENTS.md`
355
+ - `/.agent/PLANS.md`
356
+
357
+ ## Retrieval Rules
358
+
359
+ - Read this file before loading any other memory docs.
360
+ - Load only the memory docs relevant to the current task.
361
+ - If the task may benefit from prior recursive-mode experiential learnings, use this index to identify the relevant docs under `/.recursive/memory/training/` and `/.recursive/memory/domains/`.
362
+ - The optional `recursive-training-sync.py` helper is read-only; it prints startup guidance about what to read, but does not modify `MEMORY.md` or the memory plane.
363
+ - If the task plans delegated review, subagent help, review bundles, smoke-harness portability work, or capability-sensitive execution, read `/.recursive/memory/skills/SKILLS.md` and then load the relevant skill-memory shards.
364
+ - If Phase 8 will need to promote durable lessons, first capture run-local skill usage in the run artifact and only then promote generalized conclusions into skill-memory shards.
365
+ - Prefer `Status: CURRENT` docs for planning and execution.
366
+ - `Status: SUSPECT` docs may be used as leads, but revalidate them before trust.
367
+ - Exclude `STALE` and `DEPRECATED` docs from default retrieval unless doing historical analysis.
368
+
369
+ ## Registry
370
+
371
+ - `domains/` - stable functional-area knowledge with `Owns-Paths`
372
+ - `patterns/` - reusable playbooks and solution patterns
373
+ - `incidents/` - recurring failure signatures and fixes
374
+ - `episodes/` - distilled lessons from specific runs
375
+ - `training/` - extracted experiential learnings promoted from completed recursive-mode runs
376
+ - `skills/` - durable skill and capability memory, routed via `skills/SKILLS.md`
377
+ - `archive/` - historical or deprecated memory docs
378
+
379
+ ## Freshness Rules
380
+
381
+ - Durable memory docs must declare the metadata defined by the installed `recursive-mode` artifact template.
382
+ - Any doc whose `Owns-Paths` or `Watch-Paths` overlaps final changed code paths must be reviewed in Phase 8.
383
+ - Affected `CURRENT` docs should be downgraded to `SUSPECT` until revalidated against final code, `STATE.md`, and `DECISIONS.md`.
384
+ - If changed paths have no owning domain doc, create one or record the uncovered-path follow-up in `08-memory-impact.md`.
385
+ - Training memory docs should keep their canonical content under `/.recursive/memory/training/`, use the memory index as the discovery surface, and record source runs plus watch-path or applicability guidance.
386
+ - Skill-memory docs should record source runs, last validated date, environment notes, and current trust/fit guidance.
387
+ - If a run materially teaches the repo something about skill availability, delegated-review quality, review-bundle usage, or toolchain fallback behavior, Phase 8 must either create/refresh a skill-memory shard or record why no durable lesson was promoted.
388
+ - If the repo itself is a reusable skill/workflow distribution, durable memory must remain generalized. Do not store current-session run residue or temp-environment observations as if they were universal truth.
389
+ '@
390
+ }
391
+
392
+ function Get-SkillMemoryRouterBody {
393
+ @'
394
+ ## Skill Memory Router
395
+
396
+ This file routes durable skill and capability knowledge for the repository.
397
+ It summarizes what skills were available, what was attempted, what worked, what failed, and how future runs should use those skills.
398
+
399
+ Use the subfolders for durable Markdown-only skill memory:
400
+
401
+ - `availability/` - environment-specific skill availability and capability probe notes
402
+ - `usage/` - stable usage guidance and fit for specific skills
403
+ - `issues/` - recurring skill failures, limitations, or confusing behavior
404
+ - `patterns/` - reusable multi-skill operating patterns and delegation playbooks
405
+
406
+ Keep this file concise. Link to child docs instead of duplicating them.
407
+
408
+ ## Retrieval Hints
409
+
410
+ - If the run may use delegated review, subagents, or review bundles:
411
+ - read this router
412
+ - read only the most relevant skill-memory docs that are actually present for the current environment and workflow
413
+ - If the run may need specialized external capability:
414
+ - prefer the `find-skills` skill when available
415
+ - otherwise use the Skills CLI directly and treat discovered packages as candidates until quality is checked
416
+ - If the run changes the smoke harness or cross-toolchain behavior:
417
+ - read the most relevant availability/usage notes if any have been intentionally promoted into skill memory
418
+ - In Phase 8, promote durable skill lessons into one of these shards:
419
+ - `availability/` for capability probes and environment constraints
420
+ - `usage/` for stable fit/use guidance
421
+ - `issues/` for recurring failure modes
422
+ - `patterns/` for reusable operating playbooks
423
+ - Before promoting anything durable, capture run-local skill usage in the Phase 8 artifact:
424
+ - what skills were available
425
+ - what skills were sought
426
+ - what skills were attempted or used
427
+ - what worked well or poorly
428
+ - what future guidance should change
429
+
430
+ ## Current Docs
431
+
432
+ - `/.recursive/memory/skills/usage/skill-discovery-and-evaluation.md`
433
+ - `/.recursive/memory/skills/patterns/delegated-verification-and-refresh.md`
434
+ - `/.recursive/memory/skills/patterns/phase8-skill-memory-promotion.md`
435
+ - Add child docs here only when they are intentionally promoted as reusable repository guidance.
436
+ '@
437
+ }
438
+
439
+ function Get-CursorRulesMemoryPointersBody {
440
+ @'
441
+ # recursive-mode memory pointers
442
+ # Canonical repository memory lives under `/.recursive/memory/`.
443
+ # Read `/.recursive/memory/MEMORY.md` before loading any other memory docs.
444
+ # Load only the memory docs relevant to the current task.
445
+ # When repository experiential memory may help, run:
446
+ # python .recursive/scripts/recursive-training-loader.py --repo-root . --query "<task>" --files "<path1,path2>"
447
+ # This file is only a pointer surface; the canonical memory store remains `/.recursive/memory/`.
448
+ '@
449
+ }
450
+
451
+ function Get-ClaudeMemoryPointersBody {
452
+ @'
453
+ ## recursive-mode memory pointers
454
+
455
+ - Canonical repository memory lives under `/.recursive/memory/`.
456
+ - Read `/.recursive/memory/MEMORY.md` before loading any other memory docs.
457
+ - Load only the memory docs relevant to the current task.
458
+ - When repository experiential memory may help, run `python .recursive/scripts/recursive-training-loader.py --repo-root . --query "<task>" --files "<path1,path2>"`.
459
+ - Treat this file as a pointer only; the canonical memory store remains `/.recursive/memory/`.
460
+ '@
461
+ }
462
+
463
+ function Get-CopilotMemoryPointersBody {
464
+ @'
465
+ ## recursive-mode memory pointers
466
+
467
+ - Canonical repository memory lives under `/.recursive/memory/`.
468
+ - Read `/.recursive/memory/MEMORY.md` before loading any other memory docs.
469
+ - Load only the memory docs relevant to the current task.
470
+ - When repository experiential memory may help, run `python .recursive/scripts/recursive-training-loader.py --repo-root . --query "<task>" --files "<path1,path2>"`.
471
+ - Treat this file as a pointer only; the canonical memory store remains `/.recursive/memory/`.
472
+ '@
473
+ }
474
+
475
+ function Get-SkillDiscoveryMemoryDoc {
476
+ @'
477
+ Type: `pattern`
478
+ Status: `CURRENT`
479
+ Scope: `How recursive-mode runs should discover, evaluate, and record external skills or missing capabilities.`
480
+ Owns-Paths:
481
+ Watch-Paths:
482
+ - `/.recursive/RECURSIVE.md`
483
+ - `/.recursive/memory/skills/SKILLS.md`
484
+ - `/.recursive/run/`
485
+ Source-Runs:
486
+ - `none (generic repository guidance)`
487
+ Validated-At-Commit: `generic-repository-guidance`
488
+ Last-Validated: `2026-04-09T00:00:00Z`
489
+ Tags:
490
+ - `skills`
491
+ - `discovery`
492
+ - `find-skills`
493
+ - `capability`
494
+
495
+ # Skill Discovery And Evaluation
496
+
497
+ Use this guidance when a run needs a specialized capability that is not already available.
498
+
499
+ ## Preferred Order
500
+
501
+ 1. Use the `find-skills` skill if it is already installed.
502
+ 2. Otherwise use the Skills CLI directly.
503
+ 3. If nothing suitable exists, proceed with built-in capability and record that no suitable external skill was available.
504
+
505
+ ## Useful Commands
506
+
507
+ - `npx skills find <query>`
508
+ - `npx skills add <package-or-repo>`
509
+ - `npx skills add <package-or-repo> --skill <skill-name>`
510
+ - `npx skills check`
511
+ - `npx skills update`
512
+
513
+ ## Evaluation Rules
514
+
515
+ - Prefer skills from reputable publishers or organizations.
516
+ - Prefer higher install counts when the skills are otherwise comparable.
517
+ - Check upstream repository quality before recommending or installing a skill.
518
+ - Do not treat search results as proof of quality; verify source and documentation first.
519
+
520
+ ## Phase 8 Recording
521
+
522
+ If a run materially used skill discovery, capture it in `08-memory-impact.md` under:
523
+
524
+ - `## Run-Local Skill Usage Capture`
525
+ - `## Skill Memory Promotion Review`
526
+
527
+ Promote only durable, reusable conclusions into skill memory. Leave one-off session notes in the run artifact instead of turning them into durable guidance.
528
+ '@
529
+ }
530
+
531
+ function Get-DelegatedVerificationMemoryDoc {
532
+ @'
533
+ Type: `pattern`
534
+ Status: `CURRENT`
535
+ Scope: `How the main agent verifies delegated review or audit work before accepting it as lockable evidence.`
536
+ Owns-Paths:
537
+ Watch-Paths:
538
+ - `/.recursive/RECURSIVE.md`
539
+ - `/.recursive/memory/skills/SKILLS.md`
540
+ - `/.recursive/run/`
541
+ Source-Runs:
542
+ - `none (generic repository guidance)`
543
+ Validated-At-Commit: `generic-repository-guidance`
544
+ Last-Validated: `2026-04-09T00:00:00Z`
545
+ Tags:
546
+ - `skills`
547
+ - `subagent`
548
+ - `verification`
549
+ - `review-bundle`
550
+
551
+ # Delegated Verification And Refresh
552
+
553
+ Delegated work is optional helper output, not autonomous authority.
554
+
555
+ ## Main-Agent Acceptance Rules
556
+
557
+ Before accepting meaningful delegated work, the main agent should verify:
558
+
559
+ - claimed file impact against the actual diff-owned file set
560
+ - claimed artifact reads or updates against files that actually exist
561
+ - review-bundle contents against the current reviewed artifact and artifact hash
562
+ - requirement, plan, addenda, and prior recursive docs that materially informed acceptance
563
+ - whether any post-review repair made the delegated context stale
564
+
565
+ ## Record In The Phase Artifact
566
+
567
+ When delegated work materially contributes, `## Subagent Contribution Verification` should record:
568
+
569
+ - `Reviewed Action Records`
570
+ - `Main-Agent Verification Performed`
571
+ - `Acceptance Decision`
572
+ - `Refresh Handling`
573
+ - `Repair Performed After Verification`
574
+
575
+ ## Refresh Rule
576
+
577
+ If repairs materially change the reviewed artifact, changed-file scope, or evidence basis, refresh the review bundle or action record before relying on delegated work for lockable evidence.
578
+
579
+ ## Rejection Rule
580
+
581
+ If the main agent cannot verify delegated claims against actual files, actual artifacts, and the actual diff scope, reject the delegated result and fall back to self-audit for lockable completion evidence.
582
+ '@
583
+ }
584
+
585
+ function Get-Phase8SkillMemoryDoc {
586
+ @'
587
+ Type: `pattern`
588
+ Status: `CURRENT`
589
+ Scope: `How Phase 8 captures run-local skill usage and promotes only durable lessons into skill memory.`
590
+ Owns-Paths:
591
+ Watch-Paths:
592
+ - `/.recursive/RECURSIVE.md`
593
+ - `/.recursive/memory/MEMORY.md`
594
+ - `/.recursive/memory/skills/SKILLS.md`
595
+ - `/.recursive/run/`
596
+ Source-Runs:
597
+ - `none (generic repository guidance)`
598
+ Validated-At-Commit: `generic-repository-guidance`
599
+ Last-Validated: `2026-04-09T00:00:00Z`
600
+ Tags:
601
+ - `skills`
602
+ - `memory`
603
+ - `phase8`
604
+ - `promotion`
605
+
606
+ # Phase 8 Skill Memory Promotion
607
+
608
+ Skill memory should be operational, not accidental.
609
+
610
+ ## First Capture It Run-Locally
611
+
612
+ Before promoting durable guidance, record run-local skill usage in `08-memory-impact.md`:
613
+
614
+ - what skills were available
615
+ - what skills were sought
616
+ - what skills were attempted or used
617
+ - what worked well
618
+ - what issues were encountered
619
+ - what future guidance changed
620
+ - what promotion candidates exist
621
+
622
+ ## Then Decide What Becomes Durable
623
+
624
+ Promote only lessons that are:
625
+
626
+ - reusable across runs
627
+ - specific enough to change future planning or verification behavior
628
+ - not merely one-off environmental noise
629
+
630
+ ## Keep The Boundary Honest
631
+
632
+ - Run-local observations belong in the run artifact first.
633
+ - Durable memory should contain generalized guidance, not session history.
634
+ - In reusable skill/workflow repos, do not turn current-session implementation residue into durable memory unless it has been rewritten as generic repository guidance.
635
+ '@
636
+ }
637
+
638
+ function Get-RecursiveAgentsRouterBody {
639
+ @'
640
+ ## .recursive AGENTS Router
641
+
642
+ This file is a lightweight routing/index doc for agents already working inside the repository.
643
+ It exists to reduce blind doc-by-doc scanning. It is not a second workflow spec.
644
+
645
+ ## Canonical Rule
646
+
647
+ - Treat `/.recursive/RECURSIVE.md` as the single workflow source of truth.
648
+ - If this file conflicts with `/.recursive/RECURSIVE.md`, follow `/.recursive/RECURSIVE.md`.
649
+
650
+ ## Suggested Read Order
651
+
652
+ 1. Read `/.recursive/RECURSIVE.md` first for workflow rules and required behavior.
653
+ 2. Read `/.recursive/STATE.md` when the current repo state matters.
654
+ 3. Read `/.recursive/DECISIONS.md` when prior rationale or relevant earlier work matters.
655
+ 4. Read `/.recursive/memory/MEMORY.md` when task context may depend on durable memory.
656
+ 5. Read `/.recursive/memory/skills/SKILLS.md` when the task may use delegated review, subagents, review bundles, smoke-harness portability work, or other capability-sensitive execution.
657
+ 6. Read the recursive-mode package README or maintainer notes from the installed skill directory or source package checkout when changing the package itself.
658
+
659
+ ## Task Routing
660
+
661
+ - Starting or resuming a recursive-mode run:
662
+ - `/.recursive/RECURSIVE.md`
663
+ - `/.recursive/STATE.md`
664
+ - `/.recursive/DECISIONS.md`
665
+ - `/.recursive/memory/MEMORY.md`
666
+ - Authoring a new recursive-mode spec or `00-requirements.md`:
667
+ - `/.recursive/STATE.md`
668
+ - `/.recursive/DECISIONS.md`
669
+ - `/.recursive/memory/MEMORY.md`
670
+ - the installed `recursive-spec` skill
671
+ - relevant code and tests for the requested area
672
+ - Benchmarking recursive-mode against a non-recursive baseline:
673
+ - Install the separate optional `recursive-benchmark` add-on only when the user explicitly asks for benchmarking.
674
+ - Prefer `find-skills` when available; otherwise use `npx skills add <recursive-benchmark-package-or-repo> --full-depth`.
675
+ - The default exported `recursive-mode` package intentionally excludes benchmark fixtures and benchmark skill files.
676
+ - After the benchmark add-on is installed, follow its packaged fixture and harness docs.
677
+ - Working on reusable package/bootstrap/docs for this repo:
678
+ - the recursive-mode package README or maintainer notes from the installed skill directory or source package checkout
679
+ - the recursive-mode installer scripts from the installed skill directory or source package checkout
680
+ - Working on phase artifact structure or lint expectations:
681
+ - the recursive-mode artifact template from the installed skill directory or source package checkout
682
+ - the recursive-mode lint/status helpers from the installed skill directory or source package checkout
683
+ - Working on delegated review, subagent behavior, or routed CLI delegation:
684
+ - `/.recursive/memory/skills/SKILLS.md`
685
+ - `/.recursive/config/recursive-router.json`
686
+ - `/.recursive/config/recursive-router-discovered.json`
687
+ - the installed `recursive-router`, `recursive-subagent`, and `recursive-review-bundle` skills
688
+ - Working on memory behavior:
689
+ - `/.recursive/memory/MEMORY.md`
690
+ - the installed `recursive-training` skill
691
+ - `/.recursive/scripts/recursive-training-loader.py`
692
+ - `/.recursive/memory/training/`
693
+ - `/.recursive/memory/skills/SKILLS.md`
694
+
695
+ ## Non-Canonical Bridges
696
+
697
+ These are adapters, not second specs:
698
+
699
+ - `/.codex/AGENTS.md`
700
+ - `/AGENTS.md`
701
+ - `/.agent/PLANS.md`
702
+
703
+ Read them only when the tool or host expects those entrypoints.
704
+ '@
705
+ }
706
+
707
+ function Get-PlansBridgeBody {
708
+ @'
709
+ ## recursive-mode plans bridge
710
+
711
+ This file exists only for tools that expect the Codex plans bridge at `/.agent/PLANS.md`.
712
+
713
+ The canonical workflow specification lives in `/.recursive/RECURSIVE.md`.
714
+ Do not maintain a second authoritative workflow here.
715
+
716
+ If this bridge conflicts with `/.recursive/RECURSIVE.md`, follow `/.recursive/RECURSIVE.md`.
717
+
718
+ Short user commands that should trigger recursive-mode orchestration include:
719
+
720
+ - `Implement the run`
721
+ - `Implement run <run-id>`
722
+ - `Implement requirement '<run-id>'`
723
+ - `Implement the plan`
724
+ - `Create a new run based on the plan`
725
+ - `Start a recursive run`
726
+
727
+ Resolution rule:
728
+
729
+ - If a run id is explicit, use that run.
730
+ - If exactly one active/incomplete run exists and no run id is given, resume it.
731
+ - If the user refers to a plan, create a new run only when a unique source plan/requirements artifact can be identified from repo docs or immediate task context.
732
+ - If the command is ambiguous, ask for the run id or the repo path of the source plan/requirements artifact.
733
+
734
+ Spec-authoring rule:
735
+
736
+ - If the user asks to create a plan, help plan, create a spec, or write requirements for a new recursive run, prefer `recursive-spec` before orchestration.
737
+ - `recursive-spec` should confirm the user wants spec help, ask what they want to do, read `STATE.md`, `DECISIONS.md`, `MEMORY.md`, and relevant code/tests, keep the draft in temporary non-repo storage, then create the new run only after the requirements are approved.
738
+
739
+ Benchmark rule:
740
+
741
+ - If the user asks to benchmark recursive-mode, compare recursive vs non-recursive execution, or generate a recursive-mode benchmark report, install and use the separate optional `recursive-benchmark` add-on on demand instead of assuming benchmark fixtures ship with the default recursive-mode package.
742
+ - Prefer `find-skills` when available. Otherwise use `npx skills add <recursive-benchmark-package-or-repo> --full-depth`.
743
+
744
+ Audit delegation rule:
745
+
746
+ - If subagents are available and the audit/review context bundle is complete, delegated audit/review is the default path.
747
+ - If the controller still chooses `self-audit`, record a concrete `Delegation Override Reason` in the audited phase artifact.
748
+
749
+ Router rule:
750
+
751
+ - If the user asks to route delegated work through another transport/model, configure or inspect `/.recursive/config/recursive-router.json`, refresh `/.recursive/config/recursive-router-discovered.json`, re-read both immediately before choosing the delegated CLI/model, and use `recursive-router` before dispatching the delegated role.
752
+ '@
753
+ }
754
+
755
+ $resolvedRepoRoot = [System.IO.Path]::GetFullPath($RepoRoot)
756
+ Write-Output "[INFO] Repo root: $resolvedRepoRoot"
757
+
758
+ $skillRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot ".."))
759
+ $canonicalWorkflowPath = Resolve-CanonicalWorkflowPath -SkillRoot $skillRoot
760
+ $agentsBlockPath = Join-Path (Join-Path $skillRoot "references") "agents-block.md"
761
+
762
+ $recursiveRoot = Join-Path $resolvedRepoRoot ".recursive"
763
+ $codexRoot = Join-Path $resolvedRepoRoot ".codex"
764
+ $agentRoot = Join-Path $resolvedRepoRoot ".agent"
765
+ $memoryRoot = Join-Path $recursiveRoot "memory"
766
+ $trainingMemoryRoot = Join-Path $memoryRoot "training"
767
+ $skillMemoryRoot = Join-Path $memoryRoot "skills"
768
+ $runRoot = Join-Path $recursiveRoot "run"
769
+ $configRoot = Join-Path $recursiveRoot "config"
770
+
771
+ $recursivePath = Join-Path $recursiveRoot "RECURSIVE.md"
772
+ $recursiveAgentsPath = Join-Path $recursiveRoot "AGENTS.md"
773
+ $statePath = Join-Path $recursiveRoot "STATE.md"
774
+ $decisionsPath = Join-Path $recursiveRoot "DECISIONS.md"
775
+ $memoryRouterPath = Join-Path $memoryRoot "MEMORY.md"
776
+ $skillMemoryRouterPath = Join-Path $skillMemoryRoot "SKILLS.md"
777
+ $skillDiscoveryPath = Join-Path (Join-Path $skillMemoryRoot "usage") "skill-discovery-and-evaluation.md"
778
+ $delegatedVerificationPath = Join-Path (Join-Path $skillMemoryRoot "patterns") "delegated-verification-and-refresh.md"
779
+ $phase8SkillMemoryPath = Join-Path (Join-Path $skillMemoryRoot "patterns") "phase8-skill-memory-promotion.md"
780
+ $cursorRulesPath = Join-Path $resolvedRepoRoot ".cursorrules"
781
+ $claudePath = Join-Path $resolvedRepoRoot "CLAUDE.md"
782
+ $githubRoot = Join-Path $resolvedRepoRoot ".github"
783
+ $copilotInstructionsPath = Join-Path $githubRoot "copilot-instructions.md"
784
+ $codexAgentsPath = Join-Path $codexRoot "AGENTS.md"
785
+ $rootAgentsPath = Join-Path $resolvedRepoRoot "AGENTS.md"
786
+ $plansPath = Join-Path $agentRoot "PLANS.md"
787
+
788
+ $recursiveStartMarker = "<!-- RECURSIVE-MODE-CANONICAL:START -->"
789
+ $recursiveEndMarker = "<!-- RECURSIVE-MODE-CANONICAL:END -->"
790
+ $memoryStartMarker = "<!-- RECURSIVE-MODE-MEMORY:START -->"
791
+ $memoryEndMarker = "<!-- RECURSIVE-MODE-MEMORY:END -->"
792
+ $agentsStartMarker = "<!-- RECURSIVE-MODE-AGENTS:START -->"
793
+ $agentsEndMarker = "<!-- RECURSIVE-MODE-AGENTS:END -->"
794
+ $plansStartMarker = "<!-- RECURSIVE-MODE-PLANS-BRIDGE:START -->"
795
+ $plansEndMarker = "<!-- RECURSIVE-MODE-PLANS-BRIDGE:END -->"
796
+ $cursorRulesStartMarker = "# RECURSIVE-MODE-MEMORY-POINTERS:START"
797
+ $cursorRulesEndMarker = "# RECURSIVE-MODE-MEMORY-POINTERS:END"
798
+ $repoMarkdownStartMarker = "<!-- RECURSIVE-MODE-MEMORY-POINTERS:START -->"
799
+ $repoMarkdownEndMarker = "<!-- RECURSIVE-MODE-MEMORY-POINTERS:END -->"
800
+
801
+ Ensure-Directory -Path $recursiveRoot
802
+ Ensure-Directory -Path $codexRoot
803
+ Ensure-Directory -Path $agentRoot
804
+ Ensure-Directory -Path $githubRoot
805
+ Ensure-Directory -Path $memoryRoot
806
+ Ensure-Directory -Path $trainingMemoryRoot
807
+ Ensure-Directory -Path $skillMemoryRoot
808
+ Ensure-Directory -Path $runRoot
809
+ Ensure-Directory -Path $configRoot
810
+ foreach ($subdir in @("domains", "patterns", "incidents", "episodes", "archive")) {
811
+ $full = Join-Path $memoryRoot $subdir
812
+ Ensure-Directory -Path $full
813
+ Ensure-File -Path (Join-Path $full ".gitkeep") -Content ""
814
+ }
815
+ Ensure-File -Path (Join-Path $trainingMemoryRoot ".gitkeep") -Content ""
816
+ foreach ($subdir in @("availability", "usage", "issues", "patterns")) {
817
+ $full = Join-Path $skillMemoryRoot $subdir
818
+ Ensure-Directory -Path $full
819
+ Ensure-File -Path (Join-Path $full ".gitkeep") -Content ""
820
+ }
821
+
822
+ $scriptsDest = Join-Path $recursiveRoot "scripts"
823
+ Ensure-Directory -Path $scriptsDest
824
+ $skillScriptsDir = $PSScriptRoot
825
+ $runtimeScripts = Get-ChildItem -LiteralPath $skillScriptsDir -File | Where-Object {
826
+ $_.Extension -in @(".py", ".ps1") -and (
827
+ $_.Name.StartsWith("recursive-") -or
828
+ $_.Name.StartsWith("lint-") -or
829
+ $_.Name.StartsWith("verify-") -or
830
+ $_.Name -in @("recursive_phase_rules.py", "recursive_router_cli_lib.py", "recursive_router_lib.py")
831
+ )
832
+ } | Sort-Object Name
833
+ foreach ($scriptFile in $runtimeScripts) {
834
+ $scriptName = $scriptFile.Name
835
+ $src = Join-Path $skillScriptsDir $scriptName
836
+ $dst = Join-Path $scriptsDest $scriptName
837
+ if (Test-Path -LiteralPath $src) {
838
+ $content = Get-Content -LiteralPath $src -Raw -Encoding UTF8
839
+ $existing = ""
840
+ if (Test-Path -LiteralPath $dst) {
841
+ $existing = Get-Content -LiteralPath $dst -Raw -Encoding UTF8
842
+ if ($null -eq $existing) {
843
+ $existing = ""
844
+ }
845
+ }
846
+ if ($existing -ne $content) {
847
+ Write-Utf8NoBom -Path $dst -Content $content
848
+ Write-Output "[OK] Copied runtime script: $dst"
849
+ } else {
850
+ Write-Output "[OK] Up to date: $dst"
851
+ }
852
+ } else {
853
+ Write-Output "[WARN] Missing runtime script in skill repo: $src"
854
+ }
855
+ }
856
+
857
+ Ensure-File -Path (Join-Path $runRoot ".gitkeep") -Content ""
858
+ Ensure-File -Path $recursivePath -Content "# RECURSIVE.md`n"
859
+ Ensure-File -Path $recursiveAgentsPath -Content "# AGENTS.md`n"
860
+ Ensure-File -Path $statePath -Content @"
861
+ # STATE.md
862
+
863
+ ## Current State
864
+
865
+ - Initial state not documented yet.
866
+ "@
867
+ Ensure-File -Path $decisionsPath -Content @"
868
+ # DECISIONS.md
869
+
870
+ ## Recursive Run Index
871
+
872
+ - No runs recorded yet.
873
+ "@
874
+ Ensure-File -Path $memoryRouterPath -Content "# MEMORY.md`n"
875
+ Ensure-File -Path $skillMemoryRouterPath -Content "# SKILLS.md`n"
876
+ Ensure-File -Path $skillDiscoveryPath -Content (Get-SkillDiscoveryMemoryDoc)
877
+ Ensure-File -Path $delegatedVerificationPath -Content (Get-DelegatedVerificationMemoryDoc)
878
+ Ensure-File -Path $phase8SkillMemoryPath -Content (Get-Phase8SkillMemoryDoc)
879
+ Ensure-File -Path $codexAgentsPath -Content "# AGENTS.md`n"
880
+ Ensure-File -Path $plansPath -Content "# PLANS.md`n"
881
+ Ensure-File -Path $cursorRulesPath -Content ""
882
+ Ensure-File -Path $claudePath -Content ""
883
+ Ensure-File -Path $copilotInstructionsPath -Content ""
884
+ Ensure-GitIgnoreLine -RepoRoot $resolvedRepoRoot -Line "/.recursive/config/recursive-router-discovered.json"
885
+ Ensure-RouterConfigScaffold -RepoRoot $resolvedRepoRoot
886
+
887
+ Upsert-MarkedBlock `
888
+ -FilePath $recursiveAgentsPath `
889
+ -StartMarker $agentsStartMarker `
890
+ -EndMarker $agentsEndMarker `
891
+ -BlockBody ((Get-RecursiveAgentsRouterBody).TrimEnd("`r", "`n"))
892
+ Upsert-MarkedBlock `
893
+ -FilePath $memoryRouterPath `
894
+ -StartMarker $memoryStartMarker `
895
+ -EndMarker $memoryEndMarker `
896
+ -BlockBody ((Get-MemoryRouterBody).TrimEnd("`r", "`n"))
897
+ Upsert-MarkedBlock `
898
+ -FilePath $skillMemoryRouterPath `
899
+ -StartMarker $memoryStartMarker `
900
+ -EndMarker $memoryEndMarker `
901
+ -BlockBody ((Get-SkillMemoryRouterBody).TrimEnd("`r", "`n"))
902
+ Upsert-MarkedBlock `
903
+ -FilePath $cursorRulesPath `
904
+ -StartMarker $cursorRulesStartMarker `
905
+ -EndMarker $cursorRulesEndMarker `
906
+ -BlockBody ((Get-CursorRulesMemoryPointersBody).TrimEnd("`r", "`n"))
907
+ Upsert-MarkedBlock `
908
+ -FilePath $claudePath `
909
+ -StartMarker $repoMarkdownStartMarker `
910
+ -EndMarker $repoMarkdownEndMarker `
911
+ -BlockBody ((Get-ClaudeMemoryPointersBody).TrimEnd("`r", "`n"))
912
+ Upsert-MarkedBlock `
913
+ -FilePath $copilotInstructionsPath `
914
+ -StartMarker $repoMarkdownStartMarker `
915
+ -EndMarker $repoMarkdownEndMarker `
916
+ -BlockBody ((Get-CopilotMemoryPointersBody).TrimEnd("`r", "`n"))
917
+
918
+ if (-not (Test-Path -LiteralPath $agentsBlockPath)) {
919
+ throw "Missing AGENTS bridge template: $agentsBlockPath"
920
+ }
921
+ $agentsBlock = (Get-Content -LiteralPath $agentsBlockPath -Raw -Encoding UTF8).TrimEnd("`r", "`n")
922
+ Upsert-MarkedBlock `
923
+ -FilePath $codexAgentsPath `
924
+ -StartMarker $agentsStartMarker `
925
+ -EndMarker $agentsEndMarker `
926
+ -BlockBody $agentsBlock
927
+
928
+ if (Test-Path -LiteralPath $rootAgentsPath) {
929
+ Upsert-MarkedBlock `
930
+ -FilePath $rootAgentsPath `
931
+ -StartMarker $agentsStartMarker `
932
+ -EndMarker $agentsEndMarker `
933
+ -BlockBody $agentsBlock
934
+ }
935
+
936
+ Upsert-MarkedBlock `
937
+ -FilePath $plansPath `
938
+ -StartMarker $plansStartMarker `
939
+ -EndMarker $plansEndMarker `
940
+ -BlockBody ((Get-PlansBridgeBody).TrimEnd("`r", "`n"))
941
+
942
+ if (-not $SkipRecursiveUpdate) {
943
+ $canonicalBody = Get-NormalizedPlainOrWrappedContent `
944
+ -Content (Get-Content -LiteralPath $canonicalWorkflowPath -Raw -Encoding UTF8) `
945
+ -StartMarker $recursiveStartMarker `
946
+ -EndMarker $recursiveEndMarker
947
+ Upsert-OrMigrateCanonical `
948
+ -FilePath $recursivePath `
949
+ -StartMarker $recursiveStartMarker `
950
+ -EndMarker $recursiveEndMarker `
951
+ -BlockBody $canonicalBody.TrimEnd("`r", "`n")
952
+ } else {
953
+ Write-Output "[INFO] Skipped RECURSIVE.md update by configuration."
954
+ }
955
+
956
+ Write-Output "[OK] recursive-mode installation bootstrap complete."