- Introduced `help-i18n.js` for managing translations in Chinese and English for the help view. - Created `help.js` to render the help view, including command categories, workflow diagrams, and CodexLens quick-start. - Implemented search functionality with debounce for command filtering. - Added workflow diagram rendering with Cytoscape.js integration. - Developed tests for write-file verification, ensuring proper handling of small and large JSON files.
6.4 KiB
Session Management Design Evolution Analysis
1. Abstraction Layer Value Analysis
The current architecture employs a "Thick Tool, Thin CLI" pattern.
- CLI Layer (
session.ts): Acts primarily as a UI adapter. Its value lies in:- UX Enhancement: formatting JSON outputs into human-readable text (colors, indentation).
- Shortcuts: providing semantic commands like
statusandtaskwhich map to genericupdateoperations in the backend. - Safety: specialized error handling (e.g.,
EPIPE) and user feedback.
- Tool Layer (
session-manager.ts): Encapsulates the core business logic.- Centralized Security: The
validatePathParamsandfindSessionfunctions ensure operations are confined to valid session scopes, preventing path traversal. - Path Routing: The
PATH_ROUTESconstant abstracts the physical file structure away from the logical operations. Consumers request "plan" or "task", not specific file paths. - Polymorphism: Handles both "Standard WFS" (heavy workflow) and "Lite" (ephemeral) sessions through a unified interface.
- Centralized Security: The
Verdict: The abstraction is high-value for security and consistency, ensuring that all session interactions (whether from CLI or Agent) adhere to the same structural invariants. However, the semantic mapping is thinning, with the CLI often just passing raw JSON content directly to the tool.
2. Hidden Complexity Costs
The "Unified Session Manager" design hides significant complexity that is beginning to leak:
- Discovery Overhead:
findSessionperforms a linear search across 4 distinct directory roots (active,archived,lite-plan,lite-fix) for every single operation. As the number of sessions grows, this disk I/O could become a bottleneck. - Leaky Abstractions in Handling "Lite" Sessions:
executeInitcontains explicit branching logic (if (location === 'lite-plan'...)).executeArchiveexplicitly throws errors for Lite sessions.- The "Unified" interface creates a false promise of compatibility; consumers must "know" that
archivedoesn't work for Lite sessions, breaking the Liskov Substitution Principle.
- Routing Table Explosion:
PATH_ROUTESis becoming a "God Object" mapping. It mixes different domains:- Core Workflow (
session,plan) - Task Management (
task,summary) - Review Systems (
review-dim,review-iter) - Lite System (
lite-plan,exploration) - Cost: Adding a new feature requires touching the Schema, the Routing Table, and often the Operation Switch.
- Core Workflow (
3. Parameter Transformation Overhead
Data undergoes multiple transformations, creating friction:
- CLI Args -> Options Object:
argsparsed intoInitOptions,ReadOptions. - Options -> Tool Params: Specialized options (
options.taskId) are manually mapped to genericpath_params.- Risk: The CLI must implicitly know which
content_typerequires whichpath_params. For example,readActionmanually constructspath_paramsfortaskId,filename,dimension, etc. If the Tool changes a required param, the CLI breaks.
- Risk: The CLI must implicitly know which
- Tool Params -> Zod Validation: The tool re-validates the structure.
- Tool -> File System: The tool maps logical params to physical paths.
High Friction Area: The generic path_params object. It forces a loose contract. A strict type system (e.g., distinct interfaces for ReadTaskParams vs ReadPlanParams) is lost in favor of a generic Record<string, string>.
4. Alternative Architecture Proposals
Proposal A: Domain-Specific Tools (Split by Lifecycle)
Split the monolithic session_manager into targeted tools.
- Components:
wfs_manager(Standard Workflow),lite_session_manager(Lite/Ephemeral). - Pros:
- Clean separation of concerns.
litetools don't needarchiveortasklogic. - Simpler Schemas.
- Faster discovery (look in 1 place).
- Clean separation of concerns.
- Cons:
- Agent confusion: "Which tool do I use to read a file?"
- Duplicated utility code (file reading, writing).
Proposal B: Resource-Oriented Architecture (REST-like)
Focus on Resources rather than Operations.
- Components:
task_tool(CRUD for tasks),session_tool(Lifecycle),file_tool(Safe FS access within session). - Pros:
- Aligns with how LLMs think (Action on Object).
task_toolcan enforce strict schemas for task status updates, removing the "magic string" status updates in the current CLI.
- Cons:
- Loss of the "Session" as a coherent unit of work.
- Harder to implement "global" operations like
archivewhich touch multiple resources.
Proposal C: Strategy Pattern (Internal Refactor)
Keep the Unified Interface, but refactor internals.
- Design:
SessionManagerclass delegates toSessionStrategyimplementations (StandardStrategy,LiteStrategy). - Pros:
- Removes
if (lite)checks from main logic. - Preserves the simple "one tool" interface for Agents.
- Allows
LiteStrategyto throw "NotSupported" cleanly or handlearchivedifferently (e.g., delete).
- Removes
- Cons:
- Does not solve the
path_paramsloose typing issue.
- Does not solve the
5. Recommended Optimal Design
Hybrid Approach: Strategy Pattern + Stronger Typing
-
Refactor
session-manager.tsto use a Strategy Pattern.- Define a
SessionStrategyinterface:init,resolvePath,list,archive. - Implement
StandardWorkflowStrategyandLiteWorkflowStrategy. - The
handlersimply identifies the session type (viafindSessionor input param) and delegates.
- Define a
-
Flatten the Path Resolution.
- Instead of
path_params: { task_id: "1" }, promote widely used IDs to top-level optional params in the Zod schema:task_id?: string,filename?: string. This makes the contract explicit to the LLM.
- Instead of
-
Deprecate "Hybrid" content types.
- Instead of
content_type="lite-plan", just usecontent_type="plan"and let theLiteStrategydecide where that lives (plan.jsonvsIMPL_PLAN.md). This unifies the language the Agent uses—it always "reads the plan", regardless of session type.
- Instead of
Benefit: This maintains the ease of use for the Agent (one tool) while cleaning up the internal complexity and removing the "Leaky Abstractions" where the Agent currently has to know if it's in a Lite or Standard session to ask for the right file type.