@logicseek/hello-cc 0.1.4 → 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 (90) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/bin/hcc.mjs +2739 -6482
  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/commands.md +21 -9
  9. package/docs/commands.zh-CN.md +19 -9
  10. package/docs/layout-split-stack-audit.md +298 -0
  11. package/lib/automation.mjs +8 -0
  12. package/lib/cli-args.mjs +89 -0
  13. package/lib/cli-runtime.mjs +44 -0
  14. package/lib/coordination-state.mjs +218 -0
  15. package/lib/core/coordination/automation.mjs +222 -0
  16. package/lib/core/coordination/locks.mjs +46 -0
  17. package/lib/core/coordination/messages.mjs +116 -0
  18. package/lib/core/coordination/tasks.mjs +224 -0
  19. package/lib/core/coordination/teams.mjs +73 -0
  20. package/lib/core/coordination/timeline.mjs +187 -0
  21. package/lib/core/peers/bindings.mjs +83 -0
  22. package/lib/core/peers/format.mjs +13 -0
  23. package/lib/core/peers/identity.mjs +53 -0
  24. package/lib/core/peers/liveness.mjs +90 -0
  25. package/lib/core/peers/reconcile.mjs +238 -0
  26. package/lib/core/peers/session.mjs +14 -0
  27. package/lib/core/sessions/launch.mjs +89 -0
  28. package/lib/db/schema.mjs +324 -0
  29. package/lib/db/stores/peers.mjs +231 -0
  30. package/lib/db-schema.mjs +7 -0
  31. package/lib/errors.mjs +1 -0
  32. package/lib/format.mjs +39 -0
  33. package/lib/guidance.mjs +10 -2
  34. package/lib/handoff.mjs +26 -0
  35. package/lib/help.mjs +3 -0
  36. package/lib/integrations/hooks.mjs +171 -0
  37. package/lib/integrations/peers/identity.mjs +208 -0
  38. package/lib/integrations/peers/processes.mjs +151 -0
  39. package/lib/integrations/providers.mjs +282 -0
  40. package/lib/integrations/shims/script.mjs +384 -0
  41. package/lib/integrations/shims.mjs +106 -0
  42. package/lib/json-file.mjs +1 -0
  43. package/lib/locks.mjs +10 -0
  44. package/lib/messages.mjs +3 -0
  45. package/lib/package-meta.mjs +6 -24
  46. package/lib/peer-bindings.mjs +14 -0
  47. package/lib/peer-format.mjs +4 -0
  48. package/lib/peer-identity.mjs +15 -0
  49. package/lib/project-context.mjs +6 -0
  50. package/lib/project-registry.mjs +7 -0
  51. package/lib/provider-commands.mjs +13 -0
  52. package/lib/release/package-meta.mjs +31 -0
  53. package/lib/release/release-notes.mjs +40 -0
  54. package/lib/release-notes.mjs +6 -40
  55. package/lib/runtime/client.mjs +42 -0
  56. package/lib/runtime/paths.mjs +45 -0
  57. package/lib/runtime/project-context.mjs +32 -0
  58. package/lib/runtime/projects.mjs +76 -0
  59. package/lib/runtime/state.mjs +128 -0
  60. package/lib/runtime-client.mjs +3 -0
  61. package/lib/runtime-paths.mjs +11 -0
  62. package/lib/runtime-state.mjs +11 -0
  63. package/lib/session-launch.mjs +17 -0
  64. package/lib/setup.mjs +18 -765
  65. package/lib/shared/errors.mjs +7 -0
  66. package/lib/shared/json-file.mjs +14 -0
  67. package/lib/shell-path.mjs +69 -0
  68. package/lib/shim-script.mjs +1 -0
  69. package/lib/state-render.mjs +5 -0
  70. package/lib/task-cli.mjs +45 -0
  71. package/lib/task-liveness.mjs +8 -0
  72. package/lib/task-store.mjs +3 -0
  73. package/lib/team-planning.mjs +7 -0
  74. package/lib/terminal/tmux.mjs +372 -0
  75. package/lib/timeline.mjs +12 -0
  76. package/lib/tmux.mjs +18 -0
  77. package/lib/ui/help.mjs +419 -0
  78. package/lib/ui/state-render.mjs +61 -0
  79. package/lib/web/http.mjs +55 -0
  80. package/lib/web/peer-actions.mjs +270 -0
  81. package/lib/web/runtime.mjs +154 -0
  82. package/lib/web/ui-template.mjs +2055 -0
  83. package/lib/web-http.mjs +7 -0
  84. package/lib/web-peer-actions.mjs +3 -0
  85. package/lib/web-runtime.mjs +17 -0
  86. package/lib/web-ui-template.mjs +3 -0
  87. package/package.json +1 -1
  88. package/scripts/github-release.mjs +2 -2
  89. package/scripts/regression.mjs +2738 -22
  90. package/scripts/release-notes.mjs +2 -2
