@kienha/anti-chaotic 1.0.7 → 1.0.9

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.
@@ -0,0 +1,55 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: Always run tests to ensure no regressions when implementing new features or fixing bugs
4
+ ---
5
+
6
+ # Testing and Regression Rule
7
+
8
+ > [!IMPORTANT]
9
+ > This rule is **MANDATORY** when implementing new features, fixing bugs, or performing major refactors. Ensuring system stability is a top priority.
10
+
11
+ ## Critical Rules (MUST Follow)
12
+
13
+ 1. **MUST** run existing tests before starting any work to establish a baseline.
14
+ 2. **MUST** run tests after completing changes to ensure no regressions were introduced.
15
+ 3. **MUST** add new tests for any new features implemented.
16
+ 4. **MUST** add reproduction tests for any bug fixes to ensure the bug does not return.
17
+ 5. **MUST** report test results (pass/fail) in the task summary and walkthrough.
18
+ 6. **MUST NOT** proceed to finalize a task if tests are failing, unless explicitly instructed by the user after explaining the failure and its impact.
19
+
20
+ ## Decision Flow
21
+
22
+ ```
23
+ ┌─────────────────────────────────────────────────────────────┐
24
+ │ WHEN implementing a feature or fixing a bug: │
25
+ ├─────────────────────────────────────────────────────────────┤
26
+ │ 1. Run baseline tests. │
27
+ │ Are they passing? │
28
+ │ NO → Notify user of existing failures before proceeding. │
29
+ │ YES → Continue. │
30
+ ├─────────────────────────────────────────────────────────────┤
31
+ │ 2. Implement changes (Feature/Fix/Refactor). │
32
+ ├─────────────────────────────────────────────────────────────┤
33
+ │ 3. Add/Update tests for the new code. │
34
+ ├─────────────────────────────────────────────────────────────┤
35
+ │ 4. Run ALL relevant tests. │
36
+ │ Are they passing? │
37
+ │ NO → Analyze failures, fix code/tests, repeat step 4. │
38
+ │ YES → Continue. │
39
+ ├─────────────────────────────────────────────────────────────┤
40
+ │ 5. Document test results in Walkthrough/Task Summary. │
41
+ └─────────────────────────────────────────────────────────────┘
42
+ ```
43
+
44
+ ## Running Tests
45
+
46
+ - Use `npm test` to run the test suite.
47
+ - For specific tests, use `npm test -- <path_to_test_file>`.
48
+ - If the project uses a different test runner (e.g., `pytest`, `jest`, `vitest`), adapt the command accordingly based on `package.json` or project documentation.
49
+
50
+ ## What to do on Failure
51
+
52
+ 1. **Analyze logs**: Look for the specific assertion failure or error message.
53
+ 2. **Determine Root Cause**: Is it a bug in the code, a bug in the test, or a change in requirements?
54
+ 3. **Fix and Re-run**: Apply the necessary fix and run the tests again.
55
+ 4. **Communicate**: If a failure is expected or cannot be fixed easily, notify the user with a detailed explanation.
@@ -1,23 +1,28 @@
1
1
  ---
2
2
  name: ai-engineer
3
- description: AI Engineer role. Focuses on integrating AI models, building RAG pipelines, and optimizing prompts. Loads specific AI modality guides.
3
+ description: Expert AI Engineer role (10+ Years Exp). Focuses on production-grade GenAI, Agentic Systems, Advanced RAG, and rigorous Evaluation.
4
4
  license: MIT
5
5
  metadata:
6
6
  role: AI Engineer
7
- version: "1.0"
7
+ version: "2.0"
8
8
  ---
9
9
 
10
- # AI Engineer
10
+ # Senior AI Engineer
11
11
 
12
- You build intelligence into the application.
12
+ You are a Senior Staff AI Engineer with experience at top-tier tech companies (Google, OpenAI, Anthropic). You build robust, scalable, and intelligent systems. You do not just "call APIs"; you engineer reliability, observability, and performance into stochastic systems.
13
13
 
14
14
  ## Core Responsibilities
15
15
 
16
- 1. **Model Integration**: Connecting LLMs to Logic.
17
- 2. **Context Management**: RAG, Vector Search, Memory.
18
- 3. **Evaluation**: Testing AI quality.
16
+ 1. **Agentic Systems & Architecture**: Designing multi-agent workflows, planning capabilities, and reliable tool-use patterns.
17
+ 2. **Advanced RAG & Retrieval**: Implementing hybrid search, query expansion, re-ranking, and knowledge graphs.
18
+ 3. **Evaluation & Reliability (Evals)**: Setting up rigorous evaluation pipelines (LLM-as-a-judge), regression testing, and guardrails.
19
+ 4. **Model Integration & Optimization**: Function calling, structured outputs, prompt engineering, and choosing the right model for the task (latency vs. intelligence trade-offs).
20
+ 5. **MLOps & Serving**: Observability, tracing, caching, and cost management.
19
21
 
20
22
  ## Dynamic Stack Loading
21
23
 
22
- - **LLMs & RAG**: [Read specific guide](references/llm.md)
23
- - **MLOps**: (Create `references/mlops.md` if needed)
24
+ - **Agentic Patterns**: [Principles for reliable agents](references/agentic-patterns.md)
25
+ - **Advanced RAG**: [Techniques for high-recall retrieval](references/rag-advanced.md)
26
+ - **Evaluation Frameworks**: [Testing & Metrics](references/evaluation.md)
27
+ - **Serving & Optimization**: [Performance & MLOps](references/serving-optimization.md)
28
+ - **LLM Fundamentals**: [Prompting & SDKs](references/llm.md)
@@ -0,0 +1,47 @@
1
+ # Agentic Patterns & Architectures
2
+
3
+ Building agents is about engineering reliability into stochastic systems.
4
+
5
+ ## Core Patterns
6
+
7
+ ### 1. The ReAct Loop (Reason + Act)
8
+
9
+ The fundamental loop of an agent:
10
+
11
+ 1. **Thought**: Analyze the current state and goal.
12
+ 2. **Act**: Decide on a tool to call.
13
+ 3. **Obs**: Observe the output of the tool.
14
+ 4. **Repeat**.
15
+
16
+ ### 2. Planning & Reflection
17
+
18
+ - **Planning**: Break complex tasks into steps _before_ execution. (e.g., "First I will search for X, then I will calculate Y").
19
+ - **Reflection**: After an output, ask the model "Does this answer the user's question? Is it accurate?". Use a separate "Critic" prompt.
20
+
21
+ ### 3. Memory Architectures
22
+
23
+ - **Short-term**: Current context window (conversation history).
24
+ - **Long-term**: Vector database (semantic search over past interactions).
25
+ - **Procedural**: Storing successful "recipes" or tool sequences for future use.
26
+
27
+ ## Multi-Agent Architectures
28
+
29
+ ### 1. Orchestrator-Workers (Router)
30
+
31
+ A central "Manager" LLM analyzes the request and delegates to specific "Worker" agents (e.g., Coder, Researcher, Reviewer).
32
+
33
+ - **Pros**: Clear separation of concerns, easy to eval workers independently.
34
+ - **Cons**: Latency (multiple hops).
35
+
36
+ ### 2. Autonomous Teams (CrewAI / AutoGen)
37
+
38
+ Agents converse with each other to solve a problem.
39
+
40
+ - **Role-Playing**: "You represent the User", "You are the QA Tester".
41
+ - **Dynamic**: Can handle ambiguous tasks but harder to control.
42
+
43
+ ## Best Practices
44
+
45
+ - **Deterministic Tools**: Tools should be as reliable as possible (APIs, Code execution).
46
+ - **Human-in-the-Loop**: Always pause for confirmation before destructive actions (Write DB, Deploy).
47
+ - **Fail Gracefully**: If a tool fails, the agent should catch the error and retry or ask for help, not crash.
@@ -0,0 +1,42 @@
1
+ # Evaluation & Reliability
2
+
3
+ If you can't measure it, you can't improve it.
4
+
5
+ ## The Evaluation Hierarchy
6
+
7
+ ### 1. Unit Tests (Deterministic)
8
+
9
+ - Does the output JSON parse?
10
+ - Does the code compile?
11
+ - Are forbidden words present?
12
+
13
+ ### 2. LLM-as-a-Judge (Semantic)
14
+
15
+ Use a stronger model (GPT-4o) to evaluate the output of your application model.
16
+
17
+ - **Frameworks**: Ragas, DeepEval, Promptfoo.
18
+ - **Metrics**:
19
+ - **Faithfulness**: Is the answer derived _only_ from the retrieved context?
20
+ - **Answer Relevance**: Does the answer address the user's query?
21
+ - **Context Precision**: Was the relevant chunk ranked at the top?
22
+
23
+ ### 3. Human Review (Ground Truth)
24
+
25
+ - Create a "Golden Dataset" of 50-100 Q&A pairs verified by experts.
26
+ - Run regression tests against this dataset on every prompt change.
27
+
28
+ ## Techniques
29
+
30
+ ### Regression Testing
31
+
32
+ Treat prompts like code.
33
+
34
+ 1. Change strictness in system prompt.
35
+ 2. Run `promptfoo eval` against 50 test cases.
36
+ 3. Compare pass rate (98% -> 92%? **Revert**).
37
+
38
+ ### Guardrails
39
+
40
+ - **Input Rails**: PII detection, Jailbreak attempts.
41
+ - **Output Rails**: Hallucination check, Tone check.
42
+ - **Tools**: NeMo Guardrails, Llama Guard.
@@ -1,13 +1,45 @@
1
- # Tech: LLMs & RAG
1
+ # Tech: LLMs & Integration Patterns
2
2
 
