Files
deepseek-harness/packages/scaffold/helper/src/features/registry.ts
Tianyi Cui 3fc35c91ff refactor(packages): dissolve ui/ and rename sdk/ to scaffold/
git mv per the regrouping RFC: the five human-collaboration seams and
tui join packages/interaction/, app-boot becomes packages/boot/, and
jsonrpc joins the renamed scaffold/ (formerly sdk/) as its server half
beside client/protocol/create-sdk/helper/scripts/telemetry, whose
folders drop the legacy sdk- prefix. Three new group README triplets
replace the ui/ and sdk/ ones; tsconfig references/paths/globs,
knip keys, vitest globs, gate scripts, catalogs, docs, and the
lockfile follow. Adds the four settled FIXME rename markers
(dsh-sdk-server, dsh-sdk-telemetry, dsh-sdk-helper, dsh-sdk-scripts).

The scaffold folders diverge from their npm names until those renames
land, so tsconfig.base.json maps the three affected names explicitly
beside the group wildcard. Also repairs two pre-existing stale-path
classes the strengthened sweep surfaced: docs/web-styling.md's retired
web-ui host package and type-model spec fixture-literal joins.

app-boot's three Loader-composition specs time out at the default 5s
under full-suite parallel load on this filesystem (pre-existing;
pass isolated with --testTimeout=30000); interaction/scaffold/boot
suites otherwise green (687 passed).
2026-08-09 01:21:12 +08:00

88 lines
3.2 KiB
TypeScript

/**
* Builtin feature registry and definition-time conflict checks.
*
* @module @deepseek-ai/dsh-helper/features/registry
*/
import type { FeatureId, ResourceKey } from '../ids.ts'
import type { ProjectProfile } from '../project/types.ts'
import type { Feature, FeatureProjectView } from './feature.ts'
import type { CordisConfigEntryResource } from './resources.ts'
/** Compile-time builtin feature collection. */
export class FeatureRegistry {
private readonly features = new Map<FeatureId, Feature>()
/** Register and validate a complete builtin set. */
constructor(features: readonly Feature[], validationProfile: ProjectProfile) {
const owners = new Map<ResourceKey, FeatureId>()
for (const feature of features) {
if (this.features.has(feature.id)) throw new Error(`duplicate feature id: ${feature.id}`)
this.features.set(feature.id, feature)
const validationInterface = feature.supportedInterfaces[0]
if (!validationInterface) throw new Error(`feature ${feature.id} supports no run interface`)
const selections = feature.options.map(option => ({ id: feature.id, options: [option.id] }))
for (const selection of selections) {
const contribution = feature.contribution(selection, {
...validationProfile,
runInterface: validationInterface,
})
for (const resource of contribution.resources) {
const owner = owners.get(resource.key)
if (owner && owner !== feature.id) {
throw new Error(`resource ${resource.key} is declared by both ${owner} and ${feature.id}`)
}
owners.set(resource.key, feature.id)
}
}
}
}
/**
* Return all builtins in display order.
* @returns all registered features.
*/
all(): readonly Feature[] {
return [...this.features.values()]
}
/**
* Resolve one builtin or fail loud.
* @param id - stable feature identity.
* @returns registered feature.
*/
get(id: FeatureId): Feature {
const feature = this.features.get(id)
if (!feature) throw new Error(`unknown feature: ${id}`)
return feature
}
/**
* Inspect every applicable builtin in display order.
* @param project - project view to inspect.
* @returns installation snapshots for applicable features.
*/
inspect(project: FeatureProjectView): ReturnType<Feature['inspect']>[] {
return this.all()
.filter(feature => feature.isApplicable(project.profile))
.map(feature => feature.inspect(project))
}
/**
* Resolve the builtin that owns a Cordis package name for this profile.
* @param name - Loader package name.
* @param profile - project context controlling applicability.
* @returns owning feature, if the package is builtin-owned.
*/
ownerOfPackage(name: string, profile: ProjectProfile): Feature | undefined {
return this.all().find((feature) => {
if (!feature.isApplicable(profile)) return false
const selections = feature.options.map(option => ({ id: feature.id, options: [option.id] }))
return selections.some(selection => feature.contribution(selection, profile).resources.some(
(resource): resource is CordisConfigEntryResource => resource.kind === 'cordis-config-entry'
&& resource.entry.name === name,
))
})
}
}