package/docs/README.md CHANGED
@@ -22,3 +22,5 @@ summary and first command. Use these docs when you need more detail.
22
22
  levels, coordination semantics, and provider-session binding.
23
23
  - [Implementation Notes](implementation.md): architecture, protocol, command
24
24
  surface, stack, shim behavior, and implementation plan.
25
+ - [Architecture](architecture.md): target project layout, module boundaries,
26
+ dependency direction, and staged migration plan.
@@ -20,5 +20,7 @@
20
20
  - [设计说明](design.md):产品边界、项目边界、能力层级、协作语义和 provider
21
21
  session 绑定。
22
22
  - [实现说明](implementation.md):架构、协议、命令面、技术栈、shim 行为和实现计划。
23
+ - [架构设计](architecture.zh-CN.md):目标目录结构、模块边界、依赖方向和分阶段
24
+ 迁移计划。
23
25
 
24
- 设计和实现文档目前只有英文版。
26
+ `design.md` 和 `implementation.md` 目前只有英文版。
@@ -0,0 +1,217 @@
1
+ # Architecture Split Review
2
+
3
+ Date: 2026-06-14
4
+
5
+ This review covers the local commits on `master` that are ahead of
6
+ `origin/master` after `0.1.5`.
7
+
8
+ It is written from the separate review branch
9
+ `arch-review/split-layout-from-origin`. The main worktree is intentionally left
10
+ untouched because other peers may still be finishing scoped implementation work.
11
+
12
+ ## Recommendation
13
+
14
+ Keep the current architecture direction. Do not merge the new product-boundary
15
+ modules back into `bin/hcc.mjs`, and do not collapse them into another large
16
+ generic helper file.
17
+
18
+ If the goal is to publish or synchronize soon, keep the current local commit
19
+ history and add one or more cleanup commits. Those cleanup commits should focus
20
+ on remaining boundary issues and compatibility-shim policy.
21
+
22
+ If the goal is clean commit history, rebuild the stack in a separate worktree
23
+ from `origin/master`. Do not rewrite the active `master` worktree while peers
24
+ are coordinating through it.
25
+
26
+ ## What Happened
27
+
28
+ The first local split commits were mostly flat helper extraction from
29
+ `bin/hcc.mjs` into top-level `lib/*.mjs` files. They reduced the entrypoint size
30
+ but did not yet express the product architecture:
31
+
32
+ - provider and tmux helpers
33
+ - lock and team planning helpers
34
+ - peer identity, peer format, and peer binding helpers
35
+ - project registry and project context helpers
36
+ - handoff, timeline, runtime state, task liveness, automation, and render helpers
37
+ - help text, message store, runtime request, task store, task CLI, and
38
+ coordination-state helpers
39
+
40
+ Later commits introduced `docs/architecture.md` and started moving primary
41
+ implementations into product boundaries:
42
+
43
+ - `lib/core/coordination`
44
+ - `lib/core/peers`
45
+ - `lib/core/sessions`
46
+ - `lib/db`
47
+ - `lib/db/stores`
48
+ - `lib/runtime`
49
+ - `lib/terminal`
50
+ - `lib/web`
51
+ - `lib/integrations`
52
+ - `lib/release`
53
+ - `lib/shared`
54
+ - `lib/ui`
55
+
56
+ That second phase is the correct direction.
57
+
58
+ ## Keep
59
+
60
+ These boundaries are worth keeping as the primary implementation shape:
61
+
62
+ - `lib/core/coordination/*` for product coordination semantics.
63
+ - `lib/core/peers/*` for pure peer semantics.
64
+ - `lib/db/schema.mjs` and `lib/db/stores/*` for SQLite schema and stores.
65
+ - `lib/runtime/*` for runtime files, runtime client access, project registry,
66
+ and project context.
67
+ - `lib/terminal/tmux.mjs` for tmux adapter behavior.
68
+ - `lib/web/*` for Web runtime, HTTP helpers, peer actions, and UI template.
69
+ - `lib/integrations/*` for provider, hook, shim, and process integration
70
+ details.
71
+ - `lib/release/*` for release metadata and release-note logic.
72
+ - `lib/shared/*` only for small dependency-light utilities.
73
+ - `lib/ui/*` for text/help/state rendering.
74
+
75
+ ## Cleanup Candidates
76
+
77
+ The remaining cleanup should be deliberate, not another broad helper extraction.
78
+
79
+ ### Top-Level Compatibility Shims
80
+
81
+ Many top-level `lib/*.mjs` files are now compatibility re-export shims. Examples
82
+ include `lib/tmux.mjs`, `lib/provider-commands.mjs`, `lib/web-runtime.mjs`,
83
+ `lib/web-http.mjs`, `lib/web-ui-template.mjs`, `lib/task-store.mjs`,
84
+ `lib/messages.mjs`, `lib/locks.mjs`, `lib/db-schema.mjs`, and
85
+ `lib/session-launch.mjs`.
86
+
87
+ Before publish:
88
+
89
+ - Treat the installed CLI commands as the public API. Do not document new
90
+ `@logicseek/hello-cc/lib/*` imports as user-facing API.
91
+ - `@logicseek/hello-cc@0.1.5` is already published from git head `4969100`, and
92
+ that package exposed several top-level `lib/*.mjs` helper paths because the
93
+ package includes `lib/` and has no `exports` map.
94
+ - Keep already-published top-level `lib/*.mjs` paths as compatibility
95
+ re-exports for at least one release cycle unless the project explicitly
96
+ chooses a breaking package-surface change.
97
+ - For compatibility shims added only in local commits after `0.1.5`, either
98
+ remove them before the next publish or document them in the release notes as
99
+ compatibility-only and revisit removal before the following release.
100
+ - Do not let compatibility shims become the target architecture. Primary
101
+ implementations should live under the product-boundary directories.
102
+
103
+ Classify top-level shims before release:
104
+
105
+ - Group A: already-published or CLI-facing helper paths that stay stable for
106
+ this release.
107
+ - Group B: migration compatibility paths that re-export moved implementations;
108
+ keep only if needed and describe them as compatibility-only deep-import paths.
109
+ - Group C: unpublished shims with no internal use and no compatibility value;
110
+ remove before publishing.
111
+
112
+ ### CLI Boundary
113
+
114
+ `bin/hcc.mjs` is smaller but still mixes command dispatch, command handlers, Web
115
+ startup, session lifecycle, and terminal/Web orchestration. Future work should
116
+ move by command or subsystem boundary, not by helper name.
117
+
118
+ Good next boundaries:
119
+
120
+ - `lib/cli/args.mjs`
121
+ - `lib/cli/context.mjs`
122
+ - `lib/cli/dispatch.mjs`
123
+ - `lib/cli/commands/*`
124
+
125
+ ### Regression Runner
126
+
127
+ `scripts/regression.mjs` has grown too large. It should become a runner over
128
+ domain-specific files:
129
+
130
+ - `scripts/regression/cli.mjs`
131
+ - `scripts/regression/db.mjs`
132
+ - `scripts/regression/runtime.mjs`
133
+ - `scripts/regression/web.mjs`
134
+ - `scripts/regression/integrations.mjs`
135
+ - `scripts/regression/release.mjs`
136
+
137
+ This should be done after the current layout work is stable, because regression
138
+ coverage is the safety net for the refactor.
139
+
140
+ ### Setup, Discover, Guidance, and Shims
141
+
142
+ `lib/setup.mjs`, `lib/discover.mjs`, `lib/guidance.mjs`, and
143
+ `lib/shim-script.mjs` still carry mixed responsibilities. Continue splitting
144
+ these by product boundary:
145
+
146
+ - hooks under `lib/integrations/hooks*`
147
+ - shims under `lib/integrations/shims*`
148
+ - shell and terminal adapters under `lib/terminal`
149
+ - runtime/project concerns under `lib/runtime`
150
+ - guidance text generation under `lib/ui` or a dedicated guidance boundary
151
+
152
+ ### Handoff Boundary
153
+
154
+ `lib/handoff.mjs` is still a top-level helper. Decide whether it belongs in
155
+ `lib/core/coordination/handoff.mjs` as product semantics or under
156
+ `lib/cli/commands/handoff.mjs` if it is mostly CLI formatting and file listing.
157
+
158
+ ## Branch Strategy
159
+
160
+ Use one of two paths.
161
+
162
+ Path A: publish-oriented cleanup
163
+
164
+ 1. Keep current `master` history.
165
+ 2. Add focused cleanup commits.
166
+ 3. Run full regression, release checks, GitHub release dry-run, and pack dry-run.
167
+ 4. Publish/synchronize only after the cleanup decision is complete.
168
+
169
+ Path B: clean-history rebuild
170
+
171
+ 1. Keep `master` untouched.
172
+ 2. Use a separate worktree from `origin/master`.
173
+ 3. Rebuild the split as fewer architectural commits:
174
+ - architecture docs
175
+ - core coordination and peer semantics
176
+ - db schema/stores
177
+ - runtime/project/session helpers
178
+ - terminal adapters
179
+ - web runtime and UI
180
+ - integrations providers/hooks/shims
181
+ - release/shared/ui helpers
182
+ - regression restructuring
183
+ 4. Run full regression and release checks before replacing the active stack.
184
+
185
+ ## Current Decision
186
+
187
+ The safer default is Path A: keep current history and add cleanup commits.
188
+
189
+ Choose Path B only if the project explicitly values a clean local commit stack
190
+ more than the time and risk of rebuilding and revalidating the entire series.
191
+
192
+ The current safety refs are:
193
+
194
+ - `safety/layout-split-20260614-at-ffc42a7`, protecting the earlier split stack.
195
+ - `safety/layout-split-20260614-at-11fd4f6`, protecting the split stack through
196
+ `11fd4f6` before this package-surface policy update.
197
+
198
+ Because `0.1.5` is already on npm, the next publish that includes the current
199
+ local commits must bump the package version. Do not republish `0.1.5`.
200
+
201
+ ## Coordination Notes
202
+
203
+ Continue finishing any already-started layout lanes that are clearly correcting
204
+ the architecture boundary. For example, moving setup hooks and shim
205
+ implementation into `lib/integrations` is still part of the same boundary
206
+ cleanup, not a new random helper extraction.
207
+
208
+ After those active lanes finish, pause new implementation splits and make a
209
+ cleanup decision:
210
+
211
+ 1. Decide whether this review document should be copied into `master` as a
212
+ durable design record.
213
+ 2. Decide whether top-level compatibility shims are public for this release.
214
+ 3. If shims are kept, document that they are compatibility paths.
215
+ 4. If shims are removed, do it before publish and run full pack/release checks.
216
+ 5. Do not start broad `bin/hcc.mjs` command extraction or regression runner
217
+ splitting until the shim policy is settled.
@@ -0,0 +1,385 @@
1
+ # hello-cc Architecture
2
+
3
+ Date: 2026-06-14
4
+
5
+ This document defines the intended module layout for hello-cc. It is a design
6
+ target for future refactors, not a claim that every file already follows this
7
+ layout.
8
+
9
+ The goal is to stop splitting code by helper size and start moving code by
10
+ product boundary. A thin CLI, explicit core state model, dedicated runtime
11
+ layer, terminal adapters, and Web server boundary make future changes easier to
12
+ review and less likely to mix unrelated behavior.
13
+
14
+ ## Reference Shape
15
+
16
+ The target shape follows the same broad separation used by mature agent CLI
17
+ projects:
18
+
19
+ - entrypoints stay small and delegate to command or server packages;
20
+ - core coordination logic is independent from HTTP, tmux, and process launch;
21
+ - runtime files and runtime clients live outside the command handlers;
22
+ - Web server routes, WebSocket transport, and session lifecycle are explicit
23
+ server modules;
24
+ - provider-specific behavior is isolated from generic session and task logic;
25
+ - tests are grouped by domain instead of appended to one large script forever.
26
+
27
+ In particular, Codex-style layouts separate `cli`, `core`, `app-server`,
28
+ `protocol` or transport, state stores, hooks, config, and execution adapters.
29
+ hello-cc does not need Rust crates or the same scale, but it should use the same
30
+ architectural idea: split by boundary, not by convenience.
31
+
32
+ ## Current Pressure Points
33
+
34
+ The codebase has already extracted many focused modules under `lib/`, including
35
+ schema, runtime state, task/message stores, peer identity, provider command
36
+ building, tmux helpers, Web HTTP helpers, and render helpers.
37
+
38
+ The remaining structural pressure is mostly:
39
+
40
+ - `bin/hcc.mjs` still contains command dispatch, command handlers, Web server
41
+ setup, HTTP routes, WebSocket terminal handling, tmux session management, PTY
42
+ session management, external buffer adoption, and shutdown cleanup.
43
+ - `cmdWeb()` is the largest mixed boundary. It should be treated as a Web
44
+ runtime subsystem, not as a normal CLI command body.
45
+ - `scripts/regression.mjs` is a valuable full regression gate, but it should
46
+ eventually become a runner over domain-specific regression modules.
47
+
48
+ ## Target Layout
49
+
50
+ ```text
51
+ bin/
52
+ hcc.mjs
53
+
54
+ lib/
55
+ cli/
56
+ dispatch.mjs
57
+ context.mjs
58
+ commands/
59
+ ask.mjs
60
+ broadcast.mjs
61
+ down.mjs
62
+ event.mjs
63
+ gc.mjs
64
+ handoff.mjs
65
+ hooks.mjs
66
+ init.mjs
67
+ inject.mjs
68
+ join.mjs
69
+ lock.mjs
70
+ msg.mjs
71
+ peer.mjs
72
+ prompt.mjs
73
+ run.mjs
74
+ scan.mjs
75
+ setup.mjs
76
+ shim.mjs
77
+ state.mjs
78
+ status.mjs
79
+ task.mjs
80
+ team.mjs
81
+ uninstall.mjs
82
+ update.mjs
83
+ up.mjs
84
+ web.mjs
85
+
86
+ core/
87
+ coordination/
88
+ automation.mjs
89
+ handoff.mjs
90
+ locks.mjs
91
+ messages.mjs
92
+ tasks.mjs
93
+ teams.mjs
94
+ timeline.mjs
95
+ peers/
96
+ bindings.mjs
97
+ format.mjs
98
+ identity.mjs
99
+ liveness.mjs
100
+ sessions/
101
+ launch.mjs
102
+ model.mjs
103
+ providers.mjs
104
+ serialization.mjs
105
+
106
+ db/
107
+ connection.mjs
108
+ migrations.mjs
109
+ schema.mjs
110
+ stores/
111
+ locks.mjs
112
+ messages.mjs
113
+ peers.mjs
114
+ tasks.mjs
115
+
116
+ runtime/
117
+ client.mjs
118
+ paths.mjs
119
+ projects.mjs
120
+ state.mjs
121
+
122
+ terminal/
123
+ external-buffer.mjs
124
+ pty.mjs
125
+ tmux-stream.mjs
126
+ tmux.mjs
127
+
128
+ web/
129
+ projects.mjs
130
+ routes.mjs
131
+ server.mjs
132
+ session-manager.mjs
133
+ websocket.mjs
134
+ http.mjs
135
+ ui-template.mjs
136
+
137
+ integrations/
138
+ hooks/
139
+ claude.mjs
140
+ codex.mjs
141
+ providers/
142
+ claude.mjs
143
+ codex.mjs
144
+ shell.mjs
145
+ shims/
146
+ setup.mjs
147
+ script.mjs
148
+
149
+ ui/
150
+ format.mjs
151
+ help.mjs
152
+ state-render.mjs
153
+
154
+ release/
155
+ package-meta.mjs
156
+ release-notes.mjs
157
+
158
+ shared/
159
+ errors.mjs
160
+ json-file.mjs
161
+ text.mjs
162
+
163
+ scripts/
164
+ regression.mjs
165
+ regression/
166
+ cli.mjs
167
+ coordination.mjs
168
+ db.mjs
169
+ release.mjs
170
+ runtime.mjs
171
+ sessions.mjs
172
+ web.mjs
173
+ ```
174
+
175
+ ## Boundary Rules
176
+
177
+ `bin/hcc.mjs` should become a thin entrypoint. It may parse global arguments,
178
+ create the root context, invoke dispatch, and convert top-level errors to CLI
179
+ output. It should not own Web routing, DB schema, tmux streaming, provider
180
+ command construction, or task state machines.
181
+
182
+ `lib/cli/` owns command parsing and command handlers. A command handler can
183
+ open a database, call stores or core services, and print results. It should not
184
+ contain reusable domain logic when that logic can live in `core`, `runtime`,
185
+ `terminal`, `web`, or `integrations`.
186
+
187
+ `lib/core/` owns product semantics. Task lifecycle, takeover readiness, message
188
+ threading, lock conflict rules, team planning, peer identity semantics, and
189
+ session identity rules belong here. Core modules should not depend on HTTP
190
+ request objects, WebSocket objects, tmux commands, or process spawning.
191
+
192
+ `lib/db/` owns SQLite connection, schema, migrations, and data stores. Store
193
+ modules should expose explicit operations and transaction boundaries. Schema
194
+ migrations must be safe to run for every registered project database, not just
195
+ the current project.
196
+
197
+ `lib/runtime/` owns runtime files, runtime discovery, runtime client requests,
198
+ and project registry state. It should not know how Web routes render UI or how
199
+ terminal bytes are transported.
200
+
201
+ `lib/terminal/` owns terminal adapters. tmux pane inspection, tmux stream setup,
202
+ tmux input, PTY spawning, and external buffer adoption belong here. Terminal
203
+ adapters can emit session events, but they should not decide task ownership or
204
+ message behavior.
205
+
206
+ `lib/web/` owns the Web runtime. It should assemble project context, session
207
+ manager, HTTP routes, WebSocket terminal upgrade, and shutdown cleanup. Route
208
+ handlers should be small and delegate to stores, core services, runtime
209
+ modules, or terminal/session manager methods.
210
+
211
+ `lib/integrations/` owns provider-specific behavior. Claude, Codex, and shell
212
+ command construction, hook installation details, and shim scripts should stay
213
+ out of generic session and coordination modules.
214
+
215
+ `lib/ui/` owns CLI-facing text output and help. It can format already-computed
216
+ state, but it should not read or mutate project state.
217
+
218
+ `lib/release/` owns release metadata and release notes helpers. Release scripts
219
+ and GitHub release tooling should share these helpers.
220
+
221
+ `lib/shared/` is only for small, dependency-light utilities used across several
222
+ boundaries. It should not become a dumping ground.
223
+
224
+ ## Package Surface Policy
225
+
226
+ The supported public interface is the installed CLI: `hcc` and `hello-cc`.
227
+ `package.json` includes `lib/` because the CLI imports those files at runtime,
228
+ not because every `lib/*` path is a stable library API.
229
+
230
+ Do not document new user workflows that import `@logicseek/hello-cc/lib/*`.
231
+ Primary implementations should live in the target product directories, and
232
+ top-level `lib/*.mjs` files should be treated as compatibility entrypoints only
233
+ when there is a concrete compatibility reason.
234
+
235
+ `@logicseek/hello-cc@0.1.5` has already been published from git head
236
+ `4969100`. That published package exposed several top-level `lib/*.mjs` helper
237
+ paths because the package does not define an `exports` map. Do not remove or
238
+ rename those already-published paths in a routine cleanup commit; keep them as
239
+ compatibility re-exports for at least one release cycle unless the project
240
+ explicitly chooses a breaking package-surface change.
241
+
242
+ For local migration commits after `0.1.5`, avoid adding more top-level
243
+ compatibility shims by default. If an unpublished top-level shim is kept for the
244
+ next release, mention it in the release notes as compatibility-only and revisit
245
+ whether it can be removed before the following release. Do not let
246
+ compatibility shims become the target architecture.
247
+
248
+ Before release, classify top-level `lib/*.mjs` paths into three groups:
249
+
250
+ - Group A: already-published or CLI-facing helper paths that must stay stable
251
+ for this release.
252
+ - Group B: migration compatibility paths that re-export moved implementations;
253
+ keep them for one release if needed, but describe them as compatibility-only
254
+ deep-import paths.
255
+ - Group C: unpublished shims with no internal use and no compatibility value;
256
+ remove these before publishing.
257
+
258
+ Because `0.1.5` is already on npm, any release that includes local commits after
259
+ `4969100` must use a new package version. Do not try to republish `0.1.5`.
260
+
261
+ ## Dependency Direction
262
+
263
+ The intended dependency direction is:
264
+
265
+ ```text
266
+ bin -> cli -> web/runtime/db/core/terminal/integrations/ui
267
+ web -> runtime/db/core/terminal/ui
268
+ terminal -> shared/core sessions only when needed
269
+ core -> shared
270
+ db -> shared
271
+ ui -> shared
272
+ release -> shared
273
+ ```
274
+
275
+ Avoid these dependencies:
276
+
277
+ - `core` importing `web`, `terminal`, `cli`, or `integrations`;
278
+ - `db` importing `cli` or `web`;
279
+ - `terminal` importing Web route modules;
280
+ - provider integrations importing command handlers;
281
+ - `shared` importing product-specific modules.
282
+
283
+ This keeps most behavior testable without a Web runtime or tmux process.
284
+
285
+ ## Migration Plan
286
+
287
+ Refactor in small, reviewable phases. Each phase should keep public behavior and
288
+ npm package contents stable unless the task explicitly says otherwise.
289
+
290
+ 1. Document the target architecture.
291
+ This document is the contract for future splits.
292
+
293
+ 2. Move existing flat modules into target directories.
294
+ Start with low-risk moves such as `runtime-*`, `web-*`, `task-store`,
295
+ `messages`, `help`, `state-render`, and release helpers. Keep compatibility
296
+ re-export files temporarily if the import churn becomes too large.
297
+
298
+ 3. Split the Web runtime by subsystem.
299
+ Extract project selection, session manager, Web routes, WebSocket terminal
300
+ handling, tmux stream, PTY session, and external buffer adoption from
301
+ `cmdWeb()` in separate commits.
302
+
303
+ 4. Make `bin/hcc.mjs` a thin entrypoint.
304
+ Move dispatch and command groups under `lib/cli/commands/`.
305
+
306
+ 5. Split regression tests by domain.
307
+ Keep `npm test` as the single full regression command, but make it call
308
+ focused domain modules under `scripts/regression/`.
309
+
310
+ ## Web Runtime Target
311
+
312
+ The highest-value runtime split is:
313
+
314
+ ```text
315
+ lib/web/server.mjs
316
+ createWebRuntime(ctx, opts, deps)
317
+ start/stop lifecycle
318
+
319
+ lib/web/projects.mjs
320
+ rememberProject()
321
+ knownProjects()
322
+ projectFromRequest()
323
+
324
+ lib/web/session-manager.mjs
325
+ sessions map
326
+ getSession()
327
+ serializeSession()
328
+ startSession()
329
+ stopSession()
330
+ restoreManagedSessions()
331
+
332
+ lib/web/routes.mjs
333
+ routeHttpRequest(req, res, env)
334
+
335
+ lib/web/websocket.mjs
336
+ handleTerminalUpgrade(req, socket, head, env)
337
+
338
+ lib/terminal/tmux-stream.mjs
339
+ startTmuxStream()
340
+ stopTmuxStream()
341
+ refreshTmuxSnapshot()
342
+
343
+ lib/terminal/external-buffer.mjs
344
+ adoptExternalSession()
345
+ scanExternalSessions()
346
+ ```
347
+
348
+ This split makes Web blank-screen, stale session, tmux stream, and provider
349
+ binding bugs easier to isolate.
350
+
351
+ ## Testing Expectations
352
+
353
+ Every structural migration should run:
354
+
355
+ ```bash
356
+ git diff --check
357
+ node --check bin/hcc.mjs
358
+ node --check <changed modules>
359
+ npm test
360
+ ```
361
+
362
+ Release-facing changes should also run:
363
+
364
+ ```bash
365
+ npm run release:check
366
+ npm run release:github:dry-run
367
+ npm pack --dry-run --json
368
+ ```
369
+
370
+ When new modules are added under `lib/`, verify that `npm pack --dry-run --json`
371
+ includes them.
372
+
373
+ ## Non-Goals
374
+
375
+ Do not introduce TypeScript, Rust, a bundler, or a build step as part of this
376
+ layout migration. Those are separate product decisions with release and install
377
+ costs.
378
+
379
+ Do not rewrite working behavior while moving files. Directory migration commits
380
+ should be boring: imports change, module paths change, regression guards
381
+ change, behavior stays the same.
382
+
383
+ Do not move UI template assets into a framework until there is a separate Web UI
384
+ build plan. The current npm package should remain directly runnable after
385
+ install.