end-session

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

End session

结束会话

Close out the session so the next one starts from an accurate picture instead of reconstructing one. A session's durable output is more than its diff: what it learned (memory), what it moved (issues and the board), what a human must now do (follow-ups), what its docs now get wrong, and what it left behind (the workspace). Sweep those, in that order.
Announce at start: "I'm using the end-session skill to close out this session."
Run shell snippets in bash (Git Bash on Windows). Where
gh
is unavailable, use the equivalent GitHub MCP operation: a missing CLI changes the interface, not the step.
This skill leaves shipping to the
ship
skill: no version bump, changelog section, source push, or PR. A finished branch is shipped first, then this runs; a mid-flight branch stays mid-flight, recorded where it stands.
Three rules hold throughout:
  • Evidence, not recollection. An empty bucket is a valid outcome; say so and move on. An invented memory, comment, or entry is worse than none.
  • List before deleting. Every deletion — file, branch, worktree, container — is shown as a list and waits for a yes.
  • Ask before committing or discarding, except where a setting pre-authorizes it.
结束会话,让下一次会话从准确的现状开始,而不是靠重新拼凑还原。一次会话的持久产出不只是它的 diff,还包括它学到了什么(memory)、推进了什么(issues 和 Board)、现在必须由人处理什么(follow-ups)、文档中有哪些内容已经过时,以及遗留了什么(workspace)。按这个顺序逐一检查。
开始时宣告:「我正在使用 end-session Skill 来结束本次会话。」
在 bash(Windows 上使用 Git Bash)中运行 shell 代码段。如果无法使用
gh
,则使用等效的 GitHub MCP 操作:缺少 CLI 只会改变执行接口,不会改变步骤。
本 Skill 将发布工作留给
ship
Skill:不执行版本号递增、changelog 条目、源代码 push 或 PR。已完成的 branch 会先发布,然后才运行本 Skill;仍在进行中的 branch 保持原状,并记录其当前进度。
整个过程中始终遵循三条规则:
  • 以证据为准,而不是凭记忆。 没有产出也是有效结果;说明情况后继续。虚构的 memory、comment 或条目比没有更糟。
  • 先列出,再删除。 每一次删除——文件、branch、worktree、container——都要先以列表形式展示,并等待用户确认。
  • 提交或丢弃前先询问, 除非某项设置已预先授权。

0. Settings

0. 设置

This skill reads
docs/agents/workspace.md
,
docs/agents/issue-tracker.md
,
docs/agents/human-follow-up.md
,
docs/agents/docs.md
and
docs/agents/triage-labels.md
. Follow
.agents/skills/end-session/settings/README.md
to read them and complete any that are missing; the definitions sit beside it. Resolve each
discover:
value once, here, and reuse it below.
Invoked by handoff: when the arguments say
invoked by handoff; document at <path>
, the handoff document is already written and registered. Carry its path into the report, and treat the user's work as continuing on the other machine, not in this checkout.
本 Skill 读取
docs/agents/workspace.md
、
docs/agents/issue-tracker.md
、
docs/agents/human-follow-up.md
、
docs/agents/docs.md
和
docs/agents/triage-labels.md
。按照
.agents/skills/end-session/settings/README.md
的说明读取这些文件,并补齐任何缺失项;相关定义就在该文件旁。在这里将每个
discover:
值解析一次,并在下文复用。
**由 handoff 调用:**当参数显示
invoked by handoff; document at <path>
时,handoff 文档已经写好并登记。将其路径带入报告,并将用户的工作视为正在另一台机器上继续,而不是在这个 checkout 中继续。

1. Take stock

1. 盘点

Establish what the session did before writing anything:
bash
git status --short --branch
git branch --show-current
git log --oneline origin/main..HEAD
gh pr list --author @me --state open --json number,title,headRefName
Then run the
Workspace status command
. Sort what the session produced into the buckets below; each routes to a later step.
BucketStep
Durable facts about how to work in this repository or environment2. Memory
Work started, finished, blocked, discovered, or understood differently3. Issues
Actions only a human can now take4. Human follow-ups
Decisions, findings, and state changes the docs should hold5. Docs
Files, branches, worktrees, containers left behind6. Workspace
在写入任何内容前,确定本次会话做了什么:
bash
git status --short --branch
git branch --show-current
git log --oneline origin/main..HEAD
gh pr list --author @me --state open --json number,title,headRefName
然后运行
Workspace status command
。将本次会话的产出分类到以下类别;每一项都对应后续步骤。
类别步骤
关于如何在此仓库或环境中工作的持久事实2. Memory
已开始、已完成、被阻塞、已发现,或理解发生了变化的工作3. Issues
现在只有人能采取的操作4. Human follow-ups
文档应当记录的决定、发现和状态变更5. Docs
遗留的文件、branch、worktree、container6. Workspace

2. Memory

2. Memory

Memory lives outside the repository, one fact per file, in the memory directory the harness names in its instructions. Use that path exactly as given: a path derived from the checkout location differs per machine and per tool, and writes to a wrong one succeed silently and are never read. If the harness names no memory directory, skip this step and say so in the report.
MEMORY.md
there is the index: one line per memory, never content.
Save a candidate only when a fresh session here would get it wrong without the note and the repository does not already record it.
AGENTS.md
, the docs, the issue tracker, the changelog, and Git history are durable; a memory restating them goes stale the moment they change. Memory is for what is written nowhere: a trap that cost time, a preference the user stated, the state of half-decided work.
  • Read
    MEMORY.md
    first, and update a matching memory rather than adding a near-duplicate.
  • Correct or delete a memory this session proved wrong.
  • Write absolute dates, link related memories with
    [[slug]]
    , and keep every
    MEMORY.md
    pointer in step with the files.
  • Keep an unpatched security weakness out of memory bodies; point at where it is tracked instead.
Memory 位于仓库之外,按照 harness 说明指定的 memory 目录组织,每个文件只保存一项事实。严格使用给定的路径:从 checkout 位置推导出的路径会因机器和工具而异,写入错误路径会静默成功,却永远不会被读取。如果 harness 未指定 memory 目录,则跳过此步骤并在报告中说明。该目录中的
MEMORY.md
是索引:每条 memory 占一行,绝不写入正文。
仅当没有这条记录,新的会话在这里就会判断错误,并且仓库中尚未记录该信息时,才保存候选 memory。
AGENTS.md
、文档、issue tracker、changelog 和 Git history 都是持久信息源;重复记录这些内容的 memory 会在它们发生变化后立即过时。Memory 只用于记录其他地方没有的信息:曾经耗费时间的陷阱、用户明确表达的偏好,以及尚处于决策中途的工作状态。
  • 先读取
    MEMORY.md
    ;如果已有匹配的 memory,则更新它,而不是添加近似重复项。
  • 如果本次会话证明某条 memory 有误,则更正或删除它。
  • 写入绝对日期,使用
    [[slug]]
    关联相关 memory,并确保
    MEMORY.md
    中的每个指针都与文件保持同步。
  • 不要在 memory 正文中保留尚未修补的安全弱点;应指向其受跟踪的位置。

3. Issues and the board

3. Issues 与 Board

Issues carry the work; the
Board
carries its state. Labels are the five in
.agents/skills/end-session/settings/triage-labels.md
, plus any
Extra labels
in
docs/agents/triage-labels.md
.
Board writes need the
gh
token's
project
scope, and fail silently without it. Check
gh auth status
for
project
(not just
read:project
). If it is missing, report it and skip board writes; the fix (
gh auth refresh -h github.com -s project
) needs a real terminal.
Read and write the
Board
only through
.agents/skills/end-session/board.mjs
, never
gh project item-edit
or
item-list
: it finds an item from its issue, matches field and option names whatever their case or dash, writes an item's fields in one request, and reads every write back.
<board>
below is the
Board
setting's two words:
bash
node .agents/skills/end-session/board.mjs file --board "<board>" --item <owner/name#N> --set "Status=Todo"
node .agents/skills/end-session/board.mjs set --board "<board>" --item <owner/name#N> --set "Blocked by=<reason>"
node .agents/skills/end-session/board.mjs audit --board "<board>" --repo <Public repository>
file
adds the issue when it is not on the board yet and sets the fields given;
set
changes an item already there;
--set "<Field>="
clears one. A value is an option's name or a unique prefix of it (
P2
). Each prints JSON; an
error
means nothing was confirmed, so report it.
Start from what is open, in the
Public repository
and again in the
Private issue repository
when there is one — always selected explicitly with
-R
:
bash
gh issue list -R <repository> --state open --json number,title,labels \
  --jq '[.[] | {number, title, labels: [.labels[].name]}]'
For each issue the session touched:
  • Shipped — comment the outcome and what changed about the understanding of the problem. Close it once its PR has merged; while the PR is open, leave it open and name the PR.
  • Advanced but unfinished — comment where it stands and the next concrete step, written for a reader arriving cold.
  • Blocked — comment the blocker, and set the
    Board fields
    that record it.
  • Understanding changed — correct the body, or comment the correction. An issue describing the wrong problem costs more than a missing one.
  • Newly discovered work — record it as
    New work
    says: an issue, labelled and filed on the
    Board
    with
    board.mjs file
    ; or a
    Board
    draft item (
    gh project item-create --format json
    , whose
    id
    is the item's), left for the work's commitment to turn into an issue, its fields set with
    board.mjs set --item-id <id>
    . Set its board fields either way. Work that never reaches the board is invisible to the next session.
Then run
board.mjs audit
, with
--repo
for the
Public repository
and again for the
Private issue repository
when there is one. Set Done on each
closedNotDone
item the session's work closed; report the rest of
closedNotDone
, every
openDone
item and every
missing
issue rather than fixing what the session never touched. The private tracker's results stay out of anything public.
A security finding follows the
Security findings
route, never a public issue before its fix ships. Keep private-repository links and content out of public issues, PRs, and commits. Leave issues the session never touched to the
triage
skill.
Issues 承载工作,Board 承载其状态。标签包括
.agents/skills/end-session/settings/triage-labels.md
中的五项,以及
docs/agents/triage-labels.md
中列出的所有
Extra labels
。
Board 写入需要
gh
token 具备
project
scope,缺少该权限时会静默失败。通过
gh auth status
检查
project
,不能只检查
read:project
。如果缺少该权限,则报告并跳过 Board 写入;修复命令
gh auth refresh -h github.com -s project
需要在真实终端中执行。
读取和写入
Board
时只能使用
.agents/skills/end-session/board.mjs
,不要使用
gh project item-edit
或
item-list
:它会从 issue 查找对应条目,匹配字段名和选项名(无论大小写或连字符形式),在一次请求中写入条目字段,并回读每次写入。下方的
<board>
代表
Board
设置中的两个词:
bash
node .agents/skills/end-session/board.mjs file --board "<board>" --item <owner/name#N> --set "Status=Todo"
node .agents/skills/end-session/board.mjs set --board "<board>" --item <owner/name#N> --set "Blocked by=<reason>"
node .agents/skills/end-session/board.mjs audit --board "<board>" --repo <Public repository>
file
会在 issue 尚未位于 Board 上时将其添加进去,并设置给定字段;
set
修改已有条目;
--set "<Field>="
清除字段。值可以是选项名称或其唯一前缀(例如
P2
)。每条命令都会输出 JSON;出现
error
表示没有任何写入得到确认,因此必须报告。
从
Public repository
中当前开放的条目开始;如果存在
Private issue repository
,也对其执行相同操作——始终使用
-R
显式选择仓库:
bash
gh issue list -R <repository> --state open --json number,title,labels \
  --jq '[.[] | {number, title, labels: [.labels[].name]}]'
对于本次会话涉及的每个 issue:
  • 已发布——评论最终结果,以及对问题的理解发生了哪些变化。PR 合并后关闭 issue;PR 仍开放时保持 issue 开放,并注明该 PR。
  • 已推进但未完成——评论当前进度和下一步具体行动,让初次接触该工作的读者也能理解。
  • 被阻塞——评论阻塞原因,并设置记录该情况的
    Board fields
    。
  • 理解发生变化——更正正文,或评论更正内容。描述错误问题的 issue 比缺失 issue 更糟糕。
  • 新发现的工作——按照
    New work
    所述方式记录:创建 issue,添加标签并通过
    board.mjs file
    登记到
    Board
    ;或者创建 Board 草稿条目(
    gh project item-create --format json
    ,其
    id
    就是该条目的 ID),暂不将其转为 issue,但应承诺后续转为 issue,并通过
    board.mjs set --item-id <id>
    设置字段。无论采用哪种方式,都要设置其 Board 字段。未进入 Board 的工作对下一次会话而言是不可见的。
然后运行
board.mjs audit
,对
Public repository
使用
--repo
;如果存在
Private issue repository
,也再运行一次。将本次会话的工作所关闭的每个
closedNotDone
条目标记为 Done;其余
closedNotDone
、每个
openDone
条目和每个
missing
issue 均予以报告,而不是修复本次会话从未触及的内容。私有 tracker 的结果不得进入任何公开内容。
安全发现遵循
Security findings
路径;在修复发布之前,绝不创建公开 issue。将私有仓库的链接和内容排除在公开 issue、PR 和 commit 之外。未触及的 issue 留给
triage
skill 处理。

4. Human follow-ups

4. Human follow-ups

Run the
## Procedure
in
.agents/skills/end-session/settings/human-follow-up.md
for every required human action left by the session's completed work, including ones other skills already started (docs-updater,
ship
): reconcile those rather than duplicating them.
针对本次会话已完成工作留下的每项必要人工操作,运行
.agents/skills/end-session/settings/human-follow-up.md
中的
## Procedure
,包括其他 Skill 已开始处理的事项(docs-updater、ship):应进行协调,而不是重复创建。

