soulbridge 0.0.0-stage → 0.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 +202 -0
- package/NOTICE +35 -0
- package/README.md +98 -2
- package/package.json +43 -4
- package/packages/cli/src/cli.ts +220 -0
- package/packages/core/src/context.ts +77 -0
- package/packages/core/src/index.ts +146 -0
- package/packages/core/src/reflect.ts +117 -0
- package/packages/core/src/scoring.ts +87 -0
- package/packages/core/src/sqlite.ts +202 -0
- package/packages/core/src/store.ts +22 -0
- package/packages/core/src/types.ts +119 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2023 The Sigstore Authors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
soulbridge
|
|
2
|
+
Copyright 2026 soulbridge contributors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
--------------------------------------------------------------------------------
|
|
7
|
+
Third-party notices
|
|
8
|
+
--------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
Source code bundled in this repository: none.
|
|
11
|
+
|
|
12
|
+
The repository contains only original code and documentation. Runtime behavior
|
|
13
|
+
relies on Node.js built-in modules (notably `node:sqlite`), which are distributed
|
|
14
|
+
under the Node.js license and are not covered by this repository's license.
|
|
15
|
+
|
|
16
|
+
Design references (ideas, not code)
|
|
17
|
+
-----------------------------------
|
|
18
|
+
- The four-verb protocol shape (context / observe / recall / reflect) is an
|
|
19
|
+
original design informed by common agent lifecycle conventions, including the
|
|
20
|
+
Model Context Protocol's tool conventions.
|
|
21
|
+
- The emotion taxonomy *structure* used by the future affect layer (7 categories,
|
|
22
|
+
intensity 1–9, polarity) follows the publicly documented structure of the
|
|
23
|
+
Dalian University of Technology affective lexicon (DUTIR).
|
|
24
|
+
|
|
25
|
+
No word list from DUTIR — or from any third-party lexicon — is bundled here.
|
|
26
|
+
Any lexicon a user supplies remains subject to that user's own licensing
|
|
27
|
+
obligations. See docs/adr/0006-licensing.md.
|
|
28
|
+
|
|
29
|
+
--------------------------------------------------------------------------------
|
|
30
|
+
Trademarks
|
|
31
|
+
--------------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
"Claude", "Cursor", "Codex", "Pi" and other product names are trademarks of their
|
|
34
|
+
respective owners. References to them describe interoperability targets only and
|
|
35
|
+
imply no affiliation or endorsement.
|
package/README.md
CHANGED
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# soulbridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **给任何 agent 装上一个人格层。**
|
|
4
|
+
> A personality layer for any agent — continuity, forgetting, and growth across tools.
|
|
5
|
+
|
|
6
|
+
**状态:v0.0.1 骨架 · 未发布 · 接口随时会变**
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 它解决什么
|
|
11
|
+
|
|
12
|
+
Claude Code 记得你在 Claude Code 里说过的话,Cursor 不记得,Pi 不记得。
|
|
13
|
+
你的偏好、你的判断、你被纠正过的错——换一个工具,全部归零。
|
|
14
|
+
|
|
15
|
+
soulbridge 是它们之间那层**不属于任何一家**的记忆与人格:
|
|
16
|
+
|
|
17
|
+
> 一个 soul,多个宿主;一个人格,持续成长。
|
|
18
|
+
|
|
19
|
+
## 它不做什么
|
|
20
|
+
|
|
21
|
+
| 不做 | 为什么 |
|
|
22
|
+
|---|---|
|
|
23
|
+
| agent runtime | 宿主已经免费提供了,再写一遍是重复劳动 |
|
|
24
|
+
| 向量数据库 / RAG 引擎 | 内容是商品,检索可以接现成的 |
|
|
25
|
+
| 云端服务 | 默认全本地,数据不出机器 |
|
|
26
|
+
| “更像人”的叙事营销 | 只承诺可观测的事 |
|
|
27
|
+
|
|
28
|
+
## 四个动词
|
|
29
|
+
|
|
30
|
+
宿主只需要在四个时机调用,就完成了接入:
|
|
31
|
+
|
|
32
|
+
| 动词 | 时机 | 作用 |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `context()` | 会话开始 | 注入:身份 + 画像 + 相关记忆 + 表达风格 |
|
|
35
|
+
| `observe(turn)` | 每轮结束 | 观察:写入经历、更新情绪 |
|
|
36
|
+
| `recall(q)` | 需要时 | 召回:按相关性/新旧/重要度/唤醒次数排序 |
|
|
37
|
+
| `reflect(session)` | 会话结束 | 反思:把经历固化成策略与认知 |
|
|
38
|
+
|
|
39
|
+
详见 [docs/protocol.md](docs/protocol.md)。
|
|
40
|
+
|
|
41
|
+
## 30 秒跑起来
|
|
42
|
+
|
|
43
|
+
零依赖,只需要 Node ≥ 22(原生跑 TypeScript + `node:sqlite`):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
node packages/cli/src/cli.ts init
|
|
47
|
+
node packages/cli/src/cli.ts remember --type strategy "提交前先跑 make check,能省一轮 CI"
|
|
48
|
+
node packages/cli/src/cli.ts context --query "要不要先跑测试"
|
|
49
|
+
node packages/cli/src/cli.ts demo # 起一个 soul,跑完整 context→observe→reflect→context
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
不需要模型、不需要网络、不需要数据库服务。
|
|
53
|
+
|
|
54
|
+
## 架构
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
宿主(Claude Code / Pi / DSH / Cursor / Codex)
|
|
58
|
+
│ hooks + MCP
|
|
59
|
+
▼
|
|
60
|
+
packages/core 人格状态 · 评分 · 注入 · 反思 (约 800 行,零依赖)
|
|
61
|
+
│
|
|
62
|
+
▼
|
|
63
|
+
SQLite(默认) / Postgres(可选)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- **人格状态**(身份 / 情绪 / 策略 / 关系 / 特质):结构化、量小,SQL 就够
|
|
67
|
+
- **内容记忆**(对话片段 / 文档):v0 用关键词检索,之后可换成向量或外部服务
|
|
68
|
+
|
|
69
|
+
详见 [docs/architecture.md](docs/architecture.md)。
|
|
70
|
+
|
|
71
|
+
## 设计文档
|
|
72
|
+
|
|
73
|
+
| 文档 | 内容 |
|
|
74
|
+
|---|---|
|
|
75
|
+
| [thesis](docs/thesis.md) | 核心命题、三条可证伪预测、四臂实验、放弃条件 |
|
|
76
|
+
| [RFC 0001](docs/rfcs/0001-foundations.md) | 定位、用户、非目标、成功指标、四个动词、接入阶梯 |
|
|
77
|
+
| [ADR 索引](docs/rfcs/README.md) | 11 条已生效的架构决定(定位/语言/存储/依赖/协议/许可/接入/范围/评估/质量) |
|
|
78
|
+
| [protocol.v0](docs/spec/protocol.v0.md) | 四个动词的完整契约:字段、错误码、降级、测试映射 |
|
|
79
|
+
| [quality](docs/quality.md) | 质量模型、九条门禁、五条评审清单 |
|
|
80
|
+
| [references](docs/references.md) | 外部资料的去留与过期判断 |
|
|
81
|
+
|
|
82
|
+
**规则**:架构级改动必须先有 RFC 或 ADR;聊天里达成的不算决定。
|
|
83
|
+
|
|
84
|
+
## 为什么值得做
|
|
85
|
+
|
|
86
|
+
见 [docs/thesis.md](docs/thesis.md):核心命题、三条可证伪预测、四臂实验设计。
|
|
87
|
+
如果实验否定它,这个项目就该停——**先定好什么情况下放弃,再开始写代码。**
|
|
88
|
+
|
|
89
|
+
## 隐私
|
|
90
|
+
|
|
91
|
+
- 默认 SQLite,落在 `~/.soulbridge/soul.db`
|
|
92
|
+
- 零遥测、零上报
|
|
93
|
+
- 记忆可导出、可删除、可迁移
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
[Apache-2.0](LICENSE) —— 含明确专利授权,便于企业采用。第三方声明见 [NOTICE](NOTICE)。
|
|
98
|
+
|
|
99
|
+
本项目不捆绑任何第三方源码。未来若引入词库等外部资产,必须单独核查许可([ADR 0006](docs/adr/0006-licensing.md))。
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soulbridge",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A personality layer for any agent: continuity, forgetting, and growth across tools.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"soulbridge": "packages/cli/src/cli.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"packages/core/src",
|
|
12
|
+
"packages/cli/src",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"NOTICE"
|
|
16
|
+
],
|
|
17
|
+
"workspaces": [
|
|
18
|
+
"packages/*"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.18"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Jason0826/soulbridge.git"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/Jason0826/soulbridge#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/Jason0826/soulbridge/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"ai-agent",
|
|
33
|
+
"memory",
|
|
34
|
+
"personality",
|
|
35
|
+
"continuity",
|
|
36
|
+
"mcp",
|
|
37
|
+
"claude-code"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "node --test \"packages/core/test/*.test.ts\"",
|
|
41
|
+
"demo": "node packages/cli/src/cli.ts demo",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"prepublishOnly": "npm test"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Minimal CLI. No framework, no dependencies.
|
|
4
|
+
*
|
|
5
|
+
* soulbridge init
|
|
6
|
+
* soulbridge remember "以后提交前先跑 make check" --type strategy --importance 8
|
|
7
|
+
* soulbridge context --query "提交前要做什么"
|
|
8
|
+
* soulbridge recall "测试"
|
|
9
|
+
* soulbridge reflect --text "..." (or --file transcript.txt)
|
|
10
|
+
* soulbridge stats
|
|
11
|
+
* soulbridge demo
|
|
12
|
+
*/
|
|
13
|
+
import { mkdirSync, readFileSync, rmSync } from 'node:fs';
|
|
14
|
+
import { dirname, resolve } from 'node:path';
|
|
15
|
+
import type { MemoryType, Turn } from '../../core/src/index.ts';
|
|
16
|
+
import type { Soul as SoulType } from '../../core/src/index.ts';
|
|
17
|
+
|
|
18
|
+
// node:sqlite prints an ExperimentalWarning the moment it loads. Replace the default
|
|
19
|
+
// printer with a filter: the CLI's own output stays clean, other warnings still show.
|
|
20
|
+
// Must run before the dynamic import below, which is why that import is dynamic.
|
|
21
|
+
process.removeAllListeners('warning');
|
|
22
|
+
process.on('warning', (warning) => {
|
|
23
|
+
if (warning.message.includes('SQLite is an experimental feature')) return;
|
|
24
|
+
process.stderr.write(`${warning.name}: ${warning.message}\n`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { openSqlite, Soul } = await import('../../core/src/index.ts');
|
|
28
|
+
|
|
29
|
+
interface Parsed {
|
|
30
|
+
cmd: string;
|
|
31
|
+
positional: string[];
|
|
32
|
+
flags: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parse(argv: string[]): Parsed {
|
|
36
|
+
const [cmd = 'help', ...rest] = argv;
|
|
37
|
+
const positional: string[] = [];
|
|
38
|
+
const flags: Record<string, string> = {};
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
41
|
+
const arg = rest[i];
|
|
42
|
+
if (!arg.startsWith('--')) {
|
|
43
|
+
positional.push(arg);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const key = arg.slice(2);
|
|
47
|
+
const next = rest[i + 1];
|
|
48
|
+
if (next !== undefined && !next.startsWith('--')) {
|
|
49
|
+
flags[key] = next;
|
|
50
|
+
i += 1;
|
|
51
|
+
} else {
|
|
52
|
+
flags[key] = 'true';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { cmd, positional, flags };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function dbFile(): string {
|
|
60
|
+
const file = process.env.SOULBRIDGE_DB ?? resolve(process.cwd(), '.soulbridge', 'soul.db');
|
|
61
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
62
|
+
return file;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function open(file?: string, createdAt?: number): { soul: SoulType; file: string } {
|
|
66
|
+
const target = file ?? dbFile();
|
|
67
|
+
const store = openSqlite(target);
|
|
68
|
+
const soul = new Soul({
|
|
69
|
+
store,
|
|
70
|
+
soulId: process.env.SOULBRIDGE_SOUL ?? 'xiaoling',
|
|
71
|
+
userId: process.env.SOULBRIDGE_USER ?? 'local',
|
|
72
|
+
name: process.env.SOULBRIDGE_NAME ?? '小灵',
|
|
73
|
+
createdAt,
|
|
74
|
+
});
|
|
75
|
+
return { soul, file: target };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function out(value: unknown): void {
|
|
79
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function demo(): Promise<void> {
|
|
83
|
+
const dir = resolve(process.cwd(), '.soulbridge');
|
|
84
|
+
mkdirSync(dir, { recursive: true });
|
|
85
|
+
const file = resolve(dir, 'demo.db');
|
|
86
|
+
for (const suffix of ['', '-wal', '-shm']) rmSync(`${file}${suffix}`, { force: true });
|
|
87
|
+
|
|
88
|
+
// Backdate the birthday so the demo shows a relationship that has time in it.
|
|
89
|
+
const seed = openSqlite(file);
|
|
90
|
+
seed.ensureSoul({ soulId: 'xiaoling', name: '小灵', createdAt: Date.now() - 3 * 86_400_000 });
|
|
91
|
+
seed.close();
|
|
92
|
+
|
|
93
|
+
const soul = new Soul({ store: openSqlite(file), soulId: 'xiaoling', userId: 'demo', name: '小灵' });
|
|
94
|
+
|
|
95
|
+
process.stdout.write('=== 第 1 次会话(刚认识,还没有记忆)===\n');
|
|
96
|
+
process.stdout.write(`${soul.context().text}\n\n`);
|
|
97
|
+
|
|
98
|
+
process.stdout.write('=== 会话结束,反思 ===\n');
|
|
99
|
+
const result = await soul.reflect([
|
|
100
|
+
{ role: 'user', content: '以后提交前先跑 make check,别等 CI 挂了再修' },
|
|
101
|
+
{ role: 'assistant', content: '好,记住了。' },
|
|
102
|
+
{ role: 'user', content: '我喜欢简洁的回答,不要铺垫' },
|
|
103
|
+
{ role: 'user', content: '不对,这个方案是错的' },
|
|
104
|
+
]);
|
|
105
|
+
process.stdout.write(`写入 ${result.memories} 条记忆,情绪 ${JSON.stringify(result.emotion)}\n\n`);
|
|
106
|
+
|
|
107
|
+
process.stdout.write('=== 第 2 次会话:开场(无查询,按重要度注入全部)===\n');
|
|
108
|
+
process.stdout.write(`${soul.context().text}\n\n`);
|
|
109
|
+
|
|
110
|
+
process.stdout.write('=== 同一会话中,用户问「提交前要做什么」(有查询,只注入相关的)===\n');
|
|
111
|
+
process.stdout.write(`${soul.context({ query: '提交前要做什么' }).text}\n\n`);
|
|
112
|
+
|
|
113
|
+
process.stdout.write('=== stats ===\n');
|
|
114
|
+
out(soul.stats());
|
|
115
|
+
process.stdout.write(`\n数据库:${file}\n`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function main(): Promise<void> {
|
|
119
|
+
const { cmd, positional, flags } = parse(process.argv.slice(2));
|
|
120
|
+
|
|
121
|
+
switch (cmd) {
|
|
122
|
+
case 'init': {
|
|
123
|
+
const { soul, file } = open();
|
|
124
|
+
out({ ok: true, db: file, ...soul.stats() });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case 'remember': {
|
|
129
|
+
const content = positional.join(' ').trim();
|
|
130
|
+
if (!content) throw new Error('usage: soulbridge remember "内容" [--type T] [--importance N]');
|
|
131
|
+
const { soul } = open();
|
|
132
|
+
const id = soul.remember(content, {
|
|
133
|
+
type: (flags.type as MemoryType | undefined) ?? 'fact',
|
|
134
|
+
importance: flags.importance ? Number(flags.importance) : undefined,
|
|
135
|
+
});
|
|
136
|
+
out({ ok: true, id });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
case 'context': {
|
|
141
|
+
const { soul } = open();
|
|
142
|
+
const result = soul.context({
|
|
143
|
+
query: flags.query,
|
|
144
|
+
maxChars: flags.max ? Number(flags.max) : undefined,
|
|
145
|
+
});
|
|
146
|
+
out(result);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case 'recall': {
|
|
151
|
+
const query = positional.join(' ').trim();
|
|
152
|
+
if (!query) throw new Error('usage: soulbridge recall "查询" [--limit N]');
|
|
153
|
+
const { soul } = open();
|
|
154
|
+
const hits = soul.recall(query, flags.limit ? Number(flags.limit) : 5);
|
|
155
|
+
out(hits.map((h) => ({ id: h.memory.id, type: h.memory.type, content: h.memory.content, score: Number(h.score.toFixed(3)) })));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
case 'observe': {
|
|
160
|
+
const content = positional.join(' ').trim();
|
|
161
|
+
if (!content) throw new Error('usage: soulbridge observe "一句话"');
|
|
162
|
+
const { soul } = open();
|
|
163
|
+
out(soul.observe({ role: 'user', content }));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
case 'reflect': {
|
|
168
|
+
const text = flags.file ? readFileSync(flags.file, 'utf8') : (flags.text ?? '');
|
|
169
|
+
if (!text.trim()) throw new Error('usage: soulbridge reflect --text "..." | --file transcript.txt');
|
|
170
|
+
const turns: Turn[] = text
|
|
171
|
+
.split(/\r?\n/)
|
|
172
|
+
.map((line) => line.trim())
|
|
173
|
+
.filter(Boolean)
|
|
174
|
+
.map((line) => {
|
|
175
|
+
const match = line.match(/^(user|assistant|助手|用户)\s*[::]\s*(.*)$/i);
|
|
176
|
+
if (!match) return { role: 'user', content: line } as Turn;
|
|
177
|
+
const role = /^(assistant|助手)$/i.test(match[1]) ? 'assistant' : 'user';
|
|
178
|
+
return { role, content: match[2] } as Turn;
|
|
179
|
+
});
|
|
180
|
+
const { soul } = open();
|
|
181
|
+
out(await soul.reflect(turns));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
case 'stats': {
|
|
186
|
+
const { soul, file } = open();
|
|
187
|
+
out({ db: file, ...soul.stats() });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
case 'demo':
|
|
192
|
+
await demo();
|
|
193
|
+
return;
|
|
194
|
+
|
|
195
|
+
default:
|
|
196
|
+
process.stdout.write(
|
|
197
|
+
[
|
|
198
|
+
'soulbridge — 给任何 agent 装上一个人格层',
|
|
199
|
+
'',
|
|
200
|
+
'commands:',
|
|
201
|
+
' init 初始化数据库',
|
|
202
|
+
' remember <text> [--type T] 显式记住一条',
|
|
203
|
+
' context [--query Q] [--max N] 生成注入文本',
|
|
204
|
+
' recall <q> [--limit N] 召回',
|
|
205
|
+
' observe <text> 观察一轮',
|
|
206
|
+
' reflect --text|--file 会话反思',
|
|
207
|
+
' stats 看状态',
|
|
208
|
+
' demo 端到端演示(无需模型)',
|
|
209
|
+
'',
|
|
210
|
+
'env: SOULBRIDGE_DB, SOULBRIDGE_SOUL, SOULBRIDGE_USER, SOULBRIDGE_NAME',
|
|
211
|
+
'',
|
|
212
|
+
].join('\n'),
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
main().catch((error: unknown) => {
|
|
218
|
+
process.stderr.write(`soulbridge: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
219
|
+
process.exitCode = 1;
|
|
220
|
+
});
|