Skip to content

refactor(runtime): split skills.ts along discovery/metadata/context/state seams - #1428

Merged
Astro-Han merged 2 commits into
apache:mainfrom
sunheyi6:refactor/split-skills-ts-1408
Jul 24, 2026
Merged

Astro-Han merged 2 commits into
apache:mainfrom
sunheyi6:refactor/split-skills-ts-1408

Conversation

@sunheyi6

Copy link
Copy Markdown
Contributor

Closes #1408

Part of #1084 (second-pass sink-file and boundary governance).

Summary

Split the 1921-line packages/runtime/src/skills.ts into focused sub-modules along the discovery/metadata/context/state seams visible today, keeping @maka/runtime exports (20+ symbols via index.ts) stable through re-exports.

Changes

New file Responsibility
skills-discovery.ts (438 lines) resolveSkillDiscoveryPaths, normalizeSkillSource, scanSkills* family, scanSkillDir, ScannedSkill/RuntimeSkillDefinition types
skills-metadata.ts (500 lines) validateSkillMetadata, parseSkillFrontMatter, manifest-parsing family, SkillManifest/validation types, cleanPromptText
skills-context.ts (620 lines) gateSkillsByHostCapabilities, selectSkillsForContext, searchSkills + scoring, prompt rendering, loadSkillInstructions
skills-state.ts (213 lines) readSkillRuntimeState, writeSkillRuntimeState/writeSkillRuntimePreferences
skills-agent-tools.ts (180 lines) buildSkillAgentTool, buildSkillSearchAgentTool, SkillShadowSelectionTracker

Additionally, moved generic contained-file I/O helpers (readContainedRegularFile, readContainedRegularTextFile, writeContainedRegularTextFile, isRecord) into path-containment.ts — they are generic infrastructure already imported cross-package by apps/desktop/src/main/skills.ts.

skills.ts is now a thin re-export barrel (116 lines) so existing from './skills.js' imports continue to work without changes. Internal consumers (skill-invocation.ts, tool-catalog-derive.ts) updated to import from specific sub-modules directly.

Invariants

  • Behavior-neutral: no logic changes, pure code movement
  • Stable public exports: all @maka/runtime exports preserved via re-exports
  • No reverse imports: dependency graph is path-containment ← skills-metadata ← skills-state ← skills-discovery ← skills-context ← skills-agent-tools

Verification

  • tsc --noEmit on packages/runtime/tsconfig.json — no errors
  • tsc --noEmit on apps/desktop/tsconfig.main.json — no errors
  • skills.test.ts — 36/36 pass
  • skill-invocation.test.ts — 11/11 pass
  • tool-runtime-extraction-contract.test.ts — 8/8 pass

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file split matches the responsibilities present at the merge base, but the branch is stale and cannot be merged as-is.

[P2] This branch conflicts with current main in packages/runtime/src/index.ts, packages/runtime/src/skill-invocation.ts, and packages/runtime/src/skills.ts. Since the branch point, main has added skill discovery diagnostics and invocation receipts that are missing here.

Rebase first, then apply the split to the current implementations. Do not resolve these conflicts by choosing one side wholesale. Afterward, verify the runtime skill tests, package exports, and workspace typecheck.

Comment thread packages/runtime/src/path-containment.ts Outdated
…tate seams

Split the 1921-line skills.ts into focused sub-modules, keeping all
public exports stable through a re-export barrel and index.ts updates:

- skills-discovery.ts: resolveSkillDiscoveryPaths, normalizeSkillSource,
  scanSkills* family, scanSkillDir, ScannedSkill/RuntimeSkillDefinition types
- skills-metadata.ts: validateSkillMetadata, parseSkillFrontMatter,
  manifest-parsing family, SkillManifest/validation types, cleanPromptText
- skills-context.ts: gateSkillsByHostCapabilities, selectSkillsForContext,
  searchSkills + scoring, prompt rendering, loadSkillInstructions
- skills-state.ts: readSkillRuntimeState, writeSkillRuntimeState/Preferences
- skills-agent-tools.ts: buildSkillAgentTool, buildSkillSearchAgentTool,
  SkillShadowSelectionTracker
- path-containment.ts: moved readContainedRegularFile,
  readContainedRegularTextFile, writeContainedRegularTextFile, isRecord
  (generic infrastructure already imported cross-package by desktop)

skills.ts is now a thin re-export barrel so existing 'from ./skills.js'
imports continue to work. Internal consumers (skill-invocation.ts,
tool-catalog-derive.ts) updated to import from specific sub-modules.

Closes apache#1408
@sunheyi6
sunheyi6 force-pushed the refactor/split-skills-ts-1408 branch from 4196822 to 5bdc0cf Compare July 24, 2026 08:38
@Astro-Han

Copy link
Copy Markdown
Contributor

LGTM now. Merging!

@Astro-Han
Astro-Han merged commit 1c260de into apache:main Jul 24, 2026
3 checks 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.

refactor(runtime): split skills.ts along discovery/metadata/context/state seams

2 participants