mirror of
https://github.com/stablyai/orca.git
synced 2026-10-05 00:02:33 +00:00
#14397 split `shared/types.ts` into 46 per-domain modules but kept the path as a re-export barrel so the import sites did not have to change. This removes the barrel: every consumer now imports from the module that actually declares the type, and `src/shared/types.ts` is deleted. Barrels hide where a type lives, make every consumer look like it depends on the whole domain, and let an unrelated edit invalidate a module that ~2,000 files transitively import. 2,323 import declarations across 2,321 files. Rewritten mechanically: each specifier was resolved to an absolute path via the TypeScript AST and recomputed, rather than string-substituted, so alias forms (`@/../../shared/ types`) and per-specifier `type` modifiers survive. Four cases the mechanical pass had to handle, each found by a gate rather than by reading the diff: - Modules inside `src/shared` import the barrel as `./types`, not `shared/types`. A pre-filter on the latter string skipped 176 of them and left imports dangling at a deleted file, which surfaced as confusing `Property 'x' is optional in type 'Repo' but required in Pick<Repo, ...>` errors rather than "module not found". - The barrel RENAMED one type on the way through (`WorkspaceSource as WorkspaceCreateTelemetrySource`), so the original name in the owning module has to be re-aliased at each consumer. - Three test files put `;(globalThis as ...)` on the line after the import. TypeScript parses that `;` as the import statement's terminator, so replacing through `statement.getEnd()` deletes it and breaks ASI. The rewrite now stops at the module specifier. - A file that already imported directly from a module got a SECOND import from it, because the barrel re-exported those same names — which trips `import/no-duplicates` under `--deny-warnings`. A post-pass merges declarations sharing a specifier and type-only-ness; the `import type` plus `import` pair from one module is left alone, since that form is allowed. Splitting one barrel import into several genuinely adds lines, which pushed `terminal-layout-pty-ownership.ts` to 301 counted lines: its 107-character import must wrap, and neither local type collapses onto one line (101 and 116 characters). Rather than contort a type declaration to fit a line budget, `collectLeafIds` and `pruneLeaves` move to `terminal-pane-layout-tree.ts` — they are pure structural operations on the layout tree and independent of PTY ownership. `visible-worktrees.ts` similarly loses its own mini-barrel re-export of `isDefaultBranchWorkspace`, with the four real consumers repointed at the declaring module. No `max-lines` bypass added. Verified: cold `tsc --noEmit` green on node, cli, and web (buildinfo deleted first — these projects are `composite: true` and reuse stale caches); the full `pnpm lint` green, not just bare oxlint — the narrower local check is what let the duplicate imports reach CI; max-lines ratchet OK at 344.
179 lines
5.4 KiB
TypeScript
179 lines
5.4 KiB
TypeScript
import type { TuiAgent } from '../../../src/shared/tui-agent'
|
|
import type {
|
|
CreateSparseCheckoutRequest,
|
|
SetupDecision
|
|
} from '../../../src/shared/worktree/create-types'
|
|
import type { GitPushTarget } from '../../../src/shared/worktree/types'
|
|
import { getWorkspaceSourceName } from '../../../src/shared/new-workspace/workspace-source'
|
|
import { resolveMobileWorkspaceCreateName } from './mobile-workspace-name'
|
|
import type { WorkspaceAgentChoice } from './workspace-agent-selection'
|
|
|
|
export type WorkspaceCreateSetupDecision = SetupDecision
|
|
export type WorkspaceCreateSparseCheckout = CreateSparseCheckoutRequest
|
|
export type WorkspaceCreateGitPushTarget = GitPushTarget
|
|
|
|
export type WorkspaceCreateHostedStartPoint = {
|
|
baseBranch: string
|
|
pushTarget?: WorkspaceCreateGitPushTarget
|
|
}
|
|
|
|
type WorkspaceCreateGitHubItem = {
|
|
provider: 'github'
|
|
source: {
|
|
type: 'issue' | 'pr'
|
|
repoId: string
|
|
number: number
|
|
title: string
|
|
url: string
|
|
}
|
|
}
|
|
|
|
type WorkspaceCreateGitLabItem = {
|
|
provider: 'gitlab'
|
|
source: {
|
|
type: 'issue' | 'mr'
|
|
repoId: string
|
|
number: number
|
|
title: string
|
|
url: string
|
|
}
|
|
}
|
|
|
|
type WorkspaceCreateLinearItem = {
|
|
provider: 'linear'
|
|
source: {
|
|
identifier: string
|
|
title: string
|
|
url: string
|
|
workspaceId?: string
|
|
organizationUrlKey?: string
|
|
}
|
|
}
|
|
|
|
export type WorkspaceCreateTaskItem =
|
|
| WorkspaceCreateGitHubItem
|
|
| WorkspaceCreateGitLabItem
|
|
| WorkspaceCreateLinearItem
|
|
|
|
export type WorkspaceCreateParams = Record<string, unknown>
|
|
|
|
/**
|
|
* `worktree.create` fields for launching the picked agent in a fresh session.
|
|
*
|
|
* Why: send the agent id so the host resolves launch args (permission flags)
|
|
* and host-shell quoting, matching the "+" new-tab and CLI paths.
|
|
*/
|
|
export function agentLaunchCreateFields(agentId: TuiAgent | undefined): {
|
|
startupAgent?: TuiAgent
|
|
createdWithAgent?: TuiAgent
|
|
} {
|
|
if (!agentId) {
|
|
return {}
|
|
}
|
|
return { startupAgent: agentId, createdWithAgent: agentId }
|
|
}
|
|
|
|
export function buildTaskWorkspaceCreateParams(args: {
|
|
item: WorkspaceCreateTaskItem
|
|
targetRepoId: string
|
|
setupDecision: WorkspaceCreateSetupDecision
|
|
agent?: WorkspaceAgentChoice
|
|
workspaceName?: string
|
|
note?: string
|
|
baseBranch?: string
|
|
compareBaseRef?: string
|
|
branchNameOverride?: string
|
|
pushTarget?: WorkspaceCreateGitPushTarget
|
|
sparseCheckout?: WorkspaceCreateSparseCheckout
|
|
hostedStartPoint?: WorkspaceCreateHostedStartPoint
|
|
nameIsAutoManaged?: boolean
|
|
}): WorkspaceCreateParams {
|
|
const {
|
|
item,
|
|
targetRepoId,
|
|
setupDecision,
|
|
agent,
|
|
workspaceName,
|
|
note,
|
|
baseBranch,
|
|
compareBaseRef,
|
|
branchNameOverride,
|
|
pushTarget,
|
|
sparseCheckout,
|
|
hostedStartPoint,
|
|
nameIsAutoManaged = true
|
|
} = args
|
|
const shouldLaunchAgent = agent !== 'blank'
|
|
const createdWithAgent = shouldLaunchAgent ? (agent as TuiAgent) : undefined
|
|
const comment = note?.trim()
|
|
const selectedBaseBranch = baseBranch || hostedStartPoint?.baseBranch
|
|
const selectedPushTarget = pushTarget ?? hostedStartPoint?.pushTarget
|
|
// Why: desktop only sends displayName while the name is still auto-derived; a
|
|
// user-edited name suppresses it so the runtime keeps the user's chosen name.
|
|
const sourceName =
|
|
item.provider === 'linear'
|
|
? getWorkspaceSourceName({
|
|
provider: 'linear',
|
|
type: 'issue',
|
|
number: 0,
|
|
title: item.source.title,
|
|
url: item.source.url,
|
|
linearIdentifier: item.source.identifier
|
|
})
|
|
: getWorkspaceSourceName({ provider: item.provider, ...item.source })
|
|
const displayName = nameIsAutoManaged ? { displayName: sourceName.displayName } : {}
|
|
const common = {
|
|
setupDecision,
|
|
activate: true,
|
|
...(shouldLaunchAgent ? { startupDraft: item.source.url } : {}),
|
|
...(createdWithAgent ? { createdWithAgent } : {}),
|
|
...(selectedBaseBranch ? { baseBranch: selectedBaseBranch } : {}),
|
|
...(compareBaseRef ? { compareBaseRef } : {}),
|
|
...(branchNameOverride ? { branchNameOverride } : {}),
|
|
...(selectedPushTarget ? { pushTarget: selectedPushTarget } : {}),
|
|
...(sparseCheckout ? { sparseCheckout } : {}),
|
|
...(comment ? { comment } : {})
|
|
}
|
|
|
|
if (item.provider === 'github') {
|
|
const fallback = `${item.source.type}-${item.source.number}`
|
|
return {
|
|
repo: `id:${item.source.repoId}`,
|
|
name: resolveMobileWorkspaceCreateName({ draft: workspaceName, fallback }),
|
|
...displayName,
|
|
...common,
|
|
...(item.source.type === 'issue'
|
|
? { linkedIssue: item.source.number }
|
|
: { linkedPR: item.source.number })
|
|
}
|
|
}
|
|
|
|
if (item.provider === 'gitlab') {
|
|
const fallback = `${item.source.type}-${item.source.number}`
|
|
return {
|
|
repo: `id:${item.source.repoId}`,
|
|
name: resolveMobileWorkspaceCreateName({ draft: workspaceName, fallback }),
|
|
...displayName,
|
|
...common,
|
|
...(item.source.type === 'issue'
|
|
? { linkedGitLabIssue: item.source.number }
|
|
: { linkedGitLabMR: item.source.number })
|
|
}
|
|
}
|
|
|
|
return {
|
|
repo: `id:${targetRepoId}`,
|
|
name: resolveMobileWorkspaceCreateName({
|
|
draft: workspaceName,
|
|
fallback: item.source.identifier.toLowerCase()
|
|
}),
|
|
...displayName,
|
|
linkedLinearIssue: item.source.identifier,
|
|
...(item.source.workspaceId ? { linkedLinearIssueWorkspaceId: item.source.workspaceId } : {}),
|
|
...(item.source.organizationUrlKey
|
|
? { linkedLinearIssueOrganizationUrlKey: item.source.organizationUrlKey }
|
|
: {}),
|
|
...common
|
|
}
|
|
}
|