A repo-wide Not Invented Here audit (ten parallel domain surveys covering every package group, scripts/, native/, vendor/ edges, python/, test infrastructure, and CI) asked of each hand-rolled surface whether a maintained external package or Node builtin deletes it with a net win. Policy: new implemented process note records that a dependency which genuinely deletes owned code is a preferred simplification (bar: net deletion, health, boundary fit, settled seams stay); root AGENTS.md carries the one-line rule and dsh-find-simplifications now surveys for hand-rolled-where-a-dependency-exists candidates. Findings, all bilingual from birth: - proposed/simplification: eventsource-parser for llm-deepseek SSE, node:timers/promises for three hand-rolled sleeps, turndown (or minimal 'entities') for tool-web HTML->markdown, gate-script consolidation onto mdast/parseArgs/globSync - proposed/testing: execa + parseArgs + loadEnvFile + vi.waitFor for hand-rolled test subprocess plumbing - proposed/process: pnpm/action-setup for symmetric CI caching - proposed/feature: evaluate landstrip before building a Windows sandbox launcher - rejected/simplification: ~30 swap verdicts recorded (vscode-jsonrpc, p-retry, Ajv, write-file-atomic, msw, hono, better-sqlite3, wireit, landstrip-for-linux, YAML consolidation, ...) so the survey is not re-litigated from scratch Also drops the stale prompt/ entry from the AGENTS.md layout map (workspace instructions live in packages/context/workspace-context).
4.2 KiB
4.2 KiB
Agent Note: Consolidate gate scripts on already-present deps and builtins
Status: proposed
English | 中文
Problem
The scripts/ gates mostly use the right tools (node:fs globSync in 15+ gates, mdast/micromark in the markdown gates), but a handful of stragglers hand-roll what a sibling gate already does with an existing dependency or builtin:
- Duplicated fence scanners.
scripts/md-fences.ts(~55 lines, consumed bydoc-typecheck.ts) andextractEquivBlocksinscripts/verify-type-equiv.ts(~39 lines) are two copies of the same regex line-scanner for fenced code blocks, whilescripts/verify-mermaid.tsalready extracts fences by visiting mdastcodenodes via the sharedscripts/markdown.tshelpers — andmarkdownProseLinesinmarkdown.tsitself parses to mdast but then hand-tracks fence state with a second regex. The regex scanners only recognize backtick fences at column 0, so they silently disagree with the mdast-based gates on tilde and indented fences. - Hand-rolled argv parsing.
parseOptionsinscripts/publint-all.tsand its near-identical copy inscripts/verify-built-package-invariants.mjs(~26 lines) step argv indexes manually, while sibling scripts (verify-runtime-closure.ts,build-exe-for-python-sdk.ts,packages/sdk/scripts/src/args.ts) already use thenode:utilparseArgsbuiltin. - Hand-rolled directory walks. Five sites re-derive nested
readdirSyncwalks thatglobSynccovers:verify-runtime-closure.ts(packages + vendor manifests),dev-web.tsdiscoverPluginDirs,verify-package-paths.tsrealPackageNames,verify-client-domain-graph.tslistSources, andpublint-all.tsaddPath(~55–65 lines total).scripts/package-invariants.tsshows the one-lineglobSynctemplate.
No new dependency is needed anywhere; every replacement is an existing devDep or a Node builtin.
Proposal
- Extract a shared ~10–15-line mdast fence helper (visiting
codenodes forlang,meta,value,position.start.line) intoscripts/markdown.ts; rewritedoc-typecheck.tsandverify-type-equiv.tsonto it; deletemd-fences.tsand the duplicated scanner; drop the redundant fence regex inmarkdownProseLines. - Replace both
parseOptionscopies withparseArgs. - Replace the five straggler walks with
globSync. Keep the walks incheck-workspace-constraints.tsandclean.ts: they need dirent-level detail to diagnose malformed trees, which glob-by-pattern cannot report.
Alternatives considered
- A new glob/walking dependency (
tinyglobby,fdir). Rejected: the builtin already won repo-wide; these are stragglers, not a gap. p-mapforpublint-all.ts's ~19-line ordered worker pool. Deliberately left out: one new devDep for one small deletion is at the edge of the dependency policy bar, and the pool's requirements (bounded workers, deterministic order, env override) are documented in the parallel-gates note. Fold it in only ifp-mapearns a second consumer.- Leaving the fence scanners. Rejected: two drifting copies of a parser beside a third correct implementation is exactly the duplication the shared
markdown.tshelper exists to prevent, and the column-0-backtick-only limitation is a latent inconsistency between sibling gates.
Acceptance criteria
md-fences.tsis gone;doc-typecheckandverify-type-equivextract fences throughscripts/markdown.ts;pnpm run doc-syncpasses with unchanged results on the current tree (any delta traces to a fence shape the regex scanners mishandled).- Both CLIs parse via
parseArgs; unknown options still fail loud. - The five walk sites use
globSync; the gates they feed pass unchanged.
Risks
- Behavioral deltas on pathological markdown: mdast honors tilde/indented fences the regex scanners ignored, so
doc-typecheck's opt-out ratio could shift if any stray fence shape exists in the docs tree; verify by runningdoc-syncbefore/after. parseArgskeeps the last value of a duplicated option instead of erroring and consumes a---prefixed next token as a value; both are dev-tool edge cases the tests don't pin.