Context
Operator-flagged KB-sync regression surfaced after restarting the orchestrator (npm run ai:orchestrator → [ProcessSupervisor] knowledge base sync stderr):
[WARN] Failed to parse source file ai/scripts/maintenance/downloadKnowledgeBase.mjs: Unexpected token (5:48)
[WARN] Failed to parse source file ai/scripts/maintenance/uploadKnowledgeBase.mjs: Unexpected token (5:48)
The Problem
ai/services/knowledge-base/parser/SourceParser.mjs:58 hardcodes acorn.parse(content, {sourceType: 'module', locations: true, ecmaVersion: 2022}). Both failing files use ES2025 import-attribute syntax at line 5 column 48:
import packageJson from '../../../package.json' with {type: 'json'};Acorn 8.16.0 (currently pinned in package.json) supports import ... with {type: 'json'} only under ecmaVersion: 2025 or ecmaVersion: 'latest'. ecmaVersion: 2022 does not recognize the with keyword as an import attribute.
The Architectural Reality
Primary surfaces:
Provenance: The with syntax was introduced 2026-05-23 in commit e6c9df098 (#11848/#11853 buildScripts/ai → ai/scripts collapse refactor). KB-sync has been silently dropping these chunks since then; today's orchestrator restart triggered a full re-parse and surfaced the WARN.
Blast scope: WARN only — KB sync completes; the 2 affected files just don't contribute source chunks to the knowledge base. Agents querying the KB about downloadKnowledgeBase/uploadKnowledgeBase get no source-level results. Not a stop-the-world but degrades agent-facing observability.
The Fix
Single-line change at SourceParser.mjs:58:
- ast = acorn.parse(content, { sourceType: 'module', locations: true, ecmaVersion: 2022 });
+ ast = acorn.parse(content, { sourceType: 'module', locations: true, ecmaVersion: 'latest' });'latest' is acorn's documented sentinel for "the most recent ECMA version this acorn release supports" — auto-tracks new syntax as acorn is upgraded, without further hardcoded version bumps required when new TC39 features land.
Acceptance Criteria
Out of Scope
- Migrating the 2 files back to
fs.readJson (would lose the static-import benefit; we want the parser to handle modern syntax, not constrain authoring).
- Bumping acorn itself —
8.16.0 already supports 'latest'.
- Auditing for other parsers in the codebase that may have the same hardcoded-year issue (file as follow-up if any are found).
Avoided Traps
- Do NOT switch
ecmaVersion: 2025 instead of 'latest' — the literal year locks future agents into another hardcoded bump when ES2026+ syntax lands. 'latest' auto-tracks.
- Do NOT add a fallback
try { 'latest' } catch { 2022 } block — defensive code that never fires is noise. Acorn's contract is documented; trust it.
- Do NOT touch the 2 files using
import with — they're authoring the canonical modern shape; the parser is the surface to fix.
Related
- #11848 / #11853 — refactor that introduced the
import with syntax in the 2 maintenance scripts
- Operator-reported regression 2026-05-25 via orchestrator daemon log
Handoff Retrieval Hint: "SourceParser acorn ecmaVersion 2022 import attribute with type json regression".
Context
Operator-flagged KB-sync regression surfaced after restarting the orchestrator (
npm run ai:orchestrator→[ProcessSupervisor] knowledge base sync stderr):The Problem
ai/services/knowledge-base/parser/SourceParser.mjs:58hardcodesacorn.parse(content, {sourceType: 'module', locations: true, ecmaVersion: 2022}). Both failing files use ES2025 import-attribute syntax at line 5 column 48:import packageJson from '../../../package.json' with {type: 'json'};Acorn
8.16.0(currently pinned inpackage.json) supportsimport ... with {type: 'json'}only underecmaVersion: 2025orecmaVersion: 'latest'.ecmaVersion: 2022does not recognize thewithkeyword as an import attribute.The Architectural Reality
Primary surfaces:
ai/services/knowledge-base/parser/SourceParser.mjs:58— single hardcodedecmaVersion: 2022.ai/scripts/maintenance/downloadKnowledgeBase.mjsandai/scripts/maintenance/uploadKnowledgeBase.mjs.acorn.parse(..., {ecmaVersion: 'latest'})→ parses cleanlyacorn.parse(..., {ecmaVersion: 2025})→ parses cleanlyacorn.parse(..., {ecmaVersion: 2022})→Unexpected token (1:23)Provenance: The
withsyntax was introduced 2026-05-23 in commite6c9df098(#11848/#11853 buildScripts/ai → ai/scripts collapse refactor). KB-sync has been silently dropping these chunks since then; today's orchestrator restart triggered a full re-parse and surfaced the WARN.Blast scope: WARN only — KB sync completes; the 2 affected files just don't contribute source chunks to the knowledge base. Agents querying the KB about
downloadKnowledgeBase/uploadKnowledgeBaseget no source-level results. Not a stop-the-world but degrades agent-facing observability.The Fix
Single-line change at
SourceParser.mjs:58:- ast = acorn.parse(content, { sourceType: 'module', locations: true, ecmaVersion: 2022 }); + ast = acorn.parse(content, { sourceType: 'module', locations: true, ecmaVersion: 'latest' });'latest'is acorn's documented sentinel for "the most recent ECMA version this acorn release supports" — auto-tracks new syntax as acorn is upgraded, without further hardcoded version bumps required when new TC39 features land.Acceptance Criteria
SourceParser.mjs:58usesecmaVersion: 'latest'(no hardcoded year).test/playwright/unit/ai/services/knowledge-base/parser/SourceParser.spec.mjs(or equivalent canonical location) parses a fixture containingimport x from 'y.json' with {type: 'json'}without warning.npm run ai:orchestratortriggers a KB sync, noFailed to parse source filewarnings fordownloadKnowledgeBase.mjsoruploadKnowledgeBase.mjsappear in the daemon log.Out of Scope
fs.readJson(would lose the static-import benefit; we want the parser to handle modern syntax, not constrain authoring).8.16.0already supports'latest'.Avoided Traps
ecmaVersion: 2025instead of'latest'— the literal year locks future agents into another hardcoded bump when ES2026+ syntax lands.'latest'auto-tracks.try { 'latest' } catch { 2022 }block — defensive code that never fires is noise. Acorn's contract is documented; trust it.import with— they're authoring the canonical modern shape; the parser is the surface to fix.Related
import withsyntax in the 2 maintenance scriptsHandoff Retrieval Hint: "SourceParser acorn ecmaVersion 2022 import attribute with type json regression".