Skip to content

refactor: consolidate handrolled infra with @cadre-dev/framework#173

Merged
jafreck merged 4 commits intomainfrom
framework-consolidation
Mar 16, 2026
Merged

refactor: consolidate handrolled infra with @cadre-dev/framework#173
jafreck merged 4 commits intomainfrom
framework-consolidation

Conversation

@jafreck
Copy link
Owner

@jafreck jafreck commented Mar 15, 2026

Summary

Reduces duplication between AAMF's handrolled infrastructure and @cadre-dev/framework by delegating to framework primitives where the API fits, and documenting where it doesn't (with suggested upstream improvements).

Changes

Token trackingTokenTracker delegates live record storage to the framework's TokenTracker, gaining per-task token breakdowns via getByTask(). Checkpoint-restored state is held in explicit restoredTotal/restoredByPhase/restoredByAgent maps (no sentinel-phase hack).

Retry executionRetryExecutor delegates the outer retry loop to the framework's generic RetryExecutor<T>, adding a withInfraRetry() inner loop for transient infrastructure errors (503, GOAWAY, connection resets) with a fast 250ms-2s backoff profiRetry executionRetryExecutor delegates the outer retry loop to ffRetry executd Retry execution — RetryExmfO**Retry execution** — RetryExecutordelegates the outer retry loop en noaRetry executi is found.

VS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code enVS Code en*ithVS Code work's trackProcess() / killAllTrackedProcesses().

Error classification — AAMF's fine-grained classifyError() now falls back to the framework's binary classifyError() for additional infra patterns, returning infra-other when the framework catches something AAMF's patterns miss.

Cost estimator / fs utils — Documented why these remain handrolled (framework gaps) with notes for when delegation becomes viable.

Test results

All 1475 tests pass across 45 test files.

@jafreck jafreck closed this Mar 15, 2026
@jafreck jafreck reopened this Mar 15, 2026
Leverage framework 0.2.1 new APIs to delegate infrastructure that
AAMF previously implemented from scratch:

- RetryExecutor: delegate to framework with computeDelay for
  infra-fast-retry, async onRetry, RETRY_ORIGINAL for recovery
- TokenTracker: delegate with loadFromAggregates() for checkpoint
  restore, gains per-task breakdowns via getByTask()
- stripVSCodeEnv: delegate to framework
- Process tracking: replace activeChildPids with framework
- classifyError: fall back to framework binary classifier
- parseAamfOutput: fall back to cadre-json extractor
@jafreck jafreck force-pushed the framework-consolidation branch from e34a874 to 809e0b9 Compare March 15, 2026 22:26
jafreck added 3 commits March 15, 2026 15:44
Replace handrolled pricing resolution/math with framework CostEstimator,
passing AAMF 50+ model pricing table via the models config. Removes
resolvePricing, WarnFn, and the three-tier fallback chain. Keeps
AMF-specific methods (projectCost, formatCost) as thin wrappers.

Framework uses per-1K pricing; AAMF table is per-1M — converted on
construction. Cache discount mapped to framework estimateDetailed
calls with manual 50% rate calculation.
…hing

Align AgentInvocation and AgentResult with @cadre-dev/framework types:
- Rename contextFile→contextPath, taskId→workItemId, phase required
- Add outputPath, timedOut, stdout, stderr, outputExists to AgentResult
- Rename tokenUsage fields: prompt→input, completion→output, drop total
- Move AAMF-specific fields to extensions (outputFiles, structuredOutput,
  outputParsed, parseError, copilotEvents, mcpConfig, kbDbPath, etc.)

Replace CliAgentRunner/CopilotRunner/ClaudeCodeRunner with framework's
AgentLauncher + CopilotBackend/ClaudeBackend (693→391 lines). AAMF's
AgentLauncher now delegates CLI spawning to the framework and only runs
post-processing: aamf-json parsing, copilot event extraction, output
file detection, and log writing.

Update buildContext to return { contextPath, outputPath } and
buildInvocation to accept the tuple. Update buildInvocation to accept the tuple. Update buildInvocation to accept the tuple. Update buildInvocation to accept the tuple. Update buildInvocation to accept the t) buildInvocation to accept the tuple. Update buildInvocation to acceps spawning are now tested by the framework.
The lockfile resolved 0.2.0 but the code depends on 0.2.1 types
(workItemId on AgentInvocation, modelOverride, extensions). CI
was failing because npm ci installed 0.2.0 from the stale lockfile.
@jafreck jafreck merged commit 7f12a72 into main Mar 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant