@tea-agent/loop-agent 0.16.15-beta.0 → 0.16.15

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 CHANGED
@@ -18,6 +18,54 @@
18
18
  - Pi SDK 执行长推理或大段结构化输出时不再把高频流式增量事件无界累积到内存;同一响应在多个生命周期事件中重复出现的 Token 用量只统计一次,避免 `Invalid string length` 和成本数据虚高。
19
19
  - 后端测试复合执行节点继续保持 clean environment、失败分类和 fail-closed outcome,并为 initial/final Result、repair eligibility、traceability 与 Observe 投影保留结构化运行证据。
20
20
 
21
+ ## [0.16.15] - 2026-07-20
22
+
23
+ ### 修复
24
+
25
+ - frontend-test case manifest 校验接受 `evidenceDir` 为 `testcase/frontend/evidence/<caseId>` 目录根(不必强制尾斜杠/子路径),避免生成节点写出合法目录后被 materialize 门误杀。
26
+
27
+ ## [0.16.14] - 2026-07-20
28
+
29
+ ### 修复
30
+
31
+ - `frontend-test` materialize / path audit 自动并入 `testcase/frontend/**` 与 `docs/test-reports/**`,与 hybrid frontend-test DAG 生成约束对齐,避免 TaskSpec 仅声明 `tests/e2e/**` 时 `dag run-task` 直接失败。
32
+
33
+ ## [0.16.13] - 2026-07-20
34
+
35
+ ### 修复
36
+
37
+ - backend-test 的 `finalize-effective-result` 管道在节点完成后绑定 `contracts/backend-test-result.json` 为 structured artifact,使 Outcome 投影出 `backend-test-result`,解除 FE-TEST Ready Planner 对 BE-TEST 产物门的误阻断。
38
+
39
+ ## [0.16.12] - 2026-07-20
40
+
41
+ ### 修复
42
+
43
+ - `backend-test` materialize / Git checkpoint 自动并入 `testcase/**`(与 `docs/test-reports/**`)运行时写根,避免 TaskSpec 仍写 `tests/api/**` 时绿跑无法 promote、任务卡在 Running。
44
+
45
+ ## [0.16.11] - 2026-07-20
46
+
47
+ ### 修复
48
+
49
+ - Worker 报告决策不再把条件分支的 `SKIPPED` 节点当成失败;backend-test 等混合 DAG 在 revise/repair 未选中时,只要 ERROR 不存在且 run finished,即可 `report-completed` 并进入 Outcome/promote。
50
+
51
+ ## [0.16.10] - 2026-07-20
52
+
53
+ ### 修复
54
+
55
+ - 后端测试执行合同物化会清理 `managedCommand` 中的空字符串(如 `stop: ""`),避免 near-schema 侦察输出在 strict parse 下误拦 in-process BE-TEST。
56
+
57
+ ## [0.16.9] - 2026-07-20
58
+
59
+ ### 修复
60
+
61
+ - Outcome 结构化产物声明不再绑定节点 mint-time sha256;同一路径若被后续 gate(如 backend-test traceability)就地改写,投影时以磁盘重算 hash 为准,消除 BE-TEST 完成态仍被 `artifact sha256 mismatch` 误拦。
62
+
63
+ ## [0.16.8] - 2026-07-20
64
+
65
+ ### 修复
66
+
67
+ - Outcome 投影对同一 run-owned 结构化产物路径的多次 rewrite(如 backend-test case manifest initial→final)只保留最后一次 hash 声明,避免 `artifact sha256 mismatch` 误拦已完成的 BE-TEST。
68
+
21
69
  ## [0.16.7] - 2026-07-20
22
70
 
23
71
  ### 修复
@@ -186,10 +186,6 @@ function resolvePiCliPath() {
186
186
  path.join(nvmBase, nodeVersion, 'lib', 'node_modules'),
187
187
  ].flatMap((nodeModulesRoot) => PI_CLI_PACKAGE_NAMES.map((packageName) => piCliPathFromPackageRoot(nodeModulesRoot, packageName)));
