@fitlab-ai/agent-infra 0.11.1 → 0.11.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.
Files changed (131) hide show
  1. package/dist/bin/internal-cli.js +7 -2
  2. package/dist/lib/agent-clients/adapter.js +3 -0
  3. package/dist/lib/agent-clients/adapters/codex-lifecycle/recovery.js +234 -0
  4. package/dist/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.js +8 -35
  5. package/dist/lib/agent-clients/adapters/codex-lifecycle/store.js +1 -34
  6. package/dist/lib/agent-clients/adapters/codex.js +10 -0
  7. package/dist/lib/internal/cli-route-inventory.js +1 -1
  8. package/dist/lib/internal/manual-validation.js +22 -27
  9. package/dist/lib/internal/platform-comment.js +59 -0
  10. package/dist/lib/internal/sandbox-control.js +2 -171
  11. package/dist/lib/internal/task-artifact.js +1 -1
  12. package/dist/lib/internal/task-lifecycle.js +1 -1
  13. package/dist/lib/internal/task-operation-registry.js +7 -2
  14. package/dist/lib/internal/task-review.js +5 -5
  15. package/dist/lib/internal/task-validate.js +0 -6
  16. package/dist/lib/platform/comment-safety.js +7 -1
  17. package/dist/lib/platform/github-provider.js +13 -3
  18. package/dist/lib/platform/issue-comments.js +93 -15
  19. package/dist/lib/platform/pr-summary.js +7 -2
  20. package/dist/lib/platform/provider-contract.d.ts +2 -0
  21. package/dist/lib/platform/provider-validation.js +7 -2
  22. package/dist/lib/platform/verification-sync.js +19 -2
  23. package/dist/lib/sandbox/control/client.js +3 -44
  24. package/dist/lib/sandbox/control/executor.js +14 -117
  25. package/dist/lib/sandbox/control/finalization-response.js +8 -2
  26. package/dist/lib/sandbox/control/protocol.js +5 -64
  27. package/dist/lib/sandbox/control/server.js +29 -206
  28. package/dist/lib/sandbox/control/state.js +1 -7
  29. package/dist/lib/sandbox/control/task-view.js +2 -1
  30. package/dist/lib/task/artifact-command.js +6 -6
  31. package/dist/lib/task/codex-orchestration.js +10 -208
  32. package/dist/lib/task/commit-operation.js +3 -18
  33. package/dist/lib/task/control-authority.js +35 -44
  34. package/dist/lib/task/control-recovery.js +3 -42
  35. package/dist/lib/task/delegation-receipts.js +16 -78
  36. package/dist/lib/task/events.js +89 -237
  37. package/dist/lib/task/finalization-artifacts.js +1 -3
  38. package/dist/lib/task/finalization-state.js +2 -1
  39. package/dist/lib/task/finalization.js +208 -57
  40. package/dist/lib/task/lifecycle-execution.js +2 -11
  41. package/dist/lib/task/lifecycle.js +1 -1
  42. package/dist/lib/task/local-artifact-finalization.js +25 -242
  43. package/dist/lib/task/manual-validation-receipt.js +8 -3
  44. package/dist/lib/task/orchestration.js +12 -24
  45. package/dist/lib/task/review-command.js +0 -1
  46. package/dist/lib/task/review-finalization.js +46 -211
  47. package/dist/lifecycle-build-manifest.json +3 -3
  48. package/lib/agent-clients/adapter.ts +46 -0
  49. package/lib/agent-clients/adapters/codex-lifecycle/recovery.ts +297 -0
  50. package/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.ts +13 -33
  51. package/lib/agent-clients/adapters/codex-lifecycle/store.ts +1 -44
  52. package/lib/agent-clients/adapters/codex.ts +10 -0
  53. package/lib/internal/cli-route-inventory.ts +1 -1
  54. package/lib/internal/manual-validation.ts +22 -26
  55. package/lib/internal/platform-comment.ts +38 -0
  56. package/lib/internal/sandbox-control.ts +1 -185
  57. package/lib/internal/task-artifact.ts +1 -1
  58. package/lib/internal/task-lifecycle.ts +2 -2
  59. package/lib/internal/task-operation-registry.ts +8 -4
  60. package/lib/internal/task-review.ts +5 -5
  61. package/lib/internal/task-validate.ts +0 -5
  62. package/lib/platform/comment-safety.ts +8 -0
  63. package/lib/platform/github-provider.ts +11 -2
  64. package/lib/platform/issue-comments.ts +102 -17
  65. package/lib/platform/pr-summary.ts +10 -2
  66. package/lib/platform/provider-contract.ts +2 -0
  67. package/lib/platform/provider-validation.ts +6 -2
  68. package/lib/platform/verification-sync.ts +19 -2
  69. package/lib/sandbox/control/client.ts +5 -68
  70. package/lib/sandbox/control/executor.ts +14 -125
  71. package/lib/sandbox/control/finalization-response.ts +8 -2
  72. package/lib/sandbox/control/protocol.ts +7 -83
  73. package/lib/sandbox/control/server.ts +30 -220
  74. package/lib/sandbox/control/state.ts +1 -9
  75. package/lib/sandbox/control/task-view.ts +2 -1
  76. package/lib/task/artifact-command.ts +6 -7
  77. package/lib/task/codex-orchestration.ts +8 -241
  78. package/lib/task/commit-operation.ts +3 -23
  79. package/lib/task/control-authority.ts +39 -55
  80. package/lib/task/control-recovery.ts +3 -43
  81. package/lib/task/delegation-receipts.ts +14 -81
  82. package/lib/task/events.ts +106 -255
  83. package/lib/task/finalization-artifacts.ts +1 -3
  84. package/lib/task/finalization-state.ts +2 -1
  85. package/lib/task/finalization.ts +221 -65
  86. package/lib/task/lifecycle-execution.ts +10 -21
  87. package/lib/task/lifecycle.ts +2 -2
  88. package/lib/task/local-artifact-finalization.ts +23 -281
  89. package/lib/task/manual-validation-receipt.ts +8 -2
  90. package/lib/task/orchestration.ts +30 -53
  91. package/lib/task/review-command.ts +0 -1
  92. package/lib/task/review-finalization.ts +45 -193
  93. package/package.json +2 -2
  94. package/templates/.agents/rules/lifecycle-orchestration.en.md +23 -9
  95. package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +23 -9
  96. package/templates/.agents/rules/local-artifact-repair.en.md +14 -60
  97. package/templates/.agents/rules/local-artifact-repair.zh-CN.md +13 -60
  98. package/templates/.agents/skills/analyze-task/SKILL.en.md +3 -3
  99. package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +3 -3
  100. package/templates/.agents/skills/code-task/SKILL.en.md +3 -3
  101. package/templates/.agents/skills/code-task/SKILL.zh-CN.md +3 -3
  102. package/templates/.agents/skills/complete-manual-validation/SKILL.en.md +2 -2
  103. package/templates/.agents/skills/complete-manual-validation/SKILL.zh-CN.md +2 -2
  104. package/templates/.agents/skills/complete-task/SKILL.en.md +7 -8
  105. package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +7 -8
  106. package/templates/.agents/skills/plan-task/SKILL.en.md +3 -3
  107. package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +3 -3
  108. package/templates/.agents/skills/review-analysis/SKILL.en.md +2 -2
  109. package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +2 -2
  110. package/templates/.agents/skills/review-code/SKILL.en.md +3 -3
  111. package/templates/.agents/skills/review-code/SKILL.zh-CN.md +3 -3
  112. package/templates/.agents/skills/review-plan/SKILL.en.md +2 -2
  113. package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +2 -2
  114. package/templates/.agents/skills/run-manual-validation/SKILL.en.md +2 -2
  115. package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +2 -2
  116. package/templates/.agents/skills/run-task/SKILL.en.md +10 -9
  117. package/templates/.agents/skills/run-task/SKILL.zh-CN.md +10 -9
  118. package/templates/.agents/skills/run-task/reference/host-validation.en.md +2 -2
  119. package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +2 -2
  120. package/dist/lib/sandbox/control/task-workflow.js +0 -74
  121. package/dist/lib/sandbox/control/workflow-executor.js +0 -157
  122. package/dist/lib/task/lifecycle-recovery.js +0 -549
  123. package/dist/lib/task/recovery-warning.js +0 -19
  124. package/dist/lib/task/workflow-command.js +0 -18
  125. package/dist/lib/task/workflow-dispatch.js +0 -161
  126. package/lib/sandbox/control/task-workflow.ts +0 -95
  127. package/lib/sandbox/control/workflow-executor.ts +0 -183
  128. package/lib/task/lifecycle-recovery.ts +0 -691
  129. package/lib/task/recovery-warning.ts +0 -21
  130. package/lib/task/workflow-command.ts +0 -19
  131. package/lib/task/workflow-dispatch.ts +0 -171
