@whenlabs/when 0.9.2 → 0.10.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.
- package/README.md +26 -3
- package/dist/chunk-JOMP6AU5.js +40 -0
- package/dist/index.js +392 -50
- package/dist/install-33GE3HKA.js +190 -0
- package/dist/mcp.js +757 -597
- package/package.json +3 -1
- package/templates/statusline.py +311 -0
- package/dist/install-F46OPKIA.js +0 -484
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ALL_EDITORS,
|
|
4
|
+
installForEditor,
|
|
5
|
+
registerMcpServer
|
|
6
|
+
} from "./chunk-3PDLNC63.js";
|
|
7
|
+
import {
|
|
8
|
+
injectBlock
|
|
9
|
+
} from "./chunk-NYUYV3UL.js";
|
|
10
|
+
|
|
11
|
+
// src/commands/install.ts
|
|
12
|
+
import { join, resolve, dirname } from "path";
|
|
13
|
+
import { homedir } from "os";
|
|
14
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync } from "fs";
|
|
15
|
+
import { execFileSync } from "child_process";
|
|
16
|
+
import { fileURLToPath } from "url";
|
|
17
|
+
|
|
18
|
+
// src/templates/claude-md-content.ts
|
|
19
|
+
var CLAUDE_MD_CONTENT = `# WhenLabs Toolkit
|
|
20
|
+
|
|
21
|
+
## Task Timing (velocity-mcp)
|
|
22
|
+
|
|
23
|
+
Velocity tools are part of the unified \`whenlabs\` MCP server. Follow these rules for EVERY session:
|
|
24
|
+
|
|
25
|
+
1. **Before starting any discrete coding task**, call \`velocity_start_task\` with:
|
|
26
|
+
- Appropriate \`category\` (scaffold, implement, refactor, debug, test, config, docs, deploy)
|
|
27
|
+
- Relevant \`tags\` (e.g. typescript, react, sqlite, api)
|
|
28
|
+
- Clear \`description\` of what you're about to do
|
|
29
|
+
- \`estimated_files\` if you know how many files you'll touch
|
|
30
|
+
- \`project\` set to the current project name (auto-detected from git remote or directory name)
|
|
31
|
+
|
|
32
|
+
2. **After completing each task**, call \`velocity_end_task\` with:
|
|
33
|
+
- The \`task_id\` from the start call
|
|
34
|
+
- \`status\`: completed, failed, or abandoned
|
|
35
|
+
- \`actual_files\`: how many files were actually modified
|
|
36
|
+
- \`notes\`: any useful context about what happened
|
|
37
|
+
|
|
38
|
+
3. **When creating a multi-step plan**, call \`velocity_estimate\` to provide the user with a time estimate before starting work.
|
|
39
|
+
|
|
40
|
+
4. **If the user asks about speed or performance**, call \`velocity_stats\` to show aggregate data.
|
|
41
|
+
|
|
42
|
+
### Guidelines
|
|
43
|
+
- Every discrete unit of work should be tracked \u2014 don't batch multiple unrelated changes into one task
|
|
44
|
+
- If a task is abandoned or fails, still call \`velocity_end_task\` with the appropriate status
|
|
45
|
+
- Use consistent tags across sessions so the similarity matching can find comparable historical tasks
|
|
46
|
+
- Keep descriptions concise but specific enough to be useful for future matching
|
|
47
|
+
|
|
48
|
+
## WhenLabs MCP Tools (ALWAYS prefer these over shell commands)
|
|
49
|
+
|
|
50
|
+
All six tools (including velocity) are available through the unified \`whenlabs\` MCP server. **ALWAYS use these MCP tools instead of running shell commands like lsof, grep, or manual checks.** These tools are purpose-built and give better results:
|
|
51
|
+
|
|
52
|
+
| When to use | Call this tool | NOT this |
|
|
53
|
+
|-------------|---------------|----------|
|
|
54
|
+
| Check ports or port conflicts | \`berth_status\` or \`berth_check\` | \`lsof\`, \`netstat\`, \`ss\` |
|
|
55
|
+
| Scan dependency licenses | \`vow_scan\` or \`vow_check\` | manual \`npm ls\`, \`license-checker\` |
|
|
56
|
+
| Check if docs are stale | \`stale_scan\` | manual file comparison |
|
|
57
|
+
| Validate .env files | \`envalid_validate\` or \`envalid_detect\` | manual .env inspection |
|
|
58
|
+
| Generate AI context files | \`aware_init\` or \`aware_doctor\` | manual CLAUDE.md creation |
|
|
59
|
+
|
|
60
|
+
### Tool Reference
|
|
61
|
+
- \`berth_status\` \u2014 Show all active ports, Docker ports, and configured ports
|
|
62
|
+
- \`berth_check\` \u2014 Scan a project directory for port conflicts
|
|
63
|
+
- \`berth_auto_resolve\` \u2014 Check for conflicts and auto-resolve them in one step
|
|
64
|
+
- \`stale_scan\` \u2014 Detect documentation drift in the codebase
|
|
65
|
+
- \`stale_auto_fix\` \u2014 Scan for drift and auto-fix high-confidence issues in one step
|
|
66
|
+
- \`envalid_validate\` \u2014 Validate .env files against their schema
|
|
67
|
+
- \`envalid_detect\` \u2014 Find undocumented env vars in codebase
|
|
68
|
+
- \`envalid_auto_fix\` \u2014 Detect undocumented env vars and auto-generate schema entries
|
|
69
|
+
- \`aware_init\` \u2014 Auto-detect stack and generate AI context files
|
|
70
|
+
- \`aware_doctor\` \u2014 Diagnose project health and config issues
|
|
71
|
+
- \`aware_auto_sync\` \u2014 Diagnose and auto-sync stale AI context files in one step
|
|
72
|
+
- \`vow_scan\` \u2014 Scan and summarize all dependency licenses
|
|
73
|
+
- \`vow_check\` \u2014 Validate licenses against a policy file
|
|
74
|
+
|
|
75
|
+
### Cross-tool Intelligence
|
|
76
|
+
Tools provide follow-up suggestions when they detect issues relevant to other tools. When you see a "Tip:" in tool output, act on the suggestion \u2014 it means another tool can help.
|
|
77
|
+
|
|
78
|
+
### Proactive Background Scans
|
|
79
|
+
WhenLabs tools run automatically in the background on a schedule. The status line shows findings:
|
|
80
|
+
- \`stale:N\` \u2014 N docs have drifted from code. Run \`stale_scan\` and fix the drift.
|
|
81
|
+
- \`env:N\` \u2014 N .env issues found. Run \`envalid_validate\` and help the user fix them.
|
|
82
|
+
- \`ports:N\` \u2014 N port conflicts. Run \`berth_status\` and suggest resolution.
|
|
83
|
+
- \`lic:N?\` \u2014 N packages with unknown licenses. Run \`vow_scan\` for details.
|
|
84
|
+
- \`aware:stale\` \u2014 AI context files are outdated. Run \`aware_init\` to regenerate.
|
|
85
|
+
|
|
86
|
+
**When you see any of these in the status line, proactively tell the user and offer to fix the issue.** Do not wait for the user to ask.`;
|
|
87
|
+
|
|
88
|
+
// src/commands/install.ts
|
|
89
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
90
|
+
var __dirname = dirname(__filename);
|
|
91
|
+
var CLAUDE_MD_PATH = join(homedir(), ".claude", "CLAUDE.md");
|
|
92
|
+
var SCRIPTS_DIR = join(homedir(), ".claude", "scripts");
|
|
93
|
+
var STATUSLINE_PATH = join(SCRIPTS_DIR, "statusline.py");
|
|
94
|
+
var SETTINGS_PATH = join(homedir(), ".claude", "settings.json");
|
|
95
|
+
var OLD_START_MARKER = "<!-- velocity-mcp:start -->";
|
|
96
|
+
var OLD_END_MARKER = "<!-- velocity-mcp:end -->";
|
|
97
|
+
var STATUSLINE_SCRIPT = readFileSync(
|
|
98
|
+
resolve(__dirname, "..", "templates", "statusline.py"),
|
|
99
|
+
"utf-8"
|
|
100
|
+
);
|
|
101
|
+
function installStatusLine() {
|
|
102
|
+
try {
|
|
103
|
+
mkdirSync(SCRIPTS_DIR, { recursive: true });
|
|
104
|
+
writeFileSync(STATUSLINE_PATH, STATUSLINE_SCRIPT, "utf-8");
|
|
105
|
+
chmodSync(STATUSLINE_PATH, 493);
|
|
106
|
+
let settings = {};
|
|
107
|
+
if (existsSync(SETTINGS_PATH)) {
|
|
108
|
+
try {
|
|
109
|
+
settings = JSON.parse(readFileSync(SETTINGS_PATH, "utf-8"));
|
|
110
|
+
} catch {
|
|
111
|
+
settings = {};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const statuslineCmd = `python3 ${STATUSLINE_PATH}`;
|
|
115
|
+
const currentCmd = settings.statusLine?.command;
|
|
116
|
+
if (currentCmd !== statuslineCmd) {
|
|
117
|
+
settings.statusLine = { type: "command", command: statuslineCmd };
|
|
118
|
+
writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
119
|
+
}
|
|
120
|
+
return { installed: true, message: "Status line installed (proactive background scans)" };
|
|
121
|
+
} catch (err) {
|
|
122
|
+
return { installed: false, message: `Status line install failed: ${err.message}` };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function escapeRegex(str) {
|
|
126
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
127
|
+
}
|
|
128
|
+
function hasOldBlock(filePath) {
|
|
129
|
+
if (!existsSync(filePath)) return false;
|
|
130
|
+
const content = readFileSync(filePath, "utf-8");
|
|
131
|
+
return content.includes(OLD_START_MARKER) && content.includes(OLD_END_MARKER);
|
|
132
|
+
}
|
|
133
|
+
function removeOldBlock(filePath) {
|
|
134
|
+
if (!existsSync(filePath)) return;
|
|
135
|
+
let content = readFileSync(filePath, "utf-8");
|
|
136
|
+
const pattern = new RegExp(
|
|
137
|
+
`\\n?${escapeRegex(OLD_START_MARKER)}[\\s\\S]*?${escapeRegex(OLD_END_MARKER)}\\n?`,
|
|
138
|
+
"g"
|
|
139
|
+
);
|
|
140
|
+
content = content.replace(pattern, "\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
141
|
+
writeFileSync(filePath, content, "utf-8");
|
|
142
|
+
}
|
|
143
|
+
async function install(options = {}) {
|
|
144
|
+
console.log("\n\u{1F527} WhenLabs toolkit installer\n");
|
|
145
|
+
const editorFlags = options.all ? ALL_EDITORS : [
|
|
146
|
+
options.cursor && "cursor",
|
|
147
|
+
options.vscode && "vscode",
|
|
148
|
+
options.windsurf && "windsurf"
|
|
149
|
+
].filter(Boolean);
|
|
150
|
+
const claudeOnly = editorFlags.length === 0;
|
|
151
|
+
if (claudeOnly) {
|
|
152
|
+
const mcpResult = registerMcpServer();
|
|
153
|
+
console.log(mcpResult.success ? ` \u2713 ${mcpResult.message}` : ` \u2717 ${mcpResult.message}`);
|
|
154
|
+
injectBlock(CLAUDE_MD_PATH, CLAUDE_MD_CONTENT);
|
|
155
|
+
console.log(` \u2713 CLAUDE.md instructions written to ${CLAUDE_MD_PATH}`);
|
|
156
|
+
const slResult = installStatusLine();
|
|
157
|
+
console.log(slResult.installed ? ` \u2713 ${slResult.message}` : ` \u2717 ${slResult.message}`);
|
|
158
|
+
try {
|
|
159
|
+
const cwd = process.cwd();
|
|
160
|
+
execFileSync("npx", ["--yes", "@whenlabs/aware", "init", "--force"], {
|
|
161
|
+
cwd,
|
|
162
|
+
stdio: "pipe",
|
|
163
|
+
env: { ...process.env, FORCE_COLOR: "0", NO_COLOR: "1" },
|
|
164
|
+
timeout: 3e4
|
|
165
|
+
});
|
|
166
|
+
execFileSync("npx", ["--yes", "@whenlabs/aware", "sync"], {
|
|
167
|
+
cwd,
|
|
168
|
+
stdio: "pipe",
|
|
169
|
+
env: { ...process.env, FORCE_COLOR: "0", NO_COLOR: "1" },
|
|
170
|
+
timeout: 3e4
|
|
171
|
+
});
|
|
172
|
+
console.log(" \u2713 AI context files generated and synced (aware init + sync)");
|
|
173
|
+
} catch {
|
|
174
|
+
console.log(" - Skipped aware init (run `when aware init` in a project directory)");
|
|
175
|
+
}
|
|
176
|
+
if (hasOldBlock(CLAUDE_MD_PATH)) {
|
|
177
|
+
removeOldBlock(CLAUDE_MD_PATH);
|
|
178
|
+
console.log(" \u2713 Removed legacy velocity-mcp markers (migrated to whenlabs block)");
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
for (const editor of editorFlags) {
|
|
182
|
+
const result = installForEditor(editor);
|
|
183
|
+
console.log(result.success ? ` \u2713 ${result.message}` : ` \u2717 ${result.message}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
console.log("\nInstallation complete. Run `when status` to verify.\n");
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
install
|
|
190
|
+
};
|