@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,314 @@
|
|
|
1
|
+
import { isAlias, parseDocument, visit } from 'yaml';
|
|
2
|
+
|
|
3
|
+
export const PLATFORM_METADATA_LIMITS = Object.freeze({
|
|
4
|
+
identifierLength: 240,
|
|
5
|
+
symbols: 1_000,
|
|
6
|
+
relationships: 2_000,
|
|
7
|
+
nodes: 20_000,
|
|
8
|
+
depth: 96
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const identifierPattern = /^[A-Za-z0-9][A-Za-z0-9_.:/@#{}-]*$/;
|
|
12
|
+
const safeFailureCodes = new Set([
|
|
13
|
+
'invalid-platform-document',
|
|
14
|
+
'unsafe-xml-declaration',
|
|
15
|
+
'platform-analysis-limit',
|
|
16
|
+
'unsupported-platform-layout'
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export class PlatformAnalysisError extends Error {
|
|
20
|
+
constructor(code, message = code) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'PlatformAnalysisError';
|
|
23
|
+
this.code = safeFailureCodes.has(code) ? code : 'invalid-platform-document';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function fail(code) {
|
|
28
|
+
throw new PlatformAnalysisError(code);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function normalisePlatformIdentifier(value, limit = PLATFORM_METADATA_LIMITS.identifierLength) {
|
|
32
|
+
const identifier = String(value ?? '').trim();
|
|
33
|
+
if (!identifier || identifier.length > limit || !identifierPattern.test(identifier)) return '';
|
|
34
|
+
return identifier;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function normalisePlatformPathIdentifier(value, limit = PLATFORM_METADATA_LIMITS.identifierLength) {
|
|
38
|
+
const raw = String(value ?? '').trim();
|
|
39
|
+
if (!raw || raw.includes('\\') || raw.startsWith('/')) return '';
|
|
40
|
+
const identifier = normalisePlatformIdentifier(raw, limit);
|
|
41
|
+
if (!identifier) return '';
|
|
42
|
+
const segments = identifier.split('/');
|
|
43
|
+
if (segments.some((segment) => !segment || segment === '.' || segment === '..')) return '';
|
|
44
|
+
return identifier;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function safeEnum(value, allowed) {
|
|
48
|
+
const candidate = String(value ?? '').trim();
|
|
49
|
+
return allowed.has(candidate) ? candidate : '';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function safeBoolean(value) {
|
|
53
|
+
if (value === true || value === 'true') return true;
|
|
54
|
+
if (value === false || value === 'false') return false;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function safeFactMetadata(platform, metadata = {}) {
|
|
59
|
+
const result = { platform };
|
|
60
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
61
|
+
if (typeof value === 'boolean') result[key] = value;
|
|
62
|
+
else if (Number.isInteger(value) && value >= 0 && value <= PLATFORM_METADATA_LIMITS.nodes) result[key] = value;
|
|
63
|
+
else if (key === 'component_type') {
|
|
64
|
+
const identifier = normalisePlatformIdentifier(value);
|
|
65
|
+
if (identifier) result[key] = identifier;
|
|
66
|
+
} else if (key === 'visibility') {
|
|
67
|
+
const visibility = safeEnum(value, new Set(['DefaultOn', 'DefaultOff', 'Hidden']));
|
|
68
|
+
if (visibility) result[key] = visibility;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createPlatformFactCollector(options = {}) {
|
|
75
|
+
const platform = safeEnum(options.platform, new Set(['power-platform', 'salesforce']));
|
|
76
|
+
const layout = normalisePlatformIdentifier(options.layout);
|
|
77
|
+
if (!platform || !layout) fail('unsupported-platform-layout');
|
|
78
|
+
const limits = { ...PLATFORM_METADATA_LIMITS, ...(options.limits ?? {}) };
|
|
79
|
+
const symbols = [];
|
|
80
|
+
const relationships = [];
|
|
81
|
+
const symbolKeys = new Set();
|
|
82
|
+
const relationshipKeys = new Set();
|
|
83
|
+
let partial = Boolean(options.partial);
|
|
84
|
+
let truncated = false;
|
|
85
|
+
let unknownComponentCount = Number(options.unknownComponentCount ?? 0);
|
|
86
|
+
|
|
87
|
+
const markOmitted = (count = 1, wasTruncated = false) => {
|
|
88
|
+
partial = true;
|
|
89
|
+
truncated ||= wasTruncated;
|
|
90
|
+
unknownComponentCount += Math.max(0, Number(count) || 0);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const addSymbol = (kind, name, metadata = {}) => {
|
|
94
|
+
const safeKind = normalisePlatformIdentifier(kind);
|
|
95
|
+
const safeName = normalisePlatformIdentifier(name, limits.identifierLength);
|
|
96
|
+
if (!safeKind || !safeName) {
|
|
97
|
+
markOmitted();
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const key = `${safeKind}\u0000${safeName}`;
|
|
101
|
+
if (symbolKeys.has(key)) return true;
|
|
102
|
+
if (symbols.length >= limits.symbols) {
|
|
103
|
+
markOmitted(1, true);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
symbolKeys.add(key);
|
|
107
|
+
symbols.push({
|
|
108
|
+
kind: safeKind,
|
|
109
|
+
name: safeName,
|
|
110
|
+
line: null,
|
|
111
|
+
signature: '',
|
|
112
|
+
tags: [platform, safeKind],
|
|
113
|
+
metadata: safeFactMetadata(platform, metadata)
|
|
114
|
+
});
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const addRelationship = (sourceKind, sourceName, relationshipKind, targetKind, targetName, metadata = {}) => {
|
|
119
|
+
const values = [sourceKind, sourceName, relationshipKind, targetKind, targetName]
|
|
120
|
+
.map((value) => normalisePlatformIdentifier(value, limits.identifierLength));
|
|
121
|
+
if (values.some((value) => !value)) {
|
|
122
|
+
markOmitted();
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const key = values.join('\u0000');
|
|
126
|
+
if (relationshipKeys.has(key)) return true;
|
|
127
|
+
if (relationships.length >= limits.relationships) {
|
|
128
|
+
markOmitted(1, true);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
relationshipKeys.add(key);
|
|
132
|
+
relationships.push({
|
|
133
|
+
source_kind: values[0],
|
|
134
|
+
source_name: values[1],
|
|
135
|
+
source_path: '',
|
|
136
|
+
relationship_kind: values[2],
|
|
137
|
+
target_kind: values[3],
|
|
138
|
+
target_name: values[4],
|
|
139
|
+
target_path: '',
|
|
140
|
+
metadata: safeFactMetadata(platform, metadata)
|
|
141
|
+
});
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
addSymbol,
|
|
147
|
+
addRelationship,
|
|
148
|
+
markPartial: (count = 0) => markOmitted(count, false),
|
|
149
|
+
markTruncated: (count = 0) => markOmitted(count, true),
|
|
150
|
+
finish(extraMetadata = {}) {
|
|
151
|
+
const formatVersion = normalisePlatformIdentifier(extraMetadata.format_version);
|
|
152
|
+
return {
|
|
153
|
+
symbols,
|
|
154
|
+
relationships,
|
|
155
|
+
imports: [],
|
|
156
|
+
spans: [],
|
|
157
|
+
metadata: {
|
|
158
|
+
platform,
|
|
159
|
+
layout,
|
|
160
|
+
...(formatVersion ? { format_version: formatVersion } : {}),
|
|
161
|
+
partial,
|
|
162
|
+
truncated,
|
|
163
|
+
unknown_component_count: unknownComponentCount,
|
|
164
|
+
symbol_count: symbols.length,
|
|
165
|
+
relationship_count: relationships.length
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function decodeXmlText(value) {
|
|
173
|
+
return String(value ?? '')
|
|
174
|
+
.replaceAll('<', '<')
|
|
175
|
+
.replaceAll('>', '>')
|
|
176
|
+
.replaceAll('"', '"')
|
|
177
|
+
.replaceAll(''', "'")
|
|
178
|
+
.replaceAll('&', '&')
|
|
179
|
+
.trim();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function xmlName(value) {
|
|
183
|
+
return String(value ?? '').split(':').pop();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function parseAttributes(fragment) {
|
|
187
|
+
const attributes = {};
|
|
188
|
+
const withoutAttributes = fragment.replace(/([:@A-Za-z_][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,
|
|
189
|
+
(_, name, doubleQuoted, singleQuoted) => {
|
|
190
|
+
attributes[xmlName(name)] = decodeXmlText(doubleQuoted ?? singleQuoted ?? '');
|
|
191
|
+
return ' ';
|
|
192
|
+
});
|
|
193
|
+
if (withoutAttributes.trim()) fail('invalid-platform-document');
|
|
194
|
+
return attributes;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function parseSafePlatformXml(content, options = {}) {
|
|
198
|
+
const source = String(content ?? '');
|
|
199
|
+
if (/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(source)) fail('unsafe-xml-declaration');
|
|
200
|
+
const limits = { ...PLATFORM_METADATA_LIMITS, ...(options.limits ?? {}) };
|
|
201
|
+
const document = { name: '#document', attributes: {}, children: [], text: '' };
|
|
202
|
+
const stack = [document];
|
|
203
|
+
const tokenPattern = /<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<\?[\s\S]*?\?>|<[^>]*>/g;
|
|
204
|
+
let cursor = 0;
|
|
205
|
+
let nodes = 0;
|
|
206
|
+
for (const match of source.matchAll(tokenPattern)) {
|
|
207
|
+
const text = decodeXmlText(source.slice(cursor, match.index));
|
|
208
|
+
if (text) stack.at(-1).text += text;
|
|
209
|
+
cursor = match.index + match[0].length;
|
|
210
|
+
const token = match[0];
|
|
211
|
+
if (token.startsWith('<!--') || token.startsWith('<![CDATA[') || token.startsWith('<?')) continue;
|
|
212
|
+
if (token.startsWith('<!')) fail('invalid-platform-document');
|
|
213
|
+
if (token.startsWith('</')) {
|
|
214
|
+
const closing = xmlName(token.slice(2, -1).trim());
|
|
215
|
+
if (stack.length === 1 || stack.at(-1).name !== closing) fail('invalid-platform-document');
|
|
216
|
+
stack.pop();
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const selfClosing = /\/\s*>$/.test(token);
|
|
220
|
+
const inner = token.slice(1, selfClosing ? token.lastIndexOf('/') : -1).trim();
|
|
221
|
+
const nameMatch = inner.match(/^([A-Za-z_][\w:.-]*)([\s\S]*)$/);
|
|
222
|
+
if (!nameMatch) fail('invalid-platform-document');
|
|
223
|
+
nodes += 1;
|
|
224
|
+
if (nodes > limits.nodes || stack.length > limits.depth) fail('platform-analysis-limit');
|
|
225
|
+
const node = {
|
|
226
|
+
name: xmlName(nameMatch[1]),
|
|
227
|
+
attributes: parseAttributes(nameMatch[2]),
|
|
228
|
+
children: [],
|
|
229
|
+
text: ''
|
|
230
|
+
};
|
|
231
|
+
stack.at(-1).children.push(node);
|
|
232
|
+
if (!selfClosing) stack.push(node);
|
|
233
|
+
}
|
|
234
|
+
const trailing = decodeXmlText(source.slice(cursor));
|
|
235
|
+
if (trailing) stack.at(-1).text += trailing;
|
|
236
|
+
if (stack.length !== 1 || document.children.length !== 1) fail('invalid-platform-document');
|
|
237
|
+
return document.children[0];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function parseSafePlatformYaml(content, options = {}) {
|
|
241
|
+
const limits = { ...PLATFORM_METADATA_LIMITS, ...(options.limits ?? {}) };
|
|
242
|
+
try {
|
|
243
|
+
const document = parseDocument(String(content ?? ''), { maxAliasCount: 0, prettyErrors: false });
|
|
244
|
+
if (document.errors.length) fail('invalid-platform-document');
|
|
245
|
+
let aliasFound = false;
|
|
246
|
+
visit(document, { Alias: (_key, node) => { if (isAlias(node)) aliasFound = true; } });
|
|
247
|
+
if (aliasFound) fail('invalid-platform-document');
|
|
248
|
+
const value = document.toJS({ maxAliasCount: 0 });
|
|
249
|
+
assertBoundedPlatformStructure(value, limits);
|
|
250
|
+
return value;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (error instanceof PlatformAnalysisError) throw error;
|
|
253
|
+
fail('invalid-platform-document');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function assertBoundedPlatformStructure(value, limits = PLATFORM_METADATA_LIMITS) {
|
|
258
|
+
let nodes = 0;
|
|
259
|
+
const walk = (current, depth) => {
|
|
260
|
+
nodes += 1;
|
|
261
|
+
if (nodes > limits.nodes || depth > limits.depth) fail('platform-analysis-limit');
|
|
262
|
+
if (Array.isArray(current)) {
|
|
263
|
+
for (const entry of current) walk(entry, depth + 1);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (!current || typeof current !== 'object') return;
|
|
267
|
+
for (const entry of Object.values(current)) walk(entry, depth + 1);
|
|
268
|
+
};
|
|
269
|
+
walk(value, 0);
|
|
270
|
+
return { nodes };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function platformFactsFile(facts, options = {}) {
|
|
274
|
+
return {
|
|
275
|
+
file: {
|
|
276
|
+
language: options.language ?? '',
|
|
277
|
+
parser: options.parser ?? 'ewai-platform-metadata/v1',
|
|
278
|
+
parserStatus: 'parsed',
|
|
279
|
+
lineCount: String(options.content ?? '').split(/\r?\n/).length,
|
|
280
|
+
parseErrorCount: 0,
|
|
281
|
+
metadata: facts.metadata
|
|
282
|
+
},
|
|
283
|
+
symbols: facts.symbols,
|
|
284
|
+
relationships: facts.relationships,
|
|
285
|
+
imports: [],
|
|
286
|
+
spans: []
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function safePlatformFailureCode(error) {
|
|
291
|
+
return safeFailureCodes.has(error?.code) ? error.code : 'invalid-platform-document';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function xmlChildren(node, name) {
|
|
295
|
+
const expected = String(name).toLowerCase();
|
|
296
|
+
return (node?.children ?? []).filter((child) => child.name.toLowerCase() === expected);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function xmlDescendants(node, name, found = []) {
|
|
300
|
+
const expected = String(name).toLowerCase();
|
|
301
|
+
for (const child of node?.children ?? []) {
|
|
302
|
+
if (child.name.toLowerCase() === expected) found.push(child);
|
|
303
|
+
xmlDescendants(child, name, found);
|
|
304
|
+
}
|
|
305
|
+
return found;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function xmlChildText(node, name) {
|
|
309
|
+
return xmlChildren(node, name)[0]?.text?.trim() ?? '';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function platformBoolean(value) {
|
|
313
|
+
return safeBoolean(value);
|
|
314
|
+
}
|