@logicseek/hello-cc 0.1.5 → 0.1.6

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 (85) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/bin/hcc.mjs +1541 -3430
  3. package/docs/README.md +2 -0
  4. package/docs/README.zh-CN.md +3 -1
  5. package/docs/architecture-split-review.md +217 -0
  6. package/docs/architecture.md +385 -0
  7. package/docs/architecture.zh-CN.md +364 -0
  8. package/docs/layout-split-stack-audit.md +298 -0
  9. package/lib/automation.mjs +8 -0
  10. package/lib/cli-args.mjs +1 -1
  11. package/lib/cli-runtime.mjs +44 -0
  12. package/lib/coordination-state.mjs +218 -0
  13. package/lib/core/coordination/automation.mjs +222 -0
  14. package/lib/core/coordination/locks.mjs +46 -0
  15. package/lib/core/coordination/messages.mjs +116 -0
  16. package/lib/core/coordination/tasks.mjs +224 -0
  17. package/lib/core/coordination/teams.mjs +73 -0
  18. package/lib/core/coordination/timeline.mjs +187 -0
  19. package/lib/core/peers/bindings.mjs +83 -0
  20. package/lib/core/peers/format.mjs +13 -0
  21. package/lib/core/peers/identity.mjs +53 -0
  22. package/lib/core/peers/liveness.mjs +90 -0
  23. package/lib/core/peers/reconcile.mjs +238 -0
  24. package/lib/core/peers/session.mjs +14 -0
  25. package/lib/core/sessions/launch.mjs +89 -0
  26. package/lib/db/schema.mjs +324 -0
  27. package/lib/db/stores/peers.mjs +231 -0
  28. package/lib/db-schema.mjs +7 -324
  29. package/lib/errors.mjs +1 -7
  30. package/lib/handoff.mjs +26 -0
  31. package/lib/help.mjs +3 -0
  32. package/lib/integrations/hooks.mjs +171 -0
  33. package/lib/integrations/peers/identity.mjs +208 -0
  34. package/lib/integrations/peers/processes.mjs +151 -0
  35. package/lib/integrations/providers.mjs +282 -0
  36. package/lib/integrations/shims/script.mjs +384 -0
  37. package/lib/integrations/shims.mjs +106 -0
  38. package/lib/json-file.mjs +1 -14
  39. package/lib/locks.mjs +10 -0
  40. package/lib/messages.mjs +3 -0
  41. package/lib/package-meta.mjs +6 -24
  42. package/lib/peer-bindings.mjs +14 -0
  43. package/lib/peer-format.mjs +4 -0
  44. package/lib/peer-identity.mjs +15 -0
  45. package/lib/project-context.mjs +6 -0
  46. package/lib/project-registry.mjs +7 -0
  47. package/lib/provider-commands.mjs +13 -0
  48. package/lib/release/package-meta.mjs +31 -0
  49. package/lib/release/release-notes.mjs +40 -0
  50. package/lib/release-notes.mjs +6 -40
  51. package/lib/runtime/client.mjs +42 -0
  52. package/lib/runtime/paths.mjs +45 -0
  53. package/lib/runtime/project-context.mjs +32 -0
  54. package/lib/runtime/projects.mjs +76 -0
  55. package/lib/runtime/state.mjs +128 -0
  56. package/lib/runtime-client.mjs +3 -0
  57. package/lib/runtime-paths.mjs +11 -45
  58. package/lib/runtime-state.mjs +11 -0
  59. package/lib/session-launch.mjs +17 -0
  60. package/lib/setup.mjs +17 -293
  61. package/lib/shared/errors.mjs +7 -0
  62. package/lib/shared/json-file.mjs +14 -0
  63. package/lib/shim-script.mjs +1 -384
  64. package/lib/state-render.mjs +5 -0
  65. package/lib/task-cli.mjs +45 -0
  66. package/lib/task-liveness.mjs +8 -0
  67. package/lib/task-store.mjs +3 -0
  68. package/lib/team-planning.mjs +7 -0
  69. package/lib/terminal/tmux.mjs +372 -0
  70. package/lib/timeline.mjs +12 -0
  71. package/lib/tmux.mjs +18 -0
  72. package/lib/ui/help.mjs +419 -0
  73. package/lib/ui/state-render.mjs +61 -0
  74. package/lib/web/http.mjs +55 -0
  75. package/lib/web/peer-actions.mjs +270 -0
  76. package/lib/web/runtime.mjs +154 -0
  77. package/lib/web/ui-template.mjs +2055 -0
  78. package/lib/web-http.mjs +7 -55
  79. package/lib/web-peer-actions.mjs +3 -0
  80. package/lib/web-runtime.mjs +17 -108
  81. package/lib/web-ui-template.mjs +3 -1909
  82. package/package.json +1 -1
  83. package/scripts/github-release.mjs +2 -2
  84. package/scripts/regression.mjs +2468 -17
  85. package/scripts/release-notes.mjs +2 -2