188
188
  const otherCandidates = [
189
- // Prefer the project-local Pi dependency. `npm run` adds node_modules/.bin
190
- // to PATH, but direct invocations from the DAG runner may not, so resolve
191
- // the package from the current workspace explicitly.
192
- ...PI_CLI_PACKAGE_NAMES.map((packageName) => piCliPathFromPackageRoot(path.resolve(process.cwd(), 'node_modules'), packageName)),
193
189
  // Global npm installation (non-nvm)
194
190
  ...PI_CLI_PACKAGE_NAMES.map((packageName) => piCliPathFromPackageRoot('/usr/local/lib/node_modules', packageName)),
195
191
  // Bun installation
@@ -6,6 +6,8 @@ import path from "node:path";
6
6
  import { z } from "zod";
7
7
  import { getTaskPoolRoot } from "../pool/run-store.js";
8
8
  import { assertSafeRuntimeId } from "../follow-up/paths.js";
9
+ import { expandAllowedPathsForWorkflow } from "../materialize/harness-task-materializer.js";
10
+ import { resolveWorkflow } from "../task-spec/workflow-routing.js";
9
11
  const execFileAsync = promisify(execFile);
10
12
  const checkpointSchema = z.object({
11
13
  taskId: z.string().min(1),
@@ -275,13 +277,14 @@ function auditChangedPaths(changes, taskSpec) {
275
277
  throw new Error(audit.violations[0]);
276
278
  }
277
279
  function auditChangedPathsReport(changes, taskSpec) {
280
+ const allowedPaths = expandAllowedPathsForWorkflow(resolveWorkflow(taskSpec).workflow, taskSpec.constraints.allowed_paths);
278
281
  const violations = [];
279
282
  for (const changed of changes) {
280
283
  if (/(^|\/)(\.env(?:\.|$)|[^/]*\.(?:pem|key|p12|pfx))$/i.test(changed))
281
284
  violations.push(`changed path may contain sensitive material: ${changed}`);
282
285
  else if (taskSpec.constraints.forbidden_paths.some((glob) => matchesGlob(changed, glob)))
283
286
  violations.push(`changed path is forbidden for ${taskSpec.id}: ${changed}`);
284
- else if (!taskSpec.constraints.allowed_paths.some((glob) => matchesGlob(changed, glob)))
287
+ else if (!allowedPaths.some((glob) => matchesGlob(changed, glob)))
285
288
  violations.push(`changed path is outside allowed_paths for ${taskSpec.id}: ${changed}`);
286
289
  }
287
290
  return { ok: violations.length === 0, violations };
@@ -34,13 +34,17 @@ export async function materializeTaskSpec(options) {
34
34
  }
35
35
  const paths = getTaskPaths(options.repoRoot, harnessTaskId);
36
36
  const baseConfig = await loadTaskConfig(options.repoRoot, harnessTaskId);
37
+ // backend-test hybrid DAG writes under testcase/** (pytest + md cases + helpers).
38
+ // TaskSpecs often list legacy tests/api/** surfaces; union runtime write roots so
39
+ // git checkpoint / path guard can promote green BE-TEST runs.
40
+ const allowedPaths = expandAllowedPathsForWorkflow(resolvedWorkflow.workflow, options.taskSpec.constraints.allowed_paths);
37
41
  const taskConfig = {
38
42
  ...baseConfig,
39
43
  taskId: harnessTaskId,
40
44
  title: options.taskSpec.title,
41
45
  taskKind: resolvedWorkflow.taskKind,
42
46
  featureId: options.taskSpec.feature_id,
43
- allowedPaths: options.taskSpec.constraints.allowed_paths,
47
+ allowedPaths,
44
48
  forbiddenPaths: options.taskSpec.constraints.forbidden_paths,
45
49
  hardConstraints: options.taskSpec.constraints.hard_constraints,
46
50
  complexity: mapRiskLevelToComplexity(options.taskSpec.risk_level),
@@ -312,6 +316,15 @@ function bulletLines(values) {
312
316
  return ["- None"];
313
317
  return values.map((value) => `- ${value}`);
314
318
  }
319
+ /** Union TaskSpec allowed_paths with workflow-owned write roots. */
320
+ export function expandAllowedPathsForWorkflow(workflow, allowedPaths) {
321
+ const extras = workflow === "backend-test"
322
+ ? ["testcase/**", "docs/test-reports/**"]
323
+ : workflow === "frontend-test"
324
+ ? ["testcase/frontend/**", "docs/test-reports/**"]
325
+ : [];
326
+ return Array.from(new Set([...allowedPaths, ...extras]));
327
+ }
315
328
  async function loadExistingTaskConfig(repoRoot, taskId) {
316
329
  try {
317
330
  return await loadTaskConfig(repoRoot, taskId);
@@ -39,21 +39,29 @@ function toRepoRelativePath(repoRoot, candidate) {
39
39
  function structuredArtifactsFromReport(run) {
40
40
  if (!run?.nodes)
41
41
  return [];
42
- const artifacts = [];
42
+ // Multiple gates may rewrite the same run-owned path (e.g. backend-test
43
+ // case manifest initial → final). Keep the last claim in report node order
44
+ // so projector validates against the file on disk after all rewrites.
45
+ const byPath = new Map();
43
46
  for (const node of run.nodes) {
44
- if (node.structuredArtifactPath &&
45
- node.structuredArtifactSha256 &&
46
- node.structuredArtifactSchemaId) {
47
- const identity = splitStructuredArtifactIdentity(node.structuredArtifactSchemaId);
48
- artifacts.push({
49
- path: node.structuredArtifactPath,
50
- sha256: node.structuredArtifactSha256,
51
- kind: identity.kind,
52
- schemaId: identity.schemaId,
53
- });
47
+ if (!node.structuredArtifactPath ||
48
+ !node.structuredArtifactSha256 ||
49
+ !node.structuredArtifactSchemaId) {
50
+ continue;
54
51
  }
52
+ const identity = splitStructuredArtifactIdentity(node.structuredArtifactSchemaId);
53
+ const pathKey = node.structuredArtifactPath.replace(/\\/g, "/");
54
+ // Leave sha256 empty: later DAG nodes (e.g. backend-test traceability)
55
+ // may rewrite the same run-owned path in place, invalidating the mint-time
56
+ // structuredArtifactSha256. Projector re-hashes the file on disk.
57
+ byPath.set(pathKey, {
58
+ path: pathKey,
59
+ sha256: "",
60
+ kind: identity.kind,
61
+ schemaId: identity.schemaId,
62
+ });
55
63
  }
56
- return artifacts;
64
+ return Array.from(byPath.values());
57
65
  }
58
66
  /**
59
67
  * `agent-dag` — the default standard agent DAG. No dedicated test/integration
@@ -455,7 +455,8 @@ function isPathInside(root, target) {
455
455
  const relative = path.relative(root, target);
456
456
  return relative !== "" && relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
457
457
  }
458
- function decideFromReport(workerRunId, result) {
458
+ /** Exported for unit tests: map DAG report JSON into Worker report decision. */
459
+ export function decideFromReport(workerRunId, result) {
459
460
  if (!result.ok || !result.json) {
460
461
  return {
461
462
  succeeded: false,
@@ -473,11 +474,16 @@ function decideFromReport(workerRunId, result) {
473
474
  }
474
475
  const runStatus = readString(run, "status");
475
476
  const nodes = readObjectArray(run, "nodes");
477
+ // Condition-branch SKIPPED nodes are expected on green backend-test / hybrid
478
+ // paths (e.g. revise/repair not selected). Do not treat SKIPPED as failure.
479
+ // ERROR and non-success failureCategory on executed nodes still fail closed.
476
480
  const failedNode = nodes.find((node) => {
477
481
  const status = readString(node, "status");
478
482
  const failureCategory = readString(node, "failureCategory");
483
+ if (status === "SKIPPED") {
484
+ return false;
485
+ }
479
486
  return (status === "ERROR" ||
480
- status === "SKIPPED" ||
481
487
  (Boolean(failureCategory) && failureCategory !== "success"));
482
488
  });
483
489
  if (runStatus !== "completed" && runStatus !== "finished") {
@@ -334,22 +334,50 @@ function asRecord(value) {
334
334
  * Prefer exact schema payloads; otherwise map common discovery shapes onto the
335
335
  * pytest-centric runtime contract without inventing secrets or managed commands.
336
336
  */
337
+ /** Drop empty managedCommand strings; omit block when not managed-command. */
338
+ export function sanitizeBackendTestExecutionInput(value) {
339
+ const record = asRecord(value);
340
+ if (!record)
341
+ return value;
342
+ const next = { ...record };
343
+ const managed = asRecord(record.managedCommand);
344
+ if (!managed)
345
+ return next;
346
+ const cleaned = {};
347
+ for (const key of ["start", "stop", "sourceRef"]) {
348
+ const raw = managed[key];
349
+ if (typeof raw === "string" && raw.trim())
350
+ cleaned[key] = raw.trim();
351
+ }
352
+ if (next.targetMode === "managed-command") {
353
+ next.managedCommand = cleaned;
354
+ }
355
+ else if (Object.keys(cleaned).length === 0) {
356
+ delete next.managedCommand;
357
+ }
358
+ else {
359
+ // in-process / external: optional managedCommand must not carry empty strings
360
+ next.managedCommand = cleaned;
361
+ }
362
+ return next;
363
+ }
337
364
  export function coerceBackendTestExecutionInput(value) {
338
- const direct = backendTestExecutionContractSchema.safeParse(value);
365
+ const sanitized = sanitizeBackendTestExecutionInput(value);
366
+ const direct = backendTestExecutionContractSchema.safeParse(sanitized);
339
367
  if (direct.success)
340
368
  return direct.data;
341
- const record = asRecord(value);
369
+ const record = asRecord(sanitized);
342
370
  if (!record)
343
- return value;
371
+ return sanitized;
344
372
  // Near-schema payloads (string framework + runner + testRoot) must stay fail-closed.
345
373
  // Only free-form discovery envelopes are rewritten onto the pytest contract.
346
374
  const looksSchemaShaped = typeof record.framework === "string" &&
347
375
  asRecord(record.runner) !== null &&
348
376
  typeof record.testRoot === "string";
349
377
  if (looksSchemaShaped)
350
- return value;
378
+ return sanitized;
351
379
  if (typeof record.framework === "string" && record.framework !== "pytest") {
352
- return value;
380
+ return sanitized;
353
381
  }
354
382
  const frameworkObj = asRecord(record.framework);
355
383
  const discovered = asRecord(record.discoveredFixtures);
@@ -504,7 +532,10 @@ export async function materializeBackendTestExecutionContract(input) {
504
532
  catch (error) {
505
533
  throw new Error(`invalid-output: ${error instanceof Error ? error.message : String(error)}`);
506
534
  }
507
- const candidates = [parsed, coerceBackendTestExecutionInput(parsed)];
535
+ const candidates = [
536
+ sanitizeBackendTestExecutionInput(parsed),
537
+ coerceBackendTestExecutionInput(parsed),
538
+ ];
508
539
  let accepted = null;
509
540
  let lastSchemaError = "invalid execution contract";
510
541
  let lastSecretError = "";
@@ -3685,7 +3685,8 @@ function buildFrontendTestHybridDag(sources) {
3685
3685
  " if(!Array.isArray(c.acIds)||c.acIds.length===0||c.acIds.some(a=>typeof a!=='string'||!a.trim())) throw new Error('invalid acIds');",
3686
3686
  " for(const k of ['casePath','evidenceDir']){ const v=c[k]; if(typeof v!=='string'||path.isAbsolute(v)||v.includes('..')) throw new Error('unsafe '+k); }",
3687
3687
  " if(c.casePath!=='testcase/frontend/cases/'+c.caseId+'.md') throw new Error('casePath must match caseId');",
3688
- " if(!c.evidenceDir.startsWith('testcase/frontend/evidence/'+c.caseId+'/')) throw new Error('case path escapes frontend test roots');",
3688
+ // Accept evidenceDir as case root or nested path under that root.
3689
+ " { const prefix='testcase/frontend/evidence/'+c.caseId; if(!(c.evidenceDir===prefix||c.evidenceDir.startsWith(prefix+'/'))) throw new Error('case path escapes frontend test roots'); }",
3689
3690
  " if(seenCasePath.has(c.casePath)) throw new Error('duplicate casePath'); seenCasePath.add(c.casePath);",
3690
3691
  " if(seenEvidenceDir.has(c.evidenceDir)) throw new Error('duplicate evidenceDir'); seenEvidenceDir.add(c.evidenceDir);",
3691
3692
  "}",
@@ -1,4 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { existsSync } from "node:fs";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import path from "node:path";
4
5
  import { recordDecisionEnvelopeForNode, shouldPauseOnHumanEscalation, writeHumanEscalationArtifacts, } from "./decision-envelope.js";
@@ -421,6 +422,19 @@ export async function executeDagNode(input) {
421
422
  node.structuredArtifactSha256 = createHash("sha256").update(bytes).digest("hex");
422
423
  node.structuredArtifactSchemaId = task.shell.jsonArtifactGate.schemaId;
423
424
  }
425
+ else if (task.shell?.backendTestPipeline === "finalize-effective-result") {
426
+ // Pipeline materializes contracts/backend-test-result.json without jsonArtifactGate.
427
+ // Bind it so Outcome adapters project kind=backend-test-result for Ready Planner.
428
+ const artifactPath = path.join(runDir, "contracts", "backend-test-result.json");
429
+ if (existsSync(artifactPath)) {
430
+ const bytes = await readFile(artifactPath);
431
+ node.structuredArtifactPath = artifactPath;
432
+ node.structuredArtifactSha256 = createHash("sha256")
433
+ .update(bytes)
434
+ .digest("hex");
435
+ node.structuredArtifactSchemaId = "backend-test-result-v1";
436
+ }
437
+ }
424
438
  }
425
439
  state.nodes[nodeId].nodeRecordPath = path.join(runDir, `${nodeId}.json`);
426
440
  await writeNodeRecord(runDir, nodeId, state.nodes[nodeId]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tea-agent/loop-agent",
3
- "version": "0.16.15-beta.0",
3
+ "version": "0.16.15",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "loop-agent": "bin/loop-agent.js",