@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,243 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { validatePhaseArtefacts } from './delivery-artifacts.mjs';
|
|
4
|
+
import { deliveryPaths, isWithin, sha256 } from './delivery-documents.mjs';
|
|
5
|
+
import { assertCompletedEvidenceFresh, validatePhaseGateAtPaths } from './delivery-gates.mjs';
|
|
6
|
+
import { dependencyRequirementBlockers, validateIntentDependencyGraph } from './intent-dependencies.mjs';
|
|
7
|
+
import { validateIntentStateCopies } from './intents.mjs';
|
|
8
|
+
import { validateTaskGraph } from './task-graph.mjs';
|
|
9
|
+
|
|
10
|
+
const terminalPhaseStatuses = new Set(['completed', 'approved', 'skipped', 'not-supported', 'waived']);
|
|
11
|
+
const acceptedIntentStatuses = new Set(['ready', 'approved']);
|
|
12
|
+
|
|
13
|
+
function blocker(code, message, evidence = '') {
|
|
14
|
+
return { code, message, evidence };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function action(permitted, blockers = [], extra = {}) {
|
|
18
|
+
return { permitted: Boolean(permitted && blockers.length === 0), blockers, ...extra };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function phaseSequence(state) {
|
|
22
|
+
const result = [];
|
|
23
|
+
for (const phase of state.phases ?? []) {
|
|
24
|
+
result.push(phase);
|
|
25
|
+
if (phase.id === 'reconcile') result.push((state.adjuncts ?? []).find((item) => item.id === 'ui-design'));
|
|
26
|
+
if (phase.id === 'build') result.splice(result.length - 1, 0, (state.adjuncts ?? []).find((item) => item.id === 'fit-check'));
|
|
27
|
+
if (phase.id === 'retro') result.splice(result.length - 1, 0, (state.humanGates ?? []).find((item) => item.id === 'manual-qa'));
|
|
28
|
+
}
|
|
29
|
+
return result.filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function nextRequiredPhase(state) {
|
|
33
|
+
const running = phaseSequence(state).find((phase) => phase.status === 'running');
|
|
34
|
+
if (running) return running.id;
|
|
35
|
+
return phaseSequence(state).find((phase) => !terminalPhaseStatuses.has(phase.status))?.id ?? 'complete';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function progress(state) {
|
|
39
|
+
const applicable = (state.phases ?? []).filter((phase) => !['skipped', 'not-supported'].includes(phase.status));
|
|
40
|
+
if (!applicable.length) return 0;
|
|
41
|
+
return Math.round((applicable.filter((phase) => phase.status === 'completed').length / applicable.length) * 100);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function projection(intent, state, valid) {
|
|
45
|
+
if (!valid) return { lane: 'blocked', state: 'invalid-evidence', intentState: intent.status, progress: 0, phase: state?.currentPhase ?? intent.currentPhase ?? 'backlog' };
|
|
46
|
+
if (!state) {
|
|
47
|
+
const ready = acceptedIntentStatuses.has(String(intent.status).toLowerCase());
|
|
48
|
+
return { lane: ready ? 'ready' : 'backlog', state: 'not-started', intentState: intent.status, progress: 0, phase: 'backlog' };
|
|
49
|
+
}
|
|
50
|
+
if (state.status === 'completed') return { lane: 'done', state: state.status, intentState: state.intent.status, progress: 100, phase: state.currentPhase };
|
|
51
|
+
if (state.status === 'paused-awaiting-manual-qa') return { lane: 'qa', state: state.status, intentState: state.intent.status, progress: progress(state), phase: state.currentPhase };
|
|
52
|
+
if (['shelf-ready', 'validated-not-for-build'].includes(state.status)) {
|
|
53
|
+
return { lane: 'ready', state: state.status, intentState: state.intent.status, progress: progress(state), phase: state.currentPhase };
|
|
54
|
+
}
|
|
55
|
+
return { lane: 'active', state: state.status, intentState: state.intent.status, progress: progress(state), phase: state.currentPhase };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function gateBlockers(paths, state, phase) {
|
|
59
|
+
const blockers = [];
|
|
60
|
+
try {
|
|
61
|
+
validatePhaseArtefacts(
|
|
62
|
+
paths.deliveryRoot,
|
|
63
|
+
phase.id,
|
|
64
|
+
phase.validation?.providers ?? state.providers ?? [],
|
|
65
|
+
phase.validation?.cycles ?? [],
|
|
66
|
+
);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
blockers.push(blocker('phase-artefacts-incomplete', error.message, relative(paths.projectRoot, paths.deliveryRoot)));
|
|
69
|
+
}
|
|
70
|
+
if (phase.validation) {
|
|
71
|
+
for (const provider of phase.validation.providers ?? []) {
|
|
72
|
+
const cycles = (phase.validation.cycles ?? []).filter((cycle) => cycle.provider === provider);
|
|
73
|
+
if (!cycles.length || cycles.at(-1).outcome !== 'pass') {
|
|
74
|
+
blockers.push(blocker('external-validation-incomplete', `${provider} has not recorded a passing final validation cycle.`, phase.id));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const gatePath = resolve(paths.gatesRoot, phase.id, 'gate-ledger.json');
|
|
80
|
+
if (!existsSync(gatePath)) {
|
|
81
|
+
blockers.push(blocker('phase-gate-missing', `Phase ${phase.id} has no gate ledger.`, relative(paths.projectRoot, gatePath)));
|
|
82
|
+
return blockers;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const gate = JSON.parse(readFileSync(gatePath, 'utf8'));
|
|
86
|
+
if (gate.schema_version !== 1 || gate.phase !== phase.id || gate.status !== 'pass') {
|
|
87
|
+
blockers.push(blocker('phase-gate-not-passing', `Phase ${phase.id} gate ledger is not passing.`, relative(paths.projectRoot, gatePath)));
|
|
88
|
+
}
|
|
89
|
+
const honesty = gate.honesty_check ?? {};
|
|
90
|
+
for (const key of ['source_sections_edited', 'stale_text_removed', 'no_append_only_corrections', 'all_code_claims_cited']) {
|
|
91
|
+
if (honesty[key] !== true) blockers.push(blocker('phase-gate-honesty-incomplete', `Phase ${phase.id} gate is missing honesty confirmation: ${key}.`, relative(paths.projectRoot, gatePath)));
|
|
92
|
+
}
|
|
93
|
+
for (const item of gate.required_gates ?? []) {
|
|
94
|
+
if (item.status === 'not_applicable') continue;
|
|
95
|
+
if (item.status !== 'pass') {
|
|
96
|
+
blockers.push(blocker('required-gate-not-passing', `Required gate ${item.id} is ${item.status ?? 'unrecorded'}.`, item.id));
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const evidencePath = resolve(paths.deliveryRoot, item.output_path ?? '');
|
|
100
|
+
if (!item.output_path || !isWithin(paths.deliveryRoot, evidencePath) || !existsSync(evidencePath) || !statSync(evidencePath).isFile()) {
|
|
101
|
+
blockers.push(blocker('gate-evidence-missing', `Required gate ${item.id} has no valid evidence file.`, item.output_path ?? item.id));
|
|
102
|
+
} else if (!item.evidence_hash || sha256(readFileSync(evidencePath)) !== item.evidence_hash) {
|
|
103
|
+
blockers.push(blocker('gate-evidence-stale', `Required gate ${item.id} evidence has changed.`, item.output_path));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
validatePhaseGateAtPaths(paths, phase.id, gate, {
|
|
107
|
+
providers: phase.validation?.providers ?? state.providers ?? [],
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
blockers.push(blocker('phase-gate-invalid', `Phase ${phase.id} gate ledger is invalid: ${error.message}`, relative(paths.projectRoot, gatePath)));
|
|
111
|
+
}
|
|
112
|
+
return blockers;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function deriveTasks(paths, leases) {
|
|
116
|
+
const graphPath = resolve(paths.deliveryRoot, 'task-graph.json');
|
|
117
|
+
if (!existsSync(graphPath)) {
|
|
118
|
+
return { status: 'not-planned', validation: null, tasks: [], available: [], maxParallelTasks: 1 };
|
|
119
|
+
}
|
|
120
|
+
let graph = null;
|
|
121
|
+
try {
|
|
122
|
+
graph = JSON.parse(readFileSync(graphPath, 'utf8'));
|
|
123
|
+
} catch {
|
|
124
|
+
// The deterministic validator reports the parse failure.
|
|
125
|
+
}
|
|
126
|
+
const validation = validateTaskGraph(paths.deliveryRoot, {
|
|
127
|
+
slug: paths.deliveryRoot.split('/').at(-1),
|
|
128
|
+
});
|
|
129
|
+
const activeByTask = new Map(
|
|
130
|
+
leases.filter((lease) => lease.status === 'active').map((lease) => [lease.taskId, lease]),
|
|
131
|
+
);
|
|
132
|
+
const tasks = validation.tasks.map((task) => {
|
|
133
|
+
const lease = activeByTask.get(task.id) ?? null;
|
|
134
|
+
return { ...task, status: lease ? 'leased' : task.status, lease };
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
status: validation.status === 'pass' ? 'planned' : 'invalid',
|
|
138
|
+
validation,
|
|
139
|
+
tasks,
|
|
140
|
+
available: tasks.filter((task) => task.status === 'ready').map((task) => task.id),
|
|
141
|
+
maxParallelTasks: Number(graph?.parallelism?.max_parallel_tasks ?? 1),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function deriveExecutionState(projectRoot, intent, options = {}) {
|
|
146
|
+
if (!intent) throw new Error('Execution state requires an intent.');
|
|
147
|
+
const paths = deliveryPaths(projectRoot, intent.slug);
|
|
148
|
+
const blockers = [];
|
|
149
|
+
let state = null;
|
|
150
|
+
|
|
151
|
+
if (existsSync(paths.statePath)) {
|
|
152
|
+
try {
|
|
153
|
+
state = JSON.parse(readFileSync(paths.statePath, 'utf8'));
|
|
154
|
+
if (state.schema !== 'ewai.delivery-state/v1' || state.slug !== intent.slug) {
|
|
155
|
+
blockers.push(blocker('delivery-state-invalid', 'Durable delivery state has the wrong schema or slug.', relative(paths.projectRoot, paths.statePath)));
|
|
156
|
+
} else {
|
|
157
|
+
try {
|
|
158
|
+
validateIntentStateCopies(paths.projectRoot, intent.path, {
|
|
159
|
+
status: state.intent.status,
|
|
160
|
+
deliveryStatus: state.status,
|
|
161
|
+
currentPhase: state.currentPhase,
|
|
162
|
+
deliveryStatePath: relative(paths.projectRoot, paths.statePath).replaceAll('\\', '/'),
|
|
163
|
+
});
|
|
164
|
+
} catch (error) {
|
|
165
|
+
blockers.push(blocker('intent-state-drift', error.message, relative(paths.projectRoot, intent.path)));
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
assertCompletedEvidenceFresh(paths, state);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
blockers.push(blocker('completed-evidence-stale', error.message, relative(paths.projectRoot, paths.deliveryRoot)));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
blockers.push(blocker('delivery-state-invalid', `Durable delivery state cannot be read: ${error.message}`, relative(paths.projectRoot, paths.statePath)));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const catalog = options.intentCatalog instanceof Map ? options.intentCatalog : new Map();
|
|
179
|
+
if (!catalog.has(intent.id)) catalog.set(intent.id, intent);
|
|
180
|
+
const dependencyAudit = validateIntentDependencyGraph([...catalog.values()]);
|
|
181
|
+
for (const error of dependencyAudit.errors) {
|
|
182
|
+
if (error.source === intent.id || error.target === intent.id || error.cycle?.includes(intent.id)) {
|
|
183
|
+
blockers.push(blocker(error.code, error.message, error.target ?? intent.id));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const valid = blockers.length === 0;
|
|
187
|
+
const taskState = state ? deriveTasks(paths, options.leases ?? []) : { status: 'not-planned', validation: null, tasks: [], available: [], maxParallelTasks: 1 };
|
|
188
|
+
const runningPhase = state ? phaseSequence(state).find((phase) => phase.status === 'running') : null;
|
|
189
|
+
const completeBlockers = [...blockers];
|
|
190
|
+
if (runningPhase?.id === 'intent' && !acceptedIntentStatuses.has(String(intent.status).toLowerCase())) {
|
|
191
|
+
completeBlockers.push(blocker('intent-not-ready', 'Intent must be ready or approved before the Intent phase can complete.', intent.id));
|
|
192
|
+
}
|
|
193
|
+
if (runningPhase?.id === 'delivery') completeBlockers.push(...dependencyRequirementBlockers(projectRoot, intent, catalog, 'delivery'));
|
|
194
|
+
if (runningPhase && valid) completeBlockers.push(...gateBlockers(paths, state, runningPhase));
|
|
195
|
+
|
|
196
|
+
const nextPhase = state ? nextRequiredPhase(state) : null;
|
|
197
|
+
const buildApprovalPath = resolve(paths.gatesRoot, 'build/build-approval.json');
|
|
198
|
+
const buildApproved = Boolean(state?.approvals?.build && existsSync(buildApprovalPath));
|
|
199
|
+
const buildDependencyBlockers = dependencyRequirementBlockers(projectRoot, intent, catalog, 'build');
|
|
200
|
+
const buildReadinessBlockers = [
|
|
201
|
+
...blockers,
|
|
202
|
+
...buildDependencyBlockers,
|
|
203
|
+
...(nextPhase === 'build' ? [] : [blocker('build-not-next', `Build is not next; current required phase is ${nextPhase ?? 'none'}.`, nextPhase ?? '')]),
|
|
204
|
+
];
|
|
205
|
+
const taskBlockers = [...blockers];
|
|
206
|
+
if (taskState.status === 'not-planned') taskBlockers.push(blocker('task-graph-not-planned', 'No task graph exists yet.', relative(paths.projectRoot, resolve(paths.deliveryRoot, 'task-graph.json'))));
|
|
207
|
+
if (taskState.status === 'invalid') taskBlockers.push(blocker('task-graph-invalid', 'Task graph failed deterministic validation.', taskState.validation?.graphPath ?? 'task-graph.json'));
|
|
208
|
+
if (!taskState.available.length) taskBlockers.push(blocker('no-afk-task-ready', 'No unleased AFK task currently has satisfied dependencies.', 'task-graph.json'));
|
|
209
|
+
const buildRunning = state?.currentPhase === 'build'
|
|
210
|
+
&& state.phases?.find((phase) => phase.id === 'build')?.status === 'running';
|
|
211
|
+
if (!buildRunning) taskBlockers.push(blocker('build-not-running', 'Tasks can be leased only after the guarded harness has entered Build.', state?.currentPhase ?? 'not-started'));
|
|
212
|
+
|
|
213
|
+
const actions = {
|
|
214
|
+
beginHarness: action(!state && valid, state ? [blocker('delivery-already-started', 'The delivery harness has already started.', relative(paths.projectRoot, paths.statePath))] : blockers),
|
|
215
|
+
continueHarness: action(Boolean(state) && valid && !['completed', 'validated-not-for-build'].includes(state?.status), blockers, { nextPhase }),
|
|
216
|
+
completeCurrentPhase: action(Boolean(runningPhase) && valid, completeBlockers, { phase: runningPhase?.id ?? null }),
|
|
217
|
+
approveBuild: action(nextPhase === 'build' && !buildApproved && valid, [
|
|
218
|
+
...buildReadinessBlockers,
|
|
219
|
+
...(buildApproved ? [blocker('build-already-approved', 'Build has already been approved.', relative(paths.projectRoot, buildApprovalPath))] : []),
|
|
220
|
+
]),
|
|
221
|
+
enterBuild: action(nextPhase === 'build' && buildApproved && valid, [
|
|
222
|
+
...buildReadinessBlockers,
|
|
223
|
+
...(buildApproved ? [] : [blocker('build-approval-missing', 'Build requires explicit recorded approval.', relative(paths.projectRoot, buildApprovalPath))]),
|
|
224
|
+
]),
|
|
225
|
+
acquireTask: action(valid && buildRunning && taskState.status === 'planned' && taskState.available.length > 0, taskBlockers, { candidates: taskState.available }),
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
schema: 'ewai.execution-state/v1',
|
|
230
|
+
valid,
|
|
231
|
+
intent: { id: intent.id, slug: intent.slug, status: intent.status },
|
|
232
|
+
lifecycle: {
|
|
233
|
+
status: state?.status ?? 'not-started',
|
|
234
|
+
currentPhase: state?.currentPhase ?? 'backlog',
|
|
235
|
+
nextPhase,
|
|
236
|
+
deliveryStatePath: state ? relative(paths.projectRoot, paths.statePath).replaceAll('\\', '/') : null,
|
|
237
|
+
},
|
|
238
|
+
blockers,
|
|
239
|
+
actions,
|
|
240
|
+
tasks: taskState,
|
|
241
|
+
projection: projection(intent, state, valid),
|
|
242
|
+
};
|
|
243
|
+
}
|
package/src/install.mjs
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cpSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
lstatSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
symlinkSync
|
|
9
|
+
} from 'node:fs';
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const installRoot = resolve(moduleDir, '..');
|
|
16
|
+
const skillSourceRoot = resolve(installRoot, 'skills-src');
|
|
17
|
+
const claudeAgentSourceRoot = resolve(installRoot, 'agents-src/claude');
|
|
18
|
+
|
|
19
|
+
function availableSkills() {
|
|
20
|
+
return readdirSync(skillSourceRoot, { withFileTypes: true })
|
|
21
|
+
.filter((entry) => entry.isDirectory() && existsSync(resolve(skillSourceRoot, entry.name, 'SKILL.md')))
|
|
22
|
+
.map((entry) => entry.name)
|
|
23
|
+
.sort();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function availableClaudeAgents() {
|
|
27
|
+
if (!existsSync(claudeAgentSourceRoot)) return [];
|
|
28
|
+
return readdirSync(claudeAgentSourceRoot, { withFileTypes: true })
|
|
29
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.md'))
|
|
30
|
+
.map((entry) => entry.name)
|
|
31
|
+
.sort();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function selectedHosts(host, home) {
|
|
35
|
+
if (host !== 'auto') return [host];
|
|
36
|
+
const hosts = [];
|
|
37
|
+
if (existsSync(resolve(home, '.codex'))) hosts.push('codex');
|
|
38
|
+
if (existsSync(resolve(home, '.claude'))) hosts.push('claude');
|
|
39
|
+
if (
|
|
40
|
+
existsSync(resolve(home, '.gemini/antigravity-cli'))
|
|
41
|
+
|| existsSync(resolve(home, '.gemini/config'))
|
|
42
|
+
) hosts.push('antigravity');
|
|
43
|
+
return hosts.length ? hosts : ['codex'];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function skillDestinationRoot({ scope, host, home, projectRoot }) {
|
|
47
|
+
if (scope === 'project') {
|
|
48
|
+
if (!projectRoot) throw new Error('Project installation requires projectRoot');
|
|
49
|
+
return host === 'claude'
|
|
50
|
+
? resolve(projectRoot, '.claude/skills')
|
|
51
|
+
: resolve(projectRoot, '.agents/skills');
|
|
52
|
+
}
|
|
53
|
+
return host === 'claude'
|
|
54
|
+
? resolve(home, '.claude/skills')
|
|
55
|
+
: host === 'antigravity'
|
|
56
|
+
? resolve(home, '.gemini/config/skills')
|
|
57
|
+
: resolve(home, '.codex/skills');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function installSkill(source, destination, mode, force) {
|
|
61
|
+
if (existsSync(destination) || lstatExists(destination)) {
|
|
62
|
+
if (!force) return { status: 'skipped', destination };
|
|
63
|
+
rmSync(destination, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
67
|
+
if (mode === 'link') {
|
|
68
|
+
mkdirSync(destination, { recursive: true });
|
|
69
|
+
for (const entry of readdirSync(source)) {
|
|
70
|
+
symlinkSync(resolve(source, entry), resolve(destination, entry));
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
cpSync(source, destination, { recursive: true, force: false, errorOnExist: true });
|
|
74
|
+
}
|
|
75
|
+
return { status: 'installed', destination };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function installFile(source, destination, mode, force) {
|
|
79
|
+
if (lstatExists(destination)) {
|
|
80
|
+
if (!force) return { status: 'skipped', destination };
|
|
81
|
+
rmSync(destination, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
85
|
+
if (mode === 'link') symlinkSync(source, destination);
|
|
86
|
+
else cpSync(source, destination, { force: false, errorOnExist: true });
|
|
87
|
+
return { status: 'installed', destination };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function lstatExists(path) {
|
|
91
|
+
try {
|
|
92
|
+
lstatSync(path);
|
|
93
|
+
return true;
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function install(options = {}) {
|
|
100
|
+
const scope = options.scope ?? 'global';
|
|
101
|
+
const home = resolve(options.home ?? homedir());
|
|
102
|
+
const mode = options.mode ?? 'copy';
|
|
103
|
+
if (!['global', 'project'].includes(scope)) throw new Error(`Unsupported install scope: ${scope}`);
|
|
104
|
+
if (!['copy', 'link'].includes(mode)) throw new Error(`Unsupported install mode: ${mode}`);
|
|
105
|
+
|
|
106
|
+
const hosts = selectedHosts(options.host ?? 'auto', home);
|
|
107
|
+
for (const host of hosts) {
|
|
108
|
+
if (!['codex', 'claude', 'antigravity'].includes(host)) throw new Error(`Unsupported agent host: ${host}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const results = [];
|
|
112
|
+
const agentResults = [];
|
|
113
|
+
for (const host of hosts) {
|
|
114
|
+
const destinationRoot = skillDestinationRoot({
|
|
115
|
+
scope,
|
|
116
|
+
host,
|
|
117
|
+
home,
|
|
118
|
+
projectRoot: options.projectRoot ? resolve(options.projectRoot) : ''
|
|
119
|
+
});
|
|
120
|
+
mkdirSync(destinationRoot, { recursive: true });
|
|
121
|
+
for (const skill of availableSkills()) {
|
|
122
|
+
const destination = resolve(destinationRoot, skill);
|
|
123
|
+
results.push({
|
|
124
|
+
host,
|
|
125
|
+
skill,
|
|
126
|
+
...installSkill(
|
|
127
|
+
resolve(skillSourceRoot, skill),
|
|
128
|
+
destination,
|
|
129
|
+
mode,
|
|
130
|
+
Boolean(options.force)
|
|
131
|
+
)
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (host === 'claude') {
|
|
135
|
+
const agentRoot = scope === 'project'
|
|
136
|
+
? resolve(options.projectRoot, '.claude/agents')
|
|
137
|
+
: resolve(home, '.claude/agents');
|
|
138
|
+
for (const agent of availableClaudeAgents()) {
|
|
139
|
+
agentResults.push({
|
|
140
|
+
host,
|
|
141
|
+
agent: agent.slice(0, -3),
|
|
142
|
+
...installFile(
|
|
143
|
+
resolve(claudeAgentSourceRoot, agent),
|
|
144
|
+
resolve(agentRoot, agent),
|
|
145
|
+
mode,
|
|
146
|
+
Boolean(options.force)
|
|
147
|
+
)
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (scope === 'global' && options.installBin !== false) {
|
|
154
|
+
const binDir = resolve(options.binDir ?? resolve(home, '.local/bin'));
|
|
155
|
+
const destination = resolve(binDir, basename('ewai'));
|
|
156
|
+
mkdirSync(binDir, { recursive: true });
|
|
157
|
+
if (lstatExists(destination)) {
|
|
158
|
+
if (options.force) rmSync(destination, { force: true });
|
|
159
|
+
else return { scope, mode, hosts, skills: results, agents: agentResults, bin: { status: 'skipped', destination } };
|
|
160
|
+
}
|
|
161
|
+
symlinkSync(resolve(installRoot, 'bin/ewai'), destination);
|
|
162
|
+
return { scope, mode, hosts, skills: results, agents: agentResults, bin: { status: 'installed', destination } };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { scope, mode, hosts, skills: results, agents: agentResults };
|
|
166
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { projectPaths } from './paths.mjs';
|
|
4
|
+
|
|
5
|
+
const enforcementPoints = new Set(['build', 'delivery']);
|
|
6
|
+
const requiredStates = new Set(['plan-complete', 'delivered']);
|
|
7
|
+
|
|
8
|
+
function dependencyRelationships(intent) {
|
|
9
|
+
return (intent.relationships ?? []).filter((relationship) => relationship.type === 'depends-on');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function requirement(relationship) {
|
|
13
|
+
return {
|
|
14
|
+
requiredBefore: relationship.required_before ?? 'delivery',
|
|
15
|
+
requiredState: relationship.required_state ?? 'delivered',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function targetSatisfies(projectRoot, target, requiredState) {
|
|
20
|
+
if (requiredState === 'delivered') {
|
|
21
|
+
return ['completed', 'delivered'].includes(String(target.deliveryStatus ?? target.status).toLowerCase());
|
|
22
|
+
}
|
|
23
|
+
const path = resolve(projectPaths(projectRoot).buildRoot, target.slug, 'delivery-state.json');
|
|
24
|
+
if (!existsSync(path)) return false;
|
|
25
|
+
try {
|
|
26
|
+
const state = JSON.parse(readFileSync(path, 'utf8'));
|
|
27
|
+
return state.schema === 'ewai.delivery-state/v1'
|
|
28
|
+
&& state.slug === target.slug
|
|
29
|
+
&& state.phases?.find((phase) => phase.id === 'plan')?.status === 'completed';
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function validateIntentDependencyGraph(intents) {
|
|
36
|
+
const catalog = new Map(intents.map((intent) => [intent.id, intent]));
|
|
37
|
+
const errors = [];
|
|
38
|
+
const edges = new Map(intents.map((intent) => [intent.id, []]));
|
|
39
|
+
const slugOwners = new Map();
|
|
40
|
+
for (const intent of intents) {
|
|
41
|
+
const owners = slugOwners.get(intent.slug) ?? [];
|
|
42
|
+
owners.push(intent.id);
|
|
43
|
+
slugOwners.set(intent.slug, owners);
|
|
44
|
+
}
|
|
45
|
+
for (const [slug, owners] of slugOwners) {
|
|
46
|
+
if (owners.length < 2) continue;
|
|
47
|
+
for (const owner of owners) {
|
|
48
|
+
errors.push({
|
|
49
|
+
code: 'intent-slug-collision',
|
|
50
|
+
source: owner,
|
|
51
|
+
target: owners.find((candidate) => candidate !== owner),
|
|
52
|
+
message: `Intent slug ${slug} is shared by ${owners.join(', ')} but delivery folders are slug-keyed.`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const intent of intents) {
|
|
57
|
+
for (const relationship of dependencyRelationships(intent)) {
|
|
58
|
+
const { requiredBefore, requiredState } = requirement(relationship);
|
|
59
|
+
if (!catalog.has(relationship.target)) {
|
|
60
|
+
errors.push({ code: 'intent-dependency-missing', source: intent.id, target: relationship.target, message: `${intent.id} depends on missing intent ${relationship.target}.` });
|
|
61
|
+
} else {
|
|
62
|
+
edges.get(intent.id).push(relationship.target);
|
|
63
|
+
const target = catalog.get(relationship.target);
|
|
64
|
+
if ((slugOwners.get(target.slug) ?? []).length > 1) {
|
|
65
|
+
errors.push({
|
|
66
|
+
code: 'intent-dependency-target-collision',
|
|
67
|
+
source: intent.id,
|
|
68
|
+
target: relationship.target,
|
|
69
|
+
message: `${intent.id} depends on ${relationship.target}, whose slug-keyed delivery namespace collides.`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!enforcementPoints.has(requiredBefore)) {
|
|
74
|
+
errors.push({ code: 'intent-dependency-enforcement', source: intent.id, target: relationship.target, message: `${intent.id} has unsupported required_before ${requiredBefore}.` });
|
|
75
|
+
}
|
|
76
|
+
if (!requiredStates.has(requiredState)) {
|
|
77
|
+
errors.push({ code: 'intent-dependency-state', source: intent.id, target: relationship.target, message: `${intent.id} has unsupported required_state ${requiredState}.` });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const visiting = new Set();
|
|
83
|
+
const visited = new Set();
|
|
84
|
+
const visit = (id, trail = []) => {
|
|
85
|
+
if (visiting.has(id)) {
|
|
86
|
+
const cycle = [...trail, id];
|
|
87
|
+
errors.push({ code: 'intent-dependency-cycle', source: id, target: id, cycle, message: `Intent dependency cycle detected: ${cycle.join(' -> ')}.` });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (visited.has(id)) return;
|
|
91
|
+
visiting.add(id);
|
|
92
|
+
for (const target of edges.get(id) ?? []) visit(target, [...trail, id]);
|
|
93
|
+
visiting.delete(id);
|
|
94
|
+
visited.add(id);
|
|
95
|
+
};
|
|
96
|
+
for (const id of edges.keys()) visit(id);
|
|
97
|
+
return { schema: 'ewai.intent-dependency-audit/v1', status: errors.length ? 'fail' : 'pass', checked: intents.length, errors };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function dependencyRequirementBlockers(projectRoot, intent, catalog, enforcementPoint) {
|
|
101
|
+
const blockers = [];
|
|
102
|
+
for (const relationship of dependencyRelationships(intent)) {
|
|
103
|
+
const target = catalog.get(relationship.target);
|
|
104
|
+
const { requiredBefore, requiredState } = requirement(relationship);
|
|
105
|
+
if (requiredBefore !== enforcementPoint) continue;
|
|
106
|
+
if (!target) {
|
|
107
|
+
blockers.push({ code: 'intent-dependency-missing', message: `Dependency ${relationship.target} does not exist.`, evidence: relationship.target });
|
|
108
|
+
} else if (!targetSatisfies(projectRoot, target, requiredState)) {
|
|
109
|
+
blockers.push({
|
|
110
|
+
code: 'intent-dependency-incomplete',
|
|
111
|
+
message: `Dependency ${relationship.target} must reach ${requiredState} before ${enforcementPoint}.`,
|
|
112
|
+
evidence: relationship.target,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return blockers;
|
|
117
|
+
}
|