devflow-kit 1.6.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +31 -0
  3. package/dist/cli.js +3 -1
  4. package/dist/commands/hud.d.ts +22 -0
  5. package/dist/commands/hud.js +180 -0
  6. package/dist/commands/init.d.ts +1 -0
  7. package/dist/commands/init.js +114 -5
  8. package/dist/commands/list.js +1 -0
  9. package/dist/commands/uninstall.js +9 -16
  10. package/dist/hud/cache.d.ts +14 -0
  11. package/dist/hud/cache.js +54 -0
  12. package/dist/hud/colors.d.ts +23 -0
  13. package/dist/hud/colors.js +62 -0
  14. package/dist/hud/components/config-counts.d.ts +8 -0
  15. package/dist/hud/components/config-counts.js +91 -0
  16. package/dist/hud/components/context-usage.d.ts +8 -0
  17. package/dist/hud/components/context-usage.js +49 -0
  18. package/dist/hud/components/diff-stats.d.ts +3 -0
  19. package/dist/hud/components/diff-stats.js +36 -0
  20. package/dist/hud/components/directory.d.ts +3 -0
  21. package/dist/hud/components/directory.js +10 -0
  22. package/dist/hud/components/git-ahead-behind.d.ts +3 -0
  23. package/dist/hud/components/git-ahead-behind.js +16 -0
  24. package/dist/hud/components/git-branch.d.ts +3 -0
  25. package/dist/hud/components/git-branch.js +14 -0
  26. package/dist/hud/components/model.d.ts +3 -0
  27. package/dist/hud/components/model.js +21 -0
  28. package/dist/hud/components/release-info.d.ts +3 -0
  29. package/dist/hud/components/release-info.js +9 -0
  30. package/dist/hud/components/session-cost.d.ts +3 -0
  31. package/dist/hud/components/session-cost.js +9 -0
  32. package/dist/hud/components/session-duration.d.ts +3 -0
  33. package/dist/hud/components/session-duration.js +18 -0
  34. package/dist/hud/components/todo-progress.d.ts +3 -0
  35. package/dist/hud/components/todo-progress.js +11 -0
  36. package/dist/hud/components/usage-quota.d.ts +3 -0
  37. package/dist/hud/components/usage-quota.js +45 -0
  38. package/dist/hud/components/version-badge.d.ts +3 -0
  39. package/dist/hud/components/version-badge.js +80 -0
  40. package/dist/hud/components/worktree-count.d.ts +3 -0
  41. package/dist/hud/components/worktree-count.js +8 -0
  42. package/dist/hud/config.d.ts +10 -0
  43. package/dist/hud/config.js +55 -0
  44. package/dist/hud/credentials.d.ts +17 -0
  45. package/dist/hud/credentials.js +99 -0
  46. package/dist/hud/git.d.ts +7 -0
  47. package/dist/hud/git.js +153 -0
  48. package/dist/hud/index.d.ts +2 -0
  49. package/dist/hud/index.js +81 -0
  50. package/dist/hud/render.d.ts +7 -0
  51. package/dist/hud/render.js +111 -0
  52. package/dist/hud/stdin.d.ts +6 -0
  53. package/dist/hud/stdin.js +25 -0
  54. package/dist/hud/transcript.d.ts +7 -0
  55. package/dist/hud/transcript.js +130 -0
  56. package/dist/hud/types.d.ts +116 -0
  57. package/dist/hud/types.js +2 -0
  58. package/dist/hud/usage-api.d.ts +7 -0
  59. package/dist/hud/usage-api.js +84 -0
  60. package/dist/utils/manifest.d.ts +1 -0
  61. package/package.json +5 -2
  62. package/plugins/devflow-accessibility/.claude-plugin/plugin.json +1 -1
  63. package/plugins/devflow-ambient/.claude-plugin/plugin.json +1 -1
  64. package/plugins/devflow-ambient/agents/scrutinizer.md +6 -4
  65. package/plugins/devflow-ambient/agents/shepherd.md +26 -12
  66. package/plugins/devflow-ambient/agents/simplifier.md +24 -15
  67. package/plugins/devflow-ambient/agents/skimmer.md +71 -21
  68. package/plugins/devflow-audit-claude/.claude-plugin/plugin.json +1 -1
  69. package/plugins/devflow-code-review/.claude-plugin/plugin.json +1 -1
  70. package/plugins/devflow-core-skills/.claude-plugin/plugin.json +1 -1
  71. package/plugins/devflow-debug/.claude-plugin/plugin.json +1 -1
  72. package/plugins/devflow-frontend-design/.claude-plugin/plugin.json +1 -1
  73. package/plugins/devflow-go/.claude-plugin/plugin.json +1 -1
  74. package/plugins/devflow-implement/.claude-plugin/plugin.json +1 -1
  75. package/plugins/devflow-implement/agents/scrutinizer.md +6 -4
  76. package/plugins/devflow-implement/agents/shepherd.md +26 -12
  77. package/plugins/devflow-implement/agents/simplifier.md +24 -15
  78. package/plugins/devflow-implement/agents/skimmer.md +71 -21
  79. package/plugins/devflow-implement/commands/implement-teams.md +1 -1
  80. package/plugins/devflow-implement/commands/implement.md +1 -1
  81. package/plugins/devflow-implement/skills/self-review/references/stub-detection.md +135 -0
  82. package/plugins/devflow-java/.claude-plugin/plugin.json +1 -1
  83. package/plugins/devflow-python/.claude-plugin/plugin.json +1 -1
  84. package/plugins/devflow-react/.claude-plugin/plugin.json +1 -1
  85. package/plugins/devflow-resolve/.claude-plugin/plugin.json +1 -1
  86. package/plugins/devflow-resolve/agents/simplifier.md +24 -15
  87. package/plugins/devflow-rust/.claude-plugin/plugin.json +1 -1
  88. package/plugins/devflow-self-review/.claude-plugin/plugin.json +1 -1
  89. package/plugins/devflow-self-review/agents/scrutinizer.md +6 -4
  90. package/plugins/devflow-self-review/agents/simplifier.md +24 -15
  91. package/plugins/devflow-self-review/skills/self-review/references/stub-detection.md +135 -0
  92. package/plugins/devflow-specify/.claude-plugin/plugin.json +1 -1
  93. package/plugins/devflow-specify/agents/skimmer.md +71 -21
  94. package/plugins/devflow-specify/commands/specify-teams.md +1 -1
  95. package/plugins/devflow-specify/commands/specify.md +1 -1
  96. package/plugins/devflow-typescript/.claude-plugin/plugin.json +1 -1
  97. package/scripts/hud/cache.d.ts +14 -0
  98. package/scripts/hud/cache.d.ts.map +1 -0
  99. package/scripts/hud/cache.js +54 -0
  100. package/scripts/hud/cache.js.map +1 -0
  101. package/scripts/hud/colors.d.ts +23 -0
  102. package/scripts/hud/colors.d.ts.map +1 -0
  103. package/scripts/hud/colors.js +62 -0
  104. package/scripts/hud/colors.js.map +1 -0
  105. package/scripts/hud/components/config-counts.d.ts +8 -0
  106. package/scripts/hud/components/config-counts.d.ts.map +1 -0
  107. package/scripts/hud/components/config-counts.js +91 -0
  108. package/scripts/hud/components/config-counts.js.map +1 -0
  109. package/scripts/hud/components/context-usage.d.ts +8 -0
  110. package/scripts/hud/components/context-usage.d.ts.map +1 -0
  111. package/scripts/hud/components/context-usage.js +49 -0
  112. package/scripts/hud/components/context-usage.js.map +1 -0
  113. package/scripts/hud/components/diff-stats.d.ts +3 -0
  114. package/scripts/hud/components/diff-stats.d.ts.map +1 -0
  115. package/scripts/hud/components/diff-stats.js +36 -0
  116. package/scripts/hud/components/diff-stats.js.map +1 -0
  117. package/scripts/hud/components/directory.d.ts +3 -0
  118. package/scripts/hud/components/directory.d.ts.map +1 -0
  119. package/scripts/hud/components/directory.js +10 -0
  120. package/scripts/hud/components/directory.js.map +1 -0
  121. package/scripts/hud/components/git-ahead-behind.d.ts +3 -0
  122. package/scripts/hud/components/git-ahead-behind.d.ts.map +1 -0
  123. package/scripts/hud/components/git-ahead-behind.js +16 -0
  124. package/scripts/hud/components/git-ahead-behind.js.map +1 -0
  125. package/scripts/hud/components/git-branch.d.ts +3 -0
  126. package/scripts/hud/components/git-branch.d.ts.map +1 -0
  127. package/scripts/hud/components/git-branch.js +14 -0
  128. package/scripts/hud/components/git-branch.js.map +1 -0
  129. package/scripts/hud/components/model.d.ts +3 -0
  130. package/scripts/hud/components/model.d.ts.map +1 -0
  131. package/scripts/hud/components/model.js +21 -0
  132. package/scripts/hud/components/model.js.map +1 -0
  133. package/scripts/hud/components/release-info.d.ts +3 -0
  134. package/scripts/hud/components/release-info.d.ts.map +1 -0
  135. package/scripts/hud/components/release-info.js +9 -0
  136. package/scripts/hud/components/release-info.js.map +1 -0
  137. package/scripts/hud/components/session-cost.d.ts +3 -0
  138. package/scripts/hud/components/session-cost.d.ts.map +1 -0
  139. package/scripts/hud/components/session-cost.js +9 -0
  140. package/scripts/hud/components/session-cost.js.map +1 -0
  141. package/scripts/hud/components/session-duration.d.ts +3 -0
  142. package/scripts/hud/components/session-duration.d.ts.map +1 -0
  143. package/scripts/hud/components/session-duration.js +18 -0
  144. package/scripts/hud/components/session-duration.js.map +1 -0
  145. package/scripts/hud/components/todo-progress.d.ts +3 -0
  146. package/scripts/hud/components/todo-progress.d.ts.map +1 -0
  147. package/scripts/hud/components/todo-progress.js +11 -0
  148. package/scripts/hud/components/todo-progress.js.map +1 -0
  149. package/scripts/hud/components/usage-quota.d.ts +3 -0
  150. package/scripts/hud/components/usage-quota.d.ts.map +1 -0
  151. package/scripts/hud/components/usage-quota.js +45 -0
  152. package/scripts/hud/components/usage-quota.js.map +1 -0
  153. package/scripts/hud/components/version-badge.d.ts +3 -0
  154. package/scripts/hud/components/version-badge.d.ts.map +1 -0
  155. package/scripts/hud/components/version-badge.js +80 -0
  156. package/scripts/hud/components/version-badge.js.map +1 -0
  157. package/scripts/hud/components/worktree-count.d.ts +3 -0
  158. package/scripts/hud/components/worktree-count.d.ts.map +1 -0
  159. package/scripts/hud/components/worktree-count.js +8 -0
  160. package/scripts/hud/components/worktree-count.js.map +1 -0
  161. package/scripts/hud/config.d.ts +10 -0
  162. package/scripts/hud/config.d.ts.map +1 -0
  163. package/scripts/hud/config.js +55 -0
  164. package/scripts/hud/config.js.map +1 -0
  165. package/scripts/hud/credentials.d.ts +17 -0
  166. package/scripts/hud/credentials.d.ts.map +1 -0
  167. package/scripts/hud/credentials.js +99 -0
  168. package/scripts/hud/credentials.js.map +1 -0
  169. package/scripts/hud/git.d.ts +7 -0
  170. package/scripts/hud/git.d.ts.map +1 -0
  171. package/scripts/hud/git.js +153 -0
  172. package/scripts/hud/git.js.map +1 -0
  173. package/scripts/hud/index.d.ts +2 -0
  174. package/scripts/hud/index.d.ts.map +1 -0
  175. package/scripts/hud/index.js +81 -0
  176. package/scripts/hud/index.js.map +1 -0
  177. package/scripts/hud/render.d.ts +7 -0
  178. package/scripts/hud/render.d.ts.map +1 -0
  179. package/scripts/hud/render.js +111 -0
  180. package/scripts/hud/render.js.map +1 -0
  181. package/scripts/hud/stdin.d.ts +6 -0
  182. package/scripts/hud/stdin.d.ts.map +1 -0
  183. package/scripts/hud/stdin.js +25 -0
  184. package/scripts/hud/stdin.js.map +1 -0
  185. package/scripts/hud/transcript.d.ts +7 -0
  186. package/scripts/hud/transcript.d.ts.map +1 -0
  187. package/scripts/hud/transcript.js +130 -0
  188. package/scripts/hud/transcript.js.map +1 -0
  189. package/scripts/hud/types.d.ts +116 -0
  190. package/scripts/hud/types.d.ts.map +1 -0
  191. package/scripts/hud/types.js +2 -0
  192. package/scripts/hud/types.js.map +1 -0
  193. package/scripts/hud/usage-api.d.ts +7 -0
  194. package/scripts/hud/usage-api.d.ts.map +1 -0
  195. package/scripts/hud/usage-api.js +84 -0
  196. package/scripts/hud/usage-api.js.map +1 -0
  197. package/scripts/hud.sh +5 -0
  198. package/shared/agents/scrutinizer.md +6 -4
  199. package/shared/agents/shepherd.md +26 -12
  200. package/shared/agents/simplifier.md +24 -15
  201. package/shared/agents/skimmer.md +71 -21
  202. package/shared/skills/self-review/references/stub-detection.md +135 -0
  203. package/src/templates/settings.json +1 -1