package/lib/setup.mjs CHANGED
@@ -1,295 +1,19 @@
1
1
  /**
2
- * Hooks and shim installation for zero-config Claude Code / Codex integration.
3
- *
4
- * Claude Code hooks → ~/.claude/settings.json
5
- * Shim scripts → ~/.hcc-shims/{claude,codex}
6
- * PATH entry → ~/.bashrc or ~/.zshrc
7
- */
8
-
9
- import fs from 'node:fs';
10
- import path from 'node:path';
11
- import os from 'node:os';
12
- import { spawnSync } from 'node:child_process';
13
- import { readJsonSafe, writeJsonSafe } from './json-file.mjs';
14
- import { generateShim } from './shim-script.mjs';
2
+ * Compatibility entrypoint for zero-config Claude Code / Codex integration.
3
+ */
4
+ export {
5
+ installClaudeHooks,
6
+ installCodexHooks,
7
+ uninstallClaudeHooks,
8
+ uninstallCodexHooks,
9
+ verifyClaudeHooks,
10
+ verifyCodexHooks
11
+ } from './integrations/hooks.mjs';
12
+ export {
13
+ findRealBinary,
14
+ installShims,
15
+ SHIM_DIR,
16
+ uninstallShims,
17
+ verifyShims
18
+ } from './integrations/shims.mjs';
15
19
  export { installPathEntry, uninstallPathEntry } from './shell-path.mjs';
