intentdna 1.4.2 → 1.4.4
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/.claude-plugin/hooks/hooks.json +8 -8
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/cli/commands/generate.d.ts +16 -0
- package/dist/cli/commands/generate.js +151 -0
- package/dist/cli/commands/verify.js +51 -5
- package/dist/cli/index.js +22 -0
- package/dist/compiler/workflow.d.ts +9 -1
- package/dist/compiler/workflow.js +107 -5
- package/dist/hooks/cli.js +40 -1
- package/dist/hooks/enforce.d.ts +3 -0
- package/dist/hooks/enforce.js +7 -2
- package/dist/hooks/state.d.ts +2 -0
- package/dist/schema/types.d.ts +6 -0
- package/package.json +2 -1
- package/spec/parallel-isolation.md +205 -0
- package/spec/schema-spec.md +676 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intentdna",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Intent DNA — Declarative policy layer for AI agent behavior",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"files": [
|
|
35
35
|
"dist",
|
|
36
|
+
"spec",
|
|
36
37
|
".claude-plugin",
|
|
37
38
|
"README.md",
|
|
38
39
|
"LICENSE"
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Spec: DNA 并行执行 + Worktree 隔离
|
|
2
|
+
|
|
3
|
+
## Metadata
|
|
4
|
+
- Interview: 8 rounds, final ambiguity 20%
|
|
5
|
+
- Type: brownfield
|
|
6
|
+
- Date: 2026-04-14
|
|
7
|
+
- Phase: 6 (基础体验)
|
|
8
|
+
|
|
9
|
+
## Goal
|
|
10
|
+
|
|
11
|
+
DNA 模板可声明并行执行策略和文件隔离策略,编译到 workflow-runner 生成的 bash 脚本中实际执行。支持强制 worktree、编译时自动判断(scope overlap)、和无隔离三种模式。
|
|
12
|
+
|
|
13
|
+
## 核心设计决策
|
|
14
|
+
|
|
15
|
+
| 决策 | 结论 | 理由 |
|
|
16
|
+
|------|------|------|
|
|
17
|
+
| 执行方式 | 自管 worktree (bash) | 不依赖 CC 平台特性,完全自控 |
|
|
18
|
+
| isolation 语义 | 纯文件隔离 | context 隔离已由独立进程解决,context 保护已由 Handoff 解决 |
|
|
19
|
+
| Schema 声明 | step 属性 + parallel block 双支持 | 灵活性 + 简洁性兼顾 |
|
|
20
|
+
| auto 模式 | 编译时 scope overlap 检测 | DNA 独有能力——Role scope 编译时已知 |
|
|
21
|
+
| merge 策略 | escalate only (MVP) | 冲突报告给用户,不自动解决 |
|
|
22
|
+
| 模型差异 | 暂不考虑 | 后续扩展 |
|
|
23
|
+
|
|
24
|
+
## Schema 设计
|
|
25
|
+
|
|
26
|
+
### isolation 取值
|
|
27
|
+
|
|
28
|
+
| 值 | 含义 |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `none` | 共享目录(默认,当前行为) |
|
|
31
|
+
| `worktree` | 强制每个并行 step 开 worktree |
|
|
32
|
+
| `auto` | 编译时分析 scope overlap,自动决定 none 或 worktree |
|
|
33
|
+
|
|
34
|
+
### 两种声明方式
|
|
35
|
+
|
|
36
|
+
**方式 A: step 属性 + workflow 默认值(隐式并行)**
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
workflows:
|
|
40
|
+
rescue:
|
|
41
|
+
default_isolation: auto # workflow 级默认
|
|
42
|
+
merge_strategy: escalate
|
|
43
|
+
steps:
|
|
44
|
+
- id: investigate
|
|
45
|
+
role: investigator
|
|
46
|
+
- id: fix-auth
|
|
47
|
+
role: surgeon
|
|
48
|
+
isolation: worktree # step 级覆盖
|
|
49
|
+
depends_on: [investigate]
|
|
50
|
+
- id: fix-api
|
|
51
|
+
role: surgeon
|
|
52
|
+
# 继承 workflow 默认 auto
|
|
53
|
+
depends_on: [investigate]
|
|
54
|
+
- id: report
|
|
55
|
+
depends_on: [fix-auth, fix-api]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
编译器通过 `depends_on` + Kahn 拓扑排序自动检测并行组(已实现)。
|
|
59
|
+
|
|
60
|
+
**方式 B: 显式 parallel block(语法糖)**
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
workflows:
|
|
64
|
+
rescue:
|
|
65
|
+
steps:
|
|
66
|
+
- id: investigate
|
|
67
|
+
role: investigator
|
|
68
|
+
|
|
69
|
+
- parallel:
|
|
70
|
+
isolation: worktree
|
|
71
|
+
merge_strategy: escalate
|
|
72
|
+
steps:
|
|
73
|
+
- id: fix-auth
|
|
74
|
+
role: surgeon
|
|
75
|
+
- id: fix-api
|
|
76
|
+
role: surgeon
|
|
77
|
+
|
|
78
|
+
- id: report
|
|
79
|
+
depends_on: [fix-auth, fix-api]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
parallel block 编译时展开为带 `depends_on` 的独立 step + 统一 isolation 设置。
|
|
83
|
+
|
|
84
|
+
### isolation 粒度
|
|
85
|
+
|
|
86
|
+
| 粒度 | 声明位置 | 含义 |
|
|
87
|
+
|------|----------|------|
|
|
88
|
+
| step 级 | step.isolation | 该 step 的并行执行隔离 |
|
|
89
|
+
| workflow 级 | workflow.default_isolation | 所有并行组的默认隔离策略 |
|
|
90
|
+
|
|
91
|
+
step 级 > workflow 级(覆盖优先级)。
|
|
92
|
+
|
|
93
|
+
## auto 模式编译逻辑
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
对每个 ParallelGroup:
|
|
97
|
+
1. 收集组内所有 step 对应 role 的 write scope
|
|
98
|
+
2. 做 glob 交叉检测(minimatch 或等价)
|
|
99
|
+
3. 无重叠 → 编译为 none
|
|
100
|
+
4. 有重叠 → 编译为 worktree
|
|
101
|
+
5. 无法判断("**/*")→ 保守编译为 worktree
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## workflow-runner 生成
|
|
105
|
+
|
|
106
|
+
### isolation: none(当前行为不变)
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Group 1: fix-auth, fix-api (parallel, no isolation)
|
|
110
|
+
run_agent "dna-surgeon" 'prompt' "fix-auth" &
|
|
111
|
+
PID_fix_auth=$!
|
|
112
|
+
run_agent "dna-surgeon" 'prompt' "fix-api" &
|
|
113
|
+
PID_fix_api=$!
|
|
114
|
+
wait $PID_fix_auth || STEP_fix_auth_STATUS=1
|
|
115
|
+
wait $PID_fix_api || STEP_fix_api_STATUS=1
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### isolation: worktree
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Group 1: fix-auth, fix-api (parallel, worktree isolation)
|
|
122
|
+
MAIN_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
123
|
+
|
|
124
|
+
git worktree add .dna/worktrees/fix-auth -b dna-wt-fix-auth HEAD 2>/dev/null
|
|
125
|
+
git worktree add .dna/worktrees/fix-api -b dna-wt-fix-api HEAD 2>/dev/null
|
|
126
|
+
|
|
127
|
+
(cd .dna/worktrees/fix-auth && run_agent "dna-surgeon" 'prompt' "fix-auth") &
|
|
128
|
+
PID_fix_auth=$!
|
|
129
|
+
(cd .dna/worktrees/fix-api && run_agent "dna-surgeon" 'prompt' "fix-api") &
|
|
130
|
+
PID_fix_api=$!
|
|
131
|
+
|
|
132
|
+
wait $PID_fix_auth || STEP_fix_auth_STATUS=1
|
|
133
|
+
wait $PID_fix_api || STEP_fix_api_STATUS=1
|
|
134
|
+
|
|
135
|
+
# Merge (escalate on conflict)
|
|
136
|
+
merge_worktree() {
|
|
137
|
+
local branch=$1 name=$2
|
|
138
|
+
if ! git merge --no-commit --no-ff "$branch" 2>/dev/null; then
|
|
139
|
+
git merge --abort
|
|
140
|
+
echo "[Intent DNA] CONFLICT: $name conflicts with $MAIN_BRANCH. Manual resolution required."
|
|
141
|
+
echo "[Intent DNA] Branch preserved: $branch"
|
|
142
|
+
return 1
|
|
143
|
+
fi
|
|
144
|
+
git commit -m "merge: $name" --no-edit
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
merge_worktree "dna-wt-fix-auth" "fix-auth"
|
|
148
|
+
merge_worktree "dna-wt-fix-api" "fix-api"
|
|
149
|
+
|
|
150
|
+
# Cleanup (only if merge succeeded)
|
|
151
|
+
git worktree remove .dna/worktrees/fix-auth 2>/dev/null
|
|
152
|
+
git worktree remove .dna/worktrees/fix-api 2>/dev/null
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Constraint IR 扩展
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// ParallelGroup 扩展
|
|
159
|
+
interface ParallelGroup {
|
|
160
|
+
group_index: number;
|
|
161
|
+
step_ids: string[];
|
|
162
|
+
isolation: 'none' | 'worktree'; // auto 已被编译期解析
|
|
163
|
+
merge_strategy: 'escalate'; // MVP: escalate only
|
|
164
|
+
scope_overlap: boolean; // 编译期分析结果
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// WorkflowIR 扩展
|
|
168
|
+
interface WorkflowIR {
|
|
169
|
+
// ... 现有字段
|
|
170
|
+
parallel_groups?: ParallelGroupIR[]; // 新增
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 与 DNA 现有概念的关系
|
|
175
|
+
|
|
176
|
+
| DNA 概念 | 在并行隔离中的角色 |
|
|
177
|
+
|---|---|
|
|
178
|
+
| **Role scope** | auto 模式的编译时 overlap 分析输入 |
|
|
179
|
+
| **Handoff** | 并行 step 的 artifact 传递(已实现) |
|
|
180
|
+
| **Threshold codon** | 可声明 `parallel_without_isolation == false` 硬约束 |
|
|
181
|
+
| **Attract codon** | `attract: worktree_per_task` 软提示(保留兼容) |
|
|
182
|
+
| **Hooks enforce** | worktree 内 scope enforce 仍生效 |
|
|
183
|
+
|
|
184
|
+
## 不做
|
|
185
|
+
|
|
186
|
+
- 自动冲突解决(MVP 只 escalate)
|
|
187
|
+
- LLM 模型差异适配(暂不考虑)
|
|
188
|
+
- context budget 管理(已由独立进程 + Handoff 解决)
|
|
189
|
+
- container 级隔离(过度设计)
|
|
190
|
+
|
|
191
|
+
## Acceptance Criteria
|
|
192
|
+
|
|
193
|
+
- [ ] Schema: WorkflowStepDef 支持 `isolation` 字段
|
|
194
|
+
- [ ] Schema: WorkflowDef 支持 `default_isolation` + `merge_strategy`
|
|
195
|
+
- [ ] Schema: `parallel:` block 语法糖可解析
|
|
196
|
+
- [ ] Compiler: auto 模式 scope overlap 检测正确
|
|
197
|
+
- [ ] Compiler: parallel block 展开为 step + depends_on
|
|
198
|
+
- [ ] workflow-runner: isolation=none 行为不变(向后兼容)
|
|
199
|
+
- [ ] workflow-runner: isolation=worktree 生成 git worktree 生命周期脚本
|
|
200
|
+
- [ ] workflow-runner: merge 冲突时 escalate(报告 + 保留分支)
|
|
201
|
+
- [ ] E2E: 两个并行 step 写不同目录,auto → none,正确执行
|
|
202
|
+
- [ ] E2E: 两个并行 step 写相同目录,auto → worktree,隔离执行 + merge
|
|
203
|
+
- [ ] Dogfood: flutter-rewrite rescue workflow 可配置 isolation
|
|
204
|
+
- [ ] IR: ParallelGroup 包含 isolation + scope_overlap 信息
|
|
205
|
+
- [ ] 测试覆盖所有新增代码
|