@cloudpftc/opencode-orchestrator 3.5.15 → 3.6.1
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/.opencode/helpers/auto-memory-hook.mjs +104 -0
- package/.opencode/helpers/hook-handler.cjs +223 -0
- package/.opencode/helpers/intelligence.cjs +197 -0
- package/.opencode/helpers/memory.js +83 -0
- package/.opencode/helpers/post-commit +16 -0
- package/.opencode/helpers/pre-commit +26 -0
- package/.opencode/helpers/router.js +66 -0
- package/.opencode/helpers/session.js +127 -0
- package/.opencode/helpers/statusline.cjs +774 -0
- package/.opencode/settings.json +319 -0
- package/opencode.json +35 -78
- package/package.json +2 -6
- package/v3/@claude-flow/cli/README.md +391 -534
- package/v3/@claude-flow/cli/dist/src/commands/benchmark.js +2 -2
- package/v3/@claude-flow/cli/dist/src/commands/claims.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/config.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/daemon.js +3 -3
- package/v3/@claude-flow/cli/dist/src/commands/deployment.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/doctor.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/embeddings.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/hooks.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/init.js +16 -16
- package/v3/@claude-flow/cli/dist/src/commands/neural.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/performance.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/plugins.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/providers.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/security.js +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/start.js +10 -10
- package/v3/@claude-flow/cli/dist/src/commands/status.js +2 -2
- package/v3/@claude-flow/cli/dist/src/commands/transfer-store.js +1 -1
- package/v3/@claude-flow/cli/dist/src/init/executor.js +181 -133
- package/v3/@claude-flow/cli/dist/src/init/helpers-generator.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +20 -20
- package/v3/@claude-flow/cli/dist/src/init/index.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/init/index.js +1 -1
- package/v3/@claude-flow/cli/dist/src/init/mcp-generator.d.ts +2 -2
- package/v3/@claude-flow/cli/dist/src/init/mcp-generator.js +15 -15
- package/v3/@claude-flow/cli/dist/src/init/opencode-generator.d.ts +42 -0
- package/v3/@claude-flow/cli/dist/src/init/opencode-generator.js +107 -0
- package/v3/@claude-flow/cli/dist/src/init/settings-generator.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/init/settings-generator.js +18 -18
- package/v3/@claude-flow/cli/dist/src/init/{claudemd-generator.d.ts → skillmd-generator.d.ts} +8 -8
- package/v3/@claude-flow/cli/dist/src/init/{claudemd-generator.js → skillmd-generator.js} +9 -9
- package/v3/@claude-flow/cli/dist/src/init/statusline-generator.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/init/statusline-generator.js +39 -23
- package/v3/@claude-flow/cli/dist/src/init/types.d.ts +14 -10
- package/v3/@claude-flow/cli/dist/src/init/types.js +3 -3
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +1 -1
- package/v3/@claude-flow/cli/dist/src/plugins/store/discovery.js +1 -1
- package/v3/@claude-flow/cli/dist/src/runtime/headless.js +3 -3
- package/v3/@claude-flow/cli/dist/src/services/claim-service.js +1 -1
- package/v3/@claude-flow/cli/dist/src/types.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/types.js +1 -1
- package/v3/@claude-flow/cli/package.json +1 -1
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OpenCode Orchestrator Statusline Generator (Optimized)
|
|
4
|
+
* Displays real-time V3 implementation progress and system status
|
|
5
|
+
*
|
|
6
|
+
* Usage: node statusline.cjs [--json] [--compact]
|
|
7
|
+
*
|
|
8
|
+
* Performance notes:
|
|
9
|
+
* - Single git execSync call (combines branch + status + upstream)
|
|
10
|
+
* - No recursive file reading (only stat/readdir, never read test contents)
|
|
11
|
+
* - No ps aux calls (uses process.memoryUsage() + file-based metrics)
|
|
12
|
+
* - Strict 2s timeout on all execSync calls
|
|
13
|
+
* - Shared settings cache across functions
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const { execSync } = require('child_process');
|
|
20
|
+
const os = require('os');
|
|
21
|
+
|
|
22
|
+
// Configuration
|
|
23
|
+
const CONFIG = {
|
|
24
|
+
maxAgents: 15,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const CWD = process.cwd();
|
|
28
|
+
|
|
29
|
+
// ANSI colors
|
|
30
|
+
const c = {
|
|
31
|
+
reset: '\x1b[0m',
|
|
32
|
+
bold: '\x1b[1m',
|
|
33
|
+
dim: '\x1b[2m',
|
|
34
|
+
red: '\x1b[0;31m',
|
|
35
|
+
green: '\x1b[0;32m',
|
|
36
|
+
yellow: '\x1b[0;33m',
|
|
37
|
+
blue: '\x1b[0;34m',
|
|
38
|
+
purple: '\x1b[0;35m',
|
|
39
|
+
cyan: '\x1b[0;36m',
|
|
40
|
+
brightRed: '\x1b[1;31m',
|
|
41
|
+
brightGreen: '\x1b[1;32m',
|
|
42
|
+
brightYellow: '\x1b[1;33m',
|
|
43
|
+
brightBlue: '\x1b[1;34m',
|
|
44
|
+
brightPurple: '\x1b[1;35m',
|
|
45
|
+
brightCyan: '\x1b[1;36m',
|
|
46
|
+
brightWhite: '\x1b[1;37m',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Safe execSync with strict timeout (returns empty string on failure)
|
|
50
|
+
function safeExec(cmd, timeoutMs = 2000) {
|
|
51
|
+
try {
|
|
52
|
+
return execSync(cmd, {
|
|
53
|
+
encoding: 'utf-8',
|
|
54
|
+
timeout: timeoutMs,
|
|
55
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
56
|
+
}).trim();
|
|
57
|
+
} catch {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Safe JSON file reader (returns null on failure)
|
|
63
|
+
function readJSON(filePath) {
|
|
64
|
+
try {
|
|
65
|
+
if (fs.existsSync(filePath)) {
|
|
66
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
67
|
+
}
|
|
68
|
+
} catch { /* ignore */ }
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Safe file stat (returns null on failure)
|
|
73
|
+
function safeStat(filePath) {
|
|
74
|
+
try {
|
|
75
|
+
return fs.statSync(filePath);
|
|
76
|
+
} catch { /* ignore */ }
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Shared settings cache — read once, used by multiple functions
|
|
81
|
+
let _settingsCache = undefined;
|
|
82
|
+
function getSettings() {
|
|
83
|
+
if (_settingsCache !== undefined) return _settingsCache;
|
|
84
|
+
_settingsCache = readJSON(path.join(CWD, 'opencode.json'))
|
|
85
|
+
|| readJSON(path.join(CWD, '.opencode', 'settings.json'))
|
|
86
|
+
|| readJSON(path.join(CWD, '.claude', 'settings.json'))
|
|
87
|
+
|| readJSON(path.join(CWD, '.claude', 'settings.local.json'))
|
|
88
|
+
|| null;
|
|
89
|
+
return _settingsCache;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ─── Data Collection (all pure-Node.js or single-exec) ──────────
|
|
93
|
+
|
|
94
|
+
// Get all git info in ONE shell call
|
|
95
|
+
function getGitInfo() {
|
|
96
|
+
const result = {
|
|
97
|
+
name: 'user', gitBranch: '', modified: 0, untracked: 0,
|
|
98
|
+
staged: 0, ahead: 0, behind: 0,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Single shell: get user.name, branch, porcelain status, and upstream diff
|
|
102
|
+
const script = [
|
|
103
|
+
'git config user.name 2>/dev/null || echo user',
|
|
104
|
+
'echo "---SEP---"',
|
|
105
|
+
'git branch --show-current 2>/dev/null',
|
|
106
|
+
'echo "---SEP---"',
|
|
107
|
+
'git status --porcelain 2>/dev/null',
|
|
108
|
+
'echo "---SEP---"',
|
|
109
|
+
'git rev-list --left-right --count HEAD...@{upstream} 2>/dev/null || echo "0 0"',
|
|
110
|
+
].join('; ');
|
|
111
|
+
|
|
112
|
+
const raw = safeExec("sh -c '" + script + "'", 3000);
|
|
113
|
+
if (!raw) return result;
|
|
114
|
+
|
|
115
|
+
const parts = raw.split('---SEP---').map(s => s.trim());
|
|
116
|
+
if (parts.length >= 4) {
|
|
117
|
+
result.name = parts[0] || 'user';
|
|
118
|
+
result.gitBranch = parts[1] || '';
|
|
119
|
+
|
|
120
|
+
// Parse porcelain status
|
|
121
|
+
if (parts[2]) {
|
|
122
|
+
for (const line of parts[2].split('\n')) {
|
|
123
|
+
if (!line || line.length < 2) continue;
|
|
124
|
+
const x = line[0], y = line[1];
|
|
125
|
+
if (x === '?' && y === '?') { result.untracked++; continue; }
|
|
126
|
+
if (x !== ' ' && x !== '?') result.staged++;
|
|
127
|
+
if (y !== ' ' && y !== '?') result.modified++;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Parse ahead/behind
|
|
132
|
+
const ab = (parts[3] || '0 0').split(/\s+/);
|
|
133
|
+
result.ahead = parseInt(ab[0]) || 0;
|
|
134
|
+
result.behind = parseInt(ab[1]) || 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Detect model name from Claude config (pure file reads, no exec)
|
|
141
|
+
function getModelName() {
|
|
142
|
+
try {
|
|
143
|
+
const claudeConfig = readJSON(path.join(os.homedir(), '.claude.json'));
|
|
144
|
+
if (claudeConfig && claudeConfig.projects) {
|
|
145
|
+
for (const [projectPath, projectConfig] of Object.entries(claudeConfig.projects)) {
|
|
146
|
+
if (CWD === projectPath || CWD.startsWith(projectPath + '/')) {
|
|
147
|
+
const usage = projectConfig.lastModelUsage;
|
|
148
|
+
if (usage) {
|
|
149
|
+
const ids = Object.keys(usage);
|
|
150
|
+
if (ids.length > 0) {
|
|
151
|
+
let modelId = ids[ids.length - 1];
|
|
152
|
+
let latest = 0;
|
|
153
|
+
for (const id of ids) {
|
|
154
|
+
const ts = usage[id] && usage[id].lastUsedAt ? new Date(usage[id].lastUsedAt).getTime() : 0;
|
|
155
|
+
if (ts > latest) { latest = ts; modelId = id; }
|
|
156
|
+
}
|
|
157
|
+
if (modelId.includes('opus')) return 'Opus 4.6';
|
|
158
|
+
if (modelId.includes('sonnet')) return 'Sonnet 4.6';
|
|
159
|
+
if (modelId.includes('haiku')) return 'Haiku 4.5';
|
|
160
|
+
return modelId.split('-').slice(1, 3).join(' ');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} catch { /* ignore */ }
|
|
168
|
+
|
|
169
|
+
// Fallback: settings.json model field
|
|
170
|
+
const settings = getSettings();
|
|
171
|
+
if (settings && settings.model) {
|
|
172
|
+
const m = settings.model;
|
|
173
|
+
if (m.includes('opus')) return 'Opus 4.6';
|
|
174
|
+
if (m.includes('sonnet')) return 'Sonnet 4.6';
|
|
175
|
+
if (m.includes('haiku')) return 'Haiku 4.5';
|
|
176
|
+
}
|
|
177
|
+
return 'Claude Code';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Get learning stats from memory database (pure stat calls)
|
|
181
|
+
function getLearningStats() {
|
|
182
|
+
const memoryPaths = [
|
|
183
|
+
path.join(CWD, '.swarm', 'memory.db'),
|
|
184
|
+
path.join(CWD, '.opencode', 'memory.db'),
|
|
185
|
+
path.join(CWD, '.claude-flow', 'memory.db'),
|
|
186
|
+
path.join(CWD, '.claude', 'memory.db'),
|
|
187
|
+
path.join(CWD, 'data', 'memory.db'),
|
|
188
|
+
path.join(CWD, '.agentdb', 'memory.db'),
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
for (const dbPath of memoryPaths) {
|
|
192
|
+
const stat = safeStat(dbPath);
|
|
193
|
+
if (stat) {
|
|
194
|
+
const sizeKB = stat.size / 1024;
|
|
195
|
+
const patterns = Math.floor(sizeKB / 2);
|
|
196
|
+
return {
|
|
197
|
+
patterns,
|
|
198
|
+
sessions: Math.max(1, Math.floor(patterns / 10)),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Check session files count
|
|
204
|
+
let sessions = 0;
|
|
205
|
+
try {
|
|
206
|
+
const sessDir = path.join(CWD, '.claude', 'sessions');
|
|
207
|
+
if (fs.existsSync(sessDir)) {
|
|
208
|
+
sessions = fs.readdirSync(sessDir).filter(f => f.endsWith('.json')).length;
|
|
209
|
+
}
|
|
210
|
+
} catch { /* ignore */ }
|
|
211
|
+
|
|
212
|
+
return { patterns: 0, sessions };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// V3 progress from metrics files (pure file reads)
|
|
216
|
+
function getV3Progress() {
|
|
217
|
+
const learning = getLearningStats();
|
|
218
|
+
const totalDomains = 5;
|
|
219
|
+
|
|
220
|
+
const dddData = readJSON(path.join(CWD, '.opencode', 'metrics', 'ddd-progress.json'))
|
|
221
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'metrics', 'ddd-progress.json'));
|
|
222
|
+
let dddProgress = dddData ? (dddData.progress || 0) : 0;
|
|
223
|
+
let domainsCompleted = Math.min(5, Math.floor(dddProgress / 20));
|
|
224
|
+
|
|
225
|
+
if (dddProgress === 0 && learning.patterns > 0) {
|
|
226
|
+
if (learning.patterns >= 500) domainsCompleted = 5;
|
|
227
|
+
else if (learning.patterns >= 200) domainsCompleted = 4;
|
|
228
|
+
else if (learning.patterns >= 100) domainsCompleted = 3;
|
|
229
|
+
else if (learning.patterns >= 50) domainsCompleted = 2;
|
|
230
|
+
else if (learning.patterns >= 10) domainsCompleted = 1;
|
|
231
|
+
dddProgress = Math.floor((domainsCompleted / totalDomains) * 100);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
domainsCompleted, totalDomains, dddProgress,
|
|
236
|
+
patternsLearned: learning.patterns,
|
|
237
|
+
sessionsCompleted: learning.sessions,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Security status (pure file reads)
|
|
242
|
+
function getSecurityStatus() {
|
|
243
|
+
const totalCves = 3;
|
|
244
|
+
const auditData = readJSON(path.join(CWD, '.opencode', 'security', 'audit-status.json'))
|
|
245
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'security', 'audit-status.json'));
|
|
246
|
+
if (auditData) {
|
|
247
|
+
return {
|
|
248
|
+
status: auditData.status || 'PENDING',
|
|
249
|
+
cvesFixed: auditData.cvesFixed || 0,
|
|
250
|
+
totalCves: auditData.totalCves || 3,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let cvesFixed = 0;
|
|
255
|
+
try {
|
|
256
|
+
const scanDir = path.join(CWD, '.claude', 'security-scans');
|
|
257
|
+
if (fs.existsSync(scanDir)) {
|
|
258
|
+
cvesFixed = Math.min(totalCves, fs.readdirSync(scanDir).filter(f => f.endsWith('.json')).length);
|
|
259
|
+
}
|
|
260
|
+
} catch { /* ignore */ }
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
status: cvesFixed >= totalCves ? 'CLEAN' : cvesFixed > 0 ? 'IN_PROGRESS' : 'PENDING',
|
|
264
|
+
cvesFixed,
|
|
265
|
+
totalCves,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Swarm status (pure file reads, NO ps aux)
|
|
270
|
+
function getSwarmStatus() {
|
|
271
|
+
const activityData = readJSON(path.join(CWD, '.opencode', 'metrics', 'swarm-activity.json'))
|
|
272
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'metrics', 'swarm-activity.json'));
|
|
273
|
+
if (activityData && activityData.swarm) {
|
|
274
|
+
return {
|
|
275
|
+
activeAgents: activityData.swarm.agent_count || 0,
|
|
276
|
+
maxAgents: CONFIG.maxAgents,
|
|
277
|
+
coordinationActive: activityData.swarm.coordination_active || activityData.swarm.active || false,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const progressData = readJSON(path.join(CWD, '.opencode', 'metrics', 'v3-progress.json'))
|
|
282
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'metrics', 'v3-progress.json'));
|
|
283
|
+
if (progressData && progressData.swarm) {
|
|
284
|
+
return {
|
|
285
|
+
activeAgents: progressData.swarm.activeAgents || progressData.swarm.agent_count || 0,
|
|
286
|
+
maxAgents: progressData.swarm.totalAgents || CONFIG.maxAgents,
|
|
287
|
+
coordinationActive: progressData.swarm.active || (progressData.swarm.activeAgents > 0),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return { activeAgents: 0, maxAgents: CONFIG.maxAgents, coordinationActive: false };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// System metrics (uses process.memoryUsage() — no shell spawn)
|
|
295
|
+
function getSystemMetrics() {
|
|
296
|
+
const memoryMB = Math.floor(process.memoryUsage().heapUsed / 1024 / 1024);
|
|
297
|
+
const learning = getLearningStats();
|
|
298
|
+
const agentdb = getAgentDBStats();
|
|
299
|
+
|
|
300
|
+
// Intelligence from learning.json
|
|
301
|
+
const learningData = readJSON(path.join(CWD, '.opencode', 'metrics', 'learning.json'))
|
|
302
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'metrics', 'learning.json'));
|
|
303
|
+
let intelligencePct = 0;
|
|
304
|
+
let contextPct = 0;
|
|
305
|
+
|
|
306
|
+
if (learningData && learningData.intelligence && learningData.intelligence.score !== undefined) {
|
|
307
|
+
intelligencePct = Math.min(100, Math.floor(learningData.intelligence.score));
|
|
308
|
+
} else {
|
|
309
|
+
const fromPatterns = learning.patterns > 0 ? Math.min(100, Math.floor(learning.patterns / 10)) : 0;
|
|
310
|
+
const fromVectors = agentdb.vectorCount > 0 ? Math.min(100, Math.floor(agentdb.vectorCount / 100)) : 0;
|
|
311
|
+
intelligencePct = Math.max(fromPatterns, fromVectors);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Maturity fallback (pure fs checks, no git exec)
|
|
315
|
+
if (intelligencePct === 0) {
|
|
316
|
+
let score = 0;
|
|
317
|
+
if (fs.existsSync(path.join(CWD, '.claude'))) score += 15;
|
|
318
|
+
const srcDirs = ['src', 'lib', 'app', 'packages', 'v3'];
|
|
319
|
+
for (const d of srcDirs) { if (fs.existsSync(path.join(CWD, d))) { score += 15; break; } }
|
|
320
|
+
const testDirs = ['tests', 'test', '__tests__', 'spec'];
|
|
321
|
+
for (const d of testDirs) { if (fs.existsSync(path.join(CWD, d))) { score += 10; break; } }
|
|
322
|
+
const cfgFiles = ['package.json', 'tsconfig.json', 'pyproject.toml', 'Cargo.toml', 'go.mod'];
|
|
323
|
+
for (const f of cfgFiles) { if (fs.existsSync(path.join(CWD, f))) { score += 5; break; } }
|
|
324
|
+
intelligencePct = Math.min(100, score);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (learningData && learningData.sessions && learningData.sessions.total !== undefined) {
|
|
328
|
+
contextPct = Math.min(100, learningData.sessions.total * 5);
|
|
329
|
+
} else {
|
|
330
|
+
contextPct = Math.min(100, Math.floor(learning.sessions * 5));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Sub-agents from file metrics (no ps aux)
|
|
334
|
+
let subAgents = 0;
|
|
335
|
+
const activityData = readJSON(path.join(CWD, '.opencode', 'metrics', 'swarm-activity.json'))
|
|
336
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'metrics', 'swarm-activity.json'));
|
|
337
|
+
if (activityData && activityData.processes && activityData.processes.estimated_agents) {
|
|
338
|
+
subAgents = activityData.processes.estimated_agents;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return { memoryMB, contextPct, intelligencePct, subAgents };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ADR status (count files only — don't read contents)
|
|
345
|
+
function getADRStatus() {
|
|
346
|
+
const complianceData = readJSON(path.join(CWD, '.opencode', 'metrics', 'adr-compliance.json'))
|
|
347
|
+
|| readJSON(path.join(CWD, '.claude-flow', 'metrics', 'adr-compliance.json'));
|
|
348
|
+
if (complianceData) {
|
|
349
|
+
const checks = complianceData.checks || {};
|
|
350
|
+
const total = Object.keys(checks).length;
|
|
351
|
+
const impl = Object.values(checks).filter(c => c.compliant).length;
|
|
352
|
+
return { count: total, implemented: impl, compliance: complianceData.compliance || 0 };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Fallback: just count ADR files (don't read them)
|
|
356
|
+
const adrPaths = [
|
|
357
|
+
path.join(CWD, 'v3', 'implementation', 'adrs'),
|
|
358
|
+
path.join(CWD, 'docs', 'adrs'),
|
|
359
|
+
path.join(CWD, '.opencode', 'adrs'),
|
|
360
|
+
path.join(CWD, '.claude-flow', 'adrs'),
|
|
361
|
+
];
|
|
362
|
+
|
|
363
|
+
for (const adrPath of adrPaths) {
|
|
364
|
+
try {
|
|
365
|
+
if (fs.existsSync(adrPath)) {
|
|
366
|
+
const files = fs.readdirSync(adrPath).filter(f =>
|
|
367
|
+
f.endsWith('.md') && (f.startsWith('ADR-') || f.startsWith('adr-') || /^\d{4}-/.test(f))
|
|
368
|
+
);
|
|
369
|
+
const implemented = Math.floor(files.length * 0.7);
|
|
370
|
+
const compliance = files.length > 0 ? Math.floor((implemented / files.length) * 100) : 0;
|
|
371
|
+
return { count: files.length, implemented, compliance };
|
|
372
|
+
}
|
|
373
|
+
} catch { /* ignore */ }
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return { count: 0, implemented: 0, compliance: 0 };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Hooks status (shared settings cache)
|
|
380
|
+
function getHooksStatus() {
|
|
381
|
+
let enabled = 0;
|
|
382
|
+
const total = 17;
|
|
383
|
+
const settings = getSettings();
|
|
384
|
+
|
|
385
|
+
if (settings && settings.hooks) {
|
|
386
|
+
for (const category of Object.keys(settings.hooks)) {
|
|
387
|
+
const h = settings.hooks[category];
|
|
388
|
+
if (Array.isArray(h) && h.length > 0) enabled++;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
const hooksDir = path.join(CWD, '.opencode', 'hooks');
|
|
394
|
+
if (fs.existsSync(hooksDir)) {
|
|
395
|
+
const hookFiles = fs.readdirSync(hooksDir).filter(f => f.endsWith('.js') || f.endsWith('.sh')).length;
|
|
396
|
+
enabled = Math.max(enabled, hookFiles);
|
|
397
|
+
}
|
|
398
|
+
} catch { /* ignore */ }
|
|
399
|
+
|
|
400
|
+
return { enabled, total };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// AgentDB stats (pure stat calls)
|
|
404
|
+
function getAgentDBStats() {
|
|
405
|
+
let vectorCount = 0;
|
|
406
|
+
let dbSizeKB = 0;
|
|
407
|
+
let namespaces = 0;
|
|
408
|
+
let hasHnsw = false;
|
|
409
|
+
|
|
410
|
+
const dbFiles = [
|
|
411
|
+
path.join(CWD, '.swarm', 'memory.db'),
|
|
412
|
+
path.join(CWD, '.opencode', 'memory.db'),
|
|
413
|
+
path.join(CWD, '.claude-flow', 'memory.db'),
|
|
414
|
+
path.join(CWD, '.claude', 'memory.db'),
|
|
415
|
+
path.join(CWD, 'data', 'memory.db'),
|
|
416
|
+
];
|
|
417
|
+
|
|
418
|
+
for (const f of dbFiles) {
|
|
419
|
+
const stat = safeStat(f);
|
|
420
|
+
if (stat) {
|
|
421
|
+
dbSizeKB = stat.size / 1024;
|
|
422
|
+
vectorCount = Math.floor(dbSizeKB / 2);
|
|
423
|
+
namespaces = 1;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (vectorCount === 0) {
|
|
429
|
+
const dbDirs = [
|
|
430
|
+
path.join(CWD, '.opencode', 'agentdb'),
|
|
431
|
+
path.join(CWD, '.claude-flow', 'agentdb'),
|
|
432
|
+
path.join(CWD, '.swarm', 'agentdb'),
|
|
433
|
+
path.join(CWD, '.agentdb'),
|
|
434
|
+
];
|
|
435
|
+
for (const dir of dbDirs) {
|
|
436
|
+
try {
|
|
437
|
+
if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
|
|
438
|
+
const files = fs.readdirSync(dir);
|
|
439
|
+
namespaces = files.filter(f => f.endsWith('.db') || f.endsWith('.sqlite')).length;
|
|
440
|
+
for (const file of files) {
|
|
441
|
+
const stat = safeStat(path.join(dir, file));
|
|
442
|
+
if (stat && stat.isFile()) dbSizeKB += stat.size / 1024;
|
|
443
|
+
}
|
|
444
|
+
vectorCount = Math.floor(dbSizeKB / 2);
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
} catch { /* ignore */ }
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const hnswPaths = [
|
|
452
|
+
path.join(CWD, '.opencode', 'hnsw.index'),
|
|
453
|
+
path.join(CWD, '.swarm', 'hnsw.index'),
|
|
454
|
+
path.join(CWD, '.claude-flow', 'hnsw.index'),
|
|
455
|
+
];
|
|
456
|
+
for (const p of hnswPaths) {
|
|
457
|
+
const stat = safeStat(p);
|
|
458
|
+
if (stat) {
|
|
459
|
+
hasHnsw = true;
|
|
460
|
+
vectorCount = Math.max(vectorCount, Math.floor(stat.size / 512));
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return { vectorCount, dbSizeKB: Math.floor(dbSizeKB), namespaces, hasHnsw };
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Test stats (count files only — NO reading file contents)
|
|
469
|
+
function getTestStats() {
|
|
470
|
+
let testFiles = 0;
|
|
471
|
+
|
|
472
|
+
function countTestFiles(dir, depth) {
|
|
473
|
+
if (depth === undefined) depth = 0;
|
|
474
|
+
if (depth > 2) return;
|
|
475
|
+
try {
|
|
476
|
+
if (!fs.existsSync(dir)) return;
|
|
477
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
478
|
+
for (const entry of entries) {
|
|
479
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
|
|
480
|
+
countTestFiles(path.join(dir, entry.name), depth + 1);
|
|
481
|
+
} else if (entry.isFile()) {
|
|
482
|
+
const n = entry.name;
|
|
483
|
+
if (n.includes('.test.') || n.includes('.spec.') || n.includes('_test.') || n.includes('_spec.')) {
|
|
484
|
+
testFiles++;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
} catch { /* ignore */ }
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
var testDirNames = ['tests', 'test', '__tests__', 'v3/__tests__'];
|
|
492
|
+
for (var i = 0; i < testDirNames.length; i++) {
|
|
493
|
+
countTestFiles(path.join(CWD, testDirNames[i]));
|
|
494
|
+
}
|
|
495
|
+
countTestFiles(path.join(CWD, 'src'));
|
|
496
|
+
|
|
497
|
+
return { testFiles, testCases: testFiles * 4 };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Integration status (shared settings + file checks)
|
|
501
|
+
function getIntegrationStatus() {
|
|
502
|
+
const mcpServers = { total: 0, enabled: 0 };
|
|
503
|
+
const settings = getSettings();
|
|
504
|
+
|
|
505
|
+
if (settings && settings.mcpServers && typeof settings.mcpServers === 'object') {
|
|
506
|
+
const servers = Object.keys(settings.mcpServers);
|
|
507
|
+
mcpServers.total = servers.length;
|
|
508
|
+
mcpServers.enabled = settings.enabledMcpjsonServers
|
|
509
|
+
? settings.enabledMcpjsonServers.filter(s => servers.includes(s)).length
|
|
510
|
+
: servers.length;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (mcpServers.total === 0) {
|
|
514
|
+
const mcpConfig = readJSON(path.join(CWD, 'opencode.json'))
|
|
515
|
+
|| readJSON(path.join(CWD, '.mcp.json'))
|
|
516
|
+
|| readJSON(path.join(os.homedir(), '.opencode', 'mcp.json'))
|
|
517
|
+
|| readJSON(path.join(os.homedir(), '.claude', 'mcp.json'));
|
|
518
|
+
if (mcpConfig && mcpConfig.mcpServers) {
|
|
519
|
+
const s = Object.keys(mcpConfig.mcpServers);
|
|
520
|
+
mcpServers.total = s.length;
|
|
521
|
+
mcpServers.enabled = s.length;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const hasDatabase = ['.opencode/memory.db', '.swarm/memory.db', '.claude-flow/memory.db', 'data/memory.db']
|
|
526
|
+
.some(p => fs.existsSync(path.join(CWD, p)));
|
|
527
|
+
const hasApi = !!(process.env.ANTHROPIC_API_KEY || process.env.OPENAI_API_KEY);
|
|
528
|
+
|
|
529
|
+
return { mcpServers, hasDatabase, hasApi };
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Session stats (pure file reads)
|
|
533
|
+
function getSessionStats() {
|
|
534
|
+
var sessionPaths = ['.opencode/session.json', '.claude-flow/session.json', '.claude/session.json'];
|
|
535
|
+
for (var i = 0; i < sessionPaths.length; i++) {
|
|
536
|
+
const data = readJSON(path.join(CWD, sessionPaths[i]));
|
|
537
|
+
if (data && data.startTime) {
|
|
538
|
+
const diffMs = Date.now() - new Date(data.startTime).getTime();
|
|
539
|
+
const mins = Math.floor(diffMs / 60000);
|
|
540
|
+
const duration = mins < 60 ? mins + 'm' : Math.floor(mins / 60) + 'h' + (mins % 60) + 'm';
|
|
541
|
+
return { duration: duration };
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return { duration: '' };
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// ─── Rendering ──────────────────────────────────────────────────
|
|
548
|
+
|
|
549
|
+
function progressBar(current, total) {
|
|
550
|
+
const width = 5;
|
|
551
|
+
const filled = Math.round((current / total) * width);
|
|
552
|
+
return '[' + '\u25CF'.repeat(filled) + '\u25CB'.repeat(width - filled) + ']';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function generateStatusline() {
|
|
556
|
+
const git = getGitInfo();
|
|
557
|
+
// Prefer model name from Claude Code stdin data, fallback to file-based detection
|
|
558
|
+
const modelName = getModelFromStdin() || getModelName();
|
|
559
|
+
const ctxInfo = getContextFromStdin();
|
|
560
|
+
const costInfo = getCostFromStdin();
|
|
561
|
+
const progress = getV3Progress();
|
|
562
|
+
const security = getSecurityStatus();
|
|
563
|
+
const swarm = getSwarmStatus();
|
|
564
|
+
const system = getSystemMetrics();
|
|
565
|
+
const adrs = getADRStatus();
|
|
566
|
+
const hooks = getHooksStatus();
|
|
567
|
+
const agentdb = getAgentDBStats();
|
|
568
|
+
const tests = getTestStats();
|
|
569
|
+
const session = getSessionStats();
|
|
570
|
+
const integration = getIntegrationStatus();
|
|
571
|
+
const lines = [];
|
|
572
|
+
|
|
573
|
+
// Header
|
|
574
|
+
let header = c.bold + c.brightPurple + '\u258A OpenCode V3 ' + c.reset;
|
|
575
|
+
header += (swarm.coordinationActive ? c.brightCyan : c.dim) + '\u25CF ' + c.brightCyan + git.name + c.reset;
|
|
576
|
+
if (git.gitBranch) {
|
|
577
|
+
header += ' ' + c.dim + '\u2502' + c.reset + ' ' + c.brightBlue + '\u23C7 ' + git.gitBranch + c.reset;
|
|
578
|
+
const changes = git.modified + git.staged + git.untracked;
|
|
579
|
+
if (changes > 0) {
|
|
580
|
+
let ind = '';
|
|
581
|
+
if (git.staged > 0) ind += c.brightGreen + '+' + git.staged + c.reset;
|
|
582
|
+
if (git.modified > 0) ind += c.brightYellow + '~' + git.modified + c.reset;
|
|
583
|
+
if (git.untracked > 0) ind += c.dim + '?' + git.untracked + c.reset;
|
|
584
|
+
header += ' ' + ind;
|
|
585
|
+
}
|
|
586
|
+
if (git.ahead > 0) header += ' ' + c.brightGreen + '\u2191' + git.ahead + c.reset;
|
|
587
|
+
if (git.behind > 0) header += ' ' + c.brightRed + '\u2193' + git.behind + c.reset;
|
|
588
|
+
}
|
|
589
|
+
header += ' ' + c.dim + '\u2502' + c.reset + ' ' + c.purple + modelName + c.reset;
|
|
590
|
+
// Show session duration from Claude Code stdin if available, else from local files
|
|
591
|
+
const duration = costInfo ? costInfo.duration : session.duration;
|
|
592
|
+
if (duration) header += ' ' + c.dim + '\u2502' + c.reset + ' ' + c.cyan + '\u23F1 ' + duration + c.reset;
|
|
593
|
+
// Show context usage from Claude Code stdin if available
|
|
594
|
+
if (ctxInfo && ctxInfo.usedPct > 0) {
|
|
595
|
+
const ctxColor = ctxInfo.usedPct >= 90 ? c.brightRed : ctxInfo.usedPct >= 70 ? c.brightYellow : c.brightGreen;
|
|
596
|
+
header += ' ' + c.dim + '\u2502' + c.reset + ' ' + ctxColor + '\u25CF ' + ctxInfo.usedPct + '% ctx' + c.reset;
|
|
597
|
+
}
|
|
598
|
+
// Show cost from Claude Code stdin if available
|
|
599
|
+
if (costInfo && costInfo.costUsd > 0) {
|
|
600
|
+
header += ' ' + c.dim + '\u2502' + c.reset + ' ' + c.brightYellow + '$' + costInfo.costUsd.toFixed(2) + c.reset;
|
|
601
|
+
}
|
|
602
|
+
lines.push(header);
|
|
603
|
+
|
|
604
|
+
// Separator
|
|
605
|
+
lines.push(c.dim + '\u2500'.repeat(53) + c.reset);
|
|
606
|
+
|
|
607
|
+
// Line 1: DDD Domains
|
|
608
|
+
const domainsColor = progress.domainsCompleted >= 3 ? c.brightGreen : progress.domainsCompleted > 0 ? c.yellow : c.red;
|
|
609
|
+
let perfIndicator;
|
|
610
|
+
if (agentdb.hasHnsw && agentdb.vectorCount > 0) {
|
|
611
|
+
const speedup = agentdb.vectorCount > 10000 ? '12500x' : agentdb.vectorCount > 1000 ? '150x' : '10x';
|
|
612
|
+
perfIndicator = c.brightGreen + '\u26A1 HNSW ' + speedup + c.reset;
|
|
613
|
+
} else if (progress.patternsLearned > 0) {
|
|
614
|
+
const pk = progress.patternsLearned >= 1000 ? (progress.patternsLearned / 1000).toFixed(1) + 'k' : String(progress.patternsLearned);
|
|
615
|
+
perfIndicator = c.brightYellow + '\uD83D\uDCDA ' + pk + ' patterns' + c.reset;
|
|
616
|
+
} else {
|
|
617
|
+
perfIndicator = c.dim + '\u26A1 target: 150x-12500x' + c.reset;
|
|
618
|
+
}
|
|
619
|
+
lines.push(
|
|
620
|
+
c.brightCyan + '\uD83C\uDFD7\uFE0F DDD Domains' + c.reset + ' ' + progressBar(progress.domainsCompleted, progress.totalDomains) + ' ' +
|
|
621
|
+
domainsColor + progress.domainsCompleted + c.reset + '/' + c.brightWhite + progress.totalDomains + c.reset + ' ' + perfIndicator
|
|
622
|
+
);
|
|
623
|
+
|
|
624
|
+
// Line 2: Swarm + Hooks + CVE + Memory + Intelligence
|
|
625
|
+
const swarmInd = swarm.coordinationActive ? c.brightGreen + '\u25C9' + c.reset : c.dim + '\u25CB' + c.reset;
|
|
626
|
+
const agentsColor = swarm.activeAgents > 0 ? c.brightGreen : c.red;
|
|
627
|
+
const secIcon = security.status === 'CLEAN' ? '\uD83D\uDFE2' : security.status === 'IN_PROGRESS' ? '\uD83D\uDFE1' : '\uD83D\uDD34';
|
|
628
|
+
const secColor = security.status === 'CLEAN' ? c.brightGreen : security.status === 'IN_PROGRESS' ? c.brightYellow : c.brightRed;
|
|
629
|
+
const hooksColor = hooks.enabled > 0 ? c.brightGreen : c.dim;
|
|
630
|
+
const intellColor = system.intelligencePct >= 80 ? c.brightGreen : system.intelligencePct >= 40 ? c.brightYellow : c.dim;
|
|
631
|
+
|
|
632
|
+
lines.push(
|
|
633
|
+
c.brightYellow + '\uD83E\uDD16 Swarm' + c.reset + ' ' + swarmInd + ' [' + agentsColor + String(swarm.activeAgents).padStart(2) + c.reset + '/' + c.brightWhite + swarm.maxAgents + c.reset + '] ' +
|
|
634
|
+
c.brightPurple + '\uD83D\uDC65 ' + system.subAgents + c.reset + ' ' +
|
|
635
|
+
c.brightBlue + '\uD83E\uDE9D ' + hooksColor + hooks.enabled + c.reset + '/' + c.brightWhite + hooks.total + c.reset + ' ' +
|
|
636
|
+
secIcon + ' ' + secColor + 'CVE ' + security.cvesFixed + c.reset + '/' + c.brightWhite + security.totalCves + c.reset + ' ' +
|
|
637
|
+
c.brightCyan + '\uD83D\uDCBE ' + system.memoryMB + 'MB' + c.reset + ' ' +
|
|
638
|
+
intellColor + '\uD83E\uDDE0 ' + String(system.intelligencePct).padStart(3) + '%' + c.reset
|
|
639
|
+
);
|
|
640
|
+
|
|
641
|
+
// Line 3: Architecture
|
|
642
|
+
const dddColor = progress.dddProgress >= 50 ? c.brightGreen : progress.dddProgress > 0 ? c.yellow : c.red;
|
|
643
|
+
const adrColor = adrs.count > 0 ? (adrs.implemented === adrs.count ? c.brightGreen : c.yellow) : c.dim;
|
|
644
|
+
const adrDisplay = adrs.compliance > 0 ? adrColor + '\u25CF' + adrs.compliance + '%' + c.reset : adrColor + '\u25CF' + adrs.implemented + '/' + adrs.count + c.reset;
|
|
645
|
+
|
|
646
|
+
lines.push(
|
|
647
|
+
c.brightPurple + '\uD83D\uDD27 Architecture' + c.reset + ' ' +
|
|
648
|
+
c.cyan + 'ADRs' + c.reset + ' ' + adrDisplay + ' ' + c.dim + '\u2502' + c.reset + ' ' +
|
|
649
|
+
c.cyan + 'DDD' + c.reset + ' ' + dddColor + '\u25CF' + String(progress.dddProgress).padStart(3) + '%' + c.reset + ' ' + c.dim + '\u2502' + c.reset + ' ' +
|
|
650
|
+
c.cyan + 'Security' + c.reset + ' ' + secColor + '\u25CF' + security.status + c.reset
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
// Line 4: AgentDB, Tests, Integration
|
|
654
|
+
const hnswInd = agentdb.hasHnsw ? c.brightGreen + '\u26A1' + c.reset : '';
|
|
655
|
+
const sizeDisp = agentdb.dbSizeKB >= 1024 ? (agentdb.dbSizeKB / 1024).toFixed(1) + 'MB' : agentdb.dbSizeKB + 'KB';
|
|
656
|
+
const vectorColor = agentdb.vectorCount > 0 ? c.brightGreen : c.dim;
|
|
657
|
+
const testColor = tests.testFiles > 0 ? c.brightGreen : c.dim;
|
|
658
|
+
|
|
659
|
+
let integStr = '';
|
|
660
|
+
if (integration.mcpServers.total > 0) {
|
|
661
|
+
const mcpCol = integration.mcpServers.enabled === integration.mcpServers.total ? c.brightGreen :
|
|
662
|
+
integration.mcpServers.enabled > 0 ? c.brightYellow : c.red;
|
|
663
|
+
integStr += c.cyan + 'MCP' + c.reset + ' ' + mcpCol + '\u25CF' + integration.mcpServers.enabled + '/' + integration.mcpServers.total + c.reset;
|
|
664
|
+
}
|
|
665
|
+
if (integration.hasDatabase) integStr += (integStr ? ' ' : '') + c.brightGreen + '\u25C6' + c.reset + 'DB';
|
|
666
|
+
if (integration.hasApi) integStr += (integStr ? ' ' : '') + c.brightGreen + '\u25C6' + c.reset + 'API';
|
|
667
|
+
if (!integStr) integStr = c.dim + '\u25CF none' + c.reset;
|
|
668
|
+
|
|
669
|
+
lines.push(
|
|
670
|
+
c.brightCyan + '\uD83D\uDCCA AgentDB' + c.reset + ' ' +
|
|
671
|
+
c.cyan + 'Vectors' + c.reset + ' ' + vectorColor + '\u25CF' + agentdb.vectorCount + hnswInd + c.reset + ' ' + c.dim + '\u2502' + c.reset + ' ' +
|
|
672
|
+
c.cyan + 'Size' + c.reset + ' ' + c.brightWhite + sizeDisp + c.reset + ' ' + c.dim + '\u2502' + c.reset + ' ' +
|
|
673
|
+
c.cyan + 'Tests' + c.reset + ' ' + testColor + '\u25CF' + tests.testFiles + c.reset + ' ' + c.dim + '(~' + tests.testCases + ' cases)' + c.reset + ' ' + c.dim + '\u2502' + c.reset + ' ' +
|
|
674
|
+
integStr
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
return lines.join('\n');
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// JSON output
|
|
681
|
+
function generateJSON() {
|
|
682
|
+
const git = getGitInfo();
|
|
683
|
+
return {
|
|
684
|
+
user: { name: git.name, gitBranch: git.gitBranch, modelName: getModelName() },
|
|
685
|
+
v3Progress: getV3Progress(),
|
|
686
|
+
security: getSecurityStatus(),
|
|
687
|
+
swarm: getSwarmStatus(),
|
|
688
|
+
system: getSystemMetrics(),
|
|
689
|
+
adrs: getADRStatus(),
|
|
690
|
+
hooks: getHooksStatus(),
|
|
691
|
+
agentdb: getAgentDBStats(),
|
|
692
|
+
tests: getTestStats(),
|
|
693
|
+
git: { modified: git.modified, untracked: git.untracked, staged: git.staged, ahead: git.ahead, behind: git.behind },
|
|
694
|
+
lastUpdated: new Date().toISOString(),
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// ─── Stdin reader (Claude Code pipes session JSON) ──────────────
|
|
699
|
+
|
|
700
|
+
// Claude Code sends session JSON via stdin (model, context, cost, etc.)
|
|
701
|
+
// Read it synchronously so the script works both:
|
|
702
|
+
// 1. When invoked by Claude Code (stdin has JSON)
|
|
703
|
+
// 2. When invoked manually from terminal (stdin is empty/tty)
|
|
704
|
+
let _stdinData = null;
|
|
705
|
+
function getStdinData() {
|
|
706
|
+
if (_stdinData !== undefined && _stdinData !== null) return _stdinData;
|
|
707
|
+
try {
|
|
708
|
+
// Check if stdin is a TTY (manual run) — skip reading
|
|
709
|
+
if (process.stdin.isTTY) { _stdinData = null; return null; }
|
|
710
|
+
// Read stdin synchronously via fd 0
|
|
711
|
+
const chunks = [];
|
|
712
|
+
const buf = Buffer.alloc(4096);
|
|
713
|
+
let bytesRead;
|
|
714
|
+
try {
|
|
715
|
+
while ((bytesRead = fs.readSync(0, buf, 0, buf.length, null)) > 0) {
|
|
716
|
+
chunks.push(buf.slice(0, bytesRead));
|
|
717
|
+
}
|
|
718
|
+
} catch { /* EOF or read error */ }
|
|
719
|
+
const raw = Buffer.concat(chunks).toString('utf-8').trim();
|
|
720
|
+
if (raw && raw.startsWith('{')) {
|
|
721
|
+
_stdinData = JSON.parse(raw);
|
|
722
|
+
} else {
|
|
723
|
+
_stdinData = null;
|
|
724
|
+
}
|
|
725
|
+
} catch {
|
|
726
|
+
_stdinData = null;
|
|
727
|
+
}
|
|
728
|
+
return _stdinData;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// Override model detection to prefer stdin data from Claude Code
|
|
732
|
+
function getModelFromStdin() {
|
|
733
|
+
const data = getStdinData();
|
|
734
|
+
if (data && data.model && data.model.display_name) return data.model.display_name;
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// Get context window info from Claude Code session
|
|
739
|
+
function getContextFromStdin() {
|
|
740
|
+
const data = getStdinData();
|
|
741
|
+
if (data && data.context_window) {
|
|
742
|
+
return {
|
|
743
|
+
usedPct: Math.floor(data.context_window.used_percentage || 0),
|
|
744
|
+
remainingPct: Math.floor(data.context_window.remaining_percentage || 100),
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// Get cost info from Claude Code session
|
|
751
|
+
function getCostFromStdin() {
|
|
752
|
+
const data = getStdinData();
|
|
753
|
+
if (data && data.cost) {
|
|
754
|
+
const durationMs = data.cost.total_duration_ms || 0;
|
|
755
|
+
const mins = Math.floor(durationMs / 60000);
|
|
756
|
+
const secs = Math.floor((durationMs % 60000) / 1000);
|
|
757
|
+
return {
|
|
758
|
+
costUsd: data.cost.total_cost_usd || 0,
|
|
759
|
+
duration: mins > 0 ? mins + 'm' + secs + 's' : secs + 's',
|
|
760
|
+
linesAdded: data.cost.total_lines_added || 0,
|
|
761
|
+
linesRemoved: data.cost.total_lines_removed || 0,
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// ─── Main ───────────────────────────────────────────────────────
|
|
768
|
+
if (process.argv.includes('--json')) {
|
|
769
|
+
console.log(JSON.stringify(generateJSON(), null, 2));
|
|
770
|
+
} else if (process.argv.includes('--compact')) {
|
|
771
|
+
console.log(JSON.stringify(generateJSON()));
|
|
772
|
+
} else {
|
|
773
|
+
console.log(generateStatusline());
|
|
774
|
+
}
|