22 KiB
DxDesigner Part Replacement Trial Task Center Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Deliver a packaged Windows DxPartReplace.exe that manages replacement tasks, scans and selects .prj projects, edits Part Number mappings, guides one-project-at-a-time native replacement, compares fresh before/after probe evidence, advances verified projects to Completed, and records complete operational and crash logs.
Architecture: A PySide6 desktop shell calls a Qt-free service layer. SQLite stores mutable task drafts and project state, append-only JSONL plus rotating text logs preserve diagnostics, and a pure comparison module validates before/after probe profiles. The first release never automates or writes DxDesigner; it waits for operator-created read-only profiles and verifies them before advancing the queue.
Tech Stack: Python 3.12, PySide6 6.x, SQLite, pytest 8.x, pytest-qt 4.x, PyInstaller 6.x, JSON/JSONL, PowerShell 5.1-compatible packaging script.
Spec: docs/superpowers/specs/2026-09-04-dxdesigner-part-replacement-trial-task-center-design.md
Global Constraints
- Release classification remains
evaluation-only. - Operate only on complete disposable project copies.
- Match replacement rules exclusively by
Part Number; do not impose a material-number regular expression. - Do not invoke
SendKeys, UI coordinates, blind delays, automatic save, rewiring, or any DxDesigner design setter. - Do not bypass the production certification or compatibility-profile gates.
- Task deletion is soft deletion and never deletes engineering files or evidence trees.
- A project reaches
completedonly after a fresh, exact-project before/after comparison has no hard failures. - Application logging starts before the main window is constructed and captures uncaught main-thread and worker-thread exceptions.
- Preserve all pre-existing dirty-worktree changes outside the files named by a task.
Task 1: Task Records, SQLite CRUD, and Diagnostic Logging
Files:
- Create:
src/dx_productivity/trial_task_center/__init__.py - Create:
src/dx_productivity/trial_task_center/models.py - Create:
src/dx_productivity/trial_task_center/errors.py - Create:
src/dx_productivity/trial_task_center/store.py - Create:
src/dx_productivity/trial_task_center/logging_setup.py - Create:
tests/trial_task_center/test_store.py - Create:
tests/trial_task_center/test_logging_setup.py
Interfaces:
-
Produces:
TaskStatus,ProjectStatus,TaskRecord,RuleRecord,ProjectRecord,TaskCenterError. -
Produces:
TaskStore(path: Path)with task/rule/project CRUD and transactional state changes. -
Produces:
configure_logging(root: Path) -> LoggingContext,install_exception_hooks(context), andappend_task_event(...). -
Consumes: no Qt and no DxDesigner API.
-
Step 1: Write failing model and CRUD tests
Define tests that require these exact public records and methods:
class TaskStatus(str, Enum):
DRAFT = "draft"
READY = "ready"
RUNNING = "running"
PAUSED = "paused"
COMPLETED = "completed"
FAILED = "failed"
DELETED = "deleted"
class ProjectStatus(str, Enum):
PENDING = "pending"
CAPTURING_BEFORE = "capturing_before"
AWAITING_OPERATOR = "awaiting_operator"
CAPTURING_AFTER = "capturing_after"
VERIFYING = "verifying"
COMPLETED = "completed"
FAILED = "failed"
SKIPPED = "skipped"
store = TaskStore(tmp_path / "task-center.db")
task = store.create_task("试验任务", note="first")
assert store.get_task(task.task_id).name == "试验任务"
renamed = store.update_task(task.task_id, name="单项目替换", note="updated")
assert renamed.updated_utc > task.updated_utc
store.soft_delete_task(task.task_id)
assert store.list_tasks(TaskStatus.DELETED)[0].task_id == task.task_id
store.restore_task(task.task_id)
Add tests for unique nonblank names, running-task deletion rejection, rule add/edit/delete/reorder/enable, project upsert with selection preservation, unavailable rescan records, state transitions, transaction rollback, schema reopening, and crash recovery of capturing_*/verifying to a paused task plus failed project with an interruption error.
- Step 2: Run the focused tests and verify RED
Run:
$env:PYTHONPATH=(Resolve-Path 'src').Path
py -3.12 -m pytest tests/trial_task_center/test_store.py -q
Expected: collection/import failure because the package does not exist.
- Step 3: Implement immutable records and stable errors
Use frozen slotted dataclasses. TaskCenterError contains code, message, and a generated error_id with the format DXT-YYYYMMDD-<8 uppercase hex characters>. Keep user text separate from traceback detail.
- Step 4: Implement SQLite schema version 1 and CRUD
Create tasks, rules, projects, and metadata tables with foreign keys enabled, explicit ordered rule positions, canonical unique project paths per task, UTC ISO timestamps, and transaction-scoped writes. Public methods return records rather than SQLite rows. Provide at least:
create_task(name: str, note: str = "") -> TaskRecord
get_task(task_id: str) -> TaskRecord
list_tasks(status: TaskStatus | None = None) -> tuple[TaskRecord, ...]
update_task(task_id: str, *, name: str, note: str) -> TaskRecord
soft_delete_task(task_id: str) -> TaskRecord
restore_task(task_id: str) -> TaskRecord
add_rule(task_id: str, old_part_number: str, new_part_number: str) -> RuleRecord
update_rule(rule_id: str, *, old_part_number: str, new_part_number: str, enabled: bool) -> RuleRecord
delete_rule(rule_id: str) -> None
move_rule(rule_id: str, offset: int) -> tuple[RuleRecord, ...]
list_rules(task_id: str) -> tuple[RuleRecord, ...]
sync_projects(task_id: str, discovery_root: Path, paths: Sequence[Path]) -> tuple[ProjectRecord, ...]
set_project_selected(project_id: str, selected: bool) -> ProjectRecord
set_project_status(project_id: str, status: ProjectStatus, *, error_id: str | None = None, summary: str = "") -> ProjectRecord
list_projects(task_id: str) -> tuple[ProjectRecord, ...]
recover_interrupted_work() -> tuple[str, ...]
Validate the complete enabled rule set after each rule mutation by adapting parse_mapping_bytes; roll back a mutation that creates a duplicate source, self-map, chain, or cycle.
- Step 5: Write logging tests and verify RED
Tests must assert a 5 MiB rotating UTF-8 application log with five backups, structured task-event keys, flush-before-return, traceback capture, stdout/stderr capture helper behavior, and a thread exception reaching application.log with its error ID.
- Step 6: Implement logging before UI construction
configure_logging creates paths and handlers without importing Qt. install_exception_hooks installs sys.excepthook and threading.excepthook. append_task_event appends canonical one-line JSON using os.fsync and keys:
sequence,timestamp_utc,level,task_id,project_id,operation,
state_before,state_after,error_id,message,details
- Step 7: Run focused tests
Run:
$env:PYTHONPATH=(Resolve-Path 'src').Path
py -3.12 -m pytest tests/trial_task_center/test_store.py tests/trial_task_center/test_logging_setup.py -q
Expected: all pass.
- Step 8: Commit Task 1
git add src/dx_productivity/trial_task_center tests/trial_task_center/test_store.py tests/trial_task_center/test_logging_setup.py
git commit -m "feat: add trial task storage and diagnostics"
Task 2: Project Scanning, Probe Evidence, and Replacement Comparison
Files:
- Create:
src/dx_productivity/trial_task_center/scanner.py - Create:
src/dx_productivity/trial_task_center/evidence.py - Create:
src/dx_productivity/trial_task_center/comparison.py - Create:
tests/trial_task_center/test_scanner.py - Create:
tests/trial_task_center/test_evidence.py - Create:
tests/trial_task_center/test_comparison.py - Create:
tests/fixtures/trial_task_center/profile-before.json - Create:
tests/fixtures/trial_task_center/profile-after-valid.json - Create:
tests/fixtures/trial_task_center/profile-after-invalid.json
Interfaces:
-
Consumes:
MappingRulefromdx_productivity.part_replace.modelsand project identity rules from existing input helpers. -
Produces:
scan_projects(root: Path) -> tuple[Path, ...]. -
Produces:
ProbeStamp,CapturedProfile,profile_stamp, andcapture_profile. -
Produces:
ComparisonIssue,ProjectComparison,compare_profiles. -
No Qt, SQLite, or design mutation.
-
Step 1: Write scanner tests and verify RED
Tests cover recursive case-insensitive .prj discovery, canonical deterministic ordering, duplicate path identities, nonexistent/not-directory roots, inaccessible subtrees as explicit errors, and no filesystem writes.
- Step 2: Implement the scanner adapter
Reuse discover_projects(root, (".prj",)). Convert InputError into TaskCenterError without discarding its stable code. Never select newly discovered projects automatically.
- Step 3: Write evidence tests and verify RED
Require these signatures:
@dataclass(frozen=True, slots=True)
class ProbeStamp:
size: int
modified_ns: int
sha256: str
@dataclass(frozen=True, slots=True)
class CapturedProfile:
source: Path
destination: Path
stamp: ProbeStamp
project_identity: str
data: Mapping[str, object]
def profile_stamp(path: Path) -> ProbeStamp | None: ...
def capture_profile(source: Path, destination: Path, expected_project: Path,
previous: ProbeStamp | None) -> CapturedProfile: ...
Tests reject missing, unchanged, corrupt, duplicate-key, wrong-version, and wrong-project profiles. Accept only a profile whose bytes or timestamp changed and whose canonical identity matches. Assert atomic destination publication and exact SHA-256.
- Step 4: Implement evidence capture
Open and hash one stable byte snapshot, parse JSON with duplicate-key rejection, require format_version == 1, require project.identity string equality after Windows canonicalization, and write the accepted bytes atomically. Do not delete or rename the source menu-probe file.
- Step 5: Write comparison tests and verify RED
Require:
def compare_profiles(
before: Mapping[str, object],
after: Mapping[str, object],
rules: Sequence[MappingRule],
) -> ProjectComparison: ...
ProjectComparison includes passed, matched logical identities per rule, warnings, hard issues, and canonical JSON serialization. Tests cover representative material numbers, no-match warnings, two rules, existing target parts, target mismatch, missing/duplicate logical identity, changed RefDes/hierarchy/unit count/origin/position/rotation/mirror/pins/nets, unrelated changes, and unsupported parameter-presentation capability warnings.
- Step 6: Implement strict profile comparison
Build unique maps by logical_identity. Match before Part Numbers with trimmed case-insensitive comparison while preserving exact display strings. For each matched identity, require the after Part Number to match the rule target and compare all trusted protected fields. Compare unrelated components after removing expected Part Number changes. Record Part Label, Value, and parameter_probe differences only as evidence/warnings in this release; never write them.
- Step 7: Run Task 2 tests
$env:PYTHONPATH=(Resolve-Path 'src').Path
py -3.12 -m pytest tests/trial_task_center/test_scanner.py tests/trial_task_center/test_evidence.py tests/trial_task_center/test_comparison.py -q
Expected: all pass.
- Step 8: Commit Task 2
git add src/dx_productivity/trial_task_center tests/trial_task_center tests/fixtures/trial_task_center
git commit -m "feat: compare trial replacement evidence"
Task 3: Trial Runner and Application Service
Files:
- Create:
src/dx_productivity/trial_task_center/runner.py - Create:
src/dx_productivity/trial_task_center/service.py - Create:
tests/trial_task_center/test_runner.py - Create:
tests/trial_task_center/test_service.py
Interfaces:
-
Consumes: Task 1 store/logging and Task 2 scanner/evidence/comparison.
-
Produces:
OperatorInstruction,RunnerSnapshot,TrialRunner, andTaskCenterService. -
Produces synchronous methods designed to be called from a Qt worker; no Qt import.
-
Step 1: Write runner state-machine tests and verify RED
Require the exact action methods:
start_task(task_id: str, *, disposable_copy_confirmed: bool) -> RunnerSnapshot
capture_before(task_id: str, project_id: str, probe_path: Path) -> RunnerSnapshot
confirm_native_attempt(task_id: str, project_id: str) -> RunnerSnapshot
capture_after(task_id: str, project_id: str, probe_path: Path) -> RunnerSnapshot
pause_task(task_id: str) -> RunnerSnapshot
resume_task(task_id: str) -> RunnerSnapshot
retry_project(task_id: str, project_id: str) -> RunnerSnapshot
skip_project(task_id: str, project_id: str) -> RunnerSnapshot
snapshot(task_id: str) -> RunnerSnapshot
Tests cover start gates, exact first selected project, before capture, operator instructions containing project and every matching old/new rule, after capture, verifying transition, passed project completion, automatic next-project selection, task completion, hard comparison failure, pause-before-next behavior, resume, retry with new attempt evidence paths, skip, and process-restart recovery.
- Step 2: Implement the runner
The runner writes a task event before and after every durable state change. It uses per-attempt evidence directories and never overwrites prior profiles. confirm_native_attempt records an operator assertion but cannot mark success. capture_after is the only route to comparison and project completion.
- Step 3: Write service tests and verify RED
Test task CRUD delegation, directory scan preserving prior selection, project select-all/clear, rule validation errors, current instruction, log tailing, and opening evidence paths without actually launching Explorer in tests.
- Step 4: Implement
TaskCenterService
The service is the only interface the UI uses. It converts domain exceptions into TaskCenterError, logs every operation, and exposes tuple snapshots safe for worker-to-UI transfer. Inject path opener and clock dependencies for tests.
- Step 5: Run Tasks 1-3 tests and existing input/profile tests
$env:PYTHONPATH=(Resolve-Path 'src').Path
py -3.12 -m pytest tests/trial_task_center tests/part_replace/test_inputs.py tests/integration/test_part_replace_probe.py -q
Expected: all pass.
- Step 6: Commit Task 3
git add src/dx_productivity/trial_task_center/runner.py src/dx_productivity/trial_task_center/service.py tests/trial_task_center
git commit -m "feat: orchestrate trial replacement tasks"
Task 4: PySide6 Task Center UI
Files:
- Modify:
pyproject.toml - Create:
src/dx_productivity/trial_task_center/ui/__init__.py - Create:
src/dx_productivity/trial_task_center/ui/styles.py - Create:
src/dx_productivity/trial_task_center/ui/workers.py - Create:
src/dx_productivity/trial_task_center/ui/task_list.py - Create:
src/dx_productivity/trial_task_center/ui/project_table.py - Create:
src/dx_productivity/trial_task_center/ui/mapping_table.py - Create:
src/dx_productivity/trial_task_center/ui/run_panel.py - Create:
src/dx_productivity/trial_task_center/ui/main_window.py - Create:
tests/ui/test_trial_task_center_window.py - Create:
tests/ui/test_trial_task_center_workflow.py
Interfaces:
-
Consumes:
TaskCenterServiceonly; widgets do not import SQLite, profile JSON, or DxDesigner modules. -
Produces:
TrialTaskCenterWindow(service: TaskCenterService). -
All filesystem scans and evidence operations execute through
QThreadPool; no UI-thread blocking. -
Step 1: Add runtime and development dependencies
Set project dependencies and extras without loosening Python 3.12:
dependencies = ["PySide6>=6.7,<7"]
dev = [
"pytest>=8,<9", "pytest-cov>=5,<7", "coverage>=7,<8",
"build>=1.2,<2", "pytest-qt>=4.4,<5", "PyInstaller>=6.10,<7"
]
Add script:
dx-part-replace-gui = "dx_productivity.trial_task_center.application:main"
- Step 2: Write shell and CRUD interaction tests and verify RED
With QT_QPA_PLATFORM=offscreen, assert minimum size 1100x700, Active/Completed/Deleted task filters, task create/edit/delete/restore, native directory-picker injection, scan button busy state, project Select All/Clear, mapping add/edit/delete/reorder, disabled Start gates, and stable object names for UI automation.
- Step 3: Implement restrained styles and reusable async workers
Use semantic colors for canvas, surface, border, primary/secondary text, accent, success, warning, danger, and focus. Use 6 px or smaller control radii, 13 px default text, fixed 30-34 px command heights, native/Qt standard icons where available, and tooltips for icon-only actions. Do not use gradients, decorative cards, animation, or viewport-scaled fonts.
workers.py wraps callables in QRunnable and emits success/error/finished signals. Every error reaches logging and restores disabled controls.
- Step 4: Implement task navigation and workspace tables
The left pane is a task list, not cards. The main pane uses a directory toolbar, QTableView project model, mapping table, operator instruction band, action toolbar, and read-only log dock. Use stable column widths plus stretch for paths so text does not overlap. Completed projects disappear from the Pending filter and remain visible through All/Completed.
- Step 5: Implement dialogs and run actions
Task and rule edits use focused modal dialogs with validation messages. Start requires a disposable-copy confirmation dialog naming the selected project count. Capture Before/After shows the expected menu-probe path and calls the service in a worker. Errors show Chinese summary plus stable error ID and buttons to open log/evidence locations.
- Step 6: Run UI tests
$env:PYTHONPATH=(Resolve-Path 'src').Path
$env:QT_QPA_PLATFORM='offscreen'
py -3.12 -m pytest tests/ui/test_trial_task_center_window.py tests/ui/test_trial_task_center_workflow.py -q
Expected: all pass without Qt warnings or worker leaks.
- Step 7: Capture visual QA screenshots
Render populated Active and Completed states at 1100x700 and 1440x900 into .superpowers/visual-qa/trial-task-center/. Inspect for clipping, overlapping controls, unreadable paths, broken icons, hidden required actions, and one-note color use. Iterate until all four images pass.
- Step 8: Commit Task 4
git add pyproject.toml src/dx_productivity/trial_task_center/ui tests/ui
git commit -m "feat: add replacement task center UI"
Task 5: Application Bootstrap, PyInstaller EXE, and Trial Guide
Files:
- Create:
src/dx_productivity/trial_task_center/application.py - Create:
packaging/DxPartReplace.spec - Create:
packaging/Build-DxPartReplace.ps1 - Create:
tests/trial_task_center/test_application.py - Create:
tests/packaging/test_dx_part_replace_build.py - Create:
docs/user/trial-task-center.md
Interfaces:
-
Consumes: logging, store, service, and
TrialTaskCenterWindow. -
Produces:
main(argv: Sequence[str] | None = None) -> intanddist/DxPartReplace/DxPartReplace.exe. -
Supports
DX_TASK_CENTER_HOMEonly as an explicit test/deployment override; default is%LOCALAPPDATA%\DxProductivity\trial-task-center. -
Step 1: Write bootstrap tests and verify RED
Tests assert logging is configured before constructing QApplication, interrupted work recovery is logged, a second-instance database open remains safe, --smoke-test opens and closes through a zero-delay Qt timer, and fatal startup exceptions write a traceback and return a nonzero exit code.
- Step 2: Implement application bootstrap
Parse only --smoke-test and --data-root. Resolve application paths, configure logging and exception hooks, recover interrupted records, construct store/service/window, and run Qt. Log process version, executable, OS, data root, database, and log paths before window construction.
- Step 3: Write the packaging spec and build script
The spec names the executable DxPartReplace, uses windowed mode, collects PySide6 plugins, and bundles no user task database or live evidence. Build-DxPartReplace.ps1 resolves the repository root, runs focused tests, removes only the explicit repository-local build\DxPartReplace and dist\DxPartReplace targets after verifying their resolved paths, invokes PyInstaller, and prints the absolute EXE and log locations.
- Step 4: Add packaging smoke tests
Static tests validate spec/script paths and safety guards. The built-artifact smoke test launches:
$env:DX_TASK_CENTER_HOME=<temporary absolute directory>
dist\DxPartReplace\DxPartReplace.exe --smoke-test
Assert exit code 0, logs\application.log exists and contains startup and clean shutdown, and no files are written outside the temporary data root except normal OS/Qt runtime activity.
- Step 5: Write the Chinese trial guide
Document EXE launch, data/log paths, creating one task, scanning/selecting one disposable .prj, adding 4300-CA2260-A300-style mappings, Capture Before, the exact manual DxDesigner Find/Replace Part/Library Wins steps, Capture After, Completed/Failed behavior, retry, and which files to return for diagnosis. State clearly that no automatic Value/style write or save occurs.
- Step 6: Run the complete test suite
$env:PYTHONPATH=(Resolve-Path 'src').Path
$env:QT_QPA_PLATFORM='offscreen'
py -3.12 -m pytest -q
Expected: all tests pass.
- Step 7: Build and smoke-test the EXE
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\Build-DxPartReplace.ps1
Expected: exit code 0 and a working dist\DxPartReplace\DxPartReplace.exe.
- Step 8: Perform final review and commit
Review the full diff against the spec, resolve all blocking findings, then:
git add src/dx_productivity/trial_task_center packaging tests docs/user/trial-task-center.md pyproject.toml
git commit -m "build: package replacement trial task center"