@fitlab-ai/agent-infra 0.9.15 → 0.10.0

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.
Files changed (184) hide show
  1. package/dist/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.js +6 -2
  2. package/dist/lib/agent-clients/adapters/codex-lifecycle/store.js +43 -3
  3. package/dist/lib/fs/durable-write.js +2 -0
  4. package/dist/lib/internal/cli-route-inventory.js +1 -1
  5. package/dist/lib/internal/manual-validation.js +17 -8
  6. package/dist/lib/internal/task-artifact.js +1 -1
  7. package/dist/lib/internal/task-lifecycle.js +2 -2
  8. package/dist/lib/internal/task-operation-registry.js +0 -1
  9. package/dist/lib/internal/task-review.js +4 -4
  10. package/dist/lib/platform/issue-comments.js +16 -10
  11. package/dist/lib/platform/issues.js +1 -1
  12. package/dist/lib/platform/pr-change-report.js +5 -4
  13. package/dist/lib/platform/pr-summary.js +64 -32
  14. package/dist/lib/platform/pull-requests.js +3 -3
  15. package/dist/lib/platform/task-identities.js +2 -9
  16. package/dist/lib/platform/verification-sync.js +6 -2
  17. package/dist/lib/pr-review/evidence-grading.js +4 -8
  18. package/dist/lib/sandbox/commands/rm.js +21 -2
  19. package/dist/lib/sandbox/control/server.js +29 -9
  20. package/dist/lib/sandbox/control/state.js +7 -1
  21. package/dist/lib/sandbox/control/workflow-executor.js +4 -14
  22. package/dist/lib/sandbox/index.js +1 -2
  23. package/dist/lib/sandbox/removal.js +116 -1011
  24. package/dist/lib/sandbox/workspace-identity.js +17 -1
  25. package/dist/lib/task/artifact-command.js +6 -28
  26. package/dist/lib/task/artifact-operations.js +16 -230
  27. package/dist/lib/task/artifact-recovery.js +430 -0
  28. package/dist/lib/task/artifact-repair-intent.js +73 -39
  29. package/dist/lib/task/commit-operation.js +31 -4
  30. package/dist/lib/task/control-authority.js +38 -7
  31. package/dist/lib/task/control-recovery.js +14 -2
  32. package/dist/lib/task/create-service.js +1 -8
  33. package/dist/lib/task/delegation-receipts.js +64 -3
  34. package/dist/lib/task/events.js +164 -22
  35. package/dist/lib/task/human-override.js +5 -8
  36. package/dist/lib/task/intermediate-cleanup.js +66 -8
  37. package/dist/lib/task/lifecycle-recovery.js +549 -0
  38. package/dist/lib/task/lifecycle.js +12 -3
  39. package/dist/lib/task/local-artifact-finalization.js +148 -123
  40. package/dist/lib/task/manual-validation-receipt.js +5 -1
  41. package/dist/lib/task/orchestration.js +52 -2
  42. package/dist/lib/task/pr-delivery-fact.js +12 -56
  43. package/dist/lib/task/recovery-warning.js +19 -0
  44. package/dist/lib/task/review-command.js +1 -0
  45. package/dist/lib/task/review-finalization.js +104 -77
  46. package/dist/lib/task/short-id.js +15 -7
  47. package/dist/lib/task/task-execution-lock.js +1 -1
  48. package/dist/lib/task/verification-engine.js +3 -14
  49. package/dist/lib/task/workflow-command.js +0 -1
  50. package/dist/lib/version.js +1 -11
  51. package/dist/lifecycle-build-manifest.json +3 -3
  52. package/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.ts +7 -2
  53. package/lib/agent-clients/adapters/codex-lifecycle/store.ts +55 -3
  54. package/lib/fs/durable-write.ts +1 -0
  55. package/lib/internal/cli-route-inventory.ts +1 -1
  56. package/lib/internal/manual-validation.ts +17 -8
  57. package/lib/internal/task-artifact.ts +1 -1
  58. package/lib/internal/task-lifecycle.ts +4 -3
  59. package/lib/internal/task-operation-registry.ts +0 -1
  60. package/lib/internal/task-review.ts +4 -4
  61. package/lib/platform/issue-comments.ts +18 -10
  62. package/lib/platform/issues.ts +1 -1
  63. package/lib/platform/pr-change-report.ts +7 -5
  64. package/lib/platform/pr-summary.ts +64 -32
  65. package/lib/platform/pull-requests.ts +3 -3
  66. package/lib/platform/task-identities.ts +3 -14
  67. package/lib/platform/verification-sync.ts +6 -2
  68. package/lib/pr-review/evidence-grading.ts +4 -9
  69. package/lib/sandbox/commands/rm.ts +34 -2
  70. package/lib/sandbox/control/protocol.ts +5 -0
  71. package/lib/sandbox/control/server.ts +30 -10
  72. package/lib/sandbox/control/state.ts +9 -1
  73. package/lib/sandbox/control/workflow-executor.ts +4 -14
  74. package/lib/sandbox/index.ts +1 -2
  75. package/lib/sandbox/removal.ts +126 -1128
  76. package/lib/sandbox/workspace-identity.ts +19 -3
  77. package/lib/task/artifact-command.ts +8 -27
  78. package/lib/task/artifact-operations.ts +21 -251
  79. package/lib/task/artifact-recovery.ts +519 -0
  80. package/lib/task/artifact-repair-intent.ts +99 -51
  81. package/lib/task/commit-operation.ts +35 -4
  82. package/lib/task/control-authority.ts +47 -14
  83. package/lib/task/control-recovery.ts +13 -1
  84. package/lib/task/create-service.ts +1 -10
  85. package/lib/task/delegation-receipts.ts +73 -2
  86. package/lib/task/events.ts +187 -23
  87. package/lib/task/human-override.ts +5 -8
  88. package/lib/task/intermediate-cleanup.ts +50 -12
  89. package/lib/task/lifecycle-recovery.ts +691 -0
  90. package/lib/task/lifecycle.ts +13 -4
  91. package/lib/task/local-artifact-finalization.ts +176 -132
  92. package/lib/task/manual-validation-receipt.ts +5 -1
  93. package/lib/task/orchestration.ts +65 -0
  94. package/lib/task/pr-delivery-fact.ts +15 -62
  95. package/lib/task/recovery-warning.ts +21 -0
  96. package/lib/task/review-command.ts +1 -0
  97. package/lib/task/review-finalization.ts +106 -87
  98. package/lib/task/short-id.ts +27 -5
  99. package/lib/task/task-execution-lock.ts +1 -1
  100. package/lib/task/verification-engine.ts +3 -17
  101. package/lib/task/verification-types.ts +0 -2
  102. package/lib/task/workflow-command.ts +0 -1
  103. package/lib/version.ts +1 -15
  104. package/package.json +1 -1
  105. package/templates/.agents/rules/create-issue.en.md +1 -1
  106. package/templates/.agents/rules/create-issue.zh-CN.md +1 -1
  107. package/templates/.agents/rules/issue-sync.en.md +4 -2
  108. package/templates/.agents/rules/issue-sync.zh-CN.md +4 -3
  109. package/templates/.agents/rules/local-artifact-repair.en.md +46 -39
  110. package/templates/.agents/rules/local-artifact-repair.zh-CN.md +43 -36
  111. package/templates/.agents/skills/analyze-task/SKILL.en.md +6 -6
  112. package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +6 -6
  113. package/templates/.agents/skills/analyze-task/config/verify.en.json +1 -1
  114. package/templates/.agents/skills/analyze-task/config/verify.zh-CN.json +1 -1
  115. package/templates/.agents/skills/block-task/SKILL.en.md +2 -2
  116. package/templates/.agents/skills/block-task/SKILL.zh-CN.md +2 -2
  117. package/templates/.agents/skills/block-task/config/verify.json +1 -1
  118. package/templates/.agents/skills/cancel-task/SKILL.en.md +3 -3
  119. package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +3 -3
  120. package/templates/.agents/skills/cancel-task/config/verify.json +1 -1
  121. package/templates/.agents/skills/code-task/SKILL.en.md +7 -7
  122. package/templates/.agents/skills/code-task/SKILL.zh-CN.md +7 -7
  123. package/templates/.agents/skills/code-task/config/verify.en.json +1 -1
  124. package/templates/.agents/skills/code-task/config/verify.zh-CN.json +1 -1
  125. package/templates/.agents/skills/commit/reference/issue-metadata-sync.en.md +1 -1
  126. package/templates/.agents/skills/commit/reference/issue-metadata-sync.zh-CN.md +1 -1
  127. package/templates/.agents/skills/complete-manual-validation/SKILL.en.md +1 -1
  128. package/templates/.agents/skills/complete-manual-validation/SKILL.zh-CN.md +1 -1
  129. package/templates/.agents/skills/complete-task/SKILL.en.md +2 -2
  130. package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +2 -2
  131. package/templates/.agents/skills/complete-task/config/verify.en.json +2 -2
  132. package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +2 -2
  133. package/templates/.agents/skills/complete-task/reference/external-delivery.en.md +1 -1
  134. package/templates/.agents/skills/complete-task/reference/external-delivery.zh-CN.md +1 -1
  135. package/templates/.agents/skills/create-pr/SKILL.en.md +2 -2
  136. package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +2 -2
  137. package/templates/.agents/skills/create-pr/config/verify.json +1 -1
  138. package/templates/.agents/skills/create-pr/reference/pr-body-template.en.md +2 -2
  139. package/templates/.agents/skills/create-pr/reference/pr-body-template.zh-CN.md +2 -2
  140. package/templates/.agents/skills/create-task/SKILL.en.md +5 -5
  141. package/templates/.agents/skills/create-task/SKILL.zh-CN.md +5 -5
  142. package/templates/.agents/skills/create-task/config/verify.json +1 -1
  143. package/templates/.agents/skills/import-issue/SKILL.en.md +8 -8
  144. package/templates/.agents/skills/import-issue/SKILL.zh-CN.md +8 -8
  145. package/templates/.agents/skills/import-issue/config/verify.json +2 -2
  146. package/templates/.agents/skills/plan-task/SKILL.en.md +4 -4
  147. package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +4 -4
  148. package/templates/.agents/skills/plan-task/config/verify.en.json +1 -1
  149. package/templates/.agents/skills/plan-task/config/verify.zh-CN.json +1 -1
  150. package/templates/.agents/skills/restore-task/SKILL.en.md +2 -2
  151. package/templates/.agents/skills/restore-task/SKILL.zh-CN.md +2 -2
  152. package/templates/.agents/skills/restore-task/config/verify.json +1 -1
  153. package/templates/.agents/skills/review-analysis/SKILL.en.md +2 -2
  154. package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +2 -2
  155. package/templates/.agents/skills/review-analysis/config/verify.en.json +1 -1
  156. package/templates/.agents/skills/review-analysis/config/verify.zh-CN.json +1 -1
  157. package/templates/.agents/skills/review-analysis/reference/report-template.en.md +7 -7
  158. package/templates/.agents/skills/review-analysis/reference/report-template.zh-CN.md +6 -6
  159. package/templates/.agents/skills/review-code/SKILL.en.md +2 -2
  160. package/templates/.agents/skills/review-code/SKILL.zh-CN.md +2 -2
  161. package/templates/.agents/skills/review-code/config/verify.en.json +1 -1
  162. package/templates/.agents/skills/review-code/config/verify.zh-CN.json +1 -1
  163. package/templates/.agents/skills/review-code/reference/report-template.en.md +12 -12
  164. package/templates/.agents/skills/review-code/reference/report-template.zh-CN.md +12 -12
  165. package/templates/.agents/skills/review-plan/SKILL.en.md +2 -2
  166. package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +2 -2
  167. package/templates/.agents/skills/review-plan/config/verify.en.json +1 -1
  168. package/templates/.agents/skills/review-plan/config/verify.zh-CN.json +1 -1
  169. package/templates/.agents/skills/review-plan/reference/report-template.en.md +7 -7
  170. package/templates/.agents/skills/review-plan/reference/report-template.zh-CN.md +7 -7
  171. package/templates/.agents/skills/review-pr/config/verify.en.json +1 -1
  172. package/templates/.agents/skills/review-pr/config/verify.zh-CN.json +1 -1
  173. package/templates/.agents/skills/review-pr/reference/evidence-grading.en.md +3 -3
  174. package/templates/.agents/skills/review-pr/reference/evidence-grading.zh-CN.md +3 -3
  175. package/templates/.agents/skills/run-manual-validation/config/verify.en.json +1 -1
  176. package/templates/.agents/skills/run-manual-validation/config/verify.zh-CN.json +1 -1
  177. package/templates/.agents/skills/run-task/SKILL.en.md +1 -1
  178. package/templates/.agents/skills/run-task/SKILL.zh-CN.md +1 -1
  179. package/templates/.agents/templates/task.en.md +1 -1
  180. package/templates/.agents/templates/task.zh-CN.md +1 -1
  181. package/templates/.claude/commands/import-issue.en.md +1 -1
  182. package/templates/.claude/commands/import-issue.zh-CN.md +1 -1
  183. package/templates/.claude/commands/restore-task.en.md +1 -1
  184. package/templates/.claude/commands/restore-task.zh-CN.md +1 -1
