@gotgenes/pi-subagents 18.0.0 → 18.0.2

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 (257) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +22 -31
  3. package/docs/architecture/architecture.md +157 -204
  4. package/docs/architecture/history/phase-19-implement-ui-decisions.md +282 -0
  5. package/package.json +5 -6
  6. package/src/lifecycle/subagent.ts +5 -9
  7. package/src/observation/notification.ts +23 -10
  8. package/src/observation/subagent-events-observer.ts +1 -3
  9. package/src/tools/get-result-report.ts +60 -0
  10. package/src/tools/get-result-tool.ts +25 -40
  11. package/src/types.ts +1 -1
  12. package/src/ui/session-navigator.ts +0 -2
  13. package/.prettierignore +0 -5
  14. package/AGENTS.md +0 -7
  15. package/docs/plans/0048-implement-subagents-api.md +0 -304
  16. package/docs/plans/0049-remove-group-join-output-file-rpc.md +0 -180
  17. package/docs/plans/0051-update-adr-0001-hard-fork.md +0 -77
  18. package/docs/plans/0052-remove-scheduled-subagents.md +0 -133
  19. package/docs/plans/0053-extract-model-resolution-from-execute.md +0 -181
  20. package/docs/plans/0054-decompose-index-into-modules.md +0 -302
  21. package/docs/plans/0057-structured-debug-logging.md +0 -154
  22. package/docs/plans/0061-session-format-transcript.md +0 -284
  23. package/docs/plans/0066-replace-as-any-with-sdk-types.md +0 -215
  24. package/docs/plans/0069-create-subagent-runtime.md +0 -345
  25. package/docs/plans/0070-extract-event-handlers.md +0 -306
  26. package/docs/plans/0071-extract-session-config-assembler.md +0 -362
  27. package/docs/plans/0072-inject-agent-manager-collaborators.md +0 -329
  28. package/docs/plans/0076-inject-cwd-into-agent-manager.md +0 -102
  29. package/docs/plans/0077-inject-project-agents-dir.md +0 -115
  30. package/docs/plans/0080-consolidate-agent-config-lookup.md +0 -247
  31. package/docs/plans/0084-extract-git-worktree-manager.md +0 -142
  32. package/docs/plans/0087-evolve-subagent-runtime-methods.md +0 -240
  33. package/docs/plans/0098-extract-agent-record-state-machine.md +0 -435
  34. package/docs/plans/0099-replace-ctx-with-parent-snapshot.md +0 -488
  35. package/docs/plans/0100-replace-callback-threading-with-session-subscription.md +0 -454
  36. package/docs/plans/0102-consolidate-test-record-factory.md +0 -176
  37. package/docs/plans/0108-extract-agent-type-registry.md +0 -322
  38. package/docs/plans/0109-extract-settings-manager.md +0 -276
  39. package/docs/plans/0110-agent-activity-tracker.md +0 -297
  40. package/docs/plans/0111-split-agent-record-lifecycle.md +0 -582
  41. package/docs/plans/0112-replace-agent-manager-callbacks.md +0 -241
  42. package/docs/plans/0113-disambiguate-spawn-options.md +0 -155
  43. package/docs/plans/0114-narrow-agent-tool-menu-deps.md +0 -279
  44. package/docs/plans/0115-decompose-agent-tool.md +0 -337
  45. package/docs/plans/0116-type-housekeeping.md +0 -351
  46. package/docs/plans/0118-settings-manager-apply-methods.md +0 -271
  47. package/docs/plans/0123-remove-vi-fn-cast-smell.md +0 -179
  48. package/docs/plans/0131-consolidate-shared-test-fixtures.md +0 -207
  49. package/docs/plans/0132-inject-io-into-session-config.md +0 -219
  50. package/docs/plans/0133-inject-sdk-boundary-into-agent-runner.md +0 -373
  51. package/docs/plans/0134-reduce-as-any-casts.md +0 -366
  52. package/docs/plans/0135-extract-display-helpers.md +0 -182
  53. package/docs/plans/0136-decompose-agent-menu.md +0 -300
  54. package/docs/plans/0144-consolidate-observation-model.md +0 -263
  55. package/docs/plans/0145-decompose-execute-push-ctx-to-boundary.md +0 -290
  56. package/docs/plans/0146-narrow-ui-context.md +0 -319
  57. package/docs/plans/0147-inject-wrap-text-into-conversation-viewer.md +0 -166
  58. package/docs/plans/0148-split-agent-widget-rendering.md +0 -255
  59. package/docs/plans/0152-add-prompt-snippet.md +0 -91
  60. package/docs/plans/0164-reorganize-into-domain-directories.md +0 -409
  61. package/docs/plans/0165-decompose-resolved-spawn-config.md +0 -157
  62. package/docs/plans/0166-extract-parent-session-info.md +0 -231
  63. package/docs/plans/0167-narrow-runner-io.md +0 -150
  64. package/docs/plans/0168-extract-tool-filter-config.md +0 -173
  65. package/docs/plans/0169-extract-run-context-from-run-options.md +0 -194
  66. package/docs/plans/0170-reduce-build-content-lines-complexity.md +0 -225
  67. package/docs/plans/0171-reduce-render-result-complexity.md +0 -200
  68. package/docs/plans/0172-extract-turn-formatting.md +0 -206
  69. package/docs/plans/0180-reorder-append-prompt-for-kv-cache.md +0 -100
  70. package/docs/plans/0185-remove-persistent-agent-memory.md +0 -161
  71. package/docs/plans/0188-replace-any-casts-with-sdk-types.md +0 -162
  72. package/docs/plans/0192-define-session-context-interface.md +0 -107
  73. package/docs/plans/0193-runtime-owns-context-queries.md +0 -245
  74. package/docs/plans/0194-align-tool-interfaces-for-structural-typing.md +0 -139
  75. package/docs/plans/0195-convert-tool-factories-to-classes.md +0 -264
  76. package/docs/plans/0196-convert-runner-menu-to-classes.md +0 -268
  77. package/docs/plans/0205-decompose-render-widget-lines.md +0 -140
  78. package/docs/plans/0206-decompose-show-agent-detail.md +0 -211
  79. package/docs/plans/0207-decompose-agent-widget-update.md +0 -242
  80. package/docs/plans/0208-extract-shared-test-fixtures.md +0 -298
  81. package/docs/plans/0214-convert-remaining-closure-factories-to-classes.md +0 -261
  82. package/docs/plans/0215-decompose-build-parent-context.md +0 -166
  83. package/docs/plans/0216-decompose-start-agent.md +0 -255
  84. package/docs/plans/0217-extract-overwrite-guard.md +0 -176
  85. package/docs/plans/0218-push-sdk-boundary-in-settings.md +0 -172
  86. package/docs/plans/0219-reduce-test-duplication-top-3-clone-families.md +0 -162
  87. package/docs/plans/0227-evolve-agent-record-into-agent.md +0 -322
  88. package/docs/plans/0228-async-start-agent-dissolve-run-handle.md +0 -288
  89. package/docs/plans/0229-agent-born-complete.md +0 -564
  90. package/docs/plans/0230-extract-concurrency-queue.md +0 -265
  91. package/docs/plans/0231-push-exec-registry-to-runner.md +0 -245
  92. package/docs/plans/0232-agent-resume-internal-observer-lifecycle.md +0 -180
  93. package/docs/plans/0237-remove-disallowed-tools.md +0 -180
  94. package/docs/plans/0238-remove-extensions-filtering.md +0 -191
  95. package/docs/plans/0239-collapse-filter-active-tools.md +0 -217
  96. package/docs/plans/0242-rename-agent-tool-to-subagent.md +0 -165
  97. package/docs/plans/0256-extract-worktree-isolation.md +0 -256
  98. package/docs/plans/0257-extract-child-session-factory.md +0 -285
  99. package/docs/plans/0262-add-workspace-provider-seam.md +0 -264
  100. package/docs/plans/0264-remove-extension-lifecycle-control.md +0 -277
  101. package/docs/plans/0265-born-complete-subagent-session.md +0 -333
  102. package/docs/plans/0270-type-consumable-public-surface.md +0 -204
  103. package/docs/plans/0272-export-workspace-collaborator-types.md +0 -147
  104. package/docs/plans/0277-encapsulate-agent-session.md +0 -304
  105. package/docs/plans/0280-rename-agent-to-subagent.md +0 -197
  106. package/docs/plans/0360-custom-agents-default-append.md +0 -132
  107. package/docs/plans/0373-extract-subagent-state.md +0 -250
  108. package/docs/plans/0374-encapsulate-subagent-start-notification.md +0 -268
  109. package/docs/plans/0375-extract-run-listener-workspace-bracket.md +0 -300
  110. package/docs/plans/0376-extract-manager-observer.md +0 -232
  111. package/docs/plans/0377-split-widget-delegation-from-runtime.md +0 -254
  112. package/docs/plans/0378-consolidate-lifecycle-test-fixtures.md +0 -243
  113. package/docs/plans/0379-consolidate-ui-tools-test-fixtures.md +0 -335
  114. package/docs/plans/0380-extract-layered-settings-loader.md +0 -223
  115. package/docs/plans/0381-replace-concurrency-queue-with-limiter.md +0 -267
  116. package/docs/plans/0400-include-parent-prompt-in-replace-mode.md +0 -199
  117. package/docs/plans/0403-abort-subagents-on-interrupt.md +0 -180
  118. package/docs/plans/0412-unify-session-mock-builders.md +0 -146
  119. package/docs/plans/0420-fold-run-metrics-live-activity-onto-record.md +0 -228
  120. package/docs/plans/0421-migrate-activity-readers-to-record-getters.md +0 -309
  121. package/docs/plans/0422-delete-activity-tracker-ui-observer.md +0 -204
  122. package/docs/plans/0423-widget-self-drive-from-lifecycle.md +0 -264
  123. package/docs/plans/0424-drop-widget-dep-from-subagent-tool.md +0 -166
  124. package/docs/plans/0425-reconcile-subagent-events-contract.md +0 -144
  125. package/docs/plans/0426-consolidate-residual-test-clone-families.md +0 -235
  126. package/docs/plans/0427-reconsider-ui-direction.md +0 -212
  127. package/docs/plans/0441-remove-agent-definition-management-subtree.md +0 -180
  128. package/docs/plans/0442-dissolve-agents-conversation-viewer.md +0 -195
  129. package/docs/plans/0444-shrink-widget-to-background-agents.md +0 -156
  130. package/docs/plans/0445-native-session-navigation.md +0 -365
  131. package/docs/plans/0446-spike-session-navigation-entry-criteria.md +0 -171
  132. package/docs/plans/0447-extract-subagents-settings-command.md +0 -220
  133. package/docs/plans/0448-block-disabled-agent-spawn.md +0 -207
  134. package/docs/plans/0462-navigation-renderer-tui-components.md +0 -338
  135. package/docs/plans/0463-file-snapshot-source-evicted-agents.md +0 -306
  136. package/docs/retro/0048-implement-subagents-api.md +0 -44
  137. package/docs/retro/0049-remove-group-join-output-file-rpc.md +0 -49
  138. package/docs/retro/0051-update-adr-0001-hard-fork.md +0 -39
  139. package/docs/retro/0053-extract-model-resolution-from-execute.md +0 -40
  140. package/docs/retro/0054-decompose-index-into-modules.md +0 -53
  141. package/docs/retro/0057-structured-debug-logging.md +0 -77
  142. package/docs/retro/0061-session-format-transcript.md +0 -41
  143. package/docs/retro/0066-replace-as-any-with-sdk-types.md +0 -44
  144. package/docs/retro/0069-create-subagent-runtime.md +0 -43
  145. package/docs/retro/0070-extract-event-handlers.md +0 -49
  146. package/docs/retro/0071-extract-session-config-assembler.md +0 -60
  147. package/docs/retro/0072-inject-agent-manager-collaborators.md +0 -46
  148. package/docs/retro/0076-inject-cwd-into-agent-manager.md +0 -35
  149. package/docs/retro/0077-inject-project-agents-dir.md +0 -33
  150. package/docs/retro/0080-consolidate-agent-config-lookup.md +0 -35
  151. package/docs/retro/0084-extract-git-worktree-manager.md +0 -37
  152. package/docs/retro/0087-evolve-subagent-runtime-methods.md +0 -42
  153. package/docs/retro/0098-extract-agent-record-state-machine.md +0 -46
  154. package/docs/retro/0099-replace-ctx-with-parent-snapshot.md +0 -37
  155. package/docs/retro/0100-replace-callback-threading-with-session-subscription.md +0 -36
  156. package/docs/retro/0102-consolidate-test-record-factory.md +0 -30
  157. package/docs/retro/0108-extract-agent-type-registry.md +0 -41
  158. package/docs/retro/0109-extract-settings-manager.md +0 -55
  159. package/docs/retro/0110-agent-activity-tracker.md +0 -44
  160. package/docs/retro/0111-split-agent-record-lifecycle.md +0 -61
  161. package/docs/retro/0112-replace-agent-manager-callbacks.md +0 -35
  162. package/docs/retro/0113-disambiguate-spawn-options.md +0 -29
  163. package/docs/retro/0114-narrow-agent-tool-menu-deps.md +0 -38
  164. package/docs/retro/0115-decompose-agent-tool.md +0 -51
  165. package/docs/retro/0116-type-housekeeping.md +0 -42
  166. package/docs/retro/0118-settings-manager-apply-methods.md +0 -40
  167. package/docs/retro/0123-remove-vi-fn-cast-smell.md +0 -49
  168. package/docs/retro/0131-consolidate-shared-test-fixtures.md +0 -46
  169. package/docs/retro/0132-inject-io-into-session-config.md +0 -33
  170. package/docs/retro/0133-inject-sdk-boundary-into-agent-runner.md +0 -45
  171. package/docs/retro/0134-reduce-as-any-casts.md +0 -56
  172. package/docs/retro/0135-extract-display-helpers.md +0 -38
  173. package/docs/retro/0136-decompose-agent-menu.md +0 -43
  174. package/docs/retro/0144-consolidate-observation-model.md +0 -39
  175. package/docs/retro/0145-decompose-execute-push-ctx-to-boundary.md +0 -56
  176. package/docs/retro/0146-narrow-ui-context.md +0 -70
  177. package/docs/retro/0147-inject-wrap-text-into-conversation-viewer.md +0 -90
  178. package/docs/retro/0148-split-agent-widget-rendering.md +0 -39
  179. package/docs/retro/0152-add-prompt-snippet.md +0 -34
  180. package/docs/retro/0164-reorganize-into-domain-directories.md +0 -82
  181. package/docs/retro/0165-decompose-resolved-spawn-config.md +0 -78
  182. package/docs/retro/0166-extract-parent-session-info.md +0 -66
  183. package/docs/retro/0167-narrow-runner-io.md +0 -63
  184. package/docs/retro/0168-extract-tool-filter-config.md +0 -76
  185. package/docs/retro/0169-extract-run-context-from-run-options.md +0 -68
  186. package/docs/retro/0170-reduce-build-content-lines-complexity.md +0 -72
  187. package/docs/retro/0171-reduce-render-result-complexity.md +0 -77
  188. package/docs/retro/0172-extract-turn-formatting.md +0 -80
  189. package/docs/retro/0180-reorder-append-prompt-for-kv-cache.md +0 -62
  190. package/docs/retro/0185-remove-persistent-agent-memory.md +0 -73
  191. package/docs/retro/0188-replace-any-casts-with-sdk-types.md +0 -69
  192. package/docs/retro/0192-define-session-context-interface.md +0 -59
  193. package/docs/retro/0193-runtime-owns-context-queries.md +0 -75
  194. package/docs/retro/0194-align-tool-interfaces-for-structural-typing.md +0 -62
  195. package/docs/retro/0195-convert-tool-factories-to-classes.md +0 -84
  196. package/docs/retro/0196-convert-runner-menu-to-classes.md +0 -73
  197. package/docs/retro/0205-decompose-render-widget-lines.md +0 -64
  198. package/docs/retro/0206-decompose-show-agent-detail.md +0 -67
  199. package/docs/retro/0207-decompose-agent-widget-update.md +0 -92
  200. package/docs/retro/0208-extract-shared-test-fixtures.md +0 -102
  201. package/docs/retro/0214-convert-remaining-closure-factories-to-classes.md +0 -66
  202. package/docs/retro/0215-decompose-build-parent-context.md +0 -61
  203. package/docs/retro/0216-decompose-start-agent.md +0 -80
  204. package/docs/retro/0217-extract-overwrite-guard.md +0 -63
  205. package/docs/retro/0218-push-sdk-boundary-in-settings.md +0 -72
  206. package/docs/retro/0219-reduce-test-duplication-top-3-clone-families.md +0 -64
  207. package/docs/retro/0227-evolve-agent-record-into-agent.md +0 -80
  208. package/docs/retro/0228-async-start-agent-dissolve-run-handle.md +0 -80
  209. package/docs/retro/0229-agent-born-complete.md +0 -89
  210. package/docs/retro/0230-extract-concurrency-queue.md +0 -38
  211. package/docs/retro/0231-push-exec-registry-to-runner.md +0 -71
  212. package/docs/retro/0232-agent-resume-internal-observer-lifecycle.md +0 -109
  213. package/docs/retro/0237-remove-disallowed-tools.md +0 -78
  214. package/docs/retro/0238-remove-extensions-filtering.md +0 -72
  215. package/docs/retro/0239-collapse-filter-active-tools.md +0 -70
  216. package/docs/retro/0242-rename-agent-tool-to-subagent.md +0 -82
  217. package/docs/retro/0256-extract-worktree-isolation.md +0 -89
  218. package/docs/retro/0257-extract-child-session-factory.md +0 -33
  219. package/docs/retro/0262-add-workspace-provider-seam.md +0 -89
  220. package/docs/retro/0264-remove-extension-lifecycle-control.md +0 -91
  221. package/docs/retro/0265-born-complete-subagent-session.md +0 -97
  222. package/docs/retro/0270-type-consumable-public-surface.md +0 -108
  223. package/docs/retro/0272-export-workspace-collaborator-types.md +0 -38
  224. package/docs/retro/0277-encapsulate-agent-session.md +0 -80
  225. package/docs/retro/0280-rename-agent-to-subagent.md +0 -96
  226. package/docs/retro/0360-custom-agents-default-append.md +0 -81
  227. package/docs/retro/0373-extract-subagent-state.md +0 -94
  228. package/docs/retro/0374-encapsulate-subagent-start-notification.md +0 -171
  229. package/docs/retro/0375-extract-run-listener-workspace-bracket.md +0 -104
  230. package/docs/retro/0376-extract-manager-observer.md +0 -81
  231. package/docs/retro/0377-split-widget-delegation-from-runtime.md +0 -105
  232. package/docs/retro/0378-consolidate-lifecycle-test-fixtures.md +0 -100
  233. package/docs/retro/0379-consolidate-ui-tools-test-fixtures.md +0 -52
  234. package/docs/retro/0380-extract-layered-settings-loader.md +0 -97
  235. package/docs/retro/0381-replace-concurrency-queue-with-limiter.md +0 -95
  236. package/docs/retro/0400-include-parent-prompt-in-replace-mode.md +0 -84
  237. package/docs/retro/0403-abort-subagents-on-interrupt.md +0 -90
  238. package/docs/retro/0412-unify-session-mock-builders.md +0 -80
  239. package/docs/retro/0420-fold-run-metrics-live-activity-onto-record.md +0 -90
  240. package/docs/retro/0421-migrate-activity-readers-to-record-getters.md +0 -105
  241. package/docs/retro/0422-delete-activity-tracker-ui-observer.md +0 -97
  242. package/docs/retro/0423-widget-self-drive-from-lifecycle.md +0 -112
  243. package/docs/retro/0424-drop-widget-dep-from-subagent-tool.md +0 -89
  244. package/docs/retro/0425-reconcile-subagent-events-contract.md +0 -101
  245. package/docs/retro/0426-consolidate-residual-test-clone-families.md +0 -100
  246. package/docs/retro/0427-reconsider-ui-direction.md +0 -102
  247. package/docs/retro/0441-remove-agent-definition-management-subtree.md +0 -45
  248. package/docs/retro/0442-dissolve-agents-conversation-viewer.md +0 -108
  249. package/docs/retro/0444-shrink-widget-to-background-agents.md +0 -81
  250. package/docs/retro/0445-native-session-navigation.md +0 -122
  251. package/docs/retro/0446-spike-session-navigation-entry-criteria.md +0 -99
  252. package/docs/retro/0447-extract-subagents-settings-command.md +0 -91
  253. package/docs/retro/0448-block-disabled-agent-spawn.md +0 -75
  254. package/docs/retro/0462-navigation-renderer-tui-components.md +0 -105
  255. package/docs/retro/0463-file-snapshot-source-evicted-agents.md +0 -103
  256. package/src/observation/notification-state.ts +0 -27
  257. package/vitest.config.ts +0 -14
