@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,197 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import {
|
|
4
|
+
closeSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
writeFileSync
|
|
11
|
+
} from 'node:fs';
|
|
12
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
import { initializeRuntime } from './database.mjs';
|
|
15
|
+
import { syncIntentIndex } from './intents.mjs';
|
|
16
|
+
import { runtimePaths } from './paths.mjs';
|
|
17
|
+
import { dashboardRuntimeVersion } from './version.mjs';
|
|
18
|
+
import { loadProjectConfig } from '../project.mjs';
|
|
19
|
+
import { inspectPersonaEntitlement } from '../persona-entitlements.mjs';
|
|
20
|
+
|
|
21
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const serverEntry = resolve(moduleDir, 'dashboard-server.mjs');
|
|
23
|
+
|
|
24
|
+
function readState(path) {
|
|
25
|
+
if (!existsSync(path)) return null;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function writeState(path, state) {
|
|
34
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
35
|
+
writeFileSync(path, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function health(url, timeout = 800) {
|
|
39
|
+
try {
|
|
40
|
+
const target = new URL(url);
|
|
41
|
+
if (target.protocol !== 'http:' || target.hostname !== '127.0.0.1') return null;
|
|
42
|
+
const response = await fetch(`${url}/api/health`, { signal: AbortSignal.timeout(timeout) });
|
|
43
|
+
if (!response.ok) return null;
|
|
44
|
+
const body = await response.json();
|
|
45
|
+
return body?.schema === 'ewai.dashboard-health/v1' ? body : null;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function basePort(projectRoot) {
|
|
52
|
+
const digest = createHash('sha256').update(resolve(projectRoot)).digest();
|
|
53
|
+
return 47000 + digest.readUInt16BE(0) % 1000;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function candidatePorts(projectRoot, configuredPort = 0) {
|
|
57
|
+
if (configuredPort) return [configuredPort];
|
|
58
|
+
const first = basePort(projectRoot);
|
|
59
|
+
return Array.from({ length: 20 }, (_, index) => 47000 + ((first - 47000 + index) % 1000));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function matchesProject(response, projectRoot, pid) {
|
|
63
|
+
return Boolean(response
|
|
64
|
+
&& typeof response.projectRoot === 'string'
|
|
65
|
+
&& isAbsolute(response.projectRoot)
|
|
66
|
+
&& resolve(response.projectRoot) === projectRoot
|
|
67
|
+
&& Number.isSafeInteger(response.pid) && response.pid > 0
|
|
68
|
+
&& (pid === undefined || (Number.isSafeInteger(pid) && pid > 0 && response.pid === pid)));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function compatibleHealth(response, projectRoot, pid) {
|
|
72
|
+
return matchesProject(response, projectRoot, pid)
|
|
73
|
+
&& response.runtimeVersion === dashboardRuntimeVersion;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function runtimeState(paths, response, port, owned) {
|
|
77
|
+
return { schema: 'ewai.dashboard-state/v1', projectRoot: paths.projectRoot,
|
|
78
|
+
pid: response.pid, port, url: `http://127.0.0.1:${port}`,
|
|
79
|
+
startedAt: response.startedAt, owned };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function dashboardStatus(projectRoot) {
|
|
83
|
+
const paths = runtimePaths(projectRoot);
|
|
84
|
+
const state = readState(paths.dashboardStatePath);
|
|
85
|
+
if (!state?.url) return { status: 'stopped', state: null };
|
|
86
|
+
const response = await health(state.url);
|
|
87
|
+
if (!matchesProject(response, paths.projectRoot, state.pid)) {
|
|
88
|
+
return { status: 'stale', state };
|
|
89
|
+
}
|
|
90
|
+
if (!compatibleHealth(response, paths.projectRoot, state.pid)) {
|
|
91
|
+
return { status: 'stale', state: { ...state, ...response },
|
|
92
|
+
verified: state.owned !== false && response.pid !== process.pid, reason: 'runtime-version' };
|
|
93
|
+
}
|
|
94
|
+
return { status: 'running', state: { ...state, ...response } };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function ensureDashboard(projectRoot, options = {}) {
|
|
98
|
+
const paths = runtimePaths(projectRoot);
|
|
99
|
+
initializeRuntime(paths.projectRoot);
|
|
100
|
+
const indexed = syncIntentIndex(paths.projectRoot);
|
|
101
|
+
|
|
102
|
+
// Check on every launch, including reuse; check-in shares its own promise.
|
|
103
|
+
const premium = await (options.premiumCheck ?? inspectPersonaEntitlement(loadProjectConfig(paths.projectRoot).config, { home: options.home, fetchImpl: options.premiumFetchImpl }));
|
|
104
|
+
const checkin = readState(paths.checkinStatePath);
|
|
105
|
+
writeState(paths.checkinStatePath, {
|
|
106
|
+
...(checkin?.schema === 'ewai.checkin-state/v1' ? checkin : {}),
|
|
107
|
+
schema: 'ewai.checkin-state/v1', checkedAt: new Date().toISOString(), premium,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const current = await dashboardStatus(paths.projectRoot);
|
|
111
|
+
if (current.status === 'running') {
|
|
112
|
+
return { status: 'running', started: false, intentCount: indexed.count, ...current.state };
|
|
113
|
+
}
|
|
114
|
+
if (current.status === 'stale') {
|
|
115
|
+
if (current.verified && current.state?.pid) {
|
|
116
|
+
try {
|
|
117
|
+
process.kill(Number(current.state.pid), 'SIGTERM');
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (error.code !== 'ESRCH') throw error;
|
|
120
|
+
}
|
|
121
|
+
const deadline = Date.now() + 3000;
|
|
122
|
+
while (Date.now() < deadline && await health(current.state.url, 250)) {
|
|
123
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
124
|
+
}
|
|
125
|
+
if (await health(current.state.url, 250)) {
|
|
126
|
+
throw new Error('The previous EWAI dashboard is still running. Close it, restart EWAI and open the new dashboard link. Existing settings and personas are unchanged.');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
rmSync(paths.dashboardStatePath, { force: true });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
mkdirSync(paths.logRoot, { recursive: true });
|
|
133
|
+
const log = openSync(paths.dashboardLogPath, 'a');
|
|
134
|
+
try {
|
|
135
|
+
for (const port of candidatePorts(paths.projectRoot, Number(options.port || 0))) {
|
|
136
|
+
const url = `http://127.0.0.1:${port}`;
|
|
137
|
+
const existing = await health(url);
|
|
138
|
+
if (compatibleHealth(existing, paths.projectRoot)) {
|
|
139
|
+
const state = runtimeState(paths, existing, port, false);
|
|
140
|
+
writeState(paths.dashboardStatePath, state);
|
|
141
|
+
return { status: 'running', started: false, intentCount: indexed.count, ...state };
|
|
142
|
+
}
|
|
143
|
+
if (existing) continue;
|
|
144
|
+
|
|
145
|
+
const child = spawn(process.execPath, [serverEntry, '--project', paths.projectRoot, '--port', String(port)], {
|
|
146
|
+
cwd: paths.projectRoot,
|
|
147
|
+
detached: true,
|
|
148
|
+
stdio: ['ignore', log, log],
|
|
149
|
+
env: { ...process.env, ...(options.home ? { HOME: resolve(options.home) } : {}), EWAI_DASHBOARD_CHILD: '1' }
|
|
150
|
+
});
|
|
151
|
+
let spawnFailed = false;
|
|
152
|
+
child.on('error', () => { spawnFailed = true; });
|
|
153
|
+
child.unref();
|
|
154
|
+
|
|
155
|
+
const deadline = Date.now() + (options.timeout ?? 5000);
|
|
156
|
+
while (Date.now() < deadline) {
|
|
157
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
158
|
+
const response = await health(url, 500);
|
|
159
|
+
if (compatibleHealth(response, paths.projectRoot, child.pid)) {
|
|
160
|
+
const state = runtimeState(paths, response, port, true);
|
|
161
|
+
writeState(paths.dashboardStatePath, state);
|
|
162
|
+
return { status: 'running', started: true, intentCount: indexed.count, ...state };
|
|
163
|
+
}
|
|
164
|
+
if (spawnFailed || child.exitCode !== null) break;
|
|
165
|
+
}
|
|
166
|
+
if (!spawnFailed && child.exitCode === null && Number.isSafeInteger(child.pid)) {
|
|
167
|
+
try { child.kill('SIGTERM'); } catch (error) { if (error.code !== 'ESRCH') throw error; }
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} finally {
|
|
171
|
+
closeSync(log);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
throw new Error(`EWAI couldn't open a compatible dashboard. Restart EWAI and open the new dashboard link. If this continues, check the dashboard log: ${paths.dashboardLogPath}`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function stopDashboard(projectRoot) {
|
|
178
|
+
const paths = runtimePaths(projectRoot);
|
|
179
|
+
const current = await dashboardStatus(projectRoot);
|
|
180
|
+
if ((current.status !== 'running' && !current.verified) || current.state?.owned === false || current.state?.pid === process.pid) {
|
|
181
|
+
rmSync(paths.dashboardStatePath, { force: true });
|
|
182
|
+
return { status: 'stopped', stopped: false };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
process.kill(Number(current.state.pid), 'SIGTERM');
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error.code !== 'ESRCH') throw error;
|
|
189
|
+
}
|
|
190
|
+
const deadline = Date.now() + 3000;
|
|
191
|
+
while (Date.now() < deadline) {
|
|
192
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
193
|
+
if (!(await health(current.state.url, 250))) break;
|
|
194
|
+
}
|
|
195
|
+
rmSync(paths.dashboardStatePath, { force: true });
|
|
196
|
+
return { status: 'stopped', stopped: true };
|
|
197
|
+
}
|