@lbdudc/linea-core 0.1.0 → 0.1.1

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 (37) hide show
  1. package/README.md +358 -358
  2. package/dist/analysis/analyze.js.map +1 -1
  3. package/dist/analysis/runtime.js.map +1 -1
  4. package/dist/assets.js.map +1 -1
  5. package/dist/constants.js.map +1 -1
  6. package/dist/derivation/derive.js.map +1 -1
  7. package/dist/derivation/engine.js.map +1 -1
  8. package/dist/errors.js.map +1 -1
  9. package/dist/feature-model/convert.js.map +1 -1
  10. package/dist/feature-model/engine.js.map +1 -1
  11. package/dist/feature-model/inspect.js.map +1 -1
  12. package/dist/feature-model/io.js.map +1 -1
  13. package/dist/feature-model/parse.js.map +1 -1
  14. package/dist/feature-model/text.js.map +1 -1
  15. package/dist/fs/archive.js.map +1 -1
  16. package/dist/fs/diff.js.map +1 -1
  17. package/dist/fs/format.js.map +1 -1
  18. package/dist/fs/workspace.js.map +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal/guards.js.map +1 -1
  21. package/dist/line/platform-files.js.map +1 -1
  22. package/dist/line/scaffold.js.map +1 -1
  23. package/dist/line/templates/core/extra.js +54 -54
  24. package/dist/line/templates/core/transformation.js +196 -196
  25. package/dist/line/templates/metamodels/dataModel/extra.js +328 -328
  26. package/dist/line/templates/metamodels/dataModel/transformation.js +211 -211
  27. package/dist/line/templates/metamodels/sensor/extra.js +36 -36
  28. package/dist/line/templates/metamodels/sensor/transformation.js +47 -47
  29. package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -51
  30. package/dist/line/templates/pipeline/ci/test-client.sh +16 -16
  31. package/dist/line/templates/pipeline/ci/test-server.sh +16 -16
  32. package/dist/product/engine-spec.js.map +1 -1
  33. package/dist/product/spec.js.map +1 -1
  34. package/dist/product/version.js.map +1 -1
  35. package/dist/products-index/products-index.js.map +1 -1
  36. package/dist/selection/selection.js.map +1 -1
  37. package/package.json +67 -67
@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C,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,oBAAoB,CAC5B,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,gBAAgB,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACvF,CAAA;IACH,CAAC;IAED,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACnD,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;QAElC,IAAI,MAAM,KAAK,aAAa,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAA;YACxD,OAAO;gBACL,WAAW,EAAE,MAAM,IAAI,CAAC,KAAK,IAAI,EAAE,CACjC,MAAM,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;gBAC7D,UAAU,EAAE,aAAa;aAC1B,CAAA;QACH,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,KAAK,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,uBAAuB,CAAA;QACtF,OAAO;YACL,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,KAAK,IAAI,EAAE,CAC9B,MAAM,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC1D,UAAU,EAAE,KAAc;SAC3B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["/**\r\n * Feature model analysis (ADR-008, ADR-021).\r\n *\r\n * Migrated from `linea/flamapy-server/main.py`: `/analyze` (~215-270),\r\n * `/analyze/bdd` (~273-340) and `/analyze/metric` (~340-367). The RESPONSE SHAPE\r\n * is contractual — webui and linea-cli already consume these exact keys — so it\r\n * is reproduced field for field, including the `_`-prefixed metadata.\r\n *\r\n * The `safe()` pattern of `main.py:105-117` is preserved: an operation that\r\n * fails yields `null` in its own field and never aborts the whole response. A\r\n * partially analysable model still returns everything it could compute.\r\n */\r\nimport { ANALYSIS_THRESHOLDS } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { estimateFeatureCount, normalizeUvl } from '../feature-model/text.js'\r\nimport {\r\n createAnalysisRuntime,\r\n disposeAnalysisRuntime,\r\n runOperation,\r\n useRuntime,\r\n type AnalysisRuntime\r\n} from './runtime.js'\r\n\r\n/** Solver requested by the caller. */\r\nexport type AnalysisMode = 'SAT' | 'BDD'\r\n\r\n/** Metrics `analyzeMetric` accepts, matching the `match` arms of `main.py`. */\r\nexport const ANALYSIS_METRICS = ['satisfiable', 'deadFeatures', 'falseOptionalFeatures'] as const\r\n\r\n/** A metric name accepted by `analyzeMetric`. */\r\nexport type AnalysisMetric = (typeof ANALYSIS_METRICS)[number]\r\n\r\n/** Structural + SAT analysis, the fast path. */\r\nexport interface FeatureModelAnalysis {\r\n coreFeatures: unknown\r\n averageBranchingFactor: unknown\r\n maxDepth: unknown\r\n estimatedConfigurations: unknown\r\n leafNumber: unknown\r\n leafFeatures: unknown\r\n atomicSets: unknown\r\n satisfiable: unknown\r\n deadFeatures: unknown\r\n falseOptionalFeatures: unknown\r\n /** Features counted by `estimateFeatureCount` over the normalised document. */\r\n _featureCount: number\r\n /** `'small' | 'medium' | 'large' | 'very_large'`, thresholds from `main.py`. */\r\n _modelSize: string\r\n /** Echo of the requested mode. */\r\n _solveMode: AnalysisMode\r\n /** Always `[]` here: the fast path skips nothing. */\r\n _skipped: string[]\r\n _elapsedMs: number\r\n}\r\n\r\n/** BDD + enumeration analysis, the slow path. */\r\nexport interface FeatureModelBddAnalysis {\r\n configurations: unknown\r\n configsNumber: unknown\r\n configDistribution: unknown\r\n featureInclusionProb: unknown\r\n homogeneity: unknown\r\n variability: unknown\r\n uniqueFeatures: unknown\r\n variantFeatures: unknown\r\n /** Fields deliberately not computed because the model is too large. */\r\n _skipped: string[]\r\n _elapsedMs: number\r\n}\r\n\r\n/** Result of `analyzeMetric`: the requested metric plus the solver used. */\r\nexport type MetricAnalysis = Partial<Record<AnalysisMetric, unknown>> & { _solveMode: AnalysisMode }\r\n\r\n/** BDD fields, in the order `main.py` lists them. */\r\nconst BDD_FIELDS = [\r\n 'configsNumber', 'configDistribution', 'featureInclusionProb',\r\n 'homogeneity', 'variability', 'uniqueFeatures', 'variantFeatures'\r\n] as const\r\n\r\n/** Verbatim from `main.py`'s `/analyze`. */\r\nconst modelSizeOf = (featureCount: number): string => {\r\n if (featureCount < 50) return 'small'\r\n if (featureCount < 100) return 'medium'\r\n if (featureCount < 250) return 'large'\r\n return 'very_large'\r\n}\r\n\r\n/**\r\n * Normalises and sanity-checks the input, mirroring every endpoint's preamble.\r\n * `main.py` answers HTTP 400 when the document does not start with `features`.\r\n */\r\nconst prepareUvl = (uvl: unknown): string => {\r\n if (typeof uvl !== 'string') {\r\n throw new InvalidArgumentError('\"uvl\" must be a string.')\r\n }\r\n const normalised = normalizeUvl({ uvl })\r\n if (!normalised.startsWith('features')) {\r\n throw new InvalidArgumentError(\r\n 'The UVL document must start with \"features\". Got: ' +\r\n `${JSON.stringify(normalised.slice(0, 40))}`\r\n )\r\n }\r\n return normalised\r\n}\r\n\r\nconst assertMode = (mode: unknown): AnalysisMode => {\r\n if (mode === undefined) return 'BDD'\r\n if (mode !== 'SAT' && mode !== 'BDD') {\r\n throw new InvalidArgumentError(`\"mode\" must be \"SAT\" or \"BDD\", got ${JSON.stringify(mode)}.`)\r\n }\r\n return mode\r\n}\r\n\r\n/**\r\n * `main.py:safe()` — run an operation, and on failure record `null` instead of\r\n * letting one broken metric take the whole response down.\r\n */\r\nconst safe = async (run: () => Promise<unknown>): Promise<unknown> => {\r\n try {\r\n return await run()\r\n } catch {\r\n return null\r\n }\r\n}\r\n\r\n/** Runs `body` with a runtime, creating and disposing a private one if needed. */\r\nconst withRuntime = async <T>(\r\n runtime: AnalysisRuntime | undefined,\r\n body: (provided: AnalysisRuntime) => Promise<T>\r\n): Promise<T> => {\r\n if (runtime !== undefined) return await body(runtime)\r\n // Bootstrapping costs ~2.3 s; callers running more than one analysis should\r\n // create a runtime once and pass it in.\r\n const owned = await createAnalysisRuntime()\r\n try {\r\n return await body(owned)\r\n } finally {\r\n disposeAnalysisRuntime({ runtime: owned })\r\n }\r\n}\r\n\r\n/**\r\n * Fast analysis: structural metrics plus the SAT group.\r\n *\r\n * PARITY QUIRK: `mode` does NOT change what is computed. `main.py` always runs\r\n * the PySAT operations here and only echoes the requested mode back in\r\n * `_solveMode`; the BDD group lives in `analyzeFeatureModelBdd`. Reproduced as\r\n * is, because webui reads `_solveMode` to label the result.\r\n *\r\n * @param params.uvl UVL document. Normalised internally.\r\n * @param params.mode Solver to report. Defaults to `'BDD'`.\r\n * @param params.runtime Optional runtime to reuse.\r\n * @returns Every field of `main.py`'s `/analyze`. Individual failures are `null`.\r\n * @throws {InvalidArgumentError} for a non-string or non-`features` document.\r\n * @throws {AnalysisRuntimeError} if the runtime cannot start or was disposed.\r\n */\r\nexport const analyzeFeatureModel = async ({\r\n uvl,\r\n mode,\r\n runtime\r\n}: {\r\n uvl: string\r\n mode?: AnalysisMode\r\n runtime?: AnalysisRuntime\r\n}): Promise<FeatureModelAnalysis> => {\r\n const document = prepareUvl(uvl)\r\n const solveMode = assertMode(mode)\r\n const started = Date.now()\r\n const featureCount = estimateFeatureCount({ uvl: document })\r\n\r\n return await withRuntime(runtime, async (provided) => {\r\n const state = useRuntime(provided)\r\n const basic = async (operation: string): Promise<unknown> =>\r\n await safe(async () => await runOperation(state, operation, document, 'basic'))\r\n const pysat = async (operation: string): Promise<unknown> =>\r\n await safe(async () => await runOperation(state, operation, document, 'pysat'))\r\n\r\n return {\r\n coreFeatures: await basic('core_features'),\r\n averageBranchingFactor: await basic('average_branching_factor'),\r\n maxDepth: await basic('max_depth'),\r\n estimatedConfigurations: await basic('estimated_number_of_configurations'),\r\n leafNumber: await basic('count_leafs'),\r\n leafFeatures: await basic('leaf_features'),\r\n atomicSets: await basic('atomic_sets'),\r\n satisfiable: await pysat('Satisfiable'),\r\n deadFeatures: await pysat('DeadFeatures'),\r\n falseOptionalFeatures: await pysat('FalseOptionalFeatures'),\r\n _featureCount: featureCount,\r\n _modelSize: modelSizeOf(featureCount),\r\n _solveMode: solveMode,\r\n _skipped: [],\r\n _elapsedMs: Date.now() - started\r\n }\r\n })\r\n}\r\n\r\n/**\r\n * Slow analysis: the BDD group plus full configuration enumeration.\r\n *\r\n * Both are exponential, so `ANALYSIS_THRESHOLDS` gates them exactly as `main.py`\r\n * does with `SKIP_BDD` and `SKIP_ENUM`:\r\n * - at or above 100 features, every field is `null` and all eight names land in\r\n * `_skipped` — the runtime is not even touched;\r\n * - above 30 features, `configurations` alone is skipped.\r\n *\r\n * @param params.uvl UVL document.\r\n * @param params.runtime Optional runtime to reuse.\r\n * @returns Every field of `main.py`'s `/analyze/bdd`.\r\n * @throws {InvalidArgumentError} for a non-string or non-`features` document.\r\n */\r\nexport const analyzeFeatureModelBdd = async ({\r\n uvl,\r\n runtime\r\n}: {\r\n uvl: string\r\n runtime?: AnalysisRuntime\r\n}): Promise<FeatureModelBddAnalysis> => {\r\n const document = prepareUvl(uvl)\r\n const started = Date.now()\r\n const featureCount = estimateFeatureCount({ uvl: document })\r\n const skipped: string[] = []\r\n\r\n if (featureCount >= ANALYSIS_THRESHOLDS.skipBdd) {\r\n skipped.push('configurations', ...BDD_FIELDS)\r\n return {\r\n configurations: null,\r\n configsNumber: null,\r\n configDistribution: null,\r\n featureInclusionProb: null,\r\n homogeneity: null,\r\n variability: null,\r\n uniqueFeatures: null,\r\n variantFeatures: null,\r\n _skipped: skipped,\r\n _elapsedMs: Date.now() - started\r\n }\r\n }\r\n\r\n return await withRuntime(runtime, async (provided) => {\r\n const state = useRuntime(provided)\r\n\r\n let configurations: unknown = null\r\n if (featureCount <= ANALYSIS_THRESHOLDS.skipEnumeration) {\r\n configurations = await safe(async () =>\r\n await runOperation(state, 'configurations', document, 'basic'))\r\n } else {\r\n skipped.push('configurations')\r\n }\r\n\r\n const bdd = async (operation: string): Promise<unknown> =>\r\n await safe(async () => await runOperation(state, operation, document, 'bdd'))\r\n\r\n return {\r\n configurations,\r\n configsNumber: await bdd('ConfigurationsNumber'),\r\n configDistribution: await bdd('ProductDistribution'),\r\n featureInclusionProb: await bdd('FeatureInclusionProbability'),\r\n homogeneity: await bdd('Homogeneity'),\r\n variability: await bdd('Variability'),\r\n uniqueFeatures: await bdd('UniqueFeatures'),\r\n variantFeatures: await bdd('VariantFeatures'),\r\n _skipped: skipped,\r\n _elapsedMs: Date.now() - started\r\n }\r\n })\r\n}\r\n\r\n/**\r\n * Computes a single metric.\r\n *\r\n * Mirrors the `match` of `main.py`'s `/analyze/metric`, including which solver\r\n * each arm uses: only `satisfiable` honours `mode` (PySAT or BDD); the other two\r\n * are PySAT-only and always report `_solveMode: 'SAT'`.\r\n *\r\n * @param params.uvl UVL document.\r\n * @param params.metric One of `ANALYSIS_METRICS`.\r\n * @param params.mode Solver, only meaningful for `satisfiable`. Defaults to `'BDD'`.\r\n * @param params.runtime Optional runtime to reuse.\r\n * @returns The metric plus the solver actually used.\r\n * @throws {InvalidArgumentError} for an unknown metric or a malformed document.\r\n */\r\nexport const analyzeMetric = async ({\r\n uvl,\r\n metric,\r\n mode,\r\n runtime\r\n}: {\r\n uvl: string\r\n metric: AnalysisMetric\r\n mode?: AnalysisMode\r\n runtime?: AnalysisRuntime\r\n}): Promise<MetricAnalysis> => {\r\n const document = prepareUvl(uvl)\r\n const requestedMode = assertMode(mode)\r\n if (!(ANALYSIS_METRICS as readonly string[]).includes(metric)) {\r\n throw new InvalidArgumentError(\r\n `Unknown metric ${JSON.stringify(metric)}. Supported: ${ANALYSIS_METRICS.join(', ')}.`\r\n )\r\n }\r\n\r\n return await withRuntime(runtime, async (provided) => {\r\n const state = useRuntime(provided)\r\n\r\n if (metric === 'satisfiable') {\r\n const solver = requestedMode === 'SAT' ? 'pysat' : 'bdd'\r\n return {\r\n satisfiable: await safe(async () =>\r\n await runOperation(state, 'Satisfiable', document, solver)),\r\n _solveMode: requestedMode\r\n }\r\n }\r\n\r\n const operation = metric === 'deadFeatures' ? 'DeadFeatures' : 'FalseOptionalFeatures'\r\n return {\r\n [metric]: await safe(async () =>\r\n await runOperation(state, operation, document, 'pysat')),\r\n _solveMode: 'SAT' as const\r\n }\r\n })\r\n}\r\n"]}
1
+ {"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../src/analysis/analyze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC7E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EAEX,MAAM,cAAc,CAAA;AAKrB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,cAAc,EAAE,uBAAuB,CAAU,CAAA;AA8CjG,qDAAqD;AACrD,MAAM,UAAU,GAAG;IACjB,eAAe,EAAE,oBAAoB,EAAE,sBAAsB;IAC7D,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,iBAAiB;CACzD,CAAA;AAEV,4CAA4C;AAC5C,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAU,EAAE;IACnD,IAAI,YAAY,GAAG,EAAE;QAAE,OAAO,OAAO,CAAA;IACrC,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,QAAQ,CAAA;IACvC,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,OAAO,CAAA;IACtC,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,GAAY,EAAU,EAAE;IAC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AAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["/**\n * Feature model analysis (ADR-008, ADR-021).\n *\n * Migrated from `linea/flamapy-server/main.py`: `/analyze` (~215-270),\n * `/analyze/bdd` (~273-340) and `/analyze/metric` (~340-367). The RESPONSE SHAPE\n * is contractual — webui and linea-cli already consume these exact keys — so it\n * is reproduced field for field, including the `_`-prefixed metadata.\n *\n * The `safe()` pattern of `main.py:105-117` is preserved: an operation that\n * fails yields `null` in its own field and never aborts the whole response. A\n * partially analysable model still returns everything it could compute.\n */\nimport { ANALYSIS_THRESHOLDS } from '../constants.js'\nimport { InvalidArgumentError } from '../errors.js'\nimport { estimateFeatureCount, normalizeUvl } from '../feature-model/text.js'\nimport {\n createAnalysisRuntime,\n disposeAnalysisRuntime,\n runOperation,\n useRuntime,\n type AnalysisRuntime\n} from './runtime.js'\n\n/** Solver requested by the caller. */\nexport type AnalysisMode = 'SAT' | 'BDD'\n\n/** Metrics `analyzeMetric` accepts, matching the `match` arms of `main.py`. */\nexport const ANALYSIS_METRICS = ['satisfiable', 'deadFeatures', 'falseOptionalFeatures'] as const\n\n/** A metric name accepted by `analyzeMetric`. */\nexport type AnalysisMetric = (typeof ANALYSIS_METRICS)[number]\n\n/** Structural + SAT analysis, the fast path. */\nexport interface FeatureModelAnalysis {\n coreFeatures: unknown\n averageBranchingFactor: unknown\n maxDepth: unknown\n estimatedConfigurations: unknown\n leafNumber: unknown\n leafFeatures: unknown\n atomicSets: unknown\n satisfiable: unknown\n deadFeatures: unknown\n falseOptionalFeatures: unknown\n /** Features counted by `estimateFeatureCount` over the normalised document. */\n _featureCount: number\n /** `'small' | 'medium' | 'large' | 'very_large'`, thresholds from `main.py`. */\n _modelSize: string\n /** Echo of the requested mode. */\n _solveMode: AnalysisMode\n /** Always `[]` here: the fast path skips nothing. */\n _skipped: string[]\n _elapsedMs: number\n}\n\n/** BDD + enumeration analysis, the slow path. */\nexport interface FeatureModelBddAnalysis {\n configurations: unknown\n configsNumber: unknown\n configDistribution: unknown\n featureInclusionProb: unknown\n homogeneity: unknown\n variability: unknown\n uniqueFeatures: unknown\n variantFeatures: unknown\n /** Fields deliberately not computed because the model is too large. */\n _skipped: string[]\n _elapsedMs: number\n}\n\n/** Result of `analyzeMetric`: the requested metric plus the solver used. */\nexport type MetricAnalysis = Partial<Record<AnalysisMetric, unknown>> & { _solveMode: AnalysisMode }\n\n/** BDD fields, in the order `main.py` lists them. */\nconst BDD_FIELDS = [\n 'configsNumber', 'configDistribution', 'featureInclusionProb',\n 'homogeneity', 'variability', 'uniqueFeatures', 'variantFeatures'\n] as const\n\n/** Verbatim from `main.py`'s `/analyze`. */\nconst modelSizeOf = (featureCount: number): string => {\n if (featureCount < 50) return 'small'\n if (featureCount < 100) return 'medium'\n if (featureCount < 250) return 'large'\n return 'very_large'\n}\n\n/**\n * Normalises and sanity-checks the input, mirroring every endpoint's preamble.\n * `main.py` answers HTTP 400 when the document does not start with `features`.\n */\nconst prepareUvl = (uvl: unknown): string => {\n if (typeof uvl !== 'string') {\n throw new InvalidArgumentError('\"uvl\" must be a string.')\n }\n const normalised = normalizeUvl({ uvl })\n if (!normalised.startsWith('features')) {\n throw new InvalidArgumentError(\n 'The UVL document must start with \"features\". Got: ' +\n `${JSON.stringify(normalised.slice(0, 40))}`\n )\n }\n return normalised\n}\n\nconst assertMode = (mode: unknown): AnalysisMode => {\n if (mode === undefined) return 'BDD'\n if (mode !== 'SAT' && mode !== 'BDD') {\n throw new InvalidArgumentError(`\"mode\" must be \"SAT\" or \"BDD\", got ${JSON.stringify(mode)}.`)\n }\n return mode\n}\n\n/**\n * `main.py:safe()` — run an operation, and on failure record `null` instead of\n * letting one broken metric take the whole response down.\n */\nconst safe = async (run: () => Promise<unknown>): Promise<unknown> => {\n try {\n return await run()\n } catch {\n return null\n }\n}\n\n/** Runs `body` with a runtime, creating and disposing a private one if needed. */\nconst withRuntime = async <T>(\n runtime: AnalysisRuntime | undefined,\n body: (provided: AnalysisRuntime) => Promise<T>\n): Promise<T> => {\n if (runtime !== undefined) return await body(runtime)\n // Bootstrapping costs ~2.3 s; callers running more than one analysis should\n // create a runtime once and pass it in.\n const owned = await createAnalysisRuntime()\n try {\n return await body(owned)\n } finally {\n disposeAnalysisRuntime({ runtime: owned })\n }\n}\n\n/**\n * Fast analysis: structural metrics plus the SAT group.\n *\n * PARITY QUIRK: `mode` does NOT change what is computed. `main.py` always runs\n * the PySAT operations here and only echoes the requested mode back in\n * `_solveMode`; the BDD group lives in `analyzeFeatureModelBdd`. Reproduced as\n * is, because webui reads `_solveMode` to label the result.\n *\n * @param params.uvl UVL document. Normalised internally.\n * @param params.mode Solver to report. Defaults to `'BDD'`.\n * @param params.runtime Optional runtime to reuse.\n * @returns Every field of `main.py`'s `/analyze`. Individual failures are `null`.\n * @throws {InvalidArgumentError} for a non-string or non-`features` document.\n * @throws {AnalysisRuntimeError} if the runtime cannot start or was disposed.\n */\nexport const analyzeFeatureModel = async ({\n uvl,\n mode,\n runtime\n}: {\n uvl: string\n mode?: AnalysisMode\n runtime?: AnalysisRuntime\n}): Promise<FeatureModelAnalysis> => {\n const document = prepareUvl(uvl)\n const solveMode = assertMode(mode)\n const started = Date.now()\n const featureCount = estimateFeatureCount({ uvl: document })\n\n return await withRuntime(runtime, async (provided) => {\n const state = useRuntime(provided)\n const basic = async (operation: string): Promise<unknown> =>\n await safe(async () => await runOperation(state, operation, document, 'basic'))\n const pysat = async (operation: string): Promise<unknown> =>\n await safe(async () => await runOperation(state, operation, document, 'pysat'))\n\n return {\n coreFeatures: await basic('core_features'),\n averageBranchingFactor: await basic('average_branching_factor'),\n maxDepth: await basic('max_depth'),\n estimatedConfigurations: await basic('estimated_number_of_configurations'),\n leafNumber: await basic('count_leafs'),\n leafFeatures: await basic('leaf_features'),\n atomicSets: await basic('atomic_sets'),\n satisfiable: await pysat('Satisfiable'),\n deadFeatures: await pysat('DeadFeatures'),\n falseOptionalFeatures: await pysat('FalseOptionalFeatures'),\n _featureCount: featureCount,\n _modelSize: modelSizeOf(featureCount),\n _solveMode: solveMode,\n _skipped: [],\n _elapsedMs: Date.now() - started\n }\n })\n}\n\n/**\n * Slow analysis: the BDD group plus full configuration enumeration.\n *\n * Both are exponential, so `ANALYSIS_THRESHOLDS` gates them exactly as `main.py`\n * does with `SKIP_BDD` and `SKIP_ENUM`:\n * - at or above 100 features, every field is `null` and all eight names land in\n * `_skipped` — the runtime is not even touched;\n * - above 30 features, `configurations` alone is skipped.\n *\n * @param params.uvl UVL document.\n * @param params.runtime Optional runtime to reuse.\n * @returns Every field of `main.py`'s `/analyze/bdd`.\n * @throws {InvalidArgumentError} for a non-string or non-`features` document.\n */\nexport const analyzeFeatureModelBdd = async ({\n uvl,\n runtime\n}: {\n uvl: string\n runtime?: AnalysisRuntime\n}): Promise<FeatureModelBddAnalysis> => {\n const document = prepareUvl(uvl)\n const started = Date.now()\n const featureCount = estimateFeatureCount({ uvl: document })\n const skipped: string[] = []\n\n if (featureCount >= ANALYSIS_THRESHOLDS.skipBdd) {\n skipped.push('configurations', ...BDD_FIELDS)\n return {\n configurations: null,\n configsNumber: null,\n configDistribution: null,\n featureInclusionProb: null,\n homogeneity: null,\n variability: null,\n uniqueFeatures: null,\n variantFeatures: null,\n _skipped: skipped,\n _elapsedMs: Date.now() - started\n }\n }\n\n return await withRuntime(runtime, async (provided) => {\n const state = useRuntime(provided)\n\n let configurations: unknown = null\n if (featureCount <= ANALYSIS_THRESHOLDS.skipEnumeration) {\n configurations = await safe(async () =>\n await runOperation(state, 'configurations', document, 'basic'))\n } else {\n skipped.push('configurations')\n }\n\n const bdd = async (operation: string): Promise<unknown> =>\n await safe(async () => await runOperation(state, operation, document, 'bdd'))\n\n return {\n configurations,\n configsNumber: await bdd('ConfigurationsNumber'),\n configDistribution: await bdd('ProductDistribution'),\n featureInclusionProb: await bdd('FeatureInclusionProbability'),\n homogeneity: await bdd('Homogeneity'),\n variability: await bdd('Variability'),\n uniqueFeatures: await bdd('UniqueFeatures'),\n variantFeatures: await bdd('VariantFeatures'),\n _skipped: skipped,\n _elapsedMs: Date.now() - started\n }\n })\n}\n\n/**\n * Computes a single metric.\n *\n * Mirrors the `match` of `main.py`'s `/analyze/metric`, including which solver\n * each arm uses: only `satisfiable` honours `mode` (PySAT or BDD); the other two\n * are PySAT-only and always report `_solveMode: 'SAT'`.\n *\n * @param params.uvl UVL document.\n * @param params.metric One of `ANALYSIS_METRICS`.\n * @param params.mode Solver, only meaningful for `satisfiable`. Defaults to `'BDD'`.\n * @param params.runtime Optional runtime to reuse.\n * @returns The metric plus the solver actually used.\n * @throws {InvalidArgumentError} for an unknown metric or a malformed document.\n */\nexport const analyzeMetric = async ({\n uvl,\n metric,\n mode,\n runtime\n}: {\n uvl: string\n metric: AnalysisMetric\n mode?: AnalysisMode\n runtime?: AnalysisRuntime\n}): Promise<MetricAnalysis> => {\n const document = prepareUvl(uvl)\n const requestedMode = assertMode(mode)\n if (!(ANALYSIS_METRICS as readonly string[]).includes(metric)) {\n throw new InvalidArgumentError(\n `Unknown metric ${JSON.stringify(metric)}. Supported: ${ANALYSIS_METRICS.join(', ')}.`\n )\n }\n\n return await withRuntime(runtime, async (provided) => {\n const state = useRuntime(provided)\n\n if (metric === 'satisfiable') {\n const solver = requestedMode === 'SAT' ? 'pysat' : 'bdd'\n return {\n satisfiable: await safe(async () =>\n await runOperation(state, 'Satisfiable', document, solver)),\n _solveMode: requestedMode\n }\n }\n\n const operation = metric === 'deadFeatures' ? 'DeadFeatures' : 'FalseOptionalFeatures'\n return {\n [metric]: await safe(async () =>\n await runOperation(state, operation, document, 'pysat')),\n _solveMode: 'SAT' as const\n }\n })\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/analysis/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO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G,EACH,EAAE,EACF,EAAE,EACF,IAAI,CACL,CAAC,CACH,CAAA;IACD,2EAA2E;IAC3E,iDAAiD;IACjD,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IACxD,OAAO,MAAM,GAAG,CAAA;AAClB,CAAC,CAAA;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAwB,EAAgB,EAAE;IACnE,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,oBAAoB,CAAC,gEAAgE,CAAC,CAAA;IAClG,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,IAAI,oBAAoB,CAAC,kDAAkD,CAAC,CAAA;IACpF,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["/**\r\n * The Pyodide/flamapy runtime used for feature model analysis (ADR-021).\r\n *\r\n * Replaces `@lbdudc/flamapy.js`'s own `setupPyodide()`, which calls\r\n * `loadPyodide()` with no options and then `loadPackage('micropip')` — and on a\r\n * cold install that DOWNLOADS `micropip` and `packaging` from\r\n * `cdn.jsdelivr.net`, breaking ADR-002. Worse, with no network it does not\r\n * throw: every operation silently returns `undefined`.\r\n *\r\n * Here both wheels are vendored under `src/analysis/wheels/` and handed to\r\n * pyodide via `packageCacheDir`, so nothing is ever fetched. A canary operation\r\n * proves the bootstrap actually works before the runtime is handed out.\r\n *\r\n * Also replaces the historical `FlamapyWrapper` of the monolith\r\n * (`server/src/utils/flamapyUtils.mjs` before commit ed2e037), which kept a\r\n * module-level `_pyodidePromise` and a module-level `_opQueue`. ADR-014 forbids\r\n * that: the instance AND its serialisation queue live inside a handle the\r\n * CALLER owns.\r\n */\r\nimport fs from 'node:fs'\r\nimport path from 'node:path'\r\nimport { createRequire } from 'node:module'\r\nimport { loadPyodide } from 'pyodide'\r\nimport { executeFlamapyOperation } from '@lbdudc/flamapy.js/lib/python-utils.js'\r\nimport type { PyodideLike } from '@lbdudc/flamapy.js'\r\nimport { resolveAsset } from '../assets.js'\r\nimport { AnalysisRuntimeError, InvalidArgumentError } from '../errors.js'\r\n\r\n/**\r\n * How flamapy is asked to solve an operation.\r\n *\r\n * Declared locally instead of importing `TypeSolving` from\r\n * `@lbdudc/flamapy.js`, and `PyodideHandle` below instead of pyodide's\r\n * `PyodideInterface`, for the reason stated in `feature-model/engine.ts`: no\r\n * `.d.ts` emitted into `dist/` may reference a dependency that ships no types.\r\n * `RuntimeState` is reachable from the public `AnalysisRuntime`, so a\r\n * third-party type in its shape leaks into the published declarations and\r\n * breaks every consumer compiling with `skipLibCheck: false` — which is exactly\r\n * how linea-server and linea-cli are meant to build. Verified by\r\n * `npm run check:consumer`.\r\n */\r\ntype SolvingType = 'basic' | 'pysat' | 'pysat_diagnosis' | 'bdd'\r\n\r\n/** The slice of pyodide's interface this module actually uses. */\r\ninterface PyodideHandle {\r\n FS: unknown\r\n runPythonAsync: (code: string) => Promise<unknown>\r\n loadPackage: (names: string | string[]) => Promise<unknown>\r\n}\r\n\r\ndeclare const analysisRuntimeBrand: unique symbol\r\n\r\n/**\r\n * An initialised analysis runtime.\r\n *\r\n * Opaque: it wraps a Pyodide instance plus the queue that serialises operations\r\n * on it. Create it with `createAnalysisRuntime`, pass it to the analysis\r\n * functions, and release it with `disposeAnalysisRuntime`.\r\n */\r\nexport interface AnalysisRuntime {\r\n readonly [analysisRuntimeBrand]: 'linea-core/AnalysisRuntime'\r\n}\r\n\r\ninterface RuntimeState {\r\n pyodide: PyodideHandle\r\n /**\r\n * Tail of the serialisation chain.\r\n *\r\n * flamapy writes the model to a FIXED path (`uvlfile.uvl`) inside Pyodide's\r\n * virtual filesystem, so two concurrent operations on the same interpreter\r\n * would overwrite each other's input. Every operation queues behind the\r\n * previous one. The queue is per-runtime, never per-module.\r\n */\r\n queue: Promise<void>\r\n disposed: boolean\r\n}\r\n\r\nconst toState = (runtime: AnalysisRuntime): RuntimeState =>\r\n runtime as unknown as RuntimeState\r\n\r\nconst toRuntime = (state: RuntimeState): AnalysisRuntime =>\r\n state as unknown as AnalysisRuntime\r\n\r\n/** Directory holding the vendored wheels (ADR-021). */\r\nconst vendoredWheelsDir = (): string => resolveAsset({ segments: ['analysis', 'wheels'] })\r\n\r\n/**\r\n * The wheels pyodide needs before flamapy can be installed.\r\n *\r\n * Their presence is checked by NAME, not just the directory's, and that check is\r\n * the only thing standing between this module and the network. `packageCacheDir`\r\n * is a CACHE, not an override: on a miss pyodide silently falls back to\r\n * `https://cdn.jsdelivr.net/pyodide/v0.26.2/full/`, downloads the wheel and\r\n * carries on as if nothing happened. Verified — with an empty directory the\r\n * bootstrap SUCCEEDS over the network. So a missing wheel does not degrade the\r\n * runtime, it quietly breaks ADR-002, which is worse: it is a failure that only\r\n * shows up as traffic nobody is watching.\r\n *\r\n * These exact filenames are TIED TO pyodide 0.26.2, which is why `pyodide` is\r\n * pinned exactly in `dependencies` rather than floated. Bumping pyodide means\r\n * re-vendoring the wheels its release expects; if the names stop matching, this\r\n * guard fires and the analysis stops working — loudly, which is the point.\r\n */\r\nconst REQUIRED_WHEELS = ['micropip-0.6.0-py3-none-any.whl', 'packaging-23.2-py3-none-any.whl']\r\n\r\n/** Directory of `@lbdudc/flamapy.js`'s `lib/`, which holds `py/` and its wheels. */\r\nconst flamapyLibDir = (): string => {\r\n const require = createRequire(import.meta.url)\r\n return path.dirname(require.resolve('@lbdudc/flamapy.js/lib/python-utils.js'))\r\n}\r\n\r\n/**\r\n * Directory holding pyodide's own runtime files (`pyodide.asm.wasm`,\r\n * `python_stdlib.zip`, `pyodide-lock.json`).\r\n *\r\n * Passed explicitly rather than left to pyodide's self-location: it derives its\r\n * `indexURL` from its own module URL, which breaks under a bundler or test\r\n * runner that rewrites module paths. Vitest makes it look for\r\n * `node_modules/src/js/pyodide-lock.json`, which does not exist. Resolving from\r\n * the package manifest is stable everywhere.\r\n */\r\nconst pyodideIndexDir = (): string => {\r\n const require = createRequire(import.meta.url)\r\n return path.dirname(require.resolve('pyodide/package.json'))\r\n}\r\n\r\n/** Options for `createAnalysisRuntime`. */\r\nexport interface AnalysisRuntimeOptions {\r\n /**\r\n * Override the directory pyodide loads `micropip`/`packaging` from. Defaults\r\n * to the wheels vendored inside this package; only useful for testing.\r\n */\r\n wheelsDir?: string\r\n}\r\n\r\n/**\r\n * Brings up a Pyodide interpreter with flamapy installed.\r\n *\r\n * Costs roughly 2.3 s, so a caller running several analyses should create ONE\r\n * runtime and reuse it. Everything is read from disk: no network, ever.\r\n *\r\n * Before returning, a canary operation is run. If it fails — or comes back\r\n * `undefined`, which is exactly what a silently broken bootstrap produces — this\r\n * throws instead of handing out a runtime that would report empty metrics\r\n * (ADR-021).\r\n *\r\n * @param options.wheelsDir Optional override of the vendored wheels directory.\r\n * @returns An initialised runtime handle, owned by the caller.\r\n * @throws {AnalysisRuntimeError} when the bootstrap or the canary fails.\r\n */\r\nexport const createAnalysisRuntime = async ({\r\n wheelsDir = vendoredWheelsDir()\r\n}: AnalysisRuntimeOptions = {}): Promise<AnalysisRuntime> => {\r\n if (typeof wheelsDir !== 'string' || wheelsDir.trim() === '') {\r\n throw new InvalidArgumentError('\"wheelsDir\" must be a non-empty path when provided.')\r\n }\r\n if (!fs.existsSync(wheelsDir)) {\r\n throw new AnalysisRuntimeError(\r\n `Vendored wheels directory not found: ${wheelsDir}. The package build must copy src/analysis/wheels/ into dist/.`\r\n )\r\n }\r\n // Checked BEFORE booting pyodide, because after that it is too late: a missing\r\n // wheel is fetched from the CDN and the bootstrap succeeds online. See\r\n // REQUIRED_WHEELS. This is the guard ADR-002 actually rests on.\r\n const missing = REQUIRED_WHEELS.filter(\r\n (wheel) => !fs.existsSync(path.join(wheelsDir, wheel))\r\n )\r\n if (missing.length > 0) {\r\n throw new AnalysisRuntimeError(\r\n `Vendored wheels missing from ${wheelsDir}: ${missing.join(', ')}. ` +\r\n 'Without them pyodide would silently download them from cdn.jsdelivr.net, breaking ADR-002.'\r\n )\r\n }\r\n\r\n const libDir = flamapyLibDir()\r\n let pyodide: PyodideHandle\r\n try {\r\n pyodide = await loadPyodide({\r\n indexURL: pyodideIndexDir(),\r\n packageCacheDir: wheelsDir\r\n })\r\n // pyodide types `FS` as `any`; narrow it to just what is used here.\r\n const vfs = pyodide.FS as {\r\n mkdirTree: (dir: string) => void\r\n mount: (fs: unknown, options: { root: string }, mountpoint: string) => void\r\n filesystems: { NODEFS: unknown }\r\n }\r\n vfs.mkdirTree('/mnt')\r\n vfs.mount(vfs.filesystems.NODEFS, { root: libDir }, '/mnt')\r\n await pyodide.loadPackage('micropip')\r\n await pyodide.runPythonAsync(fs.readFileSync(path.join(libDir, 'py', 'packages.py'), 'utf8'))\r\n await pyodide.runPythonAsync('await install_packages()')\r\n } catch (error) {\r\n throw new AnalysisRuntimeError(\r\n `Could not start the feature model analysis runtime: ${error instanceof Error ? error.message : String(error)}`,\r\n { cause: error }\r\n )\r\n }\r\n\r\n const state: RuntimeState = { pyodide, queue: Promise.resolve(), disposed: false }\r\n\r\n // ── Canary (ADR-021) ───────────────────────────────────────────────────────\r\n // flamapy.js swallows bootstrap failures: `loadAndRunPythonScript` catches and\r\n // only console.errors, and `install_packages()` has its own bare `except`. The\r\n // result is every operation returning `undefined` with no error at all. This\r\n // proves the stack really works before the runtime escapes.\r\n const CANARY_UVL = 'features\\n Root\\n mandatory\\n A\\n B\\n'\r\n let canary: unknown\r\n try {\r\n canary = await runOperation(state, 'core_features', CANARY_UVL, 'basic')\r\n } catch (error) {\r\n throw new AnalysisRuntimeError(\r\n `The analysis runtime started but its canary operation failed: ${error instanceof Error ? error.message : String(error)}`,\r\n { cause: error }\r\n )\r\n }\r\n if (!Array.isArray(canary) || canary.length === 0) {\r\n throw new AnalysisRuntimeError(\r\n 'The analysis runtime started but returned no result for its canary operation. ' +\r\n 'This is the signature of a Pyodide bootstrap that failed silently — most likely the ' +\r\n 'vendored micropip/packaging wheels are missing, so flamapy never installed (ADR-021).'\r\n )\r\n }\r\n\r\n return toRuntime(state)\r\n}\r\n\r\n/**\r\n * Retires a runtime handle.\r\n *\r\n * IT DOES NOT FREE MEMORY, and callers must plan around that. Pyodide exposes no\r\n * teardown, so the ~180 MB WASM heap an interpreter holds stays allocated for\r\n * the life of the process; all this does is mark the handle unusable so later\r\n * analyses fail loudly instead of running on a half-torn-down interpreter.\r\n *\r\n * The practical consequence for linea-server: do NOT create a runtime per\r\n * request. Create a small, long-lived set of them and reuse. Creating and\r\n * disposing per request leaks an interpreter's worth of memory every time.\r\n *\r\n * Idempotent.\r\n *\r\n * @param params.runtime The runtime to retire.\r\n */\r\nexport const disposeAnalysisRuntime = ({ runtime }: { runtime: AnalysisRuntime }): void => {\r\n if (runtime === null || typeof runtime !== 'object') {\r\n throw new InvalidArgumentError('\"runtime\" must be a value returned by createAnalysisRuntime().')\r\n }\r\n const state = toState(runtime)\r\n state.disposed = true\r\n}\r\n\r\n/** Converts a Pyodide proxy into plain JavaScript, mirroring flamapy's `pythonToJs`. */\r\nconst toJs = (value: unknown): unknown => {\r\n if (value === null || typeof value !== 'object') return value\r\n const proxy = value as { toJs?: (options: { dicts: boolean }) => unknown, destroy?: () => void }\r\n if (typeof proxy.toJs !== 'function') return value\r\n const converted = proxy.toJs({ dicts: true })\r\n proxy.destroy?.()\r\n return converted\r\n}\r\n\r\n/**\r\n * Runs one flamapy operation on a runtime, serialised behind any previous one.\r\n *\r\n * INTERNAL. `operation` is a `FLAMAFeatureModel` method name for `'basic'`, or\r\n * the suffix of a `PySAT*`/`BDD*` operation otherwise.\r\n */\r\nexport const runOperation = async (\r\n state: RuntimeState,\r\n operation: string,\r\n uvl: string,\r\n type: SolvingType\r\n): Promise<unknown> => {\r\n if (state.disposed) {\r\n throw new AnalysisRuntimeError('This analysis runtime has already been disposed.')\r\n }\r\n const run = state.queue.then(async () =>\r\n toJs(await executeFlamapyOperation(\r\n state.pyodide as unknown as PyodideLike,\r\n operation,\r\n uvl,\r\n [],\r\n {},\r\n type\r\n ))\r\n )\r\n // Advance the chain even when this operation rejects, or one failure would\r\n // deadlock every later operation on the runtime.\r\n state.queue = run.then(() => undefined, () => undefined)\r\n return await run\r\n}\r\n\r\n/** INTERNAL: unwraps a handle for the analysis functions. */\r\nexport const useRuntime = (runtime: AnalysisRuntime): RuntimeState => {\r\n if (runtime === null || typeof runtime !== 'object') {\r\n throw new InvalidArgumentError('\"runtime\" must be a value returned by createAnalysisRuntime().')\r\n }\r\n const state = toState(runtime)\r\n if (state.disposed) {\r\n throw new AnalysisRuntimeError('This analysis runtime has already been disposed.')\r\n }\r\n return state\r\n}\r\n"]}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/analysis/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAmDzE,MAAM,OAAO,GAAG,CAAC,OAAwB,EAAgB,EAAE,CACzD,OAAkC,CAAA;AAEpC,MAAM,SAAS,GAAG,CAAC,KAAmB,EAAmB,EAAE,CACzD,KAAmC,CAAA;AAErC,uDAAuD;AACvD,MAAM,iBAAiB,GAAG,GAAW,EAAE,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,C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B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,IAAI,oBAAoB,CAAC,kDAAkD,CAAC,CAAA;IACpF,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["/**\n * The Pyodide/flamapy runtime used for feature model analysis (ADR-021).\n *\n * Replaces `@lbdudc/flamapy.js`'s own `setupPyodide()`, which calls\n * `loadPyodide()` with no options and then `loadPackage('micropip')` — and on a\n * cold install that DOWNLOADS `micropip` and `packaging` from\n * `cdn.jsdelivr.net`, breaking ADR-002. Worse, with no network it does not\n * throw: every operation silently returns `undefined`.\n *\n * Here both wheels are vendored under `src/analysis/wheels/` and handed to\n * pyodide via `packageCacheDir`, so nothing is ever fetched. A canary operation\n * proves the bootstrap actually works before the runtime is handed out.\n *\n * Also replaces the historical `FlamapyWrapper` of the monolith\n * (`server/src/utils/flamapyUtils.mjs` before commit ed2e037), which kept a\n * module-level `_pyodidePromise` and a module-level `_opQueue`. ADR-014 forbids\n * that: the instance AND its serialisation queue live inside a handle the\n * CALLER owns.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { createRequire } from 'node:module'\nimport { loadPyodide } from 'pyodide'\nimport { executeFlamapyOperation } from '@lbdudc/flamapy.js/lib/python-utils.js'\nimport type { PyodideLike } from '@lbdudc/flamapy.js'\nimport { resolveAsset } from '../assets.js'\nimport { AnalysisRuntimeError, InvalidArgumentError } from '../errors.js'\n\n/**\n * How flamapy is asked to solve an operation.\n *\n * Declared locally instead of importing `TypeSolving` from\n * `@lbdudc/flamapy.js`, and `PyodideHandle` below instead of pyodide's\n * `PyodideInterface`, for the reason stated in `feature-model/engine.ts`: no\n * `.d.ts` emitted into `dist/` may reference a dependency that ships no types.\n * `RuntimeState` is reachable from the public `AnalysisRuntime`, so a\n * third-party type in its shape leaks into the published declarations and\n * breaks every consumer compiling with `skipLibCheck: false` — which is exactly\n * how linea-server and linea-cli are meant to build. Verified by\n * `npm run check:consumer`.\n */\ntype SolvingType = 'basic' | 'pysat' | 'pysat_diagnosis' | 'bdd'\n\n/** The slice of pyodide's interface this module actually uses. */\ninterface PyodideHandle {\n FS: unknown\n runPythonAsync: (code: string) => Promise<unknown>\n loadPackage: (names: string | string[]) => Promise<unknown>\n}\n\ndeclare const analysisRuntimeBrand: unique symbol\n\n/**\n * An initialised analysis runtime.\n *\n * Opaque: it wraps a Pyodide instance plus the queue that serialises operations\n * on it. Create it with `createAnalysisRuntime`, pass it to the analysis\n * functions, and release it with `disposeAnalysisRuntime`.\n */\nexport interface AnalysisRuntime {\n readonly [analysisRuntimeBrand]: 'linea-core/AnalysisRuntime'\n}\n\ninterface RuntimeState {\n pyodide: PyodideHandle\n /**\n * Tail of the serialisation chain.\n *\n * flamapy writes the model to a FIXED path (`uvlfile.uvl`) inside Pyodide's\n * virtual filesystem, so two concurrent operations on the same interpreter\n * would overwrite each other's input. Every operation queues behind the\n * previous one. The queue is per-runtime, never per-module.\n */\n queue: Promise<void>\n disposed: boolean\n}\n\nconst toState = (runtime: AnalysisRuntime): RuntimeState =>\n runtime as unknown as RuntimeState\n\nconst toRuntime = (state: RuntimeState): AnalysisRuntime =>\n state as unknown as AnalysisRuntime\n\n/** Directory holding the vendored wheels (ADR-021). */\nconst vendoredWheelsDir = (): string => resolveAsset({ segments: ['analysis', 'wheels'] })\n\n/**\n * The wheels pyodide needs before flamapy can be installed.\n *\n * Their presence is checked by NAME, not just the directory's, and that check is\n * the only thing standing between this module and the network. `packageCacheDir`\n * is a CACHE, not an override: on a miss pyodide silently falls back to\n * `https://cdn.jsdelivr.net/pyodide/v0.26.2/full/`, downloads the wheel and\n * carries on as if nothing happened. Verified — with an empty directory the\n * bootstrap SUCCEEDS over the network. So a missing wheel does not degrade the\n * runtime, it quietly breaks ADR-002, which is worse: it is a failure that only\n * shows up as traffic nobody is watching.\n *\n * These exact filenames are TIED TO pyodide 0.26.2, which is why `pyodide` is\n * pinned exactly in `dependencies` rather than floated. Bumping pyodide means\n * re-vendoring the wheels its release expects; if the names stop matching, this\n * guard fires and the analysis stops working — loudly, which is the point.\n */\nconst REQUIRED_WHEELS = ['micropip-0.6.0-py3-none-any.whl', 'packaging-23.2-py3-none-any.whl']\n\n/** Directory of `@lbdudc/flamapy.js`'s `lib/`, which holds `py/` and its wheels. */\nconst flamapyLibDir = (): string => {\n const require = createRequire(import.meta.url)\n return path.dirname(require.resolve('@lbdudc/flamapy.js/lib/python-utils.js'))\n}\n\n/**\n * Directory holding pyodide's own runtime files (`pyodide.asm.wasm`,\n * `python_stdlib.zip`, `pyodide-lock.json`).\n *\n * Passed explicitly rather than left to pyodide's self-location: it derives its\n * `indexURL` from its own module URL, which breaks under a bundler or test\n * runner that rewrites module paths. Vitest makes it look for\n * `node_modules/src/js/pyodide-lock.json`, which does not exist. Resolving from\n * the package manifest is stable everywhere.\n */\nconst pyodideIndexDir = (): string => {\n const require = createRequire(import.meta.url)\n return path.dirname(require.resolve('pyodide/package.json'))\n}\n\n/** Options for `createAnalysisRuntime`. */\nexport interface AnalysisRuntimeOptions {\n /**\n * Override the directory pyodide loads `micropip`/`packaging` from. Defaults\n * to the wheels vendored inside this package; only useful for testing.\n */\n wheelsDir?: string\n}\n\n/**\n * Brings up a Pyodide interpreter with flamapy installed.\n *\n * Costs roughly 2.3 s, so a caller running several analyses should create ONE\n * runtime and reuse it. Everything is read from disk: no network, ever.\n *\n * Before returning, a canary operation is run. If it fails — or comes back\n * `undefined`, which is exactly what a silently broken bootstrap produces — this\n * throws instead of handing out a runtime that would report empty metrics\n * (ADR-021).\n *\n * @param options.wheelsDir Optional override of the vendored wheels directory.\n * @returns An initialised runtime handle, owned by the caller.\n * @throws {AnalysisRuntimeError} when the bootstrap or the canary fails.\n */\nexport const createAnalysisRuntime = async ({\n wheelsDir = vendoredWheelsDir()\n}: AnalysisRuntimeOptions = {}): Promise<AnalysisRuntime> => {\n if (typeof wheelsDir !== 'string' || wheelsDir.trim() === '') {\n throw new InvalidArgumentError('\"wheelsDir\" must be a non-empty path when provided.')\n }\n if (!fs.existsSync(wheelsDir)) {\n throw new AnalysisRuntimeError(\n `Vendored wheels directory not found: ${wheelsDir}. The package build must copy src/analysis/wheels/ into dist/.`\n )\n }\n // Checked BEFORE booting pyodide, because after that it is too late: a missing\n // wheel is fetched from the CDN and the bootstrap succeeds online. See\n // REQUIRED_WHEELS. This is the guard ADR-002 actually rests on.\n const missing = REQUIRED_WHEELS.filter(\n (wheel) => !fs.existsSync(path.join(wheelsDir, wheel))\n )\n if (missing.length > 0) {\n throw new AnalysisRuntimeError(\n `Vendored wheels missing from ${wheelsDir}: ${missing.join(', ')}. ` +\n 'Without them pyodide would silently download them from cdn.jsdelivr.net, breaking ADR-002.'\n )\n }\n\n const libDir = flamapyLibDir()\n let pyodide: PyodideHandle\n try {\n pyodide = await loadPyodide({\n indexURL: pyodideIndexDir(),\n packageCacheDir: wheelsDir\n })\n // pyodide types `FS` as `any`; narrow it to just what is used here.\n const vfs = pyodide.FS as {\n mkdirTree: (dir: string) => void\n mount: (fs: unknown, options: { root: string }, mountpoint: string) => void\n filesystems: { NODEFS: unknown }\n }\n vfs.mkdirTree('/mnt')\n vfs.mount(vfs.filesystems.NODEFS, { root: libDir }, '/mnt')\n await pyodide.loadPackage('micropip')\n await pyodide.runPythonAsync(fs.readFileSync(path.join(libDir, 'py', 'packages.py'), 'utf8'))\n await pyodide.runPythonAsync('await install_packages()')\n } catch (error) {\n throw new AnalysisRuntimeError(\n `Could not start the feature model analysis runtime: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n\n const state: RuntimeState = { pyodide, queue: Promise.resolve(), disposed: false }\n\n // ── Canary (ADR-021) ───────────────────────────────────────────────────────\n // flamapy.js swallows bootstrap failures: `loadAndRunPythonScript` catches and\n // only console.errors, and `install_packages()` has its own bare `except`. The\n // result is every operation returning `undefined` with no error at all. This\n // proves the stack really works before the runtime escapes.\n const CANARY_UVL = 'features\\n Root\\n mandatory\\n A\\n B\\n'\n let canary: unknown\n try {\n canary = await runOperation(state, 'core_features', CANARY_UVL, 'basic')\n } catch (error) {\n throw new AnalysisRuntimeError(\n `The analysis runtime started but its canary operation failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n if (!Array.isArray(canary) || canary.length === 0) {\n throw new AnalysisRuntimeError(\n 'The analysis runtime started but returned no result for its canary operation. ' +\n 'This is the signature of a Pyodide bootstrap that failed silently — most likely the ' +\n 'vendored micropip/packaging wheels are missing, so flamapy never installed (ADR-021).'\n )\n }\n\n return toRuntime(state)\n}\n\n/**\n * Retires a runtime handle.\n *\n * IT DOES NOT FREE MEMORY, and callers must plan around that. Pyodide exposes no\n * teardown, so the ~180 MB WASM heap an interpreter holds stays allocated for\n * the life of the process; all this does is mark the handle unusable so later\n * analyses fail loudly instead of running on a half-torn-down interpreter.\n *\n * The practical consequence for linea-server: do NOT create a runtime per\n * request. Create a small, long-lived set of them and reuse. Creating and\n * disposing per request leaks an interpreter's worth of memory every time.\n *\n * Idempotent.\n *\n * @param params.runtime The runtime to retire.\n */\nexport const disposeAnalysisRuntime = ({ runtime }: { runtime: AnalysisRuntime }): void => {\n if (runtime === null || typeof runtime !== 'object') {\n throw new InvalidArgumentError('\"runtime\" must be a value returned by createAnalysisRuntime().')\n }\n const state = toState(runtime)\n state.disposed = true\n}\n\n/** Converts a Pyodide proxy into plain JavaScript, mirroring flamapy's `pythonToJs`. */\nconst toJs = (value: unknown): unknown => {\n if (value === null || typeof value !== 'object') return value\n const proxy = value as { toJs?: (options: { dicts: boolean }) => unknown, destroy?: () => void }\n if (typeof proxy.toJs !== 'function') return value\n const converted = proxy.toJs({ dicts: true })\n proxy.destroy?.()\n return converted\n}\n\n/**\n * Runs one flamapy operation on a runtime, serialised behind any previous one.\n *\n * INTERNAL. `operation` is a `FLAMAFeatureModel` method name for `'basic'`, or\n * the suffix of a `PySAT*`/`BDD*` operation otherwise.\n */\nexport const runOperation = async (\n state: RuntimeState,\n operation: string,\n uvl: string,\n type: SolvingType\n): Promise<unknown> => {\n if (state.disposed) {\n throw new AnalysisRuntimeError('This analysis runtime has already been disposed.')\n }\n const run = state.queue.then(async () =>\n toJs(await executeFlamapyOperation(\n state.pyodide as unknown as PyodideLike,\n operation,\n uvl,\n [],\n {},\n type\n ))\n )\n // Advance the chain even when this operation rejects, or one failure would\n // deadlock every later operation on the runtime.\n state.queue = run.then(() => undefined, () => undefined)\n return await run\n}\n\n/** INTERNAL: unwraps a handle for the analysis functions. */\nexport const useRuntime = (runtime: AnalysisRuntime): RuntimeState => {\n if (runtime === null || typeof runtime !== 'object') {\n throw new InvalidArgumentError('\"runtime\" must be a value returned by createAnalysisRuntime().')\n }\n const state = toState(runtime)\n if (state.disposed) {\n throw new AnalysisRuntimeError('This analysis runtime has already been disposed.')\n }\n return state\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAEpF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,QAAQ,EAA0B,EAAU,EAAE;IAC3E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,oBAAoB,CAAC,yCAAyC,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,QAAQ,CAAC,CAAA;AAC7C,CAAC,CAAA","sourcesContent":["/**\r\n * Resolution of assets packaged with the library.\r\n *\r\n * Non-TypeScript files under `src/` (line templates, pipeline files...) are not\r\n * compiled: `scripts/copy-assets.mjs` mirrors them into `dist/` at build time,\r\n * preserving their relative path. That means `src/line/templates/x` ends up at\r\n * `dist/line/templates/x`, so the path relative to THIS module is the same\r\n * before and after the build.\r\n *\r\n * Resolution goes through `import.meta.url` and never through `process.cwd()`:\r\n * linea-core is a library and must work regardless of where the host process was\r\n * started from (ADR-014).\r\n */\r\nimport path from 'node:path'\r\nimport { fileURLToPath } from 'node:url'\r\nimport { InvalidArgumentError } from './errors.js'\r\n\r\n/**\r\n * Directory holding the packaged assets: `src/` when running from source,\r\n * `dist/` when running from the published package.\r\n */\r\nexport const assetsRoot = (): string => path.dirname(fileURLToPath(import.meta.url))\r\n\r\n/**\r\n * Resolves the absolute path of an asset shipped with linea-core.\r\n *\r\n * @param params.segments Path segments relative to the assets root,\r\n * e.g. `resolveAsset({ segments: ['line', 'templates', 'config.json'] })`.\r\n * @returns Absolute path of the asset.\r\n * @throws {InvalidArgumentError} if `segments` is not an array of strings.\r\n */\r\nexport const resolveAsset = ({ segments }: { segments: string[] }): string => {\r\n if (!Array.isArray(segments) || segments.some((segment) => typeof segment !== 'string')) {\r\n throw new InvalidArgumentError('\"segments\" must be an array of strings.')\r\n }\r\n return path.join(assetsRoot(), ...segments)\r\n}\r\n"]}
1
+ {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAEpF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,QAAQ,EAA0B,EAAU,EAAE;IAC3E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,oBAAoB,CAAC,yCAAyC,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,QAAQ,CAAC,CAAA;AAC7C,CAAC,CAAA","sourcesContent":["/**\n * Resolution of assets packaged with the library.\n *\n * Non-TypeScript files under `src/` (line templates, pipeline files...) are not\n * compiled: `scripts/copy-assets.mjs` mirrors them into `dist/` at build time,\n * preserving their relative path. That means `src/line/templates/x` ends up at\n * `dist/line/templates/x`, so the path relative to THIS module is the same\n * before and after the build.\n *\n * Resolution goes through `import.meta.url` and never through `process.cwd()`:\n * linea-core is a library and must work regardless of where the host process was\n * started from (ADR-014).\n */\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { InvalidArgumentError } from './errors.js'\n\n/**\n * Directory holding the packaged assets: `src/` when running from source,\n * `dist/` when running from the published package.\n */\nexport const assetsRoot = (): string => path.dirname(fileURLToPath(import.meta.url))\n\n/**\n * Resolves the absolute path of an asset shipped with linea-core.\n *\n * @param params.segments Path segments relative to the assets root,\n * e.g. `resolveAsset({ segments: ['line', 'templates', 'config.json'] })`.\n * @returns Absolute path of the asset.\n * @throws {InvalidArgumentError} if `segments` is not an array of strings.\n */\nexport const resolveAsset = ({ segments }: { segments: string[] }): string => {\n if (!Array.isArray(segments) || segments.some((segment) => typeof segment !== 'string')) {\n throw new InvalidArgumentError('\"segments\" must be an array of strings.')\n }\n return path.join(assetsRoot(), ...segments)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,cAAc;IACpB,0EAA0E;IAC1E,IAAI,EAAE,mBAAmB;IACzB,4DAA4D;IAC5D,KAAK,EAAE,wBAAwB;IAC/B,kFAAkF;IAClF,QAAQ,EAAE,wBAAwB;IAClC,8BAA8B;IAC9B,MAAM,EAAE,0BAA0B;IAClC,+BAA+B;IAC/B,OAAO,EAAE,uBAAuB;IAChC,sCAAsC;IACtC,cAAc,EAAE,gCAAgC;CACxC,CAAA;AAEV;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAA;AAElD;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAA;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAA;AAElC,uDAAuD;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAA;AAK1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,sDAAsD;IACtD,eAAe,EAAE,EAAE;IACnB,0DAA0D;IAC1D,OAAO,EAAE,GAAG;CACJ,CAAA;AAEV,mEAAmE;AACnE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAA6B,EAAE,CAC9E,OAAO,KAAK,KAAK,QAAQ,IAAK,mBAAyC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA","sourcesContent":["/**\r\n * Domain constants of linea-core.\r\n *\r\n * ADR-014 forbids global mutable configuration, so everything the monolith read\r\n * from `linea/server/src/resources/properties.yml` at runtime is frozen here as\r\n * a constant. Callers that need different paths pass them explicitly.\r\n */\r\n\r\n/**\r\n * Layout of a line's platform directory inside its repository.\r\n *\r\n * Migrated from `linea/server/src/resources/properties.yml` (`paths.platform.*`).\r\n * The `./` prefix used by the YAML is dropped: these are repo-relative segments\r\n * meant to be joined with a working directory (see `resolveLinePaths`).\r\n */\r\nexport const PLATFORM_PATHS = {\r\n /** `paths.platform.root` */\r\n root: 'src/platform',\r\n /** `paths.platform.code` — annotated source consumed by spl-js-engine. */\r\n code: 'src/platform/code',\r\n /** `paths.platform.model` — default (UVL) feature model. */\r\n model: 'src/platform/model.uvl',\r\n /** XML variant. properties.yml derives it via `model.replace('.uvl', '.xml')`. */\r\n modelXml: 'src/platform/model.xml',\r\n /** `paths.platform.config` */\r\n config: 'src/platform/config.json',\r\n /** `paths.platform.extraJS` */\r\n extraJs: 'src/platform/extra.js',\r\n /** `paths.platform.transformation` */\r\n transformation: 'src/platform/transformation.js'\r\n} as const\r\n\r\n/**\r\n * Product index kept at the root of every line repository (ADR-011).\r\n * Format: `{ \"productos\": [{ \"name\", \"repositorio\", \"version\"? }] }`, where\r\n * `version` is the optional, retro-compatible extension ADR-011 foresaw.\r\n */\r\nexport const PRODUCTS_INDEX_PATH = 'products.json'\r\n\r\n/**\r\n * Valid characters for line and product names.\r\n * Migrated from `linea/server/src/rest/validators/commonValidators.js:NAME_PATTERN`.\r\n */\r\nexport const NAME_PATTERN = /^[a-zA-Z0-9_\\-.]+$/\r\n\r\n/**\r\n * Product version format (`x.y.z`).\r\n * Migrated from `linea/server/src/rest/validators/commonValidators.js:VERSION_PATTERN`.\r\n */\r\nexport const VERSION_PATTERN = /^\\d+\\.\\d+\\.\\d+$/\r\n\r\n/**\r\n * Default UI languages of a generated product.\r\n * Migrated from `linea/server/src/model/entities/product.js:32` and applied as a\r\n * fallback in `generatePipeline.js:218`.\r\n */\r\nexport const DEFAULT_LANGUAGES = ['en', 'es', 'gl'] as const\r\n\r\n/**\r\n * Default spatial reference system of a generated product.\r\n * Migrated from `linea/server/src/model/entities/product.js:36`.\r\n */\r\nexport const DEFAULT_SRID = '4326'\r\n\r\n/** Feature model notations supported by the engine. */\r\nexport const FEATURE_MODEL_TYPES = ['UVL', 'XML'] as const\r\n\r\n/** A feature model notation. */\r\nexport type FeatureModelType = (typeof FEATURE_MODEL_TYPES)[number]\r\n\r\n/**\r\n * Analysis guard rails, kept for parity with `linea/flamapy-server/main.py`\r\n * (`SKIP_ENUM`, `SKIP_BDD`). Full configuration enumeration and BDD construction\r\n * are exponential; above these feature counts the monolith skips them.\r\n *\r\n * Consumed by `src/analysis/`, which lands in a later batch together with the\r\n * offline-bootstrap ADR.\r\n */\r\nexport const ANALYSIS_THRESHOLDS = {\r\n /** Skip full enumeration above this feature count. */\r\n skipEnumeration: 30,\r\n /** Skip BDD-based operations above this feature count. */\r\n skipBdd: 100\r\n} as const\r\n\r\n/** Narrowing helper for values coming from outside the library. */\r\nexport const isFeatureModelType = (value: unknown): value is FeatureModelType =>\r\n typeof value === 'string' && (FEATURE_MODEL_TYPES as readonly string[]).includes(value)\r\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,cAAc;IACpB,0EAA0E;IAC1E,IAAI,EAAE,mBAAmB;IACzB,4DAA4D;IAC5D,KAAK,EAAE,wBAAwB;IAC/B,kFAAkF;IAClF,QAAQ,EAAE,wBAAwB;IAClC,8BAA8B;IAC9B,MAAM,EAAE,0BAA0B;IAClC,+BAA+B;IAC/B,OAAO,EAAE,uBAAuB;IAChC,sCAAsC;IACtC,cAAc,EAAE,gCAAgC;CACxC,CAAA;AAEV;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAA;AAElD;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAA;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAA;AAElC,uDAAuD;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAA;AAK1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,sDAAsD;IACtD,eAAe,EAAE,EAAE;IACnB,0DAA0D;IAC1D,OAAO,EAAE,GAAG;CACJ,CAAA;AAEV,mEAAmE;AACnE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAA6B,EAAE,CAC9E,OAAO,KAAK,KAAK,QAAQ,IAAK,mBAAyC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA","sourcesContent":["/**\n * Domain constants of linea-core.\n *\n * ADR-014 forbids global mutable configuration, so everything the monolith read\n * from `linea/server/src/resources/properties.yml` at runtime is frozen here as\n * a constant. Callers that need different paths pass them explicitly.\n */\n\n/**\n * Layout of a line's platform directory inside its repository.\n *\n * Migrated from `linea/server/src/resources/properties.yml` (`paths.platform.*`).\n * The `./` prefix used by the YAML is dropped: these are repo-relative segments\n * meant to be joined with a working directory (see `resolveLinePaths`).\n */\nexport const PLATFORM_PATHS = {\n /** `paths.platform.root` */\n root: 'src/platform',\n /** `paths.platform.code` — annotated source consumed by spl-js-engine. */\n code: 'src/platform/code',\n /** `paths.platform.model` — default (UVL) feature model. */\n model: 'src/platform/model.uvl',\n /** XML variant. properties.yml derives it via `model.replace('.uvl', '.xml')`. */\n modelXml: 'src/platform/model.xml',\n /** `paths.platform.config` */\n config: 'src/platform/config.json',\n /** `paths.platform.extraJS` */\n extraJs: 'src/platform/extra.js',\n /** `paths.platform.transformation` */\n transformation: 'src/platform/transformation.js'\n} as const\n\n/**\n * Product index kept at the root of every line repository (ADR-011).\n * Format: `{ \"productos\": [{ \"name\", \"repositorio\", \"version\"? }] }`, where\n * `version` is the optional, retro-compatible extension ADR-011 foresaw.\n */\nexport const PRODUCTS_INDEX_PATH = 'products.json'\n\n/**\n * Valid characters for line and product names.\n * Migrated from `linea/server/src/rest/validators/commonValidators.js:NAME_PATTERN`.\n */\nexport const NAME_PATTERN = /^[a-zA-Z0-9_\\-.]+$/\n\n/**\n * Product version format (`x.y.z`).\n * Migrated from `linea/server/src/rest/validators/commonValidators.js:VERSION_PATTERN`.\n */\nexport const VERSION_PATTERN = /^\\d+\\.\\d+\\.\\d+$/\n\n/**\n * Default UI languages of a generated product.\n * Migrated from `linea/server/src/model/entities/product.js:32` and applied as a\n * fallback in `generatePipeline.js:218`.\n */\nexport const DEFAULT_LANGUAGES = ['en', 'es', 'gl'] as const\n\n/**\n * Default spatial reference system of a generated product.\n * Migrated from `linea/server/src/model/entities/product.js:36`.\n */\nexport const DEFAULT_SRID = '4326'\n\n/** Feature model notations supported by the engine. */\nexport const FEATURE_MODEL_TYPES = ['UVL', 'XML'] as const\n\n/** A feature model notation. */\nexport type FeatureModelType = (typeof FEATURE_MODEL_TYPES)[number]\n\n/**\n * Analysis guard rails, kept for parity with `linea/flamapy-server/main.py`\n * (`SKIP_ENUM`, `SKIP_BDD`). Full configuration enumeration and BDD construction\n * are exponential; above these feature counts the monolith skips them.\n *\n * Consumed by `src/analysis/`, which lands in a later batch together with the\n * offline-bootstrap ADR.\n */\nexport const ANALYSIS_THRESHOLDS = {\n /** Skip full enumeration above this feature count. */\n skipEnumeration: 30,\n /** Skip BDD-based operations above this feature count. */\n skipBdd: 100\n} as const\n\n/** Narrowing helper for values coming from outside the library. */\nexport const isFeatureModelType = (value: unknown): value is FeatureModelType =>\n typeof value === 'string' && (FEATURE_MODEL_TYPES as readonly string[]).includes(value)\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/derivation/derive.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAElE;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAqB,EAAE,CAC5D,eAAe,CAAC,EAAE,IAAI,EAAE,CAAiC,CAAA;AAE3D,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAU,EAAE;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAAC,qCAAqC,CAAC,CAAA;IACvE,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAAa,EAAe,EAAE;IAChD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;IAC7D,CAAC;IACD,OAAO,IAAmB,CAAA;AAC5B,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,IAAI,EACJ,SAAS,EAKV,EAAkC,EAAE;IACnC,aAAa,CAAC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C;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Product derivation with spl-js-engine.\r\n *\r\n * Migrated from:\r\n * - `linea/server/src/model/services/generatePipeline.js:runEngine` (~132-147)\r\n * - `linea/server/src/model/services/ProductService.js:generateZip` (~352-394)\r\n *\r\n * Everything those two do around the engine belongs to linea-server (ADR-003):\r\n * downloading the line archive from GitLab, permission checks, the temp\r\n * directory dance and the Mongo transaction.\r\n */\r\nimport type { ProductSpec as EngineProductSpec } from 'spl-js-engine'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { ensureDir } from '../fs/workspace.js'\r\nimport { buildEngineSpec } from '../product/engine-spec.js'\r\nimport type { ProductSpec } from '../product/spec.js'\r\nimport { createEngine, rethrowDerivationError } from './engine.js'\r\n\r\n/**\r\n * Hands the spec to the engine unchanged, as `runEngine` does.\r\n *\r\n * The cast is needed because linea-core's `ProductSpec.features` also admits the\r\n * legacy object-map form `{ Feature: true }`, while the engine's\r\n * `completeFeatureSelection` requires a string array.\r\n *\r\n * NOT normalised here, on purpose: the monolith passes `buildEngineSpec(spec)`\r\n * straight through, so an object-map spec fails there too. Normalising silently\r\n * would be a behaviour change hidden inside derivation. Callers holding a legacy\r\n * spec should run it through `normalizeFeatureSelection` first.\r\n */\r\nconst toEngineSpec = (spec: ProductSpec): EngineProductSpec =>\r\n buildEngineSpec({ spec }) as unknown as EngineProductSpec\r\n\r\nconst assertLineDir = (lineDir: unknown): string => {\r\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\r\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\r\n }\r\n return lineDir\r\n}\r\n\r\nconst assertSpec = (spec: unknown): ProductSpec => {\r\n if (typeof spec !== 'object' || spec === null || Array.isArray(spec)) {\r\n throw new InvalidArgumentError('\"spec\" must be an object.')\r\n }\r\n return spec as ProductSpec\r\n}\r\n\r\n/**\r\n * Derives a product into a directory.\r\n *\r\n * The spec goes through `buildEngineSpec` first, exactly as `runEngine` does, so\r\n * a product carrying a parsed sensor DSL takes the engine's shortcut path.\r\n *\r\n * DELIBERATE DIVERGENCE 1: `runEngine` finishes with\r\n * `fs.rmSync(lineOutput, { recursive: true, force: true })`, deleting the line\r\n * directory it just consumed. linea-core deletes NOTHING. Those directories\r\n * belong to the caller — in the monolith they happen to be throwaway temp dirs,\r\n * but here `lineDir` may well be a user's working copy. Cleaning up is the\r\n * caller's decision (ADR-009/ADR-014). A test pins this.\r\n *\r\n * DELIBERATE DIVERGENCE 2, and the one that matters most for whoever ports\r\n * linea-server: `runEngine` writes\r\n * `(await engine(lineOutput)).generateProduct(...)`. It awaits the CONSTRUCTOR\r\n * — which does return a promise — but NOT the generation, which returns one\r\n * too. So in the monolith the surrounding `try/catch` cannot catch anything\r\n * thrown during generation: the `FeatureSelectionError` its very next line\r\n * means to turn into a 400 becomes an unhandled rejection instead, and the\r\n * `rmSync` above runs while generation may still be reading the directory.\r\n *\r\n * linea-core awaits (below), which fixes both. The consequence is that the\r\n * error classification here does NOT merely replicate `runEngine`'s — it is\r\n * strictly more effective, because in the monolith most of those errors never\r\n * reach the `catch` at all.\r\n *\r\n * @param params.lineDir Line working directory (holding `src/platform/...`).\r\n * @param params.spec Product spec.\r\n * @param params.outputDir Directory to generate into. Created if missing.\r\n * @returns The directory that was generated into.\r\n * @throws {FeatureSelectionInvalidError} when the spec's feature selection is\r\n * not valid for the line's feature model.\r\n * @throws {LinePlatformNotFoundError} when the line has no usable platform, or\r\n * for any other engine failure — including a template calling a helper that\r\n * `extra.js` does not define, reported with the\r\n * `error_messages.missing_function_error` key.\r\n * @throws {InvalidArgumentError} when the arguments are malformed.\r\n */\r\nexport const deriveProduct = async ({\r\n lineDir,\r\n spec,\r\n outputDir\r\n}: {\r\n lineDir: string\r\n spec: ProductSpec\r\n outputDir: string\r\n}): Promise<{ outputDir: string }> => {\r\n assertLineDir(lineDir)\r\n const checkedSpec = assertSpec(spec)\r\n if (typeof outputDir !== 'string' || outputDir.trim() === '') {\r\n throw new InvalidArgumentError('\"outputDir\" must be a non-empty path.')\r\n }\r\n\r\n const target = ensureDir({ dirPath: outputDir })\r\n\r\n try {\r\n const engine = await createEngine(lineDir)\r\n await engine.generateProduct(target, toEngineSpec(checkedSpec))\r\n } catch (error) {\r\n rethrowDerivationError(error)\r\n }\r\n\r\n return { outputDir: target }\r\n}\r\n\r\n/**\r\n * Derives a product into a zip archive, without writing the generated tree.\r\n *\r\n * Same classification of failures as `deriveProduct`, matching `generateZip`.\r\n *\r\n * RETURN TYPE: the engine hands back a JSZip instance\r\n * (`spl-js-engine/src/output.js:ZipOutput`), which the monolith's controller\r\n * turns into base64 at the HTTP edge (`ProductController.js:117`). linea-core\r\n * materialises it into a `Buffer` instead, so the result is a real artifact a\r\n * caller can write, hash or feed to `extractArchive` without knowing anything\r\n * about JSZip. linea-server gets its base64 with `buffer.toString('base64')`.\r\n *\r\n * @param params.lineDir Line working directory.\r\n * @param params.spec Product spec.\r\n * @returns The zip archive bytes.\r\n * @throws The same errors as `deriveProduct`.\r\n */\r\nexport const deriveProductToZip = async ({\r\n lineDir,\r\n spec\r\n}: {\r\n lineDir: string\r\n spec: ProductSpec\r\n}): Promise<Buffer> => {\r\n assertLineDir(lineDir)\r\n const checkedSpec = assertSpec(spec)\r\n\r\n try {\r\n const engine = await createEngine(lineDir)\r\n const zip = await engine.generateZip(toEngineSpec(checkedSpec))\r\n const archive = zip as { generateAsync: (options: { type: 'nodebuffer' }) => Promise<Buffer> }\r\n return await archive.generateAsync({ type: 'nodebuffer' })\r\n } catch (error) {\r\n return rethrowDerivationError(error)\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/derivation/derive.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,YAAY,E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AC,CAAA;QAC1C,MAAM,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sBAAsB,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAA;AAC9B,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,OAAO,EACP,IAAI,EAIL,EAAmB,EAAE;IACpB,aAAa,CAAC,OAAO,CAAC,CAAA;IACtB,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAEpC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAA;QAC1C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;QAC/D,MAAM,OAAO,GAAG,GAA8E,CAAA;QAC9F,OAAO,MAAM,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;AACH,CAAC,CAAA","sourcesContent":["/**\n * Product derivation with spl-js-engine.\n *\n * Migrated from:\n * - `linea/server/src/model/services/generatePipeline.js:runEngine` (~132-147)\n * - `linea/server/src/model/services/ProductService.js:generateZip` (~352-394)\n *\n * Everything those two do around the engine belongs to linea-server (ADR-003):\n * downloading the line archive from GitLab, permission checks, the temp\n * directory dance and the Mongo transaction.\n */\nimport type { ProductSpec as EngineProductSpec } from 'spl-js-engine'\nimport { InvalidArgumentError } from '../errors.js'\nimport { ensureDir } from '../fs/workspace.js'\nimport { buildEngineSpec } from '../product/engine-spec.js'\nimport type { ProductSpec } from '../product/spec.js'\nimport { createEngine, rethrowDerivationError } from './engine.js'\n\n/**\n * Hands the spec to the engine unchanged, as `runEngine` does.\n *\n * The cast is needed because linea-core's `ProductSpec.features` also admits the\n * legacy object-map form `{ Feature: true }`, while the engine's\n * `completeFeatureSelection` requires a string array.\n *\n * NOT normalised here, on purpose: the monolith passes `buildEngineSpec(spec)`\n * straight through, so an object-map spec fails there too. Normalising silently\n * would be a behaviour change hidden inside derivation. Callers holding a legacy\n * spec should run it through `normalizeFeatureSelection` first.\n */\nconst toEngineSpec = (spec: ProductSpec): EngineProductSpec =>\n buildEngineSpec({ spec }) as unknown as EngineProductSpec\n\nconst assertLineDir = (lineDir: unknown): string => {\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\n }\n return lineDir\n}\n\nconst assertSpec = (spec: unknown): ProductSpec => {\n if (typeof spec !== 'object' || spec === null || Array.isArray(spec)) {\n throw new InvalidArgumentError('\"spec\" must be an object.')\n }\n return spec as ProductSpec\n}\n\n/**\n * Derives a product into a directory.\n *\n * The spec goes through `buildEngineSpec` first, exactly as `runEngine` does, so\n * a product carrying a parsed sensor DSL takes the engine's shortcut path.\n *\n * DELIBERATE DIVERGENCE 1: `runEngine` finishes with\n * `fs.rmSync(lineOutput, { recursive: true, force: true })`, deleting the line\n * directory it just consumed. linea-core deletes NOTHING. Those directories\n * belong to the caller — in the monolith they happen to be throwaway temp dirs,\n * but here `lineDir` may well be a user's working copy. Cleaning up is the\n * caller's decision (ADR-009/ADR-014). A test pins this.\n *\n * DELIBERATE DIVERGENCE 2, and the one that matters most for whoever ports\n * linea-server: `runEngine` writes\n * `(await engine(lineOutput)).generateProduct(...)`. It awaits the CONSTRUCTOR\n * — which does return a promise — but NOT the generation, which returns one\n * too. So in the monolith the surrounding `try/catch` cannot catch anything\n * thrown during generation: the `FeatureSelectionError` its very next line\n * means to turn into a 400 becomes an unhandled rejection instead, and the\n * `rmSync` above runs while generation may still be reading the directory.\n *\n * linea-core awaits (below), which fixes both. The consequence is that the\n * error classification here does NOT merely replicate `runEngine`'s — it is\n * strictly more effective, because in the monolith most of those errors never\n * reach the `catch` at all.\n *\n * @param params.lineDir Line working directory (holding `src/platform/...`).\n * @param params.spec Product spec.\n * @param params.outputDir Directory to generate into. Created if missing.\n * @returns The directory that was generated into.\n * @throws {FeatureSelectionInvalidError} when the spec's feature selection is\n * not valid for the line's feature model.\n * @throws {LinePlatformNotFoundError} when the line has no usable platform, or\n * for any other engine failure — including a template calling a helper that\n * `extra.js` does not define, reported with the\n * `error_messages.missing_function_error` key.\n * @throws {InvalidArgumentError} when the arguments are malformed.\n */\nexport const deriveProduct = async ({\n lineDir,\n spec,\n outputDir\n}: {\n lineDir: string\n spec: ProductSpec\n outputDir: string\n}): Promise<{ outputDir: string }> => {\n assertLineDir(lineDir)\n const checkedSpec = assertSpec(spec)\n if (typeof outputDir !== 'string' || outputDir.trim() === '') {\n throw new InvalidArgumentError('\"outputDir\" must be a non-empty path.')\n }\n\n const target = ensureDir({ dirPath: outputDir })\n\n try {\n const engine = await createEngine(lineDir)\n await engine.generateProduct(target, toEngineSpec(checkedSpec))\n } catch (error) {\n rethrowDerivationError(error)\n }\n\n return { outputDir: target }\n}\n\n/**\n * Derives a product into a zip archive, without writing the generated tree.\n *\n * Same classification of failures as `deriveProduct`, matching `generateZip`.\n *\n * RETURN TYPE: the engine hands back a JSZip instance\n * (`spl-js-engine/src/output.js:ZipOutput`), which the monolith's controller\n * turns into base64 at the HTTP edge (`ProductController.js:117`). linea-core\n * materialises it into a `Buffer` instead, so the result is a real artifact a\n * caller can write, hash or feed to `extractArchive` without knowing anything\n * about JSZip. linea-server gets its base64 with `buffer.toString('base64')`.\n *\n * @param params.lineDir Line working directory.\n * @param params.spec Product spec.\n * @returns The zip archive bytes.\n * @throws The same errors as `deriveProduct`.\n */\nexport const deriveProductToZip = async ({\n lineDir,\n spec\n}: {\n lineDir: string\n spec: ProductSpec\n}): Promise<Buffer> => {\n assertLineDir(lineDir)\n const checkedSpec = assertSpec(spec)\n\n try {\n const engine = await createEngine(lineDir)\n const zip = await engine.generateZip(toEngineSpec(checkedSpec))\n const archive = zip as { generateAsync: (options: { type: 'nodebuffer' }) => Promise<Buffer> }\n return await archive.generateAsync({ type: 'nodebuffer' })\n } catch (error) {\n return rethrowDerivationError(error)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/derivation/engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,gBAAgB,EAA+B,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAC9F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAC3C,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAA;IAE7D,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IACrD,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,yBAAyB,CACjC,wBAAwB,OAAO,gBAAgB,cAAc,CAAC,KAAK,SAAS,cAAc,CAAC,QAAQ,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BAA4B,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACnG,CAAC;IACD,IAAI,KAAK,YAAY,yBAAyB;QAAE,MAAM,KAAK,CAAA;IAC3D,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;QACpC,MAAM,IAAI,yBAAyB,CAAC,uCAAuC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAChG,CAAC;IACD,MAAM,IAAI,yBAAyB,CACjC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACtD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * INTERNAL adapter that builds a configured `DerivationEngine` from a line\r\n * working directory, and classifies whatever the engine throws.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js:engine` and\r\n * `getEngineModel` (~18-36). Not exported from `src/index.ts`.\r\n */\r\nimport fs from 'node:fs'\r\nimport { DerivationEngine, type DerivationEngineConfig } from 'spl-js-engine'\r\nimport { PLATFORM_PATHS } from '../constants.js'\r\nimport { FeatureSelectionInvalidError, LinePlatformNotFoundError } from '../errors.js'\r\nimport { describeSelectionFailure, isFeatureSelectionError } from '../feature-model/engine.js'\r\nimport { fileExists, readTextFile, resolveLinePaths } from '../fs/workspace.js'\r\n\r\n/**\r\n * The `featureModel` argument for `DerivationEngine`.\r\n *\r\n * PARITY QUIRK, forced by the engine rather than chosen. `setFeatureModel`\r\n * sniffs the notation with `featureModel.endsWith('uvl')` over the ARGUMENT, so:\r\n *\r\n * - for UVL it must be handed the FILE PATH — the path ends in `.uvl`, the\r\n * check passes and `FeatureModel.fromUVL` reads the file. Passing UVL *text*\r\n * would fail the `endsWith` test and the engine would try `fromXml` on it.\r\n * - for XML it must be handed the CONTENT — a path not ending in `uvl` would go\r\n * to `fromXml`, which would then try to parse the path itself as a document.\r\n *\r\n * That is exactly what `getEngineModel` does, and why it looks inconsistent.\r\n *\r\n * Note this bypasses `parseFeatureModel`, so the `asUvlContent` guard (which\r\n * appends a newline to stop `fromUVL` reading a file) is NOT in play here: for\r\n * UVL we deliberately WANT the file to be read, and the argument is a path we\r\n * built ourselves from `lineDir`, never caller-supplied content.\r\n */\r\nconst resolveEngineModel = (lineDir: string): string => {\r\n const paths = resolveLinePaths({ lineDir })\r\n if (fileExists({ filePath: paths.model })) return paths.model\r\n\r\n const xmlPath = paths.model.replace(/\\.uvl$/, '.xml')\r\n if (!fileExists({ filePath: xmlPath })) {\r\n throw new LinePlatformNotFoundError(\r\n `No feature model in \"${lineDir}\": expected \"${PLATFORM_PATHS.model}\" or \"${PLATFORM_PATHS.modelXml}\".`\r\n )\r\n }\r\n return readTextFile({ filePath: xmlPath })\r\n}\r\n\r\n/**\r\n * The slice of the engine this module actually drives.\r\n *\r\n * Declared locally rather than importing `DerivationEngineInstance`, for the\r\n * same reason as `SolvingType` in `analysis/runtime.ts`: `spl-js-engine` ships\r\n * no declarations of its own, and our ambient ones under `src/types/` are never\r\n * published. A third-party type on an exported signature therefore ends up as a\r\n * dangling reference in `dist/**\\/*.d.ts` and breaks any consumer building with\r\n * `skipLibCheck: false`. This one was NOT yet reachable from `index.d.ts`, so it\r\n * did not fail anything — it was a latent version of the bug that did.\r\n * `npm run check:consumer` now compiles every emitted declaration, so a\r\n * regression here fails immediately instead of waiting for the day something\r\n * public happens to expose it.\r\n */\r\ninterface DerivationEngineHandle {\r\n generateProduct: (outputDir: string, spec: unknown) => Promise<unknown>\r\n generateZip: (spec: unknown) => Promise<unknown>\r\n}\r\n\r\n/**\r\n * Builds a `DerivationEngine` for a line working directory.\r\n *\r\n * Remember the engine's constructor RETURNS A PROMISE — `new DerivationEngine()`\r\n * evaluates to a promise and must be awaited. The positional argument order\r\n * mirrors `utils.js:engine()`.\r\n */\r\nexport const createEngine = async (lineDir: string): Promise<DerivationEngineHandle> => {\r\n const paths = resolveLinePaths({ lineDir })\r\n const featureModel = resolveEngineModel(lineDir)\r\n\r\n if (!fs.existsSync(paths.code)) {\r\n throw new LinePlatformNotFoundError(\r\n `No annotated code in \"${lineDir}\": expected \"${PLATFORM_PATHS.code}\".`\r\n )\r\n }\r\n\r\n const config = JSON.parse(readTextFile({ filePath: paths.config })) as DerivationEngineConfig\r\n const extraJs = readTextFile({ filePath: paths.extraJs })\r\n const transformation = readTextFile({ filePath: paths.transformation })\r\n\r\n // The cast is the price of not leaking `DerivationEngineInstance` into the\r\n // published declarations: the engine's own parameter types are narrower than\r\n // the structural handle, and function parameters are contravariant. Widening\r\n // is safe here because this module is the only caller and it always passes the\r\n // output of `buildEngineSpec`.\r\n const engine = await new DerivationEngine(\r\n paths.code, featureModel, config, extraJs, transformation\r\n )\r\n return engine as unknown as DerivationEngineHandle\r\n}\r\n\r\n/**\r\n * Turns whatever the engine threw into linea-core's taxonomy.\r\n *\r\n * Replicates the classification of `generatePipeline.js:runEngine` (~132-147)\r\n * and `ProductService.js:generateZip` (~375-382):\r\n *\r\n * - `FeatureSelectionError` propagates as such — it is the caller's fault, and\r\n * the monolith maps it to a 400.\r\n * - a `ReferenceError` means an annotation called a helper that `extra.js` does\r\n * not define; the monolith logs `error_messages.missing_function_error` and\r\n * then throws `LinePlatformNotFoundError` anyway.\r\n * - anything else becomes `LinePlatformNotFoundError`.\r\n *\r\n * PARITY NOTE: in the monolith BOTH the ReferenceError branch and the catch-all\r\n * throw `LinePlatformNotFoundError`; only the LOG MESSAGE differs. linea-core\r\n * takes no log callback (generation logs are out of scope), so the distinction\r\n * is preserved where it survives: the i18n key travels in the error MESSAGE\r\n * instead of a log line, and the original error is attached as `cause`. The\r\n * thrown TYPE is identical to the monolith's in every branch.\r\n */\r\nexport const rethrowDerivationError = (error: unknown): never => {\r\n if (isFeatureSelectionError(error)) {\r\n throw new FeatureSelectionInvalidError(describeSelectionFailure(error).message, { cause: error })\r\n }\r\n if (error instanceof LinePlatformNotFoundError) throw error\r\n if (error instanceof ReferenceError) {\r\n throw new LinePlatformNotFoundError('error_messages.missing_function_error', { cause: error })\r\n }\r\n throw new LinePlatformNotFoundError(\r\n error instanceof Error ? error.message : String(error),\r\n { cause: error }\r\n )\r\n}\r\n"]}
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/derivation/engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,gBAAgB,EAA+B,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAC9F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAC3C,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAA;IAE7D,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IACrD,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,yBAAyB,CACjC,wBAAwB,OAAO,gBAAgB,cAAc,CAAC,KAAK,SAAS,cAAc,CAAC,QAAQ,IAAI,CACxG,CAAA;IACH,CAAC;IACD,OAAO,YAAY,CAAC,EAAE,QAAQ,EAAE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EAAE,KAAK,EAAE,CAAC,CAAA;IACnG,CAAC;IACD,IAAI,KAAK,YAAY,yBAAyB;QAAE,MAAM,KAAK,CAAA;IAC3D,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;QACpC,MAAM,IAAI,yBAAyB,CAAC,uCAAuC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAChG,CAAC;IACD,MAAM,IAAI,yBAAyB,CACjC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACtD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * INTERNAL adapter that builds a configured `DerivationEngine` from a line\n * working directory, and classifies whatever the engine throws.\n *\n * Migrated from `linea/server/src/model/services/utils.js:engine` and\n * `getEngineModel` (~18-36). Not exported from `src/index.ts`.\n */\nimport fs from 'node:fs'\nimport { DerivationEngine, type DerivationEngineConfig } from 'spl-js-engine'\nimport { PLATFORM_PATHS } from '../constants.js'\nimport { FeatureSelectionInvalidError, LinePlatformNotFoundError } from '../errors.js'\nimport { describeSelectionFailure, isFeatureSelectionError } from '../feature-model/engine.js'\nimport { fileExists, readTextFile, resolveLinePaths } from '../fs/workspace.js'\n\n/**\n * The `featureModel` argument for `DerivationEngine`.\n *\n * PARITY QUIRK, forced by the engine rather than chosen. `setFeatureModel`\n * sniffs the notation with `featureModel.endsWith('uvl')` over the ARGUMENT, so:\n *\n * - for UVL it must be handed the FILE PATH — the path ends in `.uvl`, the\n * check passes and `FeatureModel.fromUVL` reads the file. Passing UVL *text*\n * would fail the `endsWith` test and the engine would try `fromXml` on it.\n * - for XML it must be handed the CONTENT — a path not ending in `uvl` would go\n * to `fromXml`, which would then try to parse the path itself as a document.\n *\n * That is exactly what `getEngineModel` does, and why it looks inconsistent.\n *\n * Note this bypasses `parseFeatureModel`, so the `asUvlContent` guard (which\n * appends a newline to stop `fromUVL` reading a file) is NOT in play here: for\n * UVL we deliberately WANT the file to be read, and the argument is a path we\n * built ourselves from `lineDir`, never caller-supplied content.\n */\nconst resolveEngineModel = (lineDir: string): string => {\n const paths = resolveLinePaths({ lineDir })\n if (fileExists({ filePath: paths.model })) return paths.model\n\n const xmlPath = paths.model.replace(/\\.uvl$/, '.xml')\n if (!fileExists({ filePath: xmlPath })) {\n throw new LinePlatformNotFoundError(\n `No feature model in \"${lineDir}\": expected \"${PLATFORM_PATHS.model}\" or \"${PLATFORM_PATHS.modelXml}\".`\n )\n }\n return readTextFile({ filePath: xmlPath })\n}\n\n/**\n * The slice of the engine this module actually drives.\n *\n * Declared locally rather than importing `DerivationEngineInstance`, for the\n * same reason as `SolvingType` in `analysis/runtime.ts`: `spl-js-engine` ships\n * no declarations of its own, and our ambient ones under `src/types/` are never\n * published. A third-party type on an exported signature therefore ends up as a\n * dangling reference in `dist/**\\/*.d.ts` and breaks any consumer building with\n * `skipLibCheck: false`. This one was NOT yet reachable from `index.d.ts`, so it\n * did not fail anything — it was a latent version of the bug that did.\n * `npm run check:consumer` now compiles every emitted declaration, so a\n * regression here fails immediately instead of waiting for the day something\n * public happens to expose it.\n */\ninterface DerivationEngineHandle {\n generateProduct: (outputDir: string, spec: unknown) => Promise<unknown>\n generateZip: (spec: unknown) => Promise<unknown>\n}\n\n/**\n * Builds a `DerivationEngine` for a line working directory.\n *\n * Remember the engine's constructor RETURNS A PROMISE — `new DerivationEngine()`\n * evaluates to a promise and must be awaited. The positional argument order\n * mirrors `utils.js:engine()`.\n */\nexport const createEngine = async (lineDir: string): Promise<DerivationEngineHandle> => {\n const paths = resolveLinePaths({ lineDir })\n const featureModel = resolveEngineModel(lineDir)\n\n if (!fs.existsSync(paths.code)) {\n throw new LinePlatformNotFoundError(\n `No annotated code in \"${lineDir}\": expected \"${PLATFORM_PATHS.code}\".`\n )\n }\n\n const config = JSON.parse(readTextFile({ filePath: paths.config })) as DerivationEngineConfig\n const extraJs = readTextFile({ filePath: paths.extraJs })\n const transformation = readTextFile({ filePath: paths.transformation })\n\n // The cast is the price of not leaking `DerivationEngineInstance` into the\n // published declarations: the engine's own parameter types are narrower than\n // the structural handle, and function parameters are contravariant. Widening\n // is safe here because this module is the only caller and it always passes the\n // output of `buildEngineSpec`.\n const engine = await new DerivationEngine(\n paths.code, featureModel, config, extraJs, transformation\n )\n return engine as unknown as DerivationEngineHandle\n}\n\n/**\n * Turns whatever the engine threw into linea-core's taxonomy.\n *\n * Replicates the classification of `generatePipeline.js:runEngine` (~132-147)\n * and `ProductService.js:generateZip` (~375-382):\n *\n * - `FeatureSelectionError` propagates as such — it is the caller's fault, and\n * the monolith maps it to a 400.\n * - a `ReferenceError` means an annotation called a helper that `extra.js` does\n * not define; the monolith logs `error_messages.missing_function_error` and\n * then throws `LinePlatformNotFoundError` anyway.\n * - anything else becomes `LinePlatformNotFoundError`.\n *\n * PARITY NOTE: in the monolith BOTH the ReferenceError branch and the catch-all\n * throw `LinePlatformNotFoundError`; only the LOG MESSAGE differs. linea-core\n * takes no log callback (generation logs are out of scope), so the distinction\n * is preserved where it survives: the i18n key travels in the error MESSAGE\n * instead of a log line, and the original error is attached as `cause`. The\n * thrown TYPE is identical to the monolith's in every branch.\n */\nexport const rethrowDerivationError = (error: unknown): never => {\n if (isFeatureSelectionError(error)) {\n throw new FeatureSelectionInvalidError(describeSelectionFailure(error).message, { cause: error })\n }\n if (error instanceof LinePlatformNotFoundError) throw error\n if (error instanceof ReferenceError) {\n throw new LinePlatformNotFoundError('error_messages.missing_function_error', { cause: error })\n }\n throw new LinePlatformNotFoundError(\n error instanceof Error ? error.message : String(error),\n { cause: error }\n )\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAaH,sDAAsD;AACtD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,gEAAgE;IACvD,IAAI,CAAoB;IAEj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kBAAmB,SAAQ,cAAc;IACpD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IACtD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF","sourcesContent":["/**\r\n * Error taxonomy of linea-core.\r\n *\r\n * Migrated from `linea/server/src/model/errors/errors.js`, keeping only the\r\n * subset that belongs to the offline engine. User-facing and GitLab-facing\r\n * errors (`IncorrectCredentialsError`, `UserNotFoundError`, `PermissionError`,\r\n * `AlreadyExistent*Error`, `LineNotFoundError`) stay in linea-server: linea-core\r\n * knows nothing about users, sessions or repositories (ADR-002, ADR-003).\r\n *\r\n * Every error carries a stable `.code` so callers can branch on it without\r\n * string-matching messages or relying on `instanceof` across module instances.\r\n */\r\n\r\n/** Stable, machine-readable discriminator of a `LineaCoreError`. */\r\nexport type LineaCoreErrorCode =\r\n | 'INVALID_ARGUMENT'\r\n | 'UVL_PARSE_ERROR'\r\n | 'UNSUPPORTED_CONVERSION'\r\n | 'FEATURE_SELECTION_INVALID'\r\n | 'LINE_PLATFORM_NOT_FOUND'\r\n | 'INVALID_PRODUCT_SPEC'\r\n | 'PRODUCTS_INDEX_ERROR'\r\n | 'ANALYSIS_RUNTIME_ERROR'\r\n\r\n/** Base class of every error thrown by linea-core. */\r\nexport class LineaCoreError extends Error {\r\n /** Stable discriminator; never changes for a given subclass. */\r\n readonly code: LineaCoreErrorCode\r\n\r\n constructor (code: LineaCoreErrorCode, message: string, options?: ErrorOptions) {\r\n super(message, options)\r\n this.name = new.target.name\r\n this.code = code\r\n }\r\n}\r\n\r\n/** A parameter is missing, malformed or outside its allowed domain. */\r\nexport class InvalidArgumentError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('INVALID_ARGUMENT', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * A UVL document could not be parsed.\r\n * Equivalent of `UVLValidationError` in the monolith.\r\n */\r\nexport class UvlParseError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('UVL_PARSE_ERROR', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * The requested feature model conversion is not supported (e.g. UVL to UVL).\r\n * Migrated from `UnsupportedConversionError`.\r\n */\r\nexport class UnsupportedConversionError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('UNSUPPORTED_CONVERSION', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * A feature selection is not valid against its feature model.\r\n * Wraps `FeatureSelectionError` from spl-js-engine, which the monolith surfaces\r\n * directly (e.g. `ProductService.js:14`, `agents/tools/evolution.js`).\r\n */\r\nexport class FeatureSelectionInvalidError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('FEATURE_SELECTION_INVALID', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * A line working directory has no platform feature model.\r\n * Migrated from `LinePlatformNotFoundError` (used in `generatePipeline.js:27`).\r\n */\r\nexport class LinePlatformNotFoundError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('LINE_PLATFORM_NOT_FOUND', message, options)\r\n }\r\n}\r\n\r\n/** A product spec fails the domain rules (name, version, features, SRID...). */\r\nexport class InvalidProductSpecError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('INVALID_PRODUCT_SPEC', message, options)\r\n }\r\n}\r\n\r\n/** The `products.json` index (ADR-011) is missing, unreadable or malformed. */\r\nexport class ProductsIndexError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('PRODUCTS_INDEX_ERROR', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * The feature model analysis runtime could not start, failed its canary, or has\r\n * already been disposed (ADR-021).\r\n *\r\n * Exists so a broken Pyodide bootstrap surfaces as an explicit failure. flamapy\r\n * swallows those errors and then returns `undefined` from every operation, which\r\n * would make an offline core report empty metrics without telling anyone.\r\n */\r\nexport class AnalysisRuntimeError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('ANALYSIS_RUNTIME_ERROR', message, options)\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAaH,sDAAsD;AACtD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,gEAAgE;IACvD,IAAI,CAAoB;IAEjC,YAAa,IAAwB,EAAE,OAAe,EAAE,OAAsB;QAC5E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IACtD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAC/C,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,iBAAiB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,cAAc;IAC5D,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,4BAA6B,SAAQ,cAAc;IAC9D,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,2BAA2B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,yBAA0B,SAAQ,cAAc;IAC3D,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACpD,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,OAAO,uBAAwB,SAAQ,cAAc;IACzD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IACtD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF","sourcesContent":["/**\n * Error taxonomy of linea-core.\n *\n * Migrated from `linea/server/src/model/errors/errors.js`, keeping only the\n * subset that belongs to the offline engine. User-facing and GitLab-facing\n * errors (`IncorrectCredentialsError`, `UserNotFoundError`, `PermissionError`,\n * `AlreadyExistent*Error`, `LineNotFoundError`) stay in linea-server: linea-core\n * knows nothing about users, sessions or repositories (ADR-002, ADR-003).\n *\n * Every error carries a stable `.code` so callers can branch on it without\n * string-matching messages or relying on `instanceof` across module instances.\n */\n\n/** Stable, machine-readable discriminator of a `LineaCoreError`. */\nexport type LineaCoreErrorCode =\n | 'INVALID_ARGUMENT'\n | 'UVL_PARSE_ERROR'\n | 'UNSUPPORTED_CONVERSION'\n | 'FEATURE_SELECTION_INVALID'\n | 'LINE_PLATFORM_NOT_FOUND'\n | 'INVALID_PRODUCT_SPEC'\n | 'PRODUCTS_INDEX_ERROR'\n | 'ANALYSIS_RUNTIME_ERROR'\n\n/** Base class of every error thrown by linea-core. */\nexport class LineaCoreError extends Error {\n /** Stable discriminator; never changes for a given subclass. */\n readonly code: LineaCoreErrorCode\n\n constructor (code: LineaCoreErrorCode, message: string, options?: ErrorOptions) {\n super(message, options)\n this.name = new.target.name\n this.code = code\n }\n}\n\n/** A parameter is missing, malformed or outside its allowed domain. */\nexport class InvalidArgumentError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('INVALID_ARGUMENT', message, options)\n }\n}\n\n/**\n * A UVL document could not be parsed.\n * Equivalent of `UVLValidationError` in the monolith.\n */\nexport class UvlParseError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('UVL_PARSE_ERROR', message, options)\n }\n}\n\n/**\n * The requested feature model conversion is not supported (e.g. UVL to UVL).\n * Migrated from `UnsupportedConversionError`.\n */\nexport class UnsupportedConversionError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('UNSUPPORTED_CONVERSION', message, options)\n }\n}\n\n/**\n * A feature selection is not valid against its feature model.\n * Wraps `FeatureSelectionError` from spl-js-engine, which the monolith surfaces\n * directly (e.g. `ProductService.js:14`, `agents/tools/evolution.js`).\n */\nexport class FeatureSelectionInvalidError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('FEATURE_SELECTION_INVALID', message, options)\n }\n}\n\n/**\n * A line working directory has no platform feature model.\n * Migrated from `LinePlatformNotFoundError` (used in `generatePipeline.js:27`).\n */\nexport class LinePlatformNotFoundError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('LINE_PLATFORM_NOT_FOUND', message, options)\n }\n}\n\n/** A product spec fails the domain rules (name, version, features, SRID...). */\nexport class InvalidProductSpecError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('INVALID_PRODUCT_SPEC', message, options)\n }\n}\n\n/** The `products.json` index (ADR-011) is missing, unreadable or malformed. */\nexport class ProductsIndexError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('PRODUCTS_INDEX_ERROR', message, options)\n }\n}\n\n/**\n * The feature model analysis runtime could not start, failed its canary, or has\n * already been disposed (ADR-021).\n *\n * Exists so a broken Pyodide bootstrap surfaces as an explicit failure. flamapy\n * swallows those errors and then returns `undefined` from every operation, which\n * would make an offline core report empty metrics without telling anyone.\n */\nexport class AnalysisRuntimeError extends LineaCoreError {\n constructor (message: string, options?: ErrorOptions) {\n super('ANALYSIS_RUNTIME_ERROR', message, options)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/feature-model/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,OAAO,EACP,IAAI,EACJ,EAAE,EAKH,EAA+C,EAAE;IAChD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IAC5G,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAA;IAC1G,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,0BAA0B,CAAC,wCAAwC,IAAI,cAAc,CAAC,CAAA;IAClG,CAAC;IAED,MAAM,KAAK,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,OAAO;QACL,OAAO,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;QAC7D,IAAI,EAAE,EAAE;KACT,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Feature model notation conversion.\r\n *\r\n * Migrated from `linea/server/src/model/services/LineService.js:convertFeatureModel`\r\n * (~421-461), keeping ONLY the domain logic. Everything around it belongs to\r\n * linea-server (ADR-003): permission checks, the GitLab commit that creates the\r\n * new file and deletes the old one, the line version bump (`incrementVersion`)\r\n * and the Mongo transaction.\r\n *\r\n * Note that the monolith derives the target notation from the line's current\r\n * `featureModelType`; here both ends are explicit parameters, so the caller can\r\n * convert a document it holds in memory without owning a line.\r\n */\r\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError, UnsupportedConversionError } from '../errors.js'\r\nimport { modelToUvl, modelToXml } from './engine.js'\r\nimport { parseFeatureModel } from './parse.js'\r\n\r\n/**\r\n * Converts a feature model between UVL and XML.\r\n *\r\n * @param params.content Model document as plain text.\r\n * @param params.from Notation of `content`.\r\n * @param params.to Target notation.\r\n * @returns The converted document and its notation.\r\n * @throws {UnsupportedConversionError} when `from` equals `to` — there is no\r\n * such thing as a UVL-to-UVL conversion, and silently returning the input\r\n * would hide a caller bug.\r\n * @throws {InvalidArgumentError} when a notation is unknown.\r\n * @throws {UvlParseError} when `content` is not parseable UVL.\r\n */\r\nexport const convertFeatureModel = ({\r\n content,\r\n from,\r\n to\r\n}: {\r\n content: string\r\n from: FeatureModelType\r\n to: FeatureModelType\r\n}): { content: string, type: FeatureModelType } => {\r\n if (!isFeatureModelType(from)) {\r\n throw new InvalidArgumentError(`Unknown source feature model type \"${String(from)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n if (!isFeatureModelType(to)) {\r\n throw new InvalidArgumentError(`Unknown target feature model type \"${String(to)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n if (from === to) {\r\n throw new UnsupportedConversionError(`Cannot convert a feature model from \"${from}\" to itself.`)\r\n }\r\n\r\n const model = parseFeatureModel({ content, type: from })\r\n return {\r\n content: to === 'UVL' ? modelToUvl(model) : modelToXml(model),\r\n type: to\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/feature-model/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,OAAO,EACP,IAAI,EACJ,EAAE,EAKH,EAA+C,EAAE;IAChD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IAC5G,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAA;IAC1G,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,0BAA0B,CAAC,wCAAwC,IAAI,cAAc,CAAC,CAAA;IAClG,CAAC;IAED,MAAM,KAAK,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,OAAO;QACL,OAAO,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;QAC7D,IAAI,EAAE,EAAE;KACT,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * Feature model notation conversion.\n *\n * Migrated from `linea/server/src/model/services/LineService.js:convertFeatureModel`\n * (~421-461), keeping ONLY the domain logic. Everything around it belongs to\n * linea-server (ADR-003): permission checks, the GitLab commit that creates the\n * new file and deletes the old one, the line version bump (`incrementVersion`)\n * and the Mongo transaction.\n *\n * Note that the monolith derives the target notation from the line's current\n * `featureModelType`; here both ends are explicit parameters, so the caller can\n * convert a document it holds in memory without owning a line.\n */\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError, UnsupportedConversionError } from '../errors.js'\nimport { modelToUvl, modelToXml } from './engine.js'\nimport { parseFeatureModel } from './parse.js'\n\n/**\n * Converts a feature model between UVL and XML.\n *\n * @param params.content Model document as plain text.\n * @param params.from Notation of `content`.\n * @param params.to Target notation.\n * @returns The converted document and its notation.\n * @throws {UnsupportedConversionError} when `from` equals `to` — there is no\n * such thing as a UVL-to-UVL conversion, and silently returning the input\n * would hide a caller bug.\n * @throws {InvalidArgumentError} when a notation is unknown.\n * @throws {UvlParseError} when `content` is not parseable UVL.\n */\nexport const convertFeatureModel = ({\n content,\n from,\n to\n}: {\n content: string\n from: FeatureModelType\n to: FeatureModelType\n}): { content: string, type: FeatureModelType } => {\n if (!isFeatureModelType(from)) {\n throw new InvalidArgumentError(`Unknown source feature model type \"${String(from)}\". Use \"UVL\" or \"XML\".`)\n }\n if (!isFeatureModelType(to)) {\n throw new InvalidArgumentError(`Unknown target feature model type \"${String(to)}\". Use \"UVL\" or \"XML\".`)\n }\n if (from === to) {\n throw new UnsupportedConversionError(`Cannot convert a feature model from \"${from}\" to itself.`)\n }\n\n const model = parseFeatureModel({ content, type: from })\n return {\n content: to === 'UVL' ? modelToUvl(model) : modelToXml(model),\n type: to\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/feature-model/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,qBAAqB,MAAM,4DAA4D,CAAA;AAE9F,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAelE,MAAM,aAAa,GAAG,CAAC,KAAwB,EAAgB,EAAE,CAC/D,KAAgC,CAAA;AAElC,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAqB,EAAE,CACzD,KAAqC,CAAA;AAEvC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAU,EAAE,CAC1C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAExD;;;;;;;;;;;;;GAaG;AACH,MAAM,uBAAuB,GAAG,4DAA4D,CAAA;AAE5F,MAAM,qBAAqB,GAAG,CAAI,GAAY,EAAK,EAAE;IACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAA;IAC9B,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACrB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAM;QAC5E,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;IACnB,CAAC,CAAA;IACD,IAAI,CAAC;QACH,OAAO,GAAG,EAAE,CAAA;IACd,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAA;IAC1B,CAAC;AACH,CAAC,CAAA;AAED;;;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AAC,KAAc,EAAoB,EAAE;IAC3E,IAAI,KAAK,YAAY,qBAAqB,EAAE,CAAC;QAC3C,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,EAAE,CAAA;IACvE,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;IACpD,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AACpD,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAwB,EAAE,QAAkB,EAAY,EAAE,CAC1F,aAAa,CAAC,KAAK,CAAC,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAA","sourcesContent":["/**\r\n * INTERNAL adapter over `spl-js-engine`. This is the ONLY module in linea-core\r\n * that imports the engine.\r\n *\r\n * Two reasons for the isolation:\r\n *\r\n * 1. The engine ships no types, so its declarations are hand-written\r\n * (`src/types/spl-js-engine.d.ts`). Keeping every engine type out of the\r\n * exported signatures below guarantees that no emitted `.d.ts` in `dist/`\r\n * ever references `spl-js-engine` — consumers do not need our ambient\r\n * declarations, and `skipLibCheck: false` on their side still works.\r\n *\r\n * 2. The engine API has sharp edges that must not reach linea-core's public\r\n * surface (see `parseFeatureModel`).\r\n *\r\n * Not exported from `src/index.ts`.\r\n */\r\nimport { FeatureModel } from 'spl-js-engine'\r\nimport FeatureSelectionError from 'spl-js-engine/src/feature-model/feature-selection-error.js'\r\nimport type { FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError, UvlParseError } from '../errors.js'\r\n\r\ndeclare const featureModelBrand: unique symbol\r\n\r\n/**\r\n * A parsed feature model.\r\n *\r\n * Opaque on purpose: it is really a `FeatureModel` from `spl-js-engine`, but\r\n * that type is not part of linea-core's contract. Pass the value back into\r\n * linea-core functions; do not introspect it.\r\n */\r\nexport interface FeatureModelValue {\r\n readonly [featureModelBrand]: 'linea-core/FeatureModel'\r\n}\r\n\r\nconst toEngineModel = (value: FeatureModelValue): FeatureModel =>\r\n value as unknown as FeatureModel\r\n\r\nconst toValue = (model: FeatureModel): FeatureModelValue =>\r\n model as unknown as FeatureModelValue\r\n\r\nconst describe = (error: unknown): string =>\r\n error instanceof Error ? error.message : String(error)\r\n\r\n/**\r\n * Upstream noise filter for UVL parsing.\r\n *\r\n * `uvl-parser/src/FeatureModel.js:22-28` decides whether its argument is a path\r\n * by calling `fs.statSync(str)` inside a try/catch that does\r\n * `console.error('Error: ' + e)` before returning false. A UVL document is never\r\n * a valid path, so EVERY successful parse dumps the whole model to stderr. For a\r\n * library embedded in a TUI (linea-cli) that is corrupting output, not logging.\r\n *\r\n * This wrapper swallows exactly that message and forwards anything else. It is\r\n * safe despite touching a global: `FeatureModel.fromUVL` is fully synchronous,\r\n * so no other task can interleave, and the original `console.error` is restored\r\n * in `finally`.\r\n */\r\nconst PARSER_PATH_PROBE_NOISE = /^Error: Error: (ENOENT|ENAMETOOLONG|ERR_INVALID_ARG_VALUE)/\r\n\r\nconst withoutPathProbeNoise = <T>(run: () => T): T => {\r\n const original = console.error\r\n console.error = (...args: unknown[]): void => {\r\n const first = args[0]\r\n if (typeof first === 'string' && PARSER_PATH_PROBE_NOISE.test(first)) return\r\n original(...args)\r\n }\r\n try {\r\n return run()\r\n } finally {\r\n console.error = original\r\n }\r\n}\r\n\r\n/**\r\n * Forces `FeatureModel.fromUVL` to treat its argument as CONTENT, never as a path.\r\n *\r\n * `uvl-parser` decides with `fs.statSync(str)`: when the string happens to name\r\n * an existing file it reads that file through `antlr4.FileStream` instead of\r\n * parsing what it was given. Since linea-server hands user-controlled bodies to\r\n * `PUT /api/lines/:id/model` and `POST /api/lines/:id/model/convert` straight\r\n * into these functions, that is an arbitrary-file-read primitive — and relative\r\n * paths would resolve against `process.cwd()`, breaking the \"no ambient state\"\r\n * invariant of ADR-009/ADR-014.\r\n *\r\n * A trailing newline makes `statSync` fail with ENOENT on both Windows and\r\n * Linux, and is semantically inert in UVL. The monolith carries the same defect;\r\n * linea-core is the layer that closes it.\r\n *\r\n * Appended UNCONDITIONALLY. A \"only if it does not already end in \\n\" guard\r\n * would leave a gap on Linux, where a file name may legally contain a newline,\r\n * so `\"/tmp/evil\\n\"` would reach `statSync` untouched. A doubled trailing\r\n * newline is inert in UVL, so there is nothing to trade off.\r\n */\r\nconst asUvlContent = (content: string): string => `${content}\\n`\r\n\r\n/**\r\n * Parses UVL or XML text into an opaque model value.\r\n *\r\n * Guards three engine quirks:\r\n * - `FeatureModel.fromUVL` accepts a *path or* text. Neutralised by\r\n * `asUvlContent`: whatever the caller passes is parsed as a document, and no\r\n * file is ever opened.\r\n * - The same path probe writes the entire document to stderr; see\r\n * `withoutPathProbeNoise`.\r\n * - `DerivationEngine.setFeatureModel` sniffs the notation with\r\n * `featureModel.endsWith('uvl')` over the *content*. linea-core never relies\r\n * on that: the notation is always an explicit parameter.\r\n */\r\nexport const parseModel = (content: string, type: FeatureModelType): FeatureModelValue => {\r\n try {\r\n return toValue(\r\n type === 'XML'\r\n ? FeatureModel.fromXml(content)\r\n : withoutPathProbeNoise(() => FeatureModel.fromUVL(asUvlContent(content)))\r\n )\r\n } catch (error) {\r\n if (type === 'XML') {\r\n throw new InvalidArgumentError(`Could not parse the XML feature model: ${describe(error)}`, {\r\n cause: error\r\n })\r\n }\r\n throw new UvlParseError(`Could not parse the UVL feature model: ${describe(error)}`, {\r\n cause: error\r\n })\r\n }\r\n}\r\n\r\n/** Serialises a model to UVL. */\r\nexport const modelToUvl = (value: FeatureModelValue): string => toEngineModel(value).toUVL()\r\n\r\n/** Serialises a model to XML. */\r\nexport const modelToXml = (value: FeatureModelValue): string => toEngineModel(value).toXml()\r\n\r\n/** How a feature selection failed, normalised away from the engine's own shape. */\r\nexport interface SelectionFailure {\r\n /** Human-readable reason. Never empty. */\r\n readonly message: string\r\n /** Engine discriminator: `'TOO_MANY_CHILDS'`, `'MISSING_CHILD'`, or `null`. */\r\n readonly errorType: string | null\r\n}\r\n\r\n/**\r\n * Whether `error` is the engine's `FeatureSelectionError`.\r\n *\r\n * Needed because it does not extend `Error`, so no generic guard identifies it.\r\n * `runEngine` and `generateZip` in the monolith branch on exactly this check.\r\n */\r\nexport const isFeatureSelectionError = (error: unknown): boolean =>\r\n error instanceof FeatureSelectionError\r\n\r\n/**\r\n * Classifies whatever `completeSelection` threw.\r\n *\r\n * `FeatureSelectionError` does NOT extend `Error`, so an `instanceof Error`\r\n * branch falls through to `String(err)` for the very error it cares about. The\r\n * message survives that (the class defines `toString()`), but **`errorType` does\r\n * not**: the `TOO_MANY_CHILDS` / `MISSING_CHILD` discriminator is silently lost.\r\n * Checked explicitly here so callers can branch on it.\r\n */\r\nexport const describeSelectionFailure = (error: unknown): SelectionFailure => {\r\n if (error instanceof FeatureSelectionError) {\r\n return { message: error.message, errorType: error.errorType ?? null }\r\n }\r\n if (error instanceof Error) {\r\n return { message: error.message, errorType: null }\r\n }\r\n return { message: String(error), errorType: null }\r\n}\r\n\r\n/**\r\n * Expands a partial selection into the full set of implied features.\r\n * @throws the engine's `FeatureSelectionError` when the selection is invalid.\r\n */\r\nexport const completeSelection = (value: FeatureModelValue, features: string[]): string[] =>\r\n toEngineModel(value).completeFeatureSelection(features)\r\n"]}
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/feature-model/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,qBAAqB,MAAM,4DAA4D,CAAA;AAE9F,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAelE,MAAM,aAAa,GAAG,CAAC,KAAwB,EAAgB,EAAE,CAC/D,KAAgC,CA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AE,CAAA;AACpD,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAwB,EAAE,QAAkB,EAAY,EAAE,CAC1F,aAAa,CAAC,KAAK,CAAC,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAA","sourcesContent":["/**\n * INTERNAL adapter over `spl-js-engine`. This is the ONLY module in linea-core\n * that imports the engine.\n *\n * Two reasons for the isolation:\n *\n * 1. The engine ships no types, so its declarations are hand-written\n * (`src/types/spl-js-engine.d.ts`). Keeping every engine type out of the\n * exported signatures below guarantees that no emitted `.d.ts` in `dist/`\n * ever references `spl-js-engine` — consumers do not need our ambient\n * declarations, and `skipLibCheck: false` on their side still works.\n *\n * 2. The engine API has sharp edges that must not reach linea-core's public\n * surface (see `parseFeatureModel`).\n *\n * Not exported from `src/index.ts`.\n */\nimport { FeatureModel } from 'spl-js-engine'\nimport FeatureSelectionError from 'spl-js-engine/src/feature-model/feature-selection-error.js'\nimport type { FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError, UvlParseError } from '../errors.js'\n\ndeclare const featureModelBrand: unique symbol\n\n/**\n * A parsed feature model.\n *\n * Opaque on purpose: it is really a `FeatureModel` from `spl-js-engine`, but\n * that type is not part of linea-core's contract. Pass the value back into\n * linea-core functions; do not introspect it.\n */\nexport interface FeatureModelValue {\n readonly [featureModelBrand]: 'linea-core/FeatureModel'\n}\n\nconst toEngineModel = (value: FeatureModelValue): FeatureModel =>\n value as unknown as FeatureModel\n\nconst toValue = (model: FeatureModel): FeatureModelValue =>\n model as unknown as FeatureModelValue\n\nconst describe = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\n/**\n * Upstream noise filter for UVL parsing.\n *\n * `uvl-parser/src/FeatureModel.js:22-28` decides whether its argument is a path\n * by calling `fs.statSync(str)` inside a try/catch that does\n * `console.error('Error: ' + e)` before returning false. A UVL document is never\n * a valid path, so EVERY successful parse dumps the whole model to stderr. For a\n * library embedded in a TUI (linea-cli) that is corrupting output, not logging.\n *\n * This wrapper swallows exactly that message and forwards anything else. It is\n * safe despite touching a global: `FeatureModel.fromUVL` is fully synchronous,\n * so no other task can interleave, and the original `console.error` is restored\n * in `finally`.\n */\nconst PARSER_PATH_PROBE_NOISE = /^Error: Error: (ENOENT|ENAMETOOLONG|ERR_INVALID_ARG_VALUE)/\n\nconst withoutPathProbeNoise = <T>(run: () => T): T => {\n const original = console.error\n console.error = (...args: unknown[]): void => {\n const first = args[0]\n if (typeof first === 'string' && PARSER_PATH_PROBE_NOISE.test(first)) return\n original(...args)\n }\n try {\n return run()\n } finally {\n console.error = original\n }\n}\n\n/**\n * Forces `FeatureModel.fromUVL` to treat its argument as CONTENT, never as a path.\n *\n * `uvl-parser` decides with `fs.statSync(str)`: when the string happens to name\n * an existing file it reads that file through `antlr4.FileStream` instead of\n * parsing what it was given. Since linea-server hands user-controlled bodies to\n * `PUT /api/lines/:id/model` and `POST /api/lines/:id/model/convert` straight\n * into these functions, that is an arbitrary-file-read primitive — and relative\n * paths would resolve against `process.cwd()`, breaking the \"no ambient state\"\n * invariant of ADR-009/ADR-014.\n *\n * A trailing newline makes `statSync` fail with ENOENT on both Windows and\n * Linux, and is semantically inert in UVL. The monolith carries the same defect;\n * linea-core is the layer that closes it.\n *\n * Appended UNCONDITIONALLY. A \"only if it does not already end in \\n\" guard\n * would leave a gap on Linux, where a file name may legally contain a newline,\n * so `\"/tmp/evil\\n\"` would reach `statSync` untouched. A doubled trailing\n * newline is inert in UVL, so there is nothing to trade off.\n */\nconst asUvlContent = (content: string): string => `${content}\\n`\n\n/**\n * Parses UVL or XML text into an opaque model value.\n *\n * Guards three engine quirks:\n * - `FeatureModel.fromUVL` accepts a *path or* text. Neutralised by\n * `asUvlContent`: whatever the caller passes is parsed as a document, and no\n * file is ever opened.\n * - The same path probe writes the entire document to stderr; see\n * `withoutPathProbeNoise`.\n * - `DerivationEngine.setFeatureModel` sniffs the notation with\n * `featureModel.endsWith('uvl')` over the *content*. linea-core never relies\n * on that: the notation is always an explicit parameter.\n */\nexport const parseModel = (content: string, type: FeatureModelType): FeatureModelValue => {\n try {\n return toValue(\n type === 'XML'\n ? FeatureModel.fromXml(content)\n : withoutPathProbeNoise(() => FeatureModel.fromUVL(asUvlContent(content)))\n )\n } catch (error) {\n if (type === 'XML') {\n throw new InvalidArgumentError(`Could not parse the XML feature model: ${describe(error)}`, {\n cause: error\n })\n }\n throw new UvlParseError(`Could not parse the UVL feature model: ${describe(error)}`, {\n cause: error\n })\n }\n}\n\n/** Serialises a model to UVL. */\nexport const modelToUvl = (value: FeatureModelValue): string => toEngineModel(value).toUVL()\n\n/** Serialises a model to XML. */\nexport const modelToXml = (value: FeatureModelValue): string => toEngineModel(value).toXml()\n\n/** How a feature selection failed, normalised away from the engine's own shape. */\nexport interface SelectionFailure {\n /** Human-readable reason. Never empty. */\n readonly message: string\n /** Engine discriminator: `'TOO_MANY_CHILDS'`, `'MISSING_CHILD'`, or `null`. */\n readonly errorType: string | null\n}\n\n/**\n * Whether `error` is the engine's `FeatureSelectionError`.\n *\n * Needed because it does not extend `Error`, so no generic guard identifies it.\n * `runEngine` and `generateZip` in the monolith branch on exactly this check.\n */\nexport const isFeatureSelectionError = (error: unknown): boolean =>\n error instanceof FeatureSelectionError\n\n/**\n * Classifies whatever `completeSelection` threw.\n *\n * `FeatureSelectionError` does NOT extend `Error`, so an `instanceof Error`\n * branch falls through to `String(err)` for the very error it cares about. The\n * message survives that (the class defines `toString()`), but **`errorType` does\n * not**: the `TOO_MANY_CHILDS` / `MISSING_CHILD` discriminator is silently lost.\n * Checked explicitly here so callers can branch on it.\n */\nexport const describeSelectionFailure = (error: unknown): SelectionFailure => {\n if (error instanceof FeatureSelectionError) {\n return { message: error.message, errorType: error.errorType ?? null }\n }\n if (error instanceof Error) {\n return { message: error.message, errorType: null }\n }\n return { message: String(error), errorType: null }\n}\n\n/**\n * Expands a partial selection into the full set of implied features.\n * @throws the engine's `FeatureSelectionError` when the selection is invalid.\n */\nexport const completeSelection = (value: FeatureModelValue, features: string[]): string[] =>\n toEngineModel(value).completeFeatureSelection(features)\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../src/feature-model/inspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAA0B,MAAM,aAAa,CAAA;AAEvE;;;GAGG;AACH,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IAChD,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK;IAC9E,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW;IAC5E,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CACnD,CAAC,CAAA;AAEF,8EAA8E;AAC9E,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAY,EAAE;IACrD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IAC/B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;QAC3B,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAQ;QAC7E,gDAAgD;QAChD,IAAI,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC;YAAE,SAAQ;QAC7C,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,+BAA+B,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC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ACvC,KAAK,EAGN,EAA2B,EAAE;IAC5B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,IAAI,oBAAoB,CAAC,0DAA0D,CAAC,CAAA;IAC5F,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC3C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;IAC3C,CAAC;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Read-only inspection of feature models.\r\n *\r\n * Migrated from `linea/server/src/agents/tools/fmAnalysis.js`\r\n * (`extractFeaturesFromModel`, `computeMandatoryFeatures`). The aggregate\r\n * portfolio helpers of that file (`computePortfolioAnomalies`,\r\n * `computePairCoverage`, `findCouplingSmells`) work over product verdicts, not\r\n * over the model, and belong with the product operations.\r\n */\r\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { completeSelection, type FeatureModelValue } from './engine.js'\r\n\r\n/**\r\n * UVL tokens that are never feature names.\r\n * Verbatim from `fmAnalysis.js:UVL_KEYWORDS`.\r\n */\r\nconst UVL_KEYWORDS: ReadonlySet<string> = new Set([\r\n 'features', 'constraints', 'mandatory', 'optional', 'alternative', 'or', 'and',\r\n 'as', 'type', 'String', 'Integer', 'Real', 'Boolean', 'include', 'namespace',\r\n 'cardinality', 'abstract', 'true', 'false', 'null'\r\n])\r\n\r\n/** Port of `fmAnalysis.js:parseUvlFeatureNames`; same tokens, same output. */\r\nconst parseUvlFeatureNames = (uvl: string): string[] => {\r\n const names = new Set<string>()\r\n for (const line of uvl.split('\\n')) {\r\n const trimmed = line.trim()\r\n if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('#')) continue\r\n // Namespace declarations are not feature lines.\r\n if (trimmed.startsWith('namespace')) continue\r\n for (const match of trimmed.matchAll(/\\b([A-Za-z_][A-Za-z0-9_]*)\\b/g)) {\r\n const name = match[1]\r\n if (name !== undefined && !UVL_KEYWORDS.has(name)) names.add(name)\r\n }\r\n }\r\n return [...names]\r\n}\r\n\r\n/** Port of `fmAnalysis.js:parseXmlFeatureNames`; same regex, same output. */\r\nconst parseXmlFeatureNames = (xml: string): string[] => {\r\n const names = new Set<string>()\r\n for (const match of xml.matchAll(/\\bname=\"([^\"]+)\"/g)) {\r\n const name = match[1]\r\n if (name !== undefined) names.add(name)\r\n }\r\n return [...names]\r\n}\r\n\r\n/**\r\n * Extracts feature names from a model document without parsing it.\r\n *\r\n * Conservative by design, exactly as the monolith documents it: it prefers false\r\n * positives over false negatives, so a few extra identifiers (type names, for\r\n * instance) may show up. Callers that need exact names should parse the model\r\n * and use the engine instead.\r\n *\r\n * HARDENED PORT, not a verbatim one. `fmAnalysis.js:extractFeaturesFromModel`\r\n * coerces the notation with `(type ?? 'UVL').toUpperCase()`, defaulting a\r\n * missing or lowercase value to UVL. This function requires an exact `'UVL'` or\r\n * `'XML'` and throws otherwise.\r\n *\r\n * That matters when migrating callers: `line.featureModelType` can be\r\n * `undefined` for lines created before the field existed, which is why\r\n * `LineService.js:284,401,432` all write `(line.featureModelType ?? 'UVL')`.\r\n * Applying that same default is now the CALLER's responsibility — whoever ports\r\n * `lineHealthAgent.js:89` must pass `line.featureModelType ?? 'UVL'` explicitly\r\n * or they will get an `InvalidArgumentError` on legacy lines.\r\n *\r\n * @param params.content Model document as plain text.\r\n * @param params.type Notation of `content`. Exact, never coerced.\r\n * @returns Feature names, de-duplicated, in order of first appearance.\r\n * @throws {InvalidArgumentError} when `content` is not a string or `type` is unknown.\r\n */\r\nexport const extractFeatureNames = ({\r\n content,\r\n type\r\n}: {\r\n content: string\r\n type: FeatureModelType\r\n}): string[] => {\r\n if (typeof content !== 'string') {\r\n throw new InvalidArgumentError('\"content\" must be a string.')\r\n }\r\n if (!isFeatureModelType(type)) {\r\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n return type === 'XML' ? parseXmlFeatureNames(content) : parseUvlFeatureNames(content)\r\n}\r\n\r\n/** Outcome of probing a model with an empty selection. */\r\nexport interface MandatoryFeaturesResult {\r\n /** `true` when the model admits no valid configuration at all. */\r\n readonly voidModel: boolean\r\n /** Features implied even by an empty selection. */\r\n readonly mandatory: string[]\r\n}\r\n\r\n/**\r\n * Probes a model with an empty selection to detect the void-model case and the\r\n * features that are always present.\r\n *\r\n * Port of `fmAnalysis.js:computeMandatoryFeatures`, keeping its\r\n * degrade-gracefully contract intact: any failure from the ENGINE is reported as\r\n * `voidModel: true` with an empty `mandatory`, never as a thrown error.\r\n *\r\n * HARDENED on one point: the monolith would happily accept a non-model and\r\n * return `{ voidModel: true }` because its `try` swallows the `TypeError` too.\r\n * Here an argument that is not a parsed model is a caller bug and throws, so it\r\n * cannot masquerade as an unsatisfiable model.\r\n *\r\n * @param params.model A model returned by `parseFeatureModel`.\r\n * @returns Whether the model is void, and its mandatory features.\r\n * @throws {InvalidArgumentError} when `model` did not come from `parseFeatureModel`.\r\n */\r\nexport const computeMandatoryFeatures = ({\r\n model\r\n}: {\r\n model: FeatureModelValue\r\n}): MandatoryFeaturesResult => {\r\n if (model === null || typeof model !== 'object') {\r\n throw new InvalidArgumentError('\"model\" must be a value returned by parseFeatureModel().')\r\n }\r\n try {\r\n const result = completeSelection(model, [])\r\n return { voidModel: false, mandatory: Array.isArray(result) ? result : [] }\r\n } catch {\r\n return { voidModel: true, mandatory: [] }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../src/feature-model/inspect.ts"],"names":[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A;IAC5F,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC3C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;IAC3C,CAAC;AACH,CAAC,CAAA","sourcesContent":["/**\n * Read-only inspection of feature models.\n *\n * Migrated from `linea/server/src/agents/tools/fmAnalysis.js`\n * (`extractFeaturesFromModel`, `computeMandatoryFeatures`). The aggregate\n * portfolio helpers of that file (`computePortfolioAnomalies`,\n * `computePairCoverage`, `findCouplingSmells`) work over product verdicts, not\n * over the model, and belong with the product operations.\n */\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError } from '../errors.js'\nimport { completeSelection, type FeatureModelValue } from './engine.js'\n\n/**\n * UVL tokens that are never feature names.\n * Verbatim from `fmAnalysis.js:UVL_KEYWORDS`.\n */\nconst UVL_KEYWORDS: ReadonlySet<string> = new Set([\n 'features', 'constraints', 'mandatory', 'optional', 'alternative', 'or', 'and',\n 'as', 'type', 'String', 'Integer', 'Real', 'Boolean', 'include', 'namespace',\n 'cardinality', 'abstract', 'true', 'false', 'null'\n])\n\n/** Port of `fmAnalysis.js:parseUvlFeatureNames`; same tokens, same output. */\nconst parseUvlFeatureNames = (uvl: string): string[] => {\n const names = new Set<string>()\n for (const line of uvl.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('#')) continue\n // Namespace declarations are not feature lines.\n if (trimmed.startsWith('namespace')) continue\n for (const match of trimmed.matchAll(/\\b([A-Za-z_][A-Za-z0-9_]*)\\b/g)) {\n const name = match[1]\n if (name !== undefined && !UVL_KEYWORDS.has(name)) names.add(name)\n }\n }\n return [...names]\n}\n\n/** Port of `fmAnalysis.js:parseXmlFeatureNames`; same regex, same output. */\nconst parseXmlFeatureNames = (xml: string): string[] => {\n const names = new Set<string>()\n for (const match of xml.matchAll(/\\bname=\"([^\"]+)\"/g)) {\n const name = match[1]\n if (name !== undefined) names.add(name)\n }\n return [...names]\n}\n\n/**\n * Extracts feature names from a model document without parsing it.\n *\n * Conservative by design, exactly as the monolith documents it: it prefers false\n * positives over false negatives, so a few extra identifiers (type names, for\n * instance) may show up. Callers that need exact names should parse the model\n * and use the engine instead.\n *\n * HARDENED PORT, not a verbatim one. `fmAnalysis.js:extractFeaturesFromModel`\n * coerces the notation with `(type ?? 'UVL').toUpperCase()`, defaulting a\n * missing or lowercase value to UVL. This function requires an exact `'UVL'` or\n * `'XML'` and throws otherwise.\n *\n * That matters when migrating callers: `line.featureModelType` can be\n * `undefined` for lines created before the field existed, which is why\n * `LineService.js:284,401,432` all write `(line.featureModelType ?? 'UVL')`.\n * Applying that same default is now the CALLER's responsibility — whoever ports\n * `lineHealthAgent.js:89` must pass `line.featureModelType ?? 'UVL'` explicitly\n * or they will get an `InvalidArgumentError` on legacy lines.\n *\n * @param params.content Model document as plain text.\n * @param params.type Notation of `content`. Exact, never coerced.\n * @returns Feature names, de-duplicated, in order of first appearance.\n * @throws {InvalidArgumentError} when `content` is not a string or `type` is unknown.\n */\nexport const extractFeatureNames = ({\n content,\n type\n}: {\n content: string\n type: FeatureModelType\n}): string[] => {\n if (typeof content !== 'string') {\n throw new InvalidArgumentError('\"content\" must be a string.')\n }\n if (!isFeatureModelType(type)) {\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\n }\n return type === 'XML' ? parseXmlFeatureNames(content) : parseUvlFeatureNames(content)\n}\n\n/** Outcome of probing a model with an empty selection. */\nexport interface MandatoryFeaturesResult {\n /** `true` when the model admits no valid configuration at all. */\n readonly voidModel: boolean\n /** Features implied even by an empty selection. */\n readonly mandatory: string[]\n}\n\n/**\n * Probes a model with an empty selection to detect the void-model case and the\n * features that are always present.\n *\n * Port of `fmAnalysis.js:computeMandatoryFeatures`, keeping its\n * degrade-gracefully contract intact: any failure from the ENGINE is reported as\n * `voidModel: true` with an empty `mandatory`, never as a thrown error.\n *\n * HARDENED on one point: the monolith would happily accept a non-model and\n * return `{ voidModel: true }` because its `try` swallows the `TypeError` too.\n * Here an argument that is not a parsed model is a caller bug and throws, so it\n * cannot masquerade as an unsatisfiable model.\n *\n * @param params.model A model returned by `parseFeatureModel`.\n * @returns Whether the model is void, and its mandatory features.\n * @throws {InvalidArgumentError} when `model` did not come from `parseFeatureModel`.\n */\nexport const computeMandatoryFeatures = ({\n model\n}: {\n model: FeatureModelValue\n}): MandatoryFeaturesResult => {\n if (model === null || typeof model !== 'object') {\n throw new InvalidArgumentError('\"model\" must be a value returned by parseFeatureModel().')\n }\n try {\n const result = completeSelection(model, [])\n return { voidModel: false, mandatory: Array.isArray(result) ? result : [] }\n } catch {\n return { voidModel: true, mandatory: [] }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/feature-model/io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAgB5E,yEAAyE;AACzE,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,IAAsB,EAAU,EAAE,CACvE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,KAAK,CAAC,C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,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,YAAY,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;KACnD,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,OAAO,EACP,OAAO,EACP,IAAI,EAKL,EAAoB,EAAE;IACrB,aAAa,CAAC,OAAO,CAAC,CAAA;IACtB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;IAC/D,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,+BAA+B,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACrG,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;AACpF,CAAC,CAAA","sourcesContent":["/**\r\n * Reading and writing the platform feature model of a line working directory.\r\n *\r\n * Migrated from:\r\n * - `linea/server/src/model/services/LineService.js:getFeatureModel` (~277-293)\r\n * and `saveFeatureModel` (~391-419) — domain logic only; permissions, the\r\n * GitLab round-trip, the version bump and the Mongo transaction stay in\r\n * linea-server (ADR-003).\r\n * - `linea/server/src/agents/tools/harvest.js:readLineModel` (~97-107), which\r\n * is where the \"UVL preferred, XML fallback\" rule comes from.\r\n * - `linea/server/src/model/services/LineService.js:reconcileLines` (~152-156),\r\n * which resolves the same ambiguity for repositories that are not in the DB:\r\n * XML only when the XML file is there and the UVL one is not.\r\n *\r\n * The monolith decodes base64 (`atob(file.content)`) because files arrive from\r\n * the GitLab API. Here everything is plain text on disk.\r\n */\r\nimport path from 'node:path'\r\nimport { PLATFORM_PATHS, isFeatureModelType, type FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError, LinePlatformNotFoundError } from '../errors.js'\r\nimport { fileExists, readTextFile, writeTextFile } from '../fs/workspace.js'\r\n\r\n/**\r\n * Where a line's feature model lives and in which notation.\r\n *\r\n * There is no `exists` flag: the function throws `LinePlatformNotFoundError`\r\n * when no model is there, so a flag could only ever be `true`. Widening a public\r\n * type later is cheap; narrowing it is a breaking change.\r\n */\r\nexport interface FeatureModelLocation {\r\n /** Notation of the model found. */\r\n readonly type: FeatureModelType\r\n /** Absolute path of the model file. */\r\n readonly path: string\r\n}\r\n\r\n/** Absolute path of the model file of `lineDir` for a given notation. */\r\nconst modelPathFor = (lineDir: string, type: FeatureModelType): string =>\r\n path.join(path.resolve(lineDir), type === 'XML' ? PLATFORM_PATHS.modelXml : PLATFORM_PATHS.model)\r\n\r\nconst assertLineDir = (lineDir: string): void => {\r\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\r\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\r\n }\r\n}\r\n\r\n/**\r\n * Detects which feature model a line working directory holds.\r\n *\r\n * UVL wins when both files are present, matching the monolith: `readLineModel`\r\n * tries `model.uvl` first, and `reconcileLines` only settles on XML when the\r\n * UVL lookup fails.\r\n *\r\n * @param params.lineDir Root of the line working directory.\r\n * @returns Notation and absolute path of the model found.\r\n * @throws {LinePlatformNotFoundError} when neither `src/platform/model.uvl` nor\r\n * `src/platform/model.xml` exists.\r\n */\r\nexport const detectFeatureModelType = ({ lineDir }: { lineDir: string }): FeatureModelLocation => {\r\n assertLineDir(lineDir)\r\n\r\n const uvlPath = modelPathFor(lineDir, 'UVL')\r\n if (fileExists({ filePath: uvlPath })) return { type: 'UVL', path: uvlPath }\r\n\r\n const xmlPath = modelPathFor(lineDir, 'XML')\r\n if (fileExists({ filePath: xmlPath })) return { type: 'XML', path: xmlPath }\r\n\r\n throw new LinePlatformNotFoundError(\r\n `No feature model found in \"${path.resolve(lineDir)}\": expected \"${PLATFORM_PATHS.model}\" or \"${PLATFORM_PATHS.modelXml}\".`\r\n )\r\n}\r\n\r\n/**\r\n * Reads the platform feature model of a line working directory.\r\n *\r\n * @param params.lineDir Root of the line working directory.\r\n * @returns Notation, absolute path and contents of the model.\r\n * @throws {LinePlatformNotFoundError} when the line has no platform model.\r\n */\r\nexport const readFeatureModel = ({\r\n lineDir\r\n}: {\r\n lineDir: string\r\n}): { type: FeatureModelType, path: string, content: string } => {\r\n const location = detectFeatureModelType({ lineDir })\r\n return {\r\n type: location.type,\r\n path: location.path,\r\n content: readTextFile({ filePath: location.path })\r\n }\r\n}\r\n\r\n/**\r\n * Writes the platform feature model of a line working directory, creating\r\n * `src/platform` if needed.\r\n *\r\n * Mirrors the model half of `saveFeatureModel`: it overwrites the file for the\r\n * given notation and nothing else. It deliberately does NOT delete the model of\r\n * the other notation — that only happens in the convert flow, where the monolith\r\n * issues a single GitLab commit with a `create` plus a `delete`\r\n * (`LineService.js:convertFeatureModel`). That flow is a line-level operation\r\n * and belongs to a later batch.\r\n *\r\n * @param params.lineDir Root of the line working directory.\r\n * @param params.content Model document as plain text.\r\n * @param params.type Notation of `content`.\r\n * @returns The absolute path written.\r\n */\r\nexport const writeFeatureModel = ({\r\n lineDir,\r\n content,\r\n type\r\n}: {\r\n lineDir: string\r\n content: string\r\n type: FeatureModelType\r\n}): { path: string } => {\r\n assertLineDir(lineDir)\r\n if (typeof content !== 'string') {\r\n throw new InvalidArgumentError('\"content\" must be a string.')\r\n }\r\n if (!isFeatureModelType(type)) {\r\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n return { path: writeTextFile({ filePath: modelPathFor(lineDir, type), content }) }\r\n}\r\n"]}
1
+ {"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/feature-model/io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EA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yBAAyB,CACjC,8BAA8B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,cAAc,CAAC,KAAK,SAAS,cAAc,CAAC,QAAQ,IAAI,CAC5H,CAAA;AACH,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,OAAO,EAGR,EAA6D,EAAE;IAC9D,MAAM,QAAQ,GAAG,sBAAsB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IACpD,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,YAAY,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;KACnD,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,OAAO,EACP,OAAO,EACP,IAAI,EAKL,EAAoB,EAAE;IACrB,aAAa,CAAC,OAAO,CAAC,CAAA;IACtB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;IAC/D,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,+BAA+B,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACrG,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;AACpF,CAAC,CAAA","sourcesContent":["/**\n * Reading and writing the platform feature model of a line working directory.\n *\n * Migrated from:\n * - `linea/server/src/model/services/LineService.js:getFeatureModel` (~277-293)\n * and `saveFeatureModel` (~391-419) — domain logic only; permissions, the\n * GitLab round-trip, the version bump and the Mongo transaction stay in\n * linea-server (ADR-003).\n * - `linea/server/src/agents/tools/harvest.js:readLineModel` (~97-107), which\n * is where the \"UVL preferred, XML fallback\" rule comes from.\n * - `linea/server/src/model/services/LineService.js:reconcileLines` (~152-156),\n * which resolves the same ambiguity for repositories that are not in the DB:\n * XML only when the XML file is there and the UVL one is not.\n *\n * The monolith decodes base64 (`atob(file.content)`) because files arrive from\n * the GitLab API. Here everything is plain text on disk.\n */\nimport path from 'node:path'\nimport { PLATFORM_PATHS, isFeatureModelType, type FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError, LinePlatformNotFoundError } from '../errors.js'\nimport { fileExists, readTextFile, writeTextFile } from '../fs/workspace.js'\n\n/**\n * Where a line's feature model lives and in which notation.\n *\n * There is no `exists` flag: the function throws `LinePlatformNotFoundError`\n * when no model is there, so a flag could only ever be `true`. Widening a public\n * type later is cheap; narrowing it is a breaking change.\n */\nexport interface FeatureModelLocation {\n /** Notation of the model found. */\n readonly type: FeatureModelType\n /** Absolute path of the model file. */\n readonly path: string\n}\n\n/** Absolute path of the model file of `lineDir` for a given notation. */\nconst modelPathFor = (lineDir: string, type: FeatureModelType): string =>\n path.join(path.resolve(lineDir), type === 'XML' ? PLATFORM_PATHS.modelXml : PLATFORM_PATHS.model)\n\nconst assertLineDir = (lineDir: string): void => {\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\n }\n}\n\n/**\n * Detects which feature model a line working directory holds.\n *\n * UVL wins when both files are present, matching the monolith: `readLineModel`\n * tries `model.uvl` first, and `reconcileLines` only settles on XML when the\n * UVL lookup fails.\n *\n * @param params.lineDir Root of the line working directory.\n * @returns Notation and absolute path of the model found.\n * @throws {LinePlatformNotFoundError} when neither `src/platform/model.uvl` nor\n * `src/platform/model.xml` exists.\n */\nexport const detectFeatureModelType = ({ lineDir }: { lineDir: string }): FeatureModelLocation => {\n assertLineDir(lineDir)\n\n const uvlPath = modelPathFor(lineDir, 'UVL')\n if (fileExists({ filePath: uvlPath })) return { type: 'UVL', path: uvlPath }\n\n const xmlPath = modelPathFor(lineDir, 'XML')\n if (fileExists({ filePath: xmlPath })) return { type: 'XML', path: xmlPath }\n\n throw new LinePlatformNotFoundError(\n `No feature model found in \"${path.resolve(lineDir)}\": expected \"${PLATFORM_PATHS.model}\" or \"${PLATFORM_PATHS.modelXml}\".`\n )\n}\n\n/**\n * Reads the platform feature model of a line working directory.\n *\n * @param params.lineDir Root of the line working directory.\n * @returns Notation, absolute path and contents of the model.\n * @throws {LinePlatformNotFoundError} when the line has no platform model.\n */\nexport const readFeatureModel = ({\n lineDir\n}: {\n lineDir: string\n}): { type: FeatureModelType, path: string, content: string } => {\n const location = detectFeatureModelType({ lineDir })\n return {\n type: location.type,\n path: location.path,\n content: readTextFile({ filePath: location.path })\n }\n}\n\n/**\n * Writes the platform feature model of a line working directory, creating\n * `src/platform` if needed.\n *\n * Mirrors the model half of `saveFeatureModel`: it overwrites the file for the\n * given notation and nothing else. It deliberately does NOT delete the model of\n * the other notation — that only happens in the convert flow, where the monolith\n * issues a single GitLab commit with a `create` plus a `delete`\n * (`LineService.js:convertFeatureModel`). That flow is a line-level operation\n * and belongs to a later batch.\n *\n * @param params.lineDir Root of the line working directory.\n * @param params.content Model document as plain text.\n * @param params.type Notation of `content`.\n * @returns The absolute path written.\n */\nexport const writeFeatureModel = ({\n lineDir,\n content,\n type\n}: {\n lineDir: string\n content: string\n type: FeatureModelType\n}): { path: string } => {\n assertLineDir(lineDir)\n if (typeof content !== 'string') {\n throw new InvalidArgumentError('\"content\" must be a string.')\n }\n if (!isFeatureModelType(type)) {\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\n }\n return { path: writeTextFile({ filePath: modelPathFor(lineDir, type), content }) }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/feature-model/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAA;AAIhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,OAAO,EACP,IAAI,EAIL,EAAqB,EAAE;IACtB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAAC,4CAA4C,CAAC,CAAA;IAC9E,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,+BAA+B,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACrG,CAAC;IACD,OAAO,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AAClC,CAAC,CAAA","sourcesContent":["/**\r\n * Feature model parsing.\r\n *\r\n * Migrated from `linea/server/src/agents/tools/splContext.js:buildFeatureModel`\r\n * (~42-46), minus two things:\r\n *\r\n * - the base64 handling (`file.encoding === 'base64' ? atob(...) : ...`): in the\r\n * monolith models arrive from the GitLab API, in linea-core everything is\r\n * plain text on disk. Decoding is linea-server's problem (ADR-003).\r\n * - the module-level `fmCache` (splContext.js ~30-40). ADR-014 forbids it:\r\n * linea-core keeps no state between calls. Callers that want caching own it.\r\n */\r\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { parseModel, type FeatureModelValue } from './engine.js'\r\n\r\nexport type { FeatureModelValue } from './engine.js'\r\n\r\n/**\r\n * Parses a feature model document.\r\n *\r\n * @param params.content Model document as plain text (UVL or XML).\r\n * @param params.type Notation of `content`. Always explicit — linea-core never\r\n * sniffs the notation from the content itself.\r\n * @returns An opaque model value, to be handed back to other linea-core functions.\r\n * @throws {InvalidArgumentError} if `content` is not a non-empty string, if\r\n * `type` is not `'UVL'`/`'XML'`, or if an XML document cannot be parsed.\r\n * @throws {UvlParseError} if a UVL document cannot be parsed.\r\n */\r\nexport const parseFeatureModel = ({\r\n content,\r\n type\r\n}: {\r\n content: string\r\n type: FeatureModelType\r\n}): FeatureModelValue => {\r\n if (typeof content !== 'string' || content.trim() === '') {\r\n throw new InvalidArgumentError('A feature model needs non-empty \"content\".')\r\n }\r\n if (!isFeatureModelType(type)) {\r\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n return parseModel(content, type)\r\n}\r\n"]}
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/feature-model/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAA;AAIhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,OAAO,EACP,IAAI,EAIL,EAAqB,EAAE;IACtB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAAC,4CAA4C,CAAC,CAAA;IAC9E,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,+BAA+B,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACrG,CAAC;IACD,OAAO,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AAClC,CAAC,CAAA","sourcesContent":["/**\n * Feature model parsing.\n *\n * Migrated from `linea/server/src/agents/tools/splContext.js:buildFeatureModel`\n * (~42-46), minus two things:\n *\n * - the base64 handling (`file.encoding === 'base64' ? atob(...) : ...`): in the\n * monolith models arrive from the GitLab API, in linea-core everything is\n * plain text on disk. Decoding is linea-server's problem (ADR-003).\n * - the module-level `fmCache` (splContext.js ~30-40). ADR-014 forbids it:\n * linea-core keeps no state between calls. Callers that want caching own it.\n */\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError } from '../errors.js'\nimport { parseModel, type FeatureModelValue } from './engine.js'\n\nexport type { FeatureModelValue } from './engine.js'\n\n/**\n * Parses a feature model document.\n *\n * @param params.content Model document as plain text (UVL or XML).\n * @param params.type Notation of `content`. Always explicit — linea-core never\n * sniffs the notation from the content itself.\n * @returns An opaque model value, to be handed back to other linea-core functions.\n * @throws {InvalidArgumentError} if `content` is not a non-empty string, if\n * `type` is not `'UVL'`/`'XML'`, or if an XML document cannot be parsed.\n * @throws {UvlParseError} if a UVL document cannot be parsed.\n */\nexport const parseFeatureModel = ({\n content,\n type\n}: {\n content: string\n type: FeatureModelType\n}): FeatureModelValue => {\n if (typeof content !== 'string' || content.trim() === '') {\n throw new InvalidArgumentError('A feature model needs non-empty \"content\".')\n }\n if (!isFeatureModelType(type)) {\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\n }\n return parseModel(content, type)\n}\n"]}