@m4ike1/ion-cue 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +92 -0
  2. package/dist/dispatcher.d.ts +31 -0
  3. package/dist/dispatcher.d.ts.map +1 -0
  4. package/dist/dispatcher.js +230 -0
  5. package/dist/dispatcher.js.map +1 -0
  6. package/dist/harness-bridge.d.ts +13 -0
  7. package/dist/harness-bridge.d.ts.map +1 -0
  8. package/dist/harness-bridge.js +29 -0
  9. package/dist/harness-bridge.js.map +1 -0
  10. package/dist/harness-router.d.ts +12 -0
  11. package/dist/harness-router.d.ts.map +1 -0
  12. package/dist/harness-router.js +189 -0
  13. package/dist/harness-router.js.map +1 -0
  14. package/dist/index.d.ts +16 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +12 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/injector.d.ts +23 -0
  19. package/dist/injector.d.ts.map +1 -0
  20. package/dist/injector.js +62 -0
  21. package/dist/injector.js.map +1 -0
  22. package/dist/marks.d.ts +26 -0
  23. package/dist/marks.d.ts.map +1 -0
  24. package/dist/marks.js +59 -0
  25. package/dist/marks.js.map +1 -0
  26. package/dist/messages.d.ts +23 -0
  27. package/dist/messages.d.ts.map +1 -0
  28. package/dist/messages.js +2 -0
  29. package/dist/messages.js.map +1 -0
  30. package/dist/registry.d.ts +94 -0
  31. package/dist/registry.d.ts.map +1 -0
  32. package/dist/registry.js +582 -0
  33. package/dist/registry.js.map +1 -0
  34. package/dist/resolver.d.ts +15 -0
  35. package/dist/resolver.d.ts.map +1 -0
  36. package/dist/resolver.js +50 -0
  37. package/dist/resolver.js.map +1 -0
  38. package/dist/scanner.d.ts +32 -0
  39. package/dist/scanner.d.ts.map +1 -0
  40. package/dist/scanner.js +252 -0
  41. package/dist/scanner.js.map +1 -0
  42. package/dist/scope.d.ts +25 -0
  43. package/dist/scope.d.ts.map +1 -0
  44. package/dist/scope.js +180 -0
  45. package/dist/scope.js.map +1 -0
  46. package/dist/secret-store.d.ts +16 -0
  47. package/dist/secret-store.d.ts.map +1 -0
  48. package/dist/secret-store.js +89 -0
  49. package/dist/secret-store.js.map +1 -0
  50. package/dist/stream-events.d.ts +26 -0
  51. package/dist/stream-events.d.ts.map +1 -0
  52. package/dist/stream-events.js +2 -0
  53. package/dist/stream-events.js.map +1 -0
  54. package/dist/toml.d.ts +3 -0
  55. package/dist/toml.d.ts.map +1 -0
  56. package/dist/toml.js +117 -0
  57. package/dist/toml.js.map +1 -0
  58. package/dist/types.d.ts +182 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +2 -0
  61. package/dist/types.js.map +1 -0
  62. package/dist/validation.d.ts +5 -0
  63. package/dist/validation.d.ts.map +1 -0
  64. package/dist/validation.js +61 -0
  65. package/dist/validation.js.map +1 -0
  66. package/package.json +23 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMrD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAe;IAC9D,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,C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C;aAAM,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClD,MAAM,CAAC,SAAS,GAAG,KAAK;qBACtB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;qBACZ,KAAK,CAAC,GAAG,CAAC;qBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACV,CAAC;qBACC,IAAI,EAAE;qBACN,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;qBACzB,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAC3B;qBACA,MAAM,CAAC,OAAO,CAA0B,CAAC;YAC5C,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import { lstatSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { join } from \"path\";\nimport { parseElementToml } from \"./toml.ts\";\nimport type { BehavioralDimension, ElementDef, SectionRange } from \"./types.ts\";\nimport { detectCircularUses } from \"./validation.ts\";\n\nexport interface AliasConfig {\n\taliases: Record<string, string>;\n}\n\n/**\n * Parse alias configuration from a cue.toml-style config string.\n * Expects an [aliases] section with key = \"value\" pairs.\n */\nexport function parseAliasConfig(content: string): AliasConfig {\n\tconst aliases: Record<string, string> = {};\n\tconst lines = content.split(\"\\n\");\n\tlet inAliases = false;\n\n\tfor (const line of lines) {\n\t\tconst trimmed = line.trim();\n\t\tif (!trimmed || trimmed.startsWith(\"#\")) continue;\n\n\t\tif (trimmed === \"[aliases]\") {\n\t\t\tinAliases = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Exit aliases section on any other section header\n\t\tif (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\") && inAliases) {\n\t\t\tinAliases = false;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (inAliases) {\n\t\t\tconst kvMatch = trimmed.match(/^([a-zA-Z0-9_-]+)\\s*=\\s*(.+)$/);\n\t\t\tif (kvMatch) {\n\t\t\t\tconst key = kvMatch[1]!;\n\t\t\t\tlet value = kvMatch[2]!.trim();\n\t\t\t\t// Strip quotes\n\t\t\t\tif ((value.startsWith('\"') && value.endsWith('\"')) || (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n\t\t\t\t\tvalue = value.slice(1, -1);\n\t\t\t\t}\n\t\t\t\taliases[key] = value;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { aliases };\n}\n\nconst VALID_DIMENSIONS: BehavioralDimension[] = [\n\t\"tone\",\n\t\"register\",\n\t\"length\",\n\t\"depth\",\n\t\"structure\",\n\t\"format\",\n\t\"voice\",\n\t\"vocabulary\",\n];\n\ninterface ElementEntry {\n\tdef: ElementDef;\n\ttomlPath: string;\n\tmdPath: string;\n\tsectionIndex?: Map<string, SectionRange>;\n\tmtime?: number;\n}\n\ninterface SharedTagEntry {\n\tpath: string;\n\tsectionIndex?: Map<string, SectionRange>;\n\tmtime?: number;\n}\n\nexport interface CueRoot {\n\t/** Element root directory. */\n\tpath: string;\n\t/** Config scope the root belongs to (drives override matching). */\n\tscope: \"user\" | \"project\";\n}\n\n/**\n * Single source of truth for cue element discovery roots. Used by\n * CueRegistry.discover(), watchedPaths(), and the package manager's\n * resource collection so the config UI lists exactly what will load.\n */\nexport function cueDiscoveryRoots(\n\toptions: { projectRoot?: string; skipHome?: boolean; additionalRoots?: string[] } = {},\n): CueRoot[] {\n\tconst roots: CueRoot[] = (options.additionalRoots ?? []).map((path) => ({ path, scope: \"user\" as const }));\n\tif (!options.skipHome) {\n\t\troots.push({ path: join(homedir(), \".ion\", \"agent\", \"cue\", \"elements\"), scope: \"user\" });\n\t}\n\tif (options.projectRoot) {\n\t\troots.push({ path: join(options.projectRoot, \".ion\", \"cue\", \"elements\"), scope: \"project\" });\n\t}\n\treturn roots;\n}\n\nexport class CueRegistry {\n\tprivate elements = new Map<string, ElementEntry>();\n\tprivate sharedTags = new Map<string, SharedTagEntry>();\n\tprivate realpathCache = new Map<string, string>();\n\tprivate baseRoots: string[];\n\tprivate skipHome: boolean;\n\tprivate disabledNames = new Set<string>();\n\n\tconstructor(additionalRoots: string[] = [], options?: { skipHome?: boolean }) {\n\t\tthis.baseRoots = [...additionalRoots];\n\t\tthis.skipHome = options?.skipHome ?? false;\n\t}\n\n\tprivate computeRoots(projectRoot?: string): string[] {\n\t\treturn cueDiscoveryRoots({\n\t\t\tprojectRoot,\n\t\t\tskipHome: this.skipHome,\n\t\t\tadditionalRoots: this.baseRoots,\n\t\t}).map((r) => r.path);\n\t}\n\n\t/**\n\t * Idempotent: clears all discovered state and re-scans, so it is safe\n\t * to call again when watched files change (see watchedPaths).\n\t * `disabled` holds lowercased element names to skip (config UI toggles).\n\t */\n\tdiscover(projectRoot?: string, options?: { disabled?: string[] }): void {\n\t\tthis.elements.clear();\n\t\tthis.sharedTags.clear();\n\t\tthis.realpathCache.clear();\n\t\tconst roots = this.computeRoots(projectRoot);\n\t\tthis.disabledNames = new Set((options?.disabled ?? []).map((n) => n.toLowerCase()));\n\n\t\tfor (const root of roots) {\n\t\t\tthis.discoverFromRoot(root);\n\t\t}\n\n\t\tthis.discoverSharedTags(roots);\n\n\t\tconst defs = new Map<string, ElementDef>();\n\t\tfor (const [name, entry] of this.elements) {\n\t\t\tdefs.set(name, entry.def);\n\t\t}\n\t\tconst circularErrors = detectCircularUses(defs);\n\t\tfor (const err of circularErrors) {\n\t\t\tconsole.warn(err);\n\t\t}\n\t}\n\n\t/**\n\t * Existing directories whose changes invalidate discovery: element\n\t * roots, shared-tags dirs, and cue.toml parents. Callers watch these\n\t * (non-recursively) and call discover() again on change, then re-arm\n\t * to pick up newly created subdirectories.\n\t */\n\twatchedPaths(projectRoot?: string): string[] {\n\t\tconst dirs = new Set<string>();\n\t\tconst roots = this.computeRoots(projectRoot);\n\t\tfor (const root of roots) {\n\t\t\tdirs.add(root);\n\t\t\tdirs.add(join(root, \"..\", \"tags\"));\n\t\t\ttry {\n\t\t\t\tfor (const entry of readdirSync(root, { withFileTypes: true })) {\n\t\t\t\t\tif (entry.isDirectory()) dirs.add(join(root, entry.name));\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Root does not exist yet; the parent re-arm covers its creation.\n\t\t\t}\n\t\t}\n\t\t// Alias configs live next to the elements roots.\n\t\tif (!this.skipHome) dirs.add(join(homedir(), \".ion\", \"agent\", \"cue\"));\n\t\tif (projectRoot) dirs.add(join(projectRoot, \".ion\", \"cue\"));\n\t\tconst existing: string[] = [];\n\t\tfor (const dir of dirs) {\n\t\t\ttry {\n\t\t\t\tif (statSync(dir).isDirectory() && !existing.includes(dir)) existing.push(dir);\n\t\t\t} catch {\n\t\t\t\t// Does not exist yet; covered when the parent appears.\n\t\t\t}\n\t\t}\n\t\treturn existing;\n\t}\n\n\tprivate discoverSharedTags(roots: string[]): void {\n\t\tconst tagsDirs = [join(homedir(), \".ion\", \"agent\", \"cue\", \"tags\"), ...roots.map((r) => join(r, \"..\", \"tags\"))];\n\n\t\tfor (const tagsDir of tagsDirs) {\n\t\t\tlet entries: string[];\n\t\t\ttry {\n\t\t\t\tentries = readdirSync(tagsDir);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const file of entries) {\n\t\t\t\tif (!file.endsWith(\".md\")) continue;\n\t\t\t\tconst tagName = file.slice(0, -3).toLowerCase();\n\t\t\t\tif (this.sharedTags.has(tagName)) continue;\n\n\t\t\t\tconst filePath = join(tagsDir, file);\n\t\t\t\tthis.sharedTags.set(tagName, { path: filePath });\n\t\t\t}\n\t\t}\n\t}\n\n\tgetSharedTagSectionIndex(tagName: string): Map<string, SectionRange> | undefined {\n\t\tconst entry = this.sharedTags.get(tagName.toLowerCase());\n\t\tif (!entry) return undefined;\n\n\t\ttry {\n\t\t\tconst stat = statSync(entry.path);\n\t\t\tconst currentMtime = stat.mtimeMs;\n\n\t\t\tif (entry.sectionIndex && entry.mtime === currentMtime) {\n\t\t\t\treturn entry.sectionIndex;\n\t\t\t}\n\n\t\t\tconst body = readFileSync(entry.path, \"utf-8\");\n\t\t\tconst index = this.buildSectionIndex(body);\n\t\t\tentry.sectionIndex = index;\n\t\t\tentry.mtime = currentMtime;\n\t\t\treturn index;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tloadSharedTagBody(tagName: string): string | undefined {\n\t\tconst entry = this.sharedTags.get(tagName.toLowerCase());\n\t\tif (!entry) return undefined;\n\t\ttry {\n\t\t\treturn readFileSync(entry.path, \"utf-8\");\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tgetSharedTagOverrides(tagName: string): BehavioralDimension[] | undefined {\n\t\tconst entry = this.sharedTags.get(tagName.toLowerCase());\n\t\tif (!entry) return undefined;\n\n\t\ttry {\n\t\t\tconst body = readFileSync(entry.path, \"utf-8\");\n\t\t\tconst fm = parseFrontmatter(body);\n\t\t\treturn fm.overrides.length > 0 ? fm.overrides : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tgetSharedTagDefs(): Map<string, { description: string; overrides: BehavioralDimension[] }> {\n\t\tconst defs = new Map<string, { description: string; overrides: BehavioralDimension[] }>();\n\n\t\tfor (const [name, entry] of this.sharedTags) {\n\t\t\ttry {\n\t\t\t\tconst body = readFileSync(entry.path, \"utf-8\");\n\t\t\t\tconst fm = parseFrontmatter(body);\n\n\t\t\t\tif (!fm.description) {\n\t\t\t\t\tconst descMatch = body.match(/^##\\s+(?:Tag:\\s+)?[^\\n]+\\n+([^\\n#]+)/m);\n\t\t\t\t\tif (descMatch) fm.description = descMatch[1].trim();\n\t\t\t\t}\n\n\t\t\t\tdefs.set(name, fm);\n\t\t\t} catch {}\n\t\t}\n\n\t\treturn defs;\n\t}\n\n\tprivate discoverFromRoot(root: string): void {\n\t\tlet entries: string[];\n\t\ttry {\n\t\t\tentries = readdirSync(root);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rootTomls: string[] = [];\n\n\t\tfor (const authorDir of entries) {\n\t\t\tconst authorPath = join(root, authorDir);\n\t\t\tlet isDir = false;\n\t\t\ttry {\n\t\t\t\tisDir = statSync(authorPath).isDirectory();\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!isDir) {\n\t\t\t\tif (authorDir.endsWith(\".toml\")) rootTomls.push(authorDir);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlet authorEntries: string[];\n\t\t\ttry {\n\t\t\t\tauthorEntries = readdirSync(authorPath);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const entry of authorEntries) {\n\t\t\t\tif (!entry.endsWith(\".toml\")) continue;\n\t\t\t\tthis.registerElement(authorPath, entry);\n\t\t\t}\n\t\t}\n\n\t\tfor (const entry of rootTomls) {\n\t\t\tthis.registerElement(root, entry);\n\t\t}\n\t}\n\n\tprivate registerElement(dir: string, tomlFile: string): void {\n\t\tconst name = tomlFile.slice(0, -5);\n\t\tif (this.disabledNames.has(name.toLowerCase())) return;\n\t\tconst tomlPath = join(dir, tomlFile);\n\t\tconst mdPath = join(dir, `${name}.md`);\n\n\t\ttry {\n\t\t\tstatSync(mdPath);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tconst realToml = this.resolveRealpath(tomlPath);\n\t\tif (this.isDuplicate(realToml)) return;\n\n\t\tconst content = readFileSync(tomlPath, \"utf-8\");\n\t\tconst def = parseElementToml(content);\n\n\t\tconst normalized = def.name.toLowerCase();\n\t\tconst versionedKey = def.version ? `${normalized}@${def.version}` : normalized;\n\n\t\t// Store versioned entry\n\t\tif (this.elements.has(versionedKey)) {\n\t\t\tconsole.warn(`Element \"${def.name}@${def.version}\" from ${tomlPath} shadowed by earlier definition; skipping`);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.validateElement(def);\n\n\t\ttry {\n\t\t\tconst mdBody = readFileSync(mdPath, \"utf-8\");\n\t\t\tthis.validateTagHeaderAlignment(def, mdBody, normalized);\n\t\t} catch {\n\t\t\t// md read failure already handled by missing stat above\n\t\t}\n\n\t\tconst entry: ElementEntry = { def, tomlPath, mdPath };\n\t\tthis.elements.set(versionedKey, entry);\n\n\t\t// Also store under plain name if this is the latest version or first registration\n\t\tif (!this.elements.has(normalized)) {\n\t\t\tthis.elements.set(normalized, entry);\n\t\t} else {\n\t\t\t// Compare versions: keep the latest under the plain name\n\t\t\tconst existing = this.elements.get(normalized)!;\n\t\t\tif (def.version && existing.def.version && this.compareVersions(def.version, existing.def.version) > 0) {\n\t\t\t\tthis.elements.set(normalized, entry);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate resolveRealpath(path: string): string {\n\t\tconst cached = this.realpathCache.get(path);\n\t\tif (cached) return cached;\n\n\t\tlet real: string;\n\t\ttry {\n\t\t\tconst stat = lstatSync(path);\n\t\t\tif (stat.isSymbolicLink()) {\n\t\t\t\tconst { realpathSync } = require(\"fs\");\n\t\t\t\treal = realpathSync(path);\n\t\t\t} else {\n\t\t\t\treal = path;\n\t\t\t}\n\t\t} catch {\n\t\t\treal = path;\n\t\t}\n\n\t\tthis.realpathCache.set(path, real);\n\t\treturn real;\n\t}\n\n\tprivate isDuplicate(realpath: string): boolean {\n\t\tfor (const entry of this.elements.values()) {\n\t\t\tif (this.resolveRealpath(entry.tomlPath) === realpath) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Load aliases from cue.toml config files in project root.\n\t * Project-level aliases override home-level aliases.\n\t */\n\tloadAliases(projectRoot?: string): Record<string, string> {\n\t\tconst aliases: Record<string, string> = {};\n\n\t\t// Home directory config\n\t\tif (!this.skipHome) {\n\t\t\tconst homeConfig = join(homedir(), \".ion\", \"agent\", \"cue\", \"cue.toml\");\n\t\t\ttry {\n\t\t\t\tconst content = readFileSync(homeConfig, \"utf-8\");\n\t\t\t\tconst parsed = parseAliasConfig(content);\n\t\t\t\tObject.assign(aliases, parsed.aliases);\n\t\t\t} catch {\n\t\t\t\t// Config file doesn't exist or unreadable, skip\n\t\t\t}\n\t\t}\n\n\t\t// Project directory config (overrides home)\n\t\tif (projectRoot) {\n\t\t\tconst projectConfig = join(projectRoot, \".ion\", \"cue\", \"cue.toml\");\n\t\t\ttry {\n\t\t\t\tconst content = readFileSync(projectConfig, \"utf-8\");\n\t\t\t\tconst parsed = parseAliasConfig(content);\n\t\t\t\tObject.assign(aliases, parsed.aliases);\n\t\t\t} catch {\n\t\t\t\t// Config file doesn't exist or unreadable, skip\n\t\t\t}\n\t\t}\n\n\t\treturn aliases;\n\t}\n\n\tprivate validateElement(def: ElementDef): void {\n\t\tif (def.class === \"harness\" && !def.handler) {\n\t\t\tconsole.warn(`Element \"${def.name}\" has class harness but no handler`);\n\t\t}\n\n\t\tfor (const [tagName, tagDef] of Object.entries(def.tags)) {\n\t\t\tfor (const dim of tagDef.overrides) {\n\t\t\t\tif (!VALID_DIMENSIONS.includes(dim)) {\n\t\t\t\t\tconsole.warn(`Element \"${def.name}\" tag \"${tagName}\" has invalid override dimension: ${dim}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate validateTagHeaderAlignment(def: ElementDef, body: string, elementName: string): void {\n\t\tconst headerRe = /^##\\s+Tag:\\s+(.+)$/gm;\n\t\tconst headerTags = new Map<string, string>();\n\n\t\tfor (let match = headerRe.exec(body); match !== null; match = headerRe.exec(body)) {\n\t\t\tconst originalName = match[1].trim();\n\t\t\tconst normalizedName = originalName.toLowerCase().replace(/\\s+/g, \"-\");\n\t\t\theaderTags.set(normalizedName, originalName);\n\t\t}\n\n\t\tconst tomlTags = new Set(Object.keys(def.tags).map((t) => t.toLowerCase()));\n\n\t\tfor (const [normalizedTag, originalTag] of headerTags) {\n\t\t\tif (!tomlTags.has(normalizedTag)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Element \"${elementName}\" has orphan tag header \"## Tag: ${originalTag}\" with no [tags.${normalizedTag}] TOML entry`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfor (const tag of tomlTags) {\n\t\t\tif (!headerTags.has(tag)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Element \"${elementName}\" has undeclared [tags.${tag}] TOML entry with no matching \"## Tag:\" header`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tget(name: string): ElementDef | undefined {\n\t\treturn this.elements.get(name.toLowerCase())?.def;\n\t}\n\n\t/**\n\t * Get an element by name and optional version.\n\t * If version is provided, tries to find the exact version first, then falls back to latest compatible.\n\t * If version is not provided, returns the latest version.\n\t */\n\tgetByVersion(name: string, version?: string): ElementDef | undefined {\n\t\tconst normalized = name.toLowerCase();\n\n\t\tif (!version) {\n\t\t\t// No version pin: return latest\n\t\t\treturn this.elements.get(normalized)?.def;\n\t\t}\n\n\t\t// Try exact version match first\n\t\tconst versionedKey = `${normalized}@${version}`;\n\t\tconst exact = this.elements.get(versionedKey);\n\t\tif (exact) return exact.def;\n\n\t\t// Try prefix match for semver (e.g., \"1.2\" matches \"1.2.x\")\n\t\tconst prefix = version.endsWith(\".\") ? version : `${version}.`;\n\t\tfor (const [key, entry] of this.elements) {\n\t\t\tif (key.startsWith(`${normalized}@`) && key.slice(normalized.length + 1).startsWith(prefix)) {\n\t\t\t\treturn entry.def;\n\t\t\t}\n\t\t}\n\n\t\t// Fall back to latest\n\t\treturn this.elements.get(normalized)?.def;\n\t}\n\n\t/**\n\t * Compare two semver versions.\n\t * Returns positive if a > b, negative if a < b, 0 if equal.\n\t */\n\tprivate compareVersions(a: string, b: string): number {\n\t\tconst parseVersion = (v: string) => {\n\t\t\tconst parts = v.split(\".\").map((p) => parseInt(p, 10) || 0);\n\t\t\treturn { major: parts[0] ?? 0, minor: parts[1] ?? 0, patch: parts[2] ?? 0 };\n\t\t};\n\n\t\tconst va = parseVersion(a);\n\t\tconst vb = parseVersion(b);\n\n\t\tif (va.major !== vb.major) return va.major - vb.major;\n\t\tif (va.minor !== vb.minor) return va.minor - vb.minor;\n\t\treturn va.patch - vb.patch;\n\t}\n\n\thas(name: string): boolean {\n\t\treturn this.elements.has(name.toLowerCase());\n\t}\n\n\tlist(): ElementDef[] {\n\t\t// Deduplicate: versioned keys and plain-name keys point to the same entry.\n\t\t// Return only one entry per element by tracking seen toml paths.\n\t\tconst seen = new Set<string>();\n\t\tconst result: ElementDef[] = [];\n\t\tfor (const entry of this.elements.values()) {\n\t\t\tif (seen.has(entry.tomlPath)) continue;\n\t\t\tseen.add(entry.tomlPath);\n\t\t\tresult.push(entry.def);\n\t\t}\n\t\treturn result;\n\t}\n\n\tgetSectionIndex(name: string): Map<string, SectionRange> | undefined {\n\t\tconst entry = this.elements.get(name.toLowerCase());\n\t\tif (!entry) return undefined;\n\n\t\tconst stat = statSync(entry.mdPath);\n\t\tconst currentMtime = stat.mtimeMs;\n\n\t\tif (entry.sectionIndex && entry.mtime === currentMtime) {\n\t\t\treturn entry.sectionIndex;\n\t\t}\n\n\t\tconst body = readFileSync(entry.mdPath, \"utf-8\");\n\t\tconst index = this.buildSectionIndex(body);\n\t\tentry.sectionIndex = index;\n\t\tentry.mtime = currentMtime;\n\t\treturn index;\n\t}\n\n\tloadBody(name: string): string | undefined {\n\t\tconst entry = this.elements.get(name.toLowerCase());\n\t\tif (!entry) return undefined;\n\t\ttry {\n\t\t\treturn readFileSync(entry.mdPath, \"utf-8\");\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Load body for a specific version of an element.\n\t */\n\tloadBodyByVersion(name: string, version?: string): string | undefined {\n\t\tconst normalized = name.toLowerCase();\n\n\t\tif (!version) {\n\t\t\treturn this.loadBody(name);\n\t\t}\n\n\t\t// Try exact version match first\n\t\tconst versionedKey = `${normalized}@${version}`;\n\t\tconst exact = this.elements.get(versionedKey);\n\t\tif (exact) {\n\t\t\ttry {\n\t\t\t\treturn readFileSync(exact.mdPath, \"utf-8\");\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\t// Fall back to latest\n\t\treturn this.loadBody(name);\n\t}\n\n\tgetMdPath(name: string): string | undefined {\n\t\treturn this.elements.get(name.toLowerCase())?.mdPath;\n\t}\n\n\tprivate buildSectionIndex(body: string): Map<string, SectionRange> {\n\t\tconst index = new Map<string, SectionRange>();\n\t\tconst headerRe = /^##\\s+(?:Tag:\\s+)?(.+)$/gm;\n\t\tconst headerPositions: Array<{ name: string; pos: number }> = [];\n\n\t\tfor (let match = headerRe.exec(body); match !== null; match = headerRe.exec(body)) {\n\t\t\theaderPositions.push({ name: match[1].trim(), pos: match.index });\n\t\t}\n\n\t\tfor (let i = 0; i < headerPositions.length; i++) {\n\t\t\tconst start = headerPositions[i].pos;\n\t\t\tconst end = i + 1 < headerPositions.length ? headerPositions[i + 1].pos : body.length;\n\t\t\tconst name = headerPositions[i].name;\n\n\t\t\tif (name.toLowerCase() === \"default behavior\") {\n\t\t\t\tindex.set(\"default\", { start, end, tag: \"default\" });\n\t\t\t} else if (name.toLowerCase().startsWith(\"tag:\")) {\n\t\t\t\tconst tag = name.slice(4).trim();\n\t\t\t\tindex.set(tag.toLowerCase(), { start, end, tag });\n\t\t\t} else {\n\t\t\t\tindex.set(name.toLowerCase(), { start, end, tag: name });\n\t\t\t}\n\t\t}\n\n\t\treturn index;\n\t}\n}\n\nfunction parseFrontmatter(body: string): { description: string; overrides: BehavioralDimension[] } {\n\tconst result: { description: string; overrides: BehavioralDimension[] } = { description: \"\", overrides: [] };\n\n\tconst fmMatch = body.match(/^---\\s*\\n([\\s\\S]*?)\\n---/);\n\tif (!fmMatch) return result;\n\n\tconst fm = fmMatch[1];\n\tfor (const line of fm.split(\"\\n\")) {\n\t\tconst trimmed = line.trim();\n\t\tif (!trimmed || trimmed.startsWith(\"#\")) continue;\n\n\t\tconst kvMatch = trimmed.match(/^([a-zA-Z_-]+)\\s*[:=]\\s*(.+)$/);\n\t\tif (!kvMatch) continue;\n\n\t\tconst [, key, valueStr] = kvMatch;\n\t\tif (key === \"description\") {\n\t\t\tresult.description = valueStr\n\t\t\t\t.trim()\n\t\t\t\t.replace(/^\"(.*)\"$/, \"$1\")\n\t\t\t\t.replace(/^'(.*)'$/, \"$1\");\n\t\t} else if (key === \"overrides\") {\n\t\t\tconst inner = valueStr.trim();\n\t\t\tif (inner.startsWith(\"[\") && inner.endsWith(\"]\")) {\n\t\t\t\tresult.overrides = inner\n\t\t\t\t\t.slice(1, -1)\n\t\t\t\t\t.split(\",\")\n\t\t\t\t\t.map((s) =>\n\t\t\t\t\t\ts\n\t\t\t\t\t\t\t.trim()\n\t\t\t\t\t\t\t.replace(/^\"(.*)\"$/, \"$1\")\n\t\t\t\t\t\t\t.replace(/^'(.*)'$/, \"$1\"),\n\t\t\t\t\t)\n\t\t\t\t\t.filter(Boolean) as BehavioralDimension[];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { CueRegistry } from "./registry.ts";
2
+ import type { CueDirective, ElementDef, SectionRange } from "./types.ts";
3
+ export interface ResolvedDirective {
4
+ directive: CueDirective;
5
+ element: ElementDef;
6
+ sections: string[];
7
+ text: string;
8
+ }
9
+ export interface ResolvedSection {
10
+ range: SectionRange;
11
+ sourceBody: string;
12
+ }
13
+ export declare function resolveSections(element: ElementDef, tags: string[], body: string, sectionIndex: Map<string, SectionRange>, registry?: CueRegistry): ResolvedSection[];
14
+ export declare function resolveDirective(directive: CueDirective, registry: CueRegistry): ResolvedDirective | null;
15
+ //# sourceMappingURL=resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,WAAW,iBAAiB;IACjC,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAC9B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EACvC,QAAQ,CAAC,EAAE,WAAW,GACpB,eAAe,EAAE,CA8CnB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,GAAG,iBAAiB,GAAG,IAAI,CAazG","sourcesContent":["import type { CueRegistry } from \"./registry.ts\";\nimport type { CueDirective, ElementDef, SectionRange } from \"./types.ts\";\n\nexport interface ResolvedDirective {\n\tdirective: CueDirective;\n\telement: ElementDef;\n\tsections: string[];\n\ttext: string;\n}\n\nexport interface ResolvedSection {\n\trange: SectionRange;\n\tsourceBody: string;\n}\n\nexport function resolveSections(\n\telement: ElementDef,\n\ttags: string[],\n\tbody: string,\n\tsectionIndex: Map<string, SectionRange>,\n\tregistry?: CueRegistry,\n): ResolvedSection[] {\n\tconst sections: ResolvedSection[] = [];\n\n\tconst defaultSection = sectionIndex.get(\"default\");\n\tif (defaultSection) {\n\t\tconst hasExclusive = tags.some((t) => {\n\t\t\tconst slug = t.toLowerCase().replace(/[\\s-]+/g, \"-\");\n\t\t\tconst tagDef = element.tags[slug];\n\t\t\treturn tagDef?.exclusive;\n\t\t});\n\t\tif (!hasExclusive) {\n\t\t\tsections.push({ range: defaultSection, sourceBody: body });\n\t\t}\n\t}\n\n\tfor (const tag of tags) {\n\t\tconst normalized = tag.toLowerCase().replace(/[\\s-]+/g, \"-\");\n\t\tlet range: SectionRange | undefined = Array.from(sectionIndex.values()).find(\n\t\t\t(s: SectionRange) => s.tag.toLowerCase().replace(/[\\s-]+/g, \"-\") === normalized,\n\t\t);\n\t\tlet rangeBody = body;\n\n\t\tif (!range && registry) {\n\t\t\tconst usesEntry = element.uses.find(\n\t\t\t\t(u: { tag: string; source: string }) => u.tag.toLowerCase().replace(/[\\s-]+/g, \"-\") === normalized,\n\t\t\t);\n\n\t\t\tconst sharedTag = usesEntry ? usesEntry.tag : normalized;\n\t\t\tconst sharedIndex = registry.getSharedTagSectionIndex(sharedTag);\n\t\t\tif (sharedIndex) {\n\t\t\t\trange = Array.from(sharedIndex.values()).find(\n\t\t\t\t\t(s: SectionRange) => s.tag.toLowerCase().replace(/[\\s-]+/g, \"-\") === normalized,\n\t\t\t\t);\n\t\t\t\tif (range) {\n\t\t\t\t\tconst sharedBody = registry.loadSharedTagBody(sharedTag);\n\t\t\t\t\tif (sharedBody !== undefined) rangeBody = sharedBody;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (range) {\n\t\t\tsections.push({ range, sourceBody: rangeBody });\n\t\t}\n\t}\n\n\treturn sections;\n}\n\nexport function resolveDirective(directive: CueDirective, registry: CueRegistry): ResolvedDirective | null {\n\tconst element = registry.getByVersion(directive.element, directive.version);\n\tif (!element) return null;\n\n\tconst body = registry.loadBodyByVersion(directive.element, directive.version);\n\tconst sectionIndex = registry.getSectionIndex(directive.element);\n\tif (!body || !sectionIndex) return null;\n\n\tconst sectionRanges = resolveSections(element, directive.tags, body, sectionIndex, registry);\n\tconst sections = sectionRanges.map((r) => r.sourceBody.slice(r.range.start, r.range.end).trim());\n\tconst text = sections.join(\"\\n\\n\");\n\n\treturn { directive, element, sections, text };\n}\n"]}
@@ -0,0 +1,50 @@
1
+ export function resolveSections(element, tags, body, sectionIndex, registry) {
2
+ const sections = [];
3
+ const defaultSection = sectionIndex.get("default");
4
+ if (defaultSection) {
5
+ const hasExclusive = tags.some((t) => {
6
+ const slug = t.toLowerCase().replace(/[\s-]+/g, "-");
7
+ const tagDef = element.tags[slug];
8
+ return tagDef?.exclusive;
9
+ });
10
+ if (!hasExclusive) {
11
+ sections.push({ range: defaultSection, sourceBody: body });
12
+ }
13
+ }
14
+ for (const tag of tags) {
15
+ const normalized = tag.toLowerCase().replace(/[\s-]+/g, "-");
16
+ let range = Array.from(sectionIndex.values()).find((s) => s.tag.toLowerCase().replace(/[\s-]+/g, "-") === normalized);
17
+ let rangeBody = body;
18
+ if (!range && registry) {
19
+ const usesEntry = element.uses.find((u) => u.tag.toLowerCase().replace(/[\s-]+/g, "-") === normalized);
20
+ const sharedTag = usesEntry ? usesEntry.tag : normalized;
21
+ const sharedIndex = registry.getSharedTagSectionIndex(sharedTag);
22
+ if (sharedIndex) {
23
+ range = Array.from(sharedIndex.values()).find((s) => s.tag.toLowerCase().replace(/[\s-]+/g, "-") === normalized);
24
+ if (range) {
25
+ const sharedBody = registry.loadSharedTagBody(sharedTag);
26
+ if (sharedBody !== undefined)
27
+ rangeBody = sharedBody;
28
+ }
29
+ }
30
+ }
31
+ if (range) {
32
+ sections.push({ range, sourceBody: rangeBody });
33
+ }
34
+ }
35
+ return sections;
36
+ }
37
+ export function resolveDirective(directive, registry) {
38
+ const element = registry.getByVersion(directive.element, directive.version);
39
+ if (!element)
40
+ return null;
41
+ const body = registry.loadBodyByVersion(directive.element, directive.version);
42
+ const sectionIndex = registry.getSectionIndex(directive.element);
43
+ if (!body || !sectionIndex)
44
+ return null;
45
+ const sectionRanges = resolveSections(element, directive.tags, body, sectionIndex, registry);
46
+ const sections = sectionRanges.map((r) => r.sourceBody.slice(r.range.start, r.range.end).trim());
47
+ const text = sections.join("\n\n");
48
+ return { directive, element, sections, text };
49
+ }
50
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":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C9E,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjE,IAAI,CAAC,IAAI,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAExC,MAAM,aAAa,GAAG,eAAe,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7F,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACjG,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEnC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAAA,CAC9C","sourcesContent":["import type { CueRegistry } from \"./registry.ts\";\nimport type { CueDirective, ElementDef, SectionRange } from \"./types.ts\";\n\nexport interface ResolvedDirective {\n\tdirective: CueDirective;\n\telement: ElementDef;\n\tsections: string[];\n\ttext: string;\n}\n\nexport interface ResolvedSection {\n\trange: SectionRange;\n\tsourceBody: string;\n}\n\nexport function resolveSections(\n\telement: ElementDef,\n\ttags: string[],\n\tbody: string,\n\tsectionIndex: Map<string, SectionRange>,\n\tregistry?: CueRegistry,\n): ResolvedSection[] {\n\tconst sections: ResolvedSection[] = [];\n\n\tconst defaultSection = sectionIndex.get(\"default\");\n\tif (defaultSection) {\n\t\tconst hasExclusive = tags.some((t) => {\n\t\t\tconst slug = t.toLowerCase().replace(/[\\s-]+/g, \"-\");\n\t\t\tconst tagDef = element.tags[slug];\n\t\t\treturn tagDef?.exclusive;\n\t\t});\n\t\tif (!hasExclusive) {\n\t\t\tsections.push({ range: defaultSection, sourceBody: body });\n\t\t}\n\t}\n\n\tfor (const tag of tags) {\n\t\tconst normalized = tag.toLowerCase().replace(/[\\s-]+/g, \"-\");\n\t\tlet range: SectionRange | undefined = Array.from(sectionIndex.values()).find(\n\t\t\t(s: SectionRange) => s.tag.toLowerCase().replace(/[\\s-]+/g, \"-\") === normalized,\n\t\t);\n\t\tlet rangeBody = body;\n\n\t\tif (!range && registry) {\n\t\t\tconst usesEntry = element.uses.find(\n\t\t\t\t(u: { tag: string; source: string }) => u.tag.toLowerCase().replace(/[\\s-]+/g, \"-\") === normalized,\n\t\t\t);\n\n\t\t\tconst sharedTag = usesEntry ? usesEntry.tag : normalized;\n\t\t\tconst sharedIndex = registry.getSharedTagSectionIndex(sharedTag);\n\t\t\tif (sharedIndex) {\n\t\t\t\trange = Array.from(sharedIndex.values()).find(\n\t\t\t\t\t(s: SectionRange) => s.tag.toLowerCase().replace(/[\\s-]+/g, \"-\") === normalized,\n\t\t\t\t);\n\t\t\t\tif (range) {\n\t\t\t\t\tconst sharedBody = registry.loadSharedTagBody(sharedTag);\n\t\t\t\t\tif (sharedBody !== undefined) rangeBody = sharedBody;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (range) {\n\t\t\tsections.push({ range, sourceBody: rangeBody });\n\t\t}\n\t}\n\n\treturn sections;\n}\n\nexport function resolveDirective(directive: CueDirective, registry: CueRegistry): ResolvedDirective | null {\n\tconst element = registry.getByVersion(directive.element, directive.version);\n\tif (!element) return null;\n\n\tconst body = registry.loadBodyByVersion(directive.element, directive.version);\n\tconst sectionIndex = registry.getSectionIndex(directive.element);\n\tif (!body || !sectionIndex) return null;\n\n\tconst sectionRanges = resolveSections(element, directive.tags, body, sectionIndex, registry);\n\tconst sections = sectionRanges.map((r) => r.sourceBody.slice(r.range.start, r.range.end).trim());\n\tconst text = sections.join(\"\\n\\n\");\n\n\treturn { directive, element, sections, text };\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import type { CueDirective, Directive, ScanError } from "./types.ts";
2
+ export interface ScanResult {
3
+ directives: Directive[];
4
+ stripped: string;
5
+ errors: ScanError[];
6
+ }
7
+ /**
8
+ * Scan for directives and standalone scope statements.
9
+ *
10
+ * `excludedRanges` marks spans of the input that must not be scanned (e.g.
11
+ * mark content blocks, which are injected verbatim, not interpreted).
12
+ */
13
+ export declare function scanDirectives(input: string, excludedRanges?: Array<{
14
+ start: number;
15
+ end: number;
16
+ }>): ScanResult;
17
+ /** Remove the given spans from the input, collapsing runs of whitespace. */
18
+ export declare function stripSpans(input: string, spans: Array<{
19
+ start: number;
20
+ end: number;
21
+ }>): string;
22
+ export declare function scan(input: string): CueDirective[];
23
+ export interface FencedRange {
24
+ start: number;
25
+ end: number;
26
+ }
27
+ export declare function findFencedBlocks(input: string): FencedRange[];
28
+ export declare function isInsideFencedBlock(pos: number, ranges: Array<{
29
+ start: number;
30
+ end: number;
31
+ }>): boolean;
32
+ //# sourceMappingURL=scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EAEZ,SAAS,EACT,SAAS,EAGT,MAAM,YAAY,CAAC;AAUpB,MAAM,WAAW,UAAU;IAC1B,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,UAAU,CA4GhH;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAU9F;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CA6BlD;AA6ED,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CA4B7D;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,OAAO,CAEvG","sourcesContent":["import type {\n\tAliasCommand,\n\tCueDirective,\n\tCueScope,\n\tDirective,\n\tScanError,\n\tScopeOnlyStatement,\n\tSystemNavCommand,\n} from \"./types.ts\";\n\nconst DIRECTIVE_RE = /\\[([A-Za-z][A-Za-z0-9_-]*)(?::\\s*([^\\]]*?))?\\]/g;\n\n// Pattern to detect malformed directives: [Word Word] without colon\nconst MALFORMED_RE = /\\[([A-Za-z][A-Za-z0-9_-]*)\\s+([A-Za-z][A-Za-z0-9_-]*)\\]/g;\n\n// Standalone scope statements: {@path}, {path}, {path:10-20}, {#id}\nconst SCOPE_ONLY_RE = /\\{([^}\\n]*)\\}/g;\n\nexport interface ScanResult {\n\tdirectives: Directive[];\n\tstripped: string;\n\terrors: ScanError[];\n}\n\n/**\n * Scan for directives and standalone scope statements.\n *\n * `excludedRanges` marks spans of the input that must not be scanned (e.g.\n * mark content blocks, which are injected verbatim, not interpreted).\n */\nexport function scanDirectives(input: string, excludedRanges?: Array<{ start: number; end: number }>): ScanResult {\n\tconst fencedRanges = findFencedBlocks(input);\n\tconst skipRanges = [...fencedRanges, ...(excludedRanges ?? [])];\n\tconst directives: Directive[] = [];\n\tconst errors: ScanError[] = [];\n\n\tconst systemNav = scanSystemNav(input);\n\tif (systemNav) {\n\t\treturn { directives: [{ kind: \"system-nav\", command: systemNav }], stripped: \"\", errors };\n\t}\n\n\tconst alias = scanAlias(input);\n\tif (alias) {\n\t\treturn { directives: [{ kind: \"alias\", command: alias }], stripped: \"\", errors };\n\t}\n\n\tconst cueRe = new RegExp(DIRECTIVE_RE.source, \"g\");\n\n\tfor (let match = cueRe.exec(input); match !== null; match = cueRe.exec(input)) {\n\t\tconst start = match.index;\n\n\t\tif (isInsideFencedBlock(start, skipRanges)) continue;\n\n\t\tconst [raw, elementRaw, tagChain] = match;\n\t\tconst element = elementRaw.trim();\n\t\tconst tags = tagChain\n\t\t\t? tagChain\n\t\t\t\t\t.split(\">\")\n\t\t\t\t\t.map((t) => t.trim())\n\t\t\t\t\t.filter(Boolean)\n\t\t\t: [];\n\t\tconst scope = null;\n\n\t\tconst beforeMatch = input.slice(0, match.index);\n\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\tconst col = match.index - lastNewline;\n\n\t\tdirectives.push({\n\t\t\tkind: \"cue\",\n\t\t\tdirective: { raw, element, tags, scope, line, col, position: start },\n\t\t});\n\t}\n\n\t// Standalone scope statements: {@file}, {file}, {file:10-20}, {#id}\n\tconst scopeRe = new RegExp(SCOPE_ONLY_RE.source, \"g\");\n\tfor (let match = scopeRe.exec(input); match !== null; match = scopeRe.exec(input)) {\n\t\tconst start = match.index;\n\n\t\tif (isInsideFencedBlock(start, skipRanges)) continue;\n\n\t\tconst raw = match[1] ?? \"\";\n\t\tconst parsed = parseScope(raw);\n\t\tif (\"error\" in parsed) {\n\t\t\tconst beforeMatch = input.slice(0, start);\n\t\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\t\tconst col = start - lastNewline;\n\t\t\terrors.push({ message: parsed.error, raw: match[0], line, col });\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst statement: ScopeOnlyStatement = { scope: parsed.scope, position: start, raw: match[0] };\n\t\tdirectives.push({ kind: \"scope-only\", statement });\n\t}\n\n\t// Detect malformed directives: [Word Word] without colon\n\tconst malformedRe = new RegExp(MALFORMED_RE.source, \"g\");\n\tfor (let match = malformedRe.exec(input); match !== null; match = malformedRe.exec(input)) {\n\t\tconst start = match.index;\n\t\tif (isInsideFencedBlock(start, skipRanges)) continue;\n\n\t\t// Check if this was already matched as a valid directive\n\t\tconst wasMatched = directives.some((d) => {\n\t\t\tif (d.kind !== \"cue\") return false;\n\t\t\tconst dirStart = d.directive.position ?? input.indexOf(d.directive.raw);\n\t\t\treturn dirStart <= start && start < dirStart + d.directive.raw.length;\n\t\t});\n\t\tif (wasMatched) continue;\n\n\t\tconst beforeMatch = input.slice(0, start);\n\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\tconst col = start - lastNewline;\n\n\t\terrors.push({\n\t\t\tmessage: `Malformed directive \"${match[0]}\" — did you mean \"[${match[1]}: ${match[2]}]\"?`,\n\t\t\traw: match[0],\n\t\t\tline,\n\t\t\tcol,\n\t\t});\n\t}\n\n\t// Strip directives by span, preserving everything else\n\tconst spans = directives\n\t\t.map((d) => {\n\t\t\tif (d.kind === \"cue\") {\n\t\t\t\tconst start = d.directive.position ?? input.indexOf(d.directive.raw);\n\t\t\t\treturn { start, end: start + d.directive.raw.length };\n\t\t\t}\n\t\t\tif (d.kind !== \"scope-only\") {\n\t\t\t\tthrow new Error(\"unreachable: system-nav/alias return early\");\n\t\t\t}\n\t\t\treturn { start: d.statement.position, end: d.statement.position + d.statement.raw.length };\n\t\t})\n\t\t.sort((a, b) => a.start - b.start);\n\n\treturn { directives, stripped: stripSpans(input, spans), errors };\n}\n\n/** Remove the given spans from the input, collapsing runs of whitespace. */\nexport function stripSpans(input: string, spans: Array<{ start: number; end: number }>): string {\n\tlet stripped = \"\";\n\tlet cursor = 0;\n\tfor (const span of spans) {\n\t\tstripped += input.slice(cursor, span.start);\n\t\tcursor = span.end;\n\t}\n\tstripped += input.slice(cursor);\n\n\treturn stripped.replace(/\\s{2,}/g, \" \").trim();\n}\n\nexport function scan(input: string): CueDirective[] {\n\tconst fencedRanges = findFencedBlocks(input);\n\tconst directives: CueDirective[] = [];\n\n\tconst cueRe = new RegExp(DIRECTIVE_RE.source, \"g\");\n\n\tfor (let match = cueRe.exec(input); match !== null; match = cueRe.exec(input)) {\n\t\tconst start = match.index;\n\n\t\tif (isInsideFencedBlock(start, fencedRanges)) continue;\n\n\t\tconst [raw, elementRaw, tagChain] = match;\n\t\tconst element = elementRaw.trim();\n\t\tconst tags = tagChain\n\t\t\t? tagChain\n\t\t\t\t\t.split(\">\")\n\t\t\t\t\t.map((t) => t.trim())\n\t\t\t\t\t.filter(Boolean)\n\t\t\t: [];\n\n\t\tconst beforeMatch = input.slice(0, match.index);\n\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\tconst col = match.index - lastNewline;\n\n\t\tdirectives.push({ raw, element, tags, scope: null, line, col, position: start });\n\t}\n\n\treturn directives;\n}\n\nfunction scanSystemNav(input: string): SystemNavCommand | null {\n\tconst trimmed = input.trimStart();\n\tif (!trimmed.startsWith(\":\")) return null;\n\tconst firstLine = trimmed.split(\"\\n\")[0];\n\tconst match = firstLine.match(/^:(\\w+)\\s*(.*)?$/);\n\tif (!match) return null;\n\treturn { command: match[1], arg: match[2]?.trim() || undefined };\n}\n\nfunction scanAlias(input: string): AliasCommand | null {\n\tconst trimmed = input.trimStart();\n\tif (!trimmed.startsWith(\"/\")) return null;\n\tconst firstLine = trimmed.split(\"\\n\")[0];\n\tconst match = firstLine.match(/^\\/(\\w+)/);\n\tif (!match) return null;\n\treturn { command: match[1] };\n}\n\ntype ParsedScope = { scope: CueScope } | { error: string };\n\n/**\n * Parse the inner content of a scope statement.\n *\n * - `@path`, `path` → file (a trailing slash targets a directory)\n * - `@path:10-20`, `path:10-` → file + line range (open bounds allowed)\n * - `@glob`, `glob` → glob (contains `*` or `?`)\n * - `#id` → mark reference\n *\n * The `@` is optional — `{path}` and `{@path}` are equivalent.\n */\nfunction parseScope(raw: string): ParsedScope {\n\tif (raw.startsWith(\"#\")) {\n\t\tconst id = raw.slice(1);\n\t\tif (id === \"\") return { error: \"Empty mark identifier — expected {#name}\" };\n\t\tif (!/^[A-Za-z0-9_-]+$/.test(id)) return { error: `Malformed mark identifier \"{${raw}}\"` };\n\t\treturn { scope: { type: \"id\", value: id } };\n\t}\n\n\t// {$name} — skill reference, passed through for skill expansion\n\tif (raw.startsWith(\"$\")) {\n\t\tconst name = raw.slice(1);\n\t\tif (name === \"\") return { error: \"Empty skill reference — expected {$name}\" };\n\t\tif (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name)) return { error: `Malformed skill reference \"{${raw}}\"` };\n\t\treturn { scope: { type: \"skill\", value: name } };\n\t}\n\n\tlet ref = raw;\n\tif (ref.startsWith(\"@\")) ref = ref.slice(1);\n\tif (ref.trim() === \"\") return { error: \"Empty scope path — expected {@path}\" };\n\n\t// Line range: {@path:start-end}, {@path:start-}, {@path:-end}, {@path:start}\n\tconst rangeMatch = ref.match(/^(.+):(\\d+-\\d+|\\d+-|-\\d+|\\d+)$/);\n\tlet range: { start?: number; end?: number } | undefined;\n\tif (rangeMatch) {\n\t\tref = rangeMatch[1] ?? \"\";\n\t\tconst r = rangeMatch[2] ?? \"\";\n\t\tif (r.endsWith(\"-\")) {\n\t\t\trange = { start: parseInt(r, 10) };\n\t\t} else if (r.startsWith(\"-\")) {\n\t\t\trange = { end: parseInt(r.slice(1), 10) };\n\t\t} else if (r.includes(\"-\")) {\n\t\t\tconst [s, e] = r.split(\"-\").map((n) => parseInt(n, 10));\n\t\t\trange = { start: s, end: e };\n\t\t} else {\n\t\t\tconst n = parseInt(r, 10);\n\t\t\trange = { start: n, end: n };\n\t\t}\n\t}\n\n\tif (ref.includes(\"*\") || ref.includes(\"?\")) {\n\t\treturn { scope: { type: \"glob\", value: ref, range } };\n\t}\n\treturn { scope: { type: \"file\", value: ref, range } };\n}\n\nexport interface FencedRange {\n\tstart: number;\n\tend: number;\n}\n\nexport function findFencedBlocks(input: string): FencedRange[] {\n\tconst ranges: FencedRange[] = [];\n\tconst lines = input.split(\"\\n\");\n\tlet inBlock = false;\n\tlet blockStart = -1;\n\tlet fence = \"\";\n\n\tlet offset = 0;\n\tfor (const line of lines) {\n\t\tconst trimmed = line.trim();\n\t\tif (!inBlock && (trimmed.startsWith(\"```\") || trimmed.startsWith(\"~~~\"))) {\n\t\t\tinBlock = true;\n\t\t\tfence = trimmed.slice(0, 3);\n\t\t\tblockStart = offset;\n\t\t} else if (inBlock && trimmed.startsWith(fence)) {\n\t\t\tranges.push({ start: blockStart, end: offset + line.length });\n\t\t\tinBlock = false;\n\t\t}\n\t\toffset += line.length + 1;\n\t}\n\n\t// Also find inline backtick spans: `...`\n\tconst inlineRe = /`([^`\\n]+)`/g;\n\tfor (let m = inlineRe.exec(input); m !== null; m = inlineRe.exec(input)) {\n\t\tranges.push({ start: m.index, end: m.index + m[0].length });\n\t}\n\n\treturn ranges;\n}\n\nexport function isInsideFencedBlock(pos: number, ranges: Array<{ start: number; end: number }>): boolean {\n\treturn ranges.some((r) => pos >= r.start && pos <= r.end);\n}\n"]}
@@ -0,0 +1,252 @@
1
+ const DIRECTIVE_RE = /\[([A-Za-z][A-Za-z0-9_-]*)(?::\s*([^\]]*?))?\]/g;
2
+ // Pattern to detect malformed directives: [Word Word] without colon
3
+ const MALFORMED_RE = /\[([A-Za-z][A-Za-z0-9_-]*)\s+([A-Za-z][A-Za-z0-9_-]*)\]/g;
4
+ // Standalone scope statements: {@path}, {path}, {path:10-20}, {#id}
5
+ const SCOPE_ONLY_RE = /\{([^}\n]*)\}/g;
6
+ /**
7
+ * Scan for directives and standalone scope statements.
8
+ *
9
+ * `excludedRanges` marks spans of the input that must not be scanned (e.g.
10
+ * mark content blocks, which are injected verbatim, not interpreted).
11
+ */
12
+ export function scanDirectives(input, excludedRanges) {
13
+ const fencedRanges = findFencedBlocks(input);
14
+ const skipRanges = [...fencedRanges, ...(excludedRanges ?? [])];
15
+ const directives = [];
16
+ const errors = [];
17
+ const systemNav = scanSystemNav(input);
18
+ if (systemNav) {
19
+ return { directives: [{ kind: "system-nav", command: systemNav }], stripped: "", errors };
20
+ }
21
+ const alias = scanAlias(input);
22
+ if (alias) {
23
+ return { directives: [{ kind: "alias", command: alias }], stripped: "", errors };
24
+ }
25
+ const cueRe = new RegExp(DIRECTIVE_RE.source, "g");
26
+ for (let match = cueRe.exec(input); match !== null; match = cueRe.exec(input)) {
27
+ const start = match.index;
28
+ if (isInsideFencedBlock(start, skipRanges))
29
+ continue;
30
+ const [raw, elementRaw, tagChain] = match;
31
+ const element = elementRaw.trim();
32
+ const tags = tagChain
33
+ ? tagChain
34
+ .split(">")
35
+ .map((t) => t.trim())
36
+ .filter(Boolean)
37
+ : [];
38
+ const scope = null;
39
+ const beforeMatch = input.slice(0, match.index);
40
+ const line = beforeMatch.split("\n").length;
41
+ const lastNewline = beforeMatch.lastIndexOf("\n");
42
+ const col = match.index - lastNewline;
43
+ directives.push({
44
+ kind: "cue",
45
+ directive: { raw, element, tags, scope, line, col, position: start },
46
+ });
47
+ }
48
+ // Standalone scope statements: {@file}, {file}, {file:10-20}, {#id}
49
+ const scopeRe = new RegExp(SCOPE_ONLY_RE.source, "g");
50
+ for (let match = scopeRe.exec(input); match !== null; match = scopeRe.exec(input)) {
51
+ const start = match.index;
52
+ if (isInsideFencedBlock(start, skipRanges))
53
+ continue;
54
+ const raw = match[1] ?? "";
55
+ const parsed = parseScope(raw);
56
+ if ("error" in parsed) {
57
+ const beforeMatch = input.slice(0, start);
58
+ const line = beforeMatch.split("\n").length;
59
+ const lastNewline = beforeMatch.lastIndexOf("\n");
60
+ const col = start - lastNewline;
61
+ errors.push({ message: parsed.error, raw: match[0], line, col });
62
+ continue;
63
+ }
64
+ const statement = { scope: parsed.scope, position: start, raw: match[0] };
65
+ directives.push({ kind: "scope-only", statement });
66
+ }
67
+ // Detect malformed directives: [Word Word] without colon
68
+ const malformedRe = new RegExp(MALFORMED_RE.source, "g");
69
+ for (let match = malformedRe.exec(input); match !== null; match = malformedRe.exec(input)) {
70
+ const start = match.index;
71
+ if (isInsideFencedBlock(start, skipRanges))
72
+ continue;
73
+ // Check if this was already matched as a valid directive
74
+ const wasMatched = directives.some((d) => {
75
+ if (d.kind !== "cue")
76
+ return false;
77
+ const dirStart = d.directive.position ?? input.indexOf(d.directive.raw);
78
+ return dirStart <= start && start < dirStart + d.directive.raw.length;
79
+ });
80
+ if (wasMatched)
81
+ continue;
82
+ const beforeMatch = input.slice(0, start);
83
+ const line = beforeMatch.split("\n").length;
84
+ const lastNewline = beforeMatch.lastIndexOf("\n");
85
+ const col = start - lastNewline;
86
+ errors.push({
87
+ message: `Malformed directive "${match[0]}" — did you mean "[${match[1]}: ${match[2]}]"?`,
88
+ raw: match[0],
89
+ line,
90
+ col,
91
+ });
92
+ }
93
+ // Strip directives by span, preserving everything else
94
+ const spans = directives
95
+ .map((d) => {
96
+ if (d.kind === "cue") {
97
+ const start = d.directive.position ?? input.indexOf(d.directive.raw);
98
+ return { start, end: start + d.directive.raw.length };
99
+ }
100
+ if (d.kind !== "scope-only") {
101
+ throw new Error("unreachable: system-nav/alias return early");
102
+ }
103
+ return { start: d.statement.position, end: d.statement.position + d.statement.raw.length };
104
+ })
105
+ .sort((a, b) => a.start - b.start);
106
+ return { directives, stripped: stripSpans(input, spans), errors };
107
+ }
108
+ /** Remove the given spans from the input, collapsing runs of whitespace. */
109
+ export function stripSpans(input, spans) {
110
+ let stripped = "";
111
+ let cursor = 0;
112
+ for (const span of spans) {
113
+ stripped += input.slice(cursor, span.start);
114
+ cursor = span.end;
115
+ }
116
+ stripped += input.slice(cursor);
117
+ return stripped.replace(/\s{2,}/g, " ").trim();
118
+ }
119
+ export function scan(input) {
120
+ const fencedRanges = findFencedBlocks(input);
121
+ const directives = [];
122
+ const cueRe = new RegExp(DIRECTIVE_RE.source, "g");
123
+ for (let match = cueRe.exec(input); match !== null; match = cueRe.exec(input)) {
124
+ const start = match.index;
125
+ if (isInsideFencedBlock(start, fencedRanges))
126
+ continue;
127
+ const [raw, elementRaw, tagChain] = match;
128
+ const element = elementRaw.trim();
129
+ const tags = tagChain
130
+ ? tagChain
131
+ .split(">")
132
+ .map((t) => t.trim())
133
+ .filter(Boolean)
134
+ : [];
135
+ const beforeMatch = input.slice(0, match.index);
136
+ const line = beforeMatch.split("\n").length;
137
+ const lastNewline = beforeMatch.lastIndexOf("\n");
138
+ const col = match.index - lastNewline;
139
+ directives.push({ raw, element, tags, scope: null, line, col, position: start });
140
+ }
141
+ return directives;
142
+ }
143
+ function scanSystemNav(input) {
144
+ const trimmed = input.trimStart();
145
+ if (!trimmed.startsWith(":"))
146
+ return null;
147
+ const firstLine = trimmed.split("\n")[0];
148
+ const match = firstLine.match(/^:(\w+)\s*(.*)?$/);
149
+ if (!match)
150
+ return null;
151
+ return { command: match[1], arg: match[2]?.trim() || undefined };
152
+ }
153
+ function scanAlias(input) {
154
+ const trimmed = input.trimStart();
155
+ if (!trimmed.startsWith("/"))
156
+ return null;
157
+ const firstLine = trimmed.split("\n")[0];
158
+ const match = firstLine.match(/^\/(\w+)/);
159
+ if (!match)
160
+ return null;
161
+ return { command: match[1] };
162
+ }
163
+ /**
164
+ * Parse the inner content of a scope statement.
165
+ *
166
+ * - `@path`, `path` → file (a trailing slash targets a directory)
167
+ * - `@path:10-20`, `path:10-` → file + line range (open bounds allowed)
168
+ * - `@glob`, `glob` → glob (contains `*` or `?`)
169
+ * - `#id` → mark reference
170
+ *
171
+ * The `@` is optional — `{path}` and `{@path}` are equivalent.
172
+ */
173
+ function parseScope(raw) {
174
+ if (raw.startsWith("#")) {
175
+ const id = raw.slice(1);
176
+ if (id === "")
177
+ return { error: "Empty mark identifier — expected {#name}" };
178
+ if (!/^[A-Za-z0-9_-]+$/.test(id))
179
+ return { error: `Malformed mark identifier "{${raw}}"` };
180
+ return { scope: { type: "id", value: id } };
181
+ }
182
+ // {$name} — skill reference, passed through for skill expansion
183
+ if (raw.startsWith("$")) {
184
+ const name = raw.slice(1);
185
+ if (name === "")
186
+ return { error: "Empty skill reference — expected {$name}" };
187
+ if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name))
188
+ return { error: `Malformed skill reference "{${raw}}"` };
189
+ return { scope: { type: "skill", value: name } };
190
+ }
191
+ let ref = raw;
192
+ if (ref.startsWith("@"))
193
+ ref = ref.slice(1);
194
+ if (ref.trim() === "")
195
+ return { error: "Empty scope path — expected {@path}" };
196
+ // Line range: {@path:start-end}, {@path:start-}, {@path:-end}, {@path:start}
197
+ const rangeMatch = ref.match(/^(.+):(\d+-\d+|\d+-|-\d+|\d+)$/);
198
+ let range;
199
+ if (rangeMatch) {
200
+ ref = rangeMatch[1] ?? "";
201
+ const r = rangeMatch[2] ?? "";
202
+ if (r.endsWith("-")) {
203
+ range = { start: parseInt(r, 10) };
204
+ }
205
+ else if (r.startsWith("-")) {
206
+ range = { end: parseInt(r.slice(1), 10) };
207
+ }
208
+ else if (r.includes("-")) {
209
+ const [s, e] = r.split("-").map((n) => parseInt(n, 10));
210
+ range = { start: s, end: e };
211
+ }
212
+ else {
213
+ const n = parseInt(r, 10);
214
+ range = { start: n, end: n };
215
+ }
216
+ }
217
+ if (ref.includes("*") || ref.includes("?")) {
218
+ return { scope: { type: "glob", value: ref, range } };
219
+ }
220
+ return { scope: { type: "file", value: ref, range } };
221
+ }
222
+ export function findFencedBlocks(input) {
223
+ const ranges = [];
224
+ const lines = input.split("\n");
225
+ let inBlock = false;
226
+ let blockStart = -1;
227
+ let fence = "";
228
+ let offset = 0;
229
+ for (const line of lines) {
230
+ const trimmed = line.trim();
231
+ if (!inBlock && (trimmed.startsWith("```") || trimmed.startsWith("~~~"))) {
232
+ inBlock = true;
233
+ fence = trimmed.slice(0, 3);
234
+ blockStart = offset;
235
+ }
236
+ else if (inBlock && trimmed.startsWith(fence)) {
237
+ ranges.push({ start: blockStart, end: offset + line.length });
238
+ inBlock = false;
239
+ }
240
+ offset += line.length + 1;
241
+ }
242
+ // Also find inline backtick spans: `...`
243
+ const inlineRe = /`([^`\n]+)`/g;
244
+ for (let m = inlineRe.exec(input); m !== null; m = inlineRe.exec(input)) {
245
+ ranges.push({ start: m.index, end: m.index + m[0].length });
246
+ }
247
+ return ranges;
248
+ }
249
+ export function isInsideFencedBlock(pos, ranges) {
250
+ return ranges.some((r) => pos >= r.start && pos <= r.end);
251
+ }
252
+ //# sourceMappingURL=scanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAUA,MAAM,YAAY,GAAG,iDAAiD,CAAC;AAEvE,oEAAoE;AACpE,MAAM,YAAY,GAAG,0DAA0D,CAAC;AAEhF,oEAAoE;AACpE,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAQvC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,cAAsD,EAAc;IACjH,MAAM,YAAY,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,CAAC,GAAG,YAAY,EAAE,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,MAAM,MAAM,GAAgB,EAAE,CAAC;IAE/B,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,SAAS,EAAE,CAAC;QACf,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;IAC3F,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,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EAAE,CAAC;YACjD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9D,OAAO,GAAG,KAAK,CAAC;QACjB,CAAC;QACD,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,yCAAyC;IACzC,MAAM,QAAQ,GAAG,cAAc,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,MAA6C,EAAW;IACxG,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAAA,CAC1D","sourcesContent":["import type {\n\tAliasCommand,\n\tCueDirective,\n\tCueScope,\n\tDirective,\n\tScanError,\n\tScopeOnlyStatement,\n\tSystemNavCommand,\n} from \"./types.ts\";\n\nconst DIRECTIVE_RE = /\\[([A-Za-z][A-Za-z0-9_-]*)(?::\\s*([^\\]]*?))?\\]/g;\n\n// Pattern to detect malformed directives: [Word Word] without colon\nconst MALFORMED_RE = /\\[([A-Za-z][A-Za-z0-9_-]*)\\s+([A-Za-z][A-Za-z0-9_-]*)\\]/g;\n\n// Standalone scope statements: {@path}, {path}, {path:10-20}, {#id}\nconst SCOPE_ONLY_RE = /\\{([^}\\n]*)\\}/g;\n\nexport interface ScanResult {\n\tdirectives: Directive[];\n\tstripped: string;\n\terrors: ScanError[];\n}\n\n/**\n * Scan for directives and standalone scope statements.\n *\n * `excludedRanges` marks spans of the input that must not be scanned (e.g.\n * mark content blocks, which are injected verbatim, not interpreted).\n */\nexport function scanDirectives(input: string, excludedRanges?: Array<{ start: number; end: number }>): ScanResult {\n\tconst fencedRanges = findFencedBlocks(input);\n\tconst skipRanges = [...fencedRanges, ...(excludedRanges ?? [])];\n\tconst directives: Directive[] = [];\n\tconst errors: ScanError[] = [];\n\n\tconst systemNav = scanSystemNav(input);\n\tif (systemNav) {\n\t\treturn { directives: [{ kind: \"system-nav\", command: systemNav }], stripped: \"\", errors };\n\t}\n\n\tconst alias = scanAlias(input);\n\tif (alias) {\n\t\treturn { directives: [{ kind: \"alias\", command: alias }], stripped: \"\", errors };\n\t}\n\n\tconst cueRe = new RegExp(DIRECTIVE_RE.source, \"g\");\n\n\tfor (let match = cueRe.exec(input); match !== null; match = cueRe.exec(input)) {\n\t\tconst start = match.index;\n\n\t\tif (isInsideFencedBlock(start, skipRanges)) continue;\n\n\t\tconst [raw, elementRaw, tagChain] = match;\n\t\tconst element = elementRaw.trim();\n\t\tconst tags = tagChain\n\t\t\t? tagChain\n\t\t\t\t\t.split(\">\")\n\t\t\t\t\t.map((t) => t.trim())\n\t\t\t\t\t.filter(Boolean)\n\t\t\t: [];\n\t\tconst scope = null;\n\n\t\tconst beforeMatch = input.slice(0, match.index);\n\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\tconst col = match.index - lastNewline;\n\n\t\tdirectives.push({\n\t\t\tkind: \"cue\",\n\t\t\tdirective: { raw, element, tags, scope, line, col, position: start },\n\t\t});\n\t}\n\n\t// Standalone scope statements: {@file}, {file}, {file:10-20}, {#id}\n\tconst scopeRe = new RegExp(SCOPE_ONLY_RE.source, \"g\");\n\tfor (let match = scopeRe.exec(input); match !== null; match = scopeRe.exec(input)) {\n\t\tconst start = match.index;\n\n\t\tif (isInsideFencedBlock(start, skipRanges)) continue;\n\n\t\tconst raw = match[1] ?? \"\";\n\t\tconst parsed = parseScope(raw);\n\t\tif (\"error\" in parsed) {\n\t\t\tconst beforeMatch = input.slice(0, start);\n\t\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\t\tconst col = start - lastNewline;\n\t\t\terrors.push({ message: parsed.error, raw: match[0], line, col });\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst statement: ScopeOnlyStatement = { scope: parsed.scope, position: start, raw: match[0] };\n\t\tdirectives.push({ kind: \"scope-only\", statement });\n\t}\n\n\t// Detect malformed directives: [Word Word] without colon\n\tconst malformedRe = new RegExp(MALFORMED_RE.source, \"g\");\n\tfor (let match = malformedRe.exec(input); match !== null; match = malformedRe.exec(input)) {\n\t\tconst start = match.index;\n\t\tif (isInsideFencedBlock(start, skipRanges)) continue;\n\n\t\t// Check if this was already matched as a valid directive\n\t\tconst wasMatched = directives.some((d) => {\n\t\t\tif (d.kind !== \"cue\") return false;\n\t\t\tconst dirStart = d.directive.position ?? input.indexOf(d.directive.raw);\n\t\t\treturn dirStart <= start && start < dirStart + d.directive.raw.length;\n\t\t});\n\t\tif (wasMatched) continue;\n\n\t\tconst beforeMatch = input.slice(0, start);\n\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\tconst col = start - lastNewline;\n\n\t\terrors.push({\n\t\t\tmessage: `Malformed directive \"${match[0]}\" — did you mean \"[${match[1]}: ${match[2]}]\"?`,\n\t\t\traw: match[0],\n\t\t\tline,\n\t\t\tcol,\n\t\t});\n\t}\n\n\t// Strip directives by span, preserving everything else\n\tconst spans = directives\n\t\t.map((d) => {\n\t\t\tif (d.kind === \"cue\") {\n\t\t\t\tconst start = d.directive.position ?? input.indexOf(d.directive.raw);\n\t\t\t\treturn { start, end: start + d.directive.raw.length };\n\t\t\t}\n\t\t\tif (d.kind !== \"scope-only\") {\n\t\t\t\tthrow new Error(\"unreachable: system-nav/alias return early\");\n\t\t\t}\n\t\t\treturn { start: d.statement.position, end: d.statement.position + d.statement.raw.length };\n\t\t})\n\t\t.sort((a, b) => a.start - b.start);\n\n\treturn { directives, stripped: stripSpans(input, spans), errors };\n}\n\n/** Remove the given spans from the input, collapsing runs of whitespace. */\nexport function stripSpans(input: string, spans: Array<{ start: number; end: number }>): string {\n\tlet stripped = \"\";\n\tlet cursor = 0;\n\tfor (const span of spans) {\n\t\tstripped += input.slice(cursor, span.start);\n\t\tcursor = span.end;\n\t}\n\tstripped += input.slice(cursor);\n\n\treturn stripped.replace(/\\s{2,}/g, \" \").trim();\n}\n\nexport function scan(input: string): CueDirective[] {\n\tconst fencedRanges = findFencedBlocks(input);\n\tconst directives: CueDirective[] = [];\n\n\tconst cueRe = new RegExp(DIRECTIVE_RE.source, \"g\");\n\n\tfor (let match = cueRe.exec(input); match !== null; match = cueRe.exec(input)) {\n\t\tconst start = match.index;\n\n\t\tif (isInsideFencedBlock(start, fencedRanges)) continue;\n\n\t\tconst [raw, elementRaw, tagChain] = match;\n\t\tconst element = elementRaw.trim();\n\t\tconst tags = tagChain\n\t\t\t? tagChain\n\t\t\t\t\t.split(\">\")\n\t\t\t\t\t.map((t) => t.trim())\n\t\t\t\t\t.filter(Boolean)\n\t\t\t: [];\n\n\t\tconst beforeMatch = input.slice(0, match.index);\n\t\tconst line = beforeMatch.split(\"\\n\").length;\n\t\tconst lastNewline = beforeMatch.lastIndexOf(\"\\n\");\n\t\tconst col = match.index - lastNewline;\n\n\t\tdirectives.push({ raw, element, tags, scope: null, line, col, position: start });\n\t}\n\n\treturn directives;\n}\n\nfunction scanSystemNav(input: string): SystemNavCommand | null {\n\tconst trimmed = input.trimStart();\n\tif (!trimmed.startsWith(\":\")) return null;\n\tconst firstLine = trimmed.split(\"\\n\")[0];\n\tconst match = firstLine.match(/^:(\\w+)\\s*(.*)?$/);\n\tif (!match) return null;\n\treturn { command: match[1], arg: match[2]?.trim() || undefined };\n}\n\nfunction scanAlias(input: string): AliasCommand | null {\n\tconst trimmed = input.trimStart();\n\tif (!trimmed.startsWith(\"/\")) return null;\n\tconst firstLine = trimmed.split(\"\\n\")[0];\n\tconst match = firstLine.match(/^\\/(\\w+)/);\n\tif (!match) return null;\n\treturn { command: match[1] };\n}\n\ntype ParsedScope = { scope: CueScope } | { error: string };\n\n/**\n * Parse the inner content of a scope statement.\n *\n * - `@path`, `path` → file (a trailing slash targets a directory)\n * - `@path:10-20`, `path:10-` → file + line range (open bounds allowed)\n * - `@glob`, `glob` → glob (contains `*` or `?`)\n * - `#id` → mark reference\n *\n * The `@` is optional — `{path}` and `{@path}` are equivalent.\n */\nfunction parseScope(raw: string): ParsedScope {\n\tif (raw.startsWith(\"#\")) {\n\t\tconst id = raw.slice(1);\n\t\tif (id === \"\") return { error: \"Empty mark identifier — expected {#name}\" };\n\t\tif (!/^[A-Za-z0-9_-]+$/.test(id)) return { error: `Malformed mark identifier \"{${raw}}\"` };\n\t\treturn { scope: { type: \"id\", value: id } };\n\t}\n\n\t// {$name} — skill reference, passed through for skill expansion\n\tif (raw.startsWith(\"$\")) {\n\t\tconst name = raw.slice(1);\n\t\tif (name === \"\") return { error: \"Empty skill reference — expected {$name}\" };\n\t\tif (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name)) return { error: `Malformed skill reference \"{${raw}}\"` };\n\t\treturn { scope: { type: \"skill\", value: name } };\n\t}\n\n\tlet ref = raw;\n\tif (ref.startsWith(\"@\")) ref = ref.slice(1);\n\tif (ref.trim() === \"\") return { error: \"Empty scope path — expected {@path}\" };\n\n\t// Line range: {@path:start-end}, {@path:start-}, {@path:-end}, {@path:start}\n\tconst rangeMatch = ref.match(/^(.+):(\\d+-\\d+|\\d+-|-\\d+|\\d+)$/);\n\tlet range: { start?: number; end?: number } | undefined;\n\tif (rangeMatch) {\n\t\tref = rangeMatch[1] ?? \"\";\n\t\tconst r = rangeMatch[2] ?? \"\";\n\t\tif (r.endsWith(\"-\")) {\n\t\t\trange = { start: parseInt(r, 10) };\n\t\t} else if (r.startsWith(\"-\")) {\n\t\t\trange = { end: parseInt(r.slice(1), 10) };\n\t\t} else if (r.includes(\"-\")) {\n\t\t\tconst [s, e] = r.split(\"-\").map((n) => parseInt(n, 10));\n\t\t\trange = { start: s, end: e };\n\t\t} else {\n\t\t\tconst n = parseInt(r, 10);\n\t\t\trange = { start: n, end: n };\n\t\t}\n\t}\n\n\tif (ref.includes(\"*\") || ref.includes(\"?\")) {\n\t\treturn { scope: { type: \"glob\", value: ref, range } };\n\t}\n\treturn { scope: { type: \"file\", value: ref, range } };\n}\n\nexport interface FencedRange {\n\tstart: number;\n\tend: number;\n}\n\nexport function findFencedBlocks(input: string): FencedRange[] {\n\tconst ranges: FencedRange[] = [];\n\tconst lines = input.split(\"\\n\");\n\tlet inBlock = false;\n\tlet blockStart = -1;\n\tlet fence = \"\";\n\n\tlet offset = 0;\n\tfor (const line of lines) {\n\t\tconst trimmed = line.trim();\n\t\tif (!inBlock && (trimmed.startsWith(\"```\") || trimmed.startsWith(\"~~~\"))) {\n\t\t\tinBlock = true;\n\t\t\tfence = trimmed.slice(0, 3);\n\t\t\tblockStart = offset;\n\t\t} else if (inBlock && trimmed.startsWith(fence)) {\n\t\t\tranges.push({ start: blockStart, end: offset + line.length });\n\t\t\tinBlock = false;\n\t\t}\n\t\toffset += line.length + 1;\n\t}\n\n\t// Also find inline backtick spans: `...`\n\tconst inlineRe = /`([^`\\n]+)`/g;\n\tfor (let m = inlineRe.exec(input); m !== null; m = inlineRe.exec(input)) {\n\t\tranges.push({ start: m.index, end: m.index + m[0].length });\n\t}\n\n\treturn ranges;\n}\n\nexport function isInsideFencedBlock(pos: number, ranges: Array<{ start: number; end: number }>): boolean {\n\treturn ranges.some((r) => pos >= r.start && pos <= r.end);\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import type { CueScope } from "./types.ts";
2
+ export interface ResolvedScope {
3
+ label: string;
4
+ content: string;
5
+ paths: string[];
6
+ }
7
+ /**
8
+ * Resolve a scope statement to its backing content.
9
+ *
10
+ * - `file` → reads the single file at the given path (relative to root)
11
+ * - `glob` → reads every file matching the glob
12
+ *
13
+ * Paths are resolved relative to `projectRoot` when provided, otherwise the
14
+ * current working directory. Absolute paths are used as-is. A `file` scope
15
+ * that points at a directory on disk is treated as a glob over its contents.
16
+ * An `id` scope has no direct backing content — marks resolve it.
17
+ */
18
+ export declare function resolveScope(scope: CueScope, projectRoot?: string): ResolvedScope | null;
19
+ /**
20
+ * Resolve a directory scope to its absolute path.
21
+ *
22
+ * Returns null when the value does not resolve to an existing directory.
23
+ */
24
+ export declare function resolveDirPath(value: string, projectRoot?: string): string | null;
25
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;CAChB;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAkDxF;AAiGD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYjF","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { isAbsolute, join, relative } from \"path\";\nimport type { CueScope } from \"./types.ts\";\n\nexport interface ResolvedScope {\n\tlabel: string;\n\tcontent: string;\n\tpaths: string[];\n}\n\nconst MAX_FILE_CHARS = 200_000;\n\n/**\n * Resolve a scope statement to its backing content.\n *\n * - `file` → reads the single file at the given path (relative to root)\n * - `glob` → reads every file matching the glob\n *\n * Paths are resolved relative to `projectRoot` when provided, otherwise the\n * current working directory. Absolute paths are used as-is. A `file` scope\n * that points at a directory on disk is treated as a glob over its contents.\n * An `id` scope has no direct backing content — marks resolve it.\n */\nexport function resolveScope(scope: CueScope, projectRoot?: string): ResolvedScope | null {\n\tif (scope.type === \"id\") return null;\n\n\tif (scope.type === \"file\") {\n\t\tconst path = resolvePath(scope.value, projectRoot);\n\t\tif (!path || !existsSync(path)) return null;\n\n\t\tlet isDir = false;\n\t\ttry {\n\t\t\tisDir = statSync(path).isDirectory();\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t\tif (isDir) {\n\t\t\treturn resolveScope({ type: \"glob\", value: `${scope.value}/**/*`, range: scope.range }, projectRoot);\n\t\t}\n\n\t\tlet content: string;\n\t\ttry {\n\t\t\tcontent = readFileSync(path, \"utf-8\");\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t\t// Apply line range if specified (1-indexed inclusive, e.g., 105-210 means lines 105 through 210)\n\t\tif (scope.range) {\n\t\t\tconst lines = content.split(\"\\n\");\n\t\t\tconst start = scope.range.start !== undefined ? Math.max(0, scope.range.start - 1) : 0;\n\t\t\tconst end = scope.range.end !== undefined ? Math.min(lines.length, scope.range.end) : lines.length;\n\t\t\tlet sliced = lines.slice(start, end).join(\"\\n\");\n\t\t\tif (content.endsWith(\"\\n\") && end === lines.length) {\n\t\t\t\tsliced = sliced.replace(/\\n$/, \"\");\n\t\t\t}\n\t\t\tcontent = sliced;\n\t\t}\n\t\tconst display = projectRoot ? relative(projectRoot, path) : path;\n\t\tconst label = rangeLabel(display, scope.range);\n\t\treturn { label, content, paths: [display] };\n\t}\n\n\tconst matched = walkGlob(scope.value, projectRoot ?? process.cwd());\n\tif (matched.length === 0) return null;\n\tconst parts = matched.map(({ display, content }) => {\n\t\tconst capped = content.length > MAX_FILE_CHARS ? `${content.slice(0, MAX_FILE_CHARS)}\\n…(truncated)` : content;\n\t\treturn `--- ${display} ---\\n${capped}`;\n\t});\n\treturn {\n\t\tlabel: scope.value,\n\t\tcontent: parts.join(\"\\n\\n\"),\n\t\tpaths: matched.map((m) => m.display),\n\t};\n}\n\nfunction rangeLabel(display: string, range?: { start?: number; end?: number }): string {\n\tif (!range) return display;\n\tif (range.start !== undefined && range.end !== undefined) {\n\t\treturn range.start === range.end ? `${display}:${range.start}` : `${display}:${range.start}-${range.end}`;\n\t}\n\tif (range.start !== undefined) return `${display}:${range.start}-`;\n\treturn `${display}:-${range.end}`;\n}\n\nfunction resolvePath(value: string, projectRoot?: string): string | null {\n\tif (isAbsolute(value)) return value;\n\tif (projectRoot) return join(projectRoot, value);\n\treturn value;\n}\n\ninterface MatchedFile {\n\tdisplay: string;\n\tcontent: string;\n}\n\nfunction walkGlob(pattern: string, base: string): MatchedFile[] {\n\tconst out: MatchedFile[] = [];\n\tconst segments = pattern.split(\"/\").filter(Boolean);\n\tcollect(base, segments, \"\", out);\n\treturn out;\n}\n\nfunction collect(dir: string, segments: string[], prefix: string, out: MatchedFile[]): void {\n\tif (segments.length === 0) return;\n\tconst [seg, ...rest] = segments;\n\n\tlet entries: string[] = [];\n\ttry {\n\t\tentries = readdirSync(dir);\n\t} catch {\n\t\treturn;\n\t}\n\n\tif (seg === \"**\") {\n\t\t// Match zero-or-more path segments.\n\t\tcollect(dir, rest, prefix, out);\n\t\tfor (const e of entries) {\n\t\t\tconst full = join(dir, e);\n\t\t\tlet s: { isDirectory(): boolean };\n\t\t\ttry {\n\t\t\t\ts = statSync(full);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (s.isDirectory()) {\n\t\t\t\tcollect(full, segments, prefix ? `${prefix}/${e}` : e, out);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tconst segRe = globToRegExp(seg);\n\tfor (const e of entries) {\n\t\tconst full = join(dir, e);\n\t\tlet s: { isDirectory(): boolean };\n\t\ttry {\n\t\t\ts = statSync(full);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tconst isDir = s.isDirectory();\n\t\tif (segRe.test(e)) {\n\t\t\tif (rest.length === 0) {\n\t\t\t\tif (!isDir) {\n\t\t\t\t\tlet content = \"\";\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcontent = readFileSync(full, \"utf-8\");\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tout.push({ display: prefix ? `${prefix}/${e}` : e, content });\n\t\t\t\t}\n\t\t\t} else if (isDir) {\n\t\t\t\tcollect(full, rest, prefix ? `${prefix}/${e}` : e, out);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction globToRegExp(globStr: string): RegExp {\n\tconst escaped = globStr\n\t\t.replace(/[.+^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\t\t.replace(/\\*\\*\\//g, \"→DOUBLESTAR→\")\n\t\t.replace(/\\*/g, \"[^/]*\")\n\t\t.replace(/→DOUBLESTAR→/g, \"(?:.*/)?\");\n\treturn new RegExp(`^${escaped}$`);\n}\n\n// ─── Directory scopes ────────────────────────────────────────────────────────\n\n/**\n * Resolve a directory scope to its absolute path.\n *\n * Returns null when the value does not resolve to an existing directory.\n */\nexport function resolveDirPath(value: string, projectRoot?: string): string | null {\n\tlet path = resolvePath(value, projectRoot);\n\tif (!path || !existsSync(path)) return null;\n\tlet isDir = false;\n\ttry {\n\t\tisDir = statSync(path).isDirectory();\n\t} catch {\n\t\treturn null;\n\t}\n\tif (!isDir) return null;\n\tif (path.length > 1) path = path.replace(/\\/+$/, \"\");\n\treturn path;\n}\n"]}