teamsmith 0.1.1 → 0.1.2
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/README.md +7 -5
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +16 -0
- package/skills/teamsmith/SKILL.md +1 -1
- package/skills/teamsmith/extension/team-bg.ts +47 -11
- package/skills/teamsmith/extension/team-notify.ts +143 -4
- package/skills/teamsmith/references/openspec.md +23 -9
- package/skills/teamsmith/scripts/lib/common.sh +1 -1
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +287 -58
- package/skills/teamsmith/tests/ledger-ban.sh +1 -1
- package/skills/teamsmith/tests/lib/checkout-shape.sh +66 -14
- package/skills/teamsmith/tests/section-budgets.tsv +1 -1
- package/skills/teamsmith/tests/section-paths.tsv +1 -1
- package/skills/teamsmith/tests/section-select.sh +17 -10
- package/skills/teamsmith/tests/smoke.sh +151 -39
- package/skills/teamsmith-init/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -56,14 +56,14 @@ than replaced (`--force` replaces only an entry recognised as this skill).
|
|
|
56
56
|
### As a Pi package (no global CLI)
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
|
-
pi install git:git@github.com:Track07-cda/teamsmith@v0.1.
|
|
60
|
-
pi install -l git:git@github.com:Track07-cda/teamsmith@v0.1.
|
|
59
|
+
pi install git:git@github.com:Track07-cda/teamsmith@v0.1.2 # user level: every project
|
|
60
|
+
pi install -l git:git@github.com:Track07-cda/teamsmith@v0.1.2 # project level: recorded in .pi/settings.json
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
- **Pin a released tag**: `@v<version>`, the version `team version` prints. Latest tag:
|
|
64
64
|
`git tag --sort=-v:refname | head -1`.
|
|
65
|
-
- The `git@github.com:` form (or `ssh://git@github.com/Track07-cda/teamsmith@v0.1.
|
|
66
|
-
whether or not you have a token; the shorthand `git:github.com/Track07-cda/teamsmith@v0.1.
|
|
65
|
+
- The `git@github.com:` form (or `ssh://git@github.com/Track07-cda/teamsmith@v0.1.2`) uses your SSH key and works
|
|
66
|
+
whether or not you have a token; the shorthand `git:github.com/Track07-cda/teamsmith@v0.1.2` takes the HTTPS
|
|
67
67
|
route, so it works anonymously on the public repository and asks for credentials if your access is private.
|
|
68
68
|
- The clone lands in `~/.pi/agent/git/<host>/<path>` (user level) or `.pi/git/<host>/<path>` (project level); the
|
|
69
69
|
skill directory — the `<skill>` used in every command below — is `<clone>/skills/teamsmith`.
|
|
@@ -122,7 +122,9 @@ No forge dependency: the PM uses `git`/`gh`/`glab` directly, and cross-project c
|
|
|
122
122
|
bash <skill>/scripts/team bootstrap --print # the plan; writes nothing
|
|
123
123
|
bash <skill>/scripts/team bootstrap # .pi/team/config.sh + docs/team/** + agent worktrees + pulse
|
|
124
124
|
bash <skill>/scripts/team doctor # self-check: git/tmux/agent CLI/dependencies/gates/capacity
|
|
125
|
-
openspec init --tools pi # required dependency: spec root + the
|
|
125
|
+
openspec init --tools pi # required dependency: spec root + the generated phase commands
|
|
126
|
+
# (a pin without a `verify` workflow — 1.8.0 has only `core` —
|
|
127
|
+
# does not generate `opsx-verify`; see references/openspec.md §6)
|
|
126
128
|
```
|
|
127
129
|
|
|
128
130
|
`bootstrap` is idempotent and prints the `git worktree add` command for each agent (git stays with the PM).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamsmith",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Turn one agent session into a project owner: self-contained task briefs dispatched to worker agents in their own git worktrees, independent verification on a separate checkout, and an auditable ledger (BOARD / reviews / threads / DECISIONS). Runs on Pi today.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
> `SKILL.md`/`references/**`/`templates/**`/`extension/**` 在 Pi 里输入 `/reload`(或 `/pi-team-reload`)即生效;
|
|
6
6
|
> 判断自己是不是旧的:`team mark-loaded`(开局记一次)→ `team version --check`。
|
|
7
7
|
|
|
8
|
+
## v0.1.2 · 2026-10-13
|
|
9
|
+
|
|
10
|
+
补丁版:把「长作业车道」的工具侧修复和发布机器一起发出去。
|
|
11
|
+
|
|
12
|
+
- **长作业车道:起完就结束回合**(long-job-suspend A 刀 + P236 返工):工具说明不再要求「回合结束前
|
|
13
|
+
必须收割」——完成叫醒会把结果带回来,原地等只限「作业很短」或「结果卡住下一步且确实没别的可做」。
|
|
14
|
+
后台作业的 `start`/`wait` 两类记录写进 `state/bg.log`,`waited_s` 只量本次调用等待的时间。
|
|
15
|
+
- **挂起与中断分得开**:回合结束且确实在等自己的作业时,收件箱标 `[auto·suspended]` 并带 `awaiting=<id>`;
|
|
16
|
+
判据按 `.job` 记录的 `cwd` 归属到本会话自己的工作树(缺字段/相对路径/解析失败一律不判挂起)。
|
|
17
|
+
修前形状:只要项目里任何一个席位在做长作业,其他席位每次结束回合都会被误标(真实运行中出现四次)。
|
|
18
|
+
- **发布机器进仓并跟上改写后的形状**(P229/P233):`docs/team/tools/release-check.sh` 与
|
|
19
|
+
`publish-public.sh` 从仓外搬回仓库跟踪(此前被 ignore,坏了两周无人知),检查对象改为
|
|
20
|
+
「本仓即公开仓」:六处版本落点、最新 tag 必须等于版本且 HEAD 就在 tag 上、公开面泄漏扫描(产品面
|
|
21
|
+
查全部形状、账本面查凭据形状)、公开面不变量、三条安装路线;`--self-test` 跑真检查对四棵变异树。
|
|
22
|
+
发布清单 `docs/team/RELEASE-PUBLIC.md` 按新模型重写。
|
|
23
|
+
|
|
8
24
|
## v0.1.1 · 2026-10-04
|
|
9
25
|
|
|
10
26
|
首个发布(v0.1.0)之后当天合并的修复 —— 其中两条直接影响使用者:
|
|
@@ -3,7 +3,7 @@ name: teamsmith
|
|
|
3
3
|
description: teamsmith gives one agent real ownership of a project — it plans, writes self-contained task briefs, dispatches worker agents into their own tmux windows and git worktrees, verifies their work on an independent checkout, merges, and keeps an auditable ledger (BOARD/reviews/threads/DECISIONS). A pulse window (the periodic patrol) wakes the owner only when there is pending work, and the owner can deliberately stand down. Works with Pi; the launch/notify seam is an internal seam (frozen) reserved for a possible future non-Pi adapter, with no compatibility promise. Use when the user wants an agent to own a project end to end, dispatch tasks to worker agents, run agents in parallel in tmux with git worktree isolation, act as a PM/orchestrator over other agents, review an agent's work independently, run the patrol (`pulse`) as a tmux window, wake the PM only when there is pending work, or resume and coordinate a multi-agent project. To start a new project, use the teamsmith-init skill.
|
|
4
4
|
license: MIT
|
|
5
5
|
metadata:
|
|
6
|
-
version: "0.1.
|
|
6
|
+
version: "0.1.2"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# teamsmith · one agent that actually owns the project
|
|
@@ -24,6 +24,7 @@ import { dirname, join, resolve } from 'node:path'
|
|
|
24
24
|
|
|
25
25
|
type Job = {
|
|
26
26
|
id: string
|
|
27
|
+
root: string // 起作业时解析到的车道根 —— 账本/记录/wait 行都落它下面(会话中途换 cwd 也不漂)
|
|
27
28
|
pid: number
|
|
28
29
|
command: string
|
|
29
30
|
cwd: string
|
|
@@ -45,6 +46,20 @@ const TRUNC_MARK = '[team-bg] truncated: output exceeded the log cap, earlier ou
|
|
|
45
46
|
const CMD_DISPLAY_MAX = 100 // 结果文本里命令的码点上限(超出 → 前 100 码点 + …)
|
|
46
47
|
const CMD_ELLIPSIS = '…'
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* 车道口径(design 决策 1,单一来源)——两个工具的 description / snippet / guidelines / 起作业回执
|
|
51
|
+
* 都从这里取材,门禁(tests/bg-ledger.sh)逐字钉住:
|
|
52
|
+
* ① 起完**默认结束回合**;
|
|
53
|
+
* ② 作业完成时的**叫醒是正常收割点**(多条合并成一条,不是损失);
|
|
54
|
+
* ③ **原地等是有界例外**:预算(约 2 分钟)+ 结果卡住下一步 + 没有别的任务可推进,三条**同时**成立。
|
|
55
|
+
* 任何面都不得再出现「回合结束前必须收割」的措辞,也不得把叫醒写成惩罚/损失。
|
|
56
|
+
*/
|
|
57
|
+
const INLINE_WAIT_BUDGET = '~2 minutes'
|
|
58
|
+
const SUSPEND_DEFAULT =
|
|
59
|
+
'End your turn after starting; the completion wake-up (several completions merge into one message) is the normal harvest point.'
|
|
60
|
+
const INLINE_WAIT_EXCEPTION =
|
|
61
|
+
`Wait inline only in the bounded exception: all three must hold -- the job should finish within the inline-wait budget (${INLINE_WAIT_BUDGET}), its result blocks your immediate next step, and no other task work can advance meanwhile.`
|
|
62
|
+
|
|
48
63
|
/**
|
|
49
64
|
* 定位**本会话自己的根**:team-bg 的产物(作业日志、账本、合并窗口)都是会话本地的,
|
|
50
65
|
* 必须落在会话自己的工作树里 —— worktree 会话 = 它的 worktree,主工作树会话 = 主工作树。
|
|
@@ -258,12 +273,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
258
273
|
label: 'Team background job',
|
|
259
274
|
description:
|
|
260
275
|
'Start a long command (a gate, a build) as a detached background job and return immediately with a job id. ' +
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
promptSnippet:
|
|
276
|
+
`Output goes to state/bg/<id>.log (bounded). ${SUSPEND_DEFAULT} Then run team_bg_wait <id> there to harvest it. ` +
|
|
277
|
+
INLINE_WAIT_EXCEPTION,
|
|
278
|
+
promptSnippet:
|
|
279
|
+
'team_bg_run: start a long command in the background and end your turn ' +
|
|
280
|
+
'(returns a job id immediately; the completion wake-up is the normal harvest point)',
|
|
264
281
|
promptGuidelines: [
|
|
265
|
-
|
|
266
|
-
'(a turn must not end with unharvested background jobs).',
|
|
282
|
+
`Use team_bg_run for long gates or builds. ${SUSPEND_DEFAULT} ${INLINE_WAIT_EXCEPTION}`,
|
|
267
283
|
],
|
|
268
284
|
parameters: {
|
|
269
285
|
type: 'object',
|
|
@@ -295,11 +311,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
295
311
|
closeSync(fd)
|
|
296
312
|
}
|
|
297
313
|
const job: Job = {
|
|
298
|
-
id, pid: child.pid ?? 0, command, cwd, log, startedAt: Date.now(),
|
|
314
|
+
id, root, pid: child.pid ?? 0, command, cwd, log, startedAt: Date.now(),
|
|
299
315
|
done: false, exitCode: null, harvested: false, notified: false, waiters: [],
|
|
300
316
|
}
|
|
301
317
|
jobs.set(id, job)
|
|
302
|
-
if (job.pid > 0)
|
|
318
|
+
if (job.pid > 0) {
|
|
319
|
+
writeJobRecord(root, job)
|
|
320
|
+
// 起作业的账本行:与 .job 记录同一点位、返回 job id **之前**写(design 决策 6)。
|
|
321
|
+
// 「起了就等」与「挂起后被叫醒再收」从此只凭 state/bg.log 就能分开数。
|
|
322
|
+
appendLedger(root, `start id=${id} pid=${job.pid}`)
|
|
323
|
+
}
|
|
303
324
|
child.on('exit', (code: number | null) => finishJob(root, job, code))
|
|
304
325
|
child.on('error', (error: Error) => {
|
|
305
326
|
appendLedger(root, `spawn-error id=${id} ${String(error?.message ?? error)}`)
|
|
@@ -310,7 +331,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
310
331
|
trimTimer = setInterval(() => { for (const j of jobs.values()) if (!j.done) trimLog(j.log) }, TRIM_EVERY_MS)
|
|
311
332
|
}
|
|
312
333
|
return {
|
|
313
|
-
content: [{ type: 'text', text: `job ${id} started (pid ${job.pid}); log: ${log}\n cmd: ${displayCmd(command)}\
|
|
334
|
+
content: [{ type: 'text', text: `job ${id} started (pid ${job.pid}); log: ${log}\n cmd: ${displayCmd(command)}\n${SUSPEND_DEFAULT} Harvest job ${id} with team_bg_wait when that wake-up arrives (the result comes back inline). ${INLINE_WAIT_EXCEPTION}` }],
|
|
314
335
|
details: { id, pid: job.pid, log, cwd, cmd: command },
|
|
315
336
|
}
|
|
316
337
|
},
|
|
@@ -319,8 +340,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
319
340
|
pi.registerTool({
|
|
320
341
|
name: 'team_bg_wait',
|
|
321
342
|
label: 'Team background job wait',
|
|
322
|
-
description:
|
|
323
|
-
|
|
343
|
+
description:
|
|
344
|
+
'Wait for a job started by team_bg_run, harvest it and return its exit code plus the log tail inline. ' +
|
|
345
|
+
`${SUSPEND_DEFAULT} ${INLINE_WAIT_EXCEPTION}`,
|
|
346
|
+
promptSnippet:
|
|
347
|
+
'team_bg_wait: harvest a team_bg_run job (waits if it is still running; the completion wake-up is the normal harvest point)',
|
|
324
348
|
parameters: {
|
|
325
349
|
type: 'object',
|
|
326
350
|
properties: {
|
|
@@ -330,7 +354,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
330
354
|
required: ['id'],
|
|
331
355
|
additionalProperties: false,
|
|
332
356
|
} as any,
|
|
333
|
-
async execute(_toolCallId: string, params: any, signal: any) {
|
|
357
|
+
async execute(_toolCallId: string, params: any, signal: any, _onUpdate: any, ctx: any) {
|
|
334
358
|
const job = jobs.get(String(params?.id ?? ''))
|
|
335
359
|
if (!job) {
|
|
336
360
|
const known = [...jobs.keys()].join(', ') || '(none)'
|
|
@@ -340,23 +364,35 @@ export default function (pi: ExtensionAPI) {
|
|
|
340
364
|
? Math.max(0, Number(params.timeout_ms))
|
|
341
365
|
: DEFAULT_WAIT_MS
|
|
342
366
|
let running = false
|
|
367
|
+
let interrupted = false
|
|
368
|
+
let waitedMs = 0
|
|
343
369
|
if (!job.done && timeout > 0) {
|
|
344
370
|
job.harvested = true // 收割意图先落地:保证完成时静默(#689 第 1 条)
|
|
371
|
+
const waitingSince = Date.now()
|
|
345
372
|
const exited = await waitForExit(job, timeout, signal)
|
|
373
|
+
waitedMs = Date.now() - waitingSince // 只量**本次调用**自己等的时间,不是作业年龄
|
|
346
374
|
if (!exited && !job.done) {
|
|
347
375
|
job.harvested = false // 没收成 → 撤销意图,完成时照常唤醒
|
|
348
376
|
running = true
|
|
377
|
+
interrupted = signal?.aborted === true // 超时 vs 被中止:账本分开记(design 决策 6)
|
|
349
378
|
}
|
|
350
379
|
} else if (!job.done) {
|
|
351
380
|
running = true
|
|
381
|
+
interrupted = signal?.aborted === true
|
|
352
382
|
}
|
|
383
|
+
const waitedS = (waitedMs / 1000).toFixed(1)
|
|
384
|
+
const root = job.root || findRoot(String(ctx?.cwd ?? process.cwd()))
|
|
353
385
|
if (running) {
|
|
386
|
+
// 每次 team_bg_wait 返回一行(超时 = running;信号中止 = interrupted);既有的
|
|
387
|
+
// wake / settled-with-unharvested / spawn-error / stop 行形状一字不动。
|
|
388
|
+
appendLedger(root, `wait id=${job.id} outcome=${interrupted ? 'interrupted' : 'running'} waited_s=${waitedS}`)
|
|
354
389
|
return {
|
|
355
390
|
content: [{ type: 'text', text: `job ${job.id} is still running (pid ${job.pid}); log: ${job.log}\n cmd: ${displayCmd(job.command)}` }],
|
|
356
391
|
details: { id: job.id, running: true, log: job.log, cmd: job.command },
|
|
357
392
|
}
|
|
358
393
|
}
|
|
359
394
|
job.harvested = true
|
|
395
|
+
appendLedger(root, `wait id=${job.id} outcome=harvested waited_s=${waitedS}`)
|
|
360
396
|
const { text, truncated } = tailOf(job.log, TAIL_BYTES)
|
|
361
397
|
const secs = ((Date.now() - job.startedAt) / 1000).toFixed(1)
|
|
362
398
|
const body = truncated ? `${TRUNC_MARK}\n${text}` : text
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent'
|
|
21
21
|
import { execFileSync } from 'node:child_process'
|
|
22
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
22
|
+
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
|
23
23
|
import { dirname, join, resolve } from 'node:path'
|
|
24
24
|
import { fileURLToPath } from 'node:url'
|
|
25
25
|
|
|
@@ -132,6 +132,126 @@ function findRoot(cwd: string): string {
|
|
|
132
132
|
return derived || envRoot
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/** 后台车道自己写记录的 state 目录(team-bg 的 findRoot + stateDir 两条规则的复刻)——挂起判定
|
|
136
|
+
* **只**读这里。为什么不拿 notify 自己的 root 顶替(design 决策 4):本仓 worker worktree 不带 config,
|
|
137
|
+
* 两侧今天巧合都落主工作树;而 worktree 自带 config 的形状(S11 夹具)下车道落 worktree 侧,
|
|
138
|
+
* notify 的 git-common-dir 就会读错目录。规则:显式 TEAM_STATE_DIR 优先;否则「cwd 的 worktree 带
|
|
139
|
+
* config → 它自己;TEAM_ROOT(带 config);最近的带 config 的祖先;git 主工作树(最后的兜底)」。
|
|
140
|
+
* 任何一步推不出来 → 空串(调用方 fail-closed:不挂起)。 */
|
|
141
|
+
function laneStateDir(cwd: string): string {
|
|
142
|
+
const envDir = process.env.TEAM_STATE_DIR
|
|
143
|
+
if (envDir) return resolve(envDir)
|
|
144
|
+
let root = ''
|
|
145
|
+
const top = run('git', ['-C', cwd, 'rev-parse', '--path-format=absolute', '--show-toplevel'])
|
|
146
|
+
if (top && existsSync(join(top, '.pi/team/config.sh'))) root = resolve(top)
|
|
147
|
+
const envRoot = process.env.TEAM_ROOT ? resolve(process.env.TEAM_ROOT) : ''
|
|
148
|
+
if (!root && envRoot && existsSync(join(envRoot, '.pi/team/config.sh'))) root = envRoot
|
|
149
|
+
if (!root) {
|
|
150
|
+
let dir = resolve(cwd)
|
|
151
|
+
for (;;) {
|
|
152
|
+
if (existsSync(join(dir, '.pi/team/config.sh'))) { root = dir; break }
|
|
153
|
+
const parent = dirname(dir)
|
|
154
|
+
if (parent === dir) break
|
|
155
|
+
dir = parent
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!root) {
|
|
159
|
+
const common = run('git', ['-C', cwd, 'rev-parse', '--path-format=absolute', '--git-common-dir'])
|
|
160
|
+
if (common) {
|
|
161
|
+
const main = dirname(common)
|
|
162
|
+
if (existsSync(join(main, '.pi/team/config.sh'))) root = main
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return root ? join(root, '.pi/team/state') : ''
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** notify 自己的落点(它的项目根 + .pi/team/state)。**不许**拿它当车道的目录;只用来在两侧分歧时
|
|
169
|
+
* 记一行日志点名(否则这种错位会静默地读到错目录)。 */
|
|
170
|
+
function notifyStateDir(root: string): string {
|
|
171
|
+
return root ? join(root, '.pi/team/state') : ''
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** /proc/<pid>/stat 的启动时间指纹(第 22 字段)。comm 字段带空格/括号 → 按**最后一个** `)` 切开再数。
|
|
175
|
+
* 进程不在 / 读不到 → 空串(调用方据此判「不算在跑」)。 */
|
|
176
|
+
function procStartTime(pid: number): string {
|
|
177
|
+
try {
|
|
178
|
+
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8')
|
|
179
|
+
const rest = stat.slice(stat.lastIndexOf(')') + 1).trim().split(/\s+/)
|
|
180
|
+
return rest[19] ?? ''
|
|
181
|
+
} catch {
|
|
182
|
+
return ''
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 真实路径(软链与尾斜杠都归一):只接受绝对路径 —— 相对路径在记录里没有对象可解析,属畸形;
|
|
187
|
+
* 解析失败(路径已不存在 / 无权限)返回空串。调用方拿空串一律 fail-closed(不判挂起,绝不猜)。 */
|
|
188
|
+
function realPathOf(p: string): string {
|
|
189
|
+
if (!p || p[0] !== '/') return ''
|
|
190
|
+
try {
|
|
191
|
+
return realpathSync(p)
|
|
192
|
+
} catch {
|
|
193
|
+
return ''
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** P236 · 本会话的归属路径集合(真实路径):会话自己的 cwd 与它所在的工作树。任一路径解析失败就不
|
|
198
|
+
* 放进去 —— 集合为空 = 一条作业都不认(fail-closed 的极端形状,好过认错别人的作业)。 */
|
|
199
|
+
function ownedSessionPaths(cwd: string, worktree: string): Set<string> {
|
|
200
|
+
const owned = new Set<string>()
|
|
201
|
+
for (const p of [cwd, worktree]) {
|
|
202
|
+
const real = realPathOf(resolve(p))
|
|
203
|
+
if (real) owned.add(real)
|
|
204
|
+
}
|
|
205
|
+
return owned
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** P236 · 归属判据:作业记录里的 `cwd`(作业启动时的工作目录,也就是拥有它的那个席位的工作树)
|
|
209
|
+
* 解析到本会话自己的工作树/cwd(真实路径相等)才算「我的作业」。缺 `cwd`、相对路径、解析失败、
|
|
210
|
+
* 或指向别人的工作树 → 都不算(fail-closed)。 */
|
|
211
|
+
function isOwnedCwd(jobCwd: string, owned: Set<string>): boolean {
|
|
212
|
+
const real = realPathOf(jobCwd)
|
|
213
|
+
return real !== '' && owned.has(real)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** 在跑作业集合:读车道目录下的 `bg/*.job`,逐条做 (pid, start-time) 活体验证(与 `team bg list`
|
|
217
|
+
* 同一条身份规则),再按 `cwd` 只留**本会话自己的**作业(P236 归属范围 —— 同一车道目录里的记录
|
|
218
|
+
* 可能属于别的席位,把别人的长作业算成自己挂起会污染 `awaiting=`)。任何一条失败都**跳过**
|
|
219
|
+
* (目录/记录读不了、软链-FIFO 记录、pid 非正整数、start 缺失、/proc 读不到、指纹不符、cwd 缺失
|
|
220
|
+
* 或不属于本会话)—— fail-closed:判定的不确定方向永远是「不挂起」,绝不假造挂起(design 决策 4)。 */
|
|
221
|
+
function runningLaneJobs(laneDir: string, owned: Set<string>): string[] {
|
|
222
|
+
if (!laneDir || owned.size === 0) return []
|
|
223
|
+
let names: string[]
|
|
224
|
+
try {
|
|
225
|
+
names = readdirSync(join(laneDir, 'bg'))
|
|
226
|
+
} catch {
|
|
227
|
+
return [] // 车道还没起过作业(目录不存在)/ 读不了:没有在跑作业
|
|
228
|
+
}
|
|
229
|
+
const ids: string[] = []
|
|
230
|
+
for (const name of names.sort()) {
|
|
231
|
+
if (!name.endsWith('.job')) continue
|
|
232
|
+
const id = name.slice(0, -'.job'.length)
|
|
233
|
+
if (!/^[A-Za-z0-9._-]+$/.test(id)) continue // 平坦 id(读侧边界与 team bg 同规则)
|
|
234
|
+
try {
|
|
235
|
+
const file = join(laneDir, 'bg', name)
|
|
236
|
+
if (!lstatSync(file).isFile()) continue // 软链 / FIFO / 目录:记录畸形
|
|
237
|
+
const fields: Record<string, string> = {}
|
|
238
|
+
for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
|
|
239
|
+
const i = line.indexOf('=')
|
|
240
|
+
if (i > 0) fields[line.slice(0, i).trim()] = line.slice(i + 1).trim()
|
|
241
|
+
}
|
|
242
|
+
const pid = Number(fields.pid ?? '')
|
|
243
|
+
const start = fields.start ?? ''
|
|
244
|
+
if (!Number.isInteger(pid) || pid <= 0 || !start) continue
|
|
245
|
+
if (procStartTime(pid) !== start) continue // 死进程 / pid 复用 / /proc 读不到:都不算在跑
|
|
246
|
+
if (!isOwnedCwd(fields.cwd ?? '', owned)) continue // P236:别人的作业不算自己挂起
|
|
247
|
+
ids.push(id)
|
|
248
|
+
} catch {
|
|
249
|
+
continue // 读不了:不算在跑
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return ids
|
|
253
|
+
}
|
|
254
|
+
|
|
135
255
|
function readCfg(root: string): Cfg {
|
|
136
256
|
const file = process.env.TEAM_CONFIG_FILE || join(root, '.pi/team/config.sh')
|
|
137
257
|
const cfg: Cfg = { ...DEFAULTS }
|
|
@@ -330,8 +450,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
330
450
|
const tip = proven ? run('git', ['-C', cwd, 'rev-parse', 'HEAD']).slice(0, TIP_WIDTH) : ''
|
|
331
451
|
const revStamp = tip ? ` · task=${id} tip=${tip}` : ''
|
|
332
452
|
const dirty = run('git', ['-C', cwd, 'status', '--porcelain']).split('\n').filter(Boolean).length
|
|
333
|
-
// 未提交 = 没交付干净:让 PM 一眼看出来(CEP 实测:这种状态和"干净交付"在通知里长得一样)
|
|
334
|
-
const dirtyFlag = dirty > 0 ? `⚠ 未提交 ${dirty} 个文件 · ` : ''
|
|
335
453
|
const upstream = run('git', ['-C', cwd, 'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'])
|
|
336
454
|
const unpushed = upstream
|
|
337
455
|
? run('git', ['-C', cwd, 'rev-list', '--count', '@{upstream}..HEAD']) || '?'
|
|
@@ -355,11 +473,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
355
473
|
/* 通知绝不能打断会话 */
|
|
356
474
|
}
|
|
357
475
|
|
|
476
|
+
// 挂起判定(design 决策 4 + P236 归属范围):在跑集合从**车道自己写记录的目录**读(laneStateDir),
|
|
477
|
+
// 逐条 (pid, start-time) 验活、再按 cwd 只留**本会话自己的**作业;判定失败一律退回非挂起形状
|
|
478
|
+
// (fail-closed)——既不假造挂起,也不拿 notify 自己的 root 顶替车道目录(两侧分歧时它只负责把
|
|
479
|
+
// 这件事记进日志)。
|
|
480
|
+
// P236(缺陷现场):同一车道目录里的记录可能属于**别的席位** —— 只看「项目里有活作业」会把别人的
|
|
481
|
+
// 长作业算成自己挂起。归属判据 = 作业的 cwd 与本会话自己的工作树/cwd 解析到同一个真实路径。
|
|
482
|
+
const laneDir = laneStateDir(cwd)
|
|
483
|
+
const ownDir = notifyStateDir(root)
|
|
484
|
+
if (laneDir && ownDir && laneDir !== ownDir) {
|
|
485
|
+
log(`suspend check reads the lane's directory ${laneDir} (notify's own root would be ${ownDir})`, cfg)
|
|
486
|
+
}
|
|
487
|
+
const owned = ownedSessionPaths(cwd, join(wtPrefix, agent))
|
|
488
|
+
const running = runningLaneJobs(laneDir, owned)
|
|
489
|
+
const awaiting = running.length > 0 ? `awaiting=${running.join(',')}` : ''
|
|
490
|
+
const suspended = completed && running.length > 0
|
|
491
|
+
|
|
358
492
|
const summary = [
|
|
359
493
|
`agent:${agent}`,
|
|
360
494
|
id,
|
|
361
495
|
`branch=${branch || '-'}`,
|
|
362
496
|
`uncommitted=${dirty}`,
|
|
497
|
+
...(awaiting ? [awaiting] : []),
|
|
363
498
|
`unpushed=${unpushed}${upstream ? '' : '(no-upstream)'}`,
|
|
364
499
|
].join(' · ')
|
|
365
500
|
// 未完成的回合 + 本轮内有过生命周期事件 = 内部重启/压缩的产物,不是交付:不发简报、不敲门。
|
|
@@ -371,8 +506,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
371
506
|
}
|
|
372
507
|
lifecycleDuringTurn = ''
|
|
373
508
|
|
|
509
|
+
// 未提交 = 没交付干净:让 PM 一眼看出来(CEP 实测:这种状态和"干净交付"在通知里长得一样)。
|
|
510
|
+
// 挂起不是交付主张:省略 ⚠ 前缀(事实留在 uncommitted=<n> 字段里),否则告警框只会误导。
|
|
511
|
+
const dirtyFlag = dirty > 0 && !suspended ? `⚠ 未提交 ${dirty} 个文件 · ` : ''
|
|
512
|
+
|
|
374
513
|
count++
|
|
375
|
-
const tag = completed ? '[auto]' : '[auto·interrupted]'
|
|
514
|
+
const tag = completed ? (suspended ? '[auto·suspended]' : '[auto]') : '[auto·interrupted]'
|
|
376
515
|
// 去重键:整条末消息的「长度+指纹」+ 修订标识(新 tip = 新修订,不该被去重吞掉)。
|
|
377
516
|
// 老键(last[0:60])会把三条开头相同、后半不同的简报当成同一条吞掉(M6.3 F17)。
|
|
378
517
|
const key = `${agent}|${tag}|${summary}|${revStamp}|${last.length}:${fingerprint(last)}`
|
|
@@ -14,7 +14,8 @@ CLI reference, `validate` output). Those live where they are generated and maint
|
|
|
14
14
|
## 0. Where the authoritative OpenSpec documentation is
|
|
15
15
|
|
|
16
16
|
- **The phase commands themselves** — `.pi/prompts/opsx-*.md` and `.pi/skills/openspec-*/SKILL.md`, generated for
|
|
17
|
-
this project's agent tool (`openspec init --tools pi
|
|
17
|
+
this project's agent tool (`openspec init --tools pi`; §6 states exactly which of the five phases the installed
|
|
18
|
+
OpenSpec actually generates). That is what an agent actually follows. They describe the
|
|
18
19
|
*mechanics* of a phase (how to explore, how to write the artifacts); **who may invoke a phase, and behind which
|
|
19
20
|
gate, is teamsmith's rule, not theirs** — see §1, §2 and §4.
|
|
20
21
|
- **The artifact instructions** — `openspec instructions <artifact>` (proposal / specs / design / tasks / apply /
|
|
@@ -184,14 +185,27 @@ tip.
|
|
|
184
185
|
|
|
185
186
|
## 6. Preconditions
|
|
186
187
|
|
|
187
|
-
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
and
|
|
188
|
+
- Generate what the installed OpenSpec can generate: `openspec init --tools pi` writes the command and skill files
|
|
189
|
+
for the workflows of the active profile (use the tool's own id for a non-Pi CLI). With the version this project
|
|
190
|
+
pins — **1.8.0, whose only profile is `core`** (`openspec config list` prints
|
|
191
|
+
`workflows: propose, explore, apply, update, sync, archive (from core profile)`) — that is
|
|
192
|
+
`opsx-{explore,propose,apply,archive}` plus the helper commands `opsx-update`/`opsx-sync`, and the matching
|
|
193
|
+
skills `openspec-{explore,propose,apply-change,archive-change}` plus `openspec-sync-specs`/`openspec-update-change`.
|
|
194
|
+
**It does not generate the verify pair** (`opsx-verify.md`,
|
|
195
|
+
`openspec-verify-change/SKILL.md`): 1.8.0 has no `verify` workflow, and the `expanded` profile this guide used to
|
|
196
|
+
name does not exist (`openspec config profile expanded` → `Error: Unknown profile preset "expanded". Available
|
|
197
|
+
presets: core`). Once a project has generated files, `openspec update` refreshes them; it finds the configured
|
|
198
|
+
tools from those files and answers "No configured tools found" when there are none.
|
|
199
|
+
- **A phase whose command is missing is not a phase that did not run.** The verify phase is owned by this guide, not
|
|
200
|
+
by a generated file: run it from §1 and §5 — a different agent than the implementer, the change + the landed code
|
|
201
|
+
+ the report as its hand-in, `docs/team/reviews/<ID>.md` as its hand-out. If you want a command for it, write the
|
|
202
|
+
prompt yourself and say it is yours; do not record a hand-written prompt as generated. What teamsmith gates on is
|
|
203
|
+
the **artifact** (the review record); the command file is only checked where the checkout carries one (a checkout
|
|
204
|
+
without the machine-generated surface gets a named skip, never a red — P222).
|
|
205
|
+
- Whether the generated files are committed follows the project's own ignore rules. This repository ignores `.pi/**`
|
|
206
|
+
(`.gitignore`): the files are per-machine, every clone and every CI checkout starts without them, and the gate
|
|
207
|
+
reports the `.pi/prompts` / `.pi/skills` checks as named skips there. A project that does commit them gets those
|
|
208
|
+
checks on every checkout, which is strictly more coverage.
|
|
195
209
|
- Resolve the CLI and the spec root: `team paths` (and `team doctor`) print `TEAM_OPENSPEC_BIN` / `TEAM_SPEC_DIR`;
|
|
196
210
|
with `TEAM_REQUIRE_OPENSPEC=1` (the default) a missing CLI or spec directory fails the doctor. The gate needs the
|
|
197
211
|
CLI on `PATH` (or an absolute path in `TEAM_OPENSPEC_BIN`).
|