@mindflight/mindbrain-personal-studio 0.6.1 → 0.6.3
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/README.md +16 -8
- package/build/client/_app/immutable/chunks/CIErFlYG.js +1 -0
- package/build/client/_app/immutable/chunks/CIErFlYG.js.br +0 -0
- package/build/client/_app/immutable/chunks/CIErFlYG.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.CVz6aYsT.js → app.mURYm8o_.js} +2 -2
- package/build/client/_app/immutable/entry/app.mURYm8o_.js.br +0 -0
- package/build/client/_app/immutable/entry/app.mURYm8o_.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.D4M9ZeGO.js +1 -0
- package/build/client/_app/immutable/entry/start.D4M9ZeGO.js.br +2 -0
- package/build/client/_app/immutable/entry/start.D4M9ZeGO.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{1.BBtxY46Q.js → 1.DHKtMeFI.js} +1 -1
- package/build/client/_app/immutable/nodes/1.DHKtMeFI.js.br +1 -0
- package/build/client/_app/immutable/nodes/1.DHKtMeFI.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/handler.js +4 -4
- package/build/index.js +4 -4
- package/build/server/chunks/chunks/{internal.js-D8EA_he2.js → internal.js-C3tV0XXj.js} +2 -2
- package/build/server/chunks/chunks/{internal.js-D8EA_he2.js.map → internal.js-C3tV0XXj.js.map} +1 -1
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/{_server.ts.js-Dyfsc-VA.js → _server.ts.js-CAsXxBRq.js} +7 -2
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/_server.ts.js-CAsXxBRq.js.map +1 -0
- package/build/server/chunks/{handler-BjXBCd1c.js → handler-DlaCCnxx.js} +3 -3
- package/build/server/chunks/{handler-BjXBCd1c.js.map → handler-DlaCCnxx.js.map} +1 -1
- package/build/server/chunks/{index.js-BJYcV8V7.js → index.js-BGfKWHak.js} +2 -2
- package/build/server/chunks/{index.js-BJYcV8V7.js.map → index.js-BGfKWHak.js.map} +1 -1
- package/build/server/chunks/{manifest.js-Ddaot0P4.js → manifest.js-CnmaNf5D.js} +4 -4
- package/build/server/chunks/{manifest.js-Ddaot0P4.js.map → manifest.js-CnmaNf5D.js.map} +1 -1
- package/build/server/chunks/nodes/{1.js-BRigw_9J.js → 1.js-BypjwBYB.js} +2 -2
- package/build/server/chunks/nodes/{1.js-BRigw_9J.js.map → 1.js-BypjwBYB.js.map} +1 -1
- package/examples/immeuble/ACCEPTANCE.yaml +82 -0
- package/examples/immeuble/BIM_LITE.md +15 -0
- package/examples/immeuble/CHECKLIST.md +128 -0
- package/examples/immeuble/README.md +121 -0
- package/examples/immeuble/bundle/immeuble.bundle.json +22786 -0
- package/examples/immeuble/contracts/answer_artifacts.seed.jsonl +34 -0
- package/examples/immeuble/contracts/business_capabilities.seed.jsonl +25 -0
- package/examples/immeuble/contracts/consumer_contract.yaml +131 -0
- package/examples/immeuble/contracts/immeuble_structured_import_model.json +310 -0
- package/examples/immeuble/contracts/mapping_external_to_canonical.json +375 -0
- package/examples/immeuble/contracts/mapping_external_to_canonical.yaml +55 -0
- package/examples/immeuble/contracts/mapping_external_to_canonical_ws.json +65 -0
- package/examples/immeuble/contracts/model_contract.json +943 -0
- package/examples/immeuble/contracts/projection_catalog.yaml +366 -0
- package/examples/immeuble/contracts/scenarios.yaml +27 -0
- package/examples/immeuble/contracts/semantic_proposal.golden.json +1 -0
- package/examples/immeuble/contracts/source_profile.yaml +38 -0
- package/examples/immeuble/fake_data/DeltaFinding.csv +20 -0
- package/examples/immeuble/fake_data/ProjectionResult.csv +13 -0
- package/examples/immeuble/fake_data/ag_meeting.csv +4 -0
- package/examples/immeuble/fake_data/agenda_item.csv +4 -0
- package/examples/immeuble/fake_data/architect.csv +3 -0
- package/examples/immeuble/fake_data/architecture_firm.csv +2 -0
- package/examples/immeuble/fake_data/bank_account.csv +3 -0
- package/examples/immeuble/fake_data/billing_group.csv +41 -0
- package/examples/immeuble/fake_data/block.csv +10 -0
- package/examples/immeuble/fake_data/budget_line.csv +3 -0
- package/examples/immeuble/fake_data/building.csv +6 -0
- package/examples/immeuble/fake_data/cellar.csv +41 -0
- package/examples/immeuble/fake_data/change_order.csv +2 -0
- package/examples/immeuble/fake_data/charge_call.csv +58 -0
- package/examples/immeuble/fake_data/claim.csv +4 -0
- package/examples/immeuble/fake_data/coda_entry.csv +49 -0
- package/examples/immeuble/fake_data/compliance_certificate.csv +10 -0
- package/examples/immeuble/fake_data/contractor.csv +4 -0
- package/examples/immeuble/fake_data/decision.csv +5 -0
- package/examples/immeuble/fake_data/defect_reserve.csv +3 -0
- package/examples/immeuble/fake_data/household.csv +41 -0
- package/examples/immeuble/fake_data/inspection.csv +3 -0
- package/examples/immeuble/fake_data/insurance_policy.csv +4 -0
- package/examples/immeuble/fake_data/intervention.csv +13 -0
- package/examples/immeuble/fake_data/invoice.csv +3 -0
- package/examples/immeuble/fake_data/lease_contract.csv +12 -0
- package/examples/immeuble/fake_data/maintenance_ticket.csv +13 -0
- package/examples/immeuble/fake_data/meter.csv +4 -0
- package/examples/immeuble/fake_data/meter_reading.csv +19 -0
- package/examples/immeuble/fake_data/milestone.csv +3 -0
- package/examples/immeuble/fake_data/organization.csv +12 -0
- package/examples/immeuble/fake_data/parking_space.csv +8 -0
- package/examples/immeuble/fake_data/permit.csv +3 -0
- package/examples/immeuble/fake_data/person.csv +85 -0
- package/examples/immeuble/fake_data/private_garden.csv +7 -0
- package/examples/immeuble/fake_data/progress_event.csv +2 -0
- package/examples/immeuble/fake_data/quote.csv +3 -0
- package/examples/immeuble/fake_data/receipt.csv +2 -0
- package/examples/immeuble/fake_data/reminder.csv +11 -0
- package/examples/immeuble/fake_data/service_contract.csv +4 -0
- package/examples/immeuble/fake_data/shared_equipment.csv +8 -0
- package/examples/immeuble/fake_data/shared_space.csv +10 -0
- package/examples/immeuble/fake_data/unit.csv +41 -0
- package/examples/immeuble/fake_data/work_package.csv +4 -0
- package/examples/immeuble/fake_data/worksite_project.csv +3 -0
- package/examples/immeuble/gap-rules/L0-patrimoine.json +57 -0
- package/examples/immeuble/gap-rules/L1-syndic-naive.json +36 -0
- package/examples/immeuble/gap-rules/L1-syndic.json +61 -0
- package/examples/immeuble/gap-rules/L2-chantier.json +87 -0
- package/examples/immeuble/gap-rules/L2-exploitation.json +87 -0
- package/examples/immeuble/gap-rules/L2-finance.json +48 -0
- package/examples/immeuble/gap-rules/L2-maintenance.json +107 -0
- package/examples/immeuble/gap-rules/L2-syndic-filtered.json +39 -0
- package/examples/immeuble/gap-rules/L3-full.json +332 -0
- package/examples/immeuble/gap-rules/closed-world-contract.md +76 -0
- package/examples/immeuble/gap-rules/demo.json +51 -0
- package/examples/immeuble/gap-rules/expected-findings.yaml +100 -0
- package/examples/immeuble/gap-rules/gap-scenarios.yaml +79 -0
- package/examples/immeuble/gap-rules/motifs.json +38 -0
- package/examples/immeuble/gap-rules/syndic.json +40 -0
- package/examples/immeuble/import_manifest.yaml +25 -0
- package/examples/immeuble/import_ready/graph_edges_import.csv +848 -0
- package/examples/immeuble/import_ready/mfo_facets_import.csv +559 -0
- package/examples/immeuble/index.md +140 -0
- package/examples/immeuble/model/immeuble_model.json +418 -0
- package/examples/immeuble/reports/01-model.validation.json +56 -0
- package/examples/immeuble/reports/02-mapping.validation.json +9 -0
- package/examples/immeuble/reports/acceptance.validation.json +161 -0
- package/examples/immeuble/reports/consumer_contract.validation.json +162 -0
- package/examples/immeuble/reports/graph_edges.jsonl +847 -0
- package/examples/immeuble/reports/graph_nodes.jsonl +558 -0
- package/examples/immeuble/reports/hybrid-compare.json +144 -0
- package/examples/immeuble/reports/immeuble-import-scenario.json +233 -0
- package/examples/immeuble/reports/live-artifacts-refresh.validation.json +51 -0
- package/examples/immeuble/reports/pipeline_audit.json +59 -0
- package/examples/immeuble/reports/projection_audit.json +69 -0
- package/examples/immeuble/reports/projection_audit_immeuble.json +257 -0
- package/examples/immeuble/reports/projection_audit_immeuble.md +122 -0
- package/examples/immeuble/reports/projection_candidates.json +1596 -0
- package/examples/immeuble/reports/projection_candidates.md +117 -0
- package/examples/immeuble/reports/projection_model_validation.md +115 -0
- package/examples/immeuble/reports/reindex.json +4 -0
- package/examples/immeuble/reports/reset-immeuble-workspace.json +32 -0
- package/examples/immeuble/reports/schema-id-prefix-check.json +5 -0
- package/examples/immeuble/scripts/audit-immeuble-projections.mjs +254 -0
- package/examples/immeuble/scripts/build-immeuble-model.mjs +308 -0
- package/examples/immeuble/scripts/compare-immeuble-snapshots.sh +227 -0
- package/examples/immeuble/scripts/enrich-immeuble-demo.mjs +1135 -0
- package/examples/immeuble/scripts/reset-immeuble-workspace.mjs +139 -0
- package/examples/immeuble/scripts/run-immeuble-backend.sh +164 -0
- package/examples/immeuble/scripts/run-immeuble-import.mjs +232 -0
- package/examples/immeuble/scripts/run-immeuble-live-lab.sh +439 -0
- package/examples/immeuble/scripts/seed-immeuble-gap-rules.mjs +69 -0
- package/examples/immeuble/scripts/start-immeuble-demo.sh +52 -0
- package/examples/immeuble/scripts/starterkit/analysis-lenses.mjs +181 -0
- package/examples/immeuble/scripts/starterkit/analyze-projection-candidates.mjs +714 -0
- package/examples/immeuble/scripts/starterkit/audit-ghostcrab-projections.mjs +674 -0
- package/examples/immeuble/scripts/starterkit/facet-prefix.mjs +166 -0
- package/examples/immeuble/scripts/starterkit/sqlite-utils.mjs +131 -0
- package/examples/immeuble/scripts/verify-immeuble-acceptance.mjs +284 -0
- package/examples/immeuble/scripts/verify-immeuble-live-artifacts.mjs +140 -0
- package/examples/immeuble/scripts/yaml-lite.mjs +96 -0
- package/examples/immeuble/sources/agent-prompts/prompts/00-prerequisites-immo-mcp.md +161 -0
- package/examples/immeuble/sources/agent-prompts/prompts/00-prerequisites.md +39 -0
- package/examples/immeuble/sources/agent-prompts/prompts/01-discovery-and-model-proposal.md +42 -0
- package/examples/immeuble/sources/agent-prompts/prompts/02-ontology-register.md +44 -0
- package/examples/immeuble/sources/agent-prompts/prompts/03-gap-rules-design.md +44 -0
- package/examples/immeuble/sources/agent-prompts/prompts/04-document-ingest.md +40 -0
- package/examples/immeuble/sources/agent-prompts/prompts/05-graph-extraction.md +44 -0
- package/examples/immeuble/sources/agent-prompts/prompts/06-validate-and-compare-immo-mcp.md +109 -0
- package/examples/immeuble/sources/agent-prompts/prompts/06-validate-and-compare-test-immo-mcp3.md +30 -0
- package/examples/immeuble/sources/agent-prompts/prompts/06-validate-and-compare.md +63 -0
- package/examples/immeuble/sources/checklists/gap-rules-checklist.md +42 -0
- package/examples/immeuble/sources/checklists/ontology-checklist.md +54 -0
- package/examples/immeuble/sources/documents/README.md +42 -0
- package/examples/immeuble/sources/documents/annexes-caves-garages-jardins.md +8 -0
- package/examples/immeuble/sources/documents/annexes-jardins-garages.md +1 -0
- package/examples/immeuble/sources/documents/baux-erables.md +1 -0
- package/examples/immeuble/sources/documents/baux-locatifs.md +11 -0
- package/examples/immeuble/sources/documents/coda-janvier-2026.md +10 -0
- package/examples/immeuble/sources/documents/composition-menages.md +1 -0
- package/examples/immeuble/sources/documents/composition-occupants.md +18 -0
- package/examples/immeuble/sources/documents/expected-coverage.json +70 -0
- package/examples/immeuble/sources/documents/extrait-coda-janvier-2026.md +1 -0
- package/examples/immeuble/sources/documents/groupes-facturation.md +30 -0
- package/examples/immeuble/sources/documents/manifest.json +79 -0
- package/examples/immeuble/sources/documents/note-architecte-chantier-erables.md +3 -0
- package/examples/immeuble/sources/documents/permis-urbanisme-erables.md +3 -0
- package/examples/immeuble/sources/documents/procedures-operationnelles.md +3 -0
- package/examples/immeuble/sources/documents/pv-ag-budget-2026.md +1 -0
- package/examples/immeuble/sources/documents/pv-reception-reserves-erables.md +3 -0
- package/examples/immeuble/sources/documents/registre-coproprietaires.md +24 -0
- package/examples/immeuble/sources/documents/reglement-copropriete-tilleuls.md +1 -0
- package/examples/immeuble/sources/documents/statuts-erables.md +22 -0
- package/examples/immeuble/sources/documents/statuts-tilleuls.md +19 -0
- package/examples/immeuble/sources/documents/succession-jean-dupont.md +3 -0
- package/examples/immeuble/sources/documents/titre-propriete-tilleuls-a3.md +1 -0
- package/examples/immeuble/sources/documents/trous-pedagogiques.md +3 -0
- package/examples/immeuble/sources/ontology/README.md +1 -0
- package/examples/immeuble/sources/ontology/core.yaml +444 -0
- package/examples/immeuble/success-criteria.yaml +35 -0
- package/fixtures/immeuble-demo.sqlite +0 -0
- package/package.json +16 -3
- package/scripts/lib/sqlite-runtime.mjs +1 -1
- package/scripts/load-immeuble-demo.sh +103 -0
- package/scripts/seed-immeuble-projections.mjs +75 -148
- package/scripts/verify-immeuble-demo-sources.mjs +93 -0
- package/scripts/verify-immeuble-demo.mjs +69 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js +0 -1
- package/build/client/_app/immutable/chunks/BmeSanva.js.br +0 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js.br +0 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js +0 -1
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js.br +0 -2
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js.gz +0 -0
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/_server.ts.js-Dyfsc-VA.js.map +0 -1
- package/scripts/build-serenity-v6-concept-review-pack.mjs +0 -493
- package/scripts/build-serenity-v6-review-pack.mjs +0 -479
- package/scripts/create-serenity-production-v6.mjs +0 -627
- package/scripts/export-serenity-v6-backup.mjs +0 -178
- package/scripts/import-serenity-v6-user-decisions.mjs +0 -543
- package/scripts/materialize-serenity-v6-snapshots.mjs +0 -675
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Audit GhostCrab projections, answer artifacts, and graph quality (SQLite).
|
|
4
|
+
* Port of starterkit/scripts/audit_ghostcrab_projections.py for immeuble lab.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node audit-ghostcrab-projections.mjs \
|
|
8
|
+
* --db /path/to/immeuble.sqlite \
|
|
9
|
+
* --workspace immeuble \
|
|
10
|
+
* --model ../../contracts/model_contract.json \
|
|
11
|
+
* --answer-artifacts-seed ../../contracts/answer_artifacts.seed.jsonl \
|
|
12
|
+
* [--output-dir ../../reports] \
|
|
13
|
+
* [--strict]
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join, resolve } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import {
|
|
20
|
+
buildObservedFacetIndex,
|
|
21
|
+
edgeIsObserved,
|
|
22
|
+
missingRequiredFacets,
|
|
23
|
+
normalizeEdgeType
|
|
24
|
+
} from "./facet-prefix.mjs";
|
|
25
|
+
import {
|
|
26
|
+
dtFromUnix,
|
|
27
|
+
parseArgs,
|
|
28
|
+
parseFlag,
|
|
29
|
+
parseJsonMaybe,
|
|
30
|
+
sqliteQuery,
|
|
31
|
+
sqliteTableColumns,
|
|
32
|
+
sqliteTableExists,
|
|
33
|
+
workspaceWhere
|
|
34
|
+
} from "./sqlite-utils.mjs";
|
|
35
|
+
|
|
36
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
const immeubleRoot = resolve(scriptDir, "..", "..");
|
|
38
|
+
|
|
39
|
+
const args = parseArgs(process.argv.slice(2));
|
|
40
|
+
const dbPath = resolve(parseFlag(args, "db", join(immeubleRoot, "..", "..", "..", "data", "immeuble-lab.sqlite")));
|
|
41
|
+
const workspaceId = parseFlag(args, "workspace", "immeuble") || null;
|
|
42
|
+
const modelPath = parseFlag(args, "model", join(immeubleRoot, "contracts", "model_contract.json"));
|
|
43
|
+
const seedPath = parseFlag(args, "answer-artifacts-seed", join(immeubleRoot, "contracts", "answer_artifacts.seed.jsonl"));
|
|
44
|
+
const outputDir = resolve(parseFlag(args, "output-dir", join(immeubleRoot, "reports")));
|
|
45
|
+
const strict = args.strict === "true";
|
|
46
|
+
|
|
47
|
+
function loadModelContract(path) {
|
|
48
|
+
if (!path) return {};
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
51
|
+
} catch {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function loadPlannedProjections(model, ws) {
|
|
57
|
+
if (!model || !model.projections) return [];
|
|
58
|
+
const workspace = ws || model.workspace_id || "";
|
|
59
|
+
const projections = model.projections;
|
|
60
|
+
const planned = [];
|
|
61
|
+
|
|
62
|
+
if (Array.isArray(projections)) {
|
|
63
|
+
for (const value of projections) {
|
|
64
|
+
if (!value || typeof value !== "object") continue;
|
|
65
|
+
const name = value.name || value.label || "projection";
|
|
66
|
+
const scope = value.scope || `${workspace}:catalog:${name}`;
|
|
67
|
+
planned.push({
|
|
68
|
+
workspace_id: workspace,
|
|
69
|
+
ontology: scope.split(":")[1] ?? "catalog",
|
|
70
|
+
name,
|
|
71
|
+
expected_scope: scope,
|
|
72
|
+
label: value.label || name,
|
|
73
|
+
business_question: value.business_question || "",
|
|
74
|
+
required_schemas: value.required_schemas || [],
|
|
75
|
+
required_facets: value.required_facets || [],
|
|
76
|
+
required_edges: value.required_edges || []
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return planned;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof projections === "object") {
|
|
83
|
+
for (const [name, value] of Object.entries(projections)) {
|
|
84
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
85
|
+
const scope = value.scope || `${workspace}:projection:${name}`;
|
|
86
|
+
planned.push({
|
|
87
|
+
workspace_id: workspace,
|
|
88
|
+
ontology: scope.startsWith(`${workspace}:`) ? scope.split(":")[1] : "projection",
|
|
89
|
+
name,
|
|
90
|
+
expected_scope: scope,
|
|
91
|
+
label: value.label || name,
|
|
92
|
+
business_question: value.business_question || "",
|
|
93
|
+
required_schemas: value.required_schemas || [],
|
|
94
|
+
required_facets: value.required_facets || [],
|
|
95
|
+
required_edges: value.required_edges || []
|
|
96
|
+
});
|
|
97
|
+
} else if (Array.isArray(value)) {
|
|
98
|
+
for (const item of value) {
|
|
99
|
+
planned.push({
|
|
100
|
+
workspace_id: workspace,
|
|
101
|
+
ontology: name,
|
|
102
|
+
name: String(item),
|
|
103
|
+
expected_scope: `${workspace}:${name}:${item}`,
|
|
104
|
+
label: String(item),
|
|
105
|
+
business_question: "",
|
|
106
|
+
required_schemas: [],
|
|
107
|
+
required_facets: [],
|
|
108
|
+
required_edges: []
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return planned;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function loadPlannedLiveViews(path, ws) {
|
|
118
|
+
if (!path) return [];
|
|
119
|
+
let text;
|
|
120
|
+
try {
|
|
121
|
+
text = readFileSync(path, "utf8");
|
|
122
|
+
} catch {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const planned = [];
|
|
126
|
+
for (const [lineNo, line] of text.split("\n").entries()) {
|
|
127
|
+
const trimmed = line.trim();
|
|
128
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
129
|
+
try {
|
|
130
|
+
const item = JSON.parse(trimmed);
|
|
131
|
+
const artifact = item.artifact ?? item;
|
|
132
|
+
const kind = artifact.artifact_kind || "live_answer_view";
|
|
133
|
+
if (kind !== "live_answer_view") continue;
|
|
134
|
+
const slug = artifact.slug || (artifact.artifact_id || "").split("__").pop() || `seed_${lineNo + 1}`;
|
|
135
|
+
const artifactId = artifact.artifact_id || `live_answer_view__${slug}`;
|
|
136
|
+
planned.push({
|
|
137
|
+
artifact_id: artifactId,
|
|
138
|
+
slug,
|
|
139
|
+
workspace_id: artifact.workspace_id || ws || "",
|
|
140
|
+
public_label: artifact.public_label || slug,
|
|
141
|
+
scope: artifact.scope || ""
|
|
142
|
+
});
|
|
143
|
+
} catch {
|
|
144
|
+
// skip invalid lines
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return planned;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function fetchSqlite(dbPath, workspaceId) {
|
|
151
|
+
if (!existsSync(dbPath)) {
|
|
152
|
+
return { backend: "sqlite", available: false, error: `SQLite database not found: ${dbPath}` };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let projectionTypes = [];
|
|
156
|
+
if (sqliteTableExists(dbPath, "projection_types")) {
|
|
157
|
+
projectionTypes = sqliteQuery(
|
|
158
|
+
dbPath,
|
|
159
|
+
`SELECT type_name, compatibility_aliases, rank_bias, pack_priority, next_hop_multiplier, structured
|
|
160
|
+
FROM projection_types ORDER BY pack_priority, type_name`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let projectionRows = [];
|
|
165
|
+
if (sqliteTableExists(dbPath, "projections")) {
|
|
166
|
+
let where = "";
|
|
167
|
+
if (workspaceId) {
|
|
168
|
+
where = `WHERE scope = '${workspaceId.replace(/'/g, "''")}' OR scope LIKE '${workspaceId.replace(/'/g, "''")}:%'`;
|
|
169
|
+
}
|
|
170
|
+
projectionRows = sqliteQuery(
|
|
171
|
+
dbPath,
|
|
172
|
+
`SELECT id, agent_id, scope, proj_type, content, weight, source_ref, source_type, status,
|
|
173
|
+
created_at_unix, expires_at_unix
|
|
174
|
+
FROM projections ${where}
|
|
175
|
+
ORDER BY created_at_unix DESC, scope, proj_type`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** @type {Record<string, number>} */
|
|
180
|
+
const schemaCounts = {};
|
|
181
|
+
const facetRows = [];
|
|
182
|
+
|
|
183
|
+
if (sqliteTableExists(dbPath, "facets")) {
|
|
184
|
+
const columns = sqliteTableColumns(dbPath, "facets");
|
|
185
|
+
const { where } = workspaceWhere(columns, workspaceId);
|
|
186
|
+
for (const row of sqliteQuery(dbPath, `SELECT schema_id, facets FROM facets ${where}`)) {
|
|
187
|
+
schemaCounts[String(row.schema_id)] = (schemaCounts[String(row.schema_id)] || 0) + 1;
|
|
188
|
+
facetRows.push({ schema_id: row.schema_id, facets: row.facets });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (sqliteTableExists(dbPath, "agent_facts")) {
|
|
193
|
+
const columns = sqliteTableColumns(dbPath, "agent_facts");
|
|
194
|
+
const schemaCol = columns.has("schema_id") ? "schema_id" : "NULL";
|
|
195
|
+
const facetsCol = columns.has("facets") ? "facets" : columns.has("facets_json") ? "facets_json" : "NULL";
|
|
196
|
+
const { where } = workspaceWhere(columns, workspaceId);
|
|
197
|
+
for (const row of sqliteQuery(
|
|
198
|
+
dbPath,
|
|
199
|
+
`SELECT ${schemaCol} AS schema_id, ${facetsCol} AS facets FROM agent_facts ${where}`
|
|
200
|
+
)) {
|
|
201
|
+
if (row.schema_id) {
|
|
202
|
+
schemaCounts[String(row.schema_id)] = (schemaCounts[String(row.schema_id)] || 0) + 1;
|
|
203
|
+
}
|
|
204
|
+
facetRows.push({ schema_id: row.schema_id, facets: row.facets });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const facetIndex = buildObservedFacetIndex(facetRows);
|
|
209
|
+
|
|
210
|
+
let graphEntitiesCount = 0;
|
|
211
|
+
/** @type {Array<{ type: string }>} */
|
|
212
|
+
let graphRelations = [];
|
|
213
|
+
/** @type {Array<Record<string, unknown>>} */
|
|
214
|
+
let typeBProjectionResults = [];
|
|
215
|
+
|
|
216
|
+
if (sqliteTableExists(dbPath, "graph_entity")) {
|
|
217
|
+
const columns = sqliteTableColumns(dbPath, "graph_entity");
|
|
218
|
+
const { where } = workspaceWhere(columns, workspaceId);
|
|
219
|
+
const countRow = sqliteQuery(dbPath, `SELECT COUNT(*) AS c FROM graph_entity ${where}`)[0];
|
|
220
|
+
graphEntitiesCount = Number(countRow?.c ?? 0);
|
|
221
|
+
|
|
222
|
+
const idCol = columns.has("id") ? "id" : columns.has("entity_id") ? "entity_id" : null;
|
|
223
|
+
const typeCol = columns.has("type") ? "type" : columns.has("entity_type") ? "entity_type" : null;
|
|
224
|
+
const nameCol = columns.has("name") ? "name" : idCol;
|
|
225
|
+
const metadataCol = columns.has("metadata") ? "metadata" : columns.has("metadata_json") ? "metadata_json" : null;
|
|
226
|
+
const confidenceCol = columns.has("confidence") ? "confidence" : null;
|
|
227
|
+
|
|
228
|
+
if (idCol && typeCol && nameCol) {
|
|
229
|
+
const whereParts = [`${typeCol} = 'ProjectionResult'`];
|
|
230
|
+
if (workspaceId && columns.has("workspace_id")) {
|
|
231
|
+
whereParts.push(`workspace_id = '${workspaceId.replace(/'/g, "''")}'`);
|
|
232
|
+
}
|
|
233
|
+
for (const row of sqliteQuery(
|
|
234
|
+
dbPath,
|
|
235
|
+
`SELECT ${idCol} AS id, ${typeCol} AS type, ${nameCol} AS name,
|
|
236
|
+
${metadataCol || "NULL"} AS metadata, ${confidenceCol || "NULL"} AS confidence
|
|
237
|
+
FROM graph_entity WHERE ${whereParts.join(" AND ")} ORDER BY name`
|
|
238
|
+
)) {
|
|
239
|
+
const [ok, metadata] = parseJsonMaybe(row.metadata);
|
|
240
|
+
const meta = ok && metadata && typeof metadata === "object" ? metadata : {};
|
|
241
|
+
typeBProjectionResults.push({
|
|
242
|
+
id: String(row.id),
|
|
243
|
+
type: row.type,
|
|
244
|
+
name: row.name,
|
|
245
|
+
projection_id: meta.projection_id || "",
|
|
246
|
+
collection_id: meta.collection_id || "",
|
|
247
|
+
confidence: row.confidence,
|
|
248
|
+
metadata: meta
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (sqliteTableExists(dbPath, "graph_relation")) {
|
|
255
|
+
const columns = sqliteTableColumns(dbPath, "graph_relation");
|
|
256
|
+
const { where } = workspaceWhere(columns, workspaceId);
|
|
257
|
+
const relationCol = columns.has("relation_type")
|
|
258
|
+
? "relation_type"
|
|
259
|
+
: columns.has("label")
|
|
260
|
+
? "label"
|
|
261
|
+
: columns.has("type")
|
|
262
|
+
? "type"
|
|
263
|
+
: "relation_type";
|
|
264
|
+
graphRelations = sqliteQuery(
|
|
265
|
+
dbPath,
|
|
266
|
+
`SELECT ${relationCol} AS relation_type FROM graph_relation ${where}`
|
|
267
|
+
).map((row) => ({ type: String(row.relation_type ?? "") }));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let answerArtifacts = [];
|
|
271
|
+
if (sqliteTableExists(dbPath, "mindbrain_answer_artifacts")) {
|
|
272
|
+
let where = "";
|
|
273
|
+
if (workspaceId) {
|
|
274
|
+
const ws = workspaceId.replace(/'/g, "''");
|
|
275
|
+
where = `WHERE workspace_id = '${ws}' OR (artifact_kind = 'analysis_plan' AND (scope = '${ws}' OR scope LIKE '${ws}:%'))`;
|
|
276
|
+
}
|
|
277
|
+
answerArtifacts = sqliteQuery(
|
|
278
|
+
dbPath,
|
|
279
|
+
`SELECT artifact_id, slug, workspace_id, agent_id, scope, artifact_kind,
|
|
280
|
+
public_label, lifecycle, state, current_version, legacy_ref
|
|
281
|
+
FROM mindbrain_answer_artifacts ${where}
|
|
282
|
+
ORDER BY artifact_kind, slug`
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
backend: "sqlite",
|
|
288
|
+
available: true,
|
|
289
|
+
projection_types: projectionTypes,
|
|
290
|
+
projections: projectionRows,
|
|
291
|
+
answer_artifacts: answerArtifacts,
|
|
292
|
+
schema_counts: schemaCounts,
|
|
293
|
+
facet_index: facetIndex,
|
|
294
|
+
graph: {
|
|
295
|
+
entity_count: graphEntitiesCount,
|
|
296
|
+
relation_count: graphRelations.length,
|
|
297
|
+
relations: graphRelations,
|
|
298
|
+
orphan_relation_count: 0,
|
|
299
|
+
projection_results: typeBProjectionResults
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function projectionNameFromScope(scope) {
|
|
305
|
+
if (!scope) return "";
|
|
306
|
+
return String(scope).split(":").pop() ?? "";
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function audit(dbPath, workspaceId, modelPath, seedPath) {
|
|
310
|
+
const model = loadModelContract(modelPath);
|
|
311
|
+
const planned = loadPlannedProjections(model, workspaceId);
|
|
312
|
+
const plannedLiveViews = loadPlannedLiveViews(seedPath, workspaceId);
|
|
313
|
+
const backend = fetchSqlite(dbPath, workspaceId);
|
|
314
|
+
|
|
315
|
+
const answerArtifacts = backend.answer_artifacts || [];
|
|
316
|
+
const liveViews = answerArtifacts.filter((r) => r.artifact_kind === "live_answer_view");
|
|
317
|
+
const evidencePacks = answerArtifacts.filter((r) => r.artifact_kind === "evidence_pack");
|
|
318
|
+
const registryAnalysisPlans = answerArtifacts.filter((r) => r.artifact_kind === "analysis_plan");
|
|
319
|
+
const staleLiveViews = liveViews.filter((r) => r.lifecycle === "stale");
|
|
320
|
+
const materializedLiveViewIds = new Set(liveViews.map((r) => r.artifact_id).filter(Boolean));
|
|
321
|
+
const materializedLiveViewSlugs = new Set(liveViews.map((r) => r.slug).filter(Boolean));
|
|
322
|
+
const plannedLiveMaterialized = plannedLiveViews.filter(
|
|
323
|
+
(item) => materializedLiveViewIds.has(item.artifact_id) || materializedLiveViewSlugs.has(item.slug)
|
|
324
|
+
);
|
|
325
|
+
const plannedLiveMissing = plannedLiveViews.filter((item) => !plannedLiveMaterialized.includes(item));
|
|
326
|
+
|
|
327
|
+
const now = Date.now();
|
|
328
|
+
/** @type {Record<string, unknown>[]} */
|
|
329
|
+
const projections = [];
|
|
330
|
+
const invalidJson = [];
|
|
331
|
+
const expired = [];
|
|
332
|
+
const customTypes = new Set();
|
|
333
|
+
/** @type {Record<string, number>} */
|
|
334
|
+
const scopes = {};
|
|
335
|
+
/** @type {Record<string, number>} */
|
|
336
|
+
const statuses = {};
|
|
337
|
+
/** @type {Record<string, number>} */
|
|
338
|
+
const types = {};
|
|
339
|
+
const allowedTypes = new Set(
|
|
340
|
+
(backend.projection_types || []).map((r) => r.type_name).filter(Boolean)
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
for (const row of backend.projections || []) {
|
|
344
|
+
const [okJson, parsed] = parseJsonMaybe(row.content);
|
|
345
|
+
if (!okJson) invalidJson.push(row.id);
|
|
346
|
+
if (row.expires_at_unix) {
|
|
347
|
+
const expiresAt = Number(row.expires_at_unix) * 1000;
|
|
348
|
+
if (expiresAt < now) expired.push(row.id);
|
|
349
|
+
}
|
|
350
|
+
if (allowedTypes.size && row.proj_type && !allowedTypes.has(row.proj_type)) {
|
|
351
|
+
customTypes.add(row.proj_type);
|
|
352
|
+
}
|
|
353
|
+
const scope = String(row.scope ?? "");
|
|
354
|
+
scopes[scope] = (scopes[scope] || 0) + 1;
|
|
355
|
+
statuses[String(row.status ?? "")] = (statuses[String(row.status ?? "")] || 0) + 1;
|
|
356
|
+
types[String(row.proj_type ?? "")] = (types[String(row.proj_type ?? "")] || 0) + 1;
|
|
357
|
+
|
|
358
|
+
const contentPreview =
|
|
359
|
+
typeof parsed === "object" && parsed !== null
|
|
360
|
+
? JSON.stringify(parsed).slice(0, 260)
|
|
361
|
+
: String(row.content ?? "").slice(0, 260);
|
|
362
|
+
|
|
363
|
+
projections.push({
|
|
364
|
+
id: row.id,
|
|
365
|
+
agent_id: row.agent_id,
|
|
366
|
+
scope: row.scope,
|
|
367
|
+
proj_type: row.proj_type,
|
|
368
|
+
status: row.status,
|
|
369
|
+
weight: row.weight,
|
|
370
|
+
created_at: dtFromUnix(row.created_at_unix),
|
|
371
|
+
expires_at: dtFromUnix(row.expires_at_unix),
|
|
372
|
+
content_is_json: okJson,
|
|
373
|
+
content_preview: contentPreview,
|
|
374
|
+
json_keys: parsed && typeof parsed === "object" && !Array.isArray(parsed) ? Object.keys(parsed).sort() : []
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const materializedScopes = new Set((backend.projections || []).map((r) => r.scope).filter(Boolean));
|
|
379
|
+
for (const artifact of answerArtifacts) {
|
|
380
|
+
if (artifact.scope) materializedScopes.add(String(artifact.scope));
|
|
381
|
+
if (artifact.artifact_kind === "analysis_plan" && artifact.slug) {
|
|
382
|
+
materializedScopes.add(`${workspaceId}:catalog:${artifact.slug}`);
|
|
383
|
+
materializedScopes.add(`${workspaceId}:core:${artifact.slug}`);
|
|
384
|
+
materializedScopes.add(`${workspaceId}:competency:${artifact.slug.replace(/^immeuble_/, "")}`);
|
|
385
|
+
}
|
|
386
|
+
if (artifact.artifact_kind === "live_answer_view" && artifact.slug) {
|
|
387
|
+
materializedScopes.add(`${workspaceId}:core:${artifact.slug}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
for (const item of planned) {
|
|
391
|
+
if (materializedScopes.has(item.expected_scope)) continue;
|
|
392
|
+
const slugMatch = answerArtifacts.some(
|
|
393
|
+
(artifact) =>
|
|
394
|
+
artifact.slug === item.name ||
|
|
395
|
+
artifact.artifact_id === `analysis_plan__${item.name}` ||
|
|
396
|
+
artifact.artifact_id === `live_answer_view__${item.name}`
|
|
397
|
+
);
|
|
398
|
+
if (slugMatch) materializedScopes.add(item.expected_scope);
|
|
399
|
+
}
|
|
400
|
+
const plannedMissing = planned.filter((item) => !materializedScopes.has(item.expected_scope));
|
|
401
|
+
const plannedMaterialized = planned.filter((item) => materializedScopes.has(item.expected_scope));
|
|
402
|
+
|
|
403
|
+
const typeBResults = backend.graph?.projection_results || [];
|
|
404
|
+
const typeBProjectionIds = new Set(typeBResults.map((r) => r.projection_id).filter(Boolean));
|
|
405
|
+
const plannedTypeBMaterialized = planned.filter(
|
|
406
|
+
(item) =>
|
|
407
|
+
typeBProjectionIds.has(item.name) ||
|
|
408
|
+
typeBProjectionIds.has(projectionNameFromScope(item.expected_scope))
|
|
409
|
+
);
|
|
410
|
+
const plannedTypeBMissing = planned.filter((item) => !plannedTypeBMaterialized.includes(item));
|
|
411
|
+
|
|
412
|
+
/** @type {Record<string, number>} */
|
|
413
|
+
const relationCounts = {};
|
|
414
|
+
for (const row of backend.graph?.relations || []) {
|
|
415
|
+
const key = normalizeEdgeType(row.type);
|
|
416
|
+
relationCounts[key] = (relationCounts[key] || 0) + 1;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const schemaCounts = backend.schema_counts || {};
|
|
420
|
+
const facetIndex = backend.facet_index || buildObservedFacetIndex([]);
|
|
421
|
+
|
|
422
|
+
const requiredEdges = [...new Set(planned.flatMap((item) => item.required_edges || []))].sort();
|
|
423
|
+
const requiredSchemas = [...new Set(planned.flatMap((item) => item.required_schemas || []))].sort();
|
|
424
|
+
const requiredFacets = [...new Set(planned.flatMap((item) => item.required_facets || []))].sort();
|
|
425
|
+
|
|
426
|
+
const missingRequiredEdgeTypes = requiredEdges.filter((edge) => !edgeIsObserved(edge, relationCounts));
|
|
427
|
+
const requiredSchemasWithoutRecords = requiredSchemas.filter((schema) => {
|
|
428
|
+
const prefixed = schema.includes(":") ? schema : `immeuble:core:${schema}`;
|
|
429
|
+
return !(schemaCounts[schema] > 0 || schemaCounts[prefixed] > 0);
|
|
430
|
+
});
|
|
431
|
+
const requiredFacetsNotObserved = missingRequiredFacets(requiredFacets, facetIndex);
|
|
432
|
+
|
|
433
|
+
/** @type {Record<string, Record<string, unknown>[]>} */
|
|
434
|
+
const missingByFamily = {};
|
|
435
|
+
for (const item of plannedMissing) {
|
|
436
|
+
if (!missingByFamily[item.ontology]) missingByFamily[item.ontology] = [];
|
|
437
|
+
missingByFamily[item.ontology].push(item);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const graph = backend.graph || {};
|
|
441
|
+
let qualityScore = 100;
|
|
442
|
+
qualityScore -= Math.min(30, plannedMissing.length * 3);
|
|
443
|
+
qualityScore -= Math.min(20, missingRequiredEdgeTypes.length * 2);
|
|
444
|
+
qualityScore -= Math.min(20, requiredSchemasWithoutRecords.length * 3);
|
|
445
|
+
qualityScore -= Math.min(15, requiredFacetsNotObserved.length);
|
|
446
|
+
qualityScore -= Math.min(15, invalidJson.length * 2 + expired.length + (graph.orphan_relation_count || 0));
|
|
447
|
+
qualityScore = Math.max(0, qualityScore);
|
|
448
|
+
|
|
449
|
+
return {
|
|
450
|
+
backend: backend.backend,
|
|
451
|
+
db_path: dbPath,
|
|
452
|
+
workspace_filter: workspaceId,
|
|
453
|
+
model_path: modelPath || "",
|
|
454
|
+
answer_artifacts_seed: seedPath || "",
|
|
455
|
+
generated_at: new Date().toISOString(),
|
|
456
|
+
summary: {
|
|
457
|
+
quality_score: qualityScore,
|
|
458
|
+
projection_count: projections.length,
|
|
459
|
+
analysis_plan_row_count: projections.length,
|
|
460
|
+
type_a_declared_projection_count: projections.length,
|
|
461
|
+
answer_snapshot_count: typeBResults.length,
|
|
462
|
+
type_b_projection_result_count: typeBResults.length,
|
|
463
|
+
live_answer_view_count: liveViews.length,
|
|
464
|
+
evidence_pack_count: evidencePacks.length,
|
|
465
|
+
registry_analysis_plan_count: registryAnalysisPlans.length,
|
|
466
|
+
stale_live_view_count: staleLiveViews.length,
|
|
467
|
+
planned_projection_count: planned.length,
|
|
468
|
+
planned_materialized_count: plannedMaterialized.length,
|
|
469
|
+
planned_missing_count: plannedMissing.length,
|
|
470
|
+
planned_type_a_materialized_count: plannedMaterialized.length,
|
|
471
|
+
planned_type_a_missing_count: plannedMissing.length,
|
|
472
|
+
planned_analysis_plan_materialized_count: plannedMaterialized.length,
|
|
473
|
+
planned_analysis_plan_missing_count: plannedMissing.length,
|
|
474
|
+
planned_type_b_materialized_count: plannedTypeBMaterialized.length,
|
|
475
|
+
planned_type_b_missing_count: plannedTypeBMissing.length,
|
|
476
|
+
planned_answer_snapshot_materialized_count: plannedTypeBMaterialized.length,
|
|
477
|
+
planned_answer_snapshot_missing_count: plannedTypeBMissing.length,
|
|
478
|
+
planned_live_view_count: plannedLiveViews.length,
|
|
479
|
+
planned_live_view_materialized_count: plannedLiveMaterialized.length,
|
|
480
|
+
planned_live_view_missing_count: plannedLiveMissing.length,
|
|
481
|
+
graph_entity_count: graph.entity_count || 0,
|
|
482
|
+
graph_relation_count: graph.relation_count || 0,
|
|
483
|
+
orphan_relation_count: graph.orphan_relation_count || 0,
|
|
484
|
+
required_edge_type_gap_count: missingRequiredEdgeTypes.length,
|
|
485
|
+
required_schema_record_gap_count: requiredSchemasWithoutRecords.length,
|
|
486
|
+
required_facet_observation_gap_count: requiredFacetsNotObserved.length,
|
|
487
|
+
allowed_projection_type_count: (backend.projection_types || []).length,
|
|
488
|
+
custom_projection_types: [...customTypes].sort(),
|
|
489
|
+
invalid_json_content_count: invalidJson.length,
|
|
490
|
+
expired_projection_count: expired.length,
|
|
491
|
+
observed_facet_count: facetIndex.all.size,
|
|
492
|
+
observed_prefixed_facet_count: facetIndex.prefixed.size
|
|
493
|
+
},
|
|
494
|
+
counts: {
|
|
495
|
+
by_type: Object.fromEntries(Object.entries(types).sort()),
|
|
496
|
+
by_status: Object.fromEntries(Object.entries(statuses).sort()),
|
|
497
|
+
by_scope: Object.fromEntries(Object.entries(scopes).sort()),
|
|
498
|
+
graph_relations_by_type: Object.fromEntries(Object.entries(relationCounts).sort()),
|
|
499
|
+
facets_by_schema: Object.fromEntries(Object.entries(schemaCounts).sort())
|
|
500
|
+
},
|
|
501
|
+
allowed_projection_types: backend.projection_types || [],
|
|
502
|
+
projections,
|
|
503
|
+
answer_artifacts: answerArtifacts,
|
|
504
|
+
type_b_projection_results: typeBResults,
|
|
505
|
+
quality_flags: {
|
|
506
|
+
invalid_json_projection_ids: invalidJson,
|
|
507
|
+
expired_projection_ids: expired,
|
|
508
|
+
custom_projection_types_not_registered: [...customTypes].sort(),
|
|
509
|
+
stale_live_answer_view_ids: staleLiveViews.map((r) => r.artifact_id).filter(Boolean),
|
|
510
|
+
missing_required_edge_types: missingRequiredEdgeTypes,
|
|
511
|
+
required_schemas_without_records: requiredSchemasWithoutRecords,
|
|
512
|
+
required_facets_not_observed: requiredFacetsNotObserved,
|
|
513
|
+
orphan_relation_count: graph.orphan_relation_count || 0
|
|
514
|
+
},
|
|
515
|
+
planned_projection_gap: {
|
|
516
|
+
mode: "analysis_plan",
|
|
517
|
+
legacy_mode: "type_a_declared_projections",
|
|
518
|
+
planned_count: planned.length,
|
|
519
|
+
materialized_count: plannedMaterialized.length,
|
|
520
|
+
missing_count: plannedMissing.length,
|
|
521
|
+
missing_by_ontology: Object.fromEntries(Object.entries(missingByFamily).sort())
|
|
522
|
+
},
|
|
523
|
+
analysis_plan_gap: {
|
|
524
|
+
mode: "analysis_plan",
|
|
525
|
+
planned_count: planned.length,
|
|
526
|
+
materialized_count: plannedMaterialized.length,
|
|
527
|
+
missing_count: plannedMissing.length,
|
|
528
|
+
missing_by_ontology: Object.fromEntries(Object.entries(missingByFamily).sort())
|
|
529
|
+
},
|
|
530
|
+
type_b_projection_result_gap: {
|
|
531
|
+
mode: "answer_snapshot",
|
|
532
|
+
legacy_mode: "type_b_graph_projection_results",
|
|
533
|
+
planned_count: planned.length,
|
|
534
|
+
materialized_count: plannedTypeBMaterialized.length,
|
|
535
|
+
missing_count: plannedTypeBMissing.length,
|
|
536
|
+
available_projection_ids: [...typeBProjectionIds].sort(),
|
|
537
|
+
missing_projection_ids: plannedTypeBMissing.map((item) => item.name)
|
|
538
|
+
},
|
|
539
|
+
answer_snapshot_gap: {
|
|
540
|
+
mode: "answer_snapshot",
|
|
541
|
+
planned_count: planned.length,
|
|
542
|
+
materialized_count: plannedTypeBMaterialized.length,
|
|
543
|
+
missing_count: plannedTypeBMissing.length,
|
|
544
|
+
available_projection_ids: [...typeBProjectionIds].sort(),
|
|
545
|
+
missing_projection_ids: plannedTypeBMissing.map((item) => item.name)
|
|
546
|
+
},
|
|
547
|
+
live_answer_view_gap: {
|
|
548
|
+
mode: "live_answer_view",
|
|
549
|
+
planned_count: plannedLiveViews.length,
|
|
550
|
+
materialized_count: plannedLiveMaterialized.length,
|
|
551
|
+
missing_count: plannedLiveMissing.length,
|
|
552
|
+
missing_artifact_ids: plannedLiveMissing.map((item) => item.artifact_id),
|
|
553
|
+
note: "stale live_answer_view after import is expected until gcp brain artifact refresh"
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function writeMarkdown(report, path) {
|
|
559
|
+
const lines = [
|
|
560
|
+
"# GhostCrab Projection and Graph Audit",
|
|
561
|
+
"",
|
|
562
|
+
`- Backend: \`${report.backend}\``,
|
|
563
|
+
`- DB: \`${report.db_path}\``,
|
|
564
|
+
`- Workspace filter: \`${report.workspace_filter || "all"}\``,
|
|
565
|
+
`- Model: \`${report.model_path || "n/a"}\``,
|
|
566
|
+
`- Answer artifacts seed: \`${report.answer_artifacts_seed || "n/a"}\``,
|
|
567
|
+
`- Generated at: \`${report.generated_at}\``,
|
|
568
|
+
"",
|
|
569
|
+
"## Summary",
|
|
570
|
+
""
|
|
571
|
+
];
|
|
572
|
+
for (const [key, value] of Object.entries(report.summary)) {
|
|
573
|
+
lines.push(`- \`${key}\`: ${value}`);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
lines.push(
|
|
577
|
+
"",
|
|
578
|
+
"## Answer artifact taxonomy",
|
|
579
|
+
"",
|
|
580
|
+
"| `artifact_kind` | Storage | Legacy |",
|
|
581
|
+
"|-----------------|---------|--------|",
|
|
582
|
+
"| `analysis_plan` | `projections` | Type A |",
|
|
583
|
+
"| `live_answer_view` | `mindbrain_answer_artifacts` | *(new)* |",
|
|
584
|
+
"| `answer_snapshot` | `graph_entity` (`ProjectionResult`) | Type B |",
|
|
585
|
+
"| `evidence_pack` | `mindbrain_answer_artifacts` | evidence links |",
|
|
586
|
+
"",
|
|
587
|
+
"## Personal operator commands",
|
|
588
|
+
"",
|
|
589
|
+
"```bash",
|
|
590
|
+
`gcp brain artifact list --workspace-id ${report.workspace_filter || "<ws>"} --kind analysis_plan`,
|
|
591
|
+
`gcp brain artifact list --workspace-id ${report.workspace_filter || "<ws>"} --kind live_answer_view`,
|
|
592
|
+
"gcp brain artifact refresh live_answer_view__<slug>",
|
|
593
|
+
"```"
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
lines.push("", "## Quality Flags", "");
|
|
597
|
+
for (const [key, value] of Object.entries(report.quality_flags)) {
|
|
598
|
+
const rendered = Array.isArray(value) && value.length ? value.map((v) => `\`${v}\``).join(", ") : value;
|
|
599
|
+
lines.push(`- \`${key}\`: ${rendered || "n/a"}`);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
lines.push("", "## Graph Relation Coverage", "");
|
|
603
|
+
for (const [key, value] of Object.entries(report.counts.graph_relations_by_type || {})) {
|
|
604
|
+
lines.push(`- \`${key}\`: ${value}`);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
lines.push("", "## analysis_plan rows (projections table)", "");
|
|
608
|
+
for (const item of report.projections) {
|
|
609
|
+
lines.push(
|
|
610
|
+
`- \`${item.scope || "(no scope)"}\` | \`${item.proj_type}\` | \`${item.status}\` | \`${item.agent_id}\``
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
lines.push("", "## Answer artifacts (mindbrain_answer_artifacts)", "");
|
|
615
|
+
if (report.answer_artifacts?.length) {
|
|
616
|
+
for (const item of report.answer_artifacts) {
|
|
617
|
+
lines.push(
|
|
618
|
+
`- \`${item.artifact_id}\` | \`${item.artifact_kind}\` | \`${item.lifecycle}\` | \`${item.state}\` | v${item.current_version}`
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
} else {
|
|
622
|
+
lines.push("- n/a (table missing or empty)");
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const analysisGap = report.analysis_plan_gap || report.planned_projection_gap;
|
|
626
|
+
lines.push("", "## Planned analysis_plan gap", "");
|
|
627
|
+
lines.push(`- Planned: ${analysisGap.planned_count}`);
|
|
628
|
+
lines.push(`- Materialized: ${analysisGap.materialized_count}`);
|
|
629
|
+
lines.push(`- Missing: ${analysisGap.missing_count}`);
|
|
630
|
+
|
|
631
|
+
const liveGap = report.live_answer_view_gap || {};
|
|
632
|
+
if (liveGap.planned_count) {
|
|
633
|
+
lines.push("", "## Planned live_answer_view gap", "");
|
|
634
|
+
lines.push(`- Planned: ${liveGap.planned_count}`);
|
|
635
|
+
lines.push(`- Materialized: ${liveGap.materialized_count}`);
|
|
636
|
+
lines.push(`- Missing: ${liveGap.missing_count}`);
|
|
637
|
+
if (liveGap.note) lines.push(`- Note: ${liveGap.note}`);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
writeFileSync(path, lines.join("\n") + "\n", "utf8");
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function strictAuditFailed(report) {
|
|
644
|
+
const flags = report.quality_flags;
|
|
645
|
+
return (
|
|
646
|
+
report.summary.planned_missing_count > 0 ||
|
|
647
|
+
flags.missing_required_edge_types.length > 0 ||
|
|
648
|
+
flags.required_schemas_without_records.length > 0 ||
|
|
649
|
+
flags.required_facets_not_observed.length > 0
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function main() {
|
|
654
|
+
const report = audit(dbPath, workspaceId, modelPath, seedPath);
|
|
655
|
+
mkdirSync(outputDir, { recursive: true });
|
|
656
|
+
const suffix = workspaceId || "all";
|
|
657
|
+
const jsonPath = join(outputDir, `projection_audit_${suffix}.json`);
|
|
658
|
+
const mdPath = join(outputDir, `projection_audit_${suffix}.md`);
|
|
659
|
+
writeFileSync(jsonPath, JSON.stringify(report, null, 2) + "\n", "utf8");
|
|
660
|
+
writeMarkdown(report, mdPath);
|
|
661
|
+
|
|
662
|
+
const output = {
|
|
663
|
+
json: jsonPath,
|
|
664
|
+
markdown: mdPath,
|
|
665
|
+
summary: report.summary,
|
|
666
|
+
ok: !strict || !strictAuditFailed(report)
|
|
667
|
+
};
|
|
668
|
+
console.log(JSON.stringify(output, null, 2));
|
|
669
|
+
if (strict && strictAuditFailed(report)) {
|
|
670
|
+
process.exit(1);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
main();
|