Repository navigation
feat(cli): context instructions scaffold — 空工作区项目指令引导(对齐 Claude Code /init 与 Codex /init) - #518
Merged
Merged
Conversation
Add 'cyberagent context instructions scaffold' — the deterministic, offline, no-model analog of Claude Code /init and Codex /init. It detects fixed root markers (reading no file contents), renders a bilingual AGENTS.md draft, and never overwrites an existing AGENTS.md or AGENTS.override.md; --print previews, --json emits the full result. The draft is untrusted workflow guidance and grants no authority. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…ject-configuration-contract family Co-Authored-By: Claude <noreply@anthropic.com>
…osition The symlink subtest only ever executed on CI Linux (Windows skips symlink creation without privilege), where the positional index assertion was wrong: go.mod sorts first in the fixed detection table, so Detected[1] is the Makefile. Look the marker up by path instead. Co-Authored-By: Claude <noreply@anthropic.com>
…ncurrent writes never truncate
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机 / Motivation
对照 Claude Code 与 Codex CLI 的功能盘点(重点核对了各自的
/init工作流):两者都能在进入项目时一键生成项目指令文件(Claude Code 生成CLAUDE.md,Codex 生成AGENTS.md),让跨会话约定从第一次任务就生效。Universal-Code 的docs/context-continuity.md已经把AGENTS.md/AGENTS.override.md/CLAUDE.md/.prayu作为一等指令源,发现、指纹、revision ledger 都已就绪,但没有任何从零引导生成这些文件的入口——新项目的操作者只能凭空手写,首版体验在这里断档。本 PR 补上这一环:
cyberagent context instructions scaffold,设计上与 Claude Code/init、Codex/init对齐,但严格遵循本仓库的确定性原则:离线、不调用模型、不读取标识文件内容。变更 / Changes
internal/projectconfig/instructions_scaffold.go(新增):go.mod、package.json及各锁文件、Cargo.toml、pyproject.toml、Gemfile、pom.xml、build.gradle(.kts)、composer.json、CMakeLists.txt、Make 系、Docker 系、README、.prayu/*、CLAUDE.md、.github/workflows;仅Lstat判断存在性,不读取内容,秘密不可能进入草稿。AGENTS.md草稿:无时间戳、无 map 迭代,输出逐字节确定并附 SHA-256;大小写变体标识(Makefile/makefile等)用os.SameFile聚合,跨平台不多报。AGENTS.md或AGENTS.override.md(含会被发现流程拒绝的空文件)时拒绝,绝不覆盖;--print始终可预览。32 KiB 上限严格小于发现流程 64 KiB 单文件上限。instructionBoundary的全部边界校验;另要求 target 本身必须是已存在的真实目录(评审 F1:否则单层缺失目标会经父目录回退写错位置——已修复并加回归)。internal/app/context_command.go/app.go:context instructions scaffold --workspace <name> [--target <dir>] [--print] [--json]接线、帮助文本;仅在args[1] == "scaffold"精确匹配时进入,不影响既有context instructions用法。docs/usage.md/docs/context-continuity.md:中英文档新增脚手架说明。docs/reviews/instructions-scaffold/:按仓库惯例记录 OCR delegate 复审(发现 F1 P1 / F2 P3 / F3 P3,全部修复并复测)与覆盖明细。安全与边界 / Safety
DiscoverInstructions复核,trust=project_workflow_untrusted,授权字段除 workflow/formatting/validation 外全 false(含测试断言)。.prayu可执行配置;仅产出一份可编辑的工作区文档。.github/workflows目录 symlink 不跟随(评审 F3 修复);标识文件 symlink 仅报告不跟随。验证 / Verification
gofmt -l无输出;go vet ./internal/projectconfig/ ./internal/app/无告警。go test -race ./internal/projectconfig/通过;go test ./internal/app/ -run Context通过(Go 1.26.5 / windows-amd64)。cmd/cyberagent端到端冒烟:workspace init→ scaffold 写入(正确检出go.mod、README.md)→ 重复写入被拒 →--print预览 →--target nonexistent明确报错 →--json可解析 →context instructions能发现草稿并给出 fingerprint。差距说明 / Gap context
除本 PR 外,与 Claude Code / Codex 逐项对照后仍存在的差距(供后续规划参考,本 PR 不涉及):侧问通道(
/btw、/side)、语音听写、输出风格定制。评审跟进 / Review follow-up
外部评审提出一处 P2:
instructions_scaffold.go先用os.Lstat判断存在性、再用os.WriteFile写入,而os.WriteFile会截断已存在文件。两个并发脚手架进程可能同时通过存在性检查,后写入者覆盖前者刚创建的AGENTS.md,与"绝不覆盖"契约冲突。修复(commit
d68fe5ea):os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644),由文件系统原子保证目标不存在;AGENTS.md的拒绝不再依赖先前的存在性预检查,AGENTS.override.md的预检查保留(脚手架自身不会创建 override)。os.ErrExist统一映射为原有拒绝文案("%s already exists in %s; scaffolding never overwrites project files (--print renders a preview)",参数不变),对外错误语义不变;AGENTS.md的拒绝时机从渲染前移到写入时,文案与参数保持不变。AGENTS.md;--print预览仍然不落盘。新增回归测试(
internal/projectconfig/instructions_scaffold_test.go):TestScaffoldProjectInstructionsNeverOverwritesExistingFiles:已有AGENTS.md(含空文件)与已有AGENTS.override.md三种情况均拒绝,错误文案逐字比对,原文件内容逐字不变。TestScaffoldProjectInstructionsConcurrentCreateWritesOnce:8 个并发写者经就绪门同时争抢同一次创建,断言恰好一个成功、其余全部得到既有拒绝文案,磁盘内容与成功者的内容及 SHA-256 完全一致(无截断、无交错)。Windows 上O_CREAT|O_EXCL映射为CREATE_NEW,确定性由文件系统保证,不依赖调度时序。复测(Go 1.26.10 / windows-amd64,commit
d68fe5ea):gofmt -l internal/projectconfig无输出;go vet ./internal/projectconfig/...通过。go test -count=3 ./internal/projectconfig/...通过;go test -race -count=1 ./internal/projectconfig/...通过。go build ./...通过。