autosnippet 3.3.3 → 3.3.5
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/README.md +176 -81
- package/config/constitution.yaml +2 -0
- package/dist/lib/cli/KnowledgeSyncService.d.ts +5 -1
- package/dist/lib/cli/KnowledgeSyncService.js +5 -2
- package/dist/lib/domain/knowledge/values/Stats.d.ts +1 -1
- package/dist/lib/domain/knowledge/values/Stats.js +2 -2
- package/dist/lib/external/mcp/handlers/consolidated.js +178 -0
- package/dist/lib/external/mcp/handlers/task.js +36 -14
- package/dist/lib/external/mcp/tools.js +2 -1
- package/dist/lib/injection/modules/InfraModule.js +4 -1
- package/dist/lib/injection/modules/KnowledgeModule.js +23 -0
- package/dist/lib/repository/evolution/ProposalRepository.d.ts +99 -0
- package/dist/lib/repository/evolution/ProposalRepository.js +255 -0
- package/dist/lib/service/bootstrap/UiStartupTasks.d.ts +17 -4
- package/dist/lib/service/bootstrap/UiStartupTasks.js +53 -5
- package/dist/lib/service/evolution/DecayDetector.d.ts +4 -3
- package/dist/lib/service/evolution/DecayDetector.js +97 -22
- package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +4 -2
- package/dist/lib/service/evolution/KnowledgeMetabolism.js +29 -2
- package/dist/lib/service/evolution/ProposalExecutor.d.ts +62 -0
- package/dist/lib/service/evolution/ProposalExecutor.js +360 -0
- package/dist/lib/service/evolution/StagingManager.js +5 -3
- package/dist/lib/service/guard/GuardCrossFileChecks.js +2 -0
- package/dist/lib/service/guard/ReverseGuard.d.ts +1 -1
- package/dist/lib/service/guard/ReverseGuard.js +32 -2
- package/dist/lib/service/knowledge/SourceRefReconciler.d.ts +2 -0
- package/dist/lib/service/knowledge/SourceRefReconciler.js +48 -0
- package/dist/lib/service/task/IntentExtractor.d.ts +3 -1
- package/dist/lib/service/task/IntentExtractor.js +30 -10
- package/dist/lib/service/task/PrimeSearchPipeline.js +67 -12
- package/dist/lib/shared/schemas/mcp-tools.d.ts +2 -0
- package/dist/lib/shared/schemas/mcp-tools.js +9 -1
- package/package.json +1 -1
- package/templates/instructions/conventions.md +4 -2
package/README.md
CHANGED
|
@@ -2,177 +2,272 @@
|
|
|
2
2
|
|
|
3
3
|
# AutoSnippet
|
|
4
4
|
|
|
5
|
-
Extract
|
|
5
|
+
Extract patterns from your codebase into a knowledge base that AI coding assistants can query in your IDE — so generated code actually follows your team's conventions.
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/autosnippet)
|
|
8
8
|
[](https://github.com/GxFn/AutoSnippet/blob/main/LICENSE)
|
|
9
|
-
[](https://nodejs.org)
|
|
10
10
|
|
|
11
|
-
[
|
|
11
|
+
[中文](README_CN.md)
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
- [Why](#why) · [
|
|
17
|
+
- [Why](#why) · [Getting Started](#getting-started) · [Using in IDE](#using-in-ide) · [Evolution Architecture](#evolution-architecture) · [Engineering Capabilities](#engineering-capabilities) · [IDE Support](#ide-support) · [Docs](#docs)
|
|
18
18
|
|
|
19
19
|
## Why
|
|
20
20
|
|
|
21
|
-
Copilot and Cursor don't know how your team writes code.
|
|
21
|
+
Copilot and Cursor don't know how your team writes code. What they generate works, but doesn't look like yours — wrong naming, wrong patterns, wrong abstractions. You end up rewriting AI output or explaining the same conventions in every Code Review.
|
|
22
22
|
|
|
23
|
-
AutoSnippet builds a
|
|
23
|
+
AutoSnippet builds a layer of **localized project memory**. It scans your codebase, extracts valuable patterns (with your approval), and makes them searchable by all AI tools via [MCP](https://modelcontextprotocol.io/). Knowledge persists locally, never consuming the LLM context window — it's injected on-demand when the AI needs it. The more knowledge accumulates, the more the generated code matches your conventions.
|
|
24
24
|
|
|
25
25
|
```
|
|
26
26
|
Your code → AI extracts patterns → You review → Knowledge base
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
↓
|
|
28
|
+
Cursor / Copilot / VS Code / Xcode
|
|
29
|
+
↓
|
|
30
|
+
AI generates your way
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Getting Started
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
36
|
npm install -g autosnippet
|
|
37
37
|
|
|
38
38
|
cd your-project
|
|
39
|
-
asd setup # workspace +
|
|
40
|
-
asd ui #
|
|
39
|
+
asd setup # Initialize workspace + database + MCP config (auto-detects Cursor / VS Code / Trae / Qoder)
|
|
40
|
+
asd ui # Start background service (MCP Server + Dashboard) — IDE and MCP tools depend on this
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
> **Trae / Qoder users:** After `asd setup`, run `asd mirror` to sync `.cursor/` config to `.trae/` / `.qoder/`.
|
|
44
44
|
|
|
45
|
-
## Using in
|
|
45
|
+
## Using in IDE
|
|
46
46
|
|
|
47
|
-
`asd setup`
|
|
47
|
+
`asd setup` configures everything. Open your IDE's **Agent Mode** (Cursor Composer / VS Code Copilot Chat / Trae) and start chatting.
|
|
48
48
|
|
|
49
|
-
> **First time:**
|
|
49
|
+
> **First time:** Manually enable the `autosnippet` service in your IDE's MCP settings.
|
|
50
50
|
|
|
51
|
-
> **Tip:**
|
|
51
|
+
> **Tip:** Stronger models work better. We recommend Claude Opus 4 / Sonnet 4, GPT-5, or Gemini 3 Pro in Cursor / Copilot for more accurate patterns and fewer false positives.
|
|
52
52
|
|
|
53
|
-
### Cold Start: Build
|
|
53
|
+
### Cold Start: Build Your Knowledge Base
|
|
54
54
|
|
|
55
|
-
> 💬 *"
|
|
55
|
+
> 💬 *"Cold start — build the project knowledge base"*
|
|
56
56
|
|
|
57
|
-
The
|
|
57
|
+
The Agent scans your entire project, extracting coding patterns, architecture conventions, and call habits, while generating a project Wiki. Cold start runs once; after that, it's daily use.
|
|
58
58
|
|
|
59
|
-
### Daily:
|
|
59
|
+
### Daily Use: Just Ask
|
|
60
60
|
|
|
61
61
|
| You say | You get |
|
|
62
62
|
|---------|---------|
|
|
63
|
-
| ① *"How do we write API endpoints in this project?"* | Code
|
|
64
|
-
| ② *"Write a user registration endpoint"* | Generated code automatically follows the API conventions
|
|
65
|
-
| ③ *"Check if this file follows
|
|
66
|
-
| ④ *"Save this error handling as a project convention"* | One
|
|
63
|
+
| ① *"How do we write API endpoints in this project?"* | Code following your project's actual style, not generic examples |
|
|
64
|
+
| ② *"Write a user registration endpoint"* | Generated code automatically follows the API conventions just retrieved |
|
|
65
|
+
| ③ *"Check if this file follows our conventions"* | Pre-commit convention check — fewer back-and-forths in Code Review |
|
|
66
|
+
| ④ *"Save this error handling pattern as a project convention"* | One-time capture — every team member's AI learns this pattern |
|
|
67
67
|
|
|
68
|
-
After the Agent
|
|
68
|
+
After the Agent finishes writing code, the Guard compliance engine auto-checks the diff — violations trigger self-repair, no manual intervention needed.
|
|
69
69
|
|
|
70
|
-
###
|
|
70
|
+
### Gets Better Over Time
|
|
71
71
|
|
|
72
|
-
Review candidates in Dashboard (`asd ui`) →
|
|
72
|
+
Review and approve candidates in Dashboard (`asd ui`) → they become **Recipes** → AI references them when generating code → you spot new good patterns → keep capturing → AI increasingly writes like a team member. Knowledge is local Markdown files, travels with git, never disappears with conversations, and doesn't consume context window — no matter how large the knowledge base grows, it won't slow down AI.
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
---
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
## Evolution Architecture
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
AutoSnippet isn't a static knowledge tool — it's a **knowledge organism**. Recipes are its cells — the IDE Agent is the external driving force, and each interaction triggers coordinated responses from different organs inside the organism.
|
|
79
79
|
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
```
|
|
81
|
+
IDE Agent (Cursor / Copilot / Trae)
|
|
82
|
+
│
|
|
83
|
+
│ Capture · Write · Search · Shift · Complete · Boundary
|
|
84
|
+
│
|
|
85
|
+
═════════════════▼══════════════════════════════════════
|
|
86
|
+
║ AutoSnippet Knowledge Organism ║
|
|
87
|
+
║ ║
|
|
88
|
+
║ ┌─ Panorama (Skeleton) ──── Project Structure ───┐ ║
|
|
89
|
+
║ │ │ ║
|
|
90
|
+
║ │ Signal (Nerves) ◄────► Governance (Digest) │ ║
|
|
91
|
+
║ │ ↕ ↕ │ ║
|
|
92
|
+
║ │ ┌──────────┐ │ ║
|
|
93
|
+
║ │ │ Recipe │ │ ║
|
|
94
|
+
║ │ │ Living │ │ ║
|
|
95
|
+
║ │ │Knowledge │ │ ║
|
|
96
|
+
║ │ └──────────┘ │ ║
|
|
97
|
+
║ │ ↕ ↕ │ ║
|
|
98
|
+
║ │ Guard (Immunity) ◄────► Tool Forge (Create) │ ║
|
|
99
|
+
║ │ │ ║
|
|
100
|
+
║ └────────────────────────────────────────────────┘ ║
|
|
101
|
+
║ ║
|
|
102
|
+
══════════════════════════════════════════════════════════
|
|
84
103
|
```
|
|
85
104
|
|
|
86
|
-
|
|
105
|
+
### Agent Actions × Organism Responses
|
|
87
106
|
|
|
88
|
-
|
|
107
|
+
Each IDE Agent action triggers coordinated responses from different organs:
|
|
89
108
|
|
|
90
|
-
|
|
109
|
+
| Agent Action | Organism Response | Organs Involved |
|
|
110
|
+
|-------------|------------------|-----------------|
|
|
111
|
+
| **Capture knowledge** — extract and submit patterns | Digestive system metabolizes internally: confidence routing → staging observation → evolves or decays. Developer retains full intervention rights | Digest → Nerves |
|
|
112
|
+
| **Write code** — start coding | Nervous system analyzes intent, auto-injects relevant Recipes with sourceRefs source evidence for higher trust | Nerves → Recipe |
|
|
113
|
+
| **Search knowledge** — active search | Precise retrieval based on current intent + file context, multi-path fusion ranking, dynamic weight adjustment per scenario | Nerves → Recipe |
|
|
114
|
+
| **Shift intent** — change direction | Nervous system records drift signals, senses problems; immune system reverse-checks whether Recipes are still valid | Nerves → Immunity |
|
|
115
|
+
| **Complete task** — finish writing code | Immune system triggers Guard Review, attaches relevant Recipes for Agent to fix violations | Immunity → Recipe |
|
|
116
|
+
| **Capability boundary** — hit an unsolvable problem | Creation system calls LLM to forge temporary tools, vm-sandboxed execution, auto-reclaimed on expiry | Create |
|
|
91
117
|
|
|
92
|
-
###
|
|
118
|
+
### Five Organs
|
|
93
119
|
|
|
94
|
-
|
|
120
|
+
**Skeleton — Panorama**
|
|
95
121
|
|
|
96
|
-
|
|
122
|
+
The organism's structural awareness. AST + call graphs infer module roles & layers (four-signal fusion, 13 role types), Tarjan SCC computes coupling, Kahn topological sort infers layering, DimensionAnalyzer generates 11-dimension health radar, outputting coverage heatmaps and gap reports. All organs share this project overview.
|
|
97
123
|
|
|
98
|
-
|
|
124
|
+
**Digest — Governance**
|
|
99
125
|
|
|
100
|
-
|
|
126
|
+
The metabolic engine for new knowledge entering the organism. ContradictionDetector finds conflicts, RedundancyAnalyzer flags duplication, DecayDetector scores decay (6 strategies + 4-dimension scoring), ConfidenceRouter numerically routes (≥ 0.85 auto-publishes, < 0.2 rejects). ProposalExecutor auto-executes evolution proposals on expiry (7 types, differentiated observation windows). Six-state lifecycle: `pending → staging → active → evolving/decaying → deprecated`.
|
|
101
127
|
|
|
102
|
-
|
|
128
|
+
**Nerves — Signal + Intent**
|
|
103
129
|
|
|
104
|
-
|
|
130
|
+
Senses all Agent behavior. IntentExtractor extracts terms, infers language and module, cross-language synonym expansion, identifies 4 scenarios. SignalBus unifies 12 signal types (guard / search / usage / lifecycle / quality / exploration / panorama / decay / forge / intent / anomaly / guard_blind_spot), HitRecorder batches usage events. When the Agent shifts intent, nerves record drift signals and coordinate the immune system for reverse checking.
|
|
105
131
|
|
|
106
|
-
|
|
132
|
+
**Immunity — Guard**
|
|
107
133
|
|
|
108
|
-
|
|
134
|
+
Bidirectional immune system. Forward: four-layer detection (regex → code-level multi-line → tree-sitter AST → cross-file), built-in 8-language rules, three-state output (pass / violation / uncertain). Backward: ReverseGuard verifies Recipe-referenced API symbols still exist (5 drift types). Auto-triggers Review when Agent completes a task, handing violations along with relevant Recipes to the Agent for fixing. RuleLearner tracks P/R/F1 for auto-tuning.
|
|
109
135
|
|
|
110
|
-
|
|
136
|
+
**Create — Tool Forge**
|
|
111
137
|
|
|
112
|
-
|
|
138
|
+
Creativity at capability boundaries. Three progressive modes — Reuse (0ms) → Compose (10ms, atomic tool assembly) → Generate (~5s, LLM writes code → vm sandbox validation: 5s timeout + 18 security rules). Temporary tools have 30min TTL, auto-reclaimed on expiry. LLM participates only during forging; execution is fully deterministic.
|
|
113
139
|
|
|
114
|
-
|
|
140
|
+
### Design Philosophy
|
|
115
141
|
|
|
116
|
-
|
|
142
|
+
1. **AI Compile-Time + Engineering Runtime** — LLM produces deterministic artifacts; runtime is pure engineering logic
|
|
143
|
+
2. **Deterministic Marking + Probabilistic Resolution** — Each layer does its deterministic part; uncertainty escalates to AI
|
|
144
|
+
3. **Orthogonal Composition > Specialized Subclasses** — Capability × Strategy × Policy replaces N subclasses
|
|
145
|
+
4. **Signal-Driven > Time-Driven** — Trigger on signal saturation, not scheduled scans
|
|
146
|
+
5. **Defense in Depth** — Constitution → Gateway → Permission → SafetyPolicy → PathGuard → ConfidenceRouter
|
|
117
147
|
|
|
118
|
-
|
|
148
|
+
> Organ implementation details, engineering metrics, and defense chain breakdown in [Technical Reference](docs/technical-reference.en.md)
|
|
119
149
|
|
|
120
|
-
|
|
150
|
+
---
|
|
121
151
|
|
|
122
|
-
|
|
123
|
-
<img src="docs/images/dashboard-help-en.png" alt="Dashboard Help" width="800" />
|
|
124
|
-
</div>
|
|
152
|
+
## Engineering Capabilities
|
|
125
153
|
|
|
126
|
-
|
|
154
|
+
The above is the organism itself. Below are the engineering integration capabilities it exposes.
|
|
127
155
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
156
|
+
### Guard CLI
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
asd guard src/ # Check directory
|
|
160
|
+
asd guard:staged # pre-commit: staged files only
|
|
161
|
+
asd guard:ci --min-score 90 # CI quality gate
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Multi-Language AST
|
|
165
|
+
|
|
166
|
+
11-language tree-sitter: Go · Python · Java · Kotlin · Swift · JS · TS · Rust · ObjC · Dart · C#. 5-stage CallGraph, incremental analysis, 8 project types auto-detected.
|
|
167
|
+
|
|
168
|
+
### 6-Channel IDE Delivery
|
|
169
|
+
|
|
170
|
+
Knowledge changes auto-deliver to IDE-consumable formats:
|
|
136
171
|
|
|
137
|
-
|
|
172
|
+
| Channel | Path | Content |
|
|
173
|
+
|---------|------|---------|
|
|
174
|
+
| **A** | `.cursor/rules/autosnippet-project-rules.mdc` | alwaysApply one-liner rules |
|
|
175
|
+
| **B** | `.cursor/rules/autosnippet-patterns-{topic}.mdc` | When/Do/Don't themed rules |
|
|
176
|
+
| **C · D** | `.cursor/skills/` | Project Skills + development docs |
|
|
177
|
+
| **F** | `AGENTS.md` / `CLAUDE.md` / `.github/copilot-instructions.md` | Agent instructions |
|
|
178
|
+
| **Mirror** | `.qoder/` / `.trae/` | IDE mirrors |
|
|
179
|
+
|
|
180
|
+
### More
|
|
181
|
+
|
|
182
|
+
- **Bootstrap Cold Start** — 6-phase · 10-dimension analysis, one-time knowledge base build
|
|
183
|
+
- **Knowledge Graph** — 14 relationship types, query impact paths and dependency depth
|
|
184
|
+
- **Semantic Search** — HNSW vector index + field-weighted scoring hybrid, RRF fusion + 7-signal ranking
|
|
185
|
+
- **sourceRefs** — Recipes carry source evidence, Agent trusts without self-verification
|
|
186
|
+
- **Lark Remote** — Message from phone, intent routes to Bot or IDE
|
|
187
|
+
- **Remote Repository** — Recipe directory as git sub-repo, shared across projects
|
|
188
|
+
|
|
189
|
+
> AI-driven features require an LLM API Key. Supports Google / OpenAI / Claude / DeepSeek / Ollama with automatic fallback.
|
|
190
|
+
|
|
191
|
+
---
|
|
138
192
|
|
|
139
193
|
## Project Structure
|
|
140
194
|
|
|
141
|
-
After `asd setup`, your project
|
|
195
|
+
After `asd setup`, your project gains these:
|
|
142
196
|
|
|
143
197
|
```
|
|
144
198
|
your-project/
|
|
145
199
|
├── AutoSnippet/ # Knowledge data (git-tracked)
|
|
146
|
-
│ ├── recipes/ #
|
|
200
|
+
│ ├── recipes/ # Reviewed patterns (Markdown)
|
|
147
201
|
│ ├── candidates/ # Pending review
|
|
148
|
-
│
|
|
202
|
+
│ ├── skills/ # Project-specific Agent instructions
|
|
203
|
+
│ └── wiki/ # Project Wiki
|
|
149
204
|
├── .autosnippet/ # Runtime cache (gitignored)
|
|
150
|
-
│ ├── autosnippet.db # SQLite
|
|
151
|
-
│ └── context/ # Vector index
|
|
152
|
-
├── .cursor/
|
|
153
|
-
|
|
205
|
+
│ ├── autosnippet.db # SQLite (WAL mode)
|
|
206
|
+
│ └── context/ # Vector index (HNSW)
|
|
207
|
+
├── .cursor/
|
|
208
|
+
│ ├── mcp.json # Cursor MCP config
|
|
209
|
+
│ ├── rules/ # Channel A + B rules
|
|
210
|
+
│ └── skills/ # Channel C + D Skills
|
|
211
|
+
├── .vscode/mcp.json # VS Code MCP config
|
|
212
|
+
├── .github/copilot-instructions.md
|
|
213
|
+
├── AGENTS.md
|
|
214
|
+
└── CLAUDE.md
|
|
154
215
|
```
|
|
155
216
|
|
|
156
|
-
Recipes are Markdown files. SQLite is a read cache. If the
|
|
217
|
+
Recipes are Markdown files. SQLite is just a read cache. If the database breaks, `asd sync` rebuilds it.
|
|
157
218
|
|
|
158
|
-
|
|
219
|
+
---
|
|
159
220
|
|
|
160
|
-
|
|
221
|
+
## IDE Support
|
|
161
222
|
|
|
162
|
-
|
|
223
|
+
| IDE | Integration | Details |
|
|
224
|
+
|-----|------------|---------|
|
|
225
|
+
| **VS Code** | Extension + MCP | `#asd` tool references in Agent Mode; search, directives, CodeLens, Guard diagnostic squiggles, light-bulb fixes |
|
|
226
|
+
| **Cursor** | MCP + Rules | `.cursor/mcp.json` + `.cursor/rules/` + `.cursor/skills/` |
|
|
227
|
+
| **Claude Code** | MCP + CLAUDE.md | `CLAUDE.md` + MCP tools; supports hooks |
|
|
228
|
+
| **Trae / Qoder** | MCP | `asd setup` auto-generates, `asd mirror` syncs config |
|
|
229
|
+
| **Xcode** | File watching | `asd watch` + file directives + Snippet sync |
|
|
230
|
+
| **Lark** | Bot + WebSocket | Message from phone → intent recognition → Bot Agent or IDE Agent Mode execution |
|
|
163
231
|
|
|
164
|
-
|
|
232
|
+
### VS Code Extension
|
|
233
|
+
|
|
234
|
+
- **Comment Directives**: `// as:s <query>` search & insert, `// as:c` create candidate from selection, `// as:a` audit current file
|
|
235
|
+
- **CodeLens**: Clickable actions above directives
|
|
236
|
+
- **Guard Diagnostics**: Violations shown as squiggles + light-bulb quick fixes
|
|
237
|
+
- **Status Bar**: Live API Server connection status
|
|
238
|
+
|
|
239
|
+
All configuration auto-generated by `asd setup`. Run `asd upgrade` after updates.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Docs
|
|
244
|
+
|
|
245
|
+
| Document | Content |
|
|
246
|
+
|----------|---------|
|
|
247
|
+
| [Technical Reference](docs/technical-reference.en.md) | Six subsystem implementation details, engineering metrics, defense chain |
|
|
248
|
+
| [Dashboard](docs/dashboard.en.md) | Dashboard views and tech stack |
|
|
249
|
+
| [CLI Reference](docs/cli-reference.en.md) | Full usage for all 20 commands |
|
|
250
|
+
| [MCP Tools Reference](docs/mcp-tools.en.md) | 16 MCP tools with parameters and usage |
|
|
251
|
+
| [Architecture](docs/architecture.en.md) | Overall architecture and module design |
|
|
252
|
+
| [Configuration](docs/configuration.en.md) | LLM and advanced configuration options |
|
|
253
|
+
| [Guard Guide](docs/guard.en.md) | Guard rules and customization |
|
|
254
|
+
| [IDE Integration](docs/ide-integration.en.md) | Detailed IDE setup guides |
|
|
255
|
+
| [Lark Integration](docs/lark-integration.en.md) | Lark Bot setup and usage |
|
|
256
|
+
| [Agent Architecture](docs/agent-architecture.en.md) | Agent Runtime and MCP protocol |
|
|
257
|
+
| [Development](docs/development.en.md) | Contributing and dev environment setup |
|
|
258
|
+
|
|
259
|
+
---
|
|
165
260
|
|
|
166
261
|
## Requirements
|
|
167
262
|
|
|
168
263
|
- Node.js ≥ 22
|
|
169
|
-
- macOS recommended (Xcode features
|
|
264
|
+
- macOS recommended (Xcode features require it; other features are cross-platform)
|
|
170
265
|
- better-sqlite3 (bundled)
|
|
171
266
|
|
|
172
267
|
## Contributing
|
|
173
268
|
|
|
174
|
-
1. `npm test` before submitting
|
|
175
|
-
2. Follow existing patterns (ESM, domain-driven structure)
|
|
269
|
+
1. Run `npm test` before submitting
|
|
270
|
+
2. Follow existing code patterns (ESM, domain-driven structure)
|
|
176
271
|
|
|
177
272
|
## License
|
|
178
273
|
|
package/config/constitution.yaml
CHANGED
|
@@ -36,6 +36,7 @@ roles:
|
|
|
36
36
|
- "candidate:update"
|
|
37
37
|
- "knowledge:create"
|
|
38
38
|
- "knowledge:update"
|
|
39
|
+
- "knowledge:evolve"
|
|
39
40
|
- "submit:knowledge"
|
|
40
41
|
- "read:audit_logs:self"
|
|
41
42
|
- "knowledge:bootstrap"
|
|
@@ -46,6 +47,7 @@ roles:
|
|
|
46
47
|
- "delete:skills"
|
|
47
48
|
constraints:
|
|
48
49
|
- "can submit knowledge entries (all go to pending)"
|
|
50
|
+
- "can create evolution proposals (merge/enhance/deprecate — system auto-executes)"
|
|
49
51
|
- "cannot publish/deprecate knowledge — only developer can do that"
|
|
50
52
|
- "can reactivate deprecated entries back to pending"
|
|
51
53
|
- "cannot modify Guard rules"
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import Logger from '../infrastructure/logging/Logger.js';
|
|
17
17
|
import type { ApplyReport, ReconcileReport, RepairReport } from '../service/knowledge/SourceRefReconciler.js';
|
|
18
|
+
import { SourceRefReconciler } from '../service/knowledge/SourceRefReconciler.js';
|
|
18
19
|
export interface SyncAllReport {
|
|
19
20
|
synced: number;
|
|
20
21
|
created: number;
|
|
@@ -27,11 +28,14 @@ export interface SyncAllReport {
|
|
|
27
28
|
applyReport?: ApplyReport;
|
|
28
29
|
}
|
|
29
30
|
export declare class KnowledgeSyncService {
|
|
31
|
+
#private;
|
|
30
32
|
candidatesDir: string;
|
|
31
33
|
logger: ReturnType<typeof Logger.getInstance>;
|
|
32
34
|
projectRoot: string;
|
|
33
35
|
recipesDir: string;
|
|
34
|
-
constructor(projectRoot: string
|
|
36
|
+
constructor(projectRoot: string, options?: {
|
|
37
|
+
sourceRefReconciler?: SourceRefReconciler;
|
|
38
|
+
});
|
|
35
39
|
/**
|
|
36
40
|
* 完整同步入口 — sync + reconcile + repair
|
|
37
41
|
*
|
|
@@ -25,11 +25,13 @@ export class KnowledgeSyncService {
|
|
|
25
25
|
logger;
|
|
26
26
|
projectRoot;
|
|
27
27
|
recipesDir;
|
|
28
|
-
|
|
28
|
+
#sourceRefReconciler;
|
|
29
|
+
constructor(projectRoot, options) {
|
|
29
30
|
this.projectRoot = projectRoot;
|
|
30
31
|
this.recipesDir = path.join(projectRoot, RECIPES_DIR);
|
|
31
32
|
this.candidatesDir = path.join(projectRoot, CANDIDATES_DIR);
|
|
32
33
|
this.logger = Logger.getInstance();
|
|
34
|
+
this.#sourceRefReconciler = options?.sourceRefReconciler ?? null;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* 完整同步入口 — sync + reconcile + repair
|
|
@@ -46,7 +48,8 @@ export class KnowledgeSyncService {
|
|
|
46
48
|
const report = { ...syncReport };
|
|
47
49
|
// 2. 填充/验证 recipe_source_refs 桥接表
|
|
48
50
|
try {
|
|
49
|
-
const reconciler =
|
|
51
|
+
const reconciler = this.#sourceRefReconciler ??
|
|
52
|
+
new SourceRefReconciler(this.projectRoot, db);
|
|
50
53
|
report.reconcileReport = reconciler.reconcile({ force: opts.force });
|
|
51
54
|
// 3. git rename 修复
|
|
52
55
|
report.repairReport = await reconciler.repairRenames();
|
|
@@ -43,7 +43,7 @@ export declare class Stats {
|
|
|
43
43
|
static from(input: unknown): Stats;
|
|
44
44
|
/** 增加计数 */
|
|
45
45
|
increment(counter: StatsCounter, delta?: number): Stats;
|
|
46
|
-
/**
|
|
46
|
+
/** 记录一次命中,同时更新时间戳(Unix 秒) */
|
|
47
47
|
recordHit(counter: StatsCounter, timestamp?: number): Stats;
|
|
48
48
|
/** 转换为 JSON */
|
|
49
49
|
toJSON(): {
|
|
@@ -60,8 +60,8 @@ export class Stats {
|
|
|
60
60
|
this[counter] += delta;
|
|
61
61
|
return this;
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
64
|
-
recordHit(counter, timestamp = Date.now()) {
|
|
63
|
+
/** 记录一次命中,同时更新时间戳(Unix 秒) */
|
|
64
|
+
recordHit(counter, timestamp = Math.floor(Date.now() / 1000)) {
|
|
65
65
|
this[counter] += 1;
|
|
66
66
|
this.lastHitAt = timestamp;
|
|
67
67
|
if (counter === 'searchHits') {
|