@gotgenes/pi-subagents 6.17.0 → 6.17.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.
- package/CHANGELOG.md +27 -0
- package/docs/architecture/architecture.md +588 -536
- package/docs/architecture/history/phase-1-api-boundary.md +8 -0
- package/docs/architecture/history/phase-2-remove-scheduling.md +9 -0
- package/docs/architecture/history/phase-3-remove-rpc-groupjoin.md +11 -0
- package/docs/architecture/history/phase-4-implement-service.md +8 -0
- package/docs/architecture/history/phase-5-decompose-index.md +42 -0
- package/docs/architecture/history/phase-7-encapsulation.md +173 -0
- package/docs/architecture/history/phase-8-testability.md +103 -0
- package/docs/architecture/history/phase-9-observation-ctx.md +122 -0
- package/docs/plans/0164-reorganize-into-domain-directories.md +409 -0
- package/docs/retro/0147-inject-wrap-text-into-conversation-viewer.md +40 -0
- package/docs/retro/0164-reorganize-into-domain-directories.md +46 -0
- package/package.json +5 -1
- package/src/{agent-types.ts → config/agent-types.ts} +2 -2
- package/src/{custom-agents.ts → config/custom-agents.ts} +3 -3
- package/src/{default-agents.ts → config/default-agents.ts} +1 -1
- package/src/{invocation-config.ts → config/invocation-config.ts} +1 -1
- package/src/handlers/index.ts +2 -2
- package/src/index.ts +26 -26
- package/src/{agent-manager.ts → lifecycle/agent-manager.ts} +11 -11
- package/src/{agent-record.ts → lifecycle/agent-record.ts} +6 -6
- package/src/{agent-runner.ts → lifecycle/agent-runner.ts} +6 -6
- package/src/{parent-snapshot.ts → lifecycle/parent-snapshot.ts} +1 -1
- package/src/{worktree-state.ts → lifecycle/worktree-state.ts} +1 -1
- package/src/{worktree.ts → lifecycle/worktree.ts} +1 -1
- package/src/{notification.ts → observation/notification.ts} +4 -4
- package/src/{record-observer.ts → observation/record-observer.ts} +2 -2
- package/src/{renderer.ts → observation/renderer.ts} +2 -2
- package/src/runtime.ts +2 -2
- package/src/{service-adapter.ts → service/service-adapter.ts} +5 -5
- package/src/{service.ts → service/service.ts} +1 -1
- package/src/{env.ts → session/env.ts} +2 -2
- package/src/{memory.ts → session/memory.ts} +2 -2
- package/src/{prompts.ts → session/prompts.ts} +2 -2
- package/src/{session-config.ts → session/session-config.ts} +5 -5
- package/src/{skill-loader.ts → session/skill-loader.ts} +2 -2
- package/src/tools/agent-tool.ts +11 -12
- package/src/tools/background-spawner.ts +8 -8
- package/src/tools/foreground-runner.ts +14 -14
- package/src/tools/get-result-tool.ts +5 -5
- package/src/tools/helpers.ts +4 -4
- package/src/tools/spawn-config.ts +6 -6
- package/src/tools/steer-tool.ts +3 -3
- package/src/types.ts +1 -1
- package/src/ui/agent-activity-tracker.ts +1 -1
- package/src/ui/agent-config-editor.ts +4 -4
- package/src/ui/agent-creation-wizard.ts +5 -5
- package/src/ui/agent-menu.ts +10 -10
- package/src/ui/agent-widget.ts +5 -5
- package/src/ui/conversation-viewer.ts +6 -6
- package/src/ui/display.ts +2 -2
- package/src/ui/ui-observer.ts +1 -1
- package/src/ui/widget-renderer.ts +5 -5
- package/vitest.config.ts +14 -0
- /package/src/{execution-state.ts → lifecycle/execution-state.ts} +0 -0
- /package/src/{usage.ts → lifecycle/usage.ts} +0 -0
- /package/src/{notification-state.ts → observation/notification-state.ts} +0 -0
- /package/src/{context.ts → session/context.ts} +0 -0
- /package/src/{model-resolver.ts → session/model-resolver.ts} +0 -0
- /package/src/{session-dir.ts → session/session-dir.ts} +0 -0
|
@@ -0,0 +1,409 @@
|
|
|
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.
|
|
@@ -48,3 +48,43 @@ Full suite 50 files, 805 tests, all green.
|
|
|
48
48
|
- Cycle 2 was a single Edit call replacing the entire mock block + the two dynamic imports + `beforeEach`.
|
|
49
49
|
The autoformatter then cleaned up import ordering automatically.
|
|
50
50
|
- Architecture doc updated: smells table row struck-through and Step O marked ✓.
|
|
51
|
+
|
|
52
|
+
## Stage: Final Retrospective (2026-05-23T11:45:00Z)
|
|
53
|
+
|
|
54
|
+
### Session summary
|
|
55
|
+
|
|
56
|
+
Planned, implemented, shipped, and released issue #147 across a single session chain.
|
|
57
|
+
Two TDD cycles completed cleanly; CI passed; issue closed; `pi-subagents-v6.17.0` released.
|
|
58
|
+
Test count: 806 → 805 (deleted mock-mechanism sentinel test).
|
|
59
|
+
|
|
60
|
+
### Observations
|
|
61
|
+
|
|
62
|
+
#### What went well
|
|
63
|
+
|
|
64
|
+
- Python script for bulk constructor edits worked first-try on 17 call sites with per-test regex capture groups.
|
|
65
|
+
This is now a proven pattern — #116 and #147 both used it successfully for `ConversationViewer` constructor changes.
|
|
66
|
+
- Two-cycle TDD approach (Cycle 1: add DI with mock still present; Cycle 2: remove mock) gave a stable intermediate state and caught the missing `wrapTextWithAnsi` import before proceeding.
|
|
67
|
+
- Scope was tight: 3 files changed, 2 commits of substance, no rework on the production code.
|
|
68
|
+
|
|
69
|
+
#### What caused friction (agent side)
|
|
70
|
+
|
|
71
|
+
1. `instruction-violation` — Failed to load the `colgrep` skill during planning.
|
|
72
|
+
Constructed the path by pattern (`.pi/skills/colgrep/SKILL.md`) instead of using the `<location>` listed in the `<available_skills>` block (`packages/pi-colgrep/skills/colgrep/SKILL.md`).
|
|
73
|
+
Got ENOENT and silently moved on.
|
|
74
|
+
Impact: user-caught; required a follow-up exchange to load the skill and re-review the plan.
|
|
75
|
+
No rework needed — the plan was already correct.
|
|
76
|
+
2. `wrong-abstraction` — Cycle 2 Edit replaced the entire `vi.mock` block + dynamic imports as one chunk, leaving the `ConversationViewer` static import stranded after `const testRegistry` instead of at the top with other imports.
|
|
77
|
+
Impact: user-caught ("Wait, we have a dynamic import?"); required a follow-up edit and amend into the retro commit.
|
|
78
|
+
3. `missing-context` — Plan stated "11+" constructor call sites; actual count was 16 (11 render-width-safety + 5 safety-net).
|
|
79
|
+
The grep output during planning showed all 16 but the count wasn't verified.
|
|
80
|
+
Impact: no rework — the Python script handled all 17 (16 test + 1 production) regardless.
|
|
81
|
+
|
|
82
|
+
#### What caused friction (user side)
|
|
83
|
+
|
|
84
|
+
- No friction identified — user interventions were timely and precise.
|
|
85
|
+
|
|
86
|
+
### Changes made
|
|
87
|
+
|
|
88
|
+
1. Appended this final retrospective entry to `packages/pi-subagents/docs/retro/0147-inject-wrap-text-into-conversation-viewer.md`.
|
|
89
|
+
2. Separated `colgrep` skill loading into its own bullet in `.pi/prompts/plan-issue.md` to reduce pattern-matching shortcuts.
|
|
90
|
+
3. Replaced deterministic step in `.pi/prompts/retro.md` with a "Sync with remote" section matching the other prompts.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
issue: 164
|
|
3
|
+
issue_title: "refactor(pi-subagents): reorganize source into domain directories"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Retro: #164 — refactor(pi-subagents): reorganize source into domain directories
|
|
7
|
+
|
|
8
|
+
## Stage: Planning (2026-05-23T00:00:00Z)
|
|
9
|
+
|
|
10
|
+
### Session summary
|
|
11
|
+
|
|
12
|
+
Read issue #164, confirmed #157 (import normalization) was a prerequisite and had been completed.
|
|
13
|
+
Explored the full `src/` and `test/` structure, mapped every relative import in the 26 files to be moved, and produced a four-commit plan that moves files domain-by-domain in dependency order.
|
|
14
|
+
|
|
15
|
+
### Observations
|
|
16
|
+
|
|
17
|
+
- Issue #157 removed `.js` suffixes and introduced `#src/*` aliases in `test/` files.
|
|
18
|
+
This makes the reorganization cleaner: test imports are flat `#src/agent-manager` → `#src/lifecycle/agent-manager` with no depth variation.
|
|
19
|
+
- `lifecycle/` and `observation/` have a circular dependency (`agent-manager` ↔ `record-observer`), so they must be moved in a single commit (Step 3).
|
|
20
|
+
All other domains can be committed independently.
|
|
21
|
+
- `vitest.config.ts` uses `"test/**/*.test.ts"` — test files in new subdirectories are
|
|
22
|
+
auto-discovered without config changes.
|
|
23
|
+
- Three UI test files (`conversation-viewer.test.ts`, `display.test.ts`,
|
|
24
|
+
`widget-renderer.test.ts`) are misplaced at `test/` root; left out of scope for this issue.
|
|
25
|
+
- No `default-agents.test.ts`, `context.test.ts`, or `execution-state.test.ts` exist —
|
|
26
|
+
those src modules have no dedicated test files.
|
|
27
|
+
- The import tables in the plan enumerate every path change; `pnpm run check` will catch
|
|
28
|
+
any missed update before each commit.
|
|
29
|
+
|
|
30
|
+
## Stage: Implementation — TDD (2026-05-23T16:55:00Z)
|
|
31
|
+
|
|
32
|
+
### Session summary
|
|
33
|
+
|
|
34
|
+
Executed all four plan steps (config, session, lifecycle+observation, service) plus a fifth unplanned step converting all `src/` internal imports to `#src/` aliases.
|
|
35
|
+
All 50 test files and 805 tests pass throughout.
|
|
36
|
+
Updated `docs/architecture/architecture.md` to reflect the completed restructuring.
|
|
37
|
+
|
|
38
|
+
### Observations
|
|
39
|
+
|
|
40
|
+
- The plan's consumer tables were mostly complete but missed a few files: `src/ui/widget-renderer.ts` and `src/session-config.ts` (still at root during step 1) both imported `agent-types`; `src/service-adapter.ts` imported `model-resolver`; `test/parent-snapshot.test.ts` had a `vi.mock("#src/context")` path.
|
|
41
|
+
All caught immediately by `pnpm run check` or a failing test.
|
|
42
|
+
- `src/service-adapter.ts` and `src/service.ts` (still at root during step 3) imported `parent-snapshot` and `usage` which moved in that step, so they had to be fixed as part of step 3's commit rather than step 4's.
|
|
43
|
+
- The `#src/` alias conversion (fifth commit) was added after the user correctly observed that `src/` files should use the same alias style as `test/` files.
|
|
44
|
+
This eliminates all `../` relative cross-directory imports from `src/`.
|
|
45
|
+
Future file moves in `src/` now only require updating the `#src/domain/name` string — no relative depth arithmetic.
|
|
46
|
+
- Biome auto-fixed 14 files (import sorting / trailing whitespace) during the `#src/` conversion step; committed via `git add -A` after the pre-commit hook run.
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gotgenes/pi-subagents",
|
|
3
|
-
"version": "6.17.
|
|
3
|
+
"version": "6.17.2",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./src/service.ts"
|
|
6
6
|
},
|
|
7
|
+
"imports": {
|
|
8
|
+
"#src/*": "./src/*",
|
|
9
|
+
"#test/*": "./test/*"
|
|
10
|
+
},
|
|
7
11
|
"description": "A pi extension that brings Claude Code-style autonomous sub-agents to pi. Friendly fork of @tintinweb/pi-subagents.",
|
|
8
12
|
"author": {
|
|
9
13
|
"name": "Chris Lasher"
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* User agents override defaults with the same name. Disabled agents are kept but excluded from spawning.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { DEFAULT_AGENTS } from "
|
|
9
|
-
import type { AgentConfig } from "
|
|
8
|
+
import { DEFAULT_AGENTS } from "#src/config/default-agents";
|
|
9
|
+
import type { AgentConfig } from "#src/types";
|
|
10
10
|
|
|
11
11
|
// ── AgentConfigLookup interface ──────────────────────────────────────────────
|
|
12
12
|
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
6
6
|
import { basename, join } from "node:path";
|
|
7
7
|
import { getAgentDir, parseFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { BUILTIN_TOOL_NAMES } from "
|
|
9
|
-
import { debugLog } from "
|
|
10
|
-
import type { AgentConfig, MemoryScope, ThinkingLevel } from "
|
|
8
|
+
import { BUILTIN_TOOL_NAMES } from "#src/config/agent-types";
|
|
9
|
+
import { debugLog } from "#src/debug";
|
|
10
|
+
import type { AgentConfig, MemoryScope, ThinkingLevel } from "#src/types";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Scan for custom agent .md files from multiple locations.
|
package/src/handlers/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { SessionLifecycleHandler } from "
|
|
2
|
-
export { ToolStartHandler } from "
|
|
1
|
+
export { SessionLifecycleHandler } from "#src/handlers/lifecycle";
|
|
2
|
+
export { ToolStartHandler } from "#src/handlers/tool-start";
|