@thebackstoryis/engineering-with-ai 0.2.9
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.
- package/Docs/README.md +50 -0
- package/Docs/adoption/consultancy-and-multi-project-rollout.md +135 -0
- package/Docs/adoption/non-technical-team-guide.md +126 -0
- package/Docs/archaeology-technology-and-hosting-discovery.md +212 -0
- package/Docs/blast-radius-and-impact-routing-guide.md +325 -0
- package/Docs/blueprints/internal-blueprint-catalogue.md +146 -0
- package/Docs/blueprints/maintaining-organisation-blueprints.md +154 -0
- package/Docs/blueprints/validation-and-troubleshooting.md +168 -0
- package/Docs/cli-reference.md +113 -0
- package/Docs/completed-phase-evidence-amendments.md +74 -0
- package/Docs/consultancy-network-rollout-control-plane-guide.md +202 -0
- package/Docs/context-aware-delivery-companion-guide.md +198 -0
- package/Docs/context-aware-delivery-companion-user-guide.md +184 -0
- package/Docs/context-management-and-token-efficiency.md +113 -0
- package/Docs/design-systems/design-system-implementation-guide.md +85 -0
- package/Docs/design-systems/design-system-pack-authoring-guide.md +95 -0
- package/Docs/design-systems/design-system-review-guide.md +51 -0
- package/Docs/design-systems/design-system-user-guide.md +96 -0
- package/Docs/design-systems/product-owner-guide.md +49 -0
- package/Docs/designing-organisation-blueprint-packs.md +384 -0
- package/Docs/developer-delivery-guide.md +224 -0
- package/Docs/error-reporting-guide.md +110 -0
- package/Docs/error-reporting-provider-guide.md +49 -0
- package/Docs/examples/error-report-adapter.md +70 -0
- package/Docs/examples/meeting-review.md +76 -0
- package/Docs/examples/minimal-design-system.md +67 -0
- package/Docs/examples/prototype-review-inputs.md +175 -0
- package/Docs/examples/reproducible-archaeology-depth-example.md +144 -0
- package/Docs/examples/test-scenario-input.md +68 -0
- package/Docs/examples/worked-examples.md +147 -0
- package/Docs/existing-project-onboarding-guide.md +214 -0
- package/Docs/explanation/core-concepts.md +26 -0
- package/Docs/explanation/delivery-workflow.md +48 -0
- package/Docs/governance/governance-team-guide.md +139 -0
- package/Docs/governed-starter-project-materialisation-guide.md +284 -0
- package/Docs/guide-catalogue.md +117 -0
- package/Docs/guided-discovery-facilitator-guide.md +172 -0
- package/Docs/guided-intent-workspace-guide.md +109 -0
- package/Docs/guided-phase-evidence-drafting-guide.md +119 -0
- package/Docs/human-approval-and-assurance-guide.md +146 -0
- package/Docs/knowledge-proposals-implementer-guide.md +106 -0
- package/Docs/knowledge-proposals-user-guide.md +247 -0
- package/Docs/maintainers/context-benchmarks.md +29 -0
- package/Docs/maintainers/contributing.md +58 -0
- package/Docs/maintainers/evidence-depth-acceptance.md +72 -0
- package/Docs/maintainers/verification-walkthroughs.md +104 -0
- package/Docs/meeting-evidence-implementer-guide.md +132 -0
- package/Docs/meeting-evidence-user-guide.md +200 -0
- package/Docs/operations/dashboard-and-delivery-state.md +153 -0
- package/Docs/operations/dashboard-configuration.md +87 -0
- package/Docs/operations/installation-updating-and-entitlements.md +135 -0
- package/Docs/operations/premium-personas-setup.md +76 -0
- package/Docs/operations/troubleshooting-and-recovery.md +205 -0
- package/Docs/organisation-rollout-guide.md +142 -0
- package/Docs/persona-entitlement-provider-guide.md +199 -0
- package/Docs/persona-guided-prototype-iteration.md +129 -0
- package/Docs/personas/organisation-specific-personas.md +103 -0
- package/Docs/personas/persona-authoring-cookbook.md +176 -0
- package/Docs/personas/persona-engagement-ui.md +133 -0
- package/Docs/personas/persona-governance.md +118 -0
- package/Docs/platform-export-analysis-guide.md +336 -0
- package/Docs/policies/governance-owner-guide.md +36 -0
- package/Docs/policies/implementation-guide.md +42 -0
- package/Docs/policies/organisation-policy-design-gates.md +58 -0
- package/Docs/policies/policy-pack-authoring-guide.md +108 -0
- package/Docs/policies/product-owner-guide.md +43 -0
- package/Docs/policies/technical-owner-guide.md +37 -0
- package/Docs/product-owner-guide.md +327 -0
- package/Docs/project-portfolio-orchestration-guide.md +199 -0
- package/Docs/quality/manual-qa-and-acceptance.md +162 -0
- package/Docs/quality/persona-driven-test-scenarios.md +172 -0
- package/Docs/quality/reproducible-archaeology-depth-review-checklist.md +89 -0
- package/Docs/reference/capabilities-and-project-layout.md +678 -0
- package/Docs/reference/cli-and-configuration.md +398 -0
- package/Docs/reference/contributions-api.md +23 -0
- package/Docs/reference/security-adapter-authoring.md +81 -0
- package/Docs/reference/starter-adapter-authoring.md +74 -0
- package/Docs/repository-source-map-guide.md +381 -0
- package/Docs/reproducible-archaeology-and-discovery-depth.md +292 -0
- package/Docs/screen-prototype-creation-guide.md +324 -0
- package/Docs/security-validation-guide.md +353 -0
- package/Docs/solution-readiness-review-guide.md +123 -0
- package/Docs/standards/project-standards-authoring.md +157 -0
- package/Docs/team-hub-guide.md +162 -0
- package/Docs/team-hub-resource-registry-guide.md +167 -0
- package/Docs/tutorials/first-delivery.md +83 -0
- package/Docs/tutorials/first-session.md +62 -0
- package/Docs/using-lifecycle-hooks.md +381 -0
- package/Docs/working-with-personas.md +274 -0
- package/LICENSE +165 -0
- package/README.md +96 -0
- package/agents-src/claude/ewai-security-reviewer.md +15 -0
- package/bin/ewai +5 -0
- package/config/archaeology-record-families.yaml +59 -0
- package/config/delivery-artifacts.yaml +121 -0
- package/config/delivery-stages.yaml +77 -0
- package/config/design-system.schema.json +46 -0
- package/config/error-reporting.schema.json +79 -0
- package/config/evidence-depth.schema.json +53 -0
- package/config/intent.schema.json +90 -0
- package/config/knowledge-proposals-proposal.schema.json +34 -0
- package/config/lifecycle-event.schema.json +68 -0
- package/config/lifecycle-handler.schema.json +45 -0
- package/config/lifecycle-hook-ack.schema.json +19 -0
- package/config/meeting-evidence-candidate.schema.json +102 -0
- package/config/organisation-policy.schema.json +137 -0
- package/config/pack.schema.json +250 -0
- package/config/persona-pack.schema.json +21 -0
- package/config/persona.schema.json +17 -0
- package/config/policy-evaluation.schema.json +77 -0
- package/config/policy-facts.schema.json +140 -0
- package/config/portfolio.schema.json +68 -0
- package/config/project.schema.json +313 -0
- package/config/prototype-iteration.schema.json +128 -0
- package/config/rollout.schema.json +87 -0
- package/config/security-adapter.schema.json +31 -0
- package/config/security-scan-request.schema.json +64 -0
- package/config/security-scan-response.schema.json +52 -0
- package/config/security-validation-policy.schema.json +74 -0
- package/config/starter-source-acknowledgement.schema.json +13 -0
- package/config/starter-source-adapter.schema.json +38 -0
- package/config/starter-source-request.schema.json +61 -0
- package/package.json +77 -0
- package/packs/core/pack.yaml +7 -0
- package/packs/design-systems/default/experience-promise.md +9 -0
- package/packs/design-systems/default/intentional-review.md +10 -0
- package/packs/design-systems/default/interaction-and-entry.md +9 -0
- package/packs/design-systems/default/meaningful-content-and-states.md +9 -0
- package/packs/design-systems/default/pack.yaml +44 -0
- package/packs/design-systems/default/principles.md +10 -0
- package/packs/personas/core/pack.yaml +7 -0
- package/packs/personas/core/personas/archaeologist.md +37 -0
- package/packs/personas/core/personas/end-user.md +17 -0
- package/packs/personas/core/personas/maintainer.md +17 -0
- package/packs/personas/core/personas/operator.md +17 -0
- package/packs/personas/core/personas/specs-knowledge-curator.md +35 -0
- package/packs/technologies/laravel/pack.yaml +30 -0
- package/packs/technologies/laravel-nuxt/pack.yaml +30 -0
- package/packs/technologies/nuxt/pack.yaml +30 -0
- package/packs/technologies/power-platform/pack.yaml +31 -0
- package/packs/technologies/salesforce/pack.yaml +25 -0
- package/public/app.js +4896 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/assets/backstory-icon.png +0 -0
- package/public/dashboard-navigation.js +98 -0
- package/public/favicon-16.png +0 -0
- package/public/favicon-32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +789 -0
- package/public/styles.css +2693 -0
- package/public/team-hub/app.js +202 -0
- package/public/team-hub/index.html +79 -0
- package/public/team-hub/styles.css +90 -0
- package/scripts/publication-check.mjs +140 -0
- package/scripts/setup.mjs +21 -0
- package/skills-src/ewai-archaeology/SKILL.md +334 -0
- package/skills-src/ewai-archaeology/agents/openai.yaml +4 -0
- package/skills-src/ewai-archaeology/references/archaeology-contract.md +201 -0
- package/skills-src/ewai-archaeology/references/lifecycle-reconstruction.md +177 -0
- package/skills-src/ewai-archaeology/references/maximum-detail-reconstruction.md +97 -0
- package/skills-src/ewai-archaeology/references/model-routing.md +26 -0
- package/skills-src/ewai-architecture/SKILL.md +108 -0
- package/skills-src/ewai-architecture/agents/openai.yaml +4 -0
- package/skills-src/ewai-architecture/references/architecture-contract.md +176 -0
- package/skills-src/ewai-context/SKILL.md +68 -0
- package/skills-src/ewai-context/agents/openai.yaml +4 -0
- package/skills-src/ewai-context-import/SKILL.md +118 -0
- package/skills-src/ewai-context-import/agents/openai.yaml +4 -0
- package/skills-src/ewai-context-import/references/context-import-contract.md +106 -0
- package/skills-src/ewai-dashboard-configuration/SKILL.md +20 -0
- package/skills-src/ewai-deliver/SKILL.md +122 -0
- package/skills-src/ewai-deliver/references/delivery-evidence.md +92 -0
- package/skills-src/ewai-deliver/references/phase-routing.md +31 -0
- package/skills-src/ewai-design-system-apply/SKILL.md +27 -0
- package/skills-src/ewai-design-system-apply/agents/openai.yaml +4 -0
- package/skills-src/ewai-design-system-apply/references/application-contract.md +36 -0
- package/skills-src/ewai-design-system-author/SKILL.md +28 -0
- package/skills-src/ewai-design-system-author/agents/openai.yaml +4 -0
- package/skills-src/ewai-design-system-author/references/authoring-contract.md +38 -0
- package/skills-src/ewai-design-system-review/SKILL.md +26 -0
- package/skills-src/ewai-design-system-review/agents/openai.yaml +4 -0
- package/skills-src/ewai-design-system-review/references/review-contract.md +40 -0
- package/skills-src/ewai-error-reporting/SKILL.md +46 -0
- package/skills-src/ewai-error-reporting/agents/openai.yaml +4 -0
- package/skills-src/ewai-error-reporting/references/provider-contract.md +74 -0
- package/skills-src/ewai-evidence-depth/SKILL.md +72 -0
- package/skills-src/ewai-evidence-depth/agents/openai.yaml +4 -0
- package/skills-src/ewai-evidence-depth/references/evidence-depth-contract.md +127 -0
- package/skills-src/ewai-intent/SKILL.md +68 -0
- package/skills-src/ewai-intent/agents/openai.yaml +4 -0
- package/skills-src/ewai-intent/references/intent-contract.md +42 -0
- package/skills-src/ewai-knowledge-proposals/SKILL.md +105 -0
- package/skills-src/ewai-knowledge-proposals/agents/openai.yaml +4 -0
- package/skills-src/ewai-knowledge-proposals/references/proposal-contract.md +59 -0
- package/skills-src/ewai-meeting-evidence/SKILL.md +106 -0
- package/skills-src/ewai-meeting-evidence/agents/openai.yaml +4 -0
- package/skills-src/ewai-meeting-evidence/references/candidate-contract.md +64 -0
- package/skills-src/ewai-organisation-policy/SKILL.md +62 -0
- package/skills-src/ewai-organisation-policy/agents/openai.yaml +4 -0
- package/skills-src/ewai-organisation-policy/references/policy-contract.md +94 -0
- package/skills-src/ewai-palace-housekeeping/SKILL.md +55 -0
- package/skills-src/ewai-palace-housekeeping/agents/openai.yaml +4 -0
- package/skills-src/ewai-persona-entitlement/SKILL.md +60 -0
- package/skills-src/ewai-persona-entitlement/agents/openai.yaml +4 -0
- package/skills-src/ewai-phase-evidence/SKILL.md +79 -0
- package/skills-src/ewai-phase-evidence/agents/openai.yaml +4 -0
- package/skills-src/ewai-pipeline/SKILL.md +130 -0
- package/skills-src/ewai-pipeline/agents/openai.yaml +4 -0
- package/skills-src/ewai-pipeline/references/cli.md +86 -0
- package/skills-src/ewai-pipeline/references/specs-contract.md +16 -0
- package/skills-src/ewai-portfolio/SKILL.md +70 -0
- package/skills-src/ewai-portfolio/agents/openai.yaml +4 -0
- package/skills-src/ewai-portfolio/references/portfolio-contract.md +67 -0
- package/skills-src/ewai-project-discovery/SKILL.md +95 -0
- package/skills-src/ewai-project-discovery/agents/openai.yaml +4 -0
- package/skills-src/ewai-project-discovery/references/discovery-contract.md +34 -0
- package/skills-src/ewai-prototype-iteration/SKILL.md +30 -0
- package/skills-src/ewai-prototype-iteration/agents/openai.yaml +4 -0
- package/skills-src/ewai-prototype-iteration/references/review-contract.md +49 -0
- package/skills-src/ewai-retro/SKILL.md +48 -0
- package/skills-src/ewai-retro/agents/openai.yaml +4 -0
- package/skills-src/ewai-retro/references/asset-routing.md +14 -0
- package/skills-src/ewai-rollout/SKILL.md +74 -0
- package/skills-src/ewai-rollout/agents/openai.yaml +4 -0
- package/skills-src/ewai-rollout/references/rollout-contract.md +74 -0
- package/skills-src/ewai-shape-intents/SKILL.md +84 -0
- package/skills-src/ewai-shape-intents/agents/openai.yaml +4 -0
- package/skills-src/ewai-shape-intents/references/intent-mapping-contract.md +109 -0
- package/skills-src/ewai-solution-readiness/SKILL.md +55 -0
- package/skills-src/ewai-solution-readiness/agents/openai.yaml +4 -0
- package/skills-src/ewai-standards-check/SKILL.md +93 -0
- package/skills-src/ewai-standards-check/agents/openai.yaml +4 -0
- package/skills-src/ewai-standards-check/references/report-contract.md +116 -0
- package/skills-src/ewai-test-scenarios/SKILL.md +94 -0
- package/skills-src/ewai-test-scenarios/agents/openai.yaml +4 -0
- package/skills-src/ewai-test-scenarios/references/scenario-contract.md +88 -0
- package/src/afk-worker.mjs +16 -0
- package/src/archaeology.mjs +1333 -0
- package/src/checkin.mjs +261 -0
- package/src/cli.mjs +2427 -0
- package/src/companion-guidance.mjs +257 -0
- package/src/companion-opening.mjs +62 -0
- package/src/companion.mjs +256 -0
- package/src/context.mjs +210 -0
- package/src/dashboard-preferences.mjs +80 -0
- package/src/delivery-artifacts.mjs +204 -0
- package/src/delivery-documents.mjs +248 -0
- package/src/delivery-gates.mjs +317 -0
- package/src/delivery.mjs +1433 -0
- package/src/design-system-application.mjs +291 -0
- package/src/design-system-authoring.mjs +101 -0
- package/src/design-systems.mjs +466 -0
- package/src/discovery.mjs +1314 -0
- package/src/error-reporting.mjs +323 -0
- package/src/evidence-depth.mjs +543 -0
- package/src/execution-state.mjs +243 -0
- package/src/install.mjs +166 -0
- package/src/intent-dependencies.mjs +117 -0
- package/src/intent-maps.mjs +402 -0
- package/src/intents.mjs +747 -0
- package/src/knowledge-proposals.mjs +717 -0
- package/src/launcher.mjs +51 -0
- package/src/meeting-evidence.mjs +703 -0
- package/src/network-rollout.mjs +386 -0
- package/src/organisation-blueprints.mjs +438 -0
- package/src/organisation-policies.mjs +448 -0
- package/src/packs.mjs +44 -0
- package/src/paths.mjs +62 -0
- package/src/persona-entitlements.mjs +438 -0
- package/src/persona-licence-config.mjs +98 -0
- package/src/persona-website-provider.mjs +134 -0
- package/src/persona-zip.mjs +87 -0
- package/src/personas.mjs +159 -0
- package/src/platform-metadata-analysis.mjs +314 -0
- package/src/policy-design-gates.mjs +623 -0
- package/src/policy-gate-integration.mjs +318 -0
- package/src/portfolio.mjs +509 -0
- package/src/power-platform-source-map.mjs +190 -0
- package/src/project.mjs +449 -0
- package/src/prototype-iterations.mjs +730 -0
- package/src/repository-source-map.mjs +603 -0
- package/src/runtime/afk-conductor.mjs +973 -0
- package/src/runtime/context-assembly.mjs +457 -0
- package/src/runtime/context-benchmarks.mjs +115 -0
- package/src/runtime/dashboard-actions.mjs +109 -0
- package/src/runtime/dashboard-handoffs.mjs +149 -0
- package/src/runtime/dashboard-server.mjs +1272 -0
- package/src/runtime/dashboard.mjs +197 -0
- package/src/runtime/database.mjs +789 -0
- package/src/runtime/error-reporting.mjs +581 -0
- package/src/runtime/evidence-depth-workspace.mjs +412 -0
- package/src/runtime/execution-leases.mjs +299 -0
- package/src/runtime/guided-discovery.mjs +350 -0
- package/src/runtime/guided-intents.mjs +517 -0
- package/src/runtime/impact-analysis.mjs +535 -0
- package/src/runtime/intents.mjs +222 -0
- package/src/runtime/knowledge.mjs +86 -0
- package/src/runtime/lifecycle-hooks.mjs +1239 -0
- package/src/runtime/mcp-config.mjs +110 -0
- package/src/runtime/mcp-server.mjs +1885 -0
- package/src/runtime/palace.mjs +362 -0
- package/src/runtime/paths.mjs +58 -0
- package/src/runtime/persona-engagement.mjs +255 -0
- package/src/runtime/phase-contributions.mjs +594 -0
- package/src/runtime/policy-workspace.mjs +170 -0
- package/src/runtime/prototype-iterations.mjs +235 -0
- package/src/runtime/provider-adapters.mjs +163 -0
- package/src/runtime/repository-index.mjs +838 -0
- package/src/runtime/runs.mjs +185 -0
- package/src/runtime/security-validation.mjs +1230 -0
- package/src/runtime/starter-materialisation.mjs +1155 -0
- package/src/runtime/team-hub-client.mjs +479 -0
- package/src/runtime/team-hub-database.mjs +288 -0
- package/src/runtime/team-hub-server.mjs +191 -0
- package/src/runtime/team-hub.mjs +110 -0
- package/src/runtime/tree-sitter-index.mjs +390 -0
- package/src/runtime/version.mjs +1 -0
- package/src/runtime/work.mjs +633 -0
- package/src/salesforce-source-map.mjs +212 -0
- package/src/security-validation-config.mjs +224 -0
- package/src/solution-readiness.mjs +620 -0
- package/src/starter-materialisation-contract.mjs +407 -0
- package/src/task-graph.mjs +544 -0
- package/src/team-hub-resources.mjs +239 -0
- package/src/team-hub.mjs +242 -0
- package/src/test-scenarios.mjs +622 -0
- package/src/validation-config.mjs +289 -0
- package/templates/SPECS/1.Scope/personas/registry.yaml +12 -0
- package/templates/SPECS/5.Strategy/patterns/context-packet.md +119 -0
- package/templates/SPECS/6.Build/_tracker-template.md +16 -0
- package/templates/SPECS/pipeline.yaml +62 -0
- package/templates/discovery-answers.yaml +86 -0
- package/templates/intent-body.md +21 -0
- package/tests/fixtures/context-benchmarks.json +9 -0
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { basename, extname } from 'node:path';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { parseDocument } from 'yaml';
|
|
5
|
+
import { extractTreeSitterFacts } from './runtime/tree-sitter-index.mjs';
|
|
6
|
+
import { listProjectPacks } from './packs.mjs';
|
|
7
|
+
import { safePlatformFailureCode } from './platform-metadata-analysis.mjs';
|
|
8
|
+
import { analysePowerPlatformMetadata, powerPlatformLayout } from './power-platform-source-map.mjs';
|
|
9
|
+
import { loadProjectConfig } from './project.mjs';
|
|
10
|
+
import { analyseSalesforceMetadata, salesforceLayout } from './salesforce-source-map.mjs';
|
|
11
|
+
|
|
12
|
+
export const SOURCE_MAP_MAX_FILE_BYTES = 900_000;
|
|
13
|
+
|
|
14
|
+
const core = (id, patterns, classification, analyser, analysisDepth, priority = 0) => Object.freeze({
|
|
15
|
+
id, patterns: Object.freeze(patterns), classification, analyser, analysisDepth, priority,
|
|
16
|
+
repositories: Object.freeze([]), maxBytes: SOURCE_MAP_MAX_FILE_BYTES, sourceKind: 'core', sourceRef: 'ewai.core'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const REGISTERED_SOURCE_MAP_ANALYSERS = Object.freeze([
|
|
20
|
+
'inventory-only', 'text-summary', 'structured-keys', 'tree-sitter',
|
|
21
|
+
'power-platform-metadata', 'salesforce-metadata'
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export const CORE_SOURCE_MAP_PROFILES = Object.freeze([
|
|
25
|
+
core('core-sensitive', [], 'sensitive-config', 'inventory-only', 'inventory', 10_000),
|
|
26
|
+
core('core-tree-sitter-php', ['**/*.php'], 'source-code', 'tree-sitter', 'deep'),
|
|
27
|
+
core('core-tree-sitter-javascript', ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.jsx'], 'source-code', 'tree-sitter', 'deep'),
|
|
28
|
+
core('core-tree-sitter-typescript', ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.tsx'], 'source-code', 'tree-sitter', 'deep'),
|
|
29
|
+
core('core-tree-sitter-vue', ['**/*.vue'], 'source-code', 'tree-sitter', 'deep'),
|
|
30
|
+
core('core-structured-json', ['**/*.json', '**/*.jsonc'], 'structured-data', 'structured-keys', 'shallow'),
|
|
31
|
+
core('core-structured-yaml', ['**/*.yaml', '**/*.yml'], 'structured-data', 'structured-keys', 'shallow'),
|
|
32
|
+
core('core-structured-toml', ['**/*.toml'], 'structured-data', 'structured-keys', 'shallow'),
|
|
33
|
+
core('core-structured-xml', ['**/*.xml', '**/*.svg'], 'structured-data', 'structured-keys', 'shallow'),
|
|
34
|
+
core('core-structured-ini', ['**/*.ini', '**/*.properties'], 'structured-data', 'structured-keys', 'shallow'),
|
|
35
|
+
core('core-structured-env-template', ['**/.env.example', '**/.env.sample', '**/.env.template'], 'configuration-template', 'structured-keys', 'shallow', 20),
|
|
36
|
+
core('core-documentation', ['**/*.md', '**/*.mdx', '**/*.txt', '**/*.rst', '**/*.adoc', '**/Dockerfile', '**/Makefile', '**/Procfile', '**/Gemfile', '**/Rakefile'], 'documentation', 'text-summary', 'shallow'),
|
|
37
|
+
core('core-shallow-source', ['**/*.astro', '**/*.bash', '**/*.c', '**/*.cc', '**/*.cpp', '**/*.cs', '**/*.css', '**/*.fish', '**/*.go', '**/*.gql', '**/*.graphql', '**/*.h', '**/*.hpp', '**/*.htm', '**/*.html', '**/*.java', '**/*.kt', '**/*.kts', '**/*.less', '**/*.lua', '**/*.pl', '**/*.ps1', '**/*.py', '**/*.r', '**/*.rb', '**/*.rs', '**/*.sass', '**/*.scala', '**/*.scss', '**/*.sh', '**/*.sql', '**/*.svelte', '**/*.swift', '**/*.zsh'], 'source-code', 'text-summary', 'shallow'),
|
|
38
|
+
core('core-binary', [], 'binary', 'inventory-only', 'inventory'),
|
|
39
|
+
core('core-fallback', ['**/*'], 'unknown', 'inventory-only', 'inventory', -10_000)
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const profilesById = new Map(CORE_SOURCE_MAP_PROFILES.map((profile) => [profile.id, profile]));
|
|
43
|
+
const sensitiveNames = new Set(['.env', '.npmrc', '.netrc']);
|
|
44
|
+
const sourceRanks = Object.freeze({ core: 0, technology: 1, stack: 2, organisation: 3, project: 4 });
|
|
45
|
+
const allowedProfileFields = new Set([
|
|
46
|
+
'id', 'patterns', 'analyser', 'classification', 'priority', 'repositories', 'max_bytes'
|
|
47
|
+
]);
|
|
48
|
+
const profileIdPattern = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
|
|
49
|
+
const packIdPattern = /^(?:ewai\.[a-z0-9.-]+|org\.[a-z0-9-]+\.[a-z0-9.-]+)$/;
|
|
50
|
+
const classificationPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
51
|
+
const globCache = new Map();
|
|
52
|
+
|
|
53
|
+
function hash(value) {
|
|
54
|
+
return createHash('sha256').update(value).digest('hex');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function profile(id) {
|
|
58
|
+
return profilesById.get(id);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isSensitiveName(name) {
|
|
62
|
+
const lower = name.toLowerCase();
|
|
63
|
+
if (sensitiveNames.has(lower)) return true;
|
|
64
|
+
if (!lower.startsWith('.env.')) return false;
|
|
65
|
+
return !['.env.example', '.env.sample', '.env.template'].includes(lower);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function safePattern(pattern) {
|
|
69
|
+
const value = String(pattern ?? '').trim();
|
|
70
|
+
const segments = value.split('/');
|
|
71
|
+
if (!value || value.length > 240 || value.startsWith('/') || value.startsWith('!')
|
|
72
|
+
|| value.includes('\\') || value.includes('\0') || segments.includes('..')
|
|
73
|
+
|| /[{}()[\]]/.test(value)) {
|
|
74
|
+
throw new Error(`unsafe source map pattern: ${value || '<empty>'}`);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function globRegex(pattern) {
|
|
80
|
+
const safe = safePattern(pattern);
|
|
81
|
+
if (globCache.has(safe)) return globCache.get(safe);
|
|
82
|
+
let expression = '^';
|
|
83
|
+
for (let index = 0; index < safe.length;) {
|
|
84
|
+
if (safe[index] === '*' && safe[index + 1] === '*') {
|
|
85
|
+
if (safe[index + 2] === '/') {
|
|
86
|
+
expression += '(?:.*/)?';
|
|
87
|
+
index += 3;
|
|
88
|
+
} else {
|
|
89
|
+
expression += '.*';
|
|
90
|
+
index += 2;
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (safe[index] === '*') {
|
|
95
|
+
expression += '[^/]*';
|
|
96
|
+
index += 1;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (safe[index] === '?') {
|
|
100
|
+
expression += '[^/]';
|
|
101
|
+
index += 1;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
expression += safe[index].replace(/[|\\{}()[\]^$+?.]/g, '\\$&');
|
|
105
|
+
index += 1;
|
|
106
|
+
}
|
|
107
|
+
const compiled = new RegExp(`${expression}$`);
|
|
108
|
+
globCache.set(safe, compiled);
|
|
109
|
+
return compiled;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function sourceKindForPack(pack) {
|
|
113
|
+
if (pack.type === 'core') return 'core';
|
|
114
|
+
if (pack.type === 'organisation') return 'organisation';
|
|
115
|
+
if (pack.type === 'stack') return 'stack';
|
|
116
|
+
return 'technology';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function namespacedProfileId(id, sourceKind, sourceRef) {
|
|
120
|
+
if (sourceKind === 'core') return id;
|
|
121
|
+
if (sourceKind === 'project') return `project:${id}`;
|
|
122
|
+
return `${sourceRef}:${id}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function validateSourceMapProfile(value, context = {}) {
|
|
126
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
127
|
+
throw new Error('Source map profile must be an object.');
|
|
128
|
+
}
|
|
129
|
+
const unsupported = Object.keys(value).find((key) => !allowedProfileFields.has(key));
|
|
130
|
+
if (unsupported) throw new Error(`unsupported source map profile field: ${unsupported}`);
|
|
131
|
+
const id = String(value.id ?? '').trim();
|
|
132
|
+
if (!profileIdPattern.test(id)) throw new Error(`Invalid source map profile id: ${id || '<empty>'}`);
|
|
133
|
+
const patterns = Array.isArray(value.patterns) ? value.patterns.map(safePattern) : [];
|
|
134
|
+
if (!patterns.length) throw new Error(`Source map profile ${id} requires at least one pattern.`);
|
|
135
|
+
const analyser = String(value.analyser ?? '').trim();
|
|
136
|
+
if (!REGISTERED_SOURCE_MAP_ANALYSERS.includes(analyser)) {
|
|
137
|
+
throw new Error(`unknown source map analyser: ${analyser || '<empty>'}`);
|
|
138
|
+
}
|
|
139
|
+
const classification = String(value.classification ?? '').trim();
|
|
140
|
+
if (!classificationPattern.test(classification)) {
|
|
141
|
+
throw new Error(`Invalid source map classification: ${classification || '<empty>'}`);
|
|
142
|
+
}
|
|
143
|
+
const priority = Number(value.priority ?? 0);
|
|
144
|
+
if (!Number.isInteger(priority) || priority < -10_000 || priority > 10_000) {
|
|
145
|
+
throw new Error(`Source map profile ${id} priority must be an integer between -10000 and 10000.`);
|
|
146
|
+
}
|
|
147
|
+
const repositories = value.repositories ?? [];
|
|
148
|
+
if (!Array.isArray(repositories) || repositories.some((repository) => !String(repository).trim())) {
|
|
149
|
+
throw new Error(`Source map profile ${id} repositories must be non-empty strings.`);
|
|
150
|
+
}
|
|
151
|
+
const maxBytes = Number(value.max_bytes ?? SOURCE_MAP_MAX_FILE_BYTES);
|
|
152
|
+
if (!Number.isInteger(maxBytes) || maxBytes < 1 || maxBytes > SOURCE_MAP_MAX_FILE_BYTES) {
|
|
153
|
+
throw new Error(`Source map profile ${id} max_bytes must be between 1 and ${SOURCE_MAP_MAX_FILE_BYTES}.`);
|
|
154
|
+
}
|
|
155
|
+
const sourceKind = context.sourceKind ?? 'project';
|
|
156
|
+
const sourceRef = context.sourceRef ?? (sourceKind === 'project' ? 'pipeline.yaml' : 'unknown');
|
|
157
|
+
if (!(sourceKind in sourceRanks)) throw new Error(`Unsupported source map profile source: ${sourceKind}`);
|
|
158
|
+
return {
|
|
159
|
+
id: namespacedProfileId(id, sourceKind, sourceRef),
|
|
160
|
+
localId: id,
|
|
161
|
+
patterns,
|
|
162
|
+
analyser,
|
|
163
|
+
classification,
|
|
164
|
+
priority,
|
|
165
|
+
repositories: [...new Set(repositories.map((repository) => String(repository).trim()))].sort(),
|
|
166
|
+
maxBytes,
|
|
167
|
+
analysisDepth: ['tree-sitter', 'power-platform-metadata', 'salesforce-metadata'].includes(analyser)
|
|
168
|
+
? 'deep'
|
|
169
|
+
: analyser === 'inventory-only' ? 'inventory' : 'shallow',
|
|
170
|
+
sourceKind,
|
|
171
|
+
sourceRef,
|
|
172
|
+
sourceVersion: String(context.sourceVersion ?? '')
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function activePackIds(selected, catalogue) {
|
|
177
|
+
for (const pack of catalogue) {
|
|
178
|
+
if (!packIdPattern.test(String(pack.id ?? ''))) {
|
|
179
|
+
throw new Error(`Invalid EWAI pack id in installed catalogue: ${pack.id ?? '<empty>'}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const byId = new Map(catalogue.map((pack) => [pack.id, pack]));
|
|
183
|
+
const active = [];
|
|
184
|
+
const visiting = new Set();
|
|
185
|
+
const visit = (id) => {
|
|
186
|
+
if (active.includes(id)) return;
|
|
187
|
+
if (visiting.has(id)) throw new Error(`Circular EWAI pack dependency: ${id}`);
|
|
188
|
+
const pack = byId.get(id);
|
|
189
|
+
if (!pack) throw new Error(`Unknown configured EWAI pack: ${id}`);
|
|
190
|
+
visiting.add(id);
|
|
191
|
+
for (const requirement of pack.requires ?? []) visit(requirement);
|
|
192
|
+
visiting.delete(id);
|
|
193
|
+
active.push(id);
|
|
194
|
+
};
|
|
195
|
+
for (const id of selected) visit(id);
|
|
196
|
+
return active;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function sourceMapProfileDigest(profiles) {
|
|
200
|
+
const canonical = [...profiles].map((item) => ({
|
|
201
|
+
id: item.id,
|
|
202
|
+
patterns: [...(item.patterns ?? [])].sort(),
|
|
203
|
+
analyser: item.analyser,
|
|
204
|
+
classification: item.classification,
|
|
205
|
+
priority: Number(item.priority ?? 0),
|
|
206
|
+
repositories: [...(item.repositories ?? [])].sort(),
|
|
207
|
+
maxBytes: Number(item.maxBytes ?? SOURCE_MAP_MAX_FILE_BYTES),
|
|
208
|
+
analysisDepth: item.analysisDepth,
|
|
209
|
+
sourceKind: item.sourceKind,
|
|
210
|
+
sourceRef: item.sourceRef,
|
|
211
|
+
sourceVersion: item.sourceVersion ?? ''
|
|
212
|
+
})).sort((left, right) => left.id.localeCompare(right.id));
|
|
213
|
+
return hash(JSON.stringify(canonical));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function resolveSourceMapProfiles(projectRoot, options = {}) {
|
|
217
|
+
const { config } = options.config ? { config: options.config } : loadProjectConfig(projectRoot);
|
|
218
|
+
const catalogue = options.packs ?? listProjectPacks(projectRoot, {
|
|
219
|
+
...(options.packRoots ? { roots: options.packRoots } : {}),
|
|
220
|
+
...(options.home ? { home: options.home } : {})
|
|
221
|
+
});
|
|
222
|
+
const selected = [...new Set(['ewai.core', ...(config.packs ?? [])])];
|
|
223
|
+
const activePacks = activePackIds(selected, catalogue);
|
|
224
|
+
const byId = new Map(catalogue.map((pack) => [pack.id, pack]));
|
|
225
|
+
const profiles = [...CORE_SOURCE_MAP_PROFILES];
|
|
226
|
+
for (const id of activePacks) {
|
|
227
|
+
const pack = byId.get(id);
|
|
228
|
+
const sourceKind = sourceKindForPack(pack);
|
|
229
|
+
for (const value of pack.source_map?.profiles ?? []) {
|
|
230
|
+
profiles.push(validateSourceMapProfile(value, {
|
|
231
|
+
sourceKind,
|
|
232
|
+
sourceRef: pack.id,
|
|
233
|
+
sourceVersion: pack.version
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (const value of config.source_map?.profiles ?? []) {
|
|
238
|
+
profiles.push(validateSourceMapProfile(value, { sourceKind: 'project', sourceRef: 'pipeline.yaml' }));
|
|
239
|
+
}
|
|
240
|
+
const duplicate = profiles.find((item, index) => profiles.findIndex((candidate) => candidate.id === item.id) !== index);
|
|
241
|
+
if (duplicate) throw new Error(`Duplicate source map profile id: ${duplicate.id}`);
|
|
242
|
+
return {
|
|
243
|
+
schema: 'ewai.source-map-profiles/v1',
|
|
244
|
+
activePacks,
|
|
245
|
+
profiles,
|
|
246
|
+
digest: sourceMapProfileDigest(profiles)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function matchesRepository(profileValue, repository) {
|
|
251
|
+
if (!profileValue.repositories?.length) return true;
|
|
252
|
+
if (!repository) return false;
|
|
253
|
+
return profileValue.repositories.includes(repository.name) || profileValue.repositories.includes(repository.role);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function profileMatches(profileValue, path) {
|
|
257
|
+
return profileValue.patterns?.some((pattern) => globRegex(pattern).test(path)) ?? false;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function selectSourceMapProfile(path, options = {}) {
|
|
261
|
+
const name = basename(path);
|
|
262
|
+
if (isSensitiveName(name)) return profile('core-sensitive');
|
|
263
|
+
const candidatePath = String(path).replaceAll('\\', '/').replace(/^\.\//, '');
|
|
264
|
+
const profiles = options.profiles ?? CORE_SOURCE_MAP_PROFILES;
|
|
265
|
+
return profiles
|
|
266
|
+
.filter((item) => item.id !== 'core-sensitive' && item.id !== 'core-binary')
|
|
267
|
+
.filter((item) => matchesRepository(item, options.repository) && profileMatches(item, candidatePath))
|
|
268
|
+
.sort((left, right) => (sourceRanks[right.sourceKind] - sourceRanks[left.sourceKind])
|
|
269
|
+
|| (Number(right.priority ?? 0) - Number(left.priority ?? 0))
|
|
270
|
+
|| left.id.localeCompare(right.id))[0]
|
|
271
|
+
?? profile('core-fallback');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function sourceMapProfileFileLimit(profileValue) {
|
|
275
|
+
return Math.min(SOURCE_MAP_MAX_FILE_BYTES, Number(profileValue?.maxBytes ?? SOURCE_MAP_MAX_FILE_BYTES));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function metadataFingerprint(sizeBytes, modifiedMs, state) {
|
|
279
|
+
return hash(`ewai-source-map:${state}:${sizeBytes}:${Math.floor(Number(modifiedMs ?? 0))}`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function fingerprintRepositoryFile(path, stat, selectedProfile = selectSourceMapProfile(path)) {
|
|
283
|
+
const sizeBytes = Number(stat?.size ?? 0);
|
|
284
|
+
if (selectedProfile.id === 'core-sensitive') {
|
|
285
|
+
return { kind: 'metadata-sha256', value: metadataFingerprint(sizeBytes, stat?.mtimeMs, 'sensitive') };
|
|
286
|
+
}
|
|
287
|
+
if (sizeBytes > sourceMapProfileFileLimit(selectedProfile)) {
|
|
288
|
+
return { kind: 'metadata-sha256', value: metadataFingerprint(sizeBytes, stat?.mtimeMs, 'oversized') };
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
return { kind: 'sha256', value: hash(readFileSync(path)) };
|
|
292
|
+
} catch {
|
|
293
|
+
return { kind: 'metadata-sha256', value: metadataFingerprint(sizeBytes, stat?.mtimeMs, 'unreadable') };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function fingerprintRepositoryBuffer(buffer) {
|
|
298
|
+
return { kind: 'sha256', value: hash(buffer) };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function isProbablyBinary(buffer) {
|
|
302
|
+
if (!buffer.length) return false;
|
|
303
|
+
const sample = buffer.subarray(0, Math.min(buffer.length, 8192));
|
|
304
|
+
let suspicious = 0;
|
|
305
|
+
for (const byte of sample) {
|
|
306
|
+
if (byte === 0) return true;
|
|
307
|
+
if (byte < 7 || (byte > 13 && byte < 32)) suspicious += 1;
|
|
308
|
+
}
|
|
309
|
+
return suspicious / sample.length > 0.2;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function collectObjectKeys(value, prefix = '', keys = new Set()) {
|
|
313
|
+
if (Array.isArray(value)) {
|
|
314
|
+
for (const entry of value) collectObjectKeys(entry, prefix, keys);
|
|
315
|
+
return keys;
|
|
316
|
+
}
|
|
317
|
+
if (!value || typeof value !== 'object') return keys;
|
|
318
|
+
for (const key of Object.keys(value)) {
|
|
319
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
320
|
+
keys.add(path);
|
|
321
|
+
collectObjectKeys(value[key], path, keys);
|
|
322
|
+
}
|
|
323
|
+
return keys;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function stripJsonComments(content) {
|
|
327
|
+
let output = '';
|
|
328
|
+
let quote = '';
|
|
329
|
+
let escaped = false;
|
|
330
|
+
let lineComment = false;
|
|
331
|
+
let blockComment = false;
|
|
332
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
333
|
+
const current = content[index];
|
|
334
|
+
const next = content[index + 1];
|
|
335
|
+
if (lineComment) {
|
|
336
|
+
if (current === '\n') {
|
|
337
|
+
lineComment = false;
|
|
338
|
+
output += current;
|
|
339
|
+
} else {
|
|
340
|
+
output += ' ';
|
|
341
|
+
}
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (blockComment) {
|
|
345
|
+
if (current === '*' && next === '/') {
|
|
346
|
+
output += ' ';
|
|
347
|
+
blockComment = false;
|
|
348
|
+
index += 1;
|
|
349
|
+
} else {
|
|
350
|
+
output += current === '\n' ? '\n' : ' ';
|
|
351
|
+
}
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (quote) {
|
|
355
|
+
output += current;
|
|
356
|
+
if (escaped) escaped = false;
|
|
357
|
+
else if (current === '\\') escaped = true;
|
|
358
|
+
else if (current === quote) quote = '';
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (current === '"') {
|
|
362
|
+
quote = current;
|
|
363
|
+
output += current;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (current === '/' && next === '/') {
|
|
367
|
+
lineComment = true;
|
|
368
|
+
output += ' ';
|
|
369
|
+
index += 1;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (current === '/' && next === '*') {
|
|
373
|
+
blockComment = true;
|
|
374
|
+
output += ' ';
|
|
375
|
+
index += 1;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
output += current;
|
|
379
|
+
}
|
|
380
|
+
return output.replace(/,\s*([}\]])/g, '$1');
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function structuredKeys(path, content) {
|
|
384
|
+
const lowerName = basename(path).toLowerCase();
|
|
385
|
+
const extension = extname(lowerName);
|
|
386
|
+
if (extension === '.json' || extension === '.jsonc') {
|
|
387
|
+
const parsed = JSON.parse(stripJsonComments(content.replace(/^\uFEFF/, '')));
|
|
388
|
+
return [...collectObjectKeys(parsed)].sort();
|
|
389
|
+
}
|
|
390
|
+
if (extension === '.yaml' || extension === '.yml') {
|
|
391
|
+
const document = parseDocument(content, { maxAliasCount: 0, prettyErrors: false });
|
|
392
|
+
if (document.errors.length) throw new Error('invalid-yaml');
|
|
393
|
+
return [...collectObjectKeys(document.toJS({ maxAliasCount: 0 }))].sort();
|
|
394
|
+
}
|
|
395
|
+
if (extension === '.toml') {
|
|
396
|
+
const keys = new Set();
|
|
397
|
+
let section = '';
|
|
398
|
+
for (const rawLine of content.split(/\r?\n/)) {
|
|
399
|
+
const line = rawLine.trim();
|
|
400
|
+
const sectionMatch = line.match(/^\[([^\]]+)]$/);
|
|
401
|
+
if (sectionMatch) {
|
|
402
|
+
section = sectionMatch[1].trim();
|
|
403
|
+
keys.add(section);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const keyMatch = line.match(/^([A-Za-z0-9_.-]+)\s*=/);
|
|
407
|
+
if (keyMatch) keys.add(section ? `${section}.${keyMatch[1]}` : keyMatch[1]);
|
|
408
|
+
}
|
|
409
|
+
return [...keys].sort();
|
|
410
|
+
}
|
|
411
|
+
if (extension === '.xml' || extension === '.svg') {
|
|
412
|
+
return [...new Set([...content.matchAll(/<\/?([A-Za-z_][\w:.-]*)\b/g)].map((match) => match[1]))].sort();
|
|
413
|
+
}
|
|
414
|
+
if (extension === '.ini' || extension === '.properties') {
|
|
415
|
+
const keys = new Set();
|
|
416
|
+
let section = '';
|
|
417
|
+
for (const rawLine of content.split(/\r?\n/)) {
|
|
418
|
+
const line = rawLine.trim();
|
|
419
|
+
const sectionMatch = line.match(/^\[([^\]]+)]$/);
|
|
420
|
+
if (sectionMatch) {
|
|
421
|
+
section = sectionMatch[1].trim();
|
|
422
|
+
keys.add(section);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
const keyMatch = line.match(/^([^=:#;]+?)\s*[:=]/);
|
|
426
|
+
if (keyMatch) {
|
|
427
|
+
const key = keyMatch[1].trim();
|
|
428
|
+
keys.add(section ? `${section}.${key}` : key);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return [...keys].sort();
|
|
432
|
+
}
|
|
433
|
+
if (['.env.example', '.env.sample', '.env.template'].includes(lowerName)) {
|
|
434
|
+
return [...new Set(content.split(/\r?\n/)
|
|
435
|
+
.map((line) => line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/)?.[1])
|
|
436
|
+
.filter(Boolean))].sort();
|
|
437
|
+
}
|
|
438
|
+
throw new Error('unsupported-structured-format');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function emptyFacts(file) {
|
|
442
|
+
return { file, symbols: [], relationships: [], imports: [], spans: [] };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function baseFile(profileValue, sizeBytes, fingerprint, outcome, overrides = {}) {
|
|
446
|
+
return {
|
|
447
|
+
language: '',
|
|
448
|
+
parser: '',
|
|
449
|
+
parserStatus: 'not_applicable',
|
|
450
|
+
sizeBytes,
|
|
451
|
+
lineCount: 0,
|
|
452
|
+
parseErrorCount: 0,
|
|
453
|
+
metadata: {},
|
|
454
|
+
classification: profileValue.classification,
|
|
455
|
+
profileId: profileValue.id,
|
|
456
|
+
analyser: profileValue.analyser,
|
|
457
|
+
analysisDepth: profileValue.analysisDepth,
|
|
458
|
+
analysisOutcome: outcome,
|
|
459
|
+
fingerprintKind: fingerprint.kind,
|
|
460
|
+
fingerprint: fingerprint.value,
|
|
461
|
+
...overrides
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function platformFailure(selectedProfile, path, sizeBytes, fingerprint, error, content) {
|
|
466
|
+
const power = selectedProfile.analyser === 'power-platform-metadata';
|
|
467
|
+
const platform = power ? 'power-platform' : 'salesforce';
|
|
468
|
+
const layout = (power ? powerPlatformLayout(path) : salesforceLayout(path)) || 'unknown';
|
|
469
|
+
const failureCode = safePlatformFailureCode(error);
|
|
470
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'analysis_failed', {
|
|
471
|
+
language: path.toLowerCase().endsWith('.json') ? 'json'
|
|
472
|
+
: path.toLowerCase().endsWith('.xml') ? 'xml' : 'yaml',
|
|
473
|
+
parser: power ? 'ewai-power-platform-metadata/v1' : 'ewai-salesforce-metadata/v1',
|
|
474
|
+
parserStatus: 'failed',
|
|
475
|
+
lineCount: content ? content.split(/\r?\n/).length : 0,
|
|
476
|
+
parseErrorCount: 1,
|
|
477
|
+
metadata: {
|
|
478
|
+
platform,
|
|
479
|
+
layout,
|
|
480
|
+
partial: true,
|
|
481
|
+
truncated: failureCode === 'platform-analysis-limit',
|
|
482
|
+
unknown_component_count: 0,
|
|
483
|
+
failure_code: failureCode
|
|
484
|
+
}
|
|
485
|
+
}));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function analysePlatformFile(path, content, selectedProfile, sizeBytes, fingerprint) {
|
|
489
|
+
try {
|
|
490
|
+
const facts = selectedProfile.analyser === 'power-platform-metadata'
|
|
491
|
+
? analysePowerPlatformMetadata(path, content)
|
|
492
|
+
: analyseSalesforceMetadata(path, content);
|
|
493
|
+
return {
|
|
494
|
+
...facts,
|
|
495
|
+
file: baseFile(selectedProfile, sizeBytes, fingerprint, 'analysed', facts.file)
|
|
496
|
+
};
|
|
497
|
+
} catch (error) {
|
|
498
|
+
return platformFailure(selectedProfile, path, sizeBytes, fingerprint, error, content);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export function analyseRepositoryFile(path, options = {}) {
|
|
503
|
+
const selectedProfile = options.profile ?? selectSourceMapProfile(path);
|
|
504
|
+
const sizeBytes = Number(options.stat?.size ?? options.buffer?.length ?? 0);
|
|
505
|
+
const fileLimit = sourceMapProfileFileLimit(selectedProfile);
|
|
506
|
+
let buffer = options.buffer ?? null;
|
|
507
|
+
let readError = Boolean(options.readError);
|
|
508
|
+
if (!buffer && !readError && selectedProfile.id !== 'core-sensitive' && sizeBytes <= fileLimit) {
|
|
509
|
+
try {
|
|
510
|
+
buffer = readFileSync(path);
|
|
511
|
+
} catch {
|
|
512
|
+
readError = true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const fingerprint = options.fingerprint
|
|
516
|
+
?? (buffer ? fingerprintRepositoryBuffer(buffer) : fingerprintRepositoryFile(path, options.stat, selectedProfile));
|
|
517
|
+
if (selectedProfile.id === 'core-sensitive') {
|
|
518
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'skipped_sensitive'));
|
|
519
|
+
}
|
|
520
|
+
if (sizeBytes > fileLimit) {
|
|
521
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'skipped_oversized', {
|
|
522
|
+
analyser: 'inventory-only',
|
|
523
|
+
analysisDepth: 'inventory'
|
|
524
|
+
}));
|
|
525
|
+
}
|
|
526
|
+
if (readError) {
|
|
527
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'analysis_failed', {
|
|
528
|
+
analyser: 'inventory-only',
|
|
529
|
+
analysisDepth: 'inventory',
|
|
530
|
+
parserStatus: 'failed',
|
|
531
|
+
metadata: { failure_code: 'read-failed' }
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (isProbablyBinary(buffer)) {
|
|
536
|
+
const binaryProfile = profile('core-binary');
|
|
537
|
+
return emptyFacts(baseFile(binaryProfile, sizeBytes, fingerprint, 'inventory_only'));
|
|
538
|
+
}
|
|
539
|
+
const content = buffer.toString('utf8');
|
|
540
|
+
if (['power-platform-metadata', 'salesforce-metadata'].includes(selectedProfile.analyser)) {
|
|
541
|
+
return analysePlatformFile(path, content, selectedProfile, sizeBytes, fingerprint);
|
|
542
|
+
}
|
|
543
|
+
if (selectedProfile.analyser === 'tree-sitter') {
|
|
544
|
+
const facts = extractTreeSitterFacts(path, content, {
|
|
545
|
+
repo: options.repo ?? 'application',
|
|
546
|
+
repoRelative: options.repoRelative ?? ((candidate) => candidate)
|
|
547
|
+
});
|
|
548
|
+
if (facts.file.parserStatus === 'not_applicable') {
|
|
549
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'analysis_failed', {
|
|
550
|
+
parserStatus: 'failed',
|
|
551
|
+
parseErrorCount: 1,
|
|
552
|
+
metadata: { failure_code: 'unregistered-tree-sitter-grammar' }
|
|
553
|
+
}));
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
...facts,
|
|
557
|
+
file: {
|
|
558
|
+
...facts.file,
|
|
559
|
+
metadata: facts.file.parserStatus === 'failed'
|
|
560
|
+
? { failure_code: 'tree-sitter-analysis-failed' }
|
|
561
|
+
: facts.file.metadata,
|
|
562
|
+
classification: selectedProfile.classification,
|
|
563
|
+
profileId: selectedProfile.id,
|
|
564
|
+
analyser: selectedProfile.analyser,
|
|
565
|
+
analysisDepth: selectedProfile.analysisDepth,
|
|
566
|
+
analysisOutcome: facts.file.parserStatus === 'failed' ? 'analysis_failed' : 'analysed',
|
|
567
|
+
fingerprintKind: fingerprint.kind,
|
|
568
|
+
fingerprint: fingerprint.value
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
if (selectedProfile.analyser === 'structured-keys') {
|
|
573
|
+
try {
|
|
574
|
+
const keys = structuredKeys(path, content);
|
|
575
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'analysed', {
|
|
576
|
+
lineCount: content ? content.split(/\r?\n/).length : 0,
|
|
577
|
+
metadata: { structural_keys: keys }
|
|
578
|
+
}));
|
|
579
|
+
} catch {
|
|
580
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'analysis_failed', {
|
|
581
|
+
lineCount: content ? content.split(/\r?\n/).length : 0,
|
|
582
|
+
parserStatus: 'failed',
|
|
583
|
+
parseErrorCount: 1,
|
|
584
|
+
metadata: { failure_code: 'invalid-structured-document' }
|
|
585
|
+
}));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (selectedProfile.analyser === 'text-summary') {
|
|
589
|
+
const lines = content ? content.split(/\r?\n/) : [];
|
|
590
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'analysed', {
|
|
591
|
+
lineCount: lines.length,
|
|
592
|
+
metadata: {
|
|
593
|
+
non_empty_line_count: lines.filter((line) => line.trim()).length,
|
|
594
|
+
maximum_line_length: lines.reduce((maximum, line) => Math.max(maximum, line.length), 0)
|
|
595
|
+
}
|
|
596
|
+
}));
|
|
597
|
+
}
|
|
598
|
+
return emptyFacts(baseFile(selectedProfile, sizeBytes, fingerprint, 'inventory_only'));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export function coreSourceMapProfileDigest() {
|
|
602
|
+
return sourceMapProfileDigest(CORE_SOURCE_MAP_PROFILES);
|
|
603
|
+
}
|