clew-code 0.2.28 → 0.2.30
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/README.md +38 -28
- package/bin/clew.cjs +2 -2
- package/dist/main.js +2318 -2331
- package/docs/architecture.html +90 -91
- package/docs/changelog.html +141 -150
- package/docs/cli-reference.html +89 -90
- package/docs/commands.html +10 -9
- package/docs/daemon.html +62 -62
- package/docs/generated/providers.html +625 -0
- package/docs/generated/tools.html +559 -0
- package/docs/index.html +10 -13
- package/docs/personal-profile.html +3 -3
- package/docs/providers.html +625 -87
- package/docs/quick-start.html +81 -81
- package/docs/tools.html +551 -175
- package/docs/troubleshooting.html +86 -86
- package/package.json +165 -165
- package/scripts/auto-close-duplicates.ts +277 -0
- package/scripts/backfill-duplicate-comments.ts +213 -0
- package/scripts/codegraph.ts +221 -0
- package/scripts/comment-on-duplicates.sh +95 -0
- package/scripts/edit-issue-labels.sh +84 -0
- package/scripts/final-peer-rename.mjs +46 -0
- package/scripts/fix-encoding.mjs +83 -0
- package/scripts/fix-inconsistencies.mjs +67 -0
- package/scripts/generate-docs.ts +307 -0
- package/scripts/gh.sh +96 -0
- package/scripts/install.ps1 +37 -0
- package/scripts/install.sh +49 -0
- package/scripts/issue-lifecycle.ts +38 -0
- package/scripts/lifecycle-comment.ts +53 -0
- package/scripts/normalize-html.mjs +37 -0
- package/scripts/preload.ts +159 -0
- package/scripts/rename-content-peer-to-swarm.mjs +67 -0
- package/scripts/rename-hooks-mesh.mjs +6 -0
- package/scripts/rename-peer-to-swarm.mjs +62 -0
- package/scripts/run_devcontainer_claude_code.ps1 +152 -0
- package/scripts/scrape.py +82 -0
- package/scripts/session.ts +195 -0
- package/scripts/sweep.ts +168 -0
- package/scripts/write-discovery-test.cjs +93 -0
- package/scripts/write-discovery-test2.cjs +65 -0
- package/scripts/write-server-final.cjs +108 -0
- package/scripts/write-server-test.cjs +69 -0
- package/scripts/write-server-test2.cjs +99 -0
- package/scripts/write-server-test3.cjs +59 -0
- package/scripts/write-server-test4.cjs +108 -0
- package/scripts/write-server-v2.cjs +142 -0
- package/scripts/write-server-v2b.cjs +129 -0
- package/scripts/write-server-v2c.cjs +136 -0
- package/scripts/write-store-test.cjs +12 -0
- package/scripts/write-store-test2.cjs +163 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<#
|
|
2
|
+
.SYNOPSIS
|
|
3
|
+
Automates the setup and connection to a DevContainer environment using either Docker or Podman on Windows.
|
|
4
|
+
|
|
5
|
+
.DESCRIPTION
|
|
6
|
+
This script automates the process of initializing, starting, and connecting to a DevContainer
|
|
7
|
+
using either Docker or Podman as the container backend. It must be executed from the root
|
|
8
|
+
directory of your project and assumes the script is located in a 'Script' subdirectory.
|
|
9
|
+
|
|
10
|
+
.PARAMETER Backend
|
|
11
|
+
Specifies the container backend to use. Valid values are 'docker' or 'podman'.
|
|
12
|
+
|
|
13
|
+
.EXAMPLE
|
|
14
|
+
.\Script\run_devcontainer_claude_code.ps1 -Backend docker
|
|
15
|
+
Uses Docker as the container backend.
|
|
16
|
+
|
|
17
|
+
.EXAMPLE
|
|
18
|
+
.\Script\run_devcontainer_claude_code.ps1 -Backend podman
|
|
19
|
+
Uses Podman as the container backend.
|
|
20
|
+
|
|
21
|
+
.NOTES
|
|
22
|
+
Project Structure:
|
|
23
|
+
Project/
|
|
24
|
+
├── .devcontainer/
|
|
25
|
+
└── Script/
|
|
26
|
+
└── run_devcontainer_claude_code.ps1
|
|
27
|
+
#>
|
|
28
|
+
|
|
29
|
+
[CmdletBinding()]
|
|
30
|
+
param(
|
|
31
|
+
[Parameter(Mandatory=$true)]
|
|
32
|
+
[ValidateSet('docker','podman')]
|
|
33
|
+
[string]$Backend
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Notify script start
|
|
37
|
+
Write-Host "--- DevContainer Startup & Connection Script ---"
|
|
38
|
+
Write-Host "Using backend: $($Backend)"
|
|
39
|
+
|
|
40
|
+
# --- Prerequisite Check ---
|
|
41
|
+
Write-Host "Checking for required commands..."
|
|
42
|
+
try {
|
|
43
|
+
if (-not (Get-Command $Backend -ErrorAction SilentlyContinue)) {
|
|
44
|
+
throw "Required command '$($Backend)' not found."
|
|
45
|
+
}
|
|
46
|
+
Write-Host "- $($Backend) command found."
|
|
47
|
+
if (-not (Get-Command devcontainer -ErrorAction SilentlyContinue)) {
|
|
48
|
+
throw "Required command 'devcontainer' not found."
|
|
49
|
+
}
|
|
50
|
+
Write-Host "- devcontainer command found."
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
Write-Error "A required command is not installed or not in your PATH. $($_.Exception.Message)"
|
|
54
|
+
Write-Error "Please ensure both '$Backend' and 'devcontainer' are installed and accessible in your system's PATH."
|
|
55
|
+
exit 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# --- Backend-Specific Initialization ---
|
|
60
|
+
if ($Backend -eq 'podman') {
|
|
61
|
+
Write-Host "--- Podman Backend Initialization ---"
|
|
62
|
+
|
|
63
|
+
# --- Step 1a: Initialize Podman machine ---
|
|
64
|
+
Write-Host "Initializing Podman machine 'claudeVM'..."
|
|
65
|
+
try {
|
|
66
|
+
& podman machine init claudeVM
|
|
67
|
+
Write-Host "Podman machine 'claudeVM' initialized or already exists."
|
|
68
|
+
} catch {
|
|
69
|
+
Write-Error "Failed to initialize Podman machine: $($_.Exception.Message)"
|
|
70
|
+
exit 1 # Exit script on error
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# --- Step 1b: Start Podman machine ---
|
|
74
|
+
Write-Host "Starting Podman machine 'claudeVM'..."
|
|
75
|
+
try {
|
|
76
|
+
& podman machine start claudeVM -q
|
|
77
|
+
Write-Host "Podman machine started or already running."
|
|
78
|
+
} catch {
|
|
79
|
+
Write-Error "Failed to start Podman machine: $($_.Exception.Message)"
|
|
80
|
+
exit 1
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# --- Step 2: Set default connection ---
|
|
84
|
+
Write-Host "Setting default Podman connection to 'claudeVM'..."
|
|
85
|
+
try {
|
|
86
|
+
& podman system connection default claudeVM
|
|
87
|
+
Write-Host "Default connection set."
|
|
88
|
+
} catch {
|
|
89
|
+
Write-Warning "Failed to set default Podman connection (may be already set or machine issue): $($_.Exception.Message)"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
} elseif ($Backend -eq 'docker') {
|
|
93
|
+
Write-Host "--- Docker Backend Initialization ---"
|
|
94
|
+
|
|
95
|
+
# --- Step 1 & 2: Check Docker Desktop ---
|
|
96
|
+
Write-Host "Checking if Docker Desktop is running and docker command is available..."
|
|
97
|
+
try {
|
|
98
|
+
docker info | Out-Null
|
|
99
|
+
Write-Host "Docker Desktop (daemon) is running."
|
|
100
|
+
} catch {
|
|
101
|
+
Write-Error "Docker Desktop is not running or docker command not found."
|
|
102
|
+
Write-Error "Please ensure Docker Desktop is running."
|
|
103
|
+
exit 1
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# --- Step 3: Bring up DevContainer ---
|
|
108
|
+
Write-Host "Bringing up DevContainer in the current folder..."
|
|
109
|
+
try {
|
|
110
|
+
$arguments = @('up', '--workspace-folder', '.')
|
|
111
|
+
if ($Backend -eq 'podman') {
|
|
112
|
+
$arguments += '--docker-path', 'podman'
|
|
113
|
+
}
|
|
114
|
+
& devcontainer @arguments
|
|
115
|
+
Write-Host "DevContainer startup process completed."
|
|
116
|
+
} catch {
|
|
117
|
+
Write-Error "Failed to bring up DevContainer: $($_.Exception.Message)"
|
|
118
|
+
exit 1
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
# --- Step 4: Get DevContainer ID ---
|
|
122
|
+
Write-Host "Finding the DevContainer ID..."
|
|
123
|
+
$currentFolder = (Get-Location).Path
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
$containerId = (& $Backend ps --filter "label=devcontainer.local_folder=$currentFolder" --format '{{.ID}}').Trim()
|
|
127
|
+
} catch {
|
|
128
|
+
$displayCommand = "$Backend ps --filter `"label=devcontainer.local_folder=$currentFolder`" --format '{{.ID}}'"
|
|
129
|
+
Write-Error "Failed to get container ID (Command: $displayCommand): $($_.Exception.Message)"
|
|
130
|
+
exit 1
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (-not $containerId) {
|
|
134
|
+
Write-Error "Could not find DevContainer ID for the current folder ('$currentFolder')."
|
|
135
|
+
Write-Error "Please check if 'devcontainer up' was successful and the container is running."
|
|
136
|
+
exit 1
|
|
137
|
+
}
|
|
138
|
+
Write-Host "Found container ID: $containerId"
|
|
139
|
+
|
|
140
|
+
# --- Step 5 & 6: Execute command and enter interactive shell inside container ---
|
|
141
|
+
Write-Host "Executing 'claude' command and then starting zsh session inside container $($containerId)..."
|
|
142
|
+
try {
|
|
143
|
+
& $Backend exec -it $containerId zsh -c 'claude; exec zsh'
|
|
144
|
+
Write-Host "Interactive session ended."
|
|
145
|
+
} catch {
|
|
146
|
+
$displayCommand = "$Backend exec -it $containerId zsh -c 'claude; exec zsh'"
|
|
147
|
+
Write-Error "Failed to execute command inside container (Command: $displayCommand): $($_.Exception.Message)"
|
|
148
|
+
exit 1
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# Notify script completion
|
|
152
|
+
Write-Host "--- Script completed ---"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import json
|
|
3
|
+
import argparse
|
|
4
|
+
from duckduckgo_search import DDGS
|
|
5
|
+
from scrapling import Fetcher
|
|
6
|
+
import trafilatura
|
|
7
|
+
|
|
8
|
+
def run_search(query, max_results=5):
|
|
9
|
+
try:
|
|
10
|
+
with DDGS() as ddgs:
|
|
11
|
+
results = list(ddgs.text(query, max_results=max_results))
|
|
12
|
+
# Format to simple dict list
|
|
13
|
+
formatted = []
|
|
14
|
+
for r in results:
|
|
15
|
+
formatted.append({
|
|
16
|
+
"title": r.get("title", ""),
|
|
17
|
+
"url": r.get("href", ""),
|
|
18
|
+
"body": r.get("body", "")
|
|
19
|
+
})
|
|
20
|
+
return {"status": "ok", "results": formatted}
|
|
21
|
+
except Exception as e:
|
|
22
|
+
return {"status": "failed", "error": str(e)}
|
|
23
|
+
|
|
24
|
+
def run_scrape(url):
|
|
25
|
+
try:
|
|
26
|
+
# 1. Initialize Scrapling Fetcher
|
|
27
|
+
f = Fetcher()
|
|
28
|
+
|
|
29
|
+
# 2. Get the response object stealthily
|
|
30
|
+
res = f.get(url)
|
|
31
|
+
|
|
32
|
+
# 3. Retrieve HTML content and text
|
|
33
|
+
html = res.html_content
|
|
34
|
+
text = res.text
|
|
35
|
+
|
|
36
|
+
# 4. Extract title via XPath selector
|
|
37
|
+
title_node = res.xpath('//title/text()').get()
|
|
38
|
+
title = title_node.strip() if title_node else ""
|
|
39
|
+
|
|
40
|
+
# 5. Extract clean main text/Markdown and metadata using Trafilatura
|
|
41
|
+
clean_text = trafilatura.extract(
|
|
42
|
+
html,
|
|
43
|
+
output_format='markdown',
|
|
44
|
+
include_comments=False,
|
|
45
|
+
include_tables=True
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# 6. Extract page metadata
|
|
49
|
+
meta = trafilatura.extract_metadata(html)
|
|
50
|
+
|
|
51
|
+
result = {
|
|
52
|
+
"status": "ok",
|
|
53
|
+
"title": title or (meta.title if meta else ""),
|
|
54
|
+
"author": meta.author if meta else "",
|
|
55
|
+
"published_at": meta.date if meta else "",
|
|
56
|
+
"markdown": clean_text or text or "",
|
|
57
|
+
"url": url
|
|
58
|
+
}
|
|
59
|
+
return result
|
|
60
|
+
except Exception as e:
|
|
61
|
+
return {"status": "failed", "error": str(e)}
|
|
62
|
+
|
|
63
|
+
def main():
|
|
64
|
+
parser = argparse.ArgumentParser(description="Stealth Web Search and Scraper Helper")
|
|
65
|
+
parser.add_argument("--search", type=str, help="Search query to run on DuckDuckGo")
|
|
66
|
+
parser.add_argument("--url", type=str, help="Web page URL to scrape")
|
|
67
|
+
parser.add_argument("--max-results", type=int, default=5, help="Max search results to return")
|
|
68
|
+
|
|
69
|
+
args = parser.parse_args()
|
|
70
|
+
|
|
71
|
+
if args.search:
|
|
72
|
+
result = run_search(args.search, args.max_results)
|
|
73
|
+
print(json.dumps(result))
|
|
74
|
+
elif args.url:
|
|
75
|
+
result = run_scrape(args.url)
|
|
76
|
+
print(json.dumps(result))
|
|
77
|
+
else:
|
|
78
|
+
print(json.dumps({"status": "failed", "error": "Specify either --search or --url"}))
|
|
79
|
+
sys.exit(1)
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
main()
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Session Bridge
|
|
4
|
+
*
|
|
5
|
+
* Saves & restores session context so Claude Code can pick up
|
|
6
|
+
* where it left off across sessions.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* bun run session save "กำลัง refactor bridge reconnect logic"
|
|
10
|
+
* bun run session list # ดู sessions ล่าสุด
|
|
11
|
+
* bun run session restore # โหลด session ล่าสุดกลับมา
|
|
12
|
+
* bun run session drop # ลบ current session
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync } from 'fs'
|
|
16
|
+
import { join, dirname, basename } from 'path'
|
|
17
|
+
import { execSync } from 'child_process'
|
|
18
|
+
|
|
19
|
+
const ROOT = join(import.meta.dirname, '..')
|
|
20
|
+
const SESSIONS_DIR = join(ROOT, '.clew', 'sessions')
|
|
21
|
+
const CURRENT_LINK = join(SESSIONS_DIR, 'CURRENT.md')
|
|
22
|
+
const MAX_SESSIONS = 20
|
|
23
|
+
|
|
24
|
+
const cmd = process.argv[2]
|
|
25
|
+
const message = process.argv.slice(3).join(' ')
|
|
26
|
+
|
|
27
|
+
function run(cmd: string): string {
|
|
28
|
+
try {
|
|
29
|
+
return execSync(cmd, { cwd: ROOT, encoding: 'utf-8', timeout: 10000, stdio: ['pipe', 'pipe', 'ignore'] })
|
|
30
|
+
} catch (e: any) {
|
|
31
|
+
return e.stdout || ''
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ts(): string {
|
|
36
|
+
return new Date().toISOString().replace('T', ' ').slice(0, 19)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sessionId(): string {
|
|
40
|
+
return new Date().toISOString().slice(0, 10) + '-' + Date.now().toString(36)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getModifiedFiles(): string[] {
|
|
44
|
+
try {
|
|
45
|
+
const out = run('git diff --name-only --relative').trim()
|
|
46
|
+
const staged = run('git diff --cached --name-only --relative').trim()
|
|
47
|
+
const files = [...new Set([...out.split('\n'), ...staged.split('\n')])].filter(Boolean)
|
|
48
|
+
return files.filter(f => f.startsWith('src/'))
|
|
49
|
+
} catch {
|
|
50
|
+
return []
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getCurrentBranch(): string {
|
|
55
|
+
try {
|
|
56
|
+
return run('git branch --show-current').trim()
|
|
57
|
+
} catch {
|
|
58
|
+
return 'unknown'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getRecentCommits(count = 5): string[] {
|
|
63
|
+
try {
|
|
64
|
+
return run(`git log --oneline -${count} -- .`).trim().split('\n').filter(Boolean)
|
|
65
|
+
} catch {
|
|
66
|
+
return []
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── Commands ──
|
|
71
|
+
|
|
72
|
+
if (cmd === 'save') {
|
|
73
|
+
const id = sessionId()
|
|
74
|
+
const branch = getCurrentBranch()
|
|
75
|
+
const modified = getModifiedFiles()
|
|
76
|
+
const commits = getRecentCommits(3)
|
|
77
|
+
const content = message || '(no description)'
|
|
78
|
+
|
|
79
|
+
mkdirSync(SESSIONS_DIR, { recursive: true })
|
|
80
|
+
|
|
81
|
+
const md = [
|
|
82
|
+
`# Session: ${id}`,
|
|
83
|
+
``,
|
|
84
|
+
`- **Date**: ${ts()}`,
|
|
85
|
+
`- **Branch**: ${branch}`,
|
|
86
|
+
`- **Description**: ${content}`,
|
|
87
|
+
``,
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
if (modified.length) {
|
|
91
|
+
md.push(`## Modified Files`, ``)
|
|
92
|
+
for (const f of modified) md.push(`- \`${f}\``)
|
|
93
|
+
md.push(``)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (commits.length) {
|
|
97
|
+
md.push(`## Recent Commits`, ``)
|
|
98
|
+
md.push('```')
|
|
99
|
+
for (const c of commits) md.push(c)
|
|
100
|
+
md.push('```')
|
|
101
|
+
md.push(``)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
md.push(`## Notes`, ``)
|
|
105
|
+
md.push(`(add key decisions, pending items, or anything to remember)`)
|
|
106
|
+
md.push(``)
|
|
107
|
+
|
|
108
|
+
const filepath = join(SESSIONS_DIR, `${id}.md`)
|
|
109
|
+
writeFileSync(filepath, md.join('\n'), 'utf-8')
|
|
110
|
+
writeFileSync(CURRENT_LINK, `# Current Session\n\n${content}\n\nSee: ${id}.md`, 'utf-8')
|
|
111
|
+
|
|
112
|
+
console.log(`✅ Session saved: ${id}`)
|
|
113
|
+
console.log(` ${filepath}`)
|
|
114
|
+
if (modified.length) console.log(` ${modified.length} modified file(s)`)
|
|
115
|
+
|
|
116
|
+
} else if (cmd === 'list') {
|
|
117
|
+
mkdirSync(SESSIONS_DIR, { recursive: true })
|
|
118
|
+
const files = readdirSync(SESSIONS_DIR)
|
|
119
|
+
.filter(f => f.endsWith('.md') && f !== 'CURRENT.md')
|
|
120
|
+
.sort()
|
|
121
|
+
.reverse()
|
|
122
|
+
.slice(0, MAX_SESSIONS)
|
|
123
|
+
|
|
124
|
+
if (files.length === 0) {
|
|
125
|
+
console.log('📭 No saved sessions')
|
|
126
|
+
process.exit(0)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
console.log(`📋 Recent sessions (${files.length}):`)
|
|
130
|
+
console.log('')
|
|
131
|
+
for (const f of files) {
|
|
132
|
+
const content = readFileSync(join(SESSIONS_DIR, f), 'utf-8')
|
|
133
|
+
const firstLine = content.split('\n')[0] || f
|
|
134
|
+
const desc = content.match(/\*\*Description\*\*:\s*(.+)/)?.[1] || '(no description)'
|
|
135
|
+
const date = content.match(/\*\*Date\*\*:\s*(.+)/)?.[1] || '?'
|
|
136
|
+
console.log(` ${firstLine.replace('# ', '')}`)
|
|
137
|
+
console.log(` ${date} — ${desc}`)
|
|
138
|
+
console.log('')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
} else if (cmd === 'restore') {
|
|
142
|
+
if (!existsSync(CURRENT_LINK)) {
|
|
143
|
+
console.log('📭 No current session to restore')
|
|
144
|
+
process.exit(0)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const content = readFileSync(CURRENT_LINK, 'utf-8')
|
|
148
|
+
const refMatch = content.match(/See:\s+(.+\.md)/)
|
|
149
|
+
if (!refMatch) {
|
|
150
|
+
console.log('📭 No session file referenced')
|
|
151
|
+
process.exit(0)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const sessionFile = join(SESSIONS_DIR, refMatch[1])
|
|
155
|
+
if (!existsSync(sessionFile)) {
|
|
156
|
+
console.log(`📭 Session file not found: ${sessionFile}`)
|
|
157
|
+
process.exit(0)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const session = readFileSync(sessionFile, 'utf-8')
|
|
161
|
+
console.log('📋 Restoring session...')
|
|
162
|
+
console.log('')
|
|
163
|
+
console.log(session)
|
|
164
|
+
|
|
165
|
+
} else if (cmd === 'drop') {
|
|
166
|
+
if (existsSync(CURRENT_LINK)) {
|
|
167
|
+
const content = readFileSync(CURRENT_LINK, 'utf-8')
|
|
168
|
+
const refMatch = content.match(/See:\s+(.+\.md)/)
|
|
169
|
+
if (refMatch) {
|
|
170
|
+
const sessionFile = join(SESSIONS_DIR, refMatch[1])
|
|
171
|
+
if (existsSync(sessionFile)) {
|
|
172
|
+
try { execSync(`rm "${sessionFile}"`) } catch {}
|
|
173
|
+
console.log(`🗑️ Removed: ${refMatch[1]}`)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
try { execSync(`rm "${CURRENT_LINK}"`) } catch {}
|
|
177
|
+
console.log('✅ Session dropped')
|
|
178
|
+
} else {
|
|
179
|
+
console.log('📭 No current session')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
} else {
|
|
183
|
+
console.log(`
|
|
184
|
+
Usage:
|
|
185
|
+
bun run session save "<description>" — save current state
|
|
186
|
+
bun run session list — list recent sessions
|
|
187
|
+
bun run session restore — restore latest session
|
|
188
|
+
bun run session drop — drop current session
|
|
189
|
+
|
|
190
|
+
Examples:
|
|
191
|
+
bun run session save "adding auth middleware"
|
|
192
|
+
bun run session save "fixing bridge reconnect bug"
|
|
193
|
+
bun run session list
|
|
194
|
+
`)
|
|
195
|
+
}
|
package/scripts/sweep.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { lifecycle, STALE_UPVOTE_THRESHOLD } from "./issue-lifecycle.ts";
|
|
4
|
+
|
|
5
|
+
// --
|
|
6
|
+
|
|
7
|
+
const NEW_ISSUE = "https://github.com/JonusNattapong/ClaudeCode/issues/new/choose";
|
|
8
|
+
const DRY_RUN = process.argv.includes("--dry-run");
|
|
9
|
+
|
|
10
|
+
const CLOSE_MESSAGE = (reason: string) =>
|
|
11
|
+
`Closing for now — ${reason}. Please [open a new issue](${NEW_ISSUE}) if this is still relevant.`;
|
|
12
|
+
|
|
13
|
+
// --
|
|
14
|
+
|
|
15
|
+
async function githubRequest<T>(
|
|
16
|
+
endpoint: string,
|
|
17
|
+
method = "GET",
|
|
18
|
+
body?: unknown
|
|
19
|
+
): Promise<T> {
|
|
20
|
+
const token = process.env.GITHUB_TOKEN;
|
|
21
|
+
if (!token) throw new Error("GITHUB_TOKEN required");
|
|
22
|
+
|
|
23
|
+
const response = await fetch(`https://api.github.com${endpoint}`, {
|
|
24
|
+
method,
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${token}`,
|
|
27
|
+
Accept: "application/vnd.github.v3+json",
|
|
28
|
+
"User-Agent": "sweep",
|
|
29
|
+
...(body && { "Content-Type": "application/json" }),
|
|
30
|
+
},
|
|
31
|
+
...(body && { body: JSON.stringify(body) }),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
if (response.status === 404) return {} as T;
|
|
36
|
+
const text = await response.text();
|
|
37
|
+
throw new Error(`GitHub API ${response.status}: ${text}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return response.json();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// --
|
|
44
|
+
|
|
45
|
+
async function markStale(owner: string, repo: string) {
|
|
46
|
+
const staleDays = lifecycle.find((l) => l.label === "stale")!.days;
|
|
47
|
+
const cutoff = new Date();
|
|
48
|
+
cutoff.setDate(cutoff.getDate() - staleDays);
|
|
49
|
+
|
|
50
|
+
let labeled = 0;
|
|
51
|
+
|
|
52
|
+
console.log(`\n=== marking stale (${staleDays}d inactive) ===`);
|
|
53
|
+
|
|
54
|
+
for (let page = 1; page <= 10; page++) {
|
|
55
|
+
const issues = await githubRequest<any[]>(
|
|
56
|
+
`/repos/${owner}/${repo}/issues?state=open&sort=updated&direction=asc&per_page=100&page=${page}`
|
|
57
|
+
);
|
|
58
|
+
if (issues.length === 0) break;
|
|
59
|
+
|
|
60
|
+
for (const issue of issues) {
|
|
61
|
+
if (issue.pull_request) continue;
|
|
62
|
+
if (issue.locked) continue;
|
|
63
|
+
if (issue.assignees?.length > 0) continue;
|
|
64
|
+
|
|
65
|
+
const updatedAt = new Date(issue.updated_at);
|
|
66
|
+
if (updatedAt > cutoff) return labeled;
|
|
67
|
+
|
|
68
|
+
const alreadyStale = issue.labels?.some(
|
|
69
|
+
(l: any) => l.name === "stale" || l.name === "autoclose"
|
|
70
|
+
);
|
|
71
|
+
if (alreadyStale) continue;
|
|
72
|
+
|
|
73
|
+
const thumbsUp = issue.reactions?.["+1"] ?? 0;
|
|
74
|
+
if (thumbsUp >= STALE_UPVOTE_THRESHOLD) continue;
|
|
75
|
+
|
|
76
|
+
const base = `/repos/${owner}/${repo}/issues/${issue.number}`;
|
|
77
|
+
|
|
78
|
+
if (DRY_RUN) {
|
|
79
|
+
const age = Math.floor((Date.now() - updatedAt.getTime()) / 86400000);
|
|
80
|
+
console.log(`#${issue.number}: would label stale (${age}d inactive) — ${issue.title}`);
|
|
81
|
+
} else {
|
|
82
|
+
await githubRequest(`${base}/labels`, "POST", { labels: ["stale"] });
|
|
83
|
+
console.log(`#${issue.number}: labeled stale — ${issue.title}`);
|
|
84
|
+
}
|
|
85
|
+
labeled++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return labeled;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function closeExpired(owner: string, repo: string) {
|
|
93
|
+
let closed = 0;
|
|
94
|
+
|
|
95
|
+
for (const { label, days, reason } of lifecycle) {
|
|
96
|
+
const cutoff = new Date();
|
|
97
|
+
cutoff.setDate(cutoff.getDate() - days);
|
|
98
|
+
console.log(`\n=== ${label} (${days}d timeout) ===`);
|
|
99
|
+
|
|
100
|
+
for (let page = 1; page <= 10; page++) {
|
|
101
|
+
const issues = await githubRequest<any[]>(
|
|
102
|
+
`/repos/${owner}/${repo}/issues?state=open&labels=${label}&sort=updated&direction=asc&per_page=100&page=${page}`
|
|
103
|
+
);
|
|
104
|
+
if (issues.length === 0) break;
|
|
105
|
+
|
|
106
|
+
for (const issue of issues) {
|
|
107
|
+
if (issue.pull_request) continue;
|
|
108
|
+
if (issue.locked) continue;
|
|
109
|
+
|
|
110
|
+
const thumbsUp = issue.reactions?.["+1"] ?? 0;
|
|
111
|
+
if (thumbsUp >= STALE_UPVOTE_THRESHOLD) continue;
|
|
112
|
+
|
|
113
|
+
const base = `/repos/${owner}/${repo}/issues/${issue.number}`;
|
|
114
|
+
|
|
115
|
+
const events = await githubRequest<any[]>(`${base}/events?per_page=100`);
|
|
116
|
+
|
|
117
|
+
const labeledAt = events
|
|
118
|
+
.filter((e) => e.event === "labeled" && e.label?.name === label)
|
|
119
|
+
.map((e) => new Date(e.created_at))
|
|
120
|
+
.pop();
|
|
121
|
+
|
|
122
|
+
if (!labeledAt || labeledAt > cutoff) continue;
|
|
123
|
+
|
|
124
|
+
// Skip if a non-bot user commented after the label was applied.
|
|
125
|
+
// The triage workflow should remove lifecycle labels on human
|
|
126
|
+
// activity, but check here too as a safety net.
|
|
127
|
+
const comments = await githubRequest<any[]>(
|
|
128
|
+
`${base}/comments?since=${labeledAt.toISOString()}&per_page=100`
|
|
129
|
+
);
|
|
130
|
+
const hasHumanComment = comments.some(
|
|
131
|
+
(c) => c.user && c.user.type !== "Bot"
|
|
132
|
+
);
|
|
133
|
+
if (hasHumanComment) {
|
|
134
|
+
console.log(
|
|
135
|
+
`#${issue.number}: skipping (human activity after ${label} label)`
|
|
136
|
+
);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (DRY_RUN) {
|
|
141
|
+
const age = Math.floor((Date.now() - labeledAt.getTime()) / 86400000);
|
|
142
|
+
console.log(`#${issue.number}: would close (${label}, ${age}d old) — ${issue.title}`);
|
|
143
|
+
} else {
|
|
144
|
+
await githubRequest(`${base}/comments`, "POST", { body: CLOSE_MESSAGE(reason) });
|
|
145
|
+
await githubRequest(base, "PATCH", { state: "closed", state_reason: "not_planned" });
|
|
146
|
+
console.log(`#${issue.number}: closed (${label})`);
|
|
147
|
+
}
|
|
148
|
+
closed++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return closed;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// --
|
|
157
|
+
|
|
158
|
+
const owner = process.env.GITHUB_REPOSITORY_OWNER;
|
|
159
|
+
const repo = process.env.GITHUB_REPOSITORY_NAME;
|
|
160
|
+
if (!owner || !repo)
|
|
161
|
+
throw new Error("GITHUB_REPOSITORY_OWNER and GITHUB_REPOSITORY_NAME required");
|
|
162
|
+
|
|
163
|
+
if (DRY_RUN) console.log("DRY RUN — no changes will be made\n");
|
|
164
|
+
|
|
165
|
+
const labeled = await markStale(owner, repo);
|
|
166
|
+
const closed = await closeExpired(owner, repo);
|
|
167
|
+
|
|
168
|
+
console.log(`\nDone: ${labeled} ${DRY_RUN ? "would be labeled" : "labeled"} stale, ${closed} ${DRY_RUN ? "would be closed" : "closed"}`);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const p = 'D:/Projects/Github/clew-code/src/mesh/MeshDiscovery.test.ts';
|
|
3
|
+
const code = `import { describe, expect, test, beforeEach, afterEach } from 'bun:test';
|
|
4
|
+
import { MeshDiscovery, getGlobalDiscovery } from './MeshDiscovery.js';
|
|
5
|
+
|
|
6
|
+
describe('MeshDiscovery', () => {
|
|
7
|
+
let discovery;
|
|
8
|
+
beforeEach(() => { process.env.CLEW_MESH_LAN = undefined; });
|
|
9
|
+
afterEach(() => { if (discovery) discovery.close(); });
|
|
10
|
+
|
|
11
|
+
test('constructor generates localId', () => {
|
|
12
|
+
discovery = new MeshDiscovery();
|
|
13
|
+
expect(discovery.meshId).toBeTruthy();
|
|
14
|
+
expect(discovery.meshId.split('-').length).toBeGreaterThanOrEqual(3);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('constructor accepts callbacks', () => {
|
|
18
|
+
let c = false;
|
|
19
|
+
discovery = new MeshDiscovery({ onPeerDiscovered: () => { c = true; } });
|
|
20
|
+
expect(discovery).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('setLocalName updates hostname and ID', () => {
|
|
24
|
+
discovery = new MeshDiscovery();
|
|
25
|
+
const oid = discovery.meshId;
|
|
26
|
+
discovery.setLocalName('custom');
|
|
27
|
+
expect(discovery.hostname).toBe('custom');
|
|
28
|
+
expect(discovery.meshId).not.toBe(oid);
|
|
29
|
+
expect(discovery.meshId).toContain('custom');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('startAdvertising sets isSharing true', async () => {
|
|
33
|
+
discovery = new MeshDiscovery();
|
|
34
|
+
expect(discovery.isSharing).toBeFalse();
|
|
35
|
+
await discovery.startAdvertising(9999, '/cwd');
|
|
36
|
+
expect(discovery.isSharing).toBeTrue();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('stopAdvertising sets isSharing false', async () => {
|
|
40
|
+
discovery = new MeshDiscovery();
|
|
41
|
+
await discovery.startAdvertising(9999, '/cwd');
|
|
42
|
+
discovery.stopAdvertising();
|
|
43
|
+
expect(discovery.isSharing).toBeFalse();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('startAdvertising idempotent', async () => {
|
|
47
|
+
discovery = new MeshDiscovery();
|
|
48
|
+
await discovery.startAdvertising(9999, '/cwd');
|
|
49
|
+
await discovery.startAdvertising(8888, '/other');
|
|
50
|
+
expect(discovery.isSharing).toBeTrue();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('stopAdvertising idempotent when not advertising', () => {
|
|
54
|
+
discovery = new MeshDiscovery();
|
|
55
|
+
discovery.stopAdvertising();
|
|
56
|
+
expect(discovery.isSharing).toBeFalse();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('getPeers returns empty initially', () => {
|
|
60
|
+
discovery = new MeshDiscovery();
|
|
61
|
+
expect(discovery.getPeers()).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('getPeer returns undefined for unknown', () => {
|
|
65
|
+
discovery = new MeshDiscovery();
|
|
66
|
+
expect(discovery.getPeer('nobody')).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('discoverPeers returns array', async () => {
|
|
70
|
+
discovery = new MeshDiscovery();
|
|
71
|
+
const peers = await discovery.discoverPeers(100);
|
|
72
|
+
expect(Array.isArray(peers)).toBeTrue();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('discoverMeshs alias', async () => {
|
|
76
|
+
discovery = new MeshDiscovery();
|
|
77
|
+
const peers = await discovery.discoverMeshs(100);
|
|
78
|
+
expect(Array.isArray(peers)).toBeTrue();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('close stops advertising', () => {
|
|
82
|
+
discovery = new MeshDiscovery();
|
|
83
|
+
discovery.close();
|
|
84
|
+
expect(discovery.isSharing).toBeFalse();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('getGlobalDiscovery singleton', () => {
|
|
88
|
+
expect(getGlobalDiscovery()).toBe(getGlobalDiscovery());
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
`;
|
|
92
|
+
fs.writeFileSync(p, code, 'utf8');
|
|
93
|
+
console.log('MeshDiscovery.test.ts written');
|