5. Docs

5. Docs

Run the
docs-updater
skill on the session's work, in a subagent where the harness has one, told to follow
.agents/skills/docs-updater/SKILL.md
; otherwise follow it yourself. A subagent cannot ask the user, so complete its settings first, here, by following its step 0. Use
fix
mode for work not yet merged, and
check
mode for work
ship
already refreshed and merged, recording any drift it reports as new work, as step 3 does. Merged work whose
ship
report owed a wiki search gets one more run in
fix
mode, limited to the wikis: those stale references are fixed, not filed. Tell it this is
end-session
, and give it the session's discoveries as a list of changes beside the diff: decisions and findings land in the
Doc map
documents whose when they match, honoring each one's marker. Run step 4's procedure for any human actions it returns. Its edits come back uncommitted, and join step 6's question about uncommitted work. Keep its report for step 7.
  • Companion. When the
    Private companion
    is set and its checkout exists, inspect it from its own root: the outer repository's
    git log
    ,
    git show
    and
    git diff
    cannot see inside it. When the checkout is absent, report that companion docs could not be reconciled, and create no directory in its place. Commit companion changes by the
    ## Procedure
    in
    .agents/skills/end-session/settings/workspace.md
    .
  • Changelog debt. A behavior change committed this session without its
    Unreleased
    entry (its
    changelog.d/
    fragment, with
    Scheme: stamp-on-tag
    ) is debt to report;
    ship
    writes the changelog.
  • One tracker. A backlog, roadmap, or TODO file the session added to the tree duplicates the issue tracker; offer to move its content into issues.
在 harness 支持 subagent 时,以 subagent 方式运行
docs-updater
skill 来处理本次会话的工作,并要求其遵循
.agents/skills/docs-updater/SKILL.md
;否则自行执行。Subagent 无法询问用户,因此先在此处按照其步骤 0 完成设置。对于尚未合并的工作,使用
fix
模式;对于
ship
已刷新且已合并的工作,使用
check
模式,并按照步骤 3 将其报告的任何偏差记录为新工作。如果已合并工作的
ship
报告表明还需要进行 wiki 搜索,则再以
fix
模式运行一次,但仅限于 wiki:这些过时引用应予修复,而不是创建 issue。
告知它本次运行的是
end-session
,并以变更列表形式提供本次会话的发现,与 diff 并列:决定和发现应落到
Doc map
文档中——当其 when 标记匹配时,并遵循每个文档的 marker。对其返回的所有人工操作运行步骤 4 的流程。其编辑结果以未提交状态返回,并纳入步骤 6 关于未提交工作的询问。保留其报告,供步骤 7 使用。
  • **Companion。**设置
    Private companion
    且其 checkout 存在时,从它自身的根目录进行检查:外层仓库的
    git log
    、
    git show
    和
    git diff
    无法看到其中的内容。Checkout 不存在时,报告无法协调 companion 文档,并且不要在其原位置创建目录。按照
    .agents/skills/end-session/settings/workspace.md
    中的
    ## Procedure
    提交 companion 更改。
  • **Changelog 欠账。**本次会话提交了行为变更,却没有添加对应的
    Unreleased
    条目(位于
    changelog.d/
    中,并采用
    Scheme: stamp-on-tag
    ),则应将其作为欠账报告;changelog 由
    ship
    写入。
  • **单一 tracker。**本次会话添加到目录树中的 backlog、roadmap 或 TODO 文件与 issue tracker 重复,应主动提议将其内容移入 issues。

6. Workspace

6. Workspace

Uncommitted work first — it is the one thing cleanup can lose for good:
bash
git status --short
git stash list
Run the same in the companion when it exists. For each change, ask: commit it on its branch, stash it with a named message, or leave it. Leaving it is a valid answer; say so in the report. A companion change is committed only by the
## Procedure
in
.agents/skills/end-session/settings/workspace.md
.
Branches. A branch is finished when its PR merged at or after the branch's local tip — true for squash and merge commits alike, where
git branch --merged
misses every squashed branch:
bash
git fetch --prune origin
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads | grep -vx main); do
  tip=$(git rev-parse "$branch")
  pr=$(gh pr list --state all --head "$branch" --json number,state,headRefOid \
    --jq 'sort_by(.number) | last | select(.) | "\(.number) \(.state) \(.headRefOid)"')
  read -r number state head <<< "$pr"
  verdict=unfinished
  if [ "$state" = MERGED ]; then
    git cat-file -e "$head^{commit}" 2>/dev/null || git fetch -q origin "pull/$number/head"
    git merge-base --is-ancestor "$tip" "$head" && verdict=finished
  elif [ -z "$number" ] && git merge-base --is-ancestor "$tip" origin/main; then
    verdict=finished
  fi
  echo "$branch ${number:-no-pr} ${state:-none} $verdict"
done
git worktree list
Delete finished branches with
git branch -D
once the user agrees (
-d
refuses squashed ones). A branch with an open PR, no PR and commits of its own, or commits after its merged head holds work: keep it, and name
ship
in the report when it is ready. A remote branch still listed after the prune gets the same check before
git push origin --delete
. Remove a finished worktree with
git worktree remove <path>
, then
git worktree prune
.
Return to
main
last, after the tidying below, unless the tree has uncommitted tracked changes or the user is continuing on this branch in this checkout. Record
before="$(git rev-parse HEAD)"
, run
git switch main
, then
Sync with main
. If the sync refuses to fast-forward, local
main
has commits of its own: report it and leave
main
as it is. A companion that has diverged from its upstream (commits on both sides) is reported, never merged, rebased, reset or force-pushed. For each dependency lockfile in
git diff --name-only "$before" HEAD
, install from that lockfile in its folder, in the frozen form the repository's
AGENTS.md
gives (
npm ci
,
pnpm install --frozen-lockfile
,
dotnet tool restore
), asking first where
AGENTS.md
gates installs. Then run
Hook: after sync
from
docs/agents/workspace.md
.
Files. Delete
Safe-to-remove paths
, and stray scratch files the session left in the tree, by explicit path after listing them.
Never-remove paths
stay unless the user explicitly asks; blanket deletes such as
git clean -x
would take them too, so delete only by path.
Then:
  • Dev stack
    — report what is running and ask before stopping it; a running database may be deliberate. Never run its Never run commands here.
  • Generated-config check
    — when it reports drift, regenerate, and commit both sides.
  • Hook: end-session cleanup
    from
    docs/agents/workspace.md
    .
  • Final portability check
    , last. Name the exact state of each repository rather than calling the checkout synchronized.
