chore(yun-tianming): collapse duplicated signing, retry and cache blocks
Summary
src/commands/domain.ts: the three-way copy of "which project signs this org mutation in agent mode" (domainDelegate,zoneDelegate,zoneRelease) is now one local helper,signingScope, carrying the constraint comment once. The doc comment describingzoneDelegatewas attached to theorgArgOfconst declared between them; the const now sits above the comment so the doc lands on the function it describes. The inline--orgsuffix indomainDelegate's watch hint now uses the existingorgArgOf.src/commands/github.ts: the byte-identical 429-tolerant pollcatchinauthorizeTerminalandfindCallerRepois one local helper,backOff, that rethrows a non-429ApiErrorand returns the next interval.src/commands/upgrade.ts: the read-merge-write cache expression repeated inupgrade(twice) andbackgroundCheckis one local helper,recordLatest, returning the written cache sobackgroundCheckkeeps using it.src/commands/postgres.ts:resolveDbUrlreuses the module's existingresolvePostgresinstead of repeating its two lines;resolvePostgrestakes the same structural{ request }typeresolveDbUrlalready accepts.src/commands/ssh-config.ts:planCertAuthorityran the pureisSupersededAnchorpredicate over every line twice to build the removed set and then its complement; the kept lines are now collected in the same pass.src/agent.ts:agentHeaderscalled the purecanonicalTarget(path)twice; the single result is hoisted above the first use.
Safety
- domain.ts
signingScope— duplicate collapse: the three copies were textually identical (samedeps?.project ?? readProject()fallback, same org check, sameprojectId ? { projectId } : undefinedshape);readProjectis still awaited beforerawRequest, as before.test/domain.test.tsandtest/zone.test.tsassert the exact scope ({ projectId: 'p1' }orundefined) for matched and mismatched--org. - domain.ts doc-comment /
orgArgOfreorder — pure refactor, reorder declarations of a non-exportedconst; it is only called at runtime after module evaluation, so the TDZ is unaffected.orgArgOf(opts)is the same expression the hint inlined;test/domain.test.tschecks the hint carries--org org9. - github.ts
backOff— duplicate collapse: both catch blocks were byte-identical apart from a comment; the helper preserves "non-429ApiErrorrethrows, anything else backs off by 5s".test/github-connect.test.tsexercises bothauthorizeTerminalandfindCallerRepo. - upgrade.ts
recordLatest— duplicate collapse: identical modulo the variable name; the same object is written and returned.test/upgrade-resolver.test.tsandtest/upgrade.test.tsrunupgradeandbackgroundCheckagainst a temp cache file and assert its contents. - postgres.ts
resolveDbUrl→resolvePostgres— duplicate collapse: both statements were identical (GET /services${q(branch)}thenresolveSoleService(..., 'postgres', service)); the widened parameter type is on a non-exported function.test/db-url.test.ts,test/db-query.test.ts(resolveDbUrl) andtest/postgres-access.test.ts(resolvePostgres viadbPublicAccess/dbPrivateAccess) cover both callers. - ssh-config.ts
planCertAuthority— redundant work removed:isSupersededAnchoris a pure string predicate, so the complement of the removed set is the kept set by construction; order ofkeptis unchanged. Theknown_hosts trust anchor,an anchor rotation can be taken backandmatched field by fieldsuites intest/ssh-config.test.ts(26 tests) ran, not skipped. - agent.ts
canonicalTargethoist — redundant work removed:canonicalTargetis pure (new URLwith a fixed base); it was already evaluated before the/agent/sessionscheck in every path, so a throw happens at the same point.test/agent.test.ts(10 tests) covers bootstrap, project-route and scoped paths.
Verification
Baseline on the untouched tree:
npm run typecheck # exit 0
npm test # 106 files, 2110 passed | 135 skipped, ~31s
Final tree:
npm run typecheck # exit 0
npm test # 106 files, 2110 passed | 135 skipped, ~30s
Targeted runs after each edit: npx vitest run test/domain.test.ts test/zone.test.ts test/agent.test.ts test/github-connect.test.ts test/upgrade-resolver.test.ts test/upgrade.test.ts test/ssh-config.test.ts test/ssh-known-hosts-injection.test.ts test/db-url.test.ts test/postgres-access.test.ts test/db-query.test.ts → 392 passed, 18 skipped (the 18 are the ssh -G block, skipped because ssh is not installed here).
The 135 skips are pre-existing: ssh-keygen and ssh are absent on this machine, so the keygen-gated describe blocks in test/ssh-orchestration.test.ts and the ssh -G block in test/ssh-config.test.ts do not run. There is no lint script. No suite needs a database or Docker.
Deferred findings
src/commands/project.tsresolveProjectName(defect): splitscwdandhomedir()on/only. On Windows (C:\Users\alice\myapp) the whole path becomes one segment, so the project is created asc-users-alice-myappand the generic-directory and home-directory guards never trigger.test/create-name.test.tsonly uses POSIX paths. A fix (path.basename) changes the created name, so it is the owners' call.src/commands/postgres.ts: the branch/group query-string preamble is repeated indbAlwaysOn,dbLimits,dbStats,dbVolume,dbRestart(andsettingsSuffixis a sixth variant), and the "no manageable instance" guard appears four times with slightly different wording. Those command bodies callApiClient.load()/requireProject()directly and are not exercised by any test (only their pure helpers are), so left alone.src/commands/compute.tssetDomain/checkDomain: the 409 →domainConflictMessagemapping line is byte-identical in both, andremoveDomainrepeats the preamble. Covered by the domain-flow tests, but the gain is one line in a 2200-line file; left for a sweep that touches that area.src/commands/auth.tsloginOauth/loginDevice: identical five-line tail (doublesetSession,/me,persist, same printed line).loginOauth's body has no direct test; not refactored.src/commands/services.tsservicesRemove/servicesRenameandsrc/commands/storage.tsstorageGet/storageDelete/storageSetAccess: identical preambles, command bodies not covered by tests; not refactored.src/commands/setup.tsopenPromptInputvscanPromptViaTty: two helpers encode the same stdin-TTY / win32 //dev/ttydecision in the same order and can drift apart;canPromptViaTtyhas no direct test.src/ensure-skills.tsimportsresolveSpawnablethrough thecommands/setup.tsre-export rather than fromsrc/spawn.ts; a cross-module import change, so not touched.src/config.tspersistAutoLinkwalksfindProjectRootonce inisHomeLinkTargetand again insidewriteProject; the second walk is across a function with side effects between, so left.- 40 exported symbols are only referenced inside their own file (full list recorded in the sweep notes); dropping
exportis an API-surface change and several are intentional test seams, so not changed. - The
domainStatusLinesverdict ladder incompute.tsis repeated three times with differing messages; similar, not identical, so not collapsed.
Filed, not fixed here
- [Yun Tianming] .claude/skills/developing-insta-cli/SKILL.md: commands/ table omits five command files (already open)
Opened by Yun Tianming: nightly sweep 2026-10-23-1000, model claude-fable-5-1, 75 turns, 6 files, 85 changed lines.
Verification: npm run typecheck (exit 0) and npm test (106 files, 2110 passed, 135 skipped, identical to baseline) on the final tree; ssh-keygen/ssh-gated suites skip on this machine.
🤖 Generated with Claude Code
Summary by cubic
Collapses duplicated signing, retry, and cache logic across six command files without changing behavior. The 429-tolerant poll backoff in github.ts, the project-signing scope in domain.ts, and the cache write in upgrade.ts now live in one local helper each; the other changes remove redundant work or reuse existing helpers.
planCertAuthorityinssh-config.tscollects kept lines in the same pass that builds the removed set instead of filtering twice.canonicalTargetinagent.tsis now evaluated once instead of twice.- A doc comment in
domain.tswas moved so it lands on the function it describes, and the inline--orgsuffix reuses the existingorgArgOfhelper. resolveDbUrlinpostgres.tsnow calls the module'sresolvePostgresinstead of repeating its two lines.- Typecheck passes and all 2110 tests pass, same as baseline; a pre-existing Windows path bug in
resolveProjectNamewas noted but left for the owners.