@gotgenes/pi-subagents 7.3.0 → 7.3.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 +29 -0
- package/docs/architecture/architecture.md +148 -60
- package/docs/architecture/history/phase-12-complexity-test-fixtures.md +55 -0
- package/docs/plans/0208-extract-shared-test-fixtures.md +298 -0
- package/docs/plans/0214-convert-remaining-closure-factories-to-classes.md +261 -0
- package/docs/retro/0207-decompose-agent-widget-update.md +36 -0
- package/docs/retro/0208-extract-shared-test-fixtures.md +102 -0
- package/docs/retro/0214-convert-remaining-closure-factories-to-classes.md +40 -0
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/service/service-adapter.ts +76 -76
- package/src/ui/agent-config-editor.ts +56 -56
- package/src/ui/agent-creation-wizard.ts +28 -36
- package/src/ui/agent-menu.ts +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [7.3.2](https://github.com/gotgenes/pi-packages/compare/pi-subagents-v7.3.1...pi-subagents-v7.3.2) (2026-05-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Documentation
|
|
12
|
+
|
|
13
|
+
* mark Phase 13 Step 1 complete ([8d62590](https://github.com/gotgenes/pi-packages/commit/8d62590aeded8aba25df96ea2fbba6581572eaf7))
|
|
14
|
+
* **pi-subagents:** link Phase 13 issues [#214](https://github.com/gotgenes/pi-packages/issues/214)–[#219](https://github.com/gotgenes/pi-packages/issues/219) in architecture roadmap ([636a1e5](https://github.com/gotgenes/pi-packages/commit/636a1e500319b9ce1007c0a571dd13199cdd2606))
|
|
15
|
+
* **pi-subagents:** propose Phase 13 improvement roadmap ([caf2a53](https://github.com/gotgenes/pi-packages/commit/caf2a5376c69744db1743a9362096e764d9524b1))
|
|
16
|
+
* plan convert remaining closure factories to classes ([#214](https://github.com/gotgenes/pi-packages/issues/214)) ([2225920](https://github.com/gotgenes/pi-packages/commit/222592007e2ce29d5e6d5678a303f6cb781dae39))
|
|
17
|
+
* **retro:** add planning stage notes for issue [#214](https://github.com/gotgenes/pi-packages/issues/214) ([3072e61](https://github.com/gotgenes/pi-packages/commit/3072e618f08080065ef9f3c7520ff44e8dbc84b4))
|
|
18
|
+
* **retro:** add retro notes for issue [#208](https://github.com/gotgenes/pi-packages/issues/208) ([1436396](https://github.com/gotgenes/pi-packages/commit/1436396d71e79cbbf519877e9dc899000ebd0001))
|
|
19
|
+
* **retro:** add TDD stage notes for issue [#214](https://github.com/gotgenes/pi-packages/issues/214) ([201e1eb](https://github.com/gotgenes/pi-packages/commit/201e1ebbaba66e0d83cc006ef77b711c22fb1bb8))
|
|
20
|
+
|
|
21
|
+
## [7.3.1](https://github.com/gotgenes/pi-packages/compare/pi-subagents-v7.3.0...pi-subagents-v7.3.1) (2026-05-25)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* add parameter type annotations to shared test fixture factories ([2953adc](https://github.com/gotgenes/pi-packages/commit/2953adc5761dd4aa2d3c592ea5f8856161e01e3a))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Documentation
|
|
30
|
+
|
|
31
|
+
* plan extract shared test fixtures ([#208](https://github.com/gotgenes/pi-packages/issues/208)) ([22fafed](https://github.com/gotgenes/pi-packages/commit/22fafed860134f00f1b5d6cb7c87fa42be7dcf09))
|
|
32
|
+
* **retro:** add planning stage notes for issue [#208](https://github.com/gotgenes/pi-packages/issues/208) ([aaa9d5d](https://github.com/gotgenes/pi-packages/commit/aaa9d5d0a4654b2ebb25a7ad4d11a3a54db7c206))
|
|
33
|
+
* **retro:** add retro notes for issue [#207](https://github.com/gotgenes/pi-packages/issues/207) ([3b97a5c](https://github.com/gotgenes/pi-packages/commit/3b97a5c5b3fbb98a78ba280fbdbbdf55f61d82fc))
|
|
34
|
+
* **retro:** add TDD stage notes for issue [#208](https://github.com/gotgenes/pi-packages/issues/208) ([65d0606](https://github.com/gotgenes/pi-packages/commit/65d0606167e531518bd8de4d33f91c6080e21723))
|
|
35
|
+
* update Phase 12 Step 4 to reference test/helpers/ ([8e9e406](https://github.com/gotgenes/pi-packages/commit/8e9e406bfe12487f67363b223d037664f842acce))
|
|
36
|
+
|
|
8
37
|
## [7.3.0](https://github.com/gotgenes/pi-packages/compare/pi-subagents-v7.2.8...pi-subagents-v7.3.0) (2026-05-25)
|
|
9
38
|
|
|
10
39
|
|
|
@@ -431,36 +431,38 @@ These are fire-and-forget broadcast events — no request IDs, no reply channels
|
|
|
431
431
|
|
|
432
432
|
### Health metrics
|
|
433
433
|
|
|
434
|
-
| Metric
|
|
435
|
-
|
|
|
436
|
-
| Health score
|
|
437
|
-
| Total LOC
|
|
438
|
-
|
|
|
439
|
-
|
|
|
440
|
-
|
|
|
441
|
-
|
|
|
442
|
-
|
|
|
443
|
-
|
|
|
434
|
+
| Metric | Value |
|
|
435
|
+
| -------------------------- | ------------------------------------ |
|
|
436
|
+
| Health score | 78/100 (B) |
|
|
437
|
+
| Total LOC | 8,180 (53 files) |
|
|
438
|
+
| Test LOC | 12,026 |
|
|
439
|
+
| Dead code | 0 files, 0 exports |
|
|
440
|
+
| Maintainability index | 90.7 (good) |
|
|
441
|
+
| Avg cyclomatic complexity | 1.5 |
|
|
442
|
+
| P90 cyclomatic complexity | 2 |
|
|
443
|
+
| Production duplication | 20 lines (1 clone group) |
|
|
444
|
+
| Test duplication | 59 clone groups, 1,046 lines |
|
|
445
|
+
| Fallow refactoring targets | 1 (buildParentContext, cognitive 30) |
|
|
444
446
|
|
|
445
447
|
### Dependency bag inventory
|
|
446
448
|
|
|
447
449
|
These interfaces carry hidden dependencies that obscure true coupling.
|
|
448
450
|
Bags with 10+ fields are the highest priority for decomposition.
|
|
449
451
|
|
|
450
|
-
| Interface | Fields | Consumers | Severity
|
|
451
|
-
| --------------------------- | ------------------------------------------------------ | ------------------------------------------------- |
|
|
452
|
-
| `ResolvedSpawnConfig` | 3 nested | foreground-runner, background-spawner, agent-tool | ✓ done
|
|
453
|
-
| `AgentSpawnConfig` | 13 → 13 (ParentSessionInfo nested) | agent-manager (internal) | ✓ done
|
|
454
|
-
| `RunOptions` | 9 (`RunContext` nested) | agent-runner | ✓ done
|
|
455
|
-
| `SessionConfig` | 8 (ToolFilterConfig nested) | agent-runner (output of assembler) | ✓ done
|
|
456
|
-
| `NotificationDetails` | 10 | notification |
|
|
457
|
-
| `ResourceLoaderOptions` | 10 | agent-runner (SDK bridge) |
|
|
458
|
-
| `RunnerIO` | split → `EnvironmentIO` (3) + `SessionFactoryIO` (5+1) | agent-runner | ✓ done
|
|
459
|
-
| `CreateSessionOptions` | 9 | agent-runner (SDK bridge) |
|
|
460
|
-
| `AgentToolDeps` | 8 | agent-tool | ✓ done
|
|
461
|
-
| `AgentMenuDeps` | 8 | agent-menu |
|
|
462
|
-
| `ConversationViewerOptions` | 8 | conversation-viewer | Low
|
|
463
|
-
| `AgentRecordInit` | 8 | agent-record | Low
|
|
452
|
+
| Interface | Fields | Consumers | Severity |
|
|
453
|
+
| --------------------------- | ------------------------------------------------------ | ------------------------------------------------- | --------- |
|
|
454
|
+
| `ResolvedSpawnConfig` | 3 nested | foreground-runner, background-spawner, agent-tool | ✓ done |
|
|
455
|
+
| `AgentSpawnConfig` | 13 → 13 (ParentSessionInfo nested) | agent-manager (internal) | ✓ done |
|
|
456
|
+
| `RunOptions` | 9 (`RunContext` nested) | agent-runner | ✓ done |
|
|
457
|
+
| `SessionConfig` | 8 (ToolFilterConfig nested) | agent-runner (output of assembler) | ✓ done |
|
|
458
|
+
| `NotificationDetails` | 10 | notification | Low (DTO) |
|
|
459
|
+
| `ResourceLoaderOptions` | 10 | agent-runner (SDK bridge) | Low (SDK) |
|
|
460
|
+
| `RunnerIO` | split → `EnvironmentIO` (3) + `SessionFactoryIO` (5+1) | agent-runner | ✓ done |
|
|
461
|
+
| `CreateSessionOptions` | 9 | agent-runner (SDK bridge) | Low (SDK) |
|
|
462
|
+
| `AgentToolDeps` | 8 | agent-tool | ✓ done |
|
|
463
|
+
| `AgentMenuDeps` | 8 | agent-menu | ✓ done |
|
|
464
|
+
| `ConversationViewerOptions` | 8 | conversation-viewer | Low |
|
|
465
|
+
| `AgentRecordInit` | 8 | agent-record | Low |
|
|
464
466
|
|
|
465
467
|
### Complexity hotspots
|
|
466
468
|
|
|
@@ -472,18 +474,22 @@ No functions remain above the critical threshold — all hotspots resolved in Ph
|
|
|
472
474
|
|
|
473
475
|
Files with highest commit frequency × complexity (accelerating trend):
|
|
474
476
|
|
|
475
|
-
| Score | File
|
|
476
|
-
| ----- |
|
|
477
|
-
|
|
|
478
|
-
|
|
|
479
|
-
|
|
|
480
|
-
|
|
|
477
|
+
| Score | File | Commits | Trend |
|
|
478
|
+
| ----- | --------------------------- | ------- | -------------- |
|
|
479
|
+
| 43.3 | `index.ts` | 81 | ▲ accelerating |
|
|
480
|
+
| 26.0 | `ui/agent-menu.ts` | 33 | ▲ accelerating |
|
|
481
|
+
| 13.6 | `tools/agent-tool.ts` | 41 | ▲ accelerating |
|
|
482
|
+
| 13.3 | `ui/conversation-viewer.ts` | 16 | ▲ accelerating |
|
|
483
|
+
| 12.6 | `ui/agent-config-editor.ts` | 10 | ▼ cooling |
|
|
484
|
+
| 11.7 | `ui/agent-widget.ts` | 14 | ▲ accelerating |
|
|
485
|
+
|
|
486
|
+
Note: accelerating trends reflect recent refactoring phases, not feature churn.
|
|
487
|
+
Once structural work stabilizes, these are expected to cool.
|
|
481
488
|
|
|
482
489
|
### Production duplication
|
|
483
490
|
|
|
484
|
-
The
|
|
485
|
-
|
|
486
|
-
No known production duplication remains.
|
|
491
|
+
The prior clone group between `agent-runner.ts` and `message-formatters.ts` was resolved in #172.
|
|
492
|
+
One 20-line clone group remains between `agent-config-editor.ts:138–151` and `agent-creation-wizard.ts:231–250` — both implement the same overwrite-guard + write + reload + notify pattern.
|
|
487
493
|
|
|
488
494
|
### Proposed bag decompositions
|
|
489
495
|
|
|
@@ -600,51 +606,125 @@ Phase 11 converted all closure factories to classes, eliminating adapter closure
|
|
|
600
606
|
Four layers: SessionContext typing → runtime query methods → interface alignment → class conversions → index.ts simplification.
|
|
601
607
|
See [phase-11-closure-to-class.md](history/phase-11-closure-to-class.md) for details.
|
|
602
608
|
|
|
603
|
-
##
|
|
609
|
+
## Phase 12 (complete)
|
|
610
|
+
|
|
611
|
+
Phase 12 decomposed the three remaining high-complexity UI functions and extracted shared test fixtures.
|
|
612
|
+
All four steps are closed: [#205], [#206], [#207], [#208].
|
|
613
|
+
|
|
614
|
+
## Improvement roadmap (Phase 13)
|
|
615
|
+
|
|
616
|
+
Phase 13 addresses the remaining fallow refactoring target, `agent-manager.ts` oversized method, production duplication, SDK boundary coupling, and the heaviest test clone families.
|
|
617
|
+
Health score target: 80+ (A).
|
|
618
|
+
|
|
619
|
+
### Findings summary
|
|
620
|
+
|
|
621
|
+
| Finding | Category | Impact | Risk | Priority |
|
|
622
|
+
| ---------------------------------------------------------------- | -------------- | ------ | ---- | -------- |
|
|
623
|
+
| 3 remaining closure factories (Phase 11 survivors) | C: Coupling | 4 | 2 | 16 |
|
|
624
|
+
| `buildParentContext` cognitive 30 (only fallow target) | B: Oversized | 3 | 1 | 15 |
|
|
625
|
+
| `startAgent` in agent-manager.ts (~130 LOC method) | B: Oversized | 4 | 3 | 12 |
|
|
626
|
+
| Test duplication: 59 clone groups, 1,046 lines | D: Testability | 3 | 2 | 12 |
|
|
627
|
+
| Overwrite guard duplicated across UI modules (20 lines) | A: Redundant | 2 | 1 | 10 |
|
|
628
|
+
| `settings.ts` calls SDK function `getAgentDir()` at module level | C: Coupling | 2 | 1 | 10 |
|
|
629
|
+
|
|
630
|
+
### Step 1: Convert remaining closure factories to classes — [#214] ✓
|
|
631
|
+
|
|
632
|
+
Three closure factories converted to classes in [#214].
|
|
633
|
+
|
|
634
|
+
| Factory → Class | File | Captures |
|
|
635
|
+
| ------------------------------------------------------ | ----------------------------- | ---------------------------------------- |
|
|
636
|
+
| `createAgentConfigEditor()` → `AgentConfigEditor` | `ui/agent-config-editor.ts` | `fileOps`, `registry`, 2 dirs |
|
|
637
|
+
| `createAgentCreationWizard()` → `AgentCreationWizard` | `ui/agent-creation-wizard.ts` | `fileOps`, `manager`, `registry`, 2 dirs |
|
|
638
|
+
| `createSubagentsService()` → `SubagentsServiceAdapter` | `service/service-adapter.ts` | `manager`, `resolveModel`, `runtime` |
|
|
639
|
+
|
|
640
|
+
- Smell: C (coupling — deps hidden in closure scope instead of explicit on class)
|
|
641
|
+
- Outcome: 0 remaining closure factories (excluding pure-function factories), deps visible as constructor parameters
|
|
604
642
|
|
|
605
|
-
|
|
606
|
-
These are independent of Phase 11 and can proceed in parallel if desired.
|
|
643
|
+
### Step 2: Decompose `buildParentContext` (cognitive 30) — [#215]
|
|
607
644
|
|
|
608
|
-
|
|
645
|
+
`buildParentContext` in `session/context.ts` is the only remaining fallow refactoring target.
|
|
646
|
+
The function loops over branch entries with 3 type-check branches, each with sub-branches for role or summary.
|
|
647
|
+
Extract per-entry-type formatters: `formatMessageEntry(entry)` and `formatCompactionEntry(entry)`.
|
|
609
648
|
|
|
610
|
-
|
|
611
|
-
|
|
649
|
+
- Target: `src/session/context.ts`
|
|
650
|
+
- Smell: B (oversized function)
|
|
651
|
+
- Outcome: cognitive complexity < 10, function < 15 LOC
|
|
612
652
|
|
|
613
|
-
|
|
614
|
-
- Outcome: cognitive complexity < 10
|
|
653
|
+
### Step 3: Decompose `startAgent` in `agent-manager.ts` — [#216]
|
|
615
654
|
|
|
616
|
-
|
|
655
|
+
`startAgent` is a ~130-line private method that chains worktree setup → state transitions → observer notification → abort-signal wiring → runner invocation → `.then()` completion handler (~35 lines) → `.catch()` error handler (~15 lines).
|
|
656
|
+
Both the `.then()` and `.catch()` blocks share common finalization logic (background counter decrement, observer notification, queue drain, worktree cleanup, detach signal).
|
|
617
657
|
|
|
618
|
-
|
|
619
|
-
Extract sub-functions per menu action.
|
|
658
|
+
Extract:
|
|
620
659
|
|
|
621
|
-
|
|
622
|
-
|
|
660
|
+
1. `handleRunCompletion(record, options, result)` — worktree cleanup, state transition, execution update, observer notification.
|
|
661
|
+
2. `handleRunError(record, options, err)` — error marking, worktree cleanup.
|
|
662
|
+
3. `finalizeBackgroundRun(record)` — shared `runningBackground--`, observer, `drainQueue()`.
|
|
623
663
|
|
|
624
|
-
|
|
664
|
+
- Target: `src/lifecycle/agent-manager.ts`
|
|
665
|
+
- Smell: B (oversized method) + A (duplicated finalization logic in then/catch)
|
|
666
|
+
- Outcome: no method > 40 LOC, `agent-manager.ts` < 480 LOC
|
|
625
667
|
|
|
626
|
-
|
|
627
|
-
Extract `assembleWidgetState` (pure) and timer management.
|
|
668
|
+
### Step 4: Extract overwrite guard from UI — [#217]
|
|
628
669
|
|
|
629
|
-
-
|
|
630
|
-
|
|
670
|
+
The 20-line pattern duplicated between `agent-config-editor.ts:138–151` and `agent-creation-wizard.ts:231–250` checks file existence, prompts for confirmation, writes the file, reloads the registry, and notifies the user.
|
|
671
|
+
Extract a shared `writeAgentFile(fileOps, ui, registry, targetPath, content, label)` function.
|
|
631
672
|
|
|
632
|
-
|
|
673
|
+
- Target: new `src/ui/agent-file-writer.ts`, consumers `src/ui/agent-config-editor.ts` and `src/ui/agent-creation-wizard.ts`
|
|
674
|
+
- Smell: A (production duplication)
|
|
675
|
+
- Outcome: 0 production clone groups
|
|
633
676
|
|
|
634
|
-
|
|
677
|
+
### Step 5: Push SDK boundary in `settings.ts` — [#218]
|
|
635
678
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
679
|
+
`globalPath()` calls `getAgentDir()` (a Pi SDK function) at invocation time.
|
|
680
|
+
This hides a platform dependency inside a module that is otherwise pure configuration logic.
|
|
681
|
+
Inject `agentDir: string` as a constructor parameter to `SettingsManager` and pass the global settings path from the boundary in `index.ts`.
|
|
682
|
+
|
|
683
|
+
- Target: `src/settings.ts`, `src/index.ts`
|
|
684
|
+
- Smell: C (platform type threading)
|
|
685
|
+
- Outcome: `settings.ts` has 0 Pi SDK imports, `loadSettings`/`saveSettings` become fully testable without SDK stubs
|
|
686
|
+
|
|
687
|
+
### Step 6: Reduce test duplication — top 3 clone families — [#219]
|
|
688
|
+
|
|
689
|
+
The three heaviest remaining clone families after Phase 12:
|
|
690
|
+
|
|
691
|
+
1. `agent-manager.test.ts` — 16 clone groups, 160 duplicated lines.
|
|
692
|
+
Extract shared setup/assertion helpers into `test/helpers/manager-stubs.ts`.
|
|
693
|
+
2. `conversation-viewer.test.ts` — 8 clone groups, 91 duplicated lines.
|
|
694
|
+
Extract entry-builder helpers into existing `test/helpers/` or inline factory.
|
|
695
|
+
3. `agent-config-editor.test.ts` — 5 clone groups, 42 duplicated lines.
|
|
696
|
+
Extract shared setup helpers.
|
|
697
|
+
|
|
698
|
+
- Target: `test/lifecycle/agent-manager.test.ts`, `test/conversation-viewer.test.ts`, `test/ui/agent-config-editor.test.ts`
|
|
699
|
+
- Smell: D (test duplication)
|
|
700
|
+
- Outcome: test duplication reduced by ~200 lines (from 1,046 to < 850)
|
|
701
|
+
|
|
702
|
+
### Step dependency diagram
|
|
703
|
+
|
|
704
|
+
```mermaid
|
|
705
|
+
flowchart LR
|
|
706
|
+
S1["Step 1\nclosure to class"]
|
|
707
|
+
S2["Step 2\nbuildParentContext"]
|
|
708
|
+
S3["Step 3\nstartAgent decomp"]
|
|
709
|
+
S4["Step 4\noverwrite guard"]
|
|
710
|
+
S5["Step 5\nsettings SDK"]
|
|
711
|
+
S6["Step 6\ntest duplication"]
|
|
712
|
+
|
|
713
|
+
S1 --> S4
|
|
714
|
+
S1 --> S6
|
|
715
|
+
S3 --> S6
|
|
716
|
+
S2 ~~~ S5
|
|
717
|
+
```
|
|
639
718
|
|
|
640
|
-
|
|
719
|
+
### Tracks
|
|
641
720
|
|
|
642
|
-
|
|
643
|
-
|
|
721
|
+
1. **Track A — Structural** (Steps 1, 3): closure-to-class conversions and method decomposition.
|
|
722
|
+
2. **Track B — Complexity and coupling** (Steps 2, 5): independent, can proceed in parallel with Track A.
|
|
723
|
+
3. **Track C — Duplication** (Steps 4, 6): Step 4 depends on Step 1 (overwrite guard lives in files being converted); Step 6 depends on Steps 1 and 3 (production code they test changes first).
|
|
644
724
|
|
|
645
725
|
## Refactoring history
|
|
646
726
|
|
|
647
|
-
Phases 1–5 and 7–
|
|
727
|
+
Phases 1–5 and 7–12 are complete.
|
|
648
728
|
Phase 6 (UI extraction to a separate package) is deferred.
|
|
649
729
|
Detailed records are preserved in per-phase history files:
|
|
650
730
|
|
|
@@ -661,6 +741,7 @@ Detailed records are preserved in per-phase history files:
|
|
|
661
741
|
| 9 | Observation consolidation, ctx elimination | Complete | [phase-9-observation-ctx.md](history/phase-9-observation-ctx.md) |
|
|
662
742
|
| 10 | Domain organization, bag decomposition, complexity | Complete | [phase-10-structural-decomposition.md](history/phase-10-structural-decomposition.md) |
|
|
663
743
|
| 11 | Closure factories to classes | Complete | [phase-11-closure-to-class.md](history/phase-11-closure-to-class.md) |
|
|
744
|
+
| 12 | Complexity reduction and test fixture extraction | Complete | [phase-12-complexity-test-fixtures.md](history/phase-12-complexity-test-fixtures.md) |
|
|
664
745
|
|
|
665
746
|
### Structural refactoring issues
|
|
666
747
|
|
|
@@ -677,6 +758,7 @@ Detailed records are preserved in per-phase history files:
|
|
|
677
758
|
| Phase 10 | #164, #165, #166, #167, #168, #169, #170, #171, #172 | Domain directories, ResolvedSpawnConfig, ParentSessionInfo, RunnerIO split, ToolFilterConfig, RunContext, buildContentLines, renderResult, content-items |
|
|
678
759
|
| Phase 11 | #192, #193, #194, #195, #196 | SessionContext, runtime queries, interface alignment, tool classes, runner/menu classes, index.ts simplification |
|
|
679
760
|
| Phase 12 | #205, #206, #207, #208 | renderWidgetLines, showAgentDetail, widget update, shared test fixtures |
|
|
761
|
+
| Phase 13 | #214, #215, #216, #217, #218, #219 | Closure-to-class, buildParentContext, startAgent decomp, overwrite guard, settings SDK, test duplication |
|
|
680
762
|
|
|
681
763
|
The remaining open issue is #22 (parent-session resolution), a cross-extension track that does not gate the structural work.
|
|
682
764
|
|
|
@@ -704,3 +786,9 @@ The upstream test suite is run periodically as a regression canary for the agent
|
|
|
704
786
|
[#206]: https://github.com/gotgenes/pi-packages/issues/206
|
|
705
787
|
[#207]: https://github.com/gotgenes/pi-packages/issues/207
|
|
706
788
|
[#208]: https://github.com/gotgenes/pi-packages/issues/208
|
|
789
|
+
[#214]: https://github.com/gotgenes/pi-packages/issues/214
|
|
790
|
+
[#215]: https://github.com/gotgenes/pi-packages/issues/215
|
|
791
|
+
[#216]: https://github.com/gotgenes/pi-packages/issues/216
|
|
792
|
+
[#217]: https://github.com/gotgenes/pi-packages/issues/217
|
|
793
|
+
[#218]: https://github.com/gotgenes/pi-packages/issues/218
|
|
794
|
+
[#219]: https://github.com/gotgenes/pi-packages/issues/219
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Phase 12: Complexity reduction and test fixture extraction
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Phase 12 decomposed the three remaining high-complexity UI functions and extracted shared test fixtures into `test/helpers/`.
|
|
6
|
+
|
|
7
|
+
## Steps
|
|
8
|
+
|
|
9
|
+
### Step 1: Decompose `renderWidgetLines` (cognitive 44) — [#205]
|
|
10
|
+
|
|
11
|
+
`renderWidgetLines` in `ui/widget-renderer.ts` handled agent-status formatting, tree connectors, overflow, and empty states.
|
|
12
|
+
Extracted per-status renderers and a tree-connector utility.
|
|
13
|
+
|
|
14
|
+
- Target: `src/ui/widget-renderer.ts`
|
|
15
|
+
- Outcome: cognitive complexity < 10
|
|
16
|
+
|
|
17
|
+
### Step 2: Decompose `showAgentDetail` (cognitive 33) — [#206]
|
|
18
|
+
|
|
19
|
+
`showAgentDetail` in `ui/agent-config-editor.ts` handled display, edit, eject, and delete flows.
|
|
20
|
+
Extracted sub-functions per menu action.
|
|
21
|
+
|
|
22
|
+
- Target: `src/ui/agent-config-editor.ts`
|
|
23
|
+
- Outcome: cognitive complexity < 10
|
|
24
|
+
|
|
25
|
+
### Step 3: Decompose `update` in `agent-widget.ts` (cognitive 31) — [#207]
|
|
26
|
+
|
|
27
|
+
`update` mixed timer lifecycle, agent list assembly, render delegation, and visibility state.
|
|
28
|
+
Extracted `assembleWidgetState` (pure) and timer management.
|
|
29
|
+
|
|
30
|
+
- Target: `src/ui/agent-widget.ts`
|
|
31
|
+
- Outcome: cognitive complexity < 10
|
|
32
|
+
|
|
33
|
+
### Step 4: Extract shared test fixtures — [#208]
|
|
34
|
+
|
|
35
|
+
The 3 heaviest clone families:
|
|
36
|
+
|
|
37
|
+
- `agent-runner.test.ts` + `agent-runner-extension-tools.test.ts` (60-line shared setup)
|
|
38
|
+
- `agent-menu.test.ts` + `agent-creation-wizard.test.ts` + `agent-config-editor.test.ts` (54+51+24 lines)
|
|
39
|
+
- `agent-manager.test.ts` (18 internal clone groups, 210 duplicated lines)
|
|
40
|
+
|
|
41
|
+
Extracted shared factories into `test/helpers/runner-io.ts` and `test/helpers/ui-stubs.ts`.
|
|
42
|
+
Test duplication reduced from 71 clone groups (1,424 lines) to 59 clone groups (1,046 lines).
|
|
43
|
+
|
|
44
|
+
## Metrics change
|
|
45
|
+
|
|
46
|
+
| Metric | Before | After |
|
|
47
|
+
| -------------------------- | ---------------------- | ---------------------- |
|
|
48
|
+
| Health score | 75/100 (B) | 78/100 (B) |
|
|
49
|
+
| Fallow refactoring targets | 4 | 1 |
|
|
50
|
+
| Test duplication | 71 groups, 1,424 lines | 59 groups, 1,046 lines |
|
|
51
|
+
|
|
52
|
+
[#205]: https://github.com/gotgenes/pi-packages/issues/205
|
|
53
|
+
[#206]: https://github.com/gotgenes/pi-packages/issues/206
|
|
54
|
+
[#207]: https://github.com/gotgenes/pi-packages/issues/207
|
|
55
|
+
[#208]: https://github.com/gotgenes/pi-packages/issues/208
|