先处理未提交的工作——这是清理过程中唯一可能永久丢失的内容:
bash
git status --short
git stash list
如果存在 companion,也在其中运行相同命令。对于每项更改,询问用户:提交到所在 branch、以命名消息 stash,还是保持不变。保持不变也是有效答案,应在报告中说明。Companion 更改只能按照
.agents/skills/end-session/settings/workspace.md
中的
## Procedure
提交。
**Branches。**当 PR 在 branch 的本地 tip 处或之后合并时,该 branch 视为已完成——无论采用 squash 还是 merge commit;
git branch --merged
会漏掉所有经过 squash 的 branch:
bash
git fetch --prune origin
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads | grep -vx main); do
  tip=$(git rev-parse "$branch")
  pr=$(gh pr list --state all --head "$branch" --json number,state,headRefOid \
    --jq 'sort_by(.number) | last | select(.) | "\(.number) \(.state) \(.headRefOid)"')
  read -r number state head <<< "$pr"
  verdict=unfinished
  if [ "$state" = MERGED ]; then
    git cat-file -e "$head^{commit}" 2>/dev/null || git fetch -q origin "pull/$number/head"
    git merge-base --is-ancestor "$tip" "$head" && verdict=finished
  elif [ -z "$number" ] && git merge-base --is-ancestor "$tip" origin/main; then
    verdict=finished
  fi
  echo "$branch ${number:-no-pr} ${state:-none} $verdict"
done
git worktree list
用户同意后,使用
git branch -D
删除已完成的 branch(
-d
会拒绝经过 squash 的 branch)。如果某个 branch 有开放 PR、没有 PR 但包含自己的 commit,或者其 merged head 之后还有 commit,则它仍承载工作:应保留,并在准备好时在报告中注明
ship
。Prune 后仍列出的 remote branch,也应先执行相同检查,再运行
git push origin --delete
。使用
git worktree remove <path>
删除已完成的 worktree,然后运行
git worktree prune
。
最后返回
main
,并在完成下方整理后执行;除非目录树中存在未提交的 tracked 更改,或者用户正在此 checkout 的该 branch 上继续工作。记录
before="$(git rev-parse HEAD)"
,运行
git switch main
,然后执行
Sync with main
。如果同步拒绝 fast-forward,说明本地
main
有自己的 commit:报告情况并保持
main
不变。如果 companion 已与其 upstream 分叉(双方都有 commit),则只进行报告,绝不 merge、rebase、reset 或 force-push。对于
git diff --name-only "$before" HEAD
中列出的每个 dependency lockfile,在其所在目录中按照仓库
AGENTS.md
给出的冻结形式进行安装(
npm ci
、
pnpm install --frozen-lockfile
、
dotnet tool restore
);如果
AGENTS.md
对安装操作设置了门控,则先询问。然后运行
docs/agents/workspace.md
中的
Hook: after sync
。
**文件。**先以列表形式展示,再按明确路径删除
Safe-to-remove paths
以及本次会话遗留在目录树中的零散临时文件。
Never-remove paths
保持不变,除非用户明确要求;诸如
git clean -x
之类的一揽子删除操作也会将其删除,因此只能按路径删除。
然后:
  • Dev stack——报告正在运行的内容,并在停止前询问;正在运行的数据库可能是有意保留的。此处绝不运行其 Never run 命令。
  • Generated-config check——如果报告存在漂移,则重新生成并提交两侧内容。
  • 运行
    docs/agents/workspace.md
    中的
    Hook: end-session cleanup
    。
  • 最后执行 Final portability check。明确说明每个仓库的确切状态,不要笼统称 checkout 已同步。

7. Report

7. Report