16
-
17
- export const SHIM_DIR = path.join(os.homedir(), '.hcc-shims');
18
-
19
- // ─── Claude Code hooks ────────────────────────────────────────────────────────
20
-
21
- const CLAUDE_SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
22
-
23
- /**
24
- * Hook events we install handlers for.
25
- * - SessionStart : Inject initial coordination context
26
- * - UserPromptSubmit : Inject fresh coordination context before the model answers
27
- * - Stop : Claude goes idle after a turn → deliver inbox messages
28
- * - PostToolUse : After every tool call → heartbeat + inbox check
29
- * - PreToolUse : Before every tool call → register peer if not yet registered
30
- */
31
- const HOOK_EVENTS = ['SessionStart', 'UserPromptSubmit', 'Stop', 'PostToolUse', 'PreToolUse'];
32
-
33
- /**
34
- * Install (or update) hello-cc hooks in ~/.claude/settings.json.
35
- * Non-destructive: only adds hcc entries, never removes existing ones.
36
- * Returns the settings file path.
37
- */
38
- export function installClaudeHooks(hccBin) {
39
- const settings = readJsonSafe(CLAUDE_SETTINGS_PATH) || {};
40
-
41
- if (!settings.hooks) settings.hooks = {};
42
-
43
- const hookCmd = `${hccBin} hook`;
44
-
45
- for (const event of HOOK_EVENTS) {
46
- settings.hooks[event] = mergeHookEntry(
47
- settings.hooks[event],
48
- `${hookCmd} ${event.toLowerCase()}`
49
- );
50
- }
51
-
52
- writeJsonSafe(CLAUDE_SETTINGS_PATH, settings);
53
- return CLAUDE_SETTINGS_PATH;
54
- }
55
-
56
- /**
57
- * Remove hello-cc hook entries from ~/.claude/settings.json.
58
- */
59
- export function uninstallClaudeHooks() {
60
- const settings = readJsonSafe(CLAUDE_SETTINGS_PATH);
61
- if (!settings?.hooks) return false;
62
-
63
- for (const event of Object.keys(settings.hooks)) {
64
- if (!Array.isArray(settings.hooks[event])) continue;
65
- settings.hooks[event] = settings.hooks[event].filter(entry => {
66
- if (!Array.isArray(entry?.hooks)) return true;
67
- return !entry.hooks.some(h => isHccHookCmd(h?.command));
68
- });
69
- if (settings.hooks[event].length === 0) delete settings.hooks[event];
70
- }
71
-
72
- writeJsonSafe(CLAUDE_SETTINGS_PATH, settings);
73
- return true;
74
- }
75
-
76
- /**
77
- * Returns true if hello-cc hooks are present in ~/.claude/settings.json.
78
- */
79
- export function verifyClaudeHooks() {
80
- const settings = readJsonSafe(CLAUDE_SETTINGS_PATH);
81
- if (!settings?.hooks) return false;
82
- return HOOK_EVENTS.every(event => hasHookEntry(settings.hooks[event]));
83
- }
84
-
85
- // Append a hook entry, skipping if one already exists for hcc.
86
- function mergeHookEntry(existing, command) {
87
- const entries = Array.isArray(existing) ? [...existing] : [];
88
- const alreadyInstalled = entries.some(
89
- e => Array.isArray(e?.hooks) && e.hooks.some(h => isHccHookCmd(h?.command))
90
- );
91
- if (alreadyInstalled) return entries;
92
- entries.push({ hooks: [{ type: 'command', command }] });
93
- return entries;
94
- }
95
-
96
- function hasHookEntry(entries) {
97
- if (!Array.isArray(entries)) return false;
98
- return entries.some(e =>
99
- Array.isArray(e?.hooks) && e.hooks.some(h => isHccHookCmd(h?.command))
100
- );
101
- }
102
-
103
- function isHccHookCmd(cmd) {
104
- if (typeof cmd !== 'string') return false;
105
- return /\bhcc\b.*\bhook\b/.test(cmd) || /hello-cc.*hook/.test(cmd);
106
- }
107
-
108
- // ─── Shim scripts ─────────────────────────────────────────────────────────────
109
-
110
- /**
111
- * Install shim scripts for `claude` and `codex` into SHIM_DIR.
112
- * Returns { shimDir, installed: [paths], changed: [paths], skipped: [names] }.
113
- */
114
- export function installShims(hccBin) {
115
- fs.mkdirSync(SHIM_DIR, { recursive: true });
116
-
117
- const tools = [
118
- { name: 'claude', kind: 'claude', resumeFlag: '--resume' },
119
- { name: 'codex', kind: 'codex', resumeSubcmd: 'resume' },
120
- ];
121
-
122
- const installed = [];
123
- const changed = [];
124
- const skipped = [];
125
-
126
- for (const tool of tools) {
127
- const realBin = findRealBinary(tool.name);
128
- if (!realBin) {
129
- skipped.push(`${tool.name} (not found on PATH)`);
130
- continue;
131
- }
132
- const shimPath = path.join(SHIM_DIR, tool.name);
133
- const content = generateShim(hccBin, realBin, tool);
134
- let previous = null;
135
- try { previous = fs.readFileSync(shimPath, 'utf8'); } catch {}
136
- if (previous !== content) {
137
- fs.writeFileSync(shimPath, content, { mode: 0o755 });
138
- changed.push(shimPath);
139
- } else {
140
- try { fs.chmodSync(shimPath, 0o755); } catch {}
141
- }
142
- installed.push(shimPath);
143
- }
144
-
145
- return { shimDir: SHIM_DIR, installed, changed, skipped };
146
- }
147
-
148
- /**
149
- * Remove shim scripts.
150
- */
151
- export function uninstallShims() {
152
- const removed = [];
153
- for (const name of ['claude', 'codex']) {
154
- const p = path.join(SHIM_DIR, name);
155
- try { fs.unlinkSync(p); removed.push(p); } catch {}
156
- }
157
- try { fs.rmdirSync(SHIM_DIR); } catch {}
158
- return removed;
159
- }
160
-
161
- /**
162
- * Returns true if at least one shim is installed and in an HCC shim dir.
163
- */
164
- export function verifyShims() {
165
- return ['claude', 'codex'].some(name =>
166
- fsExists(path.join(SHIM_DIR, name))
167
- );
168
- }
169
-
170
- /**
171
- * Find the real binary for `name`, skipping the SHIM_DIR.
172
- * Checks PATH, then npm global bin, then common install locations.
173
- */
174
- export function findRealBinary(name) {
175
- // which -a lists all matches; pick first one outside SHIM_DIR
176
- const r = spawnSync('which', ['-a', name], { encoding: 'utf8', timeout: 3000 });
177
- if (r.status === 0) {
178
- for (const p of r.stdout.trim().split('\n')) {
179
- const resolved = p.trim();
180
- if (resolved && !resolved.startsWith(SHIM_DIR)) return resolved;
181
- }
182
- }
183
-
184
- // Try npm global bin
185
- const npmR = spawnSync('npm', ['root', '-g'], { encoding: 'utf8', timeout: 3000 });
186
- if (npmR.status === 0) {
187
- const npmBin = path.join(path.dirname(npmR.stdout.trim()), 'bin', name);
188
- if (fsExists(npmBin)) return npmBin;
189
- }
190
-
191
- // Common locations
192
- for (const dir of [
193
- '/usr/local/bin',
194
- '/usr/bin',
195
- path.join(os.homedir(), '.local', 'bin'),
196
- path.join(os.homedir(), '.nvm', 'current', 'bin'),
197
- ]) {
198
- const p = path.join(dir, name);
199
- if (fsExists(p)) return p;
200
- }
201
-
202
- return null;
203
- }
204
-
205
- // ─── Codex hooks ─────────────────────────────────────────────────────────────
206
-
207
- const CODEX_HOOKS_PATH = path.join(os.homedir(), '.codex', 'hooks.json');
208
-
209
- /**
210
- * Install hello-cc hooks in ~/.codex/hooks.json.
211
- *
212
- * Codex hooks.json format:
213
- * { "hooks": { "PreToolUse": [{ "matcher": "Bash", "hooks": [...] }], "Stop": [...] } }
214
- */
215
- export function installCodexHooks(hccBin) {
216
- const hooks = readJsonSafe(CODEX_HOOKS_PATH) || {};
217
-
218
- if (!hooks.hooks) hooks.hooks = {};
219
-
220
- const hookCmd = `${hccBin} hook`;
221
-
222
- // SessionStart: inject initial coordination context on startup/resume.
223
- hooks.hooks.SessionStart = mergeCodexHookEntry(
224
- hooks.hooks.SessionStart,
225
- `${hookCmd} sessionstart`,
226
- null
227
- );
228
- // UserPromptSubmit: inject fresh coordination context before each model turn.
229
- hooks.hooks.UserPromptSubmit = mergeCodexHookEntry(
230
- hooks.hooks.UserPromptSubmit,
231
- `${hookCmd} userpromptsubmit`,
232
- null
233
- );
234
- // PreToolUse: fires before every Bash tool call — heartbeat + peer registration
235
- hooks.hooks.PreToolUse = mergeCodexHookEntry(
236
- hooks.hooks.PreToolUse,
237
- `${hookCmd} pretooluse`,
238
- 'Bash'
239
- );
240
- // Stop: fires when Codex goes idle — deliver inbox messages
241
- hooks.hooks.Stop = mergeCodexHookEntry(
242
- hooks.hooks.Stop,
243
- `${hookCmd} stop`,
244
- null
245
- );
246
-
247
- writeJsonSafe(CODEX_HOOKS_PATH, hooks);
248
- return CODEX_HOOKS_PATH;
249
- }
250
-
251
- export function uninstallCodexHooks() {
252
- const hooks = readJsonSafe(CODEX_HOOKS_PATH);
253
- if (!hooks?.hooks) return false;
254
-
255
- for (const event of Object.keys(hooks.hooks)) {
256
- if (!Array.isArray(hooks.hooks[event])) continue;
257
- hooks.hooks[event] = hooks.hooks[event].filter(entry => {
258
- if (!Array.isArray(entry?.hooks)) return true;
259
- return !entry.hooks.some(h => isHccHookCmd(h?.command));
260
- });
261
- if (hooks.hooks[event].length === 0) delete hooks.hooks[event];
262
- }
263
-
264
- writeJsonSafe(CODEX_HOOKS_PATH, hooks);
265
- return true;
266
- }
267
-
268
- export function verifyCodexHooks() {
269
- const hooks = readJsonSafe(CODEX_HOOKS_PATH);
270
- if (!hooks?.hooks) return false;
271
- return ['SessionStart', 'UserPromptSubmit', 'PreToolUse', 'Stop'].every(event =>
272
- hasHookEntry(hooks.hooks[event])
273
- );
274
- }
275
-
276
- function mergeCodexHookEntry(existing, command, matcher) {
277
- const entries = Array.isArray(existing) ? [...existing] : [];
278
- const alreadyInstalled = entries.some(
279
- e => Array.isArray(e?.hooks) && e.hooks.some(h => isHccHookCmd(h?.command))
280
- );
281
- if (alreadyInstalled) return entries;
282
-
283
- const entry = {
284
- hooks: [{ type: 'command', command }],
285
- };
286
- if (matcher) entry.matcher = matcher;
287
- entries.push(entry);
288
- return entries;
289
- }
290
-
291
- // ─── Utilities ────────────────────────────────────────────────────────────────
292
-
293
- function fsExists(p) {
294
- try { fs.accessSync(p); return true; } catch { return false; }
295
- }
@@ -0,0 +1,7 @@
1
+ export class CliError extends Error {
2
+ constructor(code, message, extra = {}) {
3
+ super(message);
4
+ this.code = code;
5
+ this.extra = extra;
6
+ }
7
+ }
@@ -0,0 +1,14 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ export function readJsonSafe(filePath) {
5
+ try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }
6
+ catch { return null; }
7
+ }
8
+
9
+ export function writeJsonSafe(filePath, data) {
10
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
11
+ const tmpPath = filePath + '.tmp.' + process.pid;
12
+ fs.writeFileSync(tmpPath, JSON.stringify(data, null, 2) + '\n');
13
+ fs.renameSync(tmpPath, filePath);
14
+ }