3
- ## Stack
3
+ ## Stack Selection
4
4
 
5
- - **SDK**: Vercel AI SDK or LangChain.
6
- - **Model**: GPT-4o, Claude 3.5 Sonnet.
7
- - **Vector DB**: Supabase `pgvector`.
5
+ - **Inference Engine**:
6
+ - **Complex Reasoning**: GPT-4o, Claude 3.5 Sonnet.
7
+ - **Fast/Cheap**: Gemini Flash, Haiku, Llama 3 (Groq/Together).
8
+ - **Orchestration**:
9
+ - **Production**: Vercel AI SDK (Type-safe, streaming first).
10
+ - **Prototyping**: LangChain (Use with caution in production due to abstraction overhead).
11
+ - **Gateway**: Portkey or Helicone for observability and fallback.
8
12
 
9
- ## Best Practices
13
+ ## Advanced Patterns
10
14
 
11
- - **Streaming**: Always stream responses using `AIStream`.
12
- - **Prompts**: Version control your system prompts.
13
- - **Embeddings**: Normalize text before embedding.
15
+ ### 1. Structured Outputs
16
+
17
+ Stop parsing regex. Use native JSON mode or tool definitions to enforce strict schemas (Zod).
18
+
19
+ ```typescript
20
+ // Example using Vercel AI SDK
21
+ const { object } = await generateObject({
22
+ model: openai("gpt-4o"),
23
+ schema: z.object({
24
+ sentiment: z.enum(["positive", "negative"]),
25
+ reasoning: z.string(),
26
+ }),
27
+ prompt: "Analyze this customer feedback...",
28
+ });
29
+ ```
30
+
31
+ ### 2. Reliable Prompt Engineering
32
+
33
+ - **Chain of Thought (CoT)**: Force the model to "think" before answering. `Let's think step by step.`
34
+ - **Few-Shot Prompting**: Provide 3-5 high-quality examples of input -> output.
35
+ - **System Prompts**: strict role definition, output constraints, and "tone of voice" instructions. Version control these!
36
+
37
+ ### 3. Streaming & UI Integration
38
+
39
+ - **Optimistic UI**: Show skeleton loaders or predicted text while waiting.
40
+ - **Generative UI**: Stream React components directly from the LLM (Vercel AI SDK RSC).
41
+
42
+ ### 4. Cost Management
43
+
44
+ - **Token Counting**: Always estimate tokens before sending requests.
45
+ - **Caching**: Cache identical prompts at the edge/gateway layer.
@@ -0,0 +1,42 @@
1
+ # Advanced RAG Patterns
2
+
3
+ Move beyond naive "chunk & retrieve".
4
+
5
+ ## Retrieval Optimization
6
+
7
+ ### 1. Hybrid Search (Keyword + Semantic)
8
+
9
+ Dense vectors (semantic) miss exact matches (IDs, acronyms). Sparse vectors (BM25/Splade) miss intent.
10
+ **Solution**: Combine both with Reciprocal Rank Fusion (RRF).
11
+
12
+ - **Stack**: Pinecone (Hybrid), Weaviate, Supabase (pgvector + pg_search).
13
+
14
+ ### 2. Re-Ranking (Cross-Encoders)
15
+
16
+ Retrieving 50 docs with a bi-encoder is fast but inaccurate.
17
+ **Solution**: Retrieve 50 -> Re-rank top 5 with a Cross-Encoder (Cohere Rerank, bge-reranker). This dramatically improves precision.
18
+
19
+ ### 3. Query Transformations
20
+
21
+ Users write bad queries.
22
+
23
+ - **Expansion**: Generate synonyms or related questions.
24
+ - **Decomposition**: Break complex questions into sub-queries.
25
+ - **HyDE (Hypothetical Document Embeddings)**: Generate a fake answer, embed _that_, and search for similar real chunks.
26
+
27
+ ### 4. Contextual Compression
28
+
29
+ Don't shove 10 full documents into the context.
30
+
31
+ - Summarize retrieved docs relative to the query before passing to the LLM.
32
+
33
+ ## Knowledge Graphs (GraphRAG)
34
+
35
+ For questions requiring global reasoning ("How do the themes in book A relate to book B?").
36
+
37
+ - Extract entities and relationships -> Store in Graph DB (Neo4j) -> Traverse during retrieval.
38
+
39
+ ## Indexing Strategy
40
+
41
+ - **Parent-Child Chunking**: Retrieve small chunks (better matching), but return the parent large chunk (better context).
42
+ - **Multi-Vector Retrieval**: Embed summaries for search, but return full raw text for generation.
@@ -0,0 +1,39 @@
1
+ # Serving & Optimization (MLOps)
2
+
3
+ Moving from "it works on my laptop" to "production scale".
4
+
5
+ ## Observability & Tracing
6
+
7
+ You cannot debug a stochastic system with `console.log`.
8
+
9
+ - **Tracing**: Visualize the entire chain (User -> RAG -> Tool -> LLM).
10
+ - **Tools**: LangSmith, Arize Phoenix, Helicone.
11
+ - **Key Metrics**:
12
+ - **Latency**: Time to First Token (TTFT), Total Latency.
13
+ - **Cost**: Cost per request, Token usage.
14
+ - **Quality**: User feedback (Thumbs up/down).
15
+
16
+ ## Optimization Techniques
17
+
18
+ ### 1. Caching (The Semantic Cache)
19
+
20
+ Don't pay for the same answer twice.
21
+
22
+ - **Exact Match**: Redis check on prompt string.
23
+ - **Semantic Match**: Check vector distance of prompt embeddings (e.g., "How do I reset password" ~= "modify password steps").
24
+
25
+ ### 2. Latency Reduction
26
+
27
+ - **Streaming**: Non-negotiable for UX.
28
+ - **Speculative Decoding**: Use a small model to draft, large model to verify.
29
+ - **Quantization**: Run int8/int4 models if self-hosting (vLLM).
30
+
31
+ ### 3. Cost Control
32
+
33
+ - **Model Cascading**: Try a cheap model (Flash/Haiku) first. If confidence < X, retry with GPT-4.
34
+ - **Fine-tuning**: Fine-tune a small model (Llama 3 8B) on your specific task to match GPT-4 performance at 1/10th the cost.
35
+
36
+ ## Deployment Stack
37
+
38
+ - **Managed**: Vercel, AWS Bedrock.
39
+ - **Self-Hosted**: vLLM, TGI (Text Generation Inference), Ray Serve.
@@ -1,23 +1,53 @@
1
1
  ---
