@tea-agent/loop-agent 0.39.0-next.1 → 0.39.0-next.3
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/CHANGELOG.md +61 -0
- package/dist/build-stamp.json +2 -2
- package/dist/commands/init-upgrade.js +97 -19
- package/dist/infrastructure/harness/atomic-write.js +2 -1
- package/dist/shared/openspec-spec.js +76 -0
- package/dist/task/config-types.js +21 -0
- package/dist/task/frontend-project-capability.js +292 -38
- package/dist/workflows/dag/failure-routing.js +9 -4
- package/dist/workflows/dag/frontend-prewrite-gate.js +230 -17
- package/dist/workflows/dag/init-hybrid.js +127 -6
- package/dist/workflows/dag/lifecycle.js +4 -0
- package/dist/workflows/dag/node-execution.js +16 -6
- package/dist/workflows/dag/report.js +6 -0
- package/dist/workflows/dag/retry-policy.js +11 -0
- package/dist/workflows/dag/types.js +24 -5
- package/dist/workflows/dag/validate.js +7 -2
- package/docs/templates/frontend-design-contract.md +40 -14
- package/docs/templates/frontend-task-constraints.md +40 -13
- package/docs/templates/frontend-task-requirement.md +54 -20
- package/package.json +1 -1
- package/skills/frontend-implementation/references/node-contracts.md +12 -11
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,46 @@
|
|
|
4
4
|
|
|
5
5
|
### 新增
|
|
6
6
|
|
|
7
|
+
- `frontend-prewrite-gate` 的 OpenSpec 读取校验支持 `task.json.frontendOpenspec` 配置:`policy` 缺省 `cited`(候选 = `requiredReadPaths` ∪ 任务源显式引用的 openspec 路径),`scan-strict` 保留止血任务后的全量必读语义;`requiredReadPaths` 中非 openspec 支持路径在生成期确定性失败
|
|
8
|
+
- 确定性引用块协议:生效 plan 输出在 fenced `json` 契约块后追加 `openspec-citations` fenced 块(每行一个 JSON `{"path","section","line"}`);gate 解析并与生效 plan/review 节点的成功 read 事件核验,新增 `openspec-citation-block-unparseable` / `openspec-not-cited` / `openspec-citation-not-read` 三个 retryable-invalid failureCode(防捏造、防遗漏)
|
|
9
|
+
- `src/shared/openspec-spec.ts` 新增 `extractTaskSourceOpenspecPaths` 纯函数(反引号内联、markdown 链接目标、裸路径 token → 归一化 → spec 过滤 → 治理子树排除 → 去重排序)
|
|
10
|
+
- 生成期把 `openspecPolicy` 与候选来源元数据(`openspecCandidateSources.declared` / `taskSourceCited` / `scanStrict`)冻结进 prewrite gate 配置;`task advance` 的 advisories 说明当前模式与候选来源
|
|
11
|
+
|
|
12
|
+
### 文档
|
|
13
|
+
|
|
14
|
+
- 新增 `docs/decisions/0014-openspec-gate-claim-verification.md`,并同步 `docs/runtime/frontend-implementation-workflow.md`、`docs/templates/frontend-task-constraints.md`、`docs/templates/frontend-design-contract.md`、`skills/frontend-implementation/references/node-contracts.md`
|
|
15
|
+
|
|
16
|
+
## [0.36.4-beta.0] - 2026-08-16
|
|
17
|
+
|
|
18
|
+
> 前端 DAG 规范上下文确定性落地(beta,发布到 `beta` dist-tag)。
|
|
19
|
+
|
|
20
|
+
### 新增
|
|
21
|
+
|
|
22
|
+
- `discoverFrontendProjectCapability` 产出 `designEvidence.classified` 语义归类:按通用目录约定(`openspec/schemas/**`、`openspec/project-specs/templates/**`、`openspec/project-specs/rules/**`、`openspec/project-specs/ui/**`、`ai_workspace/**`)把规范路径分入稳定键 `schemas` / `codeTemplate` / `rule.*` / `theme` / `component` / `uiOther` / `advisoryOther`,并进入 zod schema 校验(分区恒等式:归类值集合 == `normativePaths` 集合),重复探测稳定,不硬编码具体项目文件名
|
|
23
|
+
- 前端 contract/scout/plan/design-review 节点的 `subtask_prompt` 注入归类后的规范路径(含角色语义)并明确要求报告适用规则、命中路径/章节/行号、冲突与缺失
|
|
24
|
+
|
|
25
|
+
### 修复
|
|
26
|
+
|
|
27
|
+
- `frontend-prewrite-gate` 在 `openspecCandidatePaths` 非空时强制生效 plan/review 节点实际读取候选路径:未读 → `retryable-invalid` + 新增 `openspec-not-read` failureCode,错误信息列出未读路径;空候选(greenfield)不阻断。此前读取证据仅记录不阻断(advisory),本次真正 fail-closed
|
|
28
|
+
- OpenSpec 候选发现止血:默认排除治理子树(`harness.json.governanceRoot` → 缺省 `ai_workspace/loop-agent`),移除固定 `slice(0, 40)` 截断,`openspec/**` 排序优先于 `ai_workspace/**`,仅保留 ≥200 的显式安全上限(命中时写入 `DagSpec.advisories`,非静默丢弃);`openspec-not-read` 失败原因增加实际读取路径/候选总数/排除统计与「重新生成 DAG」归因,生成后已删除/改名的候选改为 `candidate-missing-drift` 诊断而非误报「未读」
|
|
29
|
+
|
|
30
|
+
### 文档
|
|
31
|
+
|
|
32
|
+
- `docs/templates/frontend-task-constraints.md` 把裸 `TODO` 改写为「探索协议 + 结果 schema + 缺失/冲突 fail-closed」,不再出现具体业务组件名或项目专属路径/命令
|
|
33
|
+
- `docs/templates/frontend-task-requirement.md` 与 `docs/templates/frontend-design-contract.md` 把裸 `TODO` 改写为「编写协议」三要素(要写什么 / DAG 如何消费 / 缺失/冲突时 fail-closed),并新增 `test/frontend-template-no-todo.test.ts` 扫描三个前端模板断言无裸 `TODO`
|
|
34
|
+
- `docs/runtime/frontend-implementation-workflow.md` 的项目规范归类清单改为通用目录约定 + 归类规则,删除写死的示例项目文件名
|
|
35
|
+
|
|
36
|
+
## [0.36.3-beta.0] - 2026-08-16
|
|
37
|
+
|
|
38
|
+
> 前端 DAG Mock 治理收紧(beta,发布到 `beta` dist-tag)。
|
|
39
|
+
|
|
40
|
+
### 改进
|
|
41
|
+
|
|
42
|
+
- 前端 DAG 的 Mock 策略约束注入设计评审链:`mockContextBlock`(含冻结 allowlist 的「HARD CONSTRAINT」与修复路径)现在也注入 `frontend-design-review-pi` / `frontend-plan-revision-pi` / `frontend-final-design-review-pi`,消除「design-review 按项目规范要求 native、但生成期 allowlist 冻结为 not-needed、prewrite 硬阻断」的策略断环——评审链会明确提示这是生成期契约缺口(需声明 `frontendMock.verifyCommands` 或 `policy: "required"` 后重新生成 DAG)
|
|
43
|
+
- 前端任务生成期 Mock 预警:新增 `DagSpec.advisories`,任务源提到接口/API/Mock 但 auto 模式把策略收窄为 `not-needed` 时,`task advance` 的 `warnings` 会给出可操作提示(声明 `frontendMock.verifyCommands` 或 `policy: required` 后重新生成 DAG),把契约缺口提前到生成期暴露
|
|
44
|
+
|
|
45
|
+
### 新增
|
|
46
|
+
|
|
7
47
|
- 版本发布改为三渠道:main 自动发布 npm `next`(`x.y.0-next.N`)、release 分支自动发布正式 patch 到 `release-x.y`、`latest` 仅由人工 GitHub Actions promotion 移动(支持 dry-run 与 CAS 校验)
|
|
8
48
|
- 新增 `next-release.yml` / `cut-release-line.yml` / `release-line-publish.yml` / `promote-npm-latest.yml`,删除旧每日自动 latest 发布入口
|
|
9
49
|
- 发布策略改为 branch + version + channel 矩阵(`scripts/release-channel-policy.mjs`),fail closed
|
|
@@ -49,6 +89,27 @@
|
|
|
49
89
|
- move interrupt eligibility to observability to honor kernel import boundary
|
|
50
90
|
- retry semantic intake across Pi tiers with 300s timeout
|
|
51
91
|
|
|
92
|
+
## [0.36.1-beta.0] - 2026-08-16
|
|
93
|
+
|
|
94
|
+
> 标准 DAG planner 输出超长紧凑重试(beta,发布到 `beta` dist-tag)。
|
|
95
|
+
|
|
96
|
+
### 改进
|
|
97
|
+
|
|
98
|
+
- 标准 DAG 的 planner 节点(`contract-pi` / `plan-pi`)输出超长(`output-too-large`)时自动紧凑重试:新增 `PLANNER_OUTPUT_LIMIT_RETRY_POLICY`(默认重试集合 + `output-too-large`),紧凑重试指令按节点类型区分——结构化契约节点只返回单个紧凑 JSON,普通计划节点返回最小计划(有序步骤、writeSet 边界、验证命令),并丢弃上游原文引用与长证据摘录
|
|
99
|
+
|
|
100
|
+
## [0.35.4-beta.0] - 2026-08-15
|
|
101
|
+
|
|
102
|
+
> frontend prewrite 阻断误路由修正 + Mock 契约文档落地(beta,发布到 `beta` dist-tag)。
|
|
103
|
+
|
|
104
|
+
### 改进
|
|
105
|
+
|
|
106
|
+
- prewrite 阻断导致的 writer `SKIPPED`(`skippedReason=frontend-prewrite-not-authorized`)失败路由从 `DependencyFailure`/`unblock dependency` 修正为 `ContractMismatch`/`fix-frontend-task-contract-and-regenerate-dag`;`dag report` / `dag doctor` 透传 `skippedReason`,对「Mock 策略契约缺陷需改 task.json + 重新生成 DAG」这类场景给出可操作建议,而非误导性的「解除依赖」
|
|
107
|
+
|
|
108
|
+
### 文档
|
|
109
|
+
|
|
110
|
+
- `docs/templates/frontend-task-constraints.md` 的 Mock 约束从 TODO 改为可落地契约:要求从项目**探索**实际存在的确定性 Mock 验证命令(不硬编码命令名)并声明到 `task.json.frontendMock.verifyCommands`,说明生成期 `allowedMockStrategies` 来源、`mock-strategy-outside-allowed` 是生成期契约问题(修复 = 补契约 + 重新生成 DAG,plan-revision 无法修复)
|
|
111
|
+
- `docs/runtime/frontend-implementation-workflow.md` 的 task.json 输入标准补充 Mock 契约声明、命令探索与失败恢复指引
|
|
112
|
+
|
|
52
113
|
## [0.36.0] - 2026-08-15
|
|
53
114
|
|
|
54
115
|
### 新增
|
package/dist/build-stamp.json
CHANGED
|
@@ -938,6 +938,80 @@ function changedWorkspacePaths(before, after) {
|
|
|
938
938
|
.filter((relativePath) => before[relativePath] !== after[relativePath])
|
|
939
939
|
.sort();
|
|
940
940
|
}
|
|
941
|
+
/**
|
|
942
|
+
* Generated-output prefixes treated as verification noise when git ignore
|
|
943
|
+
* rules are unavailable (non-git target). In a git repo the authoritative
|
|
944
|
+
* filter is `.gitignore` via `git check-ignore`; this list only covers the
|
|
945
|
+
* common case where a verification command such as `npm run build` writes
|
|
946
|
+
* untracked artifacts (build/dist/coverage/...) into the workspace.
|
|
947
|
+
*/
|
|
948
|
+
const WORKSPACE_NOISE_PREFIXES = [
|
|
949
|
+
"node_modules/",
|
|
950
|
+
"build/",
|
|
951
|
+
"dist/",
|
|
952
|
+
"coverage/",
|
|
953
|
+
".turbo/",
|
|
954
|
+
".next/",
|
|
955
|
+
".nuxt/",
|
|
956
|
+
".cache/",
|
|
957
|
+
".parcel-cache/",
|
|
958
|
+
".vite/",
|
|
959
|
+
"out/",
|
|
960
|
+
"target/",
|
|
961
|
+
"__pycache__/",
|
|
962
|
+
];
|
|
963
|
+
function isWorkspaceNoisePath(relative) {
|
|
964
|
+
if (relative === ".git" || relative.startsWith(".git/"))
|
|
965
|
+
return true;
|
|
966
|
+
if (relative === RUN_ROOT || relative.startsWith(`${RUN_ROOT}/`))
|
|
967
|
+
return true;
|
|
968
|
+
return WORKSPACE_NOISE_PREFIXES.some((prefix) => relative === prefix.slice(0, -1) || relative.startsWith(prefix));
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Filters changed workspace paths down to meaningful (non-generated) changes
|
|
972
|
+
* so a verification command that legitimately writes git-ignored artifacts is
|
|
973
|
+
* not misjudged as an unauthorized workspace mutation. Git ignore rules are
|
|
974
|
+
* authoritative when the target is a git repo; otherwise the built-in
|
|
975
|
+
* generated-output prefixes apply.
|
|
976
|
+
*/
|
|
977
|
+
async function filterWorkspaceNoise(repoRoot, relativePaths) {
|
|
978
|
+
const builtinFiltered = relativePaths.filter((relative) => !isWorkspaceNoisePath(relative));
|
|
979
|
+
if (builtinFiltered.length === 0)
|
|
980
|
+
return builtinFiltered;
|
|
981
|
+
const ignored = await gitIgnoredPaths(repoRoot, builtinFiltered);
|
|
982
|
+
if (ignored === null)
|
|
983
|
+
return builtinFiltered;
|
|
984
|
+
return builtinFiltered.filter((relative) => !ignored.has(relative));
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Returns the subset of paths matched by git ignore rules, or null when the
|
|
988
|
+
* target is not a git repository (or git is unavailable), in which case the
|
|
989
|
+
* caller falls back to the built-in noise prefixes.
|
|
990
|
+
*/
|
|
991
|
+
async function gitIgnoredPaths(repoRoot, relativePaths) {
|
|
992
|
+
return await new Promise((resolve) => {
|
|
993
|
+
execFile("git", ["-C", repoRoot, "check-ignore", ...relativePaths], {
|
|
994
|
+
timeout: 15_000,
|
|
995
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
996
|
+
windowsHide: true,
|
|
997
|
+
}, (error, stdout) => {
|
|
998
|
+
if (error) {
|
|
999
|
+
// `git check-ignore` exits 1 when no path is ignored: that is a
|
|
1000
|
+
// successful lookup with an empty result set. Any other failure
|
|
1001
|
+
// (e.g. 128 outside a repo) means the git filter is unavailable.
|
|
1002
|
+
if (error.code === 1 && stdout.length === 0)
|
|
1003
|
+
resolve(new Set());
|
|
1004
|
+
else
|
|
1005
|
+
resolve(null);
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
resolve(new Set(stdout
|
|
1009
|
+
.split("\n")
|
|
1010
|
+
.filter(Boolean)
|
|
1011
|
+
.map((entry) => entry.split(path.sep).join("/"))));
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
941
1015
|
function isFrozenVerificationSurface(value) {
|
|
942
1016
|
return (isRecord(value) &&
|
|
943
1017
|
value.schemaVersion === 1 &&
|
|
@@ -1587,7 +1661,7 @@ async function validateContinueMerge(directory, state, anchor) {
|
|
|
1587
1661
|
await assertSafeMergePath(state.repoRoot, allowedPath);
|
|
1588
1662
|
}
|
|
1589
1663
|
const current = await snapshotWorkspace(state.repoRoot);
|
|
1590
|
-
const
|
|
1664
|
+
const rawChanged = changedWorkspacePaths(authoritativeGuard.baselineWorkspace, current);
|
|
1591
1665
|
const pending = await readPendingAcceptance({
|
|
1592
1666
|
directory,
|
|
1593
1667
|
state,
|
|
@@ -1602,6 +1676,10 @@ async function validateContinueMerge(directory, state, anchor) {
|
|
|
1602
1676
|
pending,
|
|
1603
1677
|
})
|
|
1604
1678
|
: undefined;
|
|
1679
|
+
// Only the out-of-bound drift check treats git-ignored/generated-output
|
|
1680
|
+
// changes as noise; allowed-path changes are merge content and must stay
|
|
1681
|
+
// intact even when the target is git-ignored (e.g. `.agents/skills/*`).
|
|
1682
|
+
const changed = await filterWorkspaceNoise(state.repoRoot, rawChanged);
|
|
1605
1683
|
const unexpected = changed.filter((relativePath) => {
|
|
1606
1684
|
if (allowed.has(relativePath))
|
|
1607
1685
|
return false;
|
|
@@ -1611,7 +1689,7 @@ async function validateContinueMerge(directory, state, anchor) {
|
|
|
1611
1689
|
if (unexpected.length > 0) {
|
|
1612
1690
|
throw new Error(`init upgrade merge write-guard blocked out-of-bound workspace changes: ${unexpected.join(", ")}`);
|
|
1613
1691
|
}
|
|
1614
|
-
const changedAllowed =
|
|
1692
|
+
const changedAllowed = rawChanged.filter((relativePath) => allowed.has(relativePath));
|
|
1615
1693
|
if (changedAllowed.length === 0) {
|
|
1616
1694
|
if (pending) {
|
|
1617
1695
|
throw new Error("pending merge acceptance cannot authorize a merge without an allowed workspace change");
|
|
@@ -1834,16 +1912,8 @@ async function createVerificationWriteAudit(input) {
|
|
|
1834
1912
|
const note = (scope, file) => {
|
|
1835
1913
|
events.push(`${scope}=${file.split(path.sep).join("/")}`);
|
|
1836
1914
|
};
|
|
1837
|
-
const ignoredWorkspacePath = (candidate) =>
|
|
1838
|
-
|
|
1839
|
-
return (relative === ".git" ||
|
|
1840
|
-
relative.startsWith(".git/") ||
|
|
1841
|
-
relative === "node_modules" ||
|
|
1842
|
-
relative.startsWith("node_modules/") ||
|
|
1843
|
-
relative === RUN_ROOT ||
|
|
1844
|
-
relative.startsWith(`${RUN_ROOT}/`));
|
|
1845
|
-
};
|
|
1846
|
-
const install = async (scope, directory, ignore) => {
|
|
1915
|
+
const ignoredWorkspacePath = (candidate) => isWorkspaceNoisePath(toRepoPath(canonicalRepoRoot, candidate));
|
|
1916
|
+
const install = async (scope, directory, ignore, scopeRoot) => {
|
|
1847
1917
|
const canonical = await realpath(directory);
|
|
1848
1918
|
if (watched.has(canonical))
|
|
1849
1919
|
return;
|
|
@@ -1867,11 +1937,11 @@ async function createVerificationWriteAudit(input) {
|
|
|
1867
1937
|
// traversal opens an existing child directory. Nested watchers own real
|
|
1868
1938
|
// mutations below that child; persistent changes are also snapshot-checked.
|
|
1869
1939
|
if (!existingDirectory) {
|
|
1870
|
-
note(scope, path.relative(directory, candidate) || ".");
|
|
1940
|
+
note(scope, path.relative(scopeRoot ?? directory, candidate) || ".");
|
|
1871
1941
|
}
|
|
1872
1942
|
// A parent rename can introduce a new directory. Installing its watcher
|
|
1873
1943
|
// closes the delayed-descendant gap even when the container event is noise.
|
|
1874
|
-
void install(scope, candidate, ignore).catch((error) => {
|
|
1944
|
+
void install(scope, candidate, ignore, scopeRoot).catch((error) => {
|
|
1875
1945
|
const code = error.code;
|
|
1876
1946
|
if (code !== "ENOENT" && code !== "ENOTDIR") {
|
|
1877
1947
|
failures.push(`watcher refresh failed for ${scope}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1891,10 +1961,10 @@ async function createVerificationWriteAudit(input) {
|
|
|
1891
1961
|
const child = path.join(canonical, entry.name);
|
|
1892
1962
|
if (ignore?.(child) || !entry.isDirectory() || entry.isSymbolicLink())
|
|
1893
1963
|
continue;
|
|
1894
|
-
await install(scope, child, ignore);
|
|
1964
|
+
await install(scope, child, ignore, scopeRoot);
|
|
1895
1965
|
}
|
|
1896
1966
|
};
|
|
1897
|
-
await install("workspace", canonicalRepoRoot, ignoredWorkspacePath);
|
|
1967
|
+
await install("workspace", canonicalRepoRoot, ignoredWorkspacePath, canonicalRepoRoot);
|
|
1898
1968
|
await install("controller", runRoot(input.repoRoot));
|
|
1899
1969
|
await install("controller-anchor", anchor.anchorRoot);
|
|
1900
1970
|
const piHomeEntry = await lstat(piHome).catch((error) => {
|
|
@@ -2194,17 +2264,25 @@ async function runVerificationCommand(input) {
|
|
|
2194
2264
|
if (audit.failures.length)
|
|
2195
2265
|
throw new Error(audit.failures.join("; "));
|
|
2196
2266
|
await assertFrozenVerificationSurface(repoRoot, surface);
|
|
2197
|
-
const changedWorkspace = changedWorkspacePaths(workspaceBefore, await snapshotWorkspace(repoRoot));
|
|
2267
|
+
const changedWorkspace = await filterWorkspaceNoise(repoRoot, changedWorkspacePaths(workspaceBefore, await snapshotWorkspace(repoRoot)));
|
|
2198
2268
|
const changedController = changedWorkspacePaths(controllerBefore, await snapshotDirectory(runRoot(repoRoot)));
|
|
2199
2269
|
const changedAnchors = changedWorkspacePaths(anchorBefore, await controllerAnchorSnapshot(repoRoot, state));
|
|
2200
2270
|
const changedPiHome = changedWorkspacePaths(piHomeBefore, await snapshotOptionalDirectory(path.join(os.homedir(), ".pi")));
|
|
2201
|
-
|
|
2271
|
+
// Workspace watcher events are repo-root relative (see scopeRoot in
|
|
2272
|
+
// createVerificationWriteAudit); drop git-ignored/generated-output noise
|
|
2273
|
+
// before deciding whether the subprocess wrote the workspace.
|
|
2274
|
+
const workspaceEvents = audit.events.filter((event) => event.startsWith("workspace="));
|
|
2275
|
+
const remainingEvents = [
|
|
2276
|
+
...audit.events.filter((event) => !event.startsWith("workspace=")),
|
|
2277
|
+
...(await filterWorkspaceNoise(repoRoot, workspaceEvents.map((event) => event.slice("workspace=".length)))).map((relative) => `workspace=${relative}`),
|
|
2278
|
+
];
|
|
2279
|
+
if (descendantsObserved || remainingEvents.length || changedWorkspace.length || changedController.length || changedAnchors.length || changedPiHome.length) {
|
|
2202
2280
|
return {
|
|
2203
2281
|
...result,
|
|
2204
2282
|
ok: false,
|
|
2205
2283
|
stderr: boundedOutput(`${result.stderr}\nverification write guard blocked changes: ${[
|
|
2206
2284
|
...(descendantsObserved ? ["process-tree=descendant"] : []),
|
|
2207
|
-
...(
|
|
2285
|
+
...(remainingEvents.length ? [`events=${remainingEvents.join(",")}`] : []),
|
|
2208
2286
|
...(changedWorkspace.length ? [`workspace=${changedWorkspace.join(",")}`] : []),
|
|
2209
2287
|
...(changedController.length ? [`controller=${changedController.join(",")}`] : []),
|
|
2210
2288
|
...(changedAnchors.length ? [`controller-anchor=${changedAnchors.join(",")}`] : []),
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { copyFile, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { assertHarnessWriteAllowed, } from "./completed-facts-guard.js";
|
|
4
|
+
let atomicWriteSequence = 0;
|
|
4
5
|
async function writeAtomic(targetPath, content, options) {
|
|
5
6
|
assertHarnessWriteAllowed(targetPath, options);
|
|
6
7
|
const resolved = options?.repoRoot && !path.isAbsolute(targetPath)
|
|
7
8
|
? path.resolve(options.repoRoot, targetPath)
|
|
8
9
|
: path.resolve(targetPath);
|
|
9
10
|
await mkdir(path.dirname(resolved), { recursive: true });
|
|
10
|
-
const tempPath = `${resolved}.${process.pid}.tmp`;
|
|
11
|
+
const tempPath = `${resolved}.${process.pid}.${(atomicWriteSequence += 1)}.tmp`;
|
|
11
12
|
try {
|
|
12
13
|
await writeFile(tempPath, content, "utf-8");
|
|
13
14
|
try {
|
|
@@ -14,6 +14,30 @@ export const OPENSPEC_SPEC_DIRS = [
|
|
|
14
14
|
];
|
|
15
15
|
/** Allowed spec file extensions (case-insensitive). */
|
|
16
16
|
export const OPENSPEC_SPEC_EXT_RE = /\.(md|mdx|json|yaml|yml)$/i;
|
|
17
|
+
/**
|
|
18
|
+
* Default governance subtree excluded from candidate discovery. Aligned with
|
|
19
|
+
* init.ts's DEFAULT_GOVERNANCE_ROOT; discovery derives the real root from
|
|
20
|
+
* harness.json.governanceRoot and falls back to this value.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_OPENSPEC_GOVERNANCE_ROOT = "ai_workspace/loop-agent";
|
|
23
|
+
/**
|
|
24
|
+
* Explicit safety ceiling for auto-discovered openspec candidates (>=200).
|
|
25
|
+
* Reaching the cap is reported via DagSpec.advisories, never silently dropped.
|
|
26
|
+
*/
|
|
27
|
+
export const MAX_OPENSPEC_CANDIDATE_PATHS = 200;
|
|
28
|
+
/**
|
|
29
|
+
* Returns `true` when `filePath` is the governance subtree itself or any path
|
|
30
|
+
* under it. `filePath` must be a repo-relative POSIX path (backslashes are
|
|
31
|
+
* normalised internally). Comparison is case-sensitive, matching the other
|
|
32
|
+
* predicates in this module.
|
|
33
|
+
*/
|
|
34
|
+
export function isGovernanceSubtreePath(filePath, governanceRoot) {
|
|
35
|
+
const normalized = filePath.replaceAll("\\", "/");
|
|
36
|
+
const root = governanceRoot.replaceAll("\\", "/").replace(/\/+$/, "");
|
|
37
|
+
if (!root)
|
|
38
|
+
return false;
|
|
39
|
+
return normalized === root || normalized.startsWith(root + "/");
|
|
40
|
+
}
|
|
17
41
|
/**
|
|
18
42
|
* Returns `true` when `filePath` is inside one of the canonical frontend spec
|
|
19
43
|
* directories. `filePath` must be a repo-relative POSIX path (backslashes are
|
|
@@ -47,3 +71,55 @@ export function isOpenspecSpecSearchTarget(value) {
|
|
|
47
71
|
const normalized = value.replaceAll("\\", "/");
|
|
48
72
|
return /(?:^|[^A-Za-z0-9_.-])(?:openspec\/(?:schemas|project-specs)|ai_workspace)(?:\/|$)/.test(normalized);
|
|
49
73
|
}
|
|
74
|
+
/** Normalizes a free-form path token to a repo-relative POSIX path or null. */
|
|
75
|
+
function normalizeCitationToken(raw) {
|
|
76
|
+
let token = raw.trim();
|
|
77
|
+
token = token.replace(/^[<"'`(\[\s]+|[>"'`)\]\s]+$/g, "");
|
|
78
|
+
// Strip trailing punctuation that is not part of a filename.
|
|
79
|
+
token = token.replace(/[),.;:!?]+$/g, "");
|
|
80
|
+
const hashIndex = token.indexOf("#");
|
|
81
|
+
if (hashIndex >= 0)
|
|
82
|
+
token = token.slice(0, hashIndex);
|
|
83
|
+
token = token.replace(/\\/g, "/");
|
|
84
|
+
if (!token)
|
|
85
|
+
return null;
|
|
86
|
+
return token;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Deterministically extracts repo-relative openspec spec paths explicitly cited
|
|
90
|
+
* in task-source markdown (requirement + execution constraint). Pure function,
|
|
91
|
+
* no IO.
|
|
92
|
+
*
|
|
93
|
+
* Scanned sources, in order:
|
|
94
|
+
* - backtick inline code spans (`path`)
|
|
95
|
+
* - markdown link targets ([text](path))
|
|
96
|
+
* - bare path tokens under openspec/ or ai_workspace/
|
|
97
|
+
*
|
|
98
|
+
* Every token is normalized to POSIX, stripped of a trailing `#fragment`,
|
|
99
|
+
* filtered through `isOpenspecSpecFilePath`, and excluded when it falls inside
|
|
100
|
+
* the governance subtree (matching `listOpenspecDiscovery`'s exclusion口径).
|
|
101
|
+
* Results are deduped and sorted.
|
|
102
|
+
*/
|
|
103
|
+
export function extractTaskSourceOpenspecPaths(markdown, governanceRoot = DEFAULT_OPENSPEC_GOVERNANCE_ROOT) {
|
|
104
|
+
if (!markdown)
|
|
105
|
+
return [];
|
|
106
|
+
const raw = new Set();
|
|
107
|
+
const collect = (token) => {
|
|
108
|
+
const normalized = normalizeCitationToken(token);
|
|
109
|
+
if (normalized)
|
|
110
|
+
raw.add(normalized);
|
|
111
|
+
};
|
|
112
|
+
for (const match of markdown.matchAll(/`([^`\n]+)`/g)) {
|
|
113
|
+
collect(match[1] ?? "");
|
|
114
|
+
}
|
|
115
|
+
for (const match of markdown.matchAll(/\[[^\]]*\]\(([^)\s]+)\)/g)) {
|
|
116
|
+
collect(match[1] ?? "");
|
|
117
|
+
}
|
|
118
|
+
for (const match of markdown.matchAll(/(?:^|[\s"'([>])((?:openspec|ai_workspace)\/[A-Za-z0-9._/-]+)/g)) {
|
|
119
|
+
collect(match[1] ?? "");
|
|
120
|
+
}
|
|
121
|
+
return [...raw]
|
|
122
|
+
.filter((token) => isOpenspecSpecFilePath(token) &&
|
|
123
|
+
!isGovernanceSubtreePath(token, governanceRoot))
|
|
124
|
+
.sort();
|
|
125
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { isOpenspecSpecFilePath } from "../shared/openspec-spec.js";
|
|
2
3
|
export const taskFlowSchema = z.enum([
|
|
3
4
|
"auto",
|
|
4
5
|
"micro",
|
|
@@ -65,6 +66,24 @@ export const frontendMockConfigSchema = z.object({
|
|
|
65
66
|
serviceRoot: z.string().min(1).optional(),
|
|
66
67
|
verifyCommands: z.array(frontendMockVerifyCommandSchema).optional().default([]),
|
|
67
68
|
});
|
|
69
|
+
/** OpenSpec gate policy for frontend prewrite: cited (default) vs scan-strict. */
|
|
70
|
+
export const frontendOpenspecPolicySchema = z.enum(["cited", "scan-strict"]);
|
|
71
|
+
/**
|
|
72
|
+
* Frontend OpenSpec gate configuration. `cited` (the task-config default) makes
|
|
73
|
+
* the prewrite gate verify contract-declared requiredReadPaths plus task-source
|
|
74
|
+
* citations instead of the full generation-time directory snapshot; `scan-strict`
|
|
75
|
+
* keeps the auto-discovered full-read semantics.
|
|
76
|
+
*/
|
|
77
|
+
export const frontendOpenspecConfigSchema = z.object({
|
|
78
|
+
policy: frontendOpenspecPolicySchema.optional().default("cited"),
|
|
79
|
+
requiredReadPaths: z
|
|
80
|
+
.array(z
|
|
81
|
+
.string()
|
|
82
|
+
.refine((candidate) => !candidate.includes("\\") &&
|
|
83
|
+
isOpenspecSpecFilePath(candidate), "frontendOpenspec.requiredReadPaths entries must be repo-relative supported files under openspec/schemas/, openspec/project-specs/, or ai_workspace/"))
|
|
84
|
+
.optional()
|
|
85
|
+
.default([]),
|
|
86
|
+
});
|
|
68
87
|
/** Batch limits and gate profile for the browser-driven frontend test DAG.
|
|
69
88
|
* Token fields are post-case stop thresholds, not model-provider hard caps. */
|
|
70
89
|
export const frontendTestConfigSchema = z.object({
|
|
@@ -175,6 +194,8 @@ const taskConfigObjectSchema = z.object({
|
|
|
175
194
|
frontendMock: frontendMockConfigSchema.optional(),
|
|
176
195
|
/** Frontend browser-test batch and post-case token-stop configuration. */
|
|
177
196
|
frontendTest: frontendTestConfigSchema.optional(),
|
|
197
|
+
/** Frontend OpenSpec gate policy and contract-declared required read paths. */
|
|
198
|
+
frontendOpenspec: frontendOpenspecConfigSchema.optional(),
|
|
178
199
|
notes: z.string().optional().default(""),
|
|
179
200
|
});
|
|
180
201
|
export const taskConfigSchema = z.preprocess((raw) => {
|