refactor: consolidate markdown code fences, error coercion, and byte-identical helper pairs#99932
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 4, 2026, 8:35 AM ET / 12:35 UTC. Summary PR surface: Source -224, Tests +50, Config +8, Generated 0, Other 0. Total -166 across 47 files. Reproducibility: yes. for the review finding: source inspection at the current PR head shows an exported subpath and built consumers but no matching shared tsdown entry. I did not run a package build because this review must keep the checkout read-only. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Add the missing normalization-core tsdown entry, keep the helper consolidation scoped to existing owner boundaries, and require redacted real behavior proof before merge. Do we have a high-confidence way to reproduce the issue? Yes for the review finding: source inspection at the current PR head shows an exported subpath and built consumers but no matching shared tsdown entry. I did not run a package build because this review must keep the checkout read-only. Is this the best way to solve the issue? No: the consolidation is mostly in the right ownership direction, but the new package subpath is not safely integrated until the central package build emits it. The narrow fix is to update Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 706443c79b1c. Label changesLabel justifications:
Evidence reviewedPR surface: Source -224, Tests +50, Config +8, Generated 0, Other 0. Total -166 across 47 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (4 earlier review cycles)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 034a4b719f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "./error-coercion": { | ||
| "types": "./dist/error-coercion.d.mts", | ||
| "import": "./dist/error-coercion.mjs", | ||
| "default": "./dist/error-coercion.mjs" |
There was a problem hiding this comment.
Add error-coercion to the shared tsdown entries
When adding this exported subpath, also add error-coercion to buildNormalizationCoreDistEntries in tsdown.config.ts; the repo build (pnpm build via scripts/tsdown-build.mjs) does not run this package-local script, so it will emit dist/index.mjs but not dist/error-coercion.mjs. Any built package that now imports @openclaw/normalization-core/error-coercion (for example @openclaw/media-core/read-response-with-limit) will then resolve this export to a missing file at runtime.
Useful? React with 👍 / 👎.
034a4b7 to
1328d53
Compare
|
Merged via squash.
|
…identical helper pairs (openclaw#99932) * refactor(shared): add markdown code span/fence helpers and migrate seven call sites * refactor(normalization-core): add canonical toErrorObject and migrate six copies * refactor: consolidate byte-identical helper pairs onto owner modules * refactor: reuse canonical path and token helpers in session tools and credentials * refactor(packages): dedupe compaction summarization tail and session dir parsing * fix(security): keep missing extensions dir silent in shared plugin dir lister * refactor: reuse media-core chunk reader and shared dreaming session key helper * fix(plugins): register error-coercion subpath in sdk alias table * chore(plugin-sdk): re-pin callable export count after rebase * chore(plugin-sdk): re-pin callable export count after rebase
Related: #99841
What Problem This Solves
Third consolidation pass over the verbatim-duplication backlog catalogued in #99841 (rounds one and two landed as #99850 and #99901). This round removes the remaining high-value exact clones inside core
src/andpackages/:toErrorObject(normalize unknown thrown values into an Error with cause + copied enumerable fields) existed six times:src/infra/errors.tsplus verbatim private copies in media-core, memory-host-sdk (twice), and two plugin-sdk runtime files.toPosixPath(two session tools vs the exported canonical), tilde path expansion (prompt templates vs skills loader), CLI OAuth token-field validation (portal vs Gemini readers), compaction summarization tails (main vs turn-prefix paths),extractAgentIdFromSessionsDirand the dreaming-narrative session-key classifier (two memory-host-sdk files each), and the media chunk-idle-timeout reader (core media fetch vs the media-core superset with proper cancel-with-reason).Why This Change Was Made
Same policy as the previous rounds: one canonical owner per behavior, chosen by existing ownership rather than new surface.
src/shared/markdown-code.ts(formatInlineCodeSpan,formatFencedCodeBlock) with a colocated test; all seven sites migrate. The two inline-span variants were verbatim; the OAuth hint variant gains the newline-padding rule (no-op for single-line commands).toErrorObjectmoves to@openclaw/normalization-core/error-coercion(new subpath registered in the package exports, build entry list, root tsconfig paths, and the shared Vitest alias table).src/infra/errors.tsre-exports it, so its many existing importers are untouched. The zero-dependency memory-host-sdk package intentionally keeps one internal copy, now shared between its own two files instead of duplicated.status/codex-synthetic-usage.ts,gateway/operator-scopes.ts,agents/tool-policy-audit.ts,security/installed-plugin-dirs.ts,agents/tools-effective-inventory-build.ts,shared/ignore-rules.ts(existing exportedtoPosixPath), andmemory-host-sdk/host/openclaw-runtime-session.ts. Only two new modules were added (markdown-code,tilde-path), each with multiple consumers on day one.scan_failedfinding instead of silently reporting "no plugins".Audited and intentionally left, with reasons recorded: the code-mode worker's inlined JSON serializer (standalone worker bundle cannot import), the plugin-sdk video-generation type mirror (deliberate public-API stability snapshot with assignability assertions and a jscpd-ignore marker), the skills-cli error-handling idiom (13 occurrences deserve a file-wide action wrapper, not a two-site nibble), sync/async file readers in pairing, and several near-clones whose divergence is semantic (platform-specific env setup, deprecated/current API bridges, schema declarations).
User Impact
No user-visible behavior change, with two internal hardening notes: duplicate operator scopes from plugin CLI callers are now deduplicated before gateway requests (previously only the gateway path deduped), and security audits report extensions-directory stat failures instead of silently skipping the scan. Net negative production LOC.
Evidence
src/shared/markdown-code.test.ts(12 assertions covering delimiter growth, padding, and language fences).check-import-cycles(0 cycles), and the plugin-sdk surface check (no surface change this round) are green.