@@ -1,409 +0,0 @@
1
- ---
2
- issue: 164
3
- issue_title: "refactor(pi-subagents): reorganize source into domain directories"
4
- ---
5
-
6
- # Reorganize `pi-subagents` source into domain directories
7
-
8
- ## Problem Statement
9
-
10
- The `src/` directory has 26 files at the root level spanning four ungrouped domains (`config`, `session`, `lifecycle`, `observation`) plus two more (`service`, kept-root files).
11
- The domain model is documented in `docs/architecture/architecture.md`, but only three domains (`tools/`, `ui/`, `handlers/`) have directories.
12
- The flat layout makes it hard to reason about domain boundaries and navigate to related files.
13
-
14
- ## Goals
15
-
16
- - Move the 26 flat `src/` domain files into five new subdirectories (`config/`, `session/`,
17
- `lifecycle/`, `observation/`, `service/`).
18
- - Mirror the new structure in `test/` by moving the 25 corresponding test files.
19
- - Update every import path (relative imports in `src/`; `#src/` aliases in `test/`).
20
- - Leave `index.ts`, `runtime.ts`, `types.ts`, `settings.ts`, `debug.ts` at the `src/` root.
21
- - Preserve all existing behavior — no logic changes, no interface changes, no test logic changes.
22
-
23
- ## Non-Goals
24
-
25
- - Moving `handlers/`, `tools/`, or `ui/` — these directories already exist.
26
- - Consolidating the three UI test files (`conversation-viewer.test.ts`, `display.test.ts`,
27
- `widget-renderer.test.ts`) that are misplaced at `test/` root — pre-existing inconsistency,
28
- out of scope.
29
- - Any refactoring of module interfaces or logic — this is a pure filesystem reorganization.
30
-
31
- ## Background
32
-
33
- Issue #157 (completed) removed all `.js` suffixes from relative imports and introduced `#src/*` path aliases in `tsconfig.json` and `vitest.config.ts`.
34
- This cleanup makes the current reorganization straightforward:
35
-
36
- - `src/` files use short relative imports (`"./X"`, `"../X"`) with no suffix noise.
37
- - `test/` files use `#src/X` alias imports; after the move they become `#src/domain/X`.
38
- No `../../src/` depth changes are needed in test files.
39
-
40
- `vitest.config.ts` uses `include: ["test/**/*.test.ts"]` so moved test files are automatically discovered in subdirectories without config changes.
41
-
42
- ## Design Overview
43
-
44
- ### Target layout
45
-
46
- ```text
47
- src/
48
- config/ agent-types, default-agents, custom-agents, invocation-config
49
- session/ session-config, prompts, context, memory, skill-loader, env, model-resolver, session-dir
50
- lifecycle/ agent-manager, agent-runner, agent-record, parent-snapshot,
51
- execution-state, worktree, worktree-state, usage
52
- observation/ record-observer, notification, notification-state, renderer
53
- service/ service, service-adapter
54
- handlers/ (unchanged)
55
- tools/ (unchanged)
56
- ui/ (unchanged)
57
- index.ts (unchanged)
58
- runtime.ts (unchanged)
59
- types.ts (unchanged)
60
- settings.ts (unchanged)
61
- debug.ts (unchanged)
62
-
63
- test/
64
- config/ agent-types.test.ts, custom-agents.test.ts, invocation-config.test.ts
65
- session/ env.test.ts, memory.test.ts, model-resolver.test.ts, prompts.test.ts,
66
- session-config.test.ts, session-dir.test.ts, skill-loader.test.ts
67
- lifecycle/ agent-manager.test.ts, agent-record.test.ts, agent-runner.test.ts,
68
- agent-runner-extension-tools.test.ts, agent-runner-settings.test.ts,
69
- parent-snapshot.test.ts, usage.test.ts, worktree.test.ts, worktree-state.test.ts
70
- observation/ notification.test.ts, notification-state.test.ts, record-observer.test.ts,
71
- renderer.test.ts
72
- service/ service.test.ts, service-adapter.test.ts
73
- handlers/ (unchanged)
74
- helpers/ (unchanged)
75
- tools/ (unchanged)
76
- ui/ (unchanged)
77
- (root) debug.test.ts, display.test.ts, conversation-viewer.test.ts,
78
- widget-renderer.test.ts, print-mode.test.ts, runtime.test.ts, settings.test.ts
79
- ```
80
-
81
- ### Import-path update rules
82
-
83
- When a file at `src/X.ts` moves to `src/domain/X.ts`, three sets of paths change:
84
-
85
- 1. **Moved file's own imports** — previously `"./Y"` becomes:
86
- - `"./Y"` if `Y` is in the same domain directory
87
- - `"../Y"` if `Y` stays at the `src/` root (`debug`, `types`, `runtime`)
88
- - `"../other-domain/Y"` if `Y` moves to a different domain
89
-
90
- 2. **`src/` consumers** — files in `tools/`, `ui/`, or at the root that previously imported
91
- `"../X"` or `"./X"` update to `"../domain/X"` or `"./domain/X"` respectively.
92
-
93
- 3. **`test/` consumers** — `#src/X` aliases become `#src/domain/X`; relative
94
- test-helper imports like `"./helpers/mock-session"` become `"../helpers/mock-session"` for
95
- files that move one level deeper.
96
-
97
- ### Circular dependency between `lifecycle` and `observation`
98
-
99
- `lifecycle/agent-manager.ts` imports `observation/notification-state` and `observation/record-observer`; `observation/record-observer.ts` imports `lifecycle/agent-manager` and `lifecycle/agent-record`.
100
- These two domains must be moved in the same commit to avoid a broken intermediate state.
101
-
102
- ### Commit ordering
103
-
104
- To keep each commit green, the commits follow dependency order:
105
-
106
- 1. `config/` — no cross-domain `src/` deps (imports only `debug`, `types`)
107
- 2. `session/` — no cross-domain `src/` deps (imports only `debug`, `types`, siblings)
108
- 3. `lifecycle/` + `observation/` together — circular cross-dependency
109
- 4. `service/` — depends on `lifecycle/` and `session/`, both already moved
110
-
111
- ## Module-Level Changes
112
-
113
- ### Step 1 — `config/`
114
-
115
- New directory `src/config/`, `test/config/`.
116
-
117
- **Files moved (src):** `agent-types.ts`, `custom-agents.ts`, `default-agents.ts`, `invocation-config.ts`.
118
-
119
- **Files moved (test):** `agent-types.test.ts`, `custom-agents.test.ts`, `invocation-config.test.ts`.
120
-
121
- **Imports updated inside moved `src/` files:**
122
-
123
- | File | Old import | New import |
124
- | ----------------------------- | -------------------- | ----------------------------------------- |
125
- | `config/agent-types.ts` | `"./default-agents"` | `"./default-agents"` (sibling, unchanged) |
126
- | `config/agent-types.ts` | `"./types"` | `"../types"` |
127
- | `config/custom-agents.ts` | `"./agent-types"` | `"./agent-types"` (sibling, unchanged) |
128
- | `config/custom-agents.ts` | `"./debug"` | `"../debug"` |
129
- | `config/custom-agents.ts` | `"./types"` | `"../types"` |
130
- | `config/default-agents.ts` | `"./types"` | `"../types"` |
131
- | `config/invocation-config.ts` | `"./types"` | `"../types"` |
132
-
133
- **Consumers updated (src):**
134
-
135
- | Consumer | Old import | New import |
136
- | --------------------------------- | ------------------------ | ------------------------------------------- |
137
- | `src/agent-manager.ts` | `"./agent-types"` | `"./config/agent-types"` |
138
- | `src/agent-runner.ts` | `"./agent-types"` | `"./config/agent-types"` |
139
- | `src/index.ts` | `"./agent-types"` | `"./config/agent-types"` |
140
- | `src/index.ts` | `"./custom-agents"` | `"./config/custom-agents"` |
141
- | `src/index.ts` | `"./invocation-config"` | (now via `spawn-config` — no direct import) |
142
- | `src/tools/agent-tool.ts` | `"../agent-types"` | `"../config/agent-types"` |
143
- | `src/tools/get-result-tool.ts` | `"../agent-types"` | `"../config/agent-types"` |
144
- | `src/tools/helpers.ts` | `"../agent-types"` | `"../config/agent-types"` |
145
- | `src/tools/spawn-config.ts` | `"../agent-types"` | `"../config/agent-types"` |
146
- | `src/tools/spawn-config.ts` | `"../invocation-config"` | `"../config/invocation-config"` |
147
- | `src/ui/agent-config-editor.ts` | `"../agent-types"` | `"../config/agent-types"` |
148
- | `src/ui/agent-creation-wizard.ts` | `"../agent-types"` | `"../config/agent-types"` |
149
- | `src/ui/agent-menu.ts` | `"../agent-types"` | `"../config/agent-types"` |
150
- | `src/ui/agent-widget.ts` | `"../agent-types"` | `"../config/agent-types"` |
151
- | `src/ui/conversation-viewer.ts` | `"../agent-types"` | `"../config/agent-types"` |
152
- | `src/ui/display.ts` | `"../agent-types"` | `"../config/agent-types"` |
153
-
154
- **Consumers updated (test):** All `#src/agent-types` → `#src/config/agent-types`; `#src/custom-agents` → `#src/config/custom-agents`; `#src/invocation-config` → `#src/config/invocation-config`.
155
-
156
- **Test file relative-import fix:** Test files moving from `test/` root to `test/config/` must update `"./helpers/..."` → `"../helpers/..."` (none of the three config test files use helpers, so no update needed here).
157
-
158
- ---
159
-
160
- ### Step 2 — `session/`
161
-
162
- New directory `src/session/`, `test/session/`.
163
-
164
- **Files moved (src):** `context.ts`, `env.ts`, `memory.ts`, `model-resolver.ts`, `prompts.ts`, `session-config.ts`, `session-dir.ts`, `skill-loader.ts`.
165
-
166
- **Files moved (test):** `env.test.ts`, `memory.test.ts`, `model-resolver.test.ts`, `prompts.test.ts`, `session-config.test.ts`, `session-dir.test.ts`, `skill-loader.test.ts`.
167
-
168
- **Imports updated inside moved `src/` files:**
169
-
170
- | File | Old | New |
171
- | --------------------------- | ------------------ | ---------------------------- |
172
- | `session/env.ts` | `"./debug"` | `"../debug"` |
173
- | `session/env.ts` | `"./types"` | `"../types"` |
174
- | `session/memory.ts` | `"./debug"` | `"../debug"` |
175
- | `session/memory.ts` | `"./types"` | `"../types"` |
176
- | `session/prompts.ts` | `"./env"` | `"./env"` (sibling) |
177
- | `session/prompts.ts` | `"./types"` | `"../types"` |
178
- | `session/session-config.ts` | `"./env"` | `"./env"` (sibling) |
179
- | `session/session-config.ts` | `"./prompts"` | `"./prompts"` (sibling) |
180
- | `session/session-config.ts` | `"./skill-loader"` | `"./skill-loader"` (sibling) |
181
- | `session/session-config.ts` | `"./types"` | `"../types"` |
182
- | `session/skill-loader.ts` | `"./debug"` | `"../debug"` |
183
- | `session/skill-loader.ts` | `"./memory"` | `"./memory"` (sibling) |
184
-
185
- `context.ts`, `model-resolver.ts`, `session-dir.ts` have no internal relative imports.
186
-
187
- **Consumers updated (src):**
188
-
189
- | Consumer | Old import | New import |
190
- | ------------------------------- | --------------------- | ------------------------------------------------ |
191
- | `src/agent-runner.ts` | `"./context"` | `"./session/context"` |
192
- | `src/agent-runner.ts` | `"./env"` | `"./session/env"` |
193
- | `src/agent-runner.ts` | `"./session-config"` | `"./session/session-config"` |
194
- | `src/index.ts` | `"./env"` | `"./session/env"` |
195
- | `src/index.ts` | `"./memory"` | `"./session/memory"` |
196
- | `src/index.ts` | `"./model-resolver"` | `"./session/model-resolver"` |
197
- | `src/index.ts` | `"./prompts"` | `"./session/prompts"` |
198
- | `src/index.ts` | `"./session-config"` | (no direct import in index.ts — used via runner) |
199
- | `src/index.ts` | `"./session-dir"` | `"./session/session-dir"` |
200
- | `src/index.ts` | `"./skill-loader"` | `"./session/skill-loader"` |
201
- | `src/parent-snapshot.ts` | `"./context"` | `"./session/context"` |
202
- | `src/tools/spawn-config.ts` | `"../model-resolver"` | `"../session/model-resolver"` |
203
- | `src/ui/agent-menu.ts` | `"../model-resolver"` | `"../session/model-resolver"` |
204
- | `src/ui/conversation-viewer.ts` | `"../context"` | `"../session/context"` |
205
-
206
- **Consumers updated (test):** `#src/env` → `#src/session/env`; `#src/memory` → `#src/session/memory`; `#src/model-resolver` → `#src/session/model-resolver`; `#src/prompts` → `#src/session/prompts`; `#src/session-config` → `#src/session/session-config`; `#src/session-dir` → `#src/session/session-dir`; `#src/skill-loader` → `#src/session/skill-loader`.
207
-
208
- **Test file relative-import fix:** Moved test files update `"./helpers/..."` → `"../helpers/..."`.
209
- Check: none of the seven session test files import test helpers, so no update needed.
210
-
211
- ---
212
-
213
- ### Step 3 — `lifecycle/` + `observation/` (single commit)
214
-
215
- New directories `src/lifecycle/`, `src/observation/`, `test/lifecycle/`, `test/observation/`.
216
-
217
- **Files moved (src/lifecycle):** `agent-manager.ts`, `agent-record.ts`, `agent-runner.ts`, `execution-state.ts`, `parent-snapshot.ts`, `usage.ts`, `worktree-state.ts`, `worktree.ts`.
218
-
219
- **Files moved (src/observation):** `notification.ts`, `notification-state.ts`, `record-observer.ts`, `renderer.ts`.
220
-
221
- **Files moved (test/lifecycle):** `agent-manager.test.ts`, `agent-record.test.ts`, `agent-runner.test.ts`, `agent-runner-extension-tools.test.ts`, `agent-runner-settings.test.ts`, `parent-snapshot.test.ts`, `usage.test.ts`, `worktree.test.ts`, `worktree-state.test.ts`.
222
-
223
- **Files moved (test/observation):** `notification.test.ts`, `notification-state.test.ts`, `record-observer.test.ts`, `renderer.test.ts`.
224
-
225
- **Imports updated inside moved `src/lifecycle/` files:**
226
-
227
- | File | Old | New |
228
- | ------------------------------ | ------------------------ | ------------------------------------- |
229
- | `lifecycle/agent-manager.ts` | `"./agent-record"` | `"./agent-record"` (sibling) |
230
- | `lifecycle/agent-manager.ts` | `"./agent-runner"` | `"./agent-runner"` (sibling) |
231
- | `lifecycle/agent-manager.ts` | `"./agent-types"` | `"../config/agent-types"` |
232
- | `lifecycle/agent-manager.ts` | `"./debug"` | `"../debug"` |
233
- | `lifecycle/agent-manager.ts` | `"./notification-state"` | `"../observation/notification-state"` |
234
- | `lifecycle/agent-manager.ts` | `"./parent-snapshot"` | `"./parent-snapshot"` (sibling) |
235
- | `lifecycle/agent-manager.ts` | `"./record-observer"` | `"../observation/record-observer"` |
236
- | `lifecycle/agent-manager.ts` | `"./runtime"` | `"../runtime"` |
237
- | `lifecycle/agent-manager.ts` | `"./types"` | `"../types"` |
238
- | `lifecycle/agent-manager.ts` | `"./worktree"` | `"./worktree"` (sibling) |
239
- | `lifecycle/agent-manager.ts` | `"./worktree-state"` | `"./worktree-state"` (sibling) |
240
- | `lifecycle/agent-record.ts` | `"./execution-state"` | `"./execution-state"` (sibling) |
241
- | `lifecycle/agent-record.ts` | `"./notification-state"` | `"../observation/notification-state"` |
242
- | `lifecycle/agent-record.ts` | `"./types"` | `"../types"` |
243
- | `lifecycle/agent-record.ts` | `"./usage"` | `"./usage"` (sibling) |
244
- | `lifecycle/agent-record.ts` | `"./worktree-state"` | `"./worktree-state"` (sibling) |
245
- | `lifecycle/agent-runner.ts` | `"./agent-types"` | `"../config/agent-types"` |
246
- | `lifecycle/agent-runner.ts` | `"./context"` | `"../session/context"` |
247
- | `lifecycle/agent-runner.ts` | `"./env"` | `"../session/env"` |
248
- | `lifecycle/agent-runner.ts` | `"./parent-snapshot"` | `"./parent-snapshot"` (sibling) |
249
- | `lifecycle/agent-runner.ts` | `"./session-config"` | `"../session/session-config"` |
250
- | `lifecycle/agent-runner.ts` | `"./types"` | `"../types"` |
251
- | `lifecycle/parent-snapshot.ts` | `"./context"` | `"../session/context"` |
252
- | `lifecycle/worktree.ts` | `"./debug"` | `"../debug"` |
253
- | `lifecycle/worktree-state.ts` | `"./worktree"` | `"./worktree"` (sibling) |
254
-
255
- `execution-state.ts`, `usage.ts` have no internal relative imports.
256
-
257
- **Imports updated inside moved `src/observation/` files:**
258
-
259
- | File | Old | New |
260
- | -------------------------------- | ------------------------------- | -------------------------------- |
261
- | `observation/notification.ts` | `"./debug"` | `"../debug"` |
262
- | `observation/notification.ts` | `"./types"` | `"../types"` |
263
- | `observation/notification.ts` | `"./ui/agent-activity-tracker"` | `"../ui/agent-activity-tracker"` |
264
- | `observation/notification.ts` | `"./usage"` | `"../lifecycle/usage"` |
265
- | `observation/record-observer.ts` | `"./agent-manager"` | `"../lifecycle/agent-manager"` |
266
- | `observation/record-observer.ts` | `"./agent-record"` | `"../lifecycle/agent-record"` |
267
- | `observation/renderer.ts` | `"./notification"` | `"./notification"` (sibling) |
268
- | `observation/renderer.ts` | `"./ui/display"` | `"../ui/display"` |
269
-
270
- `notification-state.ts` has no internal relative imports.
271
-
272
- **Consumers updated (src):**
273
-
274
- | Consumer | Old import | New import |
275
- | ---------------------------------- | -------------------------------------- | ---------------------------------- |
276
- | `src/index.ts` | `"./agent-manager"` | `"./lifecycle/agent-manager"` |
277
- | `src/index.ts` | `"./agent-runner"` | `"./lifecycle/agent-runner"` |
278
- | `src/index.ts` | `"./parent-snapshot"` | `"./lifecycle/parent-snapshot"` |
279
- | `src/index.ts` | `"./worktree"` | `"./lifecycle/worktree"` |
280
- | `src/index.ts` | `"./notification"` | `"./observation/notification"` |
281
- | `src/index.ts` | `"./record-observer"` | (not imported directly from index) |
282
- | `src/index.ts` | `"./renderer"` | `"./observation/renderer"` |
283
- | `src/runtime.ts` | (no changes — only imports from `ui/`) | — |
284
- | `src/types.ts` | `"./agent-record"` | `"./lifecycle/agent-record"` |
285
- | `src/tools/agent-tool.ts` | `"../agent-manager"` | `"../lifecycle/agent-manager"` |
286
- | `src/tools/agent-tool.ts` | `"../parent-snapshot"` | `"../lifecycle/parent-snapshot"` |
287
- | `src/tools/background-spawner.ts` | `"../agent-manager"` | `"../lifecycle/agent-manager"` |
288
- | `src/tools/background-spawner.ts` | `"../parent-snapshot"` | `"../lifecycle/parent-snapshot"` |
289
- | `src/tools/foreground-runner.ts` | `"../agent-manager"` | `"../lifecycle/agent-manager"` |
290
- | `src/tools/foreground-runner.ts` | `"../parent-snapshot"` | `"../lifecycle/parent-snapshot"` |
291
- | `src/tools/get-result-tool.ts` | `"../usage"` | `"../lifecycle/usage"` |
292
- | `src/tools/helpers.ts` | `"../usage"` | `"../lifecycle/usage"` |
293
- | `src/tools/spawn-config.ts` | `"../agent-runner"` | `"../lifecycle/agent-runner"` |
294
- | `src/tools/steer-tool.ts` | `"../usage"` | `"../lifecycle/usage"` |
295
- | `src/ui/agent-activity-tracker.ts` | `"../usage"` | `"../lifecycle/usage"` |
296
- | `src/ui/agent-creation-wizard.ts` | `"../parent-snapshot"` | `"../lifecycle/parent-snapshot"` |
297
- | `src/ui/agent-menu.ts` | `"../parent-snapshot"` | `"../lifecycle/parent-snapshot"` |
298
- | `src/ui/agent-widget.ts` | `"../agent-manager"` | `"../lifecycle/agent-manager"` |
299
- | `src/ui/conversation-viewer.ts` | `"../usage"` | `"../lifecycle/usage"` |
300
- | `src/ui/widget-renderer.ts` | `"../usage"` | `"../lifecycle/usage"` |
301
-
302
- **Consumers updated (test):** `#src/agent-manager` → `#src/lifecycle/agent-manager`; `#src/agent-record` → `#src/lifecycle/agent-record`; `#src/agent-runner` → `#src/lifecycle/agent-runner`; `#src/parent-snapshot` → `#src/lifecycle/parent-snapshot`; `#src/usage` → `#src/lifecycle/usage`; `#src/worktree` → `#src/lifecycle/worktree`; `#src/worktree-state` → `#src/lifecycle/worktree-state`; `#src/notification` → `#src/observation/notification`; `#src/notification-state` → `#src/observation/notification-state`; `#src/record-observer` → `#src/observation/record-observer`; `#src/renderer` → `#src/observation/renderer`.
303
-
304
- **Test file relative-import fix:** Moved test files update `"./helpers/..."` → `"../helpers/..."` where used.
305
- Check: `agent-manager.test.ts`, `agent-record.test.ts`, `agent-runner.test.ts`, `agent-runner-extension-tools.test.ts`, `agent-runner-settings.test.ts`, `record-observer.test.ts` all import test helpers via `"./helpers/..."` — these must change to `"../helpers/..."` after the move.
306
-
307
- ---
308
-
309
- ### Step 4 — `service/`
310
-
311
- New directory `src/service/`, `test/service/`.
312
-
313
- **Files moved (src):** `service.ts`, `service-adapter.ts`.
314
-
315
- **Files moved (test):** `service.test.ts`, `service-adapter.test.ts`.
316
-
317
- **Imports updated inside moved `src/` files:**
318
-
319
- | File | Old | New |
320
- | ---------------------------- | --------------------- | -------------------------------- |
321
- | `service/service.ts` | `"./usage"` | `"../lifecycle/usage"` |
322
- | `service/service-adapter.ts` | `"./model-resolver"` | `"../session/model-resolver"` |
323
- | `service/service-adapter.ts` | `"./parent-snapshot"` | `"../lifecycle/parent-snapshot"` |
324
- | `service/service-adapter.ts` | `"./service"` | `"./service"` (sibling) |
325
- | `service/service-adapter.ts` | `"./types"` | `"../types"` |
326
-
327
- **Consumers updated (src):**
328
-
329
- | Consumer | Old import | New import |
330
- | -------------- | --------------------- | ----------------------------- |
331
- | `src/index.ts` | `"./service"` | `"./service/service"` |
332
- | `src/index.ts` | `"./service-adapter"` | `"./service/service-adapter"` |
333
-
334
- **Consumers updated (test):** `#src/service` → `#src/service/service`; `#src/service-adapter` → `#src/service/service-adapter`.
335
-
336
- **Test file relative-import fix:** `service-adapter.test.ts` uses `"./helpers/make-record"` and `"./helpers/mock-session"` — update to `"../helpers/make-record"` and `"../helpers/mock-session"`.
337
-
338
- ---
339
-
340
- ### Unchanged files
341
-
342
- Root `src/` files `index.ts`, `runtime.ts`, `types.ts`, `settings.ts`, `debug.ts` stay in place.
343
- `src/handlers/`, `src/tools/`, `src/ui/` stay in place (their imports update as consumers above).
344
- `test/helpers/`, `test/handlers/`, `test/tools/`, `test/ui/` stay in place.
345
-
346
- ## Test Impact Analysis
347
-
348
- This is a pure filesystem reorganization.
349
- No new unit tests are enabled or required.
350
- No existing tests become redundant.
351
- No test logic changes — only file locations and import specifiers change.
352
-
353
- The test suite passes before and after; the green-on-each-commit discipline verifies that every import path update is correct before the next domain is moved.
354
-
355
- ## TDD Order
356
-
357
- There is no red/green cycle for new behavior.
358
- Each step follows: move files → fix imports → verify green → commit.
359
-
360
- ### Step 1 — Move `config/` domain
361
-
362
- - Create `src/config/`, `test/config/`
363
- - `git mv` 4 `src/` files into `src/config/`
364
- - `git mv` 3 `test/` files into `test/config/`
365
- - Update imports per the Module-Level Changes table for `config/`
366
- - Run `pnpm run check && pnpm run test` — must be green
367
- - Commit: `refactor: move config domain modules into src/config/ (#164)`
368
-
369
- ### Step 2 — Move `session/` domain
370
-
371
- - Create `src/session/`, `test/session/`
372
- - `git mv` 8 `src/` files into `src/session/`
373
- - `git mv` 7 `test/` files into `test/session/`
374
- - Update imports per the Module-Level Changes table for `session/`
375
- - Run `pnpm run check && pnpm run test` — must be green
376
- - Commit: `refactor: move session domain modules into src/session/ (#164)`
377
-
378
- ### Step 3 — Move `lifecycle/` + `observation/` domains (single commit)
379
-
380
- - Create `src/lifecycle/`, `src/observation/`, `test/lifecycle/`, `test/observation/`
381
- - `git mv` 8 `src/lifecycle/` files, 4 `src/observation/` files
382
- - `git mv` 9 `test/lifecycle/` files, 4 `test/observation/` files
383
- - Update imports per both tables in the Module-Level Changes section
384
- - Update `src/types.ts` re-export path
385
- - Run `pnpm run check && pnpm run test` — must be green
386
- - Commit: `refactor: move lifecycle and observation domain modules (#164)`
387
-
388
- ### Step 4 — Move `service/` domain
389
-
390
- - Create `src/service/`, `test/service/`
391
- - `git mv` 2 `src/` files into `src/service/`
392
- - `git mv` 2 `test/` files into `test/service/`
393
- - Update imports per the Module-Level Changes table for `service/`
394
- - Run `pnpm run check && pnpm run test` — must be green
395
- - Commit: `refactor: move service domain modules into src/service/ (#164)`
396
-
397
- ## Risks and Mitigations
398
-
399
- | Risk | Mitigation |
400
- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
401
- | Missed import path breaks the build | `pnpm run check` (`tsc --noEmit`) catches all unresolved paths before tests run |
402
- | Test file not auto-discovered after move | `vitest.config.ts` uses `"test/**/*.test.ts"` glob — subdirectory files are included automatically |
403
- | `git mv` history not preserved for renamed + edited files | Use `git mv` for the move, then edit the file; git tracks the rename even with content edits |
404
- | Step 3 is large (25 file moves) | All changes are mechanical with no logic edits; import tables above enumerate every update |
405
- | Forgotten consumer in `tools/`, `ui/`, or `index.ts` | TypeScript's `noEmit` check will fail on any un-updated import; the check step is mandatory before each commit |
406
-
407
- ## Open Questions
408
-
409
- None — the issue scope is fully specified and #157 resolved the prerequisite import cleanup.
@@ -1,157 +0,0 @@
1
- ---
2
- issue: 165
3
- issue_title: "refactor(pi-subagents): decompose ResolvedSpawnConfig (15 fields)"
4
- ---
5
-
6
- # Decompose ResolvedSpawnConfig into domain-aligned sub-interfaces
7
-
8
- ## Problem Statement
9
-
10
- `ResolvedSpawnConfig` in `tools/spawn-config.ts` has 15 fields mixing identity, execution, and presentation concerns.
11
- Each consumer uses a different subset but receives the full bag — violating ISP and making the real dependencies of `foreground-runner` and `background-spawner` invisible.
12
-
13
- ## Goals
14
-
15
- - Split `ResolvedSpawnConfig` into three focused interfaces: `SpawnIdentity`, `SpawnExecution`, `SpawnPresentation`.
16
- - Each consumer declares its real dependencies explicitly.
17
- - Preserve existing behavior — pure structural refactor with no behavioral changes.
18
-
19
- ## Non-Goals
20
-
21
- - Extracting `ParentSessionInfo` from `AgentSpawnConfig` — that's #166.
22
- - Changing how `resolveSpawnConfig` computes values internally.
23
- - Modifying the `AgentSpawnConfig` interface passed to `AgentManager`.
24
-
25
- ## Background
26
-
27
- `resolveSpawnConfig` is called by `agent-tool.ts` and produces a single flat config object.
28
- Three consumers read from it:
29
-
30
- 1. `agent-tool.ts` — reads `inheritContext` (to build snapshot), `runInBackground` (to branch), and `detailBase` (for resume result).
31
- 2. `foreground-runner.ts` — reads identity fields for fallback messages, execution fields for spawn options, and `detailBase` for result formatting.
32
- 3. `background-spawner.ts` — reads identity fields for launch message, execution fields for spawn options, and `detailBase` for result formatting.
33
-
34
- Two fields (`modelName`, `agentTags`) are never accessed by any external consumer — they're intermediate values used only inside `resolveSpawnConfig` to build `detailBase`.
35
- They belong on `SpawnPresentation` for transparency but could also be made internal-only.
36
-
37
- The `code-design` skill's ISP and dependency-width guidance both apply: clients should not depend on properties they don't use, and a shared bag where each consumer only touches a subset hides real dependencies.
38
-
39
- ## Design Overview
40
-
41
- ### New interfaces
42
-
43
- ```typescript
44
- /** Identity: who is being spawned. */
45
- export interface SpawnIdentity {
46
- subagentType: string;
47
- rawType: SubagentType;
48
- fellBack: boolean;
49
- displayName: string;
50
- }
51
-
52
- /** Execution: how the agent will run. */
53
- export interface SpawnExecution {
54
- prompt: string;
55
- description: string;
56
- model: Model<any> | undefined;
57
- effectiveMaxTurns: number | undefined;
58
- thinking: ThinkingLevel | undefined;
59
- inheritContext: boolean;
60
- runInBackground: boolean;
61
- isolated: boolean;
62
- isolation: IsolationMode | undefined;
63
- agentInvocation: AgentInvocation;
64
- }
65
-
66
- /** Presentation: display/UI values derived from identity + execution. */
67
- export interface SpawnPresentation {
68
- modelName: string | undefined;
69
- agentTags: string[];
70
- detailBase: Pick<AgentDetails, "displayName" | "description" | "subagentType" | "modelName" | "tags">;
71
- }
72
-
73
- /** Fully resolved config — now a composition of domain-aligned sub-interfaces. */
74
- export interface ResolvedSpawnConfig {
75
- identity: SpawnIdentity;
76
- execution: SpawnExecution;
77
- presentation: SpawnPresentation;
78
- }
79
- ```
80
-
81
- ### Consumer interaction pattern
82
-
83
- ```typescript
84
- // agent-tool.ts — uses execution for routing, presentation for resume
85
- const config = resolveSpawnConfig(params, registry, modelInfo, settings);
86
- if ("error" in config) return textResult(config.error);
87
- const snapshot = buildSnapshot(config.execution.inheritContext);
88
- if (config.execution.runInBackground) { /* ... */ }
89
- return buildDetails(config.presentation.detailBase, record);
90
-
91
- // foreground-runner.ts — destructures what it needs
92
- const { identity, execution, presentation } = params.config;
93
- record = await manager.spawnAndWait(snapshot, identity.subagentType, execution.prompt, { ... });
94
- const fallbackNote = identity.fellBack ? `Note: Unknown agent type "${identity.rawType}"...` : "";
95
- ```
96
-
97
- This follows Tell-Don't-Ask — callers pick the sub-object relevant to their concern rather than reaching through a flat bag.
98
- The one-level nesting (`config.execution.inheritContext`) is acceptable because it names the domain the field belongs to.
99
-
100
- ### Test factory migration
101
-
102
- Both test files (`foreground-runner.test.ts`, `background-spawner.test.ts`) have `makeConfig()` factories that construct the full 15-field flat object.
103
- These will be updated to construct the nested structure.
104
- The `spawn-config.test.ts` assertions will shift from `result.subagentType` to `result.identity.subagentType` etc.
105
-
106
- ## Module-Level Changes
107
-
108
- | File | Change |
109
- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
110
- | `src/tools/spawn-config.ts` | Add `SpawnIdentity`, `SpawnExecution`, `SpawnPresentation` interfaces. Change `ResolvedSpawnConfig` to nest them. Update `resolveSpawnConfig` return to build nested structure. |
111
- | `src/tools/agent-tool.ts` | Update config access: `config.execution.inheritContext`, `config.execution.runInBackground`, `config.presentation.detailBase`. |
112
- | `src/tools/foreground-runner.ts` | Destructure `config` into `identity`, `execution`, `presentation`. Update all field accesses. |
113
- | `src/tools/background-spawner.ts` | Destructure `config` into `identity`, `execution`, `presentation`. Update all field accesses. |
114
- | `test/tools/spawn-config.test.ts` | Update all assertions to use nested paths (`result.identity.subagentType`, etc.). |
115
- | `test/tools/foreground-runner.test.ts` | Update `makeConfig()` factory to build nested structure. |
116
- | `test/tools/background-spawner.test.ts` | Update `makeConfig()` factory to build nested structure. |
117
-
118
- ## Test Impact Analysis
119
-
120
- 1. No new unit tests are needed — this is a structural refactor, not new behavior.
121
- 2. No existing tests become redundant — all current `spawn-config.test.ts` assertions still verify the same computation.
122
- 3. All existing tests must be updated to match the new nested access paths, but they continue to exercise the same logic.
123
-
124
- ## TDD Order
125
-
126
- 1. **Red→Green: introduce sub-interfaces and nest `ResolvedSpawnConfig`** — change `spawn-config.ts` to export the three sub-interfaces and restructure `ResolvedSpawnConfig`.
127
- Update `resolveSpawnConfig` to return the nested shape.
128
- Update `spawn-config.test.ts` assertions to match.
129
- Commit: `refactor(pi-subagents): introduce SpawnIdentity, SpawnExecution, SpawnPresentation`
130
-
131
- 2. **Green: update `agent-tool.ts`** — migrate the three field accesses (`inheritContext`, `runInBackground`, `detailBase`) to nested paths.
132
- Run `pnpm run check` to confirm types pass.
133
- Commit: `refactor(pi-subagents): update agent-tool to use nested spawn config`
134
-
135
- 3. **Green: update `foreground-runner.ts` and its test** — destructure config and update all field accesses.
136
- Update `makeConfig()` factory in `foreground-runner.test.ts`.
137
- Commit: `refactor(pi-subagents): update foreground-runner to use nested spawn config`
138
-
139
- 4. **Green: update `background-spawner.ts` and its test** — destructure config and update all field accesses.
140
- Update `makeConfig()` factory in `background-spawner.test.ts`.
141
- Commit: `refactor(pi-subagents): update background-spawner to use nested spawn config`
142
-
143
- 5. **Verify: full suite** — run `pnpm vitest run` and `pnpm run check` to confirm no regressions.
144
- Commit (if any lint/type cleanup needed): `chore(pi-subagents): post-decomposition cleanup`
145
-
146
- ## Risks and Mitigations
147
-
148
- | Risk | Mitigation |
149
- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
150
- | Step 1 breaks type checking for all consumers simultaneously | Steps 2–4 must land in the same branch before pushing; or use a transitional type alias that spreads the sub-interfaces flat, removing it in the final step. |
151
- | Test factories diverge from production shape | Each step updates the test factory in the same commit as the source change. |
152
- | `modelName` and `agentTags` on `SpawnPresentation` look unused | They are unused by external consumers today but provide inspection affordance for debugging/logging. Keep them; #166 or later work may consume them. |
153
-
154
- ## Open Questions
155
-
156
- - None — the issue's proposed shape aligns with actual field usage patterns.
157
- The only observation is that `modelName` and `agentTags` are only consumed internally, but exposing them on `SpawnPresentation` is harmless and aids debuggability.