T-MBOK-lib-util-modules
Status: closed/done · Impact: medium · Complexity: large
Five scaffolders mint their own todayUtc(), three carry a private
SLUG_RE, six sites re-implement frontmatter regexes, and
_schema_patterns.ts is a 225-line library misfiled beside entry scripts.
Single-home the entity-agnostic helpers under lib/util so every port
task imports instead of copying.
| Location | Role today |
|---|---|
plugin/scripts/_schema_patterns.ts | schema-pattern loader library misfiled in the scripts dir (3 importers + tests) |
plugin/scripts/new_task.ts#todayUtc | one of ×5 private date stampers across scaffolders |
plugin/lib/util/yaml.ts | the only util module; no parse export — callers import npm yaml directly |
plugin/scripts/worktree_scope_guard.ts#isLinkedWorktree | worktree helper duplicated against count_inflight’s listWorktreeBasenames |
plugin/cli/backlog_cli/create.ts | inline gh pr helpers |
Proposed
Section titled “Proposed”lib/util/{date, slug, wikilinks, frontmatter, paths, git, gh, schema_patterns}.ts exist with tests; every duplication site imports the
util; _schema_patterns.ts moves out of scripts/ via git mv;
util/yaml.ts gains a parse export and the inline import { parse } from "yaml" sites migrate to it.
Approach
Section titled “Approach”git mv plugin/scripts/_schema_patterns.ts plugin/lib/util/schema_patterns.ts; fix importers. Own commit.- Add
date/slug/wikilinks/frontmatter/paths, consolidating each duplication cluster; rewrite call sites. One commit per module. - Extract
git/ghhelpers from worktree_scope_guard, count_inflight_tasks, backlog_cli, lease_cli. - Add the parse export to
util/yaml.ts; migrate direct npm-yaml importers. bunx tsc --noEmit+bun testafter each step.
Files to touch
Section titled “Files to touch”| Location | Kind | Change |
|---|---|---|
plugin/scripts/_schema_patterns.ts | delete | git mv to lib/util/schema_patterns.ts |
plugin/lib/util/ | modify | seven new modules + tests land here |
plugin/lib/util/yaml.ts | modify | add parse export |
plugin/scripts/*.ts | modify | import utils instead of private copies |
plugin/cli/backlog_cli/create.ts | modify | gh helpers → util/gh |
plugin/skills/standard-new/new_standard.ts | modify | _schema_patterns import path |
Acceptance criteria
Section titled “Acceptance criteria”- AC-1:
grep -rn "function todayUtc\|SLUG_RE\s*=" plugin/shows exactly one definition of each, underlib/util/(orlib/model/identifier.tsfor slug). - AC-2:
plugin/scripts/_schema_patterns.tsis gone;git log --follow plugin/lib/util/schema_patterns.tsshows pre-move history. - AC-3: no file under
plugin/outsidelib/util/yaml.tsimports the npmyamlpackage directly. - AC-4: full
bun test+bunx tsc --noEmitgreen.
Out of scope
Section titled “Out of scope”- Behavior changes to any consumer — this is import-path consolidation.
- sdlc.yaml config loading (T-KO35-config-sdlc-yaml).
- The prs_field split (T-JJZ3-lib-root-tidy merges its generic half into
util/frontmatter.ts).
Dependencies
Section titled “Dependencies”- none hard. Land before the port tasks so they import final util paths.
Discovery context
Section titled “Discovery context”- docs/plans/op-substrate-full-sweep.md §1e drive-out map; D-0007 §Migration step 2 (promote the obvious infra).