@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,222 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { extname, relative, resolve } from 'node:path';
|
|
4
|
+
import YAML from 'yaml';
|
|
5
|
+
import { recoverIntentTransactions } from '../intents.mjs';
|
|
6
|
+
import { openRuntimeDatabase } from './database.mjs';
|
|
7
|
+
import { runtimePaths } from './paths.mjs';
|
|
8
|
+
|
|
9
|
+
function findMarkdown(root) {
|
|
10
|
+
if (!existsSync(root)) return [];
|
|
11
|
+
const found = [];
|
|
12
|
+
for (const entry of readdirSync(root, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
13
|
+
const path = resolve(root, entry.name);
|
|
14
|
+
if (entry.isDirectory()) found.push(...findMarkdown(path));
|
|
15
|
+
if (entry.isFile() && extname(entry.name).toLowerCase() === '.md') found.push(path);
|
|
16
|
+
}
|
|
17
|
+
return found;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseFrontmatter(markdown) {
|
|
21
|
+
const match = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
22
|
+
if (!match) return {};
|
|
23
|
+
try {
|
|
24
|
+
return YAML.parse(match[1]) ?? {};
|
|
25
|
+
} catch {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function titleFromSlug(slug) {
|
|
31
|
+
return slug.split('-').map((part) => `${part[0]?.toUpperCase() ?? ''}${part.slice(1)}`).join(' ');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function problemExcerpt(markdown) {
|
|
35
|
+
const body = markdown.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
36
|
+
const lines = body.split(/\r?\n/);
|
|
37
|
+
const problemStart = lines.findIndex((line) => /^##\s+Problem\s*$/i.test(line));
|
|
38
|
+
const problemEnd = problemStart === -1
|
|
39
|
+
? -1
|
|
40
|
+
: lines.findIndex((line, index) => index > problemStart && /^##\s+/.test(line));
|
|
41
|
+
const problem = problemStart === -1
|
|
42
|
+
? ''
|
|
43
|
+
: lines.slice(problemStart + 1, problemEnd === -1 ? undefined : problemEnd).join(' ');
|
|
44
|
+
const fallback = body.replace(/^#.+$/m, '');
|
|
45
|
+
return (problem || fallback)
|
|
46
|
+
.replace(/[`*_>#\[\]]/g, '')
|
|
47
|
+
.replace(/\([^)]*\)/g, '')
|
|
48
|
+
.replace(/\s+/g, ' ')
|
|
49
|
+
.trim()
|
|
50
|
+
.slice(0, 240);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function sourceIntent(intentsRoot, path) {
|
|
54
|
+
const markdown = readFileSync(path, 'utf8');
|
|
55
|
+
const metadata = parseFrontmatter(markdown);
|
|
56
|
+
const sourcePath = relative(intentsRoot, path).replace(/\\/g, '/');
|
|
57
|
+
const id = sourcePath.replace(/\.md$/i, '');
|
|
58
|
+
const segments = id.split('/');
|
|
59
|
+
const filenameSlug = segments.at(-1);
|
|
60
|
+
const slug = metadata.slug || filenameSlug;
|
|
61
|
+
const domain = metadata.domain || (segments.length > 1 ? segments[0] : 'general');
|
|
62
|
+
return {
|
|
63
|
+
id,
|
|
64
|
+
slug,
|
|
65
|
+
domain,
|
|
66
|
+
title: metadata.title || titleFromSlug(slug),
|
|
67
|
+
status: metadata.status || 'draft',
|
|
68
|
+
deliveryStatus: metadata.delivery_status || 'not-started',
|
|
69
|
+
currentPhase: metadata.current_phase || 'backlog',
|
|
70
|
+
deliveryStatePath: metadata.delivery_state_path || '',
|
|
71
|
+
path,
|
|
72
|
+
intentMap: metadata.intent_map || null,
|
|
73
|
+
personas: Array.isArray(metadata.personas) ? metadata.personas : [],
|
|
74
|
+
relationships: Array.isArray(metadata.relationships) ? metadata.relationships : [],
|
|
75
|
+
deliveryShape: metadata.delivery_shape ?? null,
|
|
76
|
+
excerpt: problemExcerpt(markdown),
|
|
77
|
+
markdown,
|
|
78
|
+
contentHash: createHash('sha256').update(markdown).digest('hex'),
|
|
79
|
+
sourceMtimeMs: statSync(path).mtimeMs
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function syncIntentIndex(projectRoot, database = null) {
|
|
84
|
+
recoverIntentTransactions(projectRoot);
|
|
85
|
+
const ownsDatabase = !database;
|
|
86
|
+
const db = database ?? openRuntimeDatabase(projectRoot);
|
|
87
|
+
const { intentsRoot } = runtimePaths(projectRoot);
|
|
88
|
+
const intents = findMarkdown(intentsRoot).map((path) => sourceIntent(intentsRoot, path));
|
|
89
|
+
const upsert = db.prepare(`
|
|
90
|
+
INSERT INTO intents (
|
|
91
|
+
id, slug, domain, title, status, delivery_status, current_phase,
|
|
92
|
+
delivery_state_path, path, intent_map, personas_json, relationships_json,
|
|
93
|
+
delivery_shape_json,
|
|
94
|
+
excerpt, markdown, content_hash, source_mtime_ms, updated_at
|
|
95
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
|
96
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
97
|
+
slug = excluded.slug,
|
|
98
|
+
domain = excluded.domain,
|
|
99
|
+
title = excluded.title,
|
|
100
|
+
status = excluded.status,
|
|
101
|
+
delivery_status = excluded.delivery_status,
|
|
102
|
+
current_phase = excluded.current_phase,
|
|
103
|
+
delivery_state_path = excluded.delivery_state_path,
|
|
104
|
+
path = excluded.path,
|
|
105
|
+
intent_map = excluded.intent_map,
|
|
106
|
+
personas_json = excluded.personas_json,
|
|
107
|
+
relationships_json = excluded.relationships_json,
|
|
108
|
+
delivery_shape_json = excluded.delivery_shape_json,
|
|
109
|
+
excerpt = excluded.excerpt,
|
|
110
|
+
markdown = excluded.markdown,
|
|
111
|
+
content_hash = excluded.content_hash,
|
|
112
|
+
source_mtime_ms = excluded.source_mtime_ms,
|
|
113
|
+
updated_at = CURRENT_TIMESTAMP
|
|
114
|
+
`);
|
|
115
|
+
|
|
116
|
+
db.exec('BEGIN IMMEDIATE;');
|
|
117
|
+
try {
|
|
118
|
+
for (const intent of intents) {
|
|
119
|
+
upsert.run(
|
|
120
|
+
intent.id,
|
|
121
|
+
intent.slug,
|
|
122
|
+
intent.domain,
|
|
123
|
+
intent.title,
|
|
124
|
+
intent.status,
|
|
125
|
+
intent.deliveryStatus,
|
|
126
|
+
intent.currentPhase,
|
|
127
|
+
intent.deliveryStatePath,
|
|
128
|
+
intent.path,
|
|
129
|
+
intent.intentMap,
|
|
130
|
+
JSON.stringify(intent.personas),
|
|
131
|
+
JSON.stringify(intent.relationships),
|
|
132
|
+
JSON.stringify(intent.deliveryShape),
|
|
133
|
+
intent.excerpt,
|
|
134
|
+
intent.markdown,
|
|
135
|
+
intent.contentHash,
|
|
136
|
+
intent.sourceMtimeMs
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (intents.length) {
|
|
140
|
+
const placeholders = intents.map(() => '?').join(', ');
|
|
141
|
+
db.prepare(`DELETE FROM intents WHERE id NOT IN (${placeholders})`).run(...intents.map((intent) => intent.id));
|
|
142
|
+
} else {
|
|
143
|
+
db.exec('DELETE FROM intents;');
|
|
144
|
+
}
|
|
145
|
+
db.prepare(`
|
|
146
|
+
INSERT INTO runtime_meta (key, value, updated_at)
|
|
147
|
+
VALUES ('intents_last_synced_at', ?, CURRENT_TIMESTAMP)
|
|
148
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP
|
|
149
|
+
`).run(new Date().toISOString());
|
|
150
|
+
db.exec('COMMIT;');
|
|
151
|
+
} catch (error) {
|
|
152
|
+
db.exec('ROLLBACK;');
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (ownsDatabase) db.close();
|
|
157
|
+
return { count: intents.length, intents };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function rowToIntent(row, includeMarkdown = false) {
|
|
161
|
+
if (!row) return null;
|
|
162
|
+
const intent = {
|
|
163
|
+
id: row.id,
|
|
164
|
+
slug: row.slug,
|
|
165
|
+
domain: row.domain,
|
|
166
|
+
title: row.title,
|
|
167
|
+
status: row.status,
|
|
168
|
+
deliveryStatus: row.delivery_status,
|
|
169
|
+
currentPhase: row.current_phase,
|
|
170
|
+
deliveryStatePath: row.delivery_state_path,
|
|
171
|
+
path: row.path,
|
|
172
|
+
intentMap: row.intent_map || null,
|
|
173
|
+
personas: JSON.parse(row.personas_json || '[]'),
|
|
174
|
+
relationships: JSON.parse(row.relationships_json || '[]'),
|
|
175
|
+
deliveryShape: JSON.parse(row.delivery_shape_json || 'null'),
|
|
176
|
+
excerpt: row.excerpt,
|
|
177
|
+
updatedAt: row.updated_at
|
|
178
|
+
};
|
|
179
|
+
if (includeMarkdown) intent.markdown = row.markdown;
|
|
180
|
+
return intent;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function listRuntimeIntents(projectRoot, options = {}) {
|
|
184
|
+
const database = openRuntimeDatabase(projectRoot);
|
|
185
|
+
try {
|
|
186
|
+
syncIntentIndex(projectRoot, database);
|
|
187
|
+
const query = String(options.query ?? '').trim().toLowerCase();
|
|
188
|
+
const status = String(options.status ?? '').trim();
|
|
189
|
+
const rows = database.prepare(`
|
|
190
|
+
SELECT * FROM intents
|
|
191
|
+
WHERE (? = '' OR status = ?)
|
|
192
|
+
AND (? = '' OR lower(title || ' ' || slug || ' ' || domain || ' ' || coalesce(intent_map, '') || ' ' || coalesce(relationships_json, '') || ' ' || coalesce(delivery_shape_json, '') || ' ' || excerpt) LIKE '%' || ? || '%')
|
|
193
|
+
ORDER BY CASE status WHEN 'ready' THEN 0 WHEN 'draft' THEN 1 ELSE 2 END, title COLLATE NOCASE
|
|
194
|
+
`).all(status, status, query, query);
|
|
195
|
+
return rows.map((row) => rowToIntent(row));
|
|
196
|
+
} finally {
|
|
197
|
+
database.close();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function readRuntimeIntent(projectRoot, reference) {
|
|
202
|
+
const database = openRuntimeDatabase(projectRoot);
|
|
203
|
+
try {
|
|
204
|
+
syncIntentIndex(projectRoot, database);
|
|
205
|
+
const exact = database.prepare('SELECT * FROM intents WHERE id = ?').get(reference);
|
|
206
|
+
if (exact) return rowToIntent(exact, true);
|
|
207
|
+
const matches = database.prepare('SELECT * FROM intents WHERE slug = ? ORDER BY id LIMIT 2').all(reference);
|
|
208
|
+
if (matches.length > 1) throw new Error(`Ambiguous intent slug: ${reference}; use the exact domain/slug reference.`);
|
|
209
|
+
return rowToIntent(matches[0], true);
|
|
210
|
+
} finally {
|
|
211
|
+
database.close();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function runtimeIntentSummary(projectRoot) {
|
|
216
|
+
const intents = listRuntimeIntents(projectRoot);
|
|
217
|
+
const byStatus = intents.reduce((summary, intent) => {
|
|
218
|
+
summary[intent.status] = (summary[intent.status] ?? 0) + 1;
|
|
219
|
+
return summary;
|
|
220
|
+
}, {});
|
|
221
|
+
return { count: intents.length, byStatus };
|
|
222
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, realpathSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { extname, isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
+
import { runtimePaths } from './paths.mjs';
|
|
4
|
+
|
|
5
|
+
const readableExtensions = new Set(['.md', '.markdown', '.txt', '.yaml', '.yml', '.json', '.csv']);
|
|
6
|
+
const maxDocumentBytes = 2 * 1024 * 1024;
|
|
7
|
+
|
|
8
|
+
function isWithin(root, target) {
|
|
9
|
+
const rel = relative(root, target);
|
|
10
|
+
return rel === '' || (rel && !rel.startsWith('..') && !isAbsolute(rel));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function specsBoundary(projectRoot) {
|
|
14
|
+
const configured = runtimePaths(projectRoot).specsRoot;
|
|
15
|
+
if (!existsSync(configured)) return null;
|
|
16
|
+
return { configured, real: realpathSync(configured) };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function walk(boundary, directory = boundary.configured, parentPath = '') {
|
|
20
|
+
const folders = [];
|
|
21
|
+
const documents = [];
|
|
22
|
+
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name, undefined, { numeric: true }))) {
|
|
23
|
+
if (entry.name.startsWith('.')) continue;
|
|
24
|
+
const absolute = resolve(directory, entry.name);
|
|
25
|
+
const logicalPath = parentPath ? `${parentPath}/${entry.name}` : entry.name;
|
|
26
|
+
const stats = lstatSync(absolute);
|
|
27
|
+
if (stats.isSymbolicLink()) continue;
|
|
28
|
+
if (stats.isDirectory()) {
|
|
29
|
+
const children = walk(boundary, absolute, logicalPath);
|
|
30
|
+
if (children.documentCount) {
|
|
31
|
+
folders.push({ type: 'folder', name: entry.name, path: logicalPath, children: children.nodes, documentCount: children.documentCount });
|
|
32
|
+
}
|
|
33
|
+
documents.push(...children.documents);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!stats.isFile() || !readableExtensions.has(extname(entry.name).toLowerCase())) continue;
|
|
37
|
+
const real = realpathSync(absolute);
|
|
38
|
+
if (!isWithin(boundary.real, real)) continue;
|
|
39
|
+
const document = {
|
|
40
|
+
type: 'document',
|
|
41
|
+
name: entry.name,
|
|
42
|
+
path: logicalPath,
|
|
43
|
+
extension: extname(entry.name).toLowerCase(),
|
|
44
|
+
size: stats.size,
|
|
45
|
+
updatedAt: stats.mtime.toISOString()
|
|
46
|
+
};
|
|
47
|
+
documents.push(document);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
nodes: [...folders, ...documents.filter((document) => document.path.split('/').length === parentPath.split('/').filter(Boolean).length + 1)],
|
|
51
|
+
documents,
|
|
52
|
+
documentCount: documents.length
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function listKnowledge(projectRoot, options = {}) {
|
|
57
|
+
const boundary = specsBoundary(projectRoot);
|
|
58
|
+
if (!boundary) return { root: 'SPECS', tree: [], documents: [], count: 0 };
|
|
59
|
+
const result = walk(boundary);
|
|
60
|
+
const query = String(options.query ?? '').trim().toLowerCase();
|
|
61
|
+
const documents = query
|
|
62
|
+
? result.documents.filter((document) => `${document.name} ${document.path}`.toLowerCase().includes(query))
|
|
63
|
+
: result.documents;
|
|
64
|
+
return { root: 'SPECS', tree: result.nodes, documents, count: documents.length };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function readKnowledgeDocument(projectRoot, documentPath) {
|
|
68
|
+
const boundary = specsBoundary(projectRoot);
|
|
69
|
+
if (!boundary) return null;
|
|
70
|
+
const normalized = String(documentPath ?? '').replaceAll('\\', '/').replace(/^\/+/, '');
|
|
71
|
+
if (!normalized || normalized.split('/').some((part) => part === '..' || part === '')) return null;
|
|
72
|
+
const target = resolve(boundary.configured, normalized);
|
|
73
|
+
if (!isWithin(boundary.configured, target) || !existsSync(target) || lstatSync(target).isSymbolicLink() || !statSync(target).isFile()) return null;
|
|
74
|
+
const real = realpathSync(target);
|
|
75
|
+
const extension = extname(real).toLowerCase();
|
|
76
|
+
const stats = statSync(real);
|
|
77
|
+
if (!isWithin(boundary.real, real) || !readableExtensions.has(extension) || stats.size > maxDocumentBytes) return null;
|
|
78
|
+
return {
|
|
79
|
+
name: normalized.split('/').at(-1),
|
|
80
|
+
path: normalized,
|
|
81
|
+
extension,
|
|
82
|
+
size: stats.size,
|
|
83
|
+
updatedAt: stats.mtime.toISOString(),
|
|
84
|
+
content: readFileSync(real, 'utf8')
|
|
85
|
+
};
|
|
86
|
+
}
|