Skip to content

Commit 182bb37

Browse files
authored
Merge pull request #15 from SemanticVoxelProtocol/dev
feat: SVP philosophy section + signature extraction removal cleanup
2 parents 03d6587 + c8f9616 commit 182bb37

3 files changed

Lines changed: 197 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
!.github/
3030
!.github/**
3131

32-
# Within allowed dirs, re-ignore all hidden directories then whitelist .svp/ and .github/
32+
# Within allowed dirs, re-ignore all hidden directories then whitelist specific ones
3333
**/.*/
3434
!**/.svp/
3535
!**/.svp/**

packages/skills/adapters/shared.ts

Lines changed: 195 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,199 @@ export function getSkillIntro(language: string): string {
5454
- **Only recommend applicable options.** If Scan doesn't apply (no code), don't mention it. If the project is empty, don't list View. Internally exclude inapplicable paths and only present meaningful choices to the user`;
5555
}
5656

57+
// ── Skill file: Philosophy section ──
58+
59+
export function getPhilosophySection(language: string): string {
60+
if (language === "zh") {
61+
return `## SVP 哲学
62+
63+
### 为什么需要 SVP
64+
65+
软件系统的崩坏从来不是从代码开始的——是从设计与实现的脱节开始的。
66+
67+
一个函数写错了,修一行就好。但如果十个模块各自对"订单"的定义不一致,你改哪行?当模块之间的隐式假设开始矛盾,系统就进入了熵增螺旋:每次修复引入新的不一致,每次新功能让旧功能以意想不到的方式崩溃。
68+
69+
传统软件工程用架构评审、接口文档、设计规范来对抗这种熵增。但这些都依赖人的纪律——而 AI 时代的编码速度让人的纪律跟不上了。AI 可以一小时写完一个模块,但没有任何机制保证这个模块跟其他九个模块在架构上是自洽的。
70+
71+
SVP 把"先设计,再实现"这个常识形式化为一个可执行的协议。
72+
73+
### 编译模型
74+
75+
SVP 的核心抽象是一条编译链:
76+
77+
\`\`\`
78+
L5 意图 → L4 架构 → L3 逻辑契约 → L2 代码骨架 → L1 源代码
79+
\`\`\`
80+
81+
每一层只从上一层派生,不反向依赖下层。这保证了一个关键性质:**任何时候你都可以从任意层开始向下重新编译,而不破坏上层的设计完整性。**
82+
83+
这跟传统编译链的性质一样:改了 .cpp 重新编译就能得到正确的 .o,不需要去想 .o 的内部结构。SVP 让你改了 L3 契约重新编译就能得到正确的 L1 代码,不需要去想 L1 的实现细节。
84+
85+
反过来不成立。直接改 L1 不会让 L3 自动更新——就像直接 patch .o 文件不会让 .cpp 自动更新。这不是技术限制,是数学事实:信息从高层流向低层时会展开和增殖,这个过程不可逆。
86+
87+
### L3:枢纽层
88+
89+
L3 是整个体系的重心。
90+
91+
L5(意图)和 L4(架构)相对稳定——系统的目标和大模块划分不会频繁变化。L2(骨架)和 L1(代码)是自动派生的。真正需要精心设计、频繁演进的是 L3——每个功能模块的精确契约。
92+
93+
L3 定义了模块的边界:它接受什么、产出什么、遵守什么规则。对于 REST API 项目:
94+
95+
- 一个 L3 block ≈ 一个功能端点
96+
- input pins ≈ 请求参数
97+
- output pins ≈ 响应数据
98+
- constraints ≈ 路由路径、HTTP 方法、状态码、校验规则、业务逻辑
99+
100+
**L3 的精确度直接决定编译质量。** 写 \`input: body\` 等于什么都没说——编译器只能猜。写 \`constraint: "POST /api/v1/auth/register, 租户 ID 从 X-Tenant-ID header 读取, 密码最少 8 位, 首个注册用户自动成为 admin"\` 就几乎不给编译器猜的空间。
101+
102+
### 参考文档 = 头文件
103+
104+
C/C++ 的编译依赖头文件来了解其他模块的接口。SVP 的编译依赖 \`nodes/<block-id>/refs/\` 来了解外部约束。
105+
106+
API 规范、设计稿、第三方 SDK 文档、算法论文——任何影响代码实现方式的信息都应该放进 refs/。forge 在生成编译 prompt 时会自动注入 refs/ 的内容。
107+
108+
没有 refs/ 的编译像没有 #include 的编译:编译器看不到接口定义,只能靠自己推断。推断可能碰巧正确,但你不该依赖这种运气。
109+
110+
### 出错时的正确反应
111+
112+
编译结果不对时,自然反应是"去修代码"。在 SVP 里,正确反应是"去看哪层契约不够精确"。
113+
114+
\`\`\`
115+
编译出的路由是 /users/register 但应该是 /auth/register
116+
→ L3 的 constraints 里没有指定路由路径
117+
→ 补充 constraint → recompile → 自动正确
118+
\`\`\`
119+
120+
这不是教条。这是效率最优解:
121+
122+
- 改 L3 一行 → recompile 修复所有相关文件
123+
- 改 L1 一处 → 只修一个文件,下次 recompile 覆盖
124+
- L3 的改动有持久性和传播性,L1 的改动是临时的和局部的
125+
126+
### 上下文隔离
127+
128+
主 Agent 不读 L1 代码。这个约束的意义不是"分工",而是**认知保护**。
129+
130+
读了 L1 的 Agent 会不自觉地被实现细节锚定。它开始关心"这个 if 语句的分支覆盖"而不是"这个模块的接口定义是否完备"。它从架构师变成了调试工程师。
131+
132+
SVP 的 subagent 模型强制主 Agent 停留在契约层:
133+
134+
- 主 Agent 看 L3 契约 → 发现问题 → 修改契约 → 派发 subagent recompile
135+
- Subagent 在独立上下文中执行编译 → 只看到当前模块的契约和参考文档
136+
137+
这种隔离让主 Agent 始终保持全局视野,不被局部实现干扰。
138+
139+
### 验证:Translation Validation
140+
141+
SVP 不证明编译器(AI)永远正确——这不现实。
142+
143+
SVP 采用 Translation Validation 范式:**验证每次编译的产物,而不是编译器本身。**
144+
145+
- \`forge check\` 验证跨层一致性(hash 比对)
146+
- L3 的 constraints 提供可检验的断言
147+
- 未来可以基于 L3 自动生成合约测试
148+
149+
这是唯一对非确定性编译器(如 LLM)有效的验证策略。
150+
151+
### 一句话
152+
153+
**架构是因,代码是果。SVP 确保你永远在改因,而不是在补果。**`;
154+
}
155+
return `## SVP Philosophy
156+
157+
### Why SVP Exists
158+
159+
Software systems never break starting from code — they break when design and implementation drift apart.
160+
161+
A wrong function? Fix one line. But when ten modules each define "order" differently, which line do you fix? When implicit assumptions between modules start contradicting each other, the system enters an entropy spiral: every fix introduces new inconsistencies, every new feature breaks old features in unexpected ways.
162+
163+
Traditional software engineering uses architecture reviews, interface documents, and design specs to fight this entropy. But these all depend on human discipline — and AI-era coding speed has outpaced human discipline. AI can write a complete module in an hour, but nothing guarantees that module is architecturally consistent with the other nine.
164+
165+
SVP formalizes the common sense of "design first, implement second" into an executable protocol.
166+
167+
### The Compilation Model
168+
169+
SVP's core abstraction is a one-way compilation chain:
170+
171+
\`\`\`
172+
L5 Intent → L4 Architecture → L3 Logic Contracts → L2 Code Skeleton → L1 Source Code
173+
\`\`\`
174+
175+
Each layer derives only from the layer above, never depending on layers below. This guarantees a key property: **you can always recompile downward from any layer without breaking the design integrity of upper layers.**
176+
177+
This is the same property as traditional compilation: edit the .cpp, recompile, and you get a correct .o without thinking about .o internals. SVP lets you edit an L3 contract, recompile, and get correct L1 code without thinking about L1 implementation details.
178+
179+
The reverse doesn't hold. Editing L1 directly won't update L3 — just like patching a .o file won't update the .cpp. This isn't a technical limitation; it's mathematical fact: information expands and multiplies as it flows from high to low levels, and this process is irreversible.
180+
181+
### L3: The Pivot Layer
182+
183+
L3 is the center of gravity of the entire system.
184+
185+
L5 (intent) and L4 (architecture) are relatively stable — system goals and major module divisions don't change frequently. L2 (skeleton) and L1 (code) are auto-derived. What truly needs careful design and frequent evolution is L3 — the precise contract of each functional module.
186+
187+
L3 defines a module's boundaries: what it accepts, what it produces, what rules it follows. For REST API projects:
188+
189+
- One L3 block ≈ one functional endpoint
190+
- Input pins ≈ request parameters
191+
- Output pins ≈ response data
192+
- Constraints ≈ route paths, HTTP methods, status codes, validation rules, business logic
193+
194+
**L3 precision directly determines compilation quality.** Writing \`input: body\` says nothing — the compiler can only guess. Writing \`constraint: "POST /api/v1/auth/register, tenant ID from X-Tenant-ID header, password min 8 chars, first registered user auto-becomes admin"\` leaves the compiler almost no room to guess.
195+
196+
### Reference Documents = Header Files
197+
198+
C/C++ compilation depends on header files to understand other modules' interfaces. SVP compilation depends on \`nodes/<block-id>/refs/\` to understand external constraints.
199+
200+
API specs, design mockups, third-party SDK docs, algorithm papers — any information that affects how code should be written belongs in refs/. Forge automatically injects refs/ contents when generating compilation prompts.
201+
202+
Compiling without refs/ is like compiling without #include: the compiler can't see interface definitions and can only infer. The inference might happen to be correct, but you shouldn't rely on that luck.
203+
204+
### The Correct Response to Errors
205+
206+
When compilation output is wrong, the natural reaction is "go fix the code." In SVP, the correct reaction is "find which layer's contract is imprecise."
207+
208+
\`\`\`
209+
Compiled route is /users/register but should be /auth/register
210+
→ L3 constraints didn't specify the route path
211+
→ Add constraint → recompile → automatically correct
212+
\`\`\`
213+
214+
This isn't dogma. It's the most efficient approach:
215+
216+
- Change one L3 line → recompile fixes all related files
217+
- Change one L1 spot → fixes only one file, next recompile overwrites it
218+
- L3 changes are persistent and propagating; L1 changes are temporary and local
219+
220+
### Context Isolation
221+
222+
The main Agent doesn't read L1 code. This constraint isn't about "division of labor" — it's **cognitive protection**.
223+
224+
An Agent that reads L1 unconsciously anchors on implementation details. It starts caring about "this if-statement's branch coverage" instead of "is this module's interface definition complete?" It transforms from architect to debug engineer.
225+
226+
SVP's subagent model forces the main Agent to stay at the contract layer:
227+
228+
- Main Agent reads L3 contracts → finds issues → modifies contracts → dispatches subagent to recompile
229+
- Subagent compiles in an isolated context → only sees the current module's contract and reference docs
230+
231+
This isolation keeps the main Agent's global vision intact, undistracted by local implementation.
232+
233+
### Verification: Translation Validation
234+
235+
SVP doesn't prove the compiler (AI) is always correct — that's unrealistic.
236+
237+
SVP adopts the Translation Validation paradigm: **verify the product of each compilation, not the compiler itself.**
238+
239+
- \`forge check\` verifies cross-layer consistency (hash comparison)
240+
- L3 constraints provide verifiable assertions
241+
- Future: auto-generate contract tests from L3
242+
243+
This is the only verification strategy that works for non-deterministic compilers (like LLMs).
244+
245+
### In One Sentence
246+
247+
**Architecture is the cause; code is the effect. SVP ensures you're always fixing causes, never patching effects.**`;
248+
}
249+
57250
// ── Skill file: Protocol section ──
58251

59252
export function getProtocolSection(language: string, modelTierLine: string): string {
@@ -155,6 +348,8 @@ export function buildSkillFileContent(
155348
const body = [
156349
getSkillIntro(language),
157350
"",
351+
getPhilosophySection(language),
352+
"",
158353
getProtocolSection(language, modelTierLine),
159354
"",
160355
"---",
@@ -429,11 +624,6 @@ const workflowZh = `## Step 0: 诊断路由
429624
**SOURCE_DRIFT**
430625
- [AI] 运行 \`forge prompt recompile <l3-id>\` → subagent 更新代码
431626

432-
**CONTENT_DRIFT**
433-
- [AI] 运行 \`forge prompt review <l3-id>\` → subagent 判断:
434-
- L3 需要更新?还是 L1 需要修复?
435-
- 向用户展示分析结果
436-
437627
**MISSING_BLOCK_REF**
438628
- [AI] 运行 \`forge prompt update-ref <l4-id>\` → subagent 判断:
439629
- 创建缺失的 L3 contract?还是修复 L4 step 引用?
@@ -676,11 +866,6 @@ For each recompile task:
676866
**SOURCE_DRIFT**
677867
- [AI] Run \`forge prompt recompile <l3-id>\` → subagent updates code
678868

679-
**CONTENT_DRIFT**
680-
- [AI] Run \`forge prompt review <l3-id>\` → subagent determines:
681-
- Does L3 need updating? Or does L1 need fixing?
682-
- Show the analysis results to the user
683-
684869
**MISSING_BLOCK_REF**
685870
- [AI] Run \`forge prompt update-ref <l4-id>\` → subagent determines:
686871
- Create the missing L3 contract? Or fix the L4 step reference?

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"declaration": true,
1111
"skipLibCheck": true
1212
},
13-
"include": ["packages/**/*.ts"],
13+
"include": ["packages/**/*.ts", "benchmark/**/*.ts"],
1414
"exclude": ["dist"]
1515
}

0 commit comments

Comments
 (0)