Repository navigation
Description
Found by the #1038 docs audit. It is a code gap, not a docs one, and it invalidates a premise the fold epic (#1019) shipped on: intrinsic-heavy authoring (AWS Sub, the dominant real-world pattern) never folds under --fold today.
Background for a cold start
chant build --fold (#1022) statically folds each source file's AST instead of importing and running it, with per-file run-fallback for anything outside the fold subset. The folder itself lives in packages/core/src/fold/fold.ts. It CAN fold a registered intrinsic tagged template — fold.ts:254 checks intrinsics.some((i) => i.isTag === true && i.name === tagName) and reduces Sub`...`to its intrinsic node form.IntrinsicDefis declared inpackages/core/src/lexicon.ts:105 (isTag?: boolean`).
Gap 1 — the CLI fold path hardcodes intrinsics to []
The call chain is: packages/core/src/cli/commands/build.ts → build() in packages/core/src/build.ts:472 (discover(path, { fold: options?.fold })) → discover() in packages/core/src/discovery/index.ts:73 → tryFoldFile(file) at index.ts:98 → foldResource/fold in packages/core/src/discovery/fold-import.ts.
Nothing on that chain accepts or threads intrinsics. The terminal calls are hardcoded:
fold-import.ts:471—fold(argNode, ctx.consts, [])fold-import.ts:510—foldResource(node, ctx.consts, [])tryFoldFile(file)atfold-import.ts:577takes only the file path.
The seam already exists at the top: cli/commands/build.ts has options.plugins (each plugin exposes intrinsics(): IntrinsicDef[]). A grep confirms intrinsics() is consumed nowhere in core src today outside docs codegen — only unit tests exercise the param, with hand-fabricated defs (fold.test.ts).
Gap 2 — isTag registration is wrong in at least two lexicons
isTag predates the epic (it drove the docs "Tag?" column) and was never audited for fold:
lexicons/aws/src/plugin.ts:57registersSubwith noisTag— AWSSubis authored as a tagged template and must haveisTag: true. Even with Gap 1 fixed, AWS folds nothing until this is set.lexicons/gitlab/src/plugin.ts:56hasisTag: trueonreference(), which is invoked as a plain call, not a tagged template — the inverse error. (It conflatesisTagwith YAML!referencerendering.)docker(plugin.ts:48) andgithub(plugin.ts:71) have explicitisTag: false; verify those are correct while auditing.
Audit all 11 lexicons: isTag: true iff the intrinsic is authored as a JS tagged template.
Empirically confirmed
chant build <dir> --fold on lexicon examples:
[fold:run] resource-basic.ts — "appBucket" not foldable: unregistered tagged template intrinsic: Sub`...`
[fold:run] main.ts — not foldable: function call as a value is not foldable: Concat(...) (azure)
0 of ~20 AWS, 0 of ~9 Azure, 0 of ~8 GCP examples fold. The 14/98 corpus entries that fold are intrinsic-free.
Fix
- Add an
intrinsics?: IntrinsicDef[]option through the chain:build()options →DiscoveryOptions→tryFoldFile(file, intrinsics)→ replace both hardcoded[]infold-import.ts. Populate it incli/commands/build.tsfromoptions.plugins.flatMap(p => p.intrinsics?.() ?? [])(guard:intrinsicsmay be optional on the plugin interface — check). - Fix
isTagper Gap 2 across all lexicons. IfisTagis genuinely doing double duty for YAML tag rendering somewhere (gitlab), decouple: fold keys off "authored as a tagged template" only. Check how the serializer/docs codegen consumeisTagbefore changing gitlab's value — if the YAML!referencerendering depends on it, introduce a separate flag rather than breaking rendering. - Tests: a fold-import test where a resource using a registered tagged-template intrinsic folds end-to-end through
tryFoldFilewith real plugin defs (not fabricated ones); an assertion that an intrinsic-using AWS example moves from run-fallback to fold with zero drift versus the run path.
Scope guard
Azure-style intrinsics (Concat(...), Reference(...)) are plain calls, not tagged templates. They stay unfoldable after this fix. That is expected and out of scope — do not try to fold plain-call intrinsics here.
Acceptance
-
chant build --foldon an AWS example usingSubfolds (logs[fold:fold], not[fold:run]), and folded output is identical to run output. - Both hardcoded
[]infold-import.tsare gone; intrinsics flow fromoptions.plugins. -
isTagaudited across all 11 lexicons; AWSSubisisTag: true; gitlabreference()no longer claims tagged-template status (without breaking its YAML rendering). -
just build,just test,just lintgreen. Any touched lexicon also passesnpm run build -w @intentius/chant-lexicon-<name>(lexicon tsc is CI-gated separately from core; aws is vitest-only).
Activity
docs: adversarial audit of fold / TypeScript-as-Data docs (#1038) (#1043
feat(core): lexicon contract must validate intrinsic foldability — an…
feat(core): fold registered call-form intrinsics — per-intrinsic opt-…
fix(lint): EVL rules receive the intrinsic/helper registry — lint sto…