@@ -407,10 +407,7 @@ function resourceForSnapshot(policy, options, frontmatter) {
407
407
  if (policy.producerId === 'platform.issue') {
408
408
  const identity = options.probeIssueNumber !== undefined
409
409
  ? resourceIdentity(options.probeIssueNumber)
410
- : taskIssueIdentity((frontmatter || {})) || (() => {
411
- const number = toPositiveInteger(frontmatter?.issue_number);
412
- return number === null ? null : resourceIdentity(number);
413
- })();
410
+ : taskIssueIdentity((frontmatter || {}));
414
411
  return identity ? { kind: 'issue', identity, number: resourceIdentityNumber(identity) } : null;
415
412
  }
416
413
  if (policy.producerId === 'platform.pull-request') {
@@ -481,11 +478,11 @@ async function probePlatformFailure(taskRef, policy, resolved, options) {
481
478
  }
482
479
  const issueIdentity = options.probeIssueNumber !== undefined
483
480
  ? resourceIdentity(options.probeIssueNumber)
484
- : taskIssueIdentity(frontmatter) || (() => {
485
- const number = toPositiveInteger(frontmatter.issue_number);
486
- return number === null ? null : resourceIdentity(number);
487
- })();
481
+ : taskIssueIdentity(frontmatter);
488
482
  const fact = readPrDeliveryFact(frontmatter);
483
+ if (fact.status === 'invalid') {
484
+ return error(fact.error.code, fact.error.message);
485
+ }
489
486
  const pullRequestIdentity = options.probePullRequestNumber !== undefined
490
487
  ? resourceIdentity(options.probePullRequestNumber)
491
488
  : fact.status === 'valid' && fact.fact.state === 'bound' ? fact.fact.identity.resource : null;
@@ -7,11 +7,12 @@ import { checkpointCommitMatches } from './commit-identity.js';
7
7
  import { readCheckpointIntent } from './commit-intent.js';
8
8
  import { parseTaskFrontmatter } from './frontmatter.js';
9
9
  import { readTaskFinalizationReceipt } from './finalization.js';
10
- import { readLocalArtifactFinalizationIntent, semanticDigest, sha256Content } from './local-artifact-finalization.js';
10
+ import { semanticDigest, sha256Content } from './local-artifact-finalization.js';
11
+ import { artifactRecoveryRoot, readArtifactRecoveryIntent } from './artifact-repair-intent.js';
11
12
  import { parseArtifactName } from './artifact-name.js';
12
13
  import { enumerateAllTaskDirs } from './resolve-ref.js';
13
14
  const TASK_ID_RE = /^TASK-\d{8}-\d{6}$/;
14
- const LOCAL_INTENT_RE = /^(TASK-\d{8}-\d{6})-(analysis|plan|code)-(.+\.md)\.json$/;
15
+ const LOCAL_INTENT_RE = /^(TASK-\d{8}-\d{6})-(analysis|review-analysis|plan|review-plan|code|review-code)-(.+\.md)\.json$/;
15
16
  const COMMIT_INTENT_RE = /^(TASK-\d{8}-\d{6})\.json$/;
16
17
  const AUXILIARY_ROOTS = [
17
18
  '.local-artifact-finalization-intents',
@@ -110,7 +111,7 @@ function localIntentCandidate(repoRoot, task, filePath, taskId, family, artifact
110
111
  }
111
112
  let intent;
112
113
  try {
113
- intent = readLocalArtifactFinalizationIntent(repoRoot, taskId, family, artifact);
114
+ intent = readArtifactRecoveryIntent(repoRoot, taskId, family, artifact);
114
115
  }
115
116
  catch {
116
117
  return item('LFAI-CONSUMED', taskId, filePath, 'protected', 'LFAI_SCHEMA_INVALID', identity);
@@ -129,7 +130,7 @@ function localIntentCandidate(repoRoot, task, filePath, taskId, family, artifact
129
130
  catch {
130
131
  return item('LFAI-CONSUMED', taskId, filePath, 'protected', 'ARTIFACT_UNREADABLE', identity);
131
132
  }
132
- if (intent.artifactSha256 !== sha256Content(content) || intent.semanticDigest !== semanticDigest(content)) {
133
+ if (intent.finalArtifactSha256 !== sha256Content(content) || intent.finalSemanticDigest !== semanticDigest(content)) {
133
134
  return item('LFAI-CONSUMED', taskId, filePath, 'protected', 'ARTIFACT_DIGEST_MISMATCH', identity);
134
135
  }
135
136
  const receiptReason = receiptGate(repoRoot, task, options);
@@ -254,7 +255,60 @@ function scanIntermediateCleanup(repoRoot, options = {}) {
254
255
  const candidates = scanInternal(repoRoot, options);
255
256
  return buildIntermediateCleanupReport(candidates, true);
256
257
  }
257
- function removeCandidate(candidate) {
258
+ function cleanupConsumedRecoveryFiles(repoRoot, task, candidate) {
259
+ if (candidate.kind !== 'LFAI-CONSUMED' || !candidate.taskId)
260
+ return true;
261
+ if (!task)
262
+ return false;
263
+ const match = LOCAL_INTENT_RE.exec(path.basename(candidate.path));
264
+ if (!match)
265
+ return false;
266
+ let intent;
267
+ try {
268
+ intent = readArtifactRecoveryIntent(repoRoot, candidate.taskId, match[2], match[3]);
269
+ }
270
+ catch {
271
+ return false;
272
+ }
273
+ if (!intent || intent.state !== 'consumed')
274
+ return false;
275
+ const recovery = artifactRecoveryRoot(task.taskDir, intent.recoveryOperationId);
276
+ let stat = null;
277
+ try {
278
+ stat = fs.lstatSync(recovery);
279
+ }
280
+ catch (error) {
281
+ if (errorCode(error) === 'ENOENT')
282
+ return true;
283
+ return false;
284
+ }
285
+ if (!stat.isDirectory() || stat.isSymbolicLink())
286
+ return false;
287
+ let entries;
288
+ try {
289
+ entries = fs.readdirSync(recovery, { withFileTypes: true });
290
+ }
291
+ catch {
292
+ return false;
293
+ }
294
+ for (const entry of entries) {
295
+ if (entry.isSymbolicLink() || !entry.isFile() || !['baseline.md', 'candidate.md', 'final.md', 'publish.md'].includes(entry.name))
296
+ return false;
297
+ }
298
+ try {
299
+ for (const entry of entries)
300
+ fs.unlinkSync(path.join(recovery, entry.name));
301
+ fs.rmdirSync(recovery);
302
+ const recoveryRoot = path.dirname(recovery);
303
+ if (fs.readdirSync(recoveryRoot).length === 0)
304
+ fs.rmdirSync(recoveryRoot);
305
+ return true;
306
+ }
307
+ catch (error) {
308
+ return errorCode(error) === 'ENOENT';
309
+ }
310
+ }
311
+ function removeCandidate(repoRoot, candidate, task) {
258
312
  if (candidate.disposition !== 'planned')
259
313
  return candidate;
260
314
  const root = candidate.kind === 'EMPTY-AUX-PARENT'
@@ -279,6 +333,9 @@ function removeCandidate(candidate) {
279
333
  return { ...candidate, disposition: 'protected', reason: 'PATH_IDENTITY_CHANGED' };
280
334
  if (!sameFileIdentity(expected, actual))
281
335
  return { ...candidate, disposition: 'protected', reason: 'PATH_IDENTITY_CHANGED' };
336
+ if (!cleanupConsumedRecoveryFiles(repoRoot, task, candidate)) {
337
+ return { ...candidate, disposition: 'protected', reason: 'RECOVERY_STAGING_NOT_SAFE_TO_REMOVE' };
338
+ }
282
339
  try {
283
340
  if (candidate.kind === 'EMPTY-AUX-PARENT') {
284
341
  if (fs.readdirSync(candidate.path).length !== 0)
@@ -317,6 +374,7 @@ function cleanupIntermediateUnderRemovalCoordinator(repoRoot, options = {}) {
317
374
  indexes.push(index);
318
375
  byTask.set(candidate.taskId, indexes);
319
376
  }
377
+ const tasks = inspectTaskRecords(repoRoot, new Set(byTask.keys()));
320
378
  for (const taskId of [...byTask.keys()].sort()) {
321
379
  const execute = () => {
322
380
  const refreshed = scanIntermediateCleanup(repoRoot, {
@@ -330,7 +388,7 @@ function cleanupIntermediateUnderRemovalCoordinator(repoRoot, options = {}) {
330
388
  continue;
331
389
  const current = refreshedByKey.get(intermediateCleanupKey(initialCandidate));
332
390
  items[index] = current
333
- ? removeCandidate(current)
391
+ ? removeCandidate(repoRoot, current, tasks.get(taskId))
334
392
  : { ...initialCandidate, disposition: 'protected', reason: 'CANDIDATE_NO_LONGER_ELIGIBLE' };
335
393
  }
336
394
  };
@@ -351,14 +409,14 @@ function cleanupIntermediateUnderRemovalCoordinator(repoRoot, options = {}) {
351
409
  for (const [index, candidate] of items.entries()) {
352
410
  if (candidate.taskId || candidate.disposition !== 'planned')
353
411
  continue;
354
- items[index] = removeCandidate(candidate);
412
+ items[index] = removeCandidate(repoRoot, candidate);
355
413
  }
356
414
  const knownPaths = new Set(items.map((candidate) => intermediateCleanupKey(candidate)));
357
415
  for (const candidate of scanIntermediateCleanup(repoRoot, scanOptions).items) {
358
416
  if (candidate.kind !== 'EMPTY-AUX-PARENT' || candidate.disposition !== 'planned'
359
417
  || knownPaths.has(intermediateCleanupKey(candidate)))
360
418
  continue;
361
- items.push(removeCandidate(candidate));
419
+ items.push(removeCandidate(repoRoot, candidate));
362
420
  }
363
421
  return buildIntermediateCleanupReport(items);
364
422
  }