@yeaft/webchat-agent 1.0.496 → 1.0.497
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/bin/yeaft-repo.js +4 -0
- package/local-runtime/version.json +1 -1
- package/package.json +3 -1
- package/repo-workflow-cli.js +101 -0
- package/repo-workflow.js +1437 -0
- package/skills/review-merge-tag/SKILL.md +78 -0
- package/yeaft/cli-session-runner.js +4 -1
- package/yeaft/engine.js +2 -0
- package/yeaft/init.js +5 -2
- package/yeaft/routing/router.js +140 -2
- package/yeaft/skills.js +58 -37
- package/yeaft/tools/activation.js +3 -0
- package/yeaft/tools/index.js +2 -0
- package/yeaft/tools/repo-workflow.js +80 -0
- package/yeaft/tools/route-forward.js +19 -1
- package/yeaft/web-bridge.js +65 -7
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: review-merge-tag
|
|
3
|
+
description: 用 RepoWorkflow 在任意 GitHub 仓库执行开发 worktree、精确 PR review snapshot、base-ref CAS landing、数字 tag 与 workflow 验证;避免重复手工 git/gh 检查。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Repository Workflow
|
|
7
|
+
|
|
8
|
+
不要逐条调用 `git fetch`、`git worktree list`、`gh pr view`、`git ls-remote` 和 `gh run watch` 来发现同一批事实。Session 内使用 `RepoWorkflow` 工具。非 Yeaft 环境可用 `yeaft-repo` CLI 执行 `prepare` 和 `review-prep`,这两个阶段返回与工具相同的紧凑 JSON;CLI 不能执行 `land`。
|
|
9
|
+
|
|
10
|
+
## 三个边界
|
|
11
|
+
|
|
12
|
+
### 1. 开发准备
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"phase": "prepare",
|
|
17
|
+
"name": "fix-short-description"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
它会在当前仓库中确定远端默认分支、拉取最新精确基线、检查 worktree/branch/path 冲突,并创建或安全复用 `yeaft-wt/<name>`。后续开发只使用返回的 `worktree.path`。
|
|
22
|
+
|
|
23
|
+
### 2. 独立 review 准备
|
|
24
|
+
|
|
25
|
+
Reviewer 调用:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"phase": "review-prep",
|
|
30
|
+
"pr": 123
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
它会一次冻结 GitHub PR 的 base branch/base SHA/head/merge snapshot、检查 draft/conflict/checks,并创建 detached exact-snapshot review worktree。Reviewer 必须审查返回的 `reviewWorktree.path`,并把明确结论、`pullRequest.baseBranch`、`pullRequest.baseSha`、`pullRequest.headSha` 和 `pullRequest.snapshotSha` 交回开发者。
|
|
35
|
+
|
|
36
|
+
工具只冻结事实,不替代代码审查。
|
|
37
|
+
|
|
38
|
+
### 3. Review 通过后的落地
|
|
39
|
+
|
|
40
|
+
只有收到独立 reviewer 的明确批准后才能调用。Reviewer 必须用 `RouteForward` 把绑定仓库、PR、exact base branch/base SHA/head/merge snapshot 的结构化批准交回 landing VP;宿主会随该 handoff 铸造不可序列化、一次性的 approval capability。随后 landing VP 才能在处理该 handoff 的同一 turn 调用:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"phase": "land",
|
|
45
|
+
"pr": 123,
|
|
46
|
+
"baseBranch": "main",
|
|
47
|
+
"baseSha": "<exact 40-char base SHA>",
|
|
48
|
+
"reviewedHead": "<exact 40-char head SHA>",
|
|
49
|
+
"reviewedSnapshot": "<exact 40-char merge snapshot SHA>",
|
|
50
|
+
"tagPrefix": "v1.0.",
|
|
51
|
+
"workflow": "Dev Release"
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`approvedBy` 等普通字符串没有授权语义。`land` 只接受宿主 capability,并重新冻结 PR;任何 repo、PR、recipient、base branch、base SHA、head 或 snapshot 不匹配都会停止。Reviewed snapshot 必须以批准的 base SHA/head 为两个父提交;landing 的目标 ref 只从批准的 base branch 推导,并在任何写入前拒绝 PR retarget。之后它通过单次 receive-pack 更新,用 `--force-with-lease=<base-ref>:<approved-base>` 将该 exact snapshot 安装到批准的远端 base。若 base 在最后冻结与 receive 之间前进,lease 会拒绝更新,并且不会创建 tag。若要求 tag,它只在 base CAS 成功后从远端 tags 数值计算下一版,用 create-only lease 推送并复核 base 与 tag。若要求 workflow,它等待匹配 tag 与 reviewed snapshot SHA 的 run 完成。
|
|
56
|
+
|
|
57
|
+
Worktree cleanup 不属于 landing。`land` 会在任何仓库或远端副作用前拒绝 cleanup 请求,包括 active `repoRoot`;需要 cleanup 时必须在 landing 完成后走独立操作,cleanup 失败不能改变 landing 结果。
|
|
58
|
+
|
|
59
|
+
## 通用性与边界
|
|
60
|
+
|
|
61
|
+
- 适用于 Agent 可访问的任意本地 GitHub 仓库,不包含项目路径或固定 `main` 假设。
|
|
62
|
+
- 需要 `git` 和已认证的 `gh` CLI;不依赖 Python,也不通过 shell 拼接命令。
|
|
63
|
+
- 当前不支持 GitLab/Bitbucket;不要把 GitHub 成功误报为 forge-agnostic。
|
|
64
|
+
- 自动化只消除重复事实核对,不消除独立 review、测试选择、代码判断或用户授权。
|
|
65
|
+
- `land` 后若 workflow 失败,merge/tag 可能已经完成;读取错误 JSON 的 `details.remoteEffects`,不要盲目重试或重打 tag。
|
|
66
|
+
|
|
67
|
+
## CLI
|
|
68
|
+
|
|
69
|
+
Yeaft 外部或人工终端只可运行准备阶段:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
yeaft-repo prepare --name fix-short-description
|
|
73
|
+
yeaft-repo review-prep --pr 123
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
独立 CLI 不能执行 `land`。Landing 必须在 Session 中通过 `RepoWorkflow` 工具执行,并携带当前 handoff 由宿主签发、绑定 exact review 的 approval capability;普通参数或 `approvedBy` 字符串不能替代该 capability。
|
|
77
|
+
|
|
78
|
+
每条可用命令 stdout 只输出一个成功 JSON;失败时 stderr 输出一个带稳定 `code` 和副作用状态的 JSON。
|
|
@@ -250,7 +250,10 @@ export function createCliSessionRunner({
|
|
|
250
250
|
sessionMembers: meta.roster.slice(),
|
|
251
251
|
sessionAnnouncement: meta.announcement || '',
|
|
252
252
|
vpPersona: personaFactory(vpId, loaded),
|
|
253
|
-
router: createRouter({
|
|
253
|
+
router: createRouter({
|
|
254
|
+
coordinator: scopedCoordinator,
|
|
255
|
+
guard: routeForwardGuard,
|
|
256
|
+
}),
|
|
254
257
|
inboundEnvelope: envelope,
|
|
255
258
|
userAlreadyPersisted: true,
|
|
256
259
|
causalRootId,
|
package/yeaft/engine.js
CHANGED
|
@@ -1416,6 +1416,7 @@ export class Engine {
|
|
|
1416
1416
|
? vpCtx.projectSessionIds.slice()
|
|
1417
1417
|
: [],
|
|
1418
1418
|
threadId: vpCtx?.threadId || this.#currentThreadId || MAIN_THREAD_ID,
|
|
1419
|
+
turnId: vpCtx?.turnId || null,
|
|
1419
1420
|
currentVpId: vpCtx?.senderVpId || this.#vpId || null,
|
|
1420
1421
|
// task-704b: per-tool-result hard cap derives from this. Threaded
|
|
1421
1422
|
// from the live model (resolveModel(currentModel)) every turn so
|
|
@@ -3847,6 +3848,7 @@ export class Engine {
|
|
|
3847
3848
|
projectInstruction,
|
|
3848
3849
|
projectLabel,
|
|
3849
3850
|
threadId: runtimeThreadId,
|
|
3851
|
+
turnId: vpTurnId,
|
|
3850
3852
|
inboundEnvelope,
|
|
3851
3853
|
taskId,
|
|
3852
3854
|
taskMembers,
|
package/yeaft/init.js
CHANGED
|
@@ -15,7 +15,7 @@ import { mutateAgentConfig } from './config-store.js';
|
|
|
15
15
|
// layout AND rewrites pre-rename per-message frontmatter (groupId → sessionId).
|
|
16
16
|
// Idempotent via the `.yeaft-migration.done` sentinel file.
|
|
17
17
|
import { migrateSessions } from './migrate/sessions.js';
|
|
18
|
-
import {
|
|
18
|
+
import { bundledYeaftSkillsDirs } from './skills.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Check if an error is a permission error (EACCES or EPERM).
|
|
@@ -353,7 +353,10 @@ function readManifest(filePath) {
|
|
|
353
353
|
* @returns {{ copied: number, updated: number, preserved: number, skipped: number }}
|
|
354
354
|
*/
|
|
355
355
|
export function seedBundledSkills(userSkillsDir, warnings = []) {
|
|
356
|
-
|
|
356
|
+
// Seed only the highest-priority root. Runtime loading still scans every
|
|
357
|
+
// bundled root; flattening lower-priority roots into the user tier here
|
|
358
|
+
// would erase bundled provenance and conflict ordering.
|
|
359
|
+
const bundled = bundledYeaftSkillsDirs().at(-1);
|
|
357
360
|
if (!bundled) {
|
|
358
361
|
return { copied: 0, updated: 0, preserved: 0, skipped: 0 };
|
|
359
362
|
}
|
package/yeaft/routing/router.js
CHANGED
|
@@ -28,6 +28,122 @@
|
|
|
28
28
|
import { resolveMemberId } from '../sessions/roster.js';
|
|
29
29
|
import { createLoopGuard, extendCausedBy } from './loop-guard.js';
|
|
30
30
|
|
|
31
|
+
const repoApprovals = new WeakMap();
|
|
32
|
+
const REPO_APPROVAL_ISSUER_IDS = new Set(['martin']);
|
|
33
|
+
export const REPO_APPROVAL_TTL_MS = 2 * 60 * 1000;
|
|
34
|
+
|
|
35
|
+
function normalizeId(value) {
|
|
36
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizeSha(value) {
|
|
40
|
+
const sha = normalizeId(value).toLowerCase();
|
|
41
|
+
return /^[0-9a-f]{40}$/.test(sha) ? sha : '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function normalizeApprovalRepository(value) {
|
|
45
|
+
const repository = normalizeId(value).replace(/\.git$/i, '');
|
|
46
|
+
const segments = repository.split('/');
|
|
47
|
+
if (segments.length === 2) segments.unshift('github.com');
|
|
48
|
+
if (segments.length !== 3) return '';
|
|
49
|
+
const [host, owner, name] = segments;
|
|
50
|
+
const safePart = part => /^[a-z0-9_.-]+$/i.test(part) && part !== '.' && part !== '..';
|
|
51
|
+
if (!safePart(host) || !safePart(owner) || !safePart(name) || !host.includes('.')) return '';
|
|
52
|
+
return `${host}/${owner}/${name}`.toLowerCase();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isRepoApprovalIssuer(vpId) {
|
|
56
|
+
return REPO_APPROVAL_ISSUER_IDS.has(normalizeId(vpId));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Mint authority only inside the canonical Router path after roster identity
|
|
61
|
+
* resolution. Keeping this function module-private prevents callers from
|
|
62
|
+
* turning a claimed issuer string into landing authority.
|
|
63
|
+
*/
|
|
64
|
+
function issueRepoApprovalCapability(input = {}, { now = Date.now } = {}) {
|
|
65
|
+
const sessionId = normalizeId(input.sessionId);
|
|
66
|
+
const issuerVpId = normalizeId(input.issuerVpId);
|
|
67
|
+
const recipientVpId = normalizeId(input.recipientVpId);
|
|
68
|
+
const repository = normalizeApprovalRepository(input.repository);
|
|
69
|
+
const pr = Number(input.pr);
|
|
70
|
+
const baseBranch = normalizeId(input.baseBranch);
|
|
71
|
+
const baseSha = normalizeSha(input.baseSha);
|
|
72
|
+
const reviewedHead = normalizeSha(input.reviewedHead);
|
|
73
|
+
const reviewedSnapshot = normalizeSha(input.reviewedSnapshot);
|
|
74
|
+
const issuedAt = Number(now());
|
|
75
|
+
if (!sessionId || !isRepoApprovalIssuer(issuerVpId) || !recipientVpId || issuerVpId === recipientVpId
|
|
76
|
+
|| !repository || !Number.isSafeInteger(pr) || pr <= 0 || !baseBranch || !baseSha
|
|
77
|
+
|| !reviewedHead || !reviewedSnapshot || !Number.isFinite(issuedAt)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const capability = Object.freeze(Object.create(null));
|
|
81
|
+
repoApprovals.set(capability, {
|
|
82
|
+
sessionId,
|
|
83
|
+
issuerVpId,
|
|
84
|
+
recipientVpId,
|
|
85
|
+
repository,
|
|
86
|
+
pr,
|
|
87
|
+
baseBranch,
|
|
88
|
+
baseSha,
|
|
89
|
+
reviewedHead,
|
|
90
|
+
reviewedSnapshot,
|
|
91
|
+
issuedAt,
|
|
92
|
+
expiresAt: issuedAt + REPO_APPROVAL_TTL_MS,
|
|
93
|
+
turnId: null,
|
|
94
|
+
});
|
|
95
|
+
return capability;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function isRepoApprovalCapability(capability) {
|
|
99
|
+
return Boolean(capability && typeof capability === 'object' && repoApprovals.has(capability));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Bind a freshly issued capability to the exact Web execution that received it. */
|
|
103
|
+
export function bindRepoApprovalCapability(capability, expected = {}, { now = Date.now } = {}) {
|
|
104
|
+
if (!capability || typeof capability !== 'object') return false;
|
|
105
|
+
const grant = repoApprovals.get(capability);
|
|
106
|
+
const turnId = normalizeId(expected.turnId);
|
|
107
|
+
const currentTime = Number(now());
|
|
108
|
+
if (!grant || !turnId || !Number.isFinite(currentTime)) return false;
|
|
109
|
+
if (currentTime > grant.expiresAt
|
|
110
|
+
|| grant.turnId
|
|
111
|
+
|| grant.sessionId !== normalizeId(expected.sessionId)
|
|
112
|
+
|| grant.recipientVpId !== normalizeId(expected.recipientVpId)) {
|
|
113
|
+
repoApprovals.delete(capability);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
grant.turnId = turnId;
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function revokeRepoApprovalCapability(capability) {
|
|
121
|
+
if (!capability || typeof capability !== 'object') return false;
|
|
122
|
+
return repoApprovals.delete(capability);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Consume a capability exactly once and verify its complete landing tuple. */
|
|
126
|
+
export function consumeRepoApprovalCapability(capability, expected = {}, { now = Date.now } = {}) {
|
|
127
|
+
if (!capability || typeof capability !== 'object') return null;
|
|
128
|
+
const grant = repoApprovals.get(capability);
|
|
129
|
+
repoApprovals.delete(capability);
|
|
130
|
+
if (!grant) return null;
|
|
131
|
+
const currentTime = Number(now());
|
|
132
|
+
const matches = Number.isFinite(currentTime)
|
|
133
|
+
&& currentTime <= grant.expiresAt
|
|
134
|
+
&& grant.turnId
|
|
135
|
+
&& grant.turnId === normalizeId(expected.turnId)
|
|
136
|
+
&& grant.sessionId === normalizeId(expected.sessionId)
|
|
137
|
+
&& grant.recipientVpId === normalizeId(expected.recipientVpId)
|
|
138
|
+
&& grant.repository === normalizeApprovalRepository(expected.repository)
|
|
139
|
+
&& grant.pr === Number(expected.pr)
|
|
140
|
+
&& grant.baseBranch === normalizeId(expected.baseBranch)
|
|
141
|
+
&& grant.baseSha === normalizeSha(expected.baseSha)
|
|
142
|
+
&& grant.reviewedHead === normalizeSha(expected.reviewedHead)
|
|
143
|
+
&& grant.reviewedSnapshot === normalizeSha(expected.reviewedSnapshot);
|
|
144
|
+
return matches ? Object.freeze({ ...grant }) : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
31
147
|
function routeForwardParentFromEnvelope(envelope) {
|
|
32
148
|
const msg = envelope?.msg;
|
|
33
149
|
const meta = msg?.meta;
|
|
@@ -75,7 +191,8 @@ export function createRouter(deps = {}) {
|
|
|
75
191
|
if (!coordinator || typeof coordinator.ingest !== 'function') {
|
|
76
192
|
throw new Error('createRouter: coordinator (with ingest()) is required');
|
|
77
193
|
}
|
|
78
|
-
const
|
|
194
|
+
const now = typeof deps.now === 'function' ? deps.now : Date.now;
|
|
195
|
+
const guard = deps.guard || createLoopGuard({ now });
|
|
79
196
|
|
|
80
197
|
/**
|
|
81
198
|
* Forward a message from a VP to another VP (or @all). Routes through
|
|
@@ -122,6 +239,8 @@ export function createRouter(deps = {}) {
|
|
|
122
239
|
}
|
|
123
240
|
const meta = coordinator.group.getMeta();
|
|
124
241
|
if (!meta) return { ok: false, error: 'group_not_initialised' };
|
|
242
|
+
const senderVpId = resolveMemberId(meta, from);
|
|
243
|
+
if (!senderVpId) return { ok: false, error: 'sender_not_in_roster' };
|
|
125
244
|
const claimedVpIds = args.inboundEnvelope?._cliTurnContext?.claimedVpIds;
|
|
126
245
|
|
|
127
246
|
// Roster membership — `all` is reserved broadcast sentinel handled by
|
|
@@ -132,7 +251,7 @@ export function createRouter(deps = {}) {
|
|
|
132
251
|
if (targetVpId !== 'all' && !targetVpId) {
|
|
133
252
|
return { ok: false, error: 'target_not_in_roster' };
|
|
134
253
|
}
|
|
135
|
-
if (targetVpId ===
|
|
254
|
+
if (targetVpId === senderVpId) {
|
|
136
255
|
return { ok: false, error: 'self_forward_rejected' };
|
|
137
256
|
}
|
|
138
257
|
if (targetVpId !== 'all' && claimedVpIds?.has?.(targetVpId)) {
|
|
@@ -146,6 +265,24 @@ export function createRouter(deps = {}) {
|
|
|
146
265
|
// spec's intent ("depth of forwards already taken").
|
|
147
266
|
const chain = extendCausedBy(args.inboundEnvelope || null, null);
|
|
148
267
|
const routeForwardParent = routeForwardParentFromEnvelope(args.inboundEnvelope);
|
|
268
|
+
let repoApproval = null;
|
|
269
|
+
if (args.repoApproval !== undefined) {
|
|
270
|
+
if (targetVpId === 'all') {
|
|
271
|
+
return { ok: false, error: 'repo_approval_requires_single_target' };
|
|
272
|
+
}
|
|
273
|
+
if (!isRepoApprovalIssuer(senderVpId)) {
|
|
274
|
+
return { ok: false, error: 'repo_approval_issuer_forbidden' };
|
|
275
|
+
}
|
|
276
|
+
repoApproval = issueRepoApprovalCapability({
|
|
277
|
+
...args.repoApproval,
|
|
278
|
+
sessionId: meta.id,
|
|
279
|
+
issuerVpId: senderVpId,
|
|
280
|
+
recipientVpId: targetVpId,
|
|
281
|
+
}, { now });
|
|
282
|
+
if (!repoApproval) {
|
|
283
|
+
return { ok: false, error: 'invalid_repo_approval' };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
149
286
|
|
|
150
287
|
// Loop guard: for broadcast, use 'all' as the target key so one VP
|
|
151
288
|
// spamming @all still gets throttled even if each cycle hits different
|
|
@@ -182,6 +319,7 @@ export function createRouter(deps = {}) {
|
|
|
182
319
|
// of UI replay and future visible history so it doesn't render as a
|
|
183
320
|
// second assistant/user block after the target VP answers.
|
|
184
321
|
internal: true,
|
|
322
|
+
...(repoApproval ? { _repoApproval: repoApproval } : {}),
|
|
185
323
|
meta: {
|
|
186
324
|
synthetic: true,
|
|
187
325
|
injectedBy: 'route_forward',
|
package/yeaft/skills.js
CHANGED
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
*
|
|
29
29
|
* The standard tier order set up by `createSkillManager` is:
|
|
30
30
|
*
|
|
31
|
-
* tier 1 (bundled):
|
|
32
|
-
*
|
|
33
|
-
* `
|
|
31
|
+
* tier 1 (bundled): all available external yeaft-skills roots plus the Agent
|
|
32
|
+
* package's own skills. External roots load first; Agent built-ins
|
|
33
|
+
* win bundled-name conflicts. Read-only — `save()` and `remove()`
|
|
34
|
+
* never target this tier.
|
|
34
35
|
* tier 2 (user): <yeaftDir>/skills (e.g. ~/.yeaft/skills). User edits
|
|
35
36
|
* land here. `save()` writes here. `init.js` seeds it from tier 1
|
|
36
37
|
* on first boot so users start with the bundled Yeaft skills.
|
|
@@ -1197,8 +1198,9 @@ export class SkillManager {
|
|
|
1197
1198
|
* Create a SkillManager wired with the standard layered tier list and load it.
|
|
1198
1199
|
*
|
|
1199
1200
|
* Tier order (lowest → highest priority):
|
|
1200
|
-
* 1. bundled —
|
|
1201
|
-
* `
|
|
1201
|
+
* 1. bundled — every available bundled root returned by
|
|
1202
|
+
* `bundledYeaftSkillsDirs()`. External packages add skills, while the
|
|
1203
|
+
* Agent package loads last so its built-in skills win bundled conflicts.
|
|
1202
1204
|
* 2. user — `<yeaftDir>/skills` (e.g. ~/.yeaft/skills). User edits + saves.
|
|
1203
1205
|
* 3. project-claude — `<workDir>/.claude/skills` when a workDir is provided.
|
|
1204
1206
|
* Claude Code project assets, loaded so a project that integrates Claude
|
|
@@ -1218,7 +1220,7 @@ export class SkillManager {
|
|
|
1218
1220
|
* @returns {SkillManager}
|
|
1219
1221
|
*/
|
|
1220
1222
|
export function createSkillManager(yeaftDir, workDir, options = {}) {
|
|
1221
|
-
const
|
|
1223
|
+
const bundledDirs = bundledYeaftSkillsDirs();
|
|
1222
1224
|
const userDir = join(yeaftDir, 'skills');
|
|
1223
1225
|
const projectRoots = [...new Set(String(workDir || '')
|
|
1224
1226
|
.split(delimiter)
|
|
@@ -1228,9 +1230,9 @@ export function createSkillManager(yeaftDir, workDir, options = {}) {
|
|
|
1228
1230
|
const codexProjectDirs = projectRoots.map(root => join(root, '.agents', 'skills'));
|
|
1229
1231
|
const projectDirs = projectRoots.map(root => join(root, '.yeaft', 'skills'));
|
|
1230
1232
|
|
|
1231
|
-
const dirs = [
|
|
1233
|
+
const dirs = [...bundledDirs, userDir, ...claudeProjectDirs, ...codexProjectDirs, ...projectDirs];
|
|
1232
1234
|
const tierByDir = {};
|
|
1233
|
-
|
|
1235
|
+
for (const dir of bundledDirs) tierByDir[dir] = 'bundled';
|
|
1234
1236
|
tierByDir[userDir] = 'user';
|
|
1235
1237
|
for (const dir of claudeProjectDirs) tierByDir[dir] = 'project-claude';
|
|
1236
1238
|
for (const dir of codexProjectDirs) tierByDir[dir] = 'project-codex';
|
|
@@ -1256,56 +1258,75 @@ export function createSkillManager(yeaftDir, workDir, options = {}) {
|
|
|
1256
1258
|
// ─── Bundled-skills resolver ──────────────────────────────
|
|
1257
1259
|
|
|
1258
1260
|
/**
|
|
1259
|
-
* Locate
|
|
1261
|
+
* Locate every available bundled Skill root on disk.
|
|
1260
1262
|
*
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1266
|
-
*
|
|
1263
|
+
* The returned array is ordered from lowest to highest priority, matching the
|
|
1264
|
+
* `SkillManager` layered-load contract:
|
|
1265
|
+
* 1. ~/.claude/plugins/yeaft-skills/skills/ — alternate plugin layout
|
|
1266
|
+
* 2. ~/.claude/skills/yeaft-skills/skills/ — standard Claude Code layout
|
|
1267
|
+
* 3. $YEAFT_SKILLS_BUNDLED_DIR — explicit additional root
|
|
1268
|
+
* 4. <agent-pkg>/skills/ — authoritative Agent built-ins
|
|
1267
1269
|
*
|
|
1268
|
-
*
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1270
|
+
* All existing roots coexist. The Agent package is deliberately last so an
|
|
1271
|
+
* external package or env override cannot shadow safety-critical built-ins.
|
|
1272
|
+
* User and project tiers still load after these roots and retain their existing
|
|
1273
|
+
* higher-priority customization semantics.
|
|
1272
1274
|
*
|
|
1273
|
-
* @returns {string
|
|
1275
|
+
* @returns {string[]}
|
|
1274
1276
|
*/
|
|
1275
|
-
export function
|
|
1277
|
+
export function bundledYeaftSkillsDirs() {
|
|
1276
1278
|
const candidates = [];
|
|
1279
|
+
const home = homedir();
|
|
1280
|
+
if (home) {
|
|
1281
|
+
candidates.push(join(home, '.claude', 'plugins', 'yeaft-skills', 'skills'));
|
|
1282
|
+
candidates.push(join(home, '.claude', 'skills', 'yeaft-skills', 'skills'));
|
|
1283
|
+
}
|
|
1277
1284
|
|
|
1278
1285
|
const envOverride = process.env.YEAFT_SKILLS_BUNDLED_DIR;
|
|
1279
1286
|
if (envOverride && typeof envOverride === 'string' && envOverride.length > 0) {
|
|
1280
1287
|
candidates.push(envOverride);
|
|
1281
1288
|
}
|
|
1282
1289
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
candidates.push(join(home, '.claude', 'skills', 'yeaft-skills', 'skills'));
|
|
1286
|
-
candidates.push(join(home, '.claude', 'plugins', 'yeaft-skills', 'skills'));
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
// Bundled-with-agent fallback: <agent-pkg-root>/skills. The package root is
|
|
1290
|
-
// the directory containing agent/, so we walk up from this file.
|
|
1290
|
+
// Bundled-with-agent root: <agent-pkg>/skills. The package root is the
|
|
1291
|
+
// directory containing yeaft/, so walk up from this file.
|
|
1291
1292
|
try {
|
|
1292
1293
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
1293
|
-
|
|
1294
|
-
const agentRoot = join(here, '..', '..');
|
|
1295
|
-
candidates.push(join(agentRoot, 'skills'));
|
|
1294
|
+
candidates.push(join(here, '..', 'skills'));
|
|
1296
1295
|
} catch {
|
|
1297
1296
|
// fileURLToPath can throw on exotic loaders — non-fatal.
|
|
1298
1297
|
}
|
|
1299
1298
|
|
|
1300
|
-
|
|
1299
|
+
const roots = [];
|
|
1300
|
+
for (const candidate of candidates) {
|
|
1301
|
+
if (!candidate || roots.includes(candidate)) continue;
|
|
1301
1302
|
try {
|
|
1302
|
-
if (
|
|
1303
|
-
|
|
1303
|
+
if (existsSync(candidate) && statSync(candidate).isDirectory()) {
|
|
1304
|
+
roots.push(candidate);
|
|
1304
1305
|
}
|
|
1305
1306
|
} catch {
|
|
1306
|
-
//
|
|
1307
|
+
// Permission errors etc. make this candidate unavailable.
|
|
1307
1308
|
}
|
|
1308
1309
|
}
|
|
1310
|
+
return roots;
|
|
1311
|
+
}
|
|
1309
1312
|
|
|
1310
|
-
|
|
1313
|
+
/**
|
|
1314
|
+
* Back-compatible singular resolver with the original first-existing order.
|
|
1315
|
+
* New callers that load Skills must use `bundledYeaftSkillsDirs()` so all
|
|
1316
|
+
* roots coexist.
|
|
1317
|
+
*
|
|
1318
|
+
* @returns {string|null}
|
|
1319
|
+
*/
|
|
1320
|
+
export function bundledYeaftSkillsDir() {
|
|
1321
|
+
const roots = bundledYeaftSkillsDirs();
|
|
1322
|
+
const envOverride = process.env.YEAFT_SKILLS_BUNDLED_DIR;
|
|
1323
|
+
const home = homedir();
|
|
1324
|
+
const legacyOrder = [
|
|
1325
|
+
envOverride,
|
|
1326
|
+
home ? join(home, '.claude', 'skills', 'yeaft-skills', 'skills') : null,
|
|
1327
|
+
home ? join(home, '.claude', 'plugins', 'yeaft-skills', 'skills') : null,
|
|
1328
|
+
];
|
|
1329
|
+
return legacyOrder.find(candidate => candidate && roots.includes(candidate))
|
|
1330
|
+
|| roots.at(-1)
|
|
1331
|
+
|| null;
|
|
1311
1332
|
}
|
|
@@ -59,6 +59,7 @@ export const CONDITIONAL_BUILTIN_TOOL_NAMES = new Set([
|
|
|
59
59
|
'JsRepl',
|
|
60
60
|
'NotebookEdit',
|
|
61
61
|
'ImageGeneration',
|
|
62
|
+
'RepoWorkflow',
|
|
62
63
|
]);
|
|
63
64
|
|
|
64
65
|
const HISTORY_INTENT_RE = /(?:\bhistory\b|\b(?:prior|previous) (?:chat|conversation|discussion)\b|\bprevious(?:ly)? discussed\b|\bwhat did we (?:decide|discuss|say|agree)\b|\b(?:our|the) (?:earlier|last) decision\b|历史|之前(?:的)?(?:对话|讨论|会话|决定)|过去(?:的)?会话|我们(?:之前|上次)(?:决定|讨论|说)了什么)/iu;
|
|
@@ -70,6 +71,7 @@ const WORK_ITEM_INTENT_RE = /(?:\bwork ?center\b|\bwork ?item\b|\bdurable tracki
|
|
|
70
71
|
const REPL_INTENT_RE = /(?:\bjs ?repl\b|\bjavascript (?:calculation|experiment|evaluation)\b|\bcalculate\b|\bdata transform\b|JavaScript (?:计算|实验|求值)|数据转换|快速计算)/iu;
|
|
71
72
|
const NOTEBOOK_INTENT_RE = /(?:\.ipynb\b|\bjupyter\b|\bnotebook (?:cell|file)\b|Jupyter|笔记本单元格)/iu;
|
|
72
73
|
const IMAGE_GENERATION_INTENT_RE = /(?:\b(?:generate|make|design|draw) (?:me |us )?(?:an? |the )?(?:image|picture|logo|icon|illustration|graphic)\b|\bcreate (?:me |us )?(?:an? |the )?(?:illustration|image|picture|logo|icon|graphic)\b|生成(?:一张)?(?:图片|图像|标志|图标|插图)|创建(?:一张)?(?:插图|图片|图像|标志|图标)|画(?:一张)?(?:图|图片|图标))/iu;
|
|
74
|
+
const REPO_WORKFLOW_INTENT_RE = /(?:\b(?:git |github )?(?:worktree|pull request|pr) (?:workflow|review|merge|landing|prepare)\b|\b(?:review|merge|land|prepare) (?:a |the )?(?:github )?(?:pull request|pr)\b|\bhead[- ]match(?:ed)? merge\b|\bmerge (?:and|\+) tag\b|\breview[- ]prep\b|\bye?aft-repo\b|仓库(?:工作流|流程)|准备(?:开发|审查|review) worktree|(?:审查|评审|合并|准备) ?(?:github )?(?:pr|pull request|拉取请求)|合并(?:并|和)?打 tag|精确 head 合并)/iu;
|
|
73
75
|
const MCP_INTENT_RE = /(?:\bmcp\b|model context protocol|模型上下文协议)/iu;
|
|
74
76
|
|
|
75
77
|
function messageText(message) {
|
|
@@ -161,6 +163,7 @@ export function resolveActiveToolNames({
|
|
|
161
163
|
if (REPL_INTENT_RE.test(intentText)) active.add('JsRepl');
|
|
162
164
|
if (NOTEBOOK_INTENT_RE.test(intentText)) active.add('NotebookEdit');
|
|
163
165
|
if (imageGenerationConfigured && IMAGE_GENERATION_INTENT_RE.test(intentText)) active.add('ImageGeneration');
|
|
166
|
+
if (REPO_WORKFLOW_INTENT_RE.test(intentText)) active.add('RepoWorkflow');
|
|
164
167
|
|
|
165
168
|
for (const name of matchedMcpTools(intentText, toolNames)) active.add(name);
|
|
166
169
|
|
package/yeaft/tools/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { ToolRegistry } from './registry.js';
|
|
|
22
22
|
import skillTool from './skill.js';
|
|
23
23
|
import enterWorktree from './enter-worktree.js';
|
|
24
24
|
import exitWorktree from './exit-worktree.js';
|
|
25
|
+
import repoWorkflow from './repo-workflow.js';
|
|
25
26
|
|
|
26
27
|
// --- P0 Core tools ---
|
|
27
28
|
import askUser from './ask-user.js';
|
|
@@ -89,6 +90,7 @@ export const allTools = [
|
|
|
89
90
|
skillTool,
|
|
90
91
|
enterWorktree,
|
|
91
92
|
exitWorktree,
|
|
93
|
+
repoWorkflow,
|
|
92
94
|
|
|
93
95
|
// P0 Core
|
|
94
96
|
askUser,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { defineTool } from './types.js';
|
|
2
|
+
import {
|
|
3
|
+
formatRepoWorkflowError,
|
|
4
|
+
landRepoWorkflow,
|
|
5
|
+
prepareRepoReview,
|
|
6
|
+
prepareRepoWorkflow,
|
|
7
|
+
} from '../../repo-workflow.js';
|
|
8
|
+
|
|
9
|
+
const repoWorkflow = defineTool({
|
|
10
|
+
name: 'RepoWorkflow',
|
|
11
|
+
description: {
|
|
12
|
+
en: `Run one deterministic GitHub repository workflow phase and return compact structured evidence.
|
|
13
|
+
|
|
14
|
+
Use this instead of repeatedly issuing git/gh shell commands:
|
|
15
|
+
- prepare: fetch the remote default branch and create/reuse an exact-base development worktree.
|
|
16
|
+
- review-prep: freeze a PR's exact base/head/GitHub merge snapshot and create/reuse a clean detached review worktree.
|
|
17
|
+
- land: re-freeze an independently approved exact base branch/base SHA/head/snapshot and atomically install that exact snapshot on the approved remote base with an expected-old lease, then optionally create the next numeric tag and wait for a workflow. Worktree cleanup is deliberately separate.
|
|
18
|
+
|
|
19
|
+
This tool does not review code and never infers approval. The land phase requires the reviewer identity and exact SHAs returned by review-prep. Supports any local GitHub repository available to the Agent; git and authenticated gh CLIs are required.`,
|
|
20
|
+
zh: `执行一个确定性的 GitHub 仓库工作流阶段,并返回紧凑的结构化证据。
|
|
21
|
+
|
|
22
|
+
应使用此工具代替反复执行 git/gh shell 命令:
|
|
23
|
+
- prepare:拉取远端默认分支,并创建或复用精确基线的开发 worktree。
|
|
24
|
+
- review-prep:冻结 PR 的精确 base/head/GitHub merge snapshot,并创建或复用干净的 detached review worktree。
|
|
25
|
+
- land:重新冻结已经独立批准的 exact base branch/base SHA/head/snapshot,以 expected-old lease 在已批准的远端 base 上原子安装该 exact snapshot,随后可选创建下一个数字 tag 并等待 workflow。Worktree cleanup 刻意与 landing 分离。
|
|
26
|
+
|
|
27
|
+
此工具不做代码审查,也不会推断 review 已通过。land 必须提供 reviewer 身份以及 review-prep 返回的精确 SHA。适用于 Agent 可访问的任意本地 GitHub 仓库;需要 git 和已认证的 gh CLI。`,
|
|
28
|
+
},
|
|
29
|
+
parameters: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
phase: { type: 'string', enum: ['prepare', 'review-prep', 'land'] },
|
|
33
|
+
cwd: { type: 'string', description: 'Repository or worktree path; defaults to the current engine cwd' },
|
|
34
|
+
remote: { type: 'string', description: 'Git remote name (default: origin)' },
|
|
35
|
+
baseBranch: { type: 'string', description: 'Explicit base branch for prepare, or exact approved destination branch for land' },
|
|
36
|
+
baseSha: { type: 'string', description: 'Exact independently approved base SHA for land' },
|
|
37
|
+
name: { type: 'string', description: 'Development or review worktree name' },
|
|
38
|
+
worktreePath: { type: 'string', description: 'Explicit worktree path' },
|
|
39
|
+
pr: { type: 'integer', description: 'GitHub pull request number' },
|
|
40
|
+
reviewedHead: { type: 'string', description: 'Exact independently approved PR head SHA' },
|
|
41
|
+
reviewedSnapshot: { type: 'string', description: 'Exact independently approved GitHub merge snapshot SHA' },
|
|
42
|
+
tagPrefix: { type: 'string', description: 'Optional numeric tag prefix, for example v1.0.' },
|
|
43
|
+
tagStart: { type: 'integer', minimum: 0 },
|
|
44
|
+
workflow: { type: 'string', description: 'Optional GitHub Actions workflow name to wait for' },
|
|
45
|
+
waitTimeoutMs: { type: 'integer', minimum: 1 },
|
|
46
|
+
pollIntervalMs: { type: 'integer', minimum: 1 },
|
|
47
|
+
},
|
|
48
|
+
required: ['phase'],
|
|
49
|
+
},
|
|
50
|
+
timeoutMs: 0,
|
|
51
|
+
isConcurrencySafe: () => false,
|
|
52
|
+
isReadOnly: () => false,
|
|
53
|
+
isDestructive: input => input?.phase === 'land',
|
|
54
|
+
async execute(input, ctx) {
|
|
55
|
+
const options = { ...input, cwd: input.cwd || ctx?.cwd || process.cwd() };
|
|
56
|
+
try {
|
|
57
|
+
const dependencies = input.phase === 'land'
|
|
58
|
+
? {
|
|
59
|
+
signal: ctx?.signal,
|
|
60
|
+
approvalCapability: ctx?.inboundEnvelope?._repoApproval,
|
|
61
|
+
approvalContext: {
|
|
62
|
+
sessionId: ctx?.sessionId,
|
|
63
|
+
recipientVpId: ctx?.senderVpId,
|
|
64
|
+
turnId: ctx?.turnId,
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
: { signal: ctx?.signal };
|
|
68
|
+
const result = input.phase === 'prepare'
|
|
69
|
+
? await prepareRepoWorkflow(options, dependencies)
|
|
70
|
+
: input.phase === 'review-prep'
|
|
71
|
+
? await prepareRepoReview(options, dependencies)
|
|
72
|
+
: await landRepoWorkflow(options, dependencies);
|
|
73
|
+
return JSON.stringify(result);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return JSON.stringify(formatRepoWorkflowError(error));
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export default repoWorkflow;
|
|
@@ -99,6 +99,23 @@ Returns JSON: { ok, dispatched?, error?, detail? }.`,
|
|
|
99
99
|
zh: '可选:转交的简短原因',
|
|
100
100
|
},
|
|
101
101
|
},
|
|
102
|
+
repoApproval: {
|
|
103
|
+
type: 'object',
|
|
104
|
+
description: {
|
|
105
|
+
en: 'Optional structured repository landing approval. The host binds it to the authenticated sender VP, target VP, and current Session, then issues a non-serializable one-time capability.',
|
|
106
|
+
zh: '可选的结构化仓库落地批准。宿主会将其绑定到真实发送 VP、目标 VP 和当前 Session,并签发不可序列化的一次性 capability。',
|
|
107
|
+
},
|
|
108
|
+
properties: {
|
|
109
|
+
repository: { type: 'string', description: 'GitHub owner/repository identity' },
|
|
110
|
+
pr: { type: 'integer', minimum: 1 },
|
|
111
|
+
baseBranch: { type: 'string', description: 'Exact approved destination branch' },
|
|
112
|
+
baseSha: { type: 'string', description: 'Exact approved 40-character base SHA' },
|
|
113
|
+
reviewedHead: { type: 'string', description: 'Exact approved 40-character PR head SHA' },
|
|
114
|
+
reviewedSnapshot: { type: 'string', description: 'Exact approved 40-character merge snapshot SHA' },
|
|
115
|
+
},
|
|
116
|
+
required: ['repository', 'pr', 'baseBranch', 'baseSha', 'reviewedHead', 'reviewedSnapshot'],
|
|
117
|
+
additionalProperties: false,
|
|
118
|
+
},
|
|
102
119
|
},
|
|
103
120
|
required: ['to', 'text'],
|
|
104
121
|
},
|
|
@@ -109,7 +126,7 @@ Returns JSON: { ok, dispatched?, error?, detail? }.`,
|
|
|
109
126
|
// dispatch is rejected; the cost is one fresh read, not stale workspace data.
|
|
110
127
|
mayMutateWorkspaceAfterReturn: () => true,
|
|
111
128
|
async execute(input, ctx = {}) {
|
|
112
|
-
const { to, text, reason } = input || {};
|
|
129
|
+
const { to, text, reason, repoApproval } = input || {};
|
|
113
130
|
if (!to || typeof to !== 'string') {
|
|
114
131
|
return JSON.stringify({ ok: false, error: 'to_required' });
|
|
115
132
|
}
|
|
@@ -134,6 +151,7 @@ Returns JSON: { ok, dispatched?, error?, detail? }.`,
|
|
|
134
151
|
taskId: ctx.taskId ?? null,
|
|
135
152
|
inboundEnvelope: ctx.inboundEnvelope ?? null,
|
|
136
153
|
sourceThreadId: ctx.threadId ?? null,
|
|
154
|
+
repoApproval,
|
|
137
155
|
},
|
|
138
156
|
{ taskMembers: ctx.taskMembers },
|
|
139
157
|
);
|