-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
381 lines (328 loc) · 12.1 KB
/
setup.ps1
File metadata and controls
381 lines (328 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#Requires -Version 5.1
<#
.SYNOPSIS
Install PersonalKnowledgeBase skills for your AI coding assistant (Windows).
.DESCRIPTION
Creates symlinks (or copies as fallback) from your platform's skill
directory to this repo's skills/ folder. Supports global (default) and
local scopes — see examples.
.PARAMETER RemainingArguments
Platform names (cursor, claude, copilot) and optional trailing scope:
global (default) or local.
.PARAMETER Uninstall
Remove skill symlinks/copies instead of installing.
.EXAMPLE
.\setup.ps1 cursor
.\setup.ps1 cursor global
.\setup.ps1 cursor, claude global
.\setup.ps1 cursor local
.\setup.ps1 -Uninstall cursor
#>
param(
[switch]$Uninstall,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$RemainingArguments = @()
)
$ErrorActionPreference = "Stop"
$VERSION = "1.1.3"
$RepoDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$Skills = @("compile-wiki", "ask-wiki", "lint-wiki")
function Show-Usage {
@"
Usage: .\setup.ps1 <platform>... [global|local]
.\setup.ps1 -Uninstall <platform>...
Platforms: cursor, claude, copilot
Scopes (optional; default: global):
global Symlink skills, write global wiki-config next to skills,
create raw/ and output/ in this repo.
local Symlink skills, scaffold a wiki in the current directory.
Examples:
.\setup.ps1 cursor
.\setup.ps1 cursor global
.\setup.ps1 cursor, claude global
.\setup.ps1 cursor local
.\setup.ps1 -Uninstall cursor
"@ | Write-Host
exit 1
}
function Resolve-TargetDir([string]$p) {
switch ($p) {
"cursor" { return Join-Path $env:USERPROFILE ".cursor\skills" }
"claude" { return Join-Path $env:USERPROFILE ".claude\skills" }
"copilot" { return Join-Path $env:USERPROFILE ".copilot\skills" }
}
}
function Test-SymlinkSupport {
$testDir = Join-Path $env:TEMP "pkb_symlink_test_$(Get-Random)"
$testTarget = Join-Path $env:TEMP "pkb_symlink_target_$(Get-Random)"
try {
New-Item -ItemType Directory -Path $testTarget -Force | Out-Null
New-Item -ItemType SymbolicLink -Path $testDir -Target $testTarget -ErrorAction Stop | Out-Null
return $true
}
catch { return $false }
finally {
Remove-Item $testDir -Force -ErrorAction SilentlyContinue
Remove-Item $testTarget -Recurse -Force -ErrorAction SilentlyContinue
}
}
# Symlink or copy skills only (no wiki-config).
function Install-PlatformSkills([string]$p) {
$targetDir = Resolve-TargetDir $p
Write-Host "[$p] Installing skills (v$VERSION) to $targetDir"
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
foreach ($skill in $Skills) {
$src = Join-Path $RepoDir "skills\$skill"
$dst = Join-Path $targetDir $skill
if (Test-Path $dst) {
$item = Get-Item $dst -Force
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) {
$existing = $item.Target
if ($existing -eq $src) {
Write-Host " $skill -> already linked (skipped)"
continue
}
Write-Host " $skill -> updating link (was: $existing)"
Remove-Item $dst -Force
}
else {
Write-Host " $skill -> WARNING: directory exists and is NOT a symlink."
Write-Host " Back it up manually if needed, then re-run."
continue
}
}
if ($script:CanSymlink) {
New-Item -ItemType SymbolicLink -Path $dst -Target $src | Out-Null
Write-Host " $skill -> linked"
}
else {
Copy-Item -Path $src -Destination $dst -Recurse
Write-Host " $skill -> copied (symlinks unavailable, see note below)"
}
}
Write-Host "[$p] Skills done.`n"
}
function Write-GlobalWikiConfig([string]$p) {
$targetDir = Resolve-TargetDir $p
$dateStr = Get-Date -Format "yyyy-MM-dd"
$configContent = @"
# Wiki Configuration
> Generated by setup.ps1 on $dateStr. Do not edit manually.
- **Wiki root:** ``$RepoDir``
- **Wiki folder:** ``$RepoDir\wiki``
- **Raw folder:** ``$RepoDir\raw``
- **Output folder:** ``$RepoDir\output``
"@
Set-Content -Path (Join-Path $targetDir "wiki-config.md") -Value $configContent
Write-Host "[$p] wiki-config.md -> written (global)`n"
}
function Init-LocalWiki {
$localRoot = (Get-Location).Path
Write-Host "[local] Scaffolding wiki in: $localRoot"
foreach ($dir in @("raw", "output", "wiki")) {
$path = Join-Path $localRoot $dir
if (-not (Test-Path $path)) {
New-Item -ItemType Directory -Path $path -Force | Out-Null
}
}
$indexPath = Join-Path $localRoot "wiki\index.md"
if (-not (Test-Path $indexPath)) {
$srcIndex = Join-Path $RepoDir "wiki\index.md"
if (Test-Path $srcIndex) {
Copy-Item $srcIndex $indexPath
}
else {
@"
# Knowledge Base Index
Welcome to your compounding knowledge base! This file serves as the master taxonomy of all topics extracted from your raw files.
## Topics
<!-- Topics will appear here as you process raw files with compile-wiki.
Each entry follows the format: "- Topic Name: One-line description" -->
---
*Note: Topics are extracted to prioritize general concepts, abstract ideas, processes, and subject matters rather than specific authors or individuals.*
"@ | Set-Content -Path $indexPath
}
Write-Host " wiki/index.md -> created"
}
else {
Write-Host " wiki/index.md -> already exists (skipped)"
}
$logPath = Join-Path $localRoot "wiki\log.md"
if (-not (Test-Path $logPath)) {
$srcLog = Join-Path $RepoDir "wiki\log.md"
if (Test-Path $srcLog) {
Copy-Item $srcLog $logPath
}
else {
@"
# Knowledge Base Processing Log
This log tracks which files from the ``raw/`` folder have been processed and when they were added to the wiki. It prevents the agent from needlessly re-processing old files.
| Date/Time | File Processed | Key Topics Extracted | Status |
|-----------|----------------|----------------------|--------|
"@ | Set-Content -Path $logPath
}
Write-Host " wiki/log.md -> created"
}
else {
Write-Host " wiki/log.md -> already exists (skipped)"
}
$agentsPath = Join-Path $localRoot "AGENTS.md"
if (-not (Test-Path $agentsPath)) {
Copy-Item (Join-Path $RepoDir "AGENTS.md") $agentsPath
Write-Host " AGENTS.md -> copied from template"
}
else {
Write-Host " AGENTS.md -> already exists (skipped)"
}
$lintSrc = Join-Path $RepoDir "lint_graph.js"
$lintDst = Join-Path $localRoot "lint_graph.js"
if (-not (Test-Path $lintDst) -and (Test-Path $lintSrc)) {
Copy-Item $lintSrc $lintDst
Write-Host " lint_graph.js -> copied from template (for /lint-wiki)"
}
elseif (Test-Path $lintDst) {
Write-Host " lint_graph.js -> already exists (skipped)"
}
$obsSrc = Join-Path $RepoDir "wiki\.obsidian"
$obsDst = Join-Path $localRoot "wiki\.obsidian"
if (-not (Test-Path $obsDst) -and (Test-Path $obsSrc)) {
Copy-Item -Path $obsSrc -Destination $obsDst -Recurse
Write-Host " wiki/.obsidian/ -> copied from template"
}
elseif (Test-Path $obsDst) {
Write-Host " wiki/.obsidian/ -> already exists (skipped)"
}
else {
Write-Host " wiki/.obsidian/ -> template missing (skipped)"
}
$dateStr = Get-Date -Format "yyyy-MM-dd"
$configContent = @"
# Wiki Configuration
> Generated by setup.ps1 (local) on $dateStr. Do not edit manually.
- **Wiki root:** ``$localRoot``
- **Wiki folder:** ``$localRoot\wiki``
- **Raw folder:** ``$localRoot\raw``
- **Output folder:** ``$localRoot\output``
"@
Set-Content -Path (Join-Path $localRoot "wiki-config.md") -Value $configContent
Write-Host " wiki-config.md -> written (project root)"
Write-Host "[local] Done.`n"
}
function Uninstall-Platform([string]$p) {
$targetDir = Resolve-TargetDir $p
Write-Host "[$p] Removing skills from $targetDir"
foreach ($skill in $Skills) {
$dst = Join-Path $targetDir $skill
if (Test-Path $dst) {
$item = Get-Item $dst -Force
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) {
Remove-Item $dst -Force
Write-Host " $skill -> removed (symlink)"
}
else {
Remove-Item $dst -Recurse -Force
Write-Host " $skill -> removed (copy)"
}
}
else {
Write-Host " $skill -> not found (skipped)"
}
}
$configFile = Join-Path $targetDir "wiki-config.md"
if (Test-Path $configFile) {
Remove-Item $configFile -Force
Write-Host " wiki-config.md -> removed"
}
Write-Host "[$p] Uninstalled.`n"
}
# --- Parse RemainingArguments ---
if ($null -eq $RemainingArguments -or $RemainingArguments.Count -eq 0) {
Show-Usage
}
$validPlatforms = @("cursor", "claude", "copilot")
$platforms = [System.Collections.Generic.List[string]]::new()
$scope = "global"
$scopeCount = 0
foreach ($token in $RemainingArguments) {
foreach ($part in ($token -split "," | ForEach-Object { $_.Trim() } | Where-Object { $_ })) {
switch ($part) {
"global" { $scope = "global"; $scopeCount++ }
"local" { $scope = "local"; $scopeCount++ }
default {
if ($validPlatforms -notcontains $part) {
Write-Host "Unknown argument: $part" -ForegroundColor Red
Show-Usage
}
$platforms.Add($part)
}
}
}
}
if ($platforms.Count -eq 0) {
Show-Usage
}
if ($scopeCount -gt 1) {
Write-Host "Error: specify only one of 'global' or 'local'." -ForegroundColor Red
exit 1
}
# --- Main ---
if ($Uninstall) {
foreach ($p in $platforms) { Uninstall-Platform $p }
exit 0
}
$script:CanSymlink = Test-SymlinkSupport
if (-not $script:CanSymlink) {
Write-Host @"
NOTE: Symlinks are not available. Skills will be copied instead.
To enable symlinks, turn on Developer Mode:
Settings > System > For developers > Developer Mode
Then re-run this script.
With symlinks, git pull automatically updates your skills.
With copies, re-run this script after pulling updates.
"@
}
if ($scope -eq "global") {
try {
$originUrl = & git -C $RepoDir remote get-url origin 2>$null
if ($originUrl -and $originUrl -match "PersonalKnowledgeBaseCreator") {
Write-Host "Disconnecting from template repository to prevent accidental pushes..."
& git -C $RepoDir remote rename origin template-origin
Write-Host " origin -> renamed to 'template-origin'"
Write-Host " To push your wiki to your own repo, run:"
Write-Host " git remote add origin <your-repo-url>"
Write-Host ""
}
} catch {}
foreach ($dir in @("raw", "output")) {
$path = Join-Path $RepoDir $dir
if (-not (Test-Path $path)) {
New-Item -ItemType Directory -Path $path -Force | Out-Null
}
}
}
foreach ($p in $platforms) {
Install-PlatformSkills $p
if ($scope -eq "global") {
Write-GlobalWikiConfig $p
}
}
if ($scope -eq "local") {
Init-LocalWiki
}
Write-Host "Setup complete."
Write-Host ""
Write-Host "Quick start:"
if ($scope -eq "global") {
Write-Host " 1. Edit AGENTS.md and fill in your focus areas"
Write-Host " 2. Drop files into raw/"
Write-Host ' 3. Open in your AI assistant and say: "Compile the wiki"'
Write-Host " 4. Browse wiki/ in any editor (Obsidian optional -- open wiki/ as a vault for graph view)"
}
else {
Write-Host " 1. Edit AGENTS.md in this directory and fill in your focus areas"
Write-Host " 2. Drop files into raw/"
Write-Host ' 3. Open in your AI assistant and say: "Compile the wiki"'
Write-Host " 4. Browse wiki/ in any editor (Obsidian optional -- open wiki/ as a vault for graph view)"
}