2
2
  name: blockchain-engineer
3
- description: Blockchain Engineer role. Focuses on smart contracts, web3 integration, and decentralized protocols. Loads specific chain guides.
3
+ description: Expert Blockchain Engineer (10+ Years). Master of Protocol Architecture, Advanced Smart Contract Development, and Security.
4
4
  license: MIT
5
5
  metadata:
6
6
  role: Blockchain Engineer
7
- version: "1.0"
7
+ version: "2.0"
8
8
  ---
9
9
 
10
10
  # Blockchain Engineer
11
11
 
12
- You build the decentralized layer.
12
+ You are an expert Blockchain Engineer with 10+ years of experience at top tech firms. You build the decentralized layer with a focus on security, scalability, and economic robustness.
13
13
 
14
14
  ## Core Responsibilities
15
15
 
16
- 1. **Smart Contracts**: Immutable code on chain.
17
- 2. **Web3**: Connecting the frontend to the wallet.
18
- 3. **Security**: Protecting value.
16
+ 1. **Protocol Architecture**: Design tokenomics, governance structures, and ensuring incentive alignment across the network.
17
+ 2. **Smart Contract Mastery**: End-to-end lifecycle management of smart contracts on EVM (Solidity/Yul) and SVM (Rust/Anchor).
18
+ 3. **Advanced Security**: Protect value through formal verification, fuzzing, and rigorous audit preparation.
19
+ 4. **Scaling Solutions**: Architect solutions using L2s, Optimistic/ZK Rollups, and AppChains.
20
+
21
+ ## Technical Standards & Best Practices
22
+
23
+ ### Development Lifecycle
24
+
25
+ - **Environment**: Master usage of Hardhat and Foundry (Forge/Cast/Anvil) for EVM; Anchor for Solana.
26
+ - **Testing**: Beyond unit tests—implement invariant testing, fuzzing (Echo/Medusa), and fork testing.
27
+ - **CI/CD**: Automated pipelines for linting, testing, and deterministic deployments.
28
+
29
+ ### Optimization & Quality
30
+
31
+ - **Gas Golfing**: Optimize for gas efficiency using Yul/Assembly, storage layout packing, and calldata mastery.
32
+ - **Code Quality**: Enforce NatSpec documentation, strict linting (Solhint/Clippy), and clean code patterns.
33
+
34
+ ### Deployment & Ops
35
+
36
+ - **Patterns**: Use deterministic deployment (Create2) and manage upgrades via standard proxies (Transparent, UUPS, Diamond/EIP-2535).
37
+ - **Security**: Manage keys via Multi-sig (Gnosis Safe) and Timelocks. Automate ops with scripting.
38
+
39
+ ## Architecture Patterns
40
+
41
+ - **Upgradeability**: Future-proof contracts using Transparent, UUPS, or Diamond patterns.
42
+ - **Interoperability**: Connect chains using Bridges, Atomic Swaps, and CCIP.
43
+ - **Data Integration**: Index data with Subgraphs (The Graph) and secure external feeds via Oracles (Chainlink, Pyth).
19
44
 
20
45
  ## Dynamic Stack Loading
21
46
 
22
- - **EVM (Ethereum/Polygon)**: [Read specific guide](references/evm.md)
47
+ - **EVM (Ethereum/Polygon/Arbitrum)**:
48
+ - [EVM Overview](references/evm.md)
49
+ - [Solidity Development](references/solidity.md)
50
+ - [Deployment & Ops](references/deployment.md)
51
+ - [Mechanisms & Internals](references/mechanisms.md)
23
52
  - **Solana**: (Create `references/solana.md` if needed)
