(options = {})
| 40 | } |
| 41 | |
| 42 | function createLoopContract(options = {}) { |
| 43 | const id = loopId(options); |
| 44 | const command = options.command || options.action || ''; |
| 45 | const verifierCommand = options.verifierCommand || options.verify || options.verifier?.command || ''; |
| 46 | const createdAt = nowIso(options); |
| 47 | |
| 48 | return { |
| 49 | version: CONTRACT_VERSION, |
| 50 | id, |
| 51 | type: options.type || 'loop', |
| 52 | template: options.template || null, |
| 53 | title: options.title || options.goal || command || id, |
| 54 | status: normalizeStatus(options.status || 'planned'), |
| 55 | trigger: { |
| 56 | kind: options.triggerKind || options.trigger?.kind || 'manual', |
| 57 | cadence: options.cadence || options.trigger?.cadence || null, |
| 58 | command: command || null, |
| 59 | }, |
| 60 | input: { |
| 61 | source: options.inputSource || options.input?.source || 'user-request', |
| 62 | queue: options.inputQueue || options.input?.queue || null, |
| 63 | goal: options.goal || options.input?.goal || options.title || command || '', |
| 64 | }, |
| 65 | scope: { |
| 66 | description: options.scope || options.scopeDescription || options.scope?.description || 'current project', |
| 67 | paths: options.paths || options.scope?.paths || [], |
| 68 | }, |
| 69 | permissions: { |
| 70 | filesystem: options.filesystem || options.permissions?.filesystem || 'workspace-write', |
| 71 | network: options.network || options.permissions?.network || 'restricted', |
| 72 | approvals: options.approvals || options.permissions?.approvals || 'required-for-risky-actions', |
| 73 | }, |
| 74 | budget: { |
| 75 | maxAttempts: Number(options.maxAttempts || options.budget?.maxAttempts || 1), |
| 76 | maxSpend: options.maxSpend || options.budget?.maxSpend || null, |
| 77 | costPerRun: options.costPerRun || options.budget?.costPerRun || null, |
| 78 | }, |
| 79 | verifier: { |
| 80 | command: verifierCommand || null, |
| 81 | profile: options.verifierProfile || options.verifier?.profile || null, |
| 82 | required: options.verifierRequired !== undefined ? Boolean(options.verifierRequired) : Boolean(verifierCommand), |
| 83 | }, |
| 84 | retry: { |
| 85 | maxAttempts: Number(options.maxAttempts || options.retry?.maxAttempts || 1), |
| 86 | backoff: options.backoff || options.retry?.backoff || null, |
| 87 | }, |
| 88 | stopConditions: options.stopConditions || DEFAULT_STOP_CONDITIONS, |
| 89 | statePath: options.statePath || relativeLoopPath(id), |
| 90 | reviewArtifact: options.reviewArtifact || options.artifact || null, |
| 91 | recovery: { |
| 92 | rollback: options.rollback || options.recovery?.rollback || 'inspect git diff and revert loop-owned changes if needed', |
| 93 | continueCommand: options.continueCommand || options.recovery?.continueCommand || null, |
| 94 | }, |
| 95 | createdAt, |
| 96 | updatedAt: createdAt, |
| 97 | runs: options.runs || [], |
| 98 | notes: options.notes || [], |
| 99 | }; |
no test coverage detected