n2-soul 6.1.6 → 7.0.1
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/LICENSE +85 -16
- package/README.ko.md +41 -20
- package/README.md +128 -21
- package/index.js +35 -6
- package/lib/arachne/README.md +4 -0
- package/lib/arachne/assembler.js +441 -0
- package/lib/arachne/backup.js +218 -0
- package/lib/arachne/chunker.js +253 -0
- package/lib/arachne/dependency.js +185 -0
- package/lib/arachne/embedding.js +131 -0
- package/lib/arachne/ignore.js +134 -0
- package/lib/arachne/index.js +116 -0
- package/lib/arachne/indexer.js +194 -0
- package/lib/arachne/search.js +208 -0
- package/lib/arachne/store.js +420 -0
- package/lib/arachne/vector-store.js +159 -0
- package/lib/config.default.js +50 -0
- package/package.json +6 -4
- package/tools/arachne.js +214 -0
package/LICENSE
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
Apache License
|
|
3
2
|
Version 2.0, January 2004
|
|
4
3
|
http://www.apache.org/licenses/
|
|
@@ -35,19 +34,30 @@
|
|
|
35
34
|
|
|
36
35
|
"Work" shall mean the work of authorship, whether in Source or
|
|
37
36
|
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
39
|
|
|
40
40
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
41
|
form, that is based on (or derived from) the Work and for which the
|
|
42
42
|
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship.
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
44
47
|
|
|
45
48
|
"Contribution" shall mean any work of authorship, including
|
|
46
49
|
the original version of the Work and any modifications or additions
|
|
47
50
|
to that Work or Derivative Works thereof, that is intentionally
|
|
48
51
|
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
49
52
|
or by an individual or Legal Entity authorized to submit on behalf of
|
|
50
|
-
the copyright owner.
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
51
61
|
|
|
52
62
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
53
63
|
on behalf of whom a Contribution has been received by the Licensor and
|
|
@@ -68,7 +78,13 @@
|
|
|
68
78
|
where such license applies only to those patent claims licensable
|
|
69
79
|
by such Contributor that are necessarily infringed by their
|
|
70
80
|
Contribution(s) alone or by combination of their Contribution(s)
|
|
71
|
-
with the Work to which such Contribution(s) was submitted.
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
72
88
|
|
|
73
89
|
4. Redistribution. You may reproduce and distribute copies of the
|
|
74
90
|
Work or Derivative Works thereof in any medium, with or without
|
|
@@ -90,21 +106,74 @@
|
|
|
90
106
|
(d) If the Work includes a "NOTICE" text file as part of its
|
|
91
107
|
distribution, then any Derivative Works that You distribute must
|
|
92
108
|
include a readable copy of the attribution notices contained
|
|
93
|
-
within such NOTICE file
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
96
137
|
|
|
97
138
|
6. Trademarks. This License does not grant permission to use the trade
|
|
98
|
-
names, trademarks, service marks, or product names of the Licensor
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
99
142
|
|
|
100
143
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
101
|
-
agreed to in writing, Licensor provides the Work
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
108
177
|
|
|
109
178
|
Copyright 2026 N2
|
|
110
179
|
|
package/README.ko.md
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
**AI 에이전트는 세션이 끝나면 모든 걸 잊어버립니다. Soul이 그걸 해결합니다.**
|
|
6
6
|
**AI 에이전트가 위험한 행동을 할 수도 있습니다. Ark가 그걸 막습니다.**
|
|
7
|
+
**AI 에이전트가 관련 없는 코드를 읽느라 토큰을 낭비합니다. Arachne가 그걸 해결합니다.**
|
|
7
8
|
|
|
8
|
-
> ### 🚀
|
|
9
|
+
> ### 🚀 v7.0 업데이트 — Arachne
|
|
9
10
|
>
|
|
10
|
-
>
|
|
11
|
-
> ```js
|
|
12
|
-
> DATA_DIR: 'G:/내 드라이브/n2-soul'
|
|
11
|
+
> **Arachne** — 코드 컨텍스트 어셈블리 엔진. 코드베이스 전체를 인덱싱하고 AI에게 **정확히** 필요한 것만 전달합니다.
|
|
13
12
|
> ```
|
|
14
|
-
>
|
|
13
|
+
> 50,000 파일 프로젝트 → 가장 관련 있는 30개 청크 → 30K 토큰 (500K+ 대신)
|
|
14
|
+
> ```
|
|
15
|
+
> BM25 검색 + 의존성 추적 + 스마트 어셈블리. Ollama를 통한 시맨틱 검색도 지원. [자세히 →](#arachne--최고의-직조사)
|
|
15
16
|
>
|
|
16
17
|
> **Ark** (v6.0) 포함 — 토큰 비용 0으로 위험한 행동을 차단하는 AI 안전 시스템. [자세히 →](#ark--최후의-방패)
|
|
17
18
|
|
|
@@ -24,6 +25,7 @@ Cursor, VS Code Copilot 등 MCP 호환 AI 에이전트와 새 채팅을 시작
|
|
|
24
25
|
- 🏷️ **엔티티 메모리** — 인물, 하드웨어, 프로젝트를 자동 추적합니다 (v5.0)
|
|
25
26
|
- 💡 **코어 메모리** — 에이전트별 핵심 사실이 항상 로드됩니다 (v5.0)
|
|
26
27
|
- 🛡️ **Ark** — 토큰 비용 0으로 위험한 행동을 차단하는 AI 안전 시스템 (v6.0)
|
|
28
|
+
- 🕸️ **Arachne** — AI에게 정확히 필요한 코드만 전달하는 코드 컨텍스트 엔진 (v7.0)
|
|
27
29
|
|
|
28
30
|
> ⚡ **Soul은 N2 Browser의 작은 부속품 하나입니다** — 우리가 만들고 있는 AI 네이티브 브라우저의 일부예요. 멀티 에이전트 오케스트레이션, 실시간 도구 라우팅, 에이전트 간 통신 등 훨씬 더 많은 기능들이 현재 테스트 중입니다. 이건 시작에 불과합니다.
|
|
29
31
|
|
|
@@ -206,6 +208,7 @@ n2_work_end(project, title, summary, todo, entities, insights)
|
|
|
206
208
|
| **시맨틱 검색** | Ollama 임베딩 연동 (nomic-embed-text, 선택사항) |
|
|
207
209
|
| **백업/복원** | 설정 가능한 보존 기간의 증분 백업 |
|
|
208
210
|
| **Ark** | 토큰 비용 0으로 위험한 행동을 차단하는 AI 안전 시스템 (v6.0) |
|
|
211
|
+
| **🕸️ Arachne** | 🆕 코드 컨텍스트 어셈블리 — 코드베이스를 인덱싱하고 AI에게 필요한 것만 전달 (v7.0) |
|
|
209
212
|
| **☁️ 클라우드 저장** | 기억을 어디에든 저장 — Google Drive, NAS, 회사 서버, 아무 경로나 (v6.1) |
|
|
210
213
|
|
|
211
214
|
## ☁️ 클라우드 저장 — AI 기억을 원하는 곳 어디에든
|
|
@@ -270,6 +273,21 @@ DATA_DIR: '\\\\server\\team\\n2-soul' DATA_DIR: '\\\\server\\team\\n2-soul'
|
|
|
270
273
|
|
|
271
274
|
Soul의 데이터는 **100% 일반 JSON 파일** — `soul-board.json`, 원장 기록, 두뇌 메모리. 폴더를 미러링하는 동기화 서비스(Google Drive, OneDrive, Dropbox, Syncthing, rsync)라면 뭐든 완벽하게 작동합니다. 데이터베이스 마이그레이션도, API 버전도, SDK 업데이트도 필요 없습니다. 그냥 파일입니다.
|
|
272
275
|
|
|
276
|
+
## 🧹 스토리지 관리 및 GC (가비지 컬렉션)
|
|
277
|
+
|
|
278
|
+
수백 번의 세션이 누적되면 파일 개수가 무한정 늘어나지 않을까요? Soul은 이 문제를 구조적으로 해결합니다:
|
|
279
|
+
|
|
280
|
+
### 1. KV-Cache 가비지 컬렉션 (`n2_kv_gc`)
|
|
281
|
+
Soul에는 오래된 스냅샷을 자동으로 정리하는 `n2_kv_gc` 도구가 내장되어 있습니다.
|
|
282
|
+
설정에서 `maxAgeDays`를 지정해두면, 에이전트가 주기적으로 불필요해진 과거 스냅샷을 삭제하여 용량을 관리합니다.
|
|
283
|
+
|
|
284
|
+
### 2. 날짜별 파티셔닝 구조 (Ledger)
|
|
285
|
+
절대 지워지지 않는 작업 기록(Ledger)은 거대한 단일 DB 파일이 아닙니다. `ledger/YYYY/MM/DD/` 형태로 날짜별로 완벽히 분리 저장됩니다.
|
|
286
|
+
작년 기록을 백업하고 싶다면 `2025` 폴더만 압축하면 끝입니다. 6개월 지난 로그를 지우고 싶다면 해당 폴더만 지우면 됩니다. DB 파일이 꼬일 걱정이 0%입니다.
|
|
287
|
+
|
|
288
|
+
### 3. OS 레벨 통제권
|
|
289
|
+
Soul의 데이터는 모두 '일반 파일'이므로, OS 기본 기능(크론탭, 윈도우 작업 스케줄러 등)으로 보존 주기 정책을 독립적으로 제어하기 매우 쉽습니다. 특정 프로젝트 데이터가 더 이상 필요 없다면 그냥 폴더를 통째로 지우세요. 보이지 않는 DB 찌꺼기가 남지 않습니다.
|
|
290
|
+
|
|
273
291
|
## Ark — 최후의 방패
|
|
274
292
|
|
|
275
293
|

|
|
@@ -341,6 +359,7 @@ Soul의 데이터는 **100% 일반 JSON 파일** — `soul-board.json`, 원장
|
|
|
341
359
|
| `n2_kv_backup` | SQLite DB로 백업 |
|
|
342
360
|
| `n2_kv_restore` | 백업에서 복원 |
|
|
343
361
|
| `n2_kv_backup_list` | 백업 이력 조회 |
|
|
362
|
+
| `n2_arachne` | 🆕 코드 컨텍스트: 인덱싱, 검색, 어셈블, 백업, 상태 (v7.0) |
|
|
344
363
|
|
|
345
364
|
## KV-Cache 점진적 로딩
|
|
346
365
|
|
|
@@ -388,22 +407,23 @@ module.exports = {
|
|
|
388
407
|
|
|
389
408
|
```
|
|
390
409
|
soul/
|
|
391
|
-
├── rules/ # Ark 안전 규칙 (활성) ←
|
|
410
|
+
├── rules/ # Ark 안전 규칙 (활성) ← v6.0
|
|
392
411
|
│ └── default.n2 # 기본 규칙셋 (125개 패턴)
|
|
393
412
|
├── lib/
|
|
394
|
-
│
|
|
395
|
-
│
|
|
396
|
-
│
|
|
397
|
-
│
|
|
398
|
-
│
|
|
399
|
-
│
|
|
400
|
-
│
|
|
401
|
-
│
|
|
402
|
-
│
|
|
403
|
-
│
|
|
404
|
-
│
|
|
405
|
-
│
|
|
406
|
-
│
|
|
413
|
+
│ ├── ark/ # Ark 코어 엔진 ← v6.0
|
|
414
|
+
│ │ ├── index.js # createArk() 팩토리
|
|
415
|
+
│ │ ├── gate.js # SafetyGate 엔진
|
|
416
|
+
│ │ ├── parser.js # .n2 규칙 파서
|
|
417
|
+
│ │ ├── audit.js # 감사 로거
|
|
418
|
+
│ │ └── examples/ # 업종별 규칙 템플릿
|
|
419
|
+
│ └── arachne/ # Arachne 코드 컨텍스트 엔진 ← NEW v7.0
|
|
420
|
+
│ ├── index.js # createArachne() 팩토리
|
|
421
|
+
│ ├── indexer.js # 파일 스캐너 + 증분 인덱싱
|
|
422
|
+
│ ├── chunker.js # 언어 인식 코드 청킹
|
|
423
|
+
│ ├── search.js # BM25 검색 엔진
|
|
424
|
+
│ ├── assembler.js # 토큰 예산 기반 컨텍스트 어셈블리
|
|
425
|
+
│ ├── store.js # SQLite 저장 (sql.js)
|
|
426
|
+
│ └── ignore.js # .gitignore + .contextignore 지원
|
|
407
427
|
├── data/
|
|
408
428
|
│ ├── memory/ # 공유 두뇌 (n2_brain_read/write)
|
|
409
429
|
│ │ ├── entities.json # 엔티티 메모리 (자동 추적)
|
|
@@ -418,7 +438,8 @@ soul/
|
|
|
418
438
|
│ │ └── ledger/ # 변경 불가능한 작업 로그
|
|
419
439
|
│ │ └── 2026/03/09/
|
|
420
440
|
│ │ └── 001-agent.json
|
|
421
|
-
│ ├── ark-audit/ # Ark 차단/통과 로그 ←
|
|
441
|
+
│ ├── ark-audit/ # Ark 차단/통과 로그 ← v6.0
|
|
442
|
+
│ ├── arachne/ # Arachne 인덱스 DB + 임베딩 ← NEW v7.0
|
|
422
443
|
│ └── kv-cache/ # 세션 스냅샷
|
|
423
444
|
│ ├── snapshots/ # JSON 백엔드
|
|
424
445
|
│ ├── sqlite/ # SQLite 백엔드
|
package/README.md
CHANGED
|
@@ -6,18 +6,19 @@
|
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://nodejs.org)
|
|
8
8
|
[](https://www.npmjs.com/package/n2-soul)
|
|
9
|
-
[](https://github.com/choihyunsus/soul#arachne--the-greatest-weaver)
|
|
10
10
|
|
|
11
11
|
**Your AI agent forgets everything when a session ends. Soul fixes that.**
|
|
12
12
|
**Your AI agent might do something dangerous. Ark stops that.**
|
|
13
|
+
**Your AI agent wastes tokens reading irrelevant code. Arachne fixes that.**
|
|
13
14
|
|
|
14
|
-
> ### 🚀 What's New in
|
|
15
|
+
> ### 🚀 What's New in v7.0 — Arachne
|
|
15
16
|
>
|
|
16
|
-
>
|
|
17
|
-
> ```js
|
|
18
|
-
> DATA_DIR: 'G:/My Drive/n2-soul'
|
|
17
|
+
> **Arachne** — Code Context Assembly Engine. Indexes your entire codebase and picks **exactly** what your AI needs.
|
|
19
18
|
> ```
|
|
20
|
-
>
|
|
19
|
+
> 50,000 file project → 30 most relevant chunks → 30K tokens (instead of 500K+)
|
|
20
|
+
> ```
|
|
21
|
+
> BM25 search + dependency tracking + smart assembly. Optional semantic search via Ollama. [Learn more →](#arachne--the-greatest-weaver)
|
|
21
22
|
>
|
|
22
23
|
> Also includes **Ark** (v6.0) — built-in AI safety that blocks dangerous actions at zero token cost. [Learn more →](#ark--the-last-shield)
|
|
23
24
|
|
|
@@ -30,6 +31,7 @@ Every time you start a new chat with Cursor, VS Code Copilot, or any MCP-compati
|
|
|
30
31
|
- 🏷️ **Entity Memory** — auto-tracks people, hardware, projects (v5.0)
|
|
31
32
|
- 💡 **Core Memory** — agent-specific always-loaded facts (v5.0)
|
|
32
33
|
- 🛡️ **Ark** — built-in AI safety that blocks dangerous actions at zero token cost (v6.0)
|
|
34
|
+
- 🕸️ **Arachne** — code context assembly engine that picks exactly what AI needs (v7.0)
|
|
33
35
|
|
|
34
36
|
> ⚡ **Soul is one small component of N2 Browser** — an AI-native browser we're building. Multi-agent orchestration, real-time tool routing, inter-agent communication, and much more are currently in testing. This is just the beginning.
|
|
35
37
|
|
|
@@ -47,6 +49,7 @@ Every time you start a new chat with Cursor, VS Code Copilot, or any MCP-compati
|
|
|
47
49
|
- [Configuration](#configuration)
|
|
48
50
|
- [Contributing](#contributing)
|
|
49
51
|
- [Ark — The Last Shield](#ark--the-last-shield)
|
|
52
|
+
- [Arachne — The Greatest Weaver](#arachne--the-greatest-weaver)
|
|
50
53
|
|
|
51
54
|
## Quick Start
|
|
52
55
|
|
|
@@ -243,6 +246,7 @@ n2_work_end(project, title, summary, todo, entities, insights)
|
|
|
243
246
|
| **Semantic Search** | Optional Ollama embedding (nomic-embed-text) |
|
|
244
247
|
| **Backup/Restore** | Incremental backups with configurable retention |
|
|
245
248
|
| **Ark** | 🆕 Built-in AI safety — blocks dangerous actions at zero token cost |
|
|
249
|
+
| **Arachne** | 🆕 Code context assembly — indexes codebase, picks exactly what AI needs (v7.0) |
|
|
246
250
|
| **Cloud Storage** | 🆕 Store memory anywhere — Google Drive, NAS, network server, any path (v6.1) |
|
|
247
251
|
|
|
248
252
|
## ☁️ Cloud Storage — Store Your AI Memory Anywhere
|
|
@@ -307,6 +311,20 @@ DATA_DIR: '\\\\server\\team\\n2-soul' DATA_DIR: '\\\\server\\team\\n2-soul'
|
|
|
307
311
|
|
|
308
312
|
Soul's data is **100% plain JSON files** — `soul-board.json`, ledger entries, brain memory. Any sync service that mirrors folders (Google Drive, OneDrive, Dropbox, Syncthing, rsync) works perfectly because there's nothing to integrate. No database migrations, no API versions, no SDK updates. Just files.
|
|
309
313
|
|
|
314
|
+
## 🧹 Storage Management & Garbage Collection
|
|
315
|
+
|
|
316
|
+
As agents run hundreds of sessions, file count inevitably grows. Soul handles this infinite growth gracefully:
|
|
317
|
+
|
|
318
|
+
### 1. KV-Cache Garbage Collection (`n2_kv_gc`)
|
|
319
|
+
Soul includes a built-in `n2_kv_gc` tool that automatically cleans up old KV-Cache snapshots.
|
|
320
|
+
Set `maxAgeDays` in your config, and Soul will autonomously delete stale session data while preserving recent history.
|
|
321
|
+
|
|
322
|
+
### 2. Time-Partitioned Ledger
|
|
323
|
+
The immutable work ledger isn't a single massive database file. It's partitioned by date (`ledger/YYYY/MM/DD/`).
|
|
324
|
+
Want to archive 2025's logs? Just zip the `2025` folder. Want to delete logs older than 6 months? Just delete the old folders. Zero database corruption risk.
|
|
325
|
+
|
|
326
|
+
### 3. OS-Level Sovereignty
|
|
327
|
+
Because Soul's "cloud" is just your local filesystem mapped to a sync drive, you can use standard OS tools (cron jobs, Windows Task Scheduler, bash scripts) to enforce retention policies. If you delete a project folder, the project is gone. No dangling DB rows.
|
|
310
328
|
|
|
311
329
|
## Ark — The Last Shield
|
|
312
330
|
|
|
@@ -522,6 +540,92 @@ module.exports = {
|
|
|
522
540
|
- **Wildcard destruction** — blocks `rm *`, `find -delete`, `xargs rm` (self-protection bypass)
|
|
523
541
|
- **Command execution gate** — `@gate` on `execute_command`, `run_shell`, etc. (whitelist approach)
|
|
524
542
|
|
|
543
|
+
## Arachne — The Greatest Weaver
|
|
544
|
+
|
|
545
|
+
> *In Greek mythology, Arachne was a mortal weaver whose tapestries rivaled the gods. She wove exactly the right threads in exactly the right places.*
|
|
546
|
+
|
|
547
|
+
**Arachne** is Soul's code context assembly engine. It indexes your entire codebase and picks **exactly** the chunks your AI agent needs — no more, no less.
|
|
548
|
+
|
|
549
|
+
### The Problem
|
|
550
|
+
|
|
551
|
+
AI agents waste massive tokens reading irrelevant code:
|
|
552
|
+
|
|
553
|
+
| Approach | Tokens used | Relevance |
|
|
554
|
+
|----------|:----------:|:---------:|
|
|
555
|
+
| **Paste entire file** | 10,000+ | ~20% relevant |
|
|
556
|
+
| **Dump whole project** | 500,000+ | ~5% relevant |
|
|
557
|
+
| **Arachne** | ~30,000 | **~90% relevant** |
|
|
558
|
+
|
|
559
|
+
### How Arachne Works
|
|
560
|
+
|
|
561
|
+
```
|
|
562
|
+
Your 50,000-file project
|
|
563
|
+
│
|
|
564
|
+
┌────┴────┐
|
|
565
|
+
│ Index │ ← Scans all files, chunks by function/class
|
|
566
|
+
│ (boot) │ Incremental: only re-indexes changed files
|
|
567
|
+
└────┬────┘
|
|
568
|
+
│
|
|
569
|
+
┌────┴────┐
|
|
570
|
+
│ Search │ ← BM25 keyword search (+ optional semantic via Ollama)
|
|
571
|
+
│ (query) │ Finds the most relevant chunks across all files
|
|
572
|
+
└────┬────┘
|
|
573
|
+
│
|
|
574
|
+
┌────┴────┐
|
|
575
|
+
│ Assemble │ ← Picks top chunks within your token budget
|
|
576
|
+
│ (budget) │ 4 layers: fixed + short-term + associative + spare
|
|
577
|
+
└────┬────┘
|
|
578
|
+
│
|
|
579
|
+
30 most relevant
|
|
580
|
+
code chunks → AI
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### Key Features
|
|
584
|
+
|
|
585
|
+
| Feature | Description |
|
|
586
|
+
|---------|------------|
|
|
587
|
+
| **Incremental Indexing** | Only re-indexes changed files (hash-based detection) |
|
|
588
|
+
| **Language-Aware Chunking** | Splits code by function/class boundaries, not arbitrary lines |
|
|
589
|
+
| **BM25 Search** | Fast keyword search with TF-IDF ranking |
|
|
590
|
+
| **Semantic Search** | Optional Ollama embeddings (nomic-embed-text) |
|
|
591
|
+
| **Token Budget Assembly** | Smart context assembly within configurable token limits |
|
|
592
|
+
| **4-Layer Assembly** | Fixed (10%) + Short-term (30%) + Associative (40%) + Spare (20%) |
|
|
593
|
+
| **17 Languages** | JS, TS, Python, Rust, Go, Java, C/C++, C#, Ruby, PHP, Swift, Kotlin |
|
|
594
|
+
| **12 Text Formats** | MD, JSON, YAML, XML, HTML, CSS, SQL, Shell scripts |
|
|
595
|
+
| **Backup/Restore** | Incremental backups with configurable retention |
|
|
596
|
+
|
|
597
|
+
### Configuration
|
|
598
|
+
|
|
599
|
+
Arachne settings in `lib/config.default.js`:
|
|
600
|
+
|
|
601
|
+
```js
|
|
602
|
+
ARACHNE: {
|
|
603
|
+
projectDir: null, // Set to your project root to enable
|
|
604
|
+
indexing: {
|
|
605
|
+
autoIndex: true, // Auto-index on boot
|
|
606
|
+
maxFileSize: 512 * 1024,
|
|
607
|
+
},
|
|
608
|
+
assembly: {
|
|
609
|
+
defaultBudget: 30000, // Token budget for context
|
|
610
|
+
},
|
|
611
|
+
embedding: {
|
|
612
|
+
enabled: false, // true = requires: ollama pull nomic-embed-text
|
|
613
|
+
},
|
|
614
|
+
}
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
### Usage
|
|
618
|
+
|
|
619
|
+
```
|
|
620
|
+
n2_arachne(action: "index") → Index your project files
|
|
621
|
+
n2_arachne(action: "search", query: "authentication JWT") → Search code
|
|
622
|
+
n2_arachne(action: "assemble", query: "how does auth work?", budget: 30000) → Full context assembly
|
|
623
|
+
n2_arachne(action: "status") → Check index status
|
|
624
|
+
n2_arachne(action: "backup") → Backup index DB
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
> **Also available as standalone package:** [`n2-arachne`](https://www.npmjs.com/package/n2-arachne) — use Arachne without Soul.
|
|
628
|
+
|
|
525
629
|
## Available Tools
|
|
526
630
|
|
|
527
631
|
| Tool | Description |
|
|
@@ -545,6 +649,7 @@ module.exports = {
|
|
|
545
649
|
| `n2_kv_backup` | Backup to portable SQLite DB |
|
|
546
650
|
| `n2_kv_restore` | Restore from backup |
|
|
547
651
|
| `n2_kv_backup_list` | List backup history |
|
|
652
|
+
| `n2_arachne` | 🆕 Code context: index, search, assemble, backup, status (v7.0) |
|
|
548
653
|
|
|
549
654
|
## KV-Cache Progressive Loading
|
|
550
655
|
|
|
@@ -662,22 +767,23 @@ All runtime data is stored in `data/` (gitignored, auto-created):
|
|
|
662
767
|
|
|
663
768
|
```
|
|
664
769
|
soul/
|
|
665
|
-
├── rules/ # Ark safety rules (active) ←
|
|
770
|
+
├── rules/ # Ark safety rules (active) ← v6.0
|
|
666
771
|
│ └── default.n2 # Default ruleset (125 patterns)
|
|
667
772
|
├── lib/
|
|
668
|
-
│
|
|
669
|
-
│
|
|
670
|
-
│
|
|
671
|
-
│
|
|
672
|
-
│
|
|
673
|
-
│
|
|
674
|
-
│
|
|
675
|
-
│
|
|
676
|
-
│
|
|
677
|
-
│
|
|
678
|
-
│
|
|
679
|
-
│
|
|
680
|
-
│
|
|
773
|
+
│ ├── ark/ # Ark core engine ← v6.0
|
|
774
|
+
│ │ ├── index.js # createArk() factory
|
|
775
|
+
│ │ ├── gate.js # SafetyGate engine
|
|
776
|
+
│ │ ├── parser.js # .n2 rule parser
|
|
777
|
+
│ │ ├── audit.js # Audit logger
|
|
778
|
+
│ │ └── examples/ # Industry rule templates
|
|
779
|
+
│ └── arachne/ # Arachne code context engine ← NEW v7.0
|
|
780
|
+
│ ├── index.js # createArachne() factory
|
|
781
|
+
│ ├── indexer.js # File scanner + incremental indexing
|
|
782
|
+
│ ├── chunker.js # Language-aware code chunking
|
|
783
|
+
│ ├── search.js # BM25 search engine
|
|
784
|
+
│ ├── assembler.js # Context assembly with token budget
|
|
785
|
+
│ ├── store.js # SQLite storage (sql.js)
|
|
786
|
+
│ └── ignore.js # .gitignore + .contextignore support
|
|
681
787
|
├── data/
|
|
682
788
|
│ ├── memory/ # Shared brain (n2_brain_read/write)
|
|
683
789
|
│ │ ├── entities.json # Entity Memory (auto-tracked)
|
|
@@ -692,7 +798,8 @@ soul/
|
|
|
692
798
|
│ │ └── ledger/ # Immutable work logs
|
|
693
799
|
│ │ └── 2026/03/09/
|
|
694
800
|
│ │ └── 001-agent.json
|
|
695
|
-
│ ├── ark-audit/ # Ark block/pass logs ←
|
|
801
|
+
│ ├── ark-audit/ # Ark block/pass logs ← v6.0
|
|
802
|
+
│ ├── arachne/ # Arachne index DB + embeddings ← NEW v7.0
|
|
696
803
|
│ └── kv-cache/ # Session snapshots
|
|
697
804
|
│ ├── snapshots/ # JSON backend
|
|
698
805
|
│ ├── sqlite/ # SQLite backend
|
package/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
// Soul MCP
|
|
1
|
+
// Soul MCP v7.0 — Entry point. Multi-agent session orchestrator with KV-Cache + Ark + Arachne.
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
4
4
|
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
5
5
|
const { z } = require('zod');
|
|
6
6
|
const config = require('./lib/config');
|
|
7
7
|
const { createArk } = require('./lib/ark');
|
|
8
|
+
const { createArachne } = require('./lib/arachne');
|
|
8
9
|
|
|
9
10
|
// Sequences — agent lifecycle management
|
|
10
11
|
const { registerBootSequence } = require('./sequences/boot');
|
|
11
12
|
const { registerWorkSequence } = require('./sequences/work');
|
|
12
13
|
const { registerEndSequence } = require('./sequences/end');
|
|
13
14
|
|
|
14
|
-
// Tools — shared memory + KV-Cache persistence
|
|
15
|
+
// Tools — shared memory + KV-Cache persistence + code context
|
|
15
16
|
const { registerBrainTools } = require('./tools/brain');
|
|
16
17
|
const { registerKVCacheTools } = require('./tools/kv-cache');
|
|
18
|
+
const { registerArachneTools } = require('./tools/arachne');
|
|
17
19
|
|
|
18
20
|
const pkg = require('./package.json');
|
|
19
21
|
const server = new McpServer({
|
|
@@ -57,13 +59,40 @@ server.registerTool = (name, schema, handler) => {
|
|
|
57
59
|
};
|
|
58
60
|
// ═══ End Ark ═══
|
|
59
61
|
|
|
60
|
-
// Register
|
|
62
|
+
// Register core modules (all tools pass through Ark)
|
|
61
63
|
registerBootSequence(server, z, config);
|
|
62
64
|
registerWorkSequence(server, z, config);
|
|
63
65
|
registerEndSequence(server, z, config);
|
|
64
66
|
registerBrainTools(server, z, config);
|
|
65
67
|
registerKVCacheTools(server, z, config);
|
|
66
68
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
// ═══════════════════════════════════════════════════════
|
|
70
|
+
// Arachne — THE GREATEST WEAVER
|
|
71
|
+
// Code context assembly engine — indexes codebase,
|
|
72
|
+
// picks exactly what AI needs.
|
|
73
|
+
// Only activates when ARACHNE config is present.
|
|
74
|
+
// ═══════════════════════════════════════════════════════
|
|
75
|
+
async function boot() {
|
|
76
|
+
// Initialize Arachne (if configured)
|
|
77
|
+
if (config.ARACHNE?.projectDir) {
|
|
78
|
+
try {
|
|
79
|
+
const arachne = await createArachne({
|
|
80
|
+
...config.ARACHNE,
|
|
81
|
+
dataDir: config.ARACHNE.dataDir ?? path.join(config.DATA_DIR, 'arachne'),
|
|
82
|
+
});
|
|
83
|
+
registerArachneTools(server, z, arachne, config);
|
|
84
|
+
console.error(`[n2-soul] Arachne enabled: ${config.ARACHNE.projectDir}`);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(`[n2-soul] Arachne init failed: ${err.message}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Start MCP transport
|
|
91
|
+
const transport = new StdioServerTransport();
|
|
92
|
+
await server.connect(transport);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
boot().catch(err => {
|
|
96
|
+
console.error(`[n2-soul] Fatal: ${err.message}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|