@@ -1,21 +0,0 @@
1
- export type RecoveryWarning = Readonly<{ code: string; message: string; action: string }>;
2
-
3
- function warningText(value: unknown): value is string {
4
- return typeof value === 'string' && value.length > 0 && value.trim() === value && !/[\r\n]/u.test(value);
5
- }
6
-
7
- export function isRecoveryWarning(value: unknown): value is RecoveryWarning {
8
- if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
9
- const warning = value as Record<string, unknown>;
10
- return Object.keys(warning).sort().join(',') === 'action,code,message'
11
- && warningText(warning.code)
12
- && warningText(warning.message)
13
- && warningText(warning.action);
14
- }
15
-
16
- export function sameRecoveryWarning(left: unknown, right: unknown): boolean {
17
- return isRecoveryWarning(left) && isRecoveryWarning(right)
18
- && left.code === right.code
19
- && left.message === right.message
20
- && left.action === right.action;
21
- }
@@ -1,19 +0,0 @@
1
- export const TASK_WORKFLOW_COMMANDS = Object.freeze({
2
- 'artifact-inspect': ['task-artifact', 'inspect'],
3
- 'artifact-init': ['task-artifact', 'init'],
4
- 'artifact-preflight': ['task-artifact', 'preflight'],
5
- 'artifact-finalize-local': ['task-artifact', 'finalize-local'],
6
- 'review-preflight': ['task-review', 'preflight'],
7
- 'review-finalize-summary': ['task-review', 'finalize-summary'],
8
- event: ['task-event', null],
9
- 'ledger-finding-response': ['task-ledger', 'finding-respond'],
10
- 'ledger-finding-review': ['task-ledger', 'finding-review'],
11
- 'ledger-finding-upsert': ['task-ledger', 'finding-upsert'],
12
- 'decision-next-id': ['task-ledger', 'decision-next-id'],
13
- 'decision-upsert': ['task-ledger', 'decision-upsert'],
14
- 'invalidation-reconcile': ['task-invalidation', 'reconcile'],
15
- 'warning-add': ['task-warning', 'add']
16
- } as const);
17
- export type TaskWorkflowOperation = keyof typeof TASK_WORKFLOW_COMMANDS;
18
- export const TASK_WORKFLOW_OPERATIONS = Object.freeze(Object.keys(TASK_WORKFLOW_COMMANDS) as TaskWorkflowOperation[]);
19
- export type WorkflowCommand = typeof TASK_WORKFLOW_COMMANDS[TaskWorkflowOperation][0];
@@ -1,171 +0,0 @@
1
- import { reconcileTaskInvalidation } from './invalidation-command.ts';
2
- import { applyLedgerIntent } from './ledger-intents.ts';
3
- import type { LedgerIntent } from './ledger-intents.ts';
4
- import { TaskExecutionLockError, withTaskExecutionLock } from './task-execution-lock.ts';
5
- import type { TaskWorkflowOperation } from './workflow-command.ts';
6
- import { applyWorkflowWarningIntent } from './workflow-warning-intents.ts';
7
- import type { WorkflowWarningIntent } from './workflow-warning-intents.ts';
8
-
9
- export type WorkflowDispatchResult = Readonly<Record<string, unknown>>;
10
-
11
- type OptionValues = Readonly<Record<string, string | boolean>>;
12
- type DispatchFailure = Readonly<{
13
- status: 'failed';
14
- changed: false;
15
- error: Readonly<{ code: string; message: string }>;
16
- }>;
17
-
18
- function failed(code: string, message: string): DispatchFailure {
19
- return { status: 'failed', changed: false, error: { code, message } };
20
- }
21
-
22
- function isFailure(value: unknown): value is DispatchFailure {
23
- return Boolean(value) && typeof value === 'object' && (value as { status?: unknown }).status === 'failed';
24
- }
25
-
26
- function options(
27
- args: readonly string[],
28
- allowed: Readonly<Record<string, string>>
29
- ): OptionValues | DispatchFailure {
30
- const values: Record<string, string | boolean> = {};
31
- for (let index = 2; index < args.length; index += 1) {
32
- const flag = args[index]!;
33
- if (flag === '--dry-run') {
34
- if (!Object.hasOwn(allowed, flag) || values[flag] !== undefined) return failed('TASK_WORKFLOW_PAYLOAD_INVALID', `invalid option '${flag}'`);
35
- values[flag] = true;
36
- continue;
37
- }
38
- const key = allowed[flag];
39
- if (!key || values[flag] !== undefined) return failed('TASK_WORKFLOW_PAYLOAD_INVALID', `invalid option '${flag}'`);
40
- const value = args[++index];
41
- if (value === undefined || value.startsWith('--')) return failed('TASK_WORKFLOW_PAYLOAD_INVALID', `option '${flag}' requires a value`);
42
- if (flag === '--needs-implementation' && value !== 'true' && value !== 'false') {
43
- return failed('TASK_WORKFLOW_PAYLOAD_INVALID', "option '--needs-implementation' must be true or false");
44
- }
45
- values[flag] = value;
46
- }
47
- return values;
48
- }
49
-
50
- function value(values: OptionValues, flag: string): string | undefined {
51
- const candidate = values[flag];
52
- return typeof candidate === 'string' ? candidate : undefined;
53
- }
54
-
55
- function required(values: OptionValues, flags: readonly string[]): DispatchFailure | null {
56
- const missing = flags.find((flag) => value(values, flag) === undefined);
57
- return missing ? failed('TASK_WORKFLOW_PAYLOAD_INVALID', `option '${missing}' is required`) : null;
58
- }
59
-
60
- function resultForLock(error: unknown): WorkflowDispatchResult {
61
- if (error instanceof TaskExecutionLockError) return failed(error.code, error.message);
62
- throw error;
63
- }
64
-
65
- function ledgerIntent(operation: TaskWorkflowOperation, args: readonly string[]): LedgerIntent | DispatchFailure {
66
- const [taskRef, kind] = args;
67
- const mappings: Partial<Record<TaskWorkflowOperation, {
68
- kind: LedgerIntent['kind']; required: readonly string[]; flags: Readonly<Record<string, string>>;
69
- }>> = {
70
- 'ledger-finding-response': {
71
- kind: 'finding-respond', required: ['--id', '--round', '--status', '--evidence'],
72
- flags: { '--id': 'id', '--round': 'round', '--status': 'status', '--evidence': 'evidence', '--dry-run': 'dryRun' }
73
- },
74
- 'ledger-finding-review': {
75
- kind: 'finding-review', required: ['--id', '--status', '--evidence'],
76
- flags: { '--id': 'id', '--status': 'status', '--evidence': 'evidence', '--needs-implementation': 'needsImplementation', '--dry-run': 'dryRun' }
77
- },
78
- 'ledger-finding-upsert': {
79
- kind: 'finding-upsert', required: ['--stage', '--review-artifact', '--ordinal', '--severity', '--evidence'],
80
- flags: { '--stage': 'stage', '--review-artifact': 'reviewArtifact', '--ordinal': 'ordinal', '--severity': 'severity', '--evidence': 'evidence', '--dry-run': 'dryRun' }
81
- },
82
- 'decision-next-id': { kind: 'decision-next-id', required: [], flags: {} },
83
- 'decision-upsert': {
84
- kind: 'decision-upsert', required: ['--id', '--stage', '--artifact'],
85
- flags: { '--id': 'id', '--stage': 'stage', '--artifact': 'artifact', '--needs-implementation': 'needsImplementation', '--dry-run': 'dryRun' }
86
- }
87
- };
88
- const mapping = mappings[operation];
89
- if (!mapping || !taskRef || kind === undefined) return failed('TASK_WORKFLOW_PAYLOAD_INVALID', 'task workflow ledger request is invalid');
90
- const values = options(args, mapping.flags);
91
- if (isFailure(values)) return values;
92
- const missing = required(values, mapping.required);
93
- if (missing) return missing;
94
- const dryRun = values['--dry-run'] === true;
95
- if (mapping.kind === 'decision-next-id') return { kind: mapping.kind, taskRef };
96
- if (mapping.kind === 'finding-respond') return {
97
- kind: mapping.kind, taskRef, id: value(values, '--id')!, round: Number(value(values, '--round')),
98
- status: value(values, '--status') as never, evidence: value(values, '--evidence')!, ...(dryRun ? { dryRun } : {})
99
- } as LedgerIntent;
100
- if (mapping.kind === 'finding-review') return {
101
- kind: mapping.kind, taskRef, id: value(values, '--id')!, status: value(values, '--status') as never,
102
- evidence: value(values, '--evidence')!, ...(value(values, '--needs-implementation') === 'true' ? { needsImplementation: true } : {}),
103
- ...(dryRun ? { dryRun } : {})
104
- } as LedgerIntent;
105
- if (mapping.kind === 'finding-upsert') return {
106
- kind: mapping.kind, taskRef, stage: value(values, '--stage') as never, reviewArtifact: value(values, '--review-artifact')!,
107
- ordinal: Number(value(values, '--ordinal')), severity: value(values, '--severity') as never, evidence: value(values, '--evidence')!,
108
- ...(dryRun ? { dryRun } : {})
109
- } as LedgerIntent;
110
- return {
111
- kind: mapping.kind, taskRef, id: value(values, '--id')!, stage: value(values, '--stage') as never,
112
- artifact: value(values, '--artifact')!, ...(value(values, '--needs-implementation') === 'true' ? { needsImplementation: true } : {}),
113
- ...(dryRun ? { dryRun } : {})
114
- } as LedgerIntent;
115
- }
116
-
117
- function warningIntent(args: readonly string[]): WorkflowWarningIntent | DispatchFailure {
118
- const [taskRef, kind] = args;
119
- if (!taskRef || kind !== 'add') return failed('TASK_WORKFLOW_PAYLOAD_INVALID', 'task workflow warning request is invalid');
120
- const values = options(args, {
121
- '--step': 'step', '--severity': 'severity', '--code': 'code', '--target': 'target',
122
- '--message': 'message', '--action': 'action', '--dry-run': 'dryRun'
123
- });
124
- if (isFailure(values)) return values;
125
- const missing = required(values, ['--step', '--severity', '--code', '--target', '--message', '--action']);
126
- if (missing) return missing;
127
- return {
128
- kind: 'add', taskRef, step: value(values, '--step')!, severity: value(values, '--severity') as never,
129
- code: value(values, '--code')!, target: value(values, '--target')!, message: value(values, '--message')!,
130
- action: value(values, '--action')!, ...(values['--dry-run'] === true ? { dryRun: true } : {})
131
- } as WorkflowWarningIntent;
132
- }
133
-
134
- /**
135
- * The caller has already selected and authorized the execution boundary.
136
- * This function deliberately invokes task domains in that process: starting a
137
- * second CLI process would discard the broker binding and could misclassify a
138
- * sandbox process with cleared environment variables as direct-host.
139
- */
140
- export function dispatchWorkflowCommand(
141
- repoRoot: string,
142
- operation: TaskWorkflowOperation,
143
- args: readonly string[]
144
- ): WorkflowDispatchResult {
145
- const taskRef = args[0];
146
- if (!taskRef) return failed('TASK_WORKFLOW_PAYLOAD_INVALID', 'task ref is required');
147
- try {
148
- if (operation === 'invalidation-reconcile') {
149
- const values = options(args, { '--max-targets': 'maxTargets', '--dry-run': 'dryRun' });
150
- if (isFailure(values)) return values;
151
- const maxTargets = value(values, '--max-targets');
152
- if (maxTargets !== undefined && (!Number.isSafeInteger(Number(maxTargets)) || Number(maxTargets) < 1)) {
153
- return failed('TASK_WORKFLOW_PAYLOAD_INVALID', '--max-targets must be a positive integer');
154
- }
155
- return withTaskExecutionLock(repoRoot, taskRef, 'task-invalidation.reconcile', () => reconcileTaskInvalidation(taskRef, {
156
- repoRoot, ...(maxTargets === undefined ? {} : { maxTargets: Number(maxTargets) }),
157
- ...(values['--dry-run'] === true ? { dryRun: true } : {})
158
- }));
159
- }
160
- if (operation === 'warning-add') {
161
- const intent = warningIntent(args);
162
- if (isFailure(intent)) return intent;
163
- return withTaskExecutionLock(repoRoot, taskRef, 'task-warning.add', () => applyWorkflowWarningIntent(intent, { repoRoot }));
164
- }
165
- const intent = ledgerIntent(operation, args);
166
- if (isFailure(intent)) return intent;
167
- return withTaskExecutionLock(repoRoot, taskRef, `task-ledger.${intent.kind}`, () => applyLedgerIntent(intent, { repoRoot }));
168
- } catch (error) {
169
- return resultForLock(error);
170
- }
171
- }