@@ -0,0 +1,55 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { homedir } from 'node:os';
4
+ /**
5
+ * All 14 HUD components in display order.
6
+ */
7
+ export const HUD_COMPONENTS = [
8
+ 'directory',
9
+ 'gitBranch',
10
+ 'gitAheadBehind',
11
+ 'diffStats',
12
+ 'releaseInfo',
13
+ 'worktreeCount',
14
+ 'model',
15
+ 'contextUsage',
16
+ 'versionBadge',
17
+ 'sessionDuration',
18
+ 'sessionCost',
19
+ 'usageQuota',
20
+ 'todoProgress',
21
+ 'configCounts',
22
+ ];
23
+ export function getConfigPath() {
24
+ const devflowDir = process.env.DEVFLOW_DIR || path.join(process.env.HOME || homedir(), '.devflow');
25
+ return path.join(devflowDir, 'hud.json');
26
+ }
27
+ export function loadConfig() {
28
+ const configPath = getConfigPath();
29
+ try {
30
+ const raw = fs.readFileSync(configPath, 'utf-8');
31
+ const parsed = JSON.parse(raw);
32
+ return {
33
+ enabled: parsed.enabled !== false,
34
+ detail: parsed.detail === true,
35
+ };
36
+ }
37
+ catch {
38
+ return { enabled: true, detail: false };
39
+ }
40
+ }
41
+ export function saveConfig(config) {
42
+ const configPath = getConfigPath();
43
+ const dir = path.dirname(configPath);
44
+ if (!fs.existsSync(dir)) {
45
+ fs.mkdirSync(dir, { recursive: true });
46
+ }
47
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
48
+ }
49
+ export function resolveComponents(config) {
50
+ if (config.enabled)
51
+ return [...HUD_COMPONENTS];
52
+ // Version badge always renders so users see upgrade notifications
53
+ return ['versionBadge'];
54
+ }
55
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,17 @@
1
+ export interface OAuthCredentials {
2
+ accessToken: string;
3
+ subscriptionType?: string;
4
+ }
5
+ /** Resolve the Claude config directory, respecting CLAUDE_CONFIG_DIR. */
6
+ export declare function getClaudeDir(): string;
7
+ /** Read OAuth credentials from ~/.claude/.credentials.json. Injectable claudeDir for tests. */
8
+ export declare function readCredentialsFile(claudeDir?: string): OAuthCredentials | null;
9
+ /** Read OAuth token from macOS Keychain. Returns null on non-darwin or failure. */
10
+ export declare function readKeychainToken(): Promise<string | null>;
11
+ /**
12
+ * Get OAuth credentials using platform-appropriate strategy.
13
+ * macOS: Keychain first, then file fallback. Other platforms: file only.
14
+ * Hybrid: if Keychain has token but no subscriptionType, merge from file.
15
+ */
16
+ export declare function getCredentials(): Promise<OAuthCredentials | null>;
17
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1,99 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { homedir } from 'node:os';
4
+ import { execFile } from 'node:child_process';
5
+ const KEYCHAIN_TIMEOUT = 3000; // 3s
6
+ const DEBUG = !!process.env.DEVFLOW_HUD_DEBUG;
7
+ function debugLog(msg, data) {
8
+ if (!DEBUG)
9
+ return;
10
+ const entry = { ts: new Date().toISOString(), source: 'credentials', msg, ...data };
11
+ fs.appendFileSync('/tmp/hud-debug.log', JSON.stringify(entry) + '\n');
12
+ }
13
+ /** Resolve the Claude config directory, respecting CLAUDE_CONFIG_DIR. */
14
+ export function getClaudeDir() {
15
+ return (process.env.CLAUDE_CONFIG_DIR ||
16
+ path.join(process.env.HOME || homedir(), '.claude'));
17
+ }
18
+ /** Read OAuth credentials from ~/.claude/.credentials.json. Injectable claudeDir for tests. */
19
+ export function readCredentialsFile(claudeDir) {
20
+ try {
21
+ const dir = claudeDir ?? getClaudeDir();
22
+ const filePath = path.join(dir, '.credentials.json');
23
+ const raw = fs.readFileSync(filePath, 'utf-8');
24
+ const creds = JSON.parse(raw);
25
+ const oauth = creds.claudeAiOauth;
26
+ const accessToken = oauth?.accessToken;
27
+ if (typeof accessToken !== 'string' || !accessToken)
28
+ return null;
29
+ const subscriptionType = typeof oauth?.subscriptionType === 'string' ? oauth.subscriptionType : undefined;
30
+ debugLog('credentials file read', { filePath, hasSubscriptionType: !!subscriptionType });
31
+ return { accessToken, subscriptionType };
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ /** Read OAuth token from macOS Keychain. Returns null on non-darwin or failure. */
38
+ export function readKeychainToken() {
39
+ if (process.platform !== 'darwin')
40
+ return Promise.resolve(null);
41
+ return new Promise((resolve) => {
42
+ execFile('/usr/bin/security', ['find-generic-password', '-s', 'Claude Code-credentials', '-w'], { timeout: KEYCHAIN_TIMEOUT }, (err, stdout) => {
43
+ if (err || !stdout.trim()) {
44
+ debugLog('keychain read failed', { error: err?.message });
45
+ resolve(null);
46
+ return;
47
+ }
48
+ try {
49
+ const parsed = JSON.parse(stdout.trim());
50
+ const oauth = parsed.claudeAiOauth;
51
+ const token = oauth?.accessToken;
52
+ if (typeof token === 'string' && token) {
53
+ debugLog('keychain token found');
54
+ resolve(token);
55
+ }
56
+ else {
57
+ debugLog('keychain: no accessToken in parsed data');
58
+ resolve(null);
59
+ }
60
+ }
61
+ catch {
62
+ // Keychain value might be the raw token string
63
+ const trimmed = stdout.trim();
64
+ if (trimmed.length > 20) {
65
+ debugLog('keychain: raw token string');
66
+ resolve(trimmed);
67
+ }
68
+ else {
69
+ debugLog('keychain: unparseable value');
70
+ resolve(null);
71
+ }
72
+ }
73
+ });
74
+ });
75
+ }
76
+ /**
77
+ * Get OAuth credentials using platform-appropriate strategy.
78
+ * macOS: Keychain first, then file fallback. Other platforms: file only.
79
+ * Hybrid: if Keychain has token but no subscriptionType, merge from file.
80
+ */
81
+ export async function getCredentials() {
82
+ const fileCreds = readCredentialsFile();
83
+ if (process.platform !== 'darwin') {
84
+ debugLog('non-darwin: file credentials only', { found: !!fileCreds });
85
+ return fileCreds;
86
+ }
87
+ // macOS: try Keychain first
88
+ const keychainToken = await readKeychainToken();
89
+ if (keychainToken) {
90
+ // Merge subscriptionType from file if Keychain doesn't have it
91
+ const subscriptionType = fileCreds?.subscriptionType;
92
+ debugLog('using keychain token', { hasSubscriptionType: !!subscriptionType });
93
+ return { accessToken: keychainToken, subscriptionType };
94
+ }
95
+ // Fallback to file
96
+ debugLog('keychain failed, falling back to file', { found: !!fileCreds });
97
+ return fileCreds;
98
+ }
99
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1,7 @@
1
+ import type { GitStatus } from './types.js';
2
+ /**
3
+ * Gather git status for the given working directory.
4
+ * Returns null if not in a git repo or on error.
5
+ */
6
+ export declare function gatherGitStatus(cwd: string): Promise<GitStatus | null>;
7
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1,153 @@
1
+ import { execFile } from 'node:child_process';
2
+ const GIT_TIMEOUT = 1000; // 1s per command
3
+ function shellExec(cmd, args, cwd) {
4
+ return new Promise((resolve) => {
5
+ execFile(cmd, args, { cwd, timeout: GIT_TIMEOUT }, (err, stdout) => {
6
+ resolve(err ? '' : stdout.trim());
7
+ });
8
+ });
9
+ }
10
+ function gitExec(args, cwd) {
11
+ return shellExec('git', args, cwd);
12
+ }
13
+ /**
14
+ * Gather git status for the given working directory.
15
+ * Returns null if not in a git repo or on error.
16
+ */
17
+ export async function gatherGitStatus(cwd) {
18
+ // Check if in a git repo
19
+ const topLevel = await gitExec(['rev-parse', '--show-toplevel'], cwd);
20
+ if (!topLevel)
21
+ return null;
22
+ // Branch name
23
+ const branch = await gitExec(['rev-parse', '--abbrev-ref', 'HEAD'], cwd);
24
+ if (!branch)
25
+ return null;
26
+ // Dirty check
27
+ const statusOutput = await gitExec(['status', '--porcelain', '--no-optional-locks'], cwd);
28
+ let dirty = false;
29
+ let staged = false;
30
+ for (const line of statusOutput.split('\n')) {
31
+ if (line.length < 2)
32
+ continue;
33
+ const index = line[0];
34
+ const worktree = line[1];
35
+ // Index column: staged change (A/M/D/R/C)
36
+ if (index !== ' ' && index !== '?')
37
+ staged = true;
38
+ // Worktree column: unstaged change (M/D), or untracked (??)
39
+ if (worktree !== ' ' || index === '?')
40
+ dirty = true;
41
+ }
42
+ // Ahead/behind — detect base branch with layered fallback (ported from statusline.sh)
43
+ const baseBranch = await detectBaseBranch(branch, cwd);
44
+ let ahead = 0;
45
+ let behind = 0;
46
+ if (baseBranch) {
47
+ const revList = await gitExec(['rev-list', '--left-right', '--count', `${baseBranch}...HEAD`], cwd);
48
+ const parts = revList.split(/\s+/);
49
+ if (parts.length === 2) {
50
+ behind = parseInt(parts[0], 10) || 0;
51
+ ahead = parseInt(parts[1], 10) || 0;
52
+ }
53
+ }
54
+ // Diff stats against base
55
+ let filesChanged = 0;
56
+ let additions = 0;
57
+ let deletions = 0;
58
+ if (baseBranch) {
59
+ const diffStat = await gitExec(['diff', '--shortstat', baseBranch], cwd);
60
+ const filesMatch = diffStat.match(/(\d+)\s+file/);
61
+ const addMatch = diffStat.match(/(\d+)\s+insertion/);
62
+ const delMatch = diffStat.match(/(\d+)\s+deletion/);
63
+ filesChanged = filesMatch ? parseInt(filesMatch[1], 10) : 0;
64
+ additions = addMatch ? parseInt(addMatch[1], 10) : 0;
65
+ deletions = delMatch ? parseInt(delMatch[1], 10) : 0;
66
+ }
67
+ // Tag and worktree info (parallel)
68
+ const [tagOutput, worktreeOutput] = await Promise.all([
69
+ gitExec(['describe', '--tags', '--abbrev=0'], cwd),
70
+ gitExec(['worktree', 'list'], cwd),
71
+ ]);
72
+ const lastTag = tagOutput || null;
73
+ let commitsSinceTag = 0;
74
+ if (lastTag) {
75
+ const countOutput = await gitExec(['rev-list', `${lastTag}..HEAD`, '--count'], cwd);
76
+ commitsSinceTag = parseInt(countOutput, 10) || 0;
77
+ }
78
+ const worktreeCount = worktreeOutput
79
+ ? worktreeOutput.split('\n').filter(l => l.trim().length > 0).length
80
+ : 1;
81
+ return {
82
+ branch,
83
+ dirty,
84
+ staged,
85
+ ahead,
86
+ behind,
87
+ filesChanged,
88
+ additions,
89
+ deletions,
90
+ lastTag,
91
+ commitsSinceTag,
92
+ worktreeCount,
93
+ };
94
+ }
95
+ /**
96
+ * Detect the base branch for ahead/behind calculations.
97
+ * Uses a 4-layer fallback (ported from statusline.sh):
98
+ * 1. Branch reflog ("Created from")
99
+ * 2. HEAD reflog ("checkout: moving from X to branch")
100
+ * 3. GitHub PR base branch (gh pr view, cached)
101
+ * 4. main/master fallback
102
+ */
103
+ async function detectBaseBranch(branch, cwd) {
104
+ // Layer 1: branch reflog — look for "branch: Created from"
105
+ const branchLog = await gitExec(['reflog', 'show', branch, '--format=%gs', '-n', '1'], cwd);
106
+ const createdMatch = branchLog.match(/branch: Created from (.+)/);
107
+ if (createdMatch) {
108
+ const candidate = createdMatch[1];
109
+ if (candidate !== 'HEAD' && !candidate.includes('~')) {
110
+ const exists = await gitExec(['rev-parse', '--verify', candidate], cwd);
111
+ if (exists)
112
+ return candidate;
113
+ }
114
+ }
115
+ // Layer 2: HEAD reflog — look for "checkout: moving from X to branch"
116
+ const headLog = await gitExec(['reflog', 'show', 'HEAD', '--format=%gs'], cwd);
117
+ const escapedBranch = branch.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
118
+ const checkoutPattern = new RegExp(`checkout: moving from (\\S+) to ${escapedBranch}`);
119
+ for (const line of headLog.split('\n')) {
120
+ const match = line.match(checkoutPattern);
121
+ if (match) {
122
+ const candidate = match[1];
123
+ // Skip raw commit hashes and the current branch
124
+ if (candidate === branch || /^[0-9a-f]{7,}$/.test(candidate))
125
+ continue;
126
+ const exists = await gitExec(['rev-parse', '--verify', candidate], cwd);
127
+ if (exists)
128
+ return candidate;
129
+ }
130
+ }
131
+ // Layer 3: GitHub PR base branch via gh CLI
132
+ const prBase = await shellExec('gh', ['pr', 'view', '--json', 'baseRefName', '-q', '.baseRefName'], cwd);
133
+ if (prBase) {
134
+ const exists = await gitExec(['rev-parse', '--verify', prBase], cwd);
135
+ if (exists)
136
+ return prBase;
137
+ }
138
+ // Layer 4: main/master fallback (skip if already on that branch — use remote tracking instead)
139
+ for (const candidate of ['main', 'master']) {
140
+ if (candidate === branch) {
141
+ // On main/master itself — compare against remote tracking branch
142
+ const remote = await gitExec(['rev-parse', '--verify', `origin/${candidate}`], cwd);
143
+ if (remote)
144
+ return `origin/${candidate}`;
145
+ continue;
146
+ }
147
+ const exists = await gitExec(['rev-parse', '--verify', candidate], cwd);
148
+ if (exists)
149
+ return candidate;
150
+ }
151
+ return null;
152
+ }
153
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,81 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { homedir } from 'node:os';
4
+ import { readStdin } from './stdin.js';
5
+ import { loadConfig, resolveComponents } from './config.js';
6
+ import { gatherGitStatus } from './git.js';
7
+ import { parseTranscript } from './transcript.js';
8
+ import { fetchUsageData } from './usage-api.js';
9
+ import { gatherConfigCounts } from './components/config-counts.js';
10
+ import { render } from './render.js';
11
+ const OVERALL_TIMEOUT = 2000; // 2 second overall timeout
12
+ async function main() {
13
+ const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), OVERALL_TIMEOUT));
14
+ try {
15
+ const result = await Promise.race([run(), timeoutPromise]);
16
+ process.stdout.write(result);
17
+ }
18
+ catch {
19
+ // Timeout or error — output nothing (graceful degradation)
20
+ }
21
+ }
22
+ async function run() {
23
+ const stdin = await readStdin();
24
+ // Debug: dump raw stdin to file when DEVFLOW_HUD_DEBUG is set
25
+ if (process.env.DEVFLOW_HUD_DEBUG) {
26
+ fs.writeFileSync(process.env.DEVFLOW_HUD_DEBUG, JSON.stringify(stdin, null, 2));
27
+ }
28
+ const config = loadConfig();
29
+ const resolved = resolveComponents(config);
30
+ const components = new Set(resolved);
31
+ const cwd = stdin.cwd || process.cwd();
32
+ const devflowDir = process.env.DEVFLOW_DIR ||
33
+ path.join(process.env.HOME || homedir(), '.devflow');
34
+ // Determine what data to gather based on enabled components
35
+ const needsGit = components.has('gitBranch') ||
36
+ components.has('gitAheadBehind') ||
37
+ components.has('diffStats') ||
38
+ components.has('releaseInfo') ||
39
+ components.has('worktreeCount');
40
+ const needsTranscript = components.has('todoProgress') ||
41
+ components.has('configCounts');
42
+ const needsUsage = components.has('usageQuota');
43
+ const needsConfigCounts = components.has('configCounts');
44
+ // Parallel data gathering — only fetch what's needed
45
+ const [git, transcript, usage] = await Promise.all([
46
+ needsGit ? gatherGitStatus(cwd) : Promise.resolve(null),
47
+ needsTranscript && stdin.transcript_path
48
+ ? parseTranscript(stdin.transcript_path)
49
+ : Promise.resolve(null),
50
+ needsUsage ? fetchUsageData() : Promise.resolve(null),
51
+ ]);
52
+ // Session start time from transcript file creation time
53
+ let sessionStartTime = null;
54
+ if (stdin.transcript_path) {
55
+ try {
56
+ const stat = fs.statSync(stdin.transcript_path);
57
+ sessionStartTime = stat.birthtime.getTime();
58
+ }
59
+ catch { /* file may not exist yet */ }
60
+ }
61
+ // Config counts (fast, synchronous filesystem reads)
62
+ const configCountsData = needsConfigCounts
63
+ ? gatherConfigCounts(cwd)
64
+ : null;
65
+ // Terminal width via stderr (stdout is piped to Claude Code)
66
+ const terminalWidth = process.stderr.columns || 120;
67
+ const ctx = {
68
+ stdin,
69
+ git,
70
+ transcript,
71
+ usage,
72
+ configCounts: configCountsData,
73
+ config: { ...config, components: resolved },
74
+ devflowDir,
75
+ sessionStartTime,
76
+ terminalWidth,
77
+ };
78
+ return render(ctx);
79
+ }
80
+ main();
81
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ import type { GatherContext } from './types.js';
2
+ /**
3
+ * Render all enabled components into a multi-line HUD string.
4
+ * Components that return null are excluded. Empty lines are skipped.
5
+ */
6
+ export declare function render(ctx: GatherContext): Promise<string>;
7
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1,111 @@
1
+ import { dim } from './colors.js';
2
+ import directory from './components/directory.js';
3
+ import gitBranch from './components/git-branch.js';
4
+ import gitAheadBehind from './components/git-ahead-behind.js';
5
+ import diffStats from './components/diff-stats.js';
6
+ import model from './components/model.js';
7
+ import contextUsage from './components/context-usage.js';
8
+ import versionBadge from './components/version-badge.js';
9
+ import sessionDuration from './components/session-duration.js';
10
+ import usageQuota from './components/usage-quota.js';
11
+ import todoProgress from './components/todo-progress.js';
12
+ import configCounts from './components/config-counts.js';
13
+ import sessionCost from './components/session-cost.js';
14
+ import releaseInfo from './components/release-info.js';
15
+ import worktreeCount from './components/worktree-count.js';
16
+ const COMPONENT_MAP = {
17
+ directory,
18
+ gitBranch,
19
+ gitAheadBehind,
20
+ diffStats,
21
+ model,
22
+ contextUsage,
23
+ versionBadge,
24
+ sessionDuration,
25
+ usageQuota,
26
+ todoProgress,
27
+ configCounts,
28
+ sessionCost,
29
+ releaseInfo,
30
+ worktreeCount,
31
+ };
32
+ /**
33
+ * Line groupings for smart layout.
34
+ * Components are assigned to lines and only rendered if enabled.
35
+ * null entries denote section breaks (blank line between sections).
36
+ */
37
+ const LINE_GROUPS = [
38
+ // Section 1: Info (3 lines)
39
+ ['directory', 'gitBranch', 'gitAheadBehind', 'releaseInfo', 'worktreeCount', 'diffStats'],
40
+ ['contextUsage', 'usageQuota'],
41
+ ['model', 'sessionDuration', 'sessionCost', 'configCounts'],
42
+ // --- section break ---
43
+ null,
44
+ // Section 2: Activity
45
+ ['todoProgress'],
46
+ ['versionBadge'],
47
+ ];
48
+ const SEPARATOR = dim(' \u00B7 ');
49
+ /**
50
+ * Render all enabled components into a multi-line HUD string.
51
+ * Components that return null are excluded. Empty lines are skipped.
52
+ */
53
+ export async function render(ctx) {
54
+ const enabled = new Set(ctx.config.components);
55
+ // Render all enabled components in parallel
56
+ const results = new Map();
57
+ const promises = [];
58
+ for (const id of enabled) {
59
+ const fn = COMPONENT_MAP[id];
60
+ if (!fn)
61
+ continue;
62
+ promises.push(fn(ctx)
63
+ .then((result) => {
64
+ if (result)
65
+ results.set(id, result);
66
+ })
67
+ .catch(() => {
68
+ /* Component failure is non-fatal */
69
+ }));
70
+ }
71
+ await Promise.all(promises);
72
+ // Assemble lines using smart layout with section breaks
73
+ const lines = [];
74
+ let pendingBreak = false;
75
+ for (const entry of LINE_GROUPS) {
76
+ if (entry === null) {
77
+ if (lines.length > 0)
78
+ pendingBreak = true;
79
+ continue;
80
+ }
81
+ const lineResults = entry
82
+ .filter((id) => enabled.has(id) && results.has(id))
83
+ .map((id) => results.get(id));
84
+ if (lineResults.length > 0) {
85
+ if (pendingBreak) {
86
+ lines.push('');
87
+ pendingBreak = false;
88
+ }
89
+ // Separate multi-line results (containing newlines) from single-line
90
+ const singleLine = [];
91
+ for (const r of lineResults) {
92
+ if (r.text.includes('\n')) {
93
+ // Flush any accumulated single-line parts first
94
+ if (singleLine.length > 0) {
95
+ lines.push(singleLine.join(SEPARATOR));
96
+ singleLine.length = 0;
97
+ }
98
+ lines.push(r.text);
99
+ }
100
+ else {
101
+ singleLine.push(r.text);
102
+ }
103
+ }
104
+ if (singleLine.length > 0) {
105
+ lines.push(singleLine.join(SEPARATOR));
106
+ }
107
+ }
108
+ }
109
+ return lines.join('\n');
110
+ }
111
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1,6 @@
1
+ import type { StdinData } from './types.js';
2
+ /**
3
+ * Read and parse JSON from stdin. Returns empty object on parse failure.
4
+ */
5
+ export declare function readStdin(): Promise<StdinData>;
6
+ //# sourceMappingURL=stdin.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Read and parse JSON from stdin. Returns empty object on parse failure.
3
+ */
4
+ export function readStdin() {
5
+ return new Promise((resolve) => {
6
+ let data = '';
7
+ process.stdin.setEncoding('utf-8');
8
+ process.stdin.on('data', (chunk) => {
9
+ data += chunk;
10
+ });
11
+ process.stdin.on('end', () => {
12
+ try {
13
+ resolve(JSON.parse(data));
14
+ }
15
+ catch {
16
+ resolve({});
17
+ }
18
+ });
19
+ process.stdin.on('error', () => {
20
+ resolve({});
21
+ });
22
+ process.stdin.resume();
23
+ });
24
+ }
25
+ //# sourceMappingURL=stdin.js.map
@@ -0,0 +1,7 @@
1
+ import type { TranscriptData } from './types.js';
2
+ /**
3
+ * Parse a Claude Code session transcript (JSONL) to extract tool/agent activity and todo progress.
4
+ * Returns null if the file doesn't exist or can't be parsed.
5
+ */
6
+ export declare function parseTranscript(transcriptPath: string): Promise<TranscriptData | null>;
7
+ //# sourceMappingURL=transcript.d.ts.map