Skip to content

Refactor/automation#19

Merged
nficano merged 5 commits into
mainfrom
refactor/automation
May 16, 2026
Merged

Refactor/automation#19
nficano merged 5 commits into
mainfrom
refactor/automation

Conversation

@nficano
Copy link
Copy Markdown
Contributor

@nficano nficano commented May 16, 2026

No description provided.

Nick Ficano and others added 5 commits May 15, 2026 09:45
Pass 6 of lint cleanup. ESLint errors: 48 -> 40.

- handleJobSubmit (163 lines, complexity 31) split into a top-level
  pipeline (rejectIfOverConcurrencyCap -> resolveSubmitAgent ->
  validateLeaseAndConstraints -> checkIdempotency ->
  acceptAndDispatchSubmit) plus dedicated helpers for each stage.
- runHandler (110 lines, 6 params, complexity 20) -> options bag
  (RunHandlerArgs) + extracts scheduleRuntimeTimeout, runAndEmitResult,
  emitHandlerFailure, wrapHandlerError, scheduleLeaseExpiry.
- createDelegateJob (94 lines, complexity 15) -> resolveDelegateAgent,
  validateDelegateLease, constructDelegateChild.
- wrapJobCtx (4 params) -> WrapJobCtxArgs options bag.
- New sibling job-runner-helpers.ts holds the module-level error
  emitters, the runtime/lease timer helpers, validateDelegateLease,
  wrapJobCtx, and forwardEventToSubscriber (re-exported from
  job-runner.ts for back-compat).

job-runner.ts: 565 -> 546 lines. job-runner-helpers.ts: 247 lines (new).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pass 7 of lint cleanup. ESLint errors: 40 -> 26.

- Extract makeHandleFromInvocation + InvocationState to client-handle.ts.
- Extract dispatchRaw + routeJobEvent + per-type handlers (session.welcome / session.error / session.ping / session.jobs / job.subscribed / job.accepted / job.event / job.result / job.error) to client-dispatch.ts. dispatchRaw shrinks from 115 lines / complexity 39 to a thin delegator.
- Extract envelope builders (hello / submit / subscribe / unsubscribe / bye) to client-envelopes.ts.
- Inline ARCPClient methods become single-purpose: connectInternal -> wireTransport + buildAdvertisedCapabilities + awaitHandshake + rejectHandshakeForAbort; submit -> registerSubmitInvocation + wireSubmitAbort; close -> rejectAllPending + clearAutoAckTimer + sendBye.

client.ts: 856 -> 612 lines (logical 446). 0 violations for client.ts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pass 8 of lint cleanup. ESLint errors: 26 -> 1 (file-size only).

SessionContext:
- send (63 lines, complexity 24, depth 4) split into persistOutbound +
  fanOutToSubscribers + forwardEnvelopeToSubscriber + maybeEmitBackPressure.
- dispatchRaw (94 lines, complexity 20) split into parseInboundFrame +
  dropPreHandshakeNonHandshake + dedupeInbound + validateInbound +
  handleUnknownTypeDisposition + invokeHandler.

ARCPServer:
- handleSessionHello (74 lines) split into authenticateHello +
  acceptFreshSession + buildWelcomePayload.
- handleResume (88 lines, complexity 15) split into validateResumeRecord +
  rebindResumedSession + rotateResumeToken + sendResumeWelcome +
  replayResumeEvents.
- registerPostHandshakeHandlers (77 lines) split into
  registerJobLifecycleHandlers + registerSessionControlHandlers +
  registerListJobsHandler + registerSubscriptionHandlers.
- handleJobCancel (48 lines) split into emitCancelTargetMissing +
  scheduleCancelGrace.
- handleListJobs (82 lines, complexity 33) split into
  buildListJobsCandidates plus new list-jobs.ts module
  (compileListJobsFilter, compareJobListEntries, paginateJobList).
- handleJobSubscribe (92 lines, complexity 21, depth 5) split into
  authorizeSubscribe + registerSubscriber + replaySubscribeHistory.

Client-dispatch:
- onSessionError (complexity 12) split into rejectAllInvocations +
  rejectAllPendingMaps. Removed unnecessary Deferred<unknown> casts.

Remaining: server.ts file-size (1115 lines vs 500 cap) — addressed in
the next commit by extracting SessionContext to its own module.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…odules

Pass 8 (final). ESLint errors: 1 -> 0.

- Extract SessionContext class to session-context.ts (455 logical
  lines). Server.ts re-exports it. Internal usage uses an aliased
  import (SessionContextCtor) so unicorn/prefer-export-from is
  satisfied without disabling.
- Extract handleListJobs + handleJobSubscribe + helpers to
  server-subscribe.ts as free functions taking ARCPServer first.
- Extract handleResume + helpers (validateResumeRecord,
  rebindResumedSession, rotateResumeToken, sendResumeWelcome,
  replayResumeEvents) to server-resume.ts. handleResume + helpers
  use options-bag args so each stays under max-params 3.
- Make resumeStore, sessions, buildWelcomePayload,
  registerPostHandshakeHandlers, makeNegotiatedCapabilities,
  bindLogger public on ARCPServer so the new sibling modules can
  call them.
- handleJobSubscribe split (extract maybeReplaySubscribeHistory) so
  the function stays under max-lines-per-function 40.

server.ts: 1115 -> 467 logical lines.

All gates green: pnpm lint (biome + eslint) clean, pnpm typecheck
clean, pnpm test all passing (105+), check:cycles clean, check:attw
clean, check:publint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…issues)

Planning and refactor planning content has moved to per-repo GitHub issues.
The 'v0.1 release-readiness' epics (#2-#9) and 'v1.1 implementation roadmap' is now tracked as issues going forward.
@nficano nficano merged commit 45d904a into main May 16, 2026
2 checks passed
@nficano nficano deleted the refactor/automation branch May 16, 2026 02:08
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