53
+ - **ZK & Privacy**: Focus on ZK-SNARKs/STARKs for privacy and scaling.
@@ -0,0 +1,28 @@
1
+ # Tech: Smart Contract Deployment
2
+
3
+ ## Strategies
4
+
5
+ - **Immutable**: Simple deployment. Code cannot be changed. High trust, low flexibility.
6
+ - **Upgradeable Proxies**:
7
+ - **Transparent Upgradeable Proxy**: Admin logic separated. High gas overhead.
8
+ - **UUPS (Universal Upgradeable Proxy Standard)**: Upgrade logic in implementation. Cheaper gas.
9
+ - **Diamond (EIP-2535)**: Modular system, unlimited size, complex management.
10
+
11
+ ## Automation & Tooling
12
+
13
+ - **Hardhat Ignition**: Declarative deployment modules. Handles dependency management and recovery.
14
+ - **Foundry Script**: Solidity-based scripting (`forge script`). Fast and integrated with Forge tests.
15
+ - **Deterministic Deployment**:
16
+ - Use `CREATE2` to deploy to the same address across multiple chains.
17
+ - Tool: `Nick's Method` factory / `Arachnid/deterministic-deployment-proxy`.
18
+
19
+ ## Verification
20
+
21
+ - **Etherscan/Block Explorers**: ALWAYs verify source code.
22
+ - **Sourcify**: Decentralized verification based on metadata hash.
23
+
24
+ ## Operational Safety
25
+
26
+ - **Multisig (Gnosis Safe)**: Never deploy or manage admin keys with a single EOA (Externally Owned Account).
27
+ - **Timelocks**: Enforce a delay (e.g., 48h) between proposing and executing sensitive admin actions.
28
+ - **Access Control Rotation**: Plan for key rotation procedures.
@@ -0,0 +1,32 @@
1
+ # Tech: Blockchain Mechanisms & Internals
2
+
3
+ ## Consensus
4
+
5
+ - **PoS (Proof of Stake)**: Validators stake tokens to propose/attest blocks. (Ethereum, Solana).
6
+ - **PoW (Proof of Work)**: Miners solve cryptographic puzzles. (Bitcoin).
7
+ - **Finality**:
8
+ - **Probabilistic**: Bitcoin (wait ~6 blocks).
9
+ - **Deterministic**: Ethereum (after finalized epoch), Tendermint (instant).
10
+
11
+ ## State Management
12
+
13
+ - **Account Model (Ethereum/Solana)**: Global state tracks account balances and nonce.
14
+ - **UTXO (Bitcoin/Cardano)**: Unspent Transaction Outputs. State is the set of all unspent outputs.
15
+ - **Data Structures**:
16
+ - **Merkle Patricia Trie (Ethereum)**: Storage, State, Transactions, Receipts.
17
+ - **Verkle Trees**: Future upgrade for stateless clients.
18
+
19
+ ## Transaction Lifecycle
20
+
21
+ 1. **Creation**: User signs tx with private key.
22
+ 2. **Propagation**: Gossip protocol sends tx to Mempool.
23
+ 3. **Ordering**: Block Builders/Proposers select and order txs (MEV opportunity here).
24
+ 4. **Execution**: EVM executes logic, updates state trie.
25
+ 5. **Finalization**: Block is added to chain and finalized by consensus.
26
+
27
+ ## EVM Internals
28
+
29
+ - **Stack**: 1024 depth, 256-bit words. Most gas efficient.
30
+ - **Memory**: Linear, byte-addressable. Expanded in 32-byte chunks.
31
+ - **Storage**: Key-value store (256-bit -> 256-bit). Most expensive. SLOAD/SSTORE.
32
+ - **Logs**: Bloom filters used for event indexing. Cheaper than storage but not accessible by contracts.
@@ -0,0 +1,32 @@
1
+ # Tech: Solidity Development
2
+
3
+ ## Best Practices
4
+
5
+ - **Layout**: Follow [Solidty Style Guide](https://docs.soliditylang.org/en/latest/style-guide.html).
6
+ - Order: Pragma -> Import -> Interfaces -> Libraries -> Contracts.
7
+ - Inside Contract: Type declarations -> State vars -> Events -> Modifiers -> Functions.
8
+ - **Naming**: `camelCase` for variables/functions, `CapWords` for contracts/structs/events, `UPPER_CASE` for constants.
9
+ - **Error Handling**: Use custom errors (`error InsufficientFunds()`) instead of strings for gas efficiency.
10
+
11
+ ## Advanced Concepts
12
+
13
+ - **Storage Layout**: Understand slot packing to minimize storage costs.
14
+ - Pack `uint128`, `address`, `bool` into single 256-bit slots where possible.
15
+ - **Delegatecall**: Execution in the context of the caller (crucial for proxies).
16
+ - **Assembly (Yul)**: Use `assembly { ... }` for low-level memory manipulation and gas optimization.
17
+ - **EIP Standards**:
18
+ - **ERC-20/721/1155**: Token standards.
19
+ - **ERC-4626**: Tokenized Vaults.
20
+ - **ERC-2535**: Diamond Standard.
21
+
22
+ ## Security Patterns
23
+
24
+ - **Checks-Effects-Interactions**: Update state _before_ making external calls to prevent reentrancy.
25
+ - **Pull over Push**: Let users withdraw funds rather than pushing them to arrays of addresses (avoids DoS).
26
+ - **Access Control**: Use `OwnableTwoStep` or `AccessControl` (RBAC).
27
+
28
+ ## Gas Optimization
29
+
30
+ - **Calldata**: Use `calldata` instead of `memory` for read-only function arguments.
31
+ - **Unchecked Math**: Use `unchecked { ... }` when overflow/underflow is impossible (Solidity 0.8+ default checks cost gas).
32
+ - **Constants/Immutable**: Use `constant` for literal values and `immutable` for constructor-set values.
@@ -0,0 +1,82 @@
1
+ ---
2
+ description: Orchestrates breaking down requirements into actionable tasks for implementation.
3
+ ---
4
+
5
+ # Break Tasks Workflow
6
+
7
+ > [!IMPORTANT]
8
+ > **MANDATORY**: Follow `.agent/rules/documents.md` for all task-related documentation.
9
+
10
+ ---
11
+
12
+ ## MCP Usage Guidelines
13
+
14
+ | MCP Tool | When to Use |
15
+ | :------------------------------------------- | :-------------------------------------------------------- |
16
+ | `mcp_sequential-thinking_sequentialthinking` | **REQUIRED** to break down requirements into atomic tasks |
17
+ | `mcp_context7_query-docs` | To check best practices for specific technologies |
18
+
19
+ ---
20
+
21
+ ## Step 1: Identify Source Document
22
+
23
+ 1. Locate the source document (PRD, User Story, Feature Spec, or SDD).
24
+ 2. If multiple versions exist, ask the user for clarification.
25
+ 3. Relevant folders to check:
26
+ - `docs/020-Requirements/`
27
+ - `docs/022-User-Stories/`
28
+ - `docs/030-Specs/`
29
+
30
+ ---
31
+
32
+ ## Step 2: Analyze Requirements
33
+
34
+ // turbo
35
+
36
+ 1. **Invoke `[business-analysis]` skill** to extract key features and acceptance criteria.
37
+ 2. Use `sequential-thinking` to:
38
+ - Identify technical dependencies.
39
+ - Separate backend, frontend, and QA requirements.
40
+ - Spot ambiguous or missing details.
41
+ 3. List any clarifying questions for the user.
42
+ 4. **WAIT** for user clarification if needed.
43
+
44
+ ---
45
+
46
+ ## Step 3: Atomic Task Breakdown
47
+
48
+ // turbo
49
+
50
+ > 💡 **MCP**: **MUST** use `sequential-thinking` here to ensure tasks are atomic and manageable.
51
+
52
+ 1. **Invoke `[lead-architect]` skill** to create a structured task list.
53
+ 2. Group tasks by component or phase (e.g., Database, API, Logic, UI, Testing).
54
+ 3. For each task, include:
55
+ - Goal/Description.
56
+ - Acceptance Criteria.
57
+ - Estimated complexity (if applicable).
58
+ 4. Create a `task-breakdown.md` artifact representing the proposed sequence.
59
+
60
+ ---
61
+
62
+ ## Step 4: Finalize Task Documentation
63
+
64
+ // turbo
65
+
66
+ 1. After user approves the `task-breakdown.md` artifact:
67
+ 2. Update the `task.md` of the current session or create a new task file in `docs/050-Tasks/`.
68
+ 3. If creating a new file, follow standard naming: `docs/050-Tasks/Task-{FeatureName}.md`.
69
+ 4. Update `docs/050-Tasks/Tasks-MOC.md`.
70
+ 5. Present the finalized task list to the user.
71
+
72
+ ---
73
+
74
+ ## Quick Reference
75
+
76
+ | Role | Skill | Responsibility |
77
+ | :----------------- | :------------------- | :-------------------------------------- |
78
+ | Product Manager | `product-manager` | Requirement validation & prioritization |
79
+ | Lead Architect | `lead-architect` | Technical breakdown & dependencies |
80
+ | Developer | `backend-developer` | Backend/API specific tasks |
81
+ | Frontend Developer | `frontend-developer` | UI/UX specific tasks |
82
+ | QA Tester | `qa-tester` | Verification & Edge case tasks |
@@ -0,0 +1,71 @@
1
+ ---
2
+ description: Scientific debugging workflow: Hypothesize, Instrument, Reproduce, Analyze, Fix.
3
+ ---
4
+
5
+ # Scientific Debug & Fix Workflow
6
+
7
+ > [!IMPORTANT]
8
+ > **GOAL**: Follow a scientific process to identify root causes with EVIDENCE before applying fixes.
9
+ > **Best for**: Hard-to-reproduce bugs, race conditions, performance issues, and regressions.
10
+
11
+ ---
12
+
13
+ ## Step 1: Hypothesis Generation
14
+
15
+ 1. **Analyze the Issue**: Review the bug report and available context.
16
+ 2. **Generate Hypotheses**: Brainstorm multiple potential causes (e.g., "Race condition in data fetching", "Incorrect state update logic", "Edge case in input validation").
17
+ 3. **Select Top Candidates**: Prioritize the most likely hypotheses to investigate first.
18
+
19
+ ---
20
+
21
+ ## Step 2: Instrumentation
22
+
23
+ 1. **Plan Logging**: Decide WHERE key information is missing to validate your hypotheses.
24
+ 2. **Add Logging**: Instrument the code with targetted `console.log`, specific logger calls, or performance markers.
25
+ - _Goal_: Capture runtime state, variable values, and execution flow relevant to the hypotheses.
26
+ - _Tip_: Add unique prefixes to logs (e.g., `[DEBUG-HYPOTHESIS-1]`) for easy filtering.
27
+
28
+ ---
29
+
30
+ ## Step 3: Reproduction & Data Collection
31
+
32
+ 1. **Execution**: Run the application or test case to reproduce the bug.
33
+ - If a reproduction script doesn't exist, create one now if possible.
34
+ 2. **Collect Data**: Capture the output from your instrumentation.
35
+
36
+ ---
37
+
38
+ ## Step 4: Analysis & Root Cause
39
+
40
+ 1. **Analyze Evidence**: Look at the collected logs/data.
41
+ - Does the data confirm a hypothesis?
42
+ - Does it rule one out?
43
+ 2. **Pinpoint Root Cause**: Identify exactly _why_ the bug is happening based on the evidence.
44
+ 3. **Iterate (if needed)**: If inconclusive, return to Step 1 or 2 with new knowledge.
45
+
46
+ ---
47
+
48
+ ## Step 5: Targeted Implementation
49
+
50
+ 1. **Apply Fix**: Implement a targeted fix based _only_ on the confirmed root cause. Avoid "shotgun debugging" (changing things randomly).
51
+ 2. **Cleanup**: Remove the temporary debugging instrumentation.
52
+
53
+ ---
54
+
55
+ ## Step 6: Verification
56
+
57
+ // turbo
58
+
59
+ 1. **Run Reproduction Test**: Verify that the bug is gone.
60
+ 2. **Run Regression Tests**: Run related unit tests to ensure no side effects.
61
+ 3. **Lint & Type Check**: Ensure code quality standards are met.
62
+
63
+ ---
64
+
65
+ ## Step 7: Finalize
66
+
67
+ 1. **Draft Commit**: Create a concise commit message (e.g., `fix(module): description of fix`).
68
+ 2. **Report**: Summarize the process:
69
+ - What was the hypothesis?
70
+ - What evidence confirmed it?
71
+ - How was it fixed?
@@ -0,0 +1,54 @@
1
+ ---
2
+ description: General coding workflow for implementing changes, bug fixes, or minor features.
3
+ ---
4
+
5
+ # Development Workflow
6
+
7
+ > [!IMPORTANT]
8
+ > **MANDATORY**: Always read `.agent/rules/documents.md` before creating or modifying any documentation related to development.
9
+
10
+ ---
11
+
12
+ ## Step 1: Analyze & Plan
13
+
14
+ // turbo
15
+
16
+ 1. Understand the requirement or bug report.
17
+ 2. **MUST** use `mcp_sequential-thinking_sequentialthinking` to:
18
+ - Analyze the existing code structure.
19
+ - Design the solution.
20
+ - Identify potential edge cases and impacts.
21
+ 3. If the task is complex, create an `implementation_plan.md` artifact.
22
+ 4. **WAIT** for user confirmation if the plan involves major architectural changes.
23
+
24
+ ---
25
+
26
+ ## Step 2: Execute Code Changes
27
+
28
+ // turbo
29
+
30
+ 1. Implement the planned changes iteratively.
31
+ 2. **Backend**: Update models, logic, and APIs as needed.
32
+ 3. **Frontend**: Update UI components and state management.
33
+ 4. Ensure code follows project standards and linting rules.
34
+
35
+ ---
36
+
37
+ ## Step 3: Verify & Test
38
+
39
+ // turbo
40
+
41
+ 1. Run existing tests to ensure no regressions.
42
+ 2. Add new unit or integration tests for the changes.
43
+ 3. Perform manual verification (e.g., using the browser tool for UI changes).
44
+ 4. **MUST** document proof of work in a `walkthrough.md` artifact if the change is significant.
45
+
46
+ ---
47
+
48
+ ## Step 4: Finalize
49
+
50
+ // turbo
51
+
52
+ 1. Update related documentation (MOCs, API specs, etc.).
53
+ 2. Clean up any temporary files or comments.
54
+ 3. Present a summary of changes and verification results.
@@ -37,24 +37,81 @@ description: Generate comprehensive documentation (Architecture, API, Specs) fro
37
37
 
38
38
  1. **Invoke `[lead-architect]` skill** to analyze codebase structure
39
39
  2. Identify: tech stack, entry points, API routes, DB schemas
40
- 3. **WAIT** for user to confirm understanding
40
+ 3. **Clarify & Confirm**:
41
+ - **CRITICAL**: If the codebase structure is unclear or ambiguous, **ASK** the user for clarification.
42
+ - Summarize findings and **WAIT** for user to confirm understanding
41
43
 
42
44
  ---
43
45
 
44
- ## Step A2: Legacy Docs Generation (Architecture, API, Schema)
46
+ ## Step A2: Technical Documentation (Architecture, API, Schema)
45
47
 
46
48
  // turbo
47
49
 
48
50
  1. **Invoke `[lead-architect]` skill** to create:
49
51
  - System Context (C4 Context Diagram)
50
52
  - Component View (C4 Component Diagram)
53
+ - **Sequence Diagrams** for critical business flows
51
54
  2. **Invoke `[backend-developer]` skill** to:
52
- - Document API endpoints
55
+ - Document API endpoints (OpenAPI/Swagger styled)
53
56
  - Generate Entity Relationship Diagram (ERD)
57
+ - Document key algorithms or data processing pipelines
54
58
  3. Save to `docs/030-Specs/` and `docs/030-Specs/Architecture/`
55
59
 
56
60
  ---
57
61
 
62
+ ## Step A3: Functional Documentation (Reverse Engineering)
63
+
64
+ // turbo
65
+
66
+ **Objective**: Derive business logic and requirements from the existing implementation.
67
+
68
+ 1. **Invoke `[business-analysis]` skill** to:
69
+ - Analyze the codebase (controllers, services, frontend views) to understand user flows.
70
+ - **Reverse Engineer** the PRD/Functional Specs:
71
+ - Identify high-level Epics.
72
+ - Document implied User Stories & Acceptance Criteria.
73
+ - Create Use Case definitions for main features.
74
+ 2. **Draft Artifacts**:
75
+ - `docs/020-Requirements/Reverse-Engineered-Specs.md`
76
+ - `docs/022-User-Stories/Implied-User-Stories.md`
77
+ 3. **Review**: Present these findings to the user to confirm they align with business reality.
78
+
79
+ ---
80
+
81
+ ## Step A4: Operational & Quality Documentation
82
+
83
+ // turbo
84
+
85
+ **Objective**: Document how to run, test, and deploy the system.
86
+
87
+ 1. **Invoke `[devops-engineer]` skill** to create:
88
+ - **Infrastructure**: Document cloud resources, Docker setup (`docs/030-Specs/Architecture/Infrastructure.md`).
89
+ - **Deployment**: CI/CD pipelines and release process (`docs/030-Specs/Architecture/Deployment.md`).
90
+ - **Configuration**: Environment variables reference (`docs/030-Specs/Configuration.md`).
91
+ 2. **Invoke `[qa-tester]` skill** to create:
92
+ - **Test Strategy**: Overview of testing tools and approach (`docs/035-QA/Test-Plans/Strategy.md`).
93
+ - **Coverage Report**: Summary of current test coverage and gaps (`docs/035-QA/Reports/Coverage.md`).
94
+ 3. **Invoke `[backend-developer]` skill** to create/update:
95
+ - **Onboarding**: `docs/060-Manuals/Admin-Guide/Setup-Guide.md` (Prerequisites, installation, running locally).
96
+ - **Scripts**: Document usage of `package.json` scripts (`docs/060-Manuals/Admin-Guide/Scripts.md`).
97
+
98
+ ---
99
+
100
+ ## Step A5: Project Planning & Strategy
101
+
102
+ // turbo
103
+
104
+ **Objective**: Establish high-level strategy and roadmap based on current state.
105
+
106
+ 1. **Invoke `[product-manager]` skill** to:
107
+ - **Analyze Maturity**: Assess current feature set against typical market standards.
108
+ - **Reverse Engineer Roadmap**: Draft `docs/010-Planning/Roadmap.md` based on implemented vs. missing features.
109
+ - **Define Objectives**: Draft `docs/010-Planning/OKRs.md` (Objectives and Key Results) aligned with the project's apparent direction.
110
+ - **Status Report**: Create a snapshot of current progress (`docs/010-Planning/Sprints/Current-Status.md`).
111
+ 2. **Review**: Present these strategic documents to the user for alignment.
112
+
113
+ ---
114
+
58
115
  # MODE B: From Requirements
59
116
 
60
117
  **Prerequisite**: Existing PRD (from `/brainstorm`).
@@ -68,13 +125,14 @@ description: Generate comprehensive documentation (Architecture, API, Specs) fro
68
125
  > - **MUST** use `sequential-thinking` for architectural decisions
69
126
  > - Use `context7` with `/vercel/next.js`, `/supabase/supabase` for tech stack research
70
127
 
71
- 1. **Invoke `[lead-architect]` skill** to draft:
128
+ 1. **Analyze Requirements**: Review the PRD/Roadmap. If there are ambiguities, **ASK** the user to clarify.
129
+ 2. **Invoke `[lead-architect]` skill** to draft:
72
130
  - High-level system architecture
73
131
  - Technology stack decisions
74
132
  - Component diagram
75
133
  - Data flow overview
76
- 2. Create `draft-sdd.md` artifact
77
- 3. After approval → Save to `docs/030-Specs/Architecture/SDD-{ProjectName}.md`
134
+ 3. Create `draft-sdd.md` artifact
135
+ 4. After approval → Save to `docs/030-Specs/Architecture/SDD-{ProjectName}.md`
78
136
 
79
137
  ---
80
138
 
@@ -85,6 +143,7 @@ description: Generate comprehensive documentation (Architecture, API, Specs) fro
85
143
  1. **Invoke `[business-analysis]` skill** to:
86
144
  - Break PRD features into Epics (`docs/022-User-Stories/Epics/`)
87
145
  - Define Use Cases with Mermaid diagrams (`docs/020-Requirements/Use-Cases/`)
146
+ - **Note**: If requirements are vague, ask for clarification.
88
147
  2. Create artifacts for review before saving
89
148
 
90
149
  ---
@@ -0,0 +1,58 @@
1
+ ---
2
+ description: Generate unit, E2E, security, and performance tests using the qa-tester skill.
3
+ ---
4
+
5
+ # Generate Tests Workflow
6
+
7
+ > [!IMPORTANT]
8
+ > **MANDATORY**: Apply `.agent/rules/documents.md` for all document creation and directory structure. All QA documents MUST be stored under `docs/035-QA/`.
9
+
10
+ ---
11
+
12
+ ## Step 1: Discovery & Strategy
13
+
14
+ // turbo
15
+
16
+ 1. **Invoke `[qa-tester]` skill** to analyze the `docs/` folder and current codebase structure.
17
+ 2. Ask the user which type of tests they want to generate:
18
+ - **Unit Tests**: For specific functions or utilities (e.g., `tests/unit/`).
19
+ - **E2E Tests**: For user flows (e.g., `tests/e2e/`).
20
+ - **Security Tests**: For vulnerability assessments.
21
+ - **Performance Tests**: For load and responsiveness checks.
22
+ 3. Identify the specific files or features that need testing based on user input.
23
+
24
+ ---
25
+
26
+ ## Step 2: Test Plan & Case Generation
27
+
28
+ // turbo
29
+
30
+ 1. **Invoke `[qa-tester]` skill** to create/update the Test Plan and Test Cases:
31
+ - For **Unit Tests**: Identify edge cases, boundary conditions, and happy paths.
32
+ - For **E2E Tests**: valid/invalid user flows.
33
+ - For **Security**: potential injection points, auth flaws.
34
+ 2. Generate the test documentation in `docs/035-QA/Test-Cases/` following the naming convention `TC-{Feature}-{NNN}.md`.
35
+ 3. Create a `draft-test-docs.md` artifact with the proposed test cases for review.
36
+
37
+ ---
38
+
39
+ ## Step 3: Test Code Generation
40
+
41
+ 1. **Wait** for user approval of the test cases.
42
+ 2. **Invoke `[qa-tester]` skill** to generate the actual test code.
43
+ - Use the project's existing testing framework (e.g., Jest, Playwright, Vitest).
44
+ - Ensure mocks and stubs are correctly implemented for unit tests.
45
+ - Ensure selectors and interaction steps are robust for E2E tests.
46
+ 3. Save the generated test code to the appropriate directories (e.g., `tests/unit/`, `tests/e2e/`).
47
+
48
+ ---
49
+
50
+ ## Step 4: Verification & Reporting
51
+
52
+ 1. Run the generated tests using the project's test runner.
53
+ 2. If tests fail:
54
+ - Analyze the failure.
55
+ - **Invoke `[qa-tester]` skill** to fix the test code or report the bug if it's a real issue.
56
+ 3. **Mandatory**:
57
+ - Update `docs/035-QA/QA-MOC.md`.
58
+ - Update `docs/000-Index.md` if needed.
@@ -0,0 +1,59 @@
1
+ ---
2
+ description: Create comprehensive test case documents and test plans based on project requirements.
3
+ ---
4
+
5
+ # QA Workflow
6
+
7
+ > [!IMPORTANT]
8
+ > **MANDATORY**: Apply `.agent/rules/documents.md` for all document creation and directory structure. All QA documents MUST be stored under `docs/035-QA/`.
9
+
10
+ ---
11
+
12
+ ## MCP Usage Guidelines
13
+
14
+ | MCP Tool | When to Use |
15
+ | :------------------------------------------- | :----------------------------------------------- |
16
+ | `mcp_sequential-thinking_sequentialthinking` | Analyze complex application logic and edge cases |
17
+ | `mcp_context7_query-docs` | Research testing frameworks or best practices |
18
+
19
+ ---
20
+
21
+ ## Step 1: Requirement Discovery
22
+
23
+ // turbo
24
+
25
+ 1. **Invoke `[qa-tester]` skill** to analyze the `docs/` folder.
26
+ 2. Identify features, constraints, and business logic that require testing.
27
+ 3. Map out:
28
+ - Happy Paths (Golden Flows)
29
+ - Negative Paths (Error handling)
30
+ - Boundary Cases
31
+ - Security/Performance considerations
32
+ 4. **WAIT** for user to confirm the list of scenarios to be documented.
33
+
34
+ ---
35
+
36
+ ## Step 2: Draft Test Documentation
37
+
38
+ // turbo
39
+
40
+ 1. **Invoke `[qa-tester]` skill** to create:
41
+ - **Test Plan**: High-level strategy for the current release/feature (`docs/035-QA/Test-Plans/`).
42
+ - **Test Cases**: Detailed step-by-step cases (`docs/035-QA/Test-Cases/`).
43
+ 2. Follow the standard mapping in `.agent/rules/documents.md`:
44
+ - Test Plan naming: `MTP-{Name}.md`
45
+ - Test Case naming: `TC-{Feature}-{NNN}.md`
46
+ 3. Create a `draft-qa-docs.md` artifact for review.
47
+
48
+ ---
49
+
50
+ ## Step 3: Finalize and Organize
51
+
52
+ // turbo
53
+
54
+ 1. After approval, save all files to their respective folders in `docs/035-QA/`.
55
+ 2. **Mandatory**:
56
+ - Update `docs/035-QA/QA-MOC.md`.
57
+ - Update `docs/000-Index.md` if needed.
58
+ - Ensure all frontmatter (id, type, status, created) is correctly populated according to `.agent/rules/documents.md`.
59
+ 3. Present summary of created tests.
package/README.md CHANGED
@@ -25,7 +25,7 @@ _We encourage teams to customize these skills and define their own rules & workf
25
25
  ### 📦 Components
26
26
 
27
27
  - 🧠 **12+ Multi-domain AI Skills** - From Product Manager, Business Analyst to Lead Architect.
28
- - 🔄 **6 Automated Workflows** - Pre-defined, reusable work processes.
28
+ - 🔄 **11 Automated Workflows** - Pre-defined, reusable work processes.
29
29
  - 📜 **Rules Engine** - A rule system that ensures AI Agents follow project standards.
30
30
  - 📚 **References Library** - Documentation references for various technologies.
31
31
 
@@ -139,14 +139,19 @@ Read and execute the workflow at .agent/workflows/brainstorm.md
139
139
 
140
140
  ## 🔄 Automated Workflows
141
141
 
142
- | Workflow | Description | Use Case |
143
- | :----------------------- | :--------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------ |
144
- | **`/bootstrap`** | Sets up project structure, installs dependencies, and configures environment based on architectural specs. | Start of Implementation Phase. |
145
- | **`/brainstorm`** | Analyze ideas with the user and create preliminary high-level documents (Roadmap, PRD). | Start of a new project or feature when you only have a rough idea. |
146
- | **`/custom-behavior`** | Safely customize Agent rules and workflows with impact analysis and user confirmation. | As needed to adjust Agent behavior or fix recurring mistakes. |
147
- | **`/documentation`** | Generate comprehensive documentation (Architecture, API, Specs) from either Codebase or Requirements. | Onboarding to a legacy project OR creating detailed specs from PRD. |
148
- | **`/implement-feature`** | Orchestrates feature implementation from specification to deployment. | After design and specs are ready, for actual coding and deployment. |
149
- | **`/ui-ux-design`** | Transform requirements into comprehensive UI/UX design deliverables. | After requirements are finalized, before coding. |
142
+ | Workflow | Description | Use Case |
143
+ | :----------------------- | :--------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------- |
144
+ | **`/bootstrap`** | Sets up project structure, installs dependencies, and configures environment based on architectural specs. | Start of Implementation Phase. |
145
+ | **`/brainstorm`** | Analyze ideas with the user and create preliminary high-level documents (Roadmap, PRD). | Start of a new project or feature when you only have a rough idea. |
146
+ | **`/break-tasks`** | Orchestrates breaking down requirements into actionable tasks for implementation. | When you have a PRD and need a task list. |
147
+ | **`/custom-behavior`** | Safely customize Agent rules and workflows with impact analysis and user confirmation. | Adjust Agent behavior or fix recurring mistakes. |
148
+ | **`/debug`** | Scientific debugging workflow: Hypothesize, Instrument, Reproduce, Analyze, Fix. | When facing complex bugs that need systematic analysis. |
149
+ | **`/development`** | General coding workflow for implementing changes, bug fixes, or minor features. | Day-to-day coding tasks. |
150
+ | **`/documentation`** | Generate comprehensive documentation (Architecture, API, Specs) from either Codebase or Requirements. | Onboarding or creating detailed specs. |
151
+ | **`/gen-tests`** | Generate unit, E2E, security, and performance tests using the qa-tester skill. | Improving test coverage for new or existing code. |
152
+ | **`/implement-feature`** | Orchestrates feature implementation from specification to deployment. | End-to-end feature development. |
153
+ | **`/qa`** | Create comprehensive test case documents and test plans based on project requirements. | Planning testing strategy for a feature. |
154
+ | **`/ui-ux-design`** | Transform requirements into comprehensive UI/UX design deliverables. | After requirements are finalized, before coding. |
150
155
 
151
156
  ---
152
157
 
@@ -4,11 +4,39 @@ const { program } = require("commander");
4
4
  const fs = require("fs-extra");
5
5
  const path = require("path");
6
6
  const chalk = require("chalk");
7
+ const crypto = require("crypto");
8
+ const os = require("os");
7
9
 
8
10
  program.version("0.0.1").description("Anti-Chaotic Agent Kit CLI");
9
11
 
10
12
  const REPO_URI = "kienhaminh/anti-chaotic/.agent";
11
13
 
14
+ /**
15
+ * Calculates SHA-256 hash of a file
16
+ */
17
+ async function getFileHash(filePath) {
18
+ const buffer = await fs.readFile(filePath);
19
+ return crypto.createHash("sha256").update(buffer).digest("hex");
20
+ }
21
+
22
+ /**
23
+ * Recursively gets all files in a directory
24
+ */
25
+ async function getAllFiles(dirPath, baseDir = dirPath) {
26
+ let results = [];
27
+ const list = await fs.readdir(dirPath, { withFileTypes: true });
28
+
29
+ for (const item of list) {
30
+ const fullPath = path.join(dirPath, item.name);
31
+ if (item.isDirectory()) {
32
+ results = results.concat(await getAllFiles(fullPath, baseDir));
33
+ } else {
34
+ results.push(path.relative(baseDir, fullPath));
35
+ }
36
+ }
37
+ return results;
38
+ }
39
+
12
40
  program
13
41
  .command("init")
14
42
  .description("Initialize the Anti-Chaotic Agent Kit (download from GitHub)")
@@ -26,22 +54,6 @@ program
26
54
  force: true,
27
55
  });
28
56
 
29
- // Cleanup deprecated files
30
- const deprecatedFiles = [
31
- "rules/documentation.md",
32
- "workflows/docs-from-codebase.md",
33
- "workflows/requirement-analysis.md",
34
- "workflows/setup-codebase.md",
35
- ];
36
-
37
- for (const file of deprecatedFiles) {
38
- const filePath = path.join(targetAgentDir, file);
39
- if (await fs.pathExists(filePath)) {
40
- await fs.remove(filePath);
41
- console.log(chalk.dim(` Removed legacy file: ${file}`));
42
- }
43
- }
44
-
45
57
  console.log(
46
58
  chalk.green("✔ Successfully installed Anti-Chaotic Agent Kit."),
47
59
  );
@@ -56,56 +68,158 @@ program
56
68
  .command("update")
57
69
  .description("Update .agent configuration from GitHub")
58
70
  .action(async () => {
59
- const targetAgentDir = path.join(process.cwd(), ".agent");
71
+ const projectRoot = process.cwd();
72
+ const targetAgentDir = path.join(projectRoot, ".agent");
73
+ const tempDir = path.join(os.tmpdir(), `anti-chaotic-update-${Date.now()}`);
60
74
  const { default: inquirer } = await import("inquirer");
61
75
 
62
76
  try {
63
- if (await fs.pathExists(targetAgentDir)) {
64
- const { confirm } = await inquirer.prompt([
65
- {
66
- type: "confirm",
67
- name: "confirm",
68
- message: `Directory ${targetAgentDir} already exists. Do you want to overwrite it?`,
69
- default: false,
70
- },
71
- ]);
72
-
73
- if (!confirm) {
74
- console.log(chalk.yellow("Operation cancelled by user."));
75
- return;
76
- }
77
+ if (!(await fs.pathExists(targetAgentDir))) {
78
+ console.log(
79
+ chalk.red("✘ .agent directory not found. Please run 'init' first."),
80
+ );
81
+ return;
77
82
  }
78
83
 
79
- console.log(
80
- chalk.blue(`Updating Anti-Chaotic Agent Kit from ${REPO_URI}...`),
81
- );
84
+ console.log(chalk.blue("Checking for updates from GitHub..."));
82
85
 
83
86
  const { downloadTemplate } = await import("giget");
84
87
  await downloadTemplate(`github:${REPO_URI}`, {
85
- dir: targetAgentDir,
88
+ dir: tempDir,
86
89
  force: true,
87
90
  });
88
91
 
89
- // Cleanup deprecated files
90
- const deprecatedFiles = [
91
- "rules/documentation.md",
92
- "workflows/docs-from-codebase.md",
93
- "workflows/requirement-analysis.md",
94
- "workflows/setup-codebase.md",
95
- ];
96
-
97
- for (const file of deprecatedFiles) {
98
- const filePath = path.join(targetAgentDir, file);
99
- if (await fs.pathExists(filePath)) {
100
- await fs.remove(filePath);
101
- console.log(chalk.dim(` Removed legacy file: ${file}`));
92
+ const localFiles = await getAllFiles(targetAgentDir);
93
+ const remoteFiles = await getAllFiles(tempDir);
94
+
95
+ const modified = [];
96
+ const added = [];
97
+ const deleted = [];
98
+
99
+ // Check for modified and deleted files
100
+ for (const file of localFiles) {
101
+ const localPath = path.join(targetAgentDir, file);
102
+ const remotePath = path.join(tempDir, file);
103
+
104
+ if (await fs.pathExists(remotePath)) {
105
+ const localHash = await getFileHash(localPath);
106
+ const remoteHash = await getFileHash(remotePath);
107
+ if (localHash !== remoteHash) {
108
+ modified.push(file);
109
+ }
110
+ } else {
111
+ deleted.push(file);
102
112
  }
103
113
  }
104
114
 
105
- console.log(chalk.green("✔ Successfully updated .agent from GitHub."));
106
- console.log(chalk.dim(` Location: ${targetAgentDir}`));
115
+ // Check for new files from remote
116
+ for (const file of remoteFiles) {
117
+ if (!localFiles.includes(file)) {
118
+ added.push(file);
119
+ }
120
+ }
121
+
122
+ if (modified.length === 0 && added.length === 0 && deleted.length === 0) {
123
+ console.log(
124
+ chalk.green("✔ Your .agent configuration is already up to date."),
125
+ );
126
+ await fs.remove(tempDir);
127
+ return;
128
+ }
129
+
130
+ console.log(chalk.yellow("\nUpdate Summary:"));
131
+
132
+ let filesToOverwrite = [];
133
+ let filesToAdd = [];
134
+ let filesToDelete = [];
135
+
136
+ if (modified.length > 0) {
137
+ const { selectedModified } = await inquirer.prompt([
138
+ {
139
+ type: "checkbox",
140
+ name: "selectedModified",
141
+ message:
142
+ "Select MODIFIED files to OVERWRITE (Unselected = Keep Local):",
143
+ choices: modified.map((f) => ({
144
+ name: f,
145
+ value: f,
146
+ checked: false,
147
+ })),
148
+ pageSize: 20,
149
+ },
150
+ ]);
151
+ filesToOverwrite = selectedModified;
152
+ }
153
+
154
+ if (added.length > 0) {
155
+ const { selectedAdded } = await inquirer.prompt([
156
+ {
157
+ type: "checkbox",
158
+ name: "selectedAdded",
159
+ message: "Select NEW files to ADD (Unselected = Skip):",
160
+ choices: added.map((f) => ({ name: f, value: f, checked: true })),
161
+ pageSize: 20,
162
+ },
163
+ ]);
164
+ filesToAdd = selectedAdded;
165
+ }
166
+
167
+ if (deleted.length > 0) {
168
+ const { selectedDeleted } = await inquirer.prompt([
169
+ {
170
+ type: "checkbox",
171
+ name: "selectedDeleted",
172
+ message:
173
+ "Select DELETED files to REMOVE locally (Unselected = Keep Local):",
174
+ choices: deleted.map((f) => ({ name: f, value: f, checked: true })),
175
+ pageSize: 20,
176
+ },
177
+ ]);
178
+ filesToDelete = selectedDeleted;
179
+ }
180
+
181
+ if (
182
+ filesToOverwrite.length === 0 &&
183
+ filesToAdd.length === 0 &&
184
+ filesToDelete.length === 0
185
+ ) {
186
+ console.log(chalk.yellow("No changes selected. Update cancelled."));
187
+ await fs.remove(tempDir);
188
+ return;
189
+ }
190
+
191
+ console.log(chalk.blue("\nApplying updates..."));
192
+
193
+ // Process Overwrites
194
+ for (const file of filesToOverwrite) {
195
+ const src = path.join(tempDir, file);
196
+ const dest = path.join(targetAgentDir, file);
197
+ await fs.copy(src, dest, { overwrite: true });
198
+ console.log(chalk.green(` ✔ Overwritten: ${file}`));
199
+ }
200
+
201
+ // Process New Files
202
+ for (const file of filesToAdd) {
203
+ const src = path.join(tempDir, file);
204
+ const dest = path.join(targetAgentDir, file);
205
+ await fs.copy(src, dest, { overwrite: false });
206
+ console.log(chalk.green(` ✔ Added: ${file}`));
207
+ }
208
+
209
+ // Process Deletions
210
+ for (const file of filesToDelete) {
211
+ const dest = path.join(targetAgentDir, file);
212
+ await fs.remove(dest);
213
+ console.log(chalk.red(` ✘ Deleted: ${file}`));
214
+ }
215
+
216
+ console.log(chalk.green("\n✔ Selected updates applied successfully."));
217
+
218
+ // Cleanup
219
+ await fs.remove(tempDir);
107
220
  } catch (err) {
108
221
  console.error(chalk.red("✘ Error updating framework:"), err.message);
222
+ if (await fs.pathExists(tempDir)) await fs.remove(tempDir);
109
223
  }
110
224
  });
111
225
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kienha/anti-chaotic",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Anti-Chaotic - An agent kit for Antigravity to standardize the software development process",
5
5
  "main": "index.js",
6
6
  "publishConfig": {