Run this last, so the counts are the session's final state. Set
public_repository
from
Public repository
and
companion_repository
from
Private issue repository
(empty for
none
). For each other repository the session wrote to (pushed to, or opened a PR or issue in), run it again with that repository's own settings.
bash
count_open() {
  if result="$(gh api --paginate "$endpoint" --jq "$field" 2>&1)"; then
    printf '%s' "$result" | grep -c .
  else
    case "$result" in
      *disabled*|*"not enabled"*|*"no analysis found"*|*"must be enabled"*) echo disabled ;;
      *) echo "not readable" ;;
    esac
  fi
}
for column in "public $public_repository" "companion $companion_repository"; do
  read -r role repository <<< "$column"
  [ -n "$repository" ] || continue
  echo "$role open PRs: $(gh pr list -R "$repository" --state open --limit 500 --json number --jq length 2>/dev/null || echo 'not readable')"
  field='.[].number'
  for kind in dependabot code-scanning secret-scanning; do
    endpoint="repos/$repository/$kind/alerts?state=open&per_page=100"
    echo "$role $kind: $(count_open)"
  done
  if [ "$role" = public ]; then
    endpoint="repos/$repository/security-advisories?state=draft&per_page=100"
    field='.[].ghsa_id'
    echo "$role draft advisories: $(count_open)"
  elif ! labels="$(gh label list -R "$repository" --limit 500 --json name --jq '.[].name' 2>/dev/null)"; then
    echo "$role security issues: not readable"
  elif ! printf '%s\n' "$labels" | grep -qx security; then
    echo "$role security issues: no label"
  else
    gh issue list -R "$repository" --state open --label security --limit 500 --json labels --jq "
      [.[] | [.labels[].name] | any(. == \"wontfix\" or . == \"deferred-trigger\")] |
      \"$role security issues: open \(map(select(. | not)) | length), accepted risk \(map(select(.)) | length)\"" \
      2>/dev/null || echo "$role security issues: not readable"
  fi
done
Then print this template, every section every time, with
none
where there is nothing to say:
markdown
undefined
最后运行此步骤,确保计数反映会话结束时的最终状态。通过
Public repository
设置
public_repository
,通过
Private issue repository
设置
companion_repository
(值为
none
时留空)。对于本次会话写入的其他每个仓库(执行过 push,或在其中创建了 PR 或 issue),使用该仓库自身的设置再次运行。
bash
count_open() {
  if result="$(gh api --paginate "$endpoint" --jq "$field" 2>&1)"; then
    printf '%s' "$result" | grep -c .
  else
    case "$result" in
      *disabled*|*"not enabled"*|*"no analysis found"*|*"must be enabled"*) echo disabled ;;
      *) echo "not readable" ;;
    esac
  fi
}
for column in "public $public_repository" "companion $companion_repository"; do
  read -r role repository <<< "$column"
  [ -n "$repository" ] || continue
  echo "$role open PRs: $(gh pr list -R "$repository" --state open --limit 500 --json number --jq length 2>/dev/null || echo 'not readable')"
  field='.[].number'
  for kind in dependabot code-scanning secret-scanning; do
    endpoint="repos/$repository/$kind/alerts?state=open&per_page=100"
    echo "$role $kind: $(count_open)"
  done
  if [ "$role" = public ]; then
    endpoint="repos/$repository/security-advisories?state=draft&per_page=100"
    field='.[].ghsa_id'
    echo "$role draft advisories: $(count_open)"
  elif ! labels="$(gh label list -R "$repository" --limit 500 --json name --jq '.[].name' 2>/dev/null)"; then
    echo "$role security issues: not readable"
  elif ! printf '%s\n' "$labels" | grep -qx security; then
    echo "$role security issues: no label"
  else
    gh issue list -R "$repository" --state open --label security --limit 500 --json labels --jq "
      [.[] | [.labels[].name] | any(. == \"wontfix\" or . == \"deferred-trigger\")] |
      \"$role security issues: open \(map(select(. | not)) | length), accepted risk \(map(select(.)) | length)\"" \
      2>/dev/null || echo "$role security issues: not readable"
  fi
done
然后打印以下模板,每次都包含所有章节;没有内容可写时使用
none
:
markdown
undefined

End of session: <repository>, <date>

End of session: <repository>, <date>

What this session did

What this session did

  • Memory: <added, updated or deleted, each with its reason; or why this step was skipped>
  • Issues: <commented, closed, labelled or opened, by number>
  • Workspace: <deleted; kept and why; uncommitted changes, unpushed branches, running containers>
  • Settings files written: <list from step 0>
  • Handoff document: <its path, when handoff invoked this skill>
  • Not done: <everything skipped or left unfinished, and changelog debt>
  • Memory: <added, updated or deleted, each with its reason; or why this step was skipped>
  • Issues: <commented, closed, labelled or opened, by number>
  • Workspace: <deleted; kept and why; uncommitted changes, unpushed branches, running containers>
  • Settings files written: <list from step 0>
  • Handoff document: <its path, when handoff invoked this skill>
  • Not done: <everything skipped or left unfinished, and changelog debt>

Docs

Docs

  • Searched: <documents checked, the terms searched for, and where, from docs-updater's report>
  • Updated: <documents and their commit state, the companion's too, or that it was absent>
  • Drift reported, not fixed: <list>
  • Searched: <documents checked, the terms searched for, and where, from docs-updater's report>
  • Updated: <documents and their commit state, the companion's too, or that it was absent>
  • Drift reported, not fixed: <list>

Repository status

Repository status

PublicPrivate companion
Open PRs: this sessionnn
Open PRs: others and botsnn
Dependabot alertsnn
Code scanning alertsnn
Secret scanning alertsnn
Draft advisoriesnn/a
security
issues: open
n/an
security
issues: accepted risk
n/an
PublicPrivate companion
Open PRs: this sessionnn
Open PRs: others and botsnn
Dependabot alertsnn
Code scanning alertsnn
Secret scanning alertsnn
Draft advisoriesnn/a
security
issues: open
n/an
security
issues: accepted risk
n/an

Human steps before the next session

Human steps before the next session

  • <what, where, and why it blocks>
  • <what, where, and why it blocks>

Human follow-ups

Human follow-ups

  • <verified issue or wiki link, or what is unpublished and why>

- **Status cells** hold a count, `n/a`, or what the snippet printed: `disabled`, `not readable` or
  `no label`. Those three are never written as `0`: none of them says nothing is open. `this session`
  counts the PRs this session opened that are still open, and `others and bots` is the rest of the
  total. An open `security` issue also labelled `wontfix` or `deferred-trigger` is an accepted risk.
- **Columns.** Leave out the companion column when there is no companion. Each other repository
  gets its own pair, headed by its public name; a companion whose repository cannot be resolved has
  `not readable` in every cell.
- **Human steps before the next session** holds only what stops the next session: a PR to merge, an
  expired login, work to push from this machine, a decision the user owes. Tracked work with no such
  urgency is a follow-up.
- **Counts and roles only.** The security rows carry no title, identifier or package name, and the
  report names a companion by its role, never its repository. A report holding a companion's counts
  stays out of public issues, PRs and commits.

Name plainly what was not done. An accurate "these three things are still open" is the point of the
skill.
  • <verified issue or wiki link, or what is unpublished and why>

- **状态单元格**只能保存计数、`n/a` 或代码片段打印出的结果:`disabled`、`not readable` 或 `no label`。这三个值绝不能写成 `0`:它们都不表示“没有开放项”。`this session` 统计本次会话创建且仍开放的 PR;`others and bots` 是总数中的其余部分。开放的 `security` issue 如果还带有 `wontfix` 或 `deferred-trigger` 标签,则属于已接受风险。
- **列。**没有 companion 时省略 companion 列。其他每个仓库各自拥有一对列,并以公开名称作为标题;如果无法解析某个 companion 的仓库,则其每个单元格都写 `not readable`。
- **下次会话前需要人工处理的步骤**只包含会阻碍下次会话的事项:待合并的 PR、过期登录、需要从本机 push 的工作,或需要用户作出的决定。已跟踪但没有这种紧迫性的工作属于 follow-up。
- **只记录计数和角色。**security 行不得包含标题、标识符或包名;报告中 companion 只以其角色称呼,绝不写其仓库名。包含 companion 计数的报告不得进入公开 issue、PR 和 commit。

明确说明未完成的内容。准确指出“这三项仍未完成”正是本 Skill 的核心。