@yss123/cage-cli 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +40 -2
- package/bin/cage.js +6 -0
- package/bin/create-cage-app.js +6 -0
- package/dist/analyze.d.ts +18 -0
- package/dist/analyze.js +28 -0
- package/dist/analyze.js.map +1 -0
- package/dist/baseline.d.ts +5 -0
- package/dist/baseline.js +50 -0
- package/dist/baseline.js.map +1 -0
- package/dist/budget.d.ts +7 -0
- package/dist/budget.js +52 -0
- package/dist/budget.js.map +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +72 -0
- package/dist/context.js +202 -0
- package/dist/context.js.map +1 -0
- package/dist/create-prompt.d.ts +5 -0
- package/dist/create-prompt.js +50 -0
- package/dist/create-prompt.js.map +1 -0
- package/dist/create.d.ts +18 -0
- package/dist/create.js +64 -0
- package/dist/create.js.map +1 -0
- package/dist/derive.d.ts +14 -0
- package/dist/derive.js +163 -0
- package/dist/derive.js.map +1 -0
- package/dist/dev.d.ts +2 -0
- package/dist/dev.js +116 -0
- package/dist/dev.js.map +1 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.js +15 -0
- package/dist/env.js.map +1 -0
- package/dist/findings.d.ts +11 -0
- package/dist/findings.js +13 -0
- package/dist/findings.js.map +1 -0
- package/dist/gen/contracts.d.ts +6 -0
- package/dist/gen/contracts.js +188 -0
- package/dist/gen/contracts.js.map +1 -0
- package/dist/gen/index.d.ts +19 -0
- package/dist/gen/index.js +177 -0
- package/dist/gen/index.js.map +1 -0
- package/dist/gen/zod-code.d.ts +7 -0
- package/dist/gen/zod-code.js +163 -0
- package/dist/gen/zod-code.js.map +1 -0
- package/dist/graph-command.d.ts +11 -0
- package/dist/graph-command.js +67 -0
- package/dist/graph-command.js.map +1 -0
- package/dist/graph-model.d.ts +21 -0
- package/dist/graph-model.js +101 -0
- package/dist/graph-model.js.map +1 -0
- package/dist/graph-presentation.d.ts +11 -0
- package/dist/graph-presentation.js +25 -0
- package/dist/graph-presentation.js.map +1 -0
- package/dist/graph-query.d.ts +171 -0
- package/dist/graph-query.js +242 -0
- package/dist/graph-query.js.map +1 -0
- package/dist/graph-relations.d.ts +14 -0
- package/dist/graph-relations.js +142 -0
- package/dist/graph-relations.js.map +1 -0
- package/dist/graph-search.d.ts +21 -0
- package/dist/graph-search.js +63 -0
- package/dist/graph-search.js.map +1 -0
- package/dist/graph-snapshot.d.ts +11 -0
- package/dist/graph-snapshot.js +29 -0
- package/dist/graph-snapshot.js.map +1 -0
- package/dist/graph.d.ts +11 -0
- package/dist/graph.js +105 -0
- package/dist/graph.js.map +1 -0
- package/dist/impact.d.ts +34 -0
- package/dist/impact.js +235 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +6 -0
- package/dist/init.js +131 -0
- package/dist/init.js.map +1 -0
- package/dist/load.d.ts +6 -0
- package/dist/load.js +17 -0
- package/dist/load.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +221 -0
- package/dist/main.js.map +1 -0
- package/dist/migrate.d.ts +4 -0
- package/dist/migrate.js +30 -0
- package/dist/migrate.js.map +1 -0
- package/dist/ontology.d.ts +43 -0
- package/dist/ontology.js +280 -0
- package/dist/ontology.js.map +1 -0
- package/dist/process.d.ts +6 -0
- package/dist/process.js +39 -0
- package/dist/process.js.map +1 -0
- package/dist/project-structure.d.ts +8 -0
- package/dist/project-structure.js +94 -0
- package/dist/project-structure.js.map +1 -0
- package/dist/rules.d.ts +23 -0
- package/dist/rules.js +251 -0
- package/dist/rules.js.map +1 -0
- package/dist/static-check.d.ts +23 -0
- package/dist/static-check.js +222 -0
- package/dist/static-check.js.map +1 -0
- package/dist/sync.d.ts +5 -0
- package/dist/sync.js +118 -0
- package/dist/sync.js.map +1 -0
- package/dist/upgrade.d.ts +10 -0
- package/dist/upgrade.js +81 -0
- package/dist/upgrade.js.map +1 -0
- package/dist/verify.d.ts +7 -0
- package/dist/verify.js +88 -0
- package/dist/verify.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/graph-ui/app.js +1103 -0
- package/graph-ui/graph-model.js +100 -0
- package/graph-ui/graph-relations.js +141 -0
- package/graph-ui/graph-search.js +62 -0
- package/graph-ui/index.html +197 -0
- package/graph-ui/model.js +83 -0
- package/graph-ui/relations.js +2 -0
- package/graph-ui/structure.js +77 -0
- package/graph-ui/style.css +1719 -0
- package/package.json +60 -3
- package/templates/app/.dockerignore +10 -0
- package/templates/app/.env.example +61 -0
- package/templates/app/.github/workflows/cage.yml +44 -0
- package/templates/app/AGENTS.md +96 -0
- package/templates/app/Dockerfile +25 -0
- package/templates/app/README.md +88 -0
- package/templates/app/_gitignore +8 -0
- package/templates/app/apps/api/package.json +16 -0
- package/templates/app/apps/api/src/main.ts +10 -0
- package/templates/app/apps/api/src/worker.ts +14 -0
- package/templates/app/apps/api/tsconfig.json +5 -0
- package/templates/app/apps/web/index.html +13 -0
- package/templates/app/apps/web/package.json +22 -0
- package/templates/app/apps/web/src/app/app.tsx +18 -0
- package/templates/app/apps/web/src/app/styles/global.css +663 -0
- package/templates/app/apps/web/src/app/workspace-layout.tsx +70 -0
- package/templates/app/apps/web/src/main.tsx +13 -0
- package/templates/app/apps/web/src/modules/approval/hooks/use-approval-tasks.ts +20 -0
- package/templates/app/apps/web/src/modules/approval/index.ts +2 -0
- package/templates/app/apps/web/src/modules/approval/pages/approval-tasks-page.tsx +54 -0
- package/templates/app/apps/web/src/modules/auth/index.ts +1 -0
- package/templates/app/apps/web/src/modules/auth/pages/login-page.tsx +59 -0
- package/templates/app/apps/web/src/modules/inventory/index.ts +1 -0
- package/templates/app/apps/web/src/modules/inventory/pages/inventory-page.tsx +74 -0
- package/templates/app/apps/web/src/modules/purchase/components/purchase-order-form.tsx +60 -0
- package/templates/app/apps/web/src/modules/purchase/index.ts +2 -0
- package/templates/app/apps/web/src/modules/purchase/pages/purchase-orders-page.tsx +210 -0
- package/templates/app/apps/web/src/shared/hooks/use-command.ts +29 -0
- package/templates/app/apps/web/src/shared/lib/error-message.ts +15 -0
- package/templates/app/apps/web/src/shared/ui/notice.tsx +13 -0
- package/templates/app/apps/web/src/shared/ui/page-heading.tsx +28 -0
- package/templates/app/apps/web/tsconfig.json +11 -0
- package/templates/app/apps/web/vite.config.ts +19 -0
- package/templates/app/cage.config.json +114 -0
- package/templates/app/db/migrations/0001_init.sql +112 -0
- package/templates/app/docs/ai/README.md +77 -0
- package/templates/app/docs/ai/architecture.md +122 -0
- package/templates/app/docs/ai/ontology-context.md +117 -0
- package/templates/app/docs/ai/primitives.md +249 -0
- package/templates/app/docs/ai/project-structure.md +123 -0
- package/templates/app/docs/ai/purchase-example.md +97 -0
- package/templates/app/docs/ai/recipes.md +81 -0
- package/templates/app/docs/ai/relations.md +160 -0
- package/templates/app/docs/ai/transfers.md +92 -0
- package/templates/app/docs/ai/troubleshooting.md +60 -0
- package/templates/app/docs/ai/workflow.md +139 -0
- package/templates/app/docs/errors/CAGE-APPR-001.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-002.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-003.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-004.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-005.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-006.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-007.md +50 -0
- package/templates/app/docs/errors/CAGE-APPR-010.md +48 -0
- package/templates/app/docs/errors/CAGE-AUTH-001.md +47 -0
- package/templates/app/docs/errors/CAGE-BUDGET-001.md +47 -0
- package/templates/app/docs/errors/CAGE-BUDGET-002.md +47 -0
- package/templates/app/docs/errors/CAGE-BUDGET-003.md +47 -0
- package/templates/app/docs/errors/CAGE-CMD-002.md +47 -0
- package/templates/app/docs/errors/CAGE-CMD-003.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-001.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-002.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-003.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-004.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-005.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-006.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-007.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-008.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-009.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-010.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-011.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-012.md +47 -0
- package/templates/app/docs/errors/CAGE-CREATE-001.md +52 -0
- package/templates/app/docs/errors/CAGE-DECL-001.md +48 -0
- package/templates/app/docs/errors/CAGE-DECL-002.md +47 -0
- package/templates/app/docs/errors/CAGE-DECL-003.md +47 -0
- package/templates/app/docs/errors/CAGE-DECL-004.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-001.md +48 -0
- package/templates/app/docs/errors/CAGE-DEP-002.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-003.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-004.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-005.md +47 -0
- package/templates/app/docs/errors/CAGE-DLQ-001.md +48 -0
- package/templates/app/docs/errors/CAGE-ENV-001.md +52 -0
- package/templates/app/docs/errors/CAGE-EVENT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-EVENT-002.md +50 -0
- package/templates/app/docs/errors/CAGE-FIELD-001.md +47 -0
- package/templates/app/docs/errors/CAGE-FIELD-002.md +47 -0
- package/templates/app/docs/errors/CAGE-FIELD-003.md +47 -0
- package/templates/app/docs/errors/CAGE-FIELD-004.md +47 -0
- package/templates/app/docs/errors/CAGE-GEN-001.md +48 -0
- package/templates/app/docs/errors/CAGE-GEN-002.md +47 -0
- package/templates/app/docs/errors/CAGE-GRANT-001.md +49 -0
- package/templates/app/docs/errors/CAGE-GRANT-002.md +48 -0
- package/templates/app/docs/errors/CAGE-GRANT-003.md +47 -0
- package/templates/app/docs/errors/CAGE-IMPACT-001.md +48 -0
- package/templates/app/docs/errors/CAGE-INIT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-INIT-002.md +49 -0
- package/templates/app/docs/errors/CAGE-INIT-003.md +48 -0
- package/templates/app/docs/errors/CAGE-INIT-004.md +48 -0
- package/templates/app/docs/errors/CAGE-JOB-001.md +47 -0
- package/templates/app/docs/errors/CAGE-JOB-002.md +47 -0
- package/templates/app/docs/errors/CAGE-JOB-003.md +47 -0
- package/templates/app/docs/errors/CAGE-LINT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-MIG-001.md +47 -0
- package/templates/app/docs/errors/CAGE-MIG-002.md +47 -0
- package/templates/app/docs/errors/CAGE-MIG-003.md +5 -0
- package/templates/app/docs/errors/CAGE-MIG-004.md +5 -0
- package/templates/app/docs/errors/CAGE-MIG-005.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-001.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-002.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-003.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-004.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-005.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-006.md +47 -0
- package/templates/app/docs/errors/CAGE-ORG-001.md +49 -0
- package/templates/app/docs/errors/CAGE-PAIR-002.md +50 -0
- package/templates/app/docs/errors/CAGE-QUERY-001.md +47 -0
- package/templates/app/docs/errors/CAGE-QUERY-002.md +47 -0
- package/templates/app/docs/errors/CAGE-QUERY-003.md +49 -0
- package/templates/app/docs/errors/CAGE-REACT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-REACT-002.md +47 -0
- package/templates/app/docs/errors/CAGE-READS-001.md +47 -0
- package/templates/app/docs/errors/CAGE-REG-001.md +53 -0
- package/templates/app/docs/errors/CAGE-REG-002.md +48 -0
- package/templates/app/docs/errors/CAGE-REG-003.md +47 -0
- package/templates/app/docs/errors/CAGE-REL-001.md +64 -0
- package/templates/app/docs/errors/CAGE-ROUTE-001.md +47 -0
- package/templates/app/docs/errors/CAGE-SCOPE-001.md +47 -0
- package/templates/app/docs/errors/CAGE-SCOPE-002.md +47 -0
- package/templates/app/docs/errors/CAGE-SECRET-001.md +48 -0
- package/templates/app/docs/errors/CAGE-SECRET-002.md +47 -0
- package/templates/app/docs/errors/CAGE-SENS-001.md +48 -0
- package/templates/app/docs/errors/CAGE-SQL-001.md +47 -0
- package/templates/app/docs/errors/CAGE-SQL-002.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-001.md +49 -0
- package/templates/app/docs/errors/CAGE-STATE-002.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-003.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-004.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-005.md +48 -0
- package/templates/app/docs/errors/CAGE-STATE-010.md +48 -0
- package/templates/app/docs/errors/CAGE-STATE-011.md +48 -0
- package/templates/app/docs/errors/CAGE-STRUCT-001.md +51 -0
- package/templates/app/docs/errors/CAGE-STRUCT-002.md +51 -0
- package/templates/app/docs/errors/CAGE-SYNC-001.md +48 -0
- package/templates/app/docs/errors/CAGE-TEST-001.md +47 -0
- package/templates/app/docs/errors/CAGE-UNSAFE-001.md +48 -0
- package/templates/app/docs/errors/CAGE-UPGRADE-001.md +48 -0
- package/templates/app/docs/errors/README.md +307 -0
- package/templates/app/docs/errors/runtime.md +50 -0
- package/templates/app/package.json +22 -0
- package/templates/app/packages/contracts/package.json +16 -0
- package/templates/app/packages/contracts/src/aggregates/dept/index.ts +74 -0
- package/templates/app/packages/contracts/src/aggregates/inventory/index.ts +57 -0
- package/templates/app/packages/contracts/src/aggregates/inventory-lock/index.ts +52 -0
- package/templates/app/packages/contracts/src/aggregates/purchase-order/index.ts +72 -0
- package/templates/app/packages/contracts/src/aggregates/role/index.ts +85 -0
- package/templates/app/packages/contracts/src/aggregates/user/index.ts +89 -0
- package/templates/app/packages/contracts/src/index.ts +81 -0
- package/templates/app/packages/contracts/src/queries/index.ts +17 -0
- package/templates/app/packages/contracts/tsconfig.json +5 -0
- package/templates/app/packages/domain/package.json +23 -0
- package/templates/app/packages/domain/src/index.ts +6 -0
- package/templates/app/packages/domain/src/integrations/erp.ts +36 -0
- package/templates/app/packages/domain/src/modules/inventory/index.ts +2 -0
- package/templates/app/packages/domain/src/modules/inventory/inventory.ts +43 -0
- package/templates/app/packages/domain/src/modules/purchase/approvals.ts +18 -0
- package/templates/app/packages/domain/src/modules/purchase/index.ts +6 -0
- package/templates/app/packages/domain/src/modules/purchase/jobs.ts +13 -0
- package/templates/app/packages/domain/src/modules/purchase/purchase-order.test.ts +137 -0
- package/templates/app/packages/domain/src/modules/purchase/purchase-order.ts +122 -0
- package/templates/app/packages/domain/src/modules/purchase/queries.ts +10 -0
- package/templates/app/packages/domain/src/workflows/purchase-inventory.ts +24 -0
- package/templates/app/packages/domain/tsconfig.json +5 -0
- package/templates/app/pnpm-workspace.yaml +10 -0
- package/templates/app/renovate.json +5 -0
- package/templates/app/tsconfig.base.json +8 -0
- package/templates/blank/.dockerignore +10 -0
- package/templates/blank/.env.example +61 -0
- package/templates/blank/.github/workflows/cage.yml +44 -0
- package/templates/blank/AGENTS.md +96 -0
- package/templates/blank/Dockerfile +25 -0
- package/templates/blank/README.md +37 -0
- package/templates/blank/_gitignore +8 -0
- package/templates/blank/apps/api/package.json +15 -0
- package/templates/blank/apps/api/src/main.ts +11 -0
- package/templates/blank/apps/api/src/worker.ts +8 -0
- package/templates/blank/apps/api/tsconfig.json +5 -0
- package/templates/blank/apps/web/index.html +13 -0
- package/templates/blank/apps/web/package.json +22 -0
- package/templates/blank/apps/web/src/app/app.tsx +44 -0
- package/templates/blank/apps/web/src/app/styles/global.css +516 -0
- package/templates/blank/apps/web/src/app/workspace-layout.tsx +70 -0
- package/templates/blank/apps/web/src/main.tsx +13 -0
- package/templates/blank/apps/web/src/modules/auth/index.ts +1 -0
- package/templates/blank/apps/web/src/modules/auth/pages/login-page.tsx +87 -0
- package/templates/blank/apps/web/src/modules/workspace/index.ts +1 -0
- package/templates/blank/apps/web/src/modules/workspace/pages/home-page.tsx +45 -0
- package/templates/blank/apps/web/src/shared/lib/error-message.ts +11 -0
- package/templates/blank/apps/web/src/shared/ui/brand.tsx +11 -0
- package/templates/blank/apps/web/tsconfig.json +11 -0
- package/templates/blank/apps/web/vite.config.ts +19 -0
- package/templates/blank/cage.config.json +14 -0
- package/templates/blank/db/migrations/0001_init.sql +63 -0
- package/templates/blank/docs/ai/README.md +77 -0
- package/templates/blank/docs/ai/architecture.md +122 -0
- package/templates/blank/docs/ai/ontology-context.md +117 -0
- package/templates/blank/docs/ai/primitives.md +249 -0
- package/templates/blank/docs/ai/project-structure.md +123 -0
- package/templates/blank/docs/ai/purchase-example.md +97 -0
- package/templates/blank/docs/ai/recipes.md +81 -0
- package/templates/blank/docs/ai/relations.md +160 -0
- package/templates/blank/docs/ai/transfers.md +92 -0
- package/templates/blank/docs/ai/troubleshooting.md +60 -0
- package/templates/blank/docs/ai/workflow.md +139 -0
- package/templates/blank/docs/errors/CAGE-APPR-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-006.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-007.md +50 -0
- package/templates/blank/docs/errors/CAGE-APPR-010.md +48 -0
- package/templates/blank/docs/errors/CAGE-AUTH-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-BUDGET-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-BUDGET-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-BUDGET-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-CMD-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-CMD-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-006.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-007.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-008.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-009.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-010.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-011.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-012.md +47 -0
- package/templates/blank/docs/errors/CAGE-CREATE-001.md +52 -0
- package/templates/blank/docs/errors/CAGE-DECL-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-DECL-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-DECL-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-DECL-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-DEP-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-DLQ-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-ENV-001.md +52 -0
- package/templates/blank/docs/errors/CAGE-EVENT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-EVENT-002.md +50 -0
- package/templates/blank/docs/errors/CAGE-FIELD-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-FIELD-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-FIELD-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-FIELD-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-GEN-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-GEN-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-GRANT-001.md +49 -0
- package/templates/blank/docs/errors/CAGE-GRANT-002.md +48 -0
- package/templates/blank/docs/errors/CAGE-GRANT-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-IMPACT-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-INIT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-INIT-002.md +49 -0
- package/templates/blank/docs/errors/CAGE-INIT-003.md +48 -0
- package/templates/blank/docs/errors/CAGE-INIT-004.md +48 -0
- package/templates/blank/docs/errors/CAGE-JOB-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-JOB-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-JOB-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-LINT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-MIG-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-MIG-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-MIG-003.md +5 -0
- package/templates/blank/docs/errors/CAGE-MIG-004.md +5 -0
- package/templates/blank/docs/errors/CAGE-MIG-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-006.md +47 -0
- package/templates/blank/docs/errors/CAGE-ORG-001.md +49 -0
- package/templates/blank/docs/errors/CAGE-PAIR-002.md +50 -0
- package/templates/blank/docs/errors/CAGE-QUERY-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-QUERY-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-QUERY-003.md +49 -0
- package/templates/blank/docs/errors/CAGE-REACT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-REACT-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-READS-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-REG-001.md +53 -0
- package/templates/blank/docs/errors/CAGE-REG-002.md +48 -0
- package/templates/blank/docs/errors/CAGE-REG-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-REL-001.md +64 -0
- package/templates/blank/docs/errors/CAGE-ROUTE-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-SCOPE-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-SCOPE-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-SECRET-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-SECRET-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-SENS-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-SQL-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-SQL-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-001.md +49 -0
- package/templates/blank/docs/errors/CAGE-STATE-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-005.md +48 -0
- package/templates/blank/docs/errors/CAGE-STATE-010.md +48 -0
- package/templates/blank/docs/errors/CAGE-STATE-011.md +48 -0
- package/templates/blank/docs/errors/CAGE-STRUCT-001.md +51 -0
- package/templates/blank/docs/errors/CAGE-STRUCT-002.md +51 -0
- package/templates/blank/docs/errors/CAGE-SYNC-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-TEST-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-UNSAFE-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-UPGRADE-001.md +48 -0
- package/templates/blank/docs/errors/README.md +307 -0
- package/templates/blank/docs/errors/runtime.md +50 -0
- package/templates/blank/docs/examples/purchase-admin/README.md +5 -0
- package/templates/blank/docs/examples/purchase-admin/apps/api/src/main.ts +10 -0
- package/templates/blank/docs/examples/purchase-admin/apps/api/src/worker.ts +14 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/app/app.tsx +18 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/app/styles/global.css +663 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/app/workspace-layout.tsx +70 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/main.tsx +13 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/approval/hooks/use-approval-tasks.ts +20 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/approval/index.ts +2 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/approval/pages/approval-tasks-page.tsx +54 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/auth/index.ts +1 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/auth/pages/login-page.tsx +59 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/inventory/index.ts +1 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/inventory/pages/inventory-page.tsx +74 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/purchase/components/purchase-order-form.tsx +60 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/purchase/index.ts +2 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/purchase/pages/purchase-orders-page.tsx +210 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/hooks/use-command.ts +29 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/lib/error-message.ts +15 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/ui/notice.tsx +13 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/ui/page-heading.tsx +28 -0
- package/templates/blank/docs/examples/purchase-admin/cage.config.json +114 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/dept/index.ts +74 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/inventory/index.ts +57 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/inventory-lock/index.ts +52 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/purchase-order/index.ts +72 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/role/index.ts +85 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/user/index.ts +89 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/index.ts +81 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/queries/index.ts +17 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/index.ts +6 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/integrations/erp.ts +36 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/inventory/index.ts +2 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/inventory/inventory.ts +43 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/approvals.ts +18 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/index.ts +6 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/jobs.ts +13 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/purchase-order.test.ts +137 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/purchase-order.ts +122 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/queries.ts +10 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/workflows/purchase-inventory.ts +24 -0
- package/templates/blank/package.json +22 -0
- package/templates/blank/packages/contracts/package.json +16 -0
- package/templates/blank/packages/contracts/src/aggregates/dept/index.ts +74 -0
- package/templates/blank/packages/contracts/src/aggregates/role/index.ts +85 -0
- package/templates/blank/packages/contracts/src/aggregates/user/index.ts +89 -0
- package/templates/blank/packages/contracts/src/index.ts +55 -0
- package/templates/blank/packages/contracts/src/queries/index.ts +13 -0
- package/templates/blank/packages/contracts/tsconfig.json +5 -0
- package/templates/blank/packages/domain/package.json +23 -0
- package/templates/blank/packages/domain/src/index.ts +4 -0
- package/templates/blank/packages/domain/tsconfig.json +5 -0
- package/templates/blank/pnpm-workspace.yaml +10 -0
- package/templates/blank/renovate.json +5 -0
- package/templates/blank/tsconfig.base.json +8 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// CLI 负责参数和输出;查询函数本身可组合,Web 和其他工具无需再解析终端文本。
|
|
2
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { abs } from './config.js';
|
|
5
|
+
import { errorsOnly } from './findings.js';
|
|
6
|
+
import { collectGraph } from './graph.js';
|
|
7
|
+
import { kindLabels } from './graph-model.js';
|
|
8
|
+
import { searchGraph, inspectGraph, findGraphPath, formatGraphQuery } from './graph-query.js';
|
|
9
|
+
import { buildContext, formatContext } from './context.js';
|
|
10
|
+
function integerOption(name, raw, fallback, minimum) {
|
|
11
|
+
if (raw === undefined)
|
|
12
|
+
return fallback;
|
|
13
|
+
const value = Number(raw);
|
|
14
|
+
if (!raw.trim() || !Number.isSafeInteger(value) || value < minimum)
|
|
15
|
+
throw new Error(`--${name} 必须是大于等于 ${minimum} 的整数`);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
export async function graphCommand(cfg, action, targets, options) {
|
|
19
|
+
const count = action === 'path' ? 2 : 1;
|
|
20
|
+
if (targets.length !== count || targets.some((target) => !target.trim()))
|
|
21
|
+
throw new Error(action === 'path'
|
|
22
|
+
? 'graph path 需要两个节点:cage graph path <起点> <终点>'
|
|
23
|
+
: `${action} 需要一个关键词或节点;含空格的需求请用引号包住`);
|
|
24
|
+
if (options.format && !['md', 'json'].includes(options.format))
|
|
25
|
+
throw new Error('--format 只能是 md 或 json');
|
|
26
|
+
if (options.kind && !Object.hasOwn(kindLabels, options.kind))
|
|
27
|
+
throw new Error(`未知节点类型 ${options.kind}`);
|
|
28
|
+
if (options.direction && !['out', 'both'].includes(options.direction))
|
|
29
|
+
throw new Error('--direction 只能是 out 或 both');
|
|
30
|
+
const optionActions = {
|
|
31
|
+
kind: ['search'],
|
|
32
|
+
direction: ['path'],
|
|
33
|
+
depth: ['context', 'path'],
|
|
34
|
+
limit: ['context', 'search'],
|
|
35
|
+
};
|
|
36
|
+
for (const [option, actions] of Object.entries(optionActions))
|
|
37
|
+
if (options[option] !== undefined && !actions.includes(action))
|
|
38
|
+
throw new Error(`--${option} 只用于 ${actions.join(' / ')} 查询`);
|
|
39
|
+
const depth = integerOption('depth', options.depth, action === 'path' ? 6 : 3, 0);
|
|
40
|
+
const limit = integerOption('limit', options.limit, action === 'search' ? 10 : 40, 1);
|
|
41
|
+
const snapshot = await collectGraph(cfg.root);
|
|
42
|
+
const report = action === 'context'
|
|
43
|
+
? buildContext(cfg, snapshot, targets[0], { depth, limit })
|
|
44
|
+
: action === 'search'
|
|
45
|
+
? searchGraph(snapshot, targets[0], { limit, kind: options.kind })
|
|
46
|
+
: action === 'inspect'
|
|
47
|
+
? inspectGraph(snapshot, targets[0])
|
|
48
|
+
: findGraphPath(snapshot, targets[0], targets[1], {
|
|
49
|
+
depth,
|
|
50
|
+
direction: options.direction,
|
|
51
|
+
});
|
|
52
|
+
const output = options.format === 'json'
|
|
53
|
+
? JSON.stringify(report, null, 2)
|
|
54
|
+
: report.operation === 'context'
|
|
55
|
+
? formatContext(report)
|
|
56
|
+
: formatGraphQuery(report);
|
|
57
|
+
if (options.out) {
|
|
58
|
+
const file = abs(cfg, options.out);
|
|
59
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
60
|
+
writeFileSync(file, output + '\n');
|
|
61
|
+
}
|
|
62
|
+
else
|
|
63
|
+
console.log(output);
|
|
64
|
+
// 图规则失败时仍交付上下文帮助定位,但不能用成功退出码掩盖错误。
|
|
65
|
+
return report.status === 'ok' && errorsOnly(report.findings).length === 0 ? 0 : 1;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=graph-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-command.js","sourceRoot":"","sources":["../src/graph-command.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,GAAG,EAAmB,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAW3D,SAAS,aAAa,CAAC,IAAY,EAAE,GAAuB,EAAE,QAAgB,EAAE,OAAe;IAC7F,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,OAAO;QAChE,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,YAAY,OAAO,MAAM,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CACh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,OAAO,CAAC,MAAM,KAAK,MAAM;QACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS;YAC9B,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC;YACvB,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;;QAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,kCAAkC;IAClC,OAAO,MAAM,CAAC,MAAM,KAAK,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { NodeKind, OntEdge, OntNode, Ontology } from './ontology.js';
|
|
2
|
+
export declare const kindLabels: Record<NodeKind | 'entry', string>;
|
|
3
|
+
export declare const edgeLabels: Record<string, string>;
|
|
4
|
+
export interface ViewNode extends Omit<OntNode, 'kind'> {
|
|
5
|
+
key: string;
|
|
6
|
+
kind: NodeKind | 'entry';
|
|
7
|
+
}
|
|
8
|
+
export interface ViewEdge extends Omit<OntEdge, 'kind'> {
|
|
9
|
+
key: string;
|
|
10
|
+
kind: OntEdge['kind'] | 'ownership';
|
|
11
|
+
derived: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface GraphModel {
|
|
14
|
+
nodes: ViewNode[];
|
|
15
|
+
edges: ViewEdge[];
|
|
16
|
+
}
|
|
17
|
+
/** graph.labels 的显示覆盖不参与本体哈希;声明内的 description 仍由抽取器
|
|
18
|
+
* 按该声明的含义处理。中文展示不会替换路由、权限或数据表使用的稳定标识。 */
|
|
19
|
+
export declare function nodeLabel(node: ViewNode, labels?: Record<string, string>): string;
|
|
20
|
+
export declare function projectGraph(graph: Ontology): GraphModel;
|
|
21
|
+
export declare function neighborhood(model: GraphModel, key: string): Set<string>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export const kindLabels = {
|
|
2
|
+
aggregate: '业务对象',
|
|
3
|
+
command: '命令',
|
|
4
|
+
event: '事件',
|
|
5
|
+
reaction: '反应',
|
|
6
|
+
query: '查询',
|
|
7
|
+
approval: '审批',
|
|
8
|
+
route: '审批路由',
|
|
9
|
+
job: '定时任务',
|
|
10
|
+
connector: '连接器',
|
|
11
|
+
outbound: '出站映射',
|
|
12
|
+
inbound: '入站回调',
|
|
13
|
+
field: '字段',
|
|
14
|
+
state: '状态',
|
|
15
|
+
capability: '能力点',
|
|
16
|
+
entry: '新建入口',
|
|
17
|
+
};
|
|
18
|
+
export const edgeLabels = {
|
|
19
|
+
transition: '状态迁移',
|
|
20
|
+
reads: '读取',
|
|
21
|
+
emits: '发出',
|
|
22
|
+
uses: '使用字段',
|
|
23
|
+
triggers: '触发',
|
|
24
|
+
cancels: '取消审批',
|
|
25
|
+
targets: '调用目标',
|
|
26
|
+
queries: '查询',
|
|
27
|
+
refs: '引用',
|
|
28
|
+
calls: '调用',
|
|
29
|
+
binds: '审批绑定',
|
|
30
|
+
field: '声明字段',
|
|
31
|
+
ownership: '归属(标识推导)',
|
|
32
|
+
};
|
|
33
|
+
/** graph.labels 的显示覆盖不参与本体哈希;声明内的 description 仍由抽取器
|
|
34
|
+
* 按该声明的含义处理。中文展示不会替换路由、权限或数据表使用的稳定标识。 */
|
|
35
|
+
export function nodeLabel(node, labels = {}) {
|
|
36
|
+
if (node.kind === 'entry')
|
|
37
|
+
return '新建入口';
|
|
38
|
+
return labels[node.key] || String(node.attrs.description || node.id);
|
|
39
|
+
}
|
|
40
|
+
export function projectGraph(graph) {
|
|
41
|
+
const nodes = graph.nodes.map((n) => ({ ...n, key: `${n.kind}:${n.id}` }));
|
|
42
|
+
const edges = [];
|
|
43
|
+
const find = (id, kinds) => nodes.find((n) => n.id === id && kinds.includes(n.kind));
|
|
44
|
+
// 原始边以业务 ID 存端点;投影时按关系类型恢复端点身份,不能猜成同名的状态或能力点。
|
|
45
|
+
const endpoints = {
|
|
46
|
+
transition: [['state', 'entry'], ['state']],
|
|
47
|
+
field: [['aggregate'], ['field']],
|
|
48
|
+
refs: [['field'], ['aggregate']],
|
|
49
|
+
reads: [['command'], ['aggregate']],
|
|
50
|
+
queries: [['query', 'job'], ['aggregate']],
|
|
51
|
+
emits: [['command'], ['event']],
|
|
52
|
+
triggers: [['event'], ['reaction', 'approval', 'outbound']],
|
|
53
|
+
cancels: [['event'], ['approval']],
|
|
54
|
+
targets: [
|
|
55
|
+
['reaction', 'outbound', 'inbound'],
|
|
56
|
+
['command', 'connector'],
|
|
57
|
+
],
|
|
58
|
+
calls: [['job'], ['command']],
|
|
59
|
+
binds: [
|
|
60
|
+
['route', 'approval'],
|
|
61
|
+
['approval', 'command'],
|
|
62
|
+
],
|
|
63
|
+
uses: [['command', 'event', 'query', 'approval', 'route', 'outbound'], ['field']],
|
|
64
|
+
};
|
|
65
|
+
for (const edge of graph.edges) {
|
|
66
|
+
const [fromKinds, toKinds] = endpoints[edge.kind];
|
|
67
|
+
let from = find(edge.from, fromKinds);
|
|
68
|
+
const to = find(edge.to, toKinds);
|
|
69
|
+
if (!from && edge.kind === 'transition' && edge.from.endsWith('.[new]')) {
|
|
70
|
+
from = { key: `entry:${edge.from}`, id: edge.from, kind: 'entry', hash: '', attrs: {} };
|
|
71
|
+
nodes.push(from);
|
|
72
|
+
}
|
|
73
|
+
if (from && to)
|
|
74
|
+
edges.push({ ...edge, from: from.key, to: to.key, key: `edge:${edges.length}`, derived: false });
|
|
75
|
+
}
|
|
76
|
+
for (const node of nodes) {
|
|
77
|
+
if (!['command', 'state', 'capability', 'entry'].includes(node.kind))
|
|
78
|
+
continue;
|
|
79
|
+
const owner = nodes.find((n) => n.kind === 'aggregate' && node.id.startsWith(`${n.id}.`));
|
|
80
|
+
if (owner)
|
|
81
|
+
edges.push({
|
|
82
|
+
key: `owner:${node.key}`,
|
|
83
|
+
kind: 'ownership',
|
|
84
|
+
from: owner.key,
|
|
85
|
+
to: node.key,
|
|
86
|
+
derived: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { nodes, edges };
|
|
90
|
+
}
|
|
91
|
+
export function neighborhood(model, key) {
|
|
92
|
+
const connected = new Set([key]);
|
|
93
|
+
for (const edge of model.edges) {
|
|
94
|
+
if (edge.from === key)
|
|
95
|
+
connected.add(edge.to);
|
|
96
|
+
if (edge.to === key)
|
|
97
|
+
connected.add(edge.from);
|
|
98
|
+
}
|
|
99
|
+
return connected;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=graph-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-model.js","sourceRoot":"","sources":["../src/graph-model.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,UAAU,GAAuC;IAC5D,SAAS,EAAE,MAAM;IACjB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,KAAK;IACjB,KAAK,EAAE,MAAM;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAA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;gBACZ,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;IACP,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,GAAW;IACzD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG;YAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,IAAI,CAAC,EAAE,KAAK,GAAG;YAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Registry } from '@yss123/cage-kernel';
|
|
2
|
+
import type { CageConfig } from './config.js';
|
|
3
|
+
export interface GraphPresentation {
|
|
4
|
+
title: string;
|
|
5
|
+
labels: Record<string, string>;
|
|
6
|
+
/** 配置可覆盖短标题,检索仍保留声明原描述,避免丢失业务关键词。 */
|
|
7
|
+
descriptions?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
/** 图谱、CLI 检索和 AI 上下文复用同一套中文名称。graph.labels 的显示覆盖
|
|
10
|
+
* 与语义图分开,不被 impact 当成业务变化;配置短标题优先于声明的长描述。 */
|
|
11
|
+
export declare function graphPresentation(cfg: CageConfig, registry: Registry): GraphPresentation;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** 图谱、CLI 检索和 AI 上下文复用同一套中文名称。graph.labels 的显示覆盖
|
|
2
|
+
* 与语义图分开,不被 impact 当成业务变化;配置短标题优先于声明的长描述。 */
|
|
3
|
+
export function graphPresentation(cfg, registry) {
|
|
4
|
+
const labels = {};
|
|
5
|
+
const remember = (kind, id, description) => {
|
|
6
|
+
if (description)
|
|
7
|
+
labels[`${kind}:${id}`] = description;
|
|
8
|
+
};
|
|
9
|
+
for (const a of registry.aggregates)
|
|
10
|
+
remember('aggregate', a.name, a.description);
|
|
11
|
+
for (const c of registry.commands)
|
|
12
|
+
remember('command', c.capability, c.cmd.description);
|
|
13
|
+
for (const e of registry.events)
|
|
14
|
+
remember('event', e.name, e.description);
|
|
15
|
+
for (const q of registry.queries)
|
|
16
|
+
remember('query', q.name, q.description);
|
|
17
|
+
for (const j of registry.jobs)
|
|
18
|
+
remember('job', j.name, j.description);
|
|
19
|
+
return {
|
|
20
|
+
title: cfg.graph?.title ?? cfg.name,
|
|
21
|
+
labels: { ...labels, ...cfg.graph?.labels },
|
|
22
|
+
descriptions: labels,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=graph-presentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-presentation.js","sourceRoot":"","sources":["../src/graph-presentation.ts"],"names":[],"mappings":"AAUA;6CAC6C;AAC7C,MAAM,UAAU,iBAAiB,CAAC,GAAe,EAAE,QAAkB;IACnE,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAU,EAAE,WAAoB,EAAE,EAAE;QAClE,IAAI,WAAW;YAAE,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC,GAAG,WAAW,CAAC;IACzD,CAAC,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,UAAU;QAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAClF,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ;QAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACxF,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM;QAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC1E,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,OAAO;QAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC3E,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI;QAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IACtE,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,IAAI,GAAG,CAAC,IAAI;QACnC,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE;QAC3C,YAAY,EAAE,MAAM;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { GraphSnapshot } from './graph-snapshot.js';
|
|
2
|
+
import { type ViewEdge, type ViewNode } from './graph-model.js';
|
|
3
|
+
import { type GraphSearchHit } from './graph-search.js';
|
|
4
|
+
export interface SourceReference {
|
|
5
|
+
file: string;
|
|
6
|
+
line?: number;
|
|
7
|
+
precision: 'declaration' | 'aggregate';
|
|
8
|
+
}
|
|
9
|
+
export interface GraphNodeInfo {
|
|
10
|
+
key: string;
|
|
11
|
+
id: string;
|
|
12
|
+
kind: ViewNode['kind'];
|
|
13
|
+
kindLabel: string;
|
|
14
|
+
label: string;
|
|
15
|
+
hash: string;
|
|
16
|
+
source: SourceReference | null;
|
|
17
|
+
attrs: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface GraphRelationInfo extends ViewEdge {
|
|
20
|
+
label: string;
|
|
21
|
+
why: string;
|
|
22
|
+
purpose: string;
|
|
23
|
+
direction: string;
|
|
24
|
+
evidence: {
|
|
25
|
+
basis: 'declared' | 'inferred' | 'text-match';
|
|
26
|
+
entries: string[];
|
|
27
|
+
source: SourceReference | null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface NodeResolution {
|
|
31
|
+
selector: string;
|
|
32
|
+
status: 'ok' | 'ambiguous' | 'not-found';
|
|
33
|
+
candidates: GraphSearchHit[];
|
|
34
|
+
}
|
|
35
|
+
export declare const graphLimits: string[];
|
|
36
|
+
export declare function graphReader(snapshot: GraphSnapshot, freshness?: 'fresh-extraction' | 'displayed-snapshot'): {
|
|
37
|
+
model: import("./graph-model.js").GraphModel;
|
|
38
|
+
byKey: Map<string, ViewNode>;
|
|
39
|
+
meta: {
|
|
40
|
+
schemaVersion: 1;
|
|
41
|
+
project: string;
|
|
42
|
+
domain: string;
|
|
43
|
+
extractedAt: string;
|
|
44
|
+
freshness: "fresh-extraction" | "displayed-snapshot";
|
|
45
|
+
graphHash: string;
|
|
46
|
+
findings: import("./findings.js").Finding[];
|
|
47
|
+
limitations: string[];
|
|
48
|
+
};
|
|
49
|
+
sourceOf: (node: ViewNode) => SourceReference | null;
|
|
50
|
+
nodeInfo: (node: ViewNode) => GraphNodeInfo;
|
|
51
|
+
relationInfo: (edge: ViewEdge) => GraphRelationInfo;
|
|
52
|
+
search: (query: string, kind?: ViewNode["kind"]) => GraphSearchHit[];
|
|
53
|
+
resolve: (selector: string) => NodeResolution;
|
|
54
|
+
};
|
|
55
|
+
export declare function searchGraph(snapshot: GraphSnapshot, query: string, options?: {
|
|
56
|
+
limit?: number;
|
|
57
|
+
kind?: ViewNode['kind'];
|
|
58
|
+
}): {
|
|
59
|
+
operation: "search";
|
|
60
|
+
status: "ok" | "not-found";
|
|
61
|
+
query: string;
|
|
62
|
+
total: number;
|
|
63
|
+
truncated: boolean;
|
|
64
|
+
hits: {
|
|
65
|
+
source: SourceReference | null;
|
|
66
|
+
key: string;
|
|
67
|
+
id: string;
|
|
68
|
+
kind: ViewNode["kind"];
|
|
69
|
+
label: string;
|
|
70
|
+
score: number;
|
|
71
|
+
matches: import("./graph-search.js").SearchMatch[];
|
|
72
|
+
}[];
|
|
73
|
+
schemaVersion: 1;
|
|
74
|
+
project: string;
|
|
75
|
+
domain: string;
|
|
76
|
+
extractedAt: string;
|
|
77
|
+
freshness: "fresh-extraction" | "displayed-snapshot";
|
|
78
|
+
graphHash: string;
|
|
79
|
+
findings: import("./findings.js").Finding[];
|
|
80
|
+
limitations: string[];
|
|
81
|
+
};
|
|
82
|
+
export declare function inspectGraph(snapshot: GraphSnapshot, selector: string): {
|
|
83
|
+
operation: "inspect";
|
|
84
|
+
status: "ok" | "ambiguous" | "not-found";
|
|
85
|
+
resolution: NodeResolution;
|
|
86
|
+
node: GraphNodeInfo | null;
|
|
87
|
+
relations: GraphRelationInfo[];
|
|
88
|
+
schemaVersion: 1;
|
|
89
|
+
project: string;
|
|
90
|
+
domain: string;
|
|
91
|
+
extractedAt: string;
|
|
92
|
+
freshness: "fresh-extraction" | "displayed-snapshot";
|
|
93
|
+
graphHash: string;
|
|
94
|
+
findings: import("./findings.js").Finding[];
|
|
95
|
+
limitations: string[];
|
|
96
|
+
};
|
|
97
|
+
export interface GraphPathStep {
|
|
98
|
+
from: string;
|
|
99
|
+
to: string;
|
|
100
|
+
traversal: 'forward' | 'reverse';
|
|
101
|
+
relation: GraphRelationInfo;
|
|
102
|
+
}
|
|
103
|
+
/** 默认沿箭头找最短关系链;双向探索要显式选择 both,每一步保留原箭头。
|
|
104
|
+
* 归属虚线只用于整理对象,不能借它制造“任意两个命令都会互相调用”的短路。 */
|
|
105
|
+
export declare function findGraphPath(snapshot: GraphSnapshot, from: string, to: string, options?: {
|
|
106
|
+
direction?: 'out' | 'both';
|
|
107
|
+
depth?: number;
|
|
108
|
+
}): {
|
|
109
|
+
status: "ambiguous" | "not-found";
|
|
110
|
+
nodes: GraphNodeInfo[];
|
|
111
|
+
steps: GraphPathStep[];
|
|
112
|
+
operation: "path";
|
|
113
|
+
from: NodeResolution;
|
|
114
|
+
to: NodeResolution;
|
|
115
|
+
direction: "out" | "both";
|
|
116
|
+
depth: number;
|
|
117
|
+
schemaVersion: 1;
|
|
118
|
+
project: string;
|
|
119
|
+
domain: string;
|
|
120
|
+
extractedAt: string;
|
|
121
|
+
freshness: "fresh-extraction" | "displayed-snapshot";
|
|
122
|
+
graphHash: string;
|
|
123
|
+
findings: import("./findings.js").Finding[];
|
|
124
|
+
limitations: string[];
|
|
125
|
+
} | {
|
|
126
|
+
status: "ok";
|
|
127
|
+
nodes: GraphNodeInfo[];
|
|
128
|
+
steps: GraphPathStep[];
|
|
129
|
+
operation: "path";
|
|
130
|
+
from: NodeResolution;
|
|
131
|
+
to: NodeResolution;
|
|
132
|
+
direction: "out" | "both";
|
|
133
|
+
depth: number;
|
|
134
|
+
schemaVersion: 1;
|
|
135
|
+
project: string;
|
|
136
|
+
domain: string;
|
|
137
|
+
extractedAt: string;
|
|
138
|
+
freshness: "fresh-extraction" | "displayed-snapshot";
|
|
139
|
+
graphHash: string;
|
|
140
|
+
findings: import("./findings.js").Finding[];
|
|
141
|
+
limitations: string[];
|
|
142
|
+
} | {
|
|
143
|
+
status: "not-found-within-depth";
|
|
144
|
+
nodes: GraphNodeInfo[];
|
|
145
|
+
steps: GraphPathStep[];
|
|
146
|
+
operation: "path";
|
|
147
|
+
from: NodeResolution;
|
|
148
|
+
to: NodeResolution;
|
|
149
|
+
direction: "out" | "both";
|
|
150
|
+
depth: number;
|
|
151
|
+
schemaVersion: 1;
|
|
152
|
+
project: string;
|
|
153
|
+
domain: string;
|
|
154
|
+
extractedAt: string;
|
|
155
|
+
freshness: "fresh-extraction" | "displayed-snapshot";
|
|
156
|
+
graphHash: string;
|
|
157
|
+
findings: import("./findings.js").Finding[];
|
|
158
|
+
limitations: string[];
|
|
159
|
+
};
|
|
160
|
+
export declare const sourceText: (source: SourceReference | null) => string;
|
|
161
|
+
export declare const evidenceLabels: {
|
|
162
|
+
declared: string;
|
|
163
|
+
inferred: string;
|
|
164
|
+
'text-match': string;
|
|
165
|
+
};
|
|
166
|
+
export declare function relationMarkdown(relation: GraphRelationInfo): string[];
|
|
167
|
+
export declare function reportHeader(report: ReturnType<typeof graphReader>['meta'], title: string): string[];
|
|
168
|
+
export declare function reportFooter(report: ReturnType<typeof graphReader>['meta']): string[];
|
|
169
|
+
type QueryReport = ReturnType<typeof searchGraph> | ReturnType<typeof inspectGraph> | ReturnType<typeof findGraphPath>;
|
|
170
|
+
export declare function formatGraphQuery(report: QueryReport): string;
|
|
171
|
+
export {};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// 本体查询只消费一次抽取快照。CLI 每次重新抽取;Web 使用页面显示的快照,
|
|
2
|
+
// 报告明确记录时间与来源,不能把常驻页面里的旧图伪装成刚分析的代码。
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { kindLabels, nodeLabel, projectGraph } from './graph-model.js';
|
|
5
|
+
import { explainEdge } from './graph-relations.js';
|
|
6
|
+
import { searchGraphNodes } from './graph-search.js';
|
|
7
|
+
export const graphLimits = [
|
|
8
|
+
'图描述业务声明及可抽取的依赖;条件分支、计算和 map 返回 null 等行为仍须阅读源码。',
|
|
9
|
+
'名称检索与测试匹配是候选线索;未覆盖全部前端依赖,也不证明业务正确性或测试已通过。',
|
|
10
|
+
'source.precision=aggregate 表示只定位到所属聚合声明;source=null 表示当前项目索引没有源码位置。',
|
|
11
|
+
];
|
|
12
|
+
export function graphReader(snapshot, freshness = 'fresh-extraction') {
|
|
13
|
+
const model = projectGraph(snapshot.graph);
|
|
14
|
+
const byKey = new Map(model.nodes.map((node) => [node.key, node]));
|
|
15
|
+
const labels = snapshot.presentation.labels;
|
|
16
|
+
const sourceOf = (node) => {
|
|
17
|
+
if (node.file)
|
|
18
|
+
return { file: node.file, line: node.line, precision: 'declaration' };
|
|
19
|
+
if (['field', 'state', 'capability', 'entry'].includes(node.kind)) {
|
|
20
|
+
const owner = byKey.get(`aggregate:${node.id.split('.')[0]}`);
|
|
21
|
+
if (owner?.file)
|
|
22
|
+
return { file: owner.file, line: owner.line, precision: 'aggregate' };
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
const nodeInfo = (node) => ({
|
|
27
|
+
key: node.key,
|
|
28
|
+
id: node.id,
|
|
29
|
+
kind: node.kind,
|
|
30
|
+
kindLabel: kindLabels[node.kind],
|
|
31
|
+
label: nodeLabel(node, labels),
|
|
32
|
+
hash: node.hash,
|
|
33
|
+
source: sourceOf(node),
|
|
34
|
+
attrs: node.attrs,
|
|
35
|
+
});
|
|
36
|
+
const relationInfo = (edge) => {
|
|
37
|
+
const explanation = explainEdge(edge, model, labels);
|
|
38
|
+
return {
|
|
39
|
+
...edge,
|
|
40
|
+
label: explanation.label,
|
|
41
|
+
why: explanation.why,
|
|
42
|
+
purpose: explanation.purpose,
|
|
43
|
+
direction: explanation.direction,
|
|
44
|
+
evidence: {
|
|
45
|
+
basis: explanation.basis,
|
|
46
|
+
entries: explanation.evidence,
|
|
47
|
+
source: sourceOf(explanation.source),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const search = (query, kind) => searchGraphNodes(model, query, labels, { kind, descriptions: snapshot.presentation.descriptions });
|
|
52
|
+
const resolve = (selector) => {
|
|
53
|
+
const query = selector.normalize('NFKC').trim().toLowerCase();
|
|
54
|
+
// 先匹配带类型的完整身份,再匹配裸 ID / 中文全称。歧义时返回候选,不偷选第一项。
|
|
55
|
+
const keyed = model.nodes.filter((n) => n.key.normalize('NFKC').toLowerCase() === query);
|
|
56
|
+
const exact = keyed.length
|
|
57
|
+
? keyed
|
|
58
|
+
: model.nodes.filter((n) => n.id.normalize('NFKC').toLowerCase() === query);
|
|
59
|
+
const named = exact.length
|
|
60
|
+
? exact
|
|
61
|
+
: model.nodes.filter((n) => nodeLabel(n, labels).normalize('NFKC').toLowerCase() === query);
|
|
62
|
+
const hits = search(selector);
|
|
63
|
+
const candidates = named.length
|
|
64
|
+
? named.map((n) => hits.find((hit) => hit.key === n.key))
|
|
65
|
+
: hits.slice(0, 8);
|
|
66
|
+
return {
|
|
67
|
+
selector,
|
|
68
|
+
status: named.length === 1 ? 'ok' : named.length > 1 ? 'ambiguous' : 'not-found',
|
|
69
|
+
candidates,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const meta = {
|
|
73
|
+
schemaVersion: 1,
|
|
74
|
+
project: snapshot.project,
|
|
75
|
+
domain: snapshot.domain,
|
|
76
|
+
extractedAt: snapshot.generatedAt,
|
|
77
|
+
freshness,
|
|
78
|
+
graphHash: createHash('sha256').update(JSON.stringify(snapshot.graph)).digest('hex').slice(0, 16),
|
|
79
|
+
findings: snapshot.findings,
|
|
80
|
+
limitations: graphLimits,
|
|
81
|
+
};
|
|
82
|
+
return { model, byKey, meta, sourceOf, nodeInfo, relationInfo, search, resolve };
|
|
83
|
+
}
|
|
84
|
+
export function searchGraph(snapshot, query, options = {}) {
|
|
85
|
+
const reader = graphReader(snapshot);
|
|
86
|
+
const hits = reader.search(query, options.kind);
|
|
87
|
+
const limit = options.limit ?? 10;
|
|
88
|
+
return {
|
|
89
|
+
...reader.meta,
|
|
90
|
+
operation: 'search',
|
|
91
|
+
status: hits.length ? 'ok' : 'not-found',
|
|
92
|
+
query,
|
|
93
|
+
total: hits.length,
|
|
94
|
+
truncated: hits.length > limit,
|
|
95
|
+
hits: hits
|
|
96
|
+
.slice(0, limit)
|
|
97
|
+
.map((hit) => ({ ...hit, source: reader.sourceOf(reader.byKey.get(hit.key)) })),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function inspectGraph(snapshot, selector) {
|
|
101
|
+
const reader = graphReader(snapshot);
|
|
102
|
+
const resolution = reader.resolve(selector);
|
|
103
|
+
const node = resolution.status === 'ok' ? reader.byKey.get(resolution.candidates[0].key) : undefined;
|
|
104
|
+
return {
|
|
105
|
+
...reader.meta,
|
|
106
|
+
operation: 'inspect',
|
|
107
|
+
status: resolution.status,
|
|
108
|
+
resolution,
|
|
109
|
+
node: node ? reader.nodeInfo(node) : null,
|
|
110
|
+
relations: node
|
|
111
|
+
? reader.model.edges
|
|
112
|
+
.filter((edge) => edge.from === node.key ||
|
|
113
|
+
edge.to === node.key ||
|
|
114
|
+
(edge.kind === 'transition' && edge.via === node.id && node.kind === 'command'))
|
|
115
|
+
.map(reader.relationInfo)
|
|
116
|
+
: [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** 默认沿箭头找最短关系链;双向探索要显式选择 both,每一步保留原箭头。
|
|
120
|
+
* 归属虚线只用于整理对象,不能借它制造“任意两个命令都会互相调用”的短路。 */
|
|
121
|
+
export function findGraphPath(snapshot, from, to, options = {}) {
|
|
122
|
+
const reader = graphReader(snapshot);
|
|
123
|
+
const start = reader.resolve(from), end = reader.resolve(to);
|
|
124
|
+
const direction = options.direction ?? 'out', depth = options.depth ?? 6;
|
|
125
|
+
const base = { ...reader.meta, operation: 'path', from: start, to: end, direction, depth };
|
|
126
|
+
const nodes = [], steps = [];
|
|
127
|
+
if (start.status !== 'ok' || end.status !== 'ok')
|
|
128
|
+
return {
|
|
129
|
+
...base,
|
|
130
|
+
status: start.status === 'ambiguous' || end.status === 'ambiguous'
|
|
131
|
+
? 'ambiguous'
|
|
132
|
+
: 'not-found',
|
|
133
|
+
nodes,
|
|
134
|
+
steps,
|
|
135
|
+
};
|
|
136
|
+
const first = start.candidates[0].key, last = end.candidates[0].key;
|
|
137
|
+
const queue = [{ key: first, steps: [] }];
|
|
138
|
+
const visited = new Set([first]);
|
|
139
|
+
for (const current of queue) {
|
|
140
|
+
if (current.key === last) {
|
|
141
|
+
steps.push(...current.steps);
|
|
142
|
+
nodes.push(...[first, ...steps.map((s) => s.to)].map((key) => reader.nodeInfo(reader.byKey.get(key))));
|
|
143
|
+
return { ...base, status: 'ok', nodes, steps };
|
|
144
|
+
}
|
|
145
|
+
if (current.steps.length >= depth)
|
|
146
|
+
continue;
|
|
147
|
+
for (const edge of reader.model.edges) {
|
|
148
|
+
if (edge.derived)
|
|
149
|
+
continue;
|
|
150
|
+
const forward = edge.from === current.key;
|
|
151
|
+
const next = forward
|
|
152
|
+
? edge.to
|
|
153
|
+
: direction === 'both' && edge.to === current.key
|
|
154
|
+
? edge.from
|
|
155
|
+
: undefined;
|
|
156
|
+
if (!next || visited.has(next))
|
|
157
|
+
continue;
|
|
158
|
+
visited.add(next);
|
|
159
|
+
queue.push({
|
|
160
|
+
key: next,
|
|
161
|
+
steps: [
|
|
162
|
+
...current.steps,
|
|
163
|
+
{
|
|
164
|
+
from: current.key,
|
|
165
|
+
to: next,
|
|
166
|
+
traversal: forward ? 'forward' : 'reverse',
|
|
167
|
+
relation: reader.relationInfo(edge),
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { ...base, status: 'not-found-within-depth', nodes, steps };
|
|
174
|
+
}
|
|
175
|
+
export const sourceText = (source) => source
|
|
176
|
+
? `${source.file}${source.line ? `:${source.line}` : ''}${source.precision === 'aggregate' ? '(所属聚合)' : ''}`
|
|
177
|
+
: '当前工程无源码定位,查对应依赖的公开 API';
|
|
178
|
+
export const evidenceLabels = { declared: '显式声明', inferred: '规则推导', 'text-match': '文本匹配线索' };
|
|
179
|
+
export function relationMarkdown(relation) {
|
|
180
|
+
return [
|
|
181
|
+
`- ${relation.from} → ${relation.to}:${relation.label}${relation.via ? `;经 ${relation.via}` : ''}`,
|
|
182
|
+
` - 原因:${relation.why}`,
|
|
183
|
+
` - 用途:${relation.purpose}`,
|
|
184
|
+
` - 依据:${evidenceLabels[relation.evidence.basis]};${relation.evidence.entries.join(';')}`,
|
|
185
|
+
` - 源码:${sourceText(relation.evidence.source)}`,
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
export function reportHeader(report, title) {
|
|
189
|
+
return [
|
|
190
|
+
`# ${title}`,
|
|
191
|
+
'',
|
|
192
|
+
`项目:${report.project};抽取时间:${report.extractedAt};图指纹:${report.graphHash}`,
|
|
193
|
+
`来源:${report.freshness === 'fresh-extraction' ? '本次重新抽取' : '页面当前快照,修改代码后需重新抽取'}。`,
|
|
194
|
+
'',
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
export function reportFooter(report) {
|
|
198
|
+
return [
|
|
199
|
+
'',
|
|
200
|
+
'## 当前规则问题',
|
|
201
|
+
'',
|
|
202
|
+
...(report.findings.length
|
|
203
|
+
? report.findings.map((f) => `- [${f.code}] ${f.at ?? ''} ${f.reason};修复:${f.fix}`)
|
|
204
|
+
: ['当前抽取未发现规则问题;未执行测试。']),
|
|
205
|
+
'',
|
|
206
|
+
'## 使用边界',
|
|
207
|
+
'',
|
|
208
|
+
...report.limitations.map((note) => `- ${note}`),
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
export function formatGraphQuery(report) {
|
|
212
|
+
const lines = reportHeader(report, `Cage 本体${report.operation === 'search' ? '检索' : report.operation === 'inspect' ? '节点详情' : '关系路径'}`);
|
|
213
|
+
if (report.operation === 'search') {
|
|
214
|
+
lines.push(`关键词:${report.query};命中 ${report.total} 项${report.truncated ? ',结果已截断,可提高 --limit 或缩小关键词' : ''}。`, '');
|
|
215
|
+
for (const hit of report.hits)
|
|
216
|
+
lines.push(`- **${hit.label}** \`${hit.key}\`(${kindLabels[hit.kind]},得分 ${hit.score})`, ` - 命中:${hit.matches.map((m) => `${m.field}=${m.value}(${m.terms.join('、')})`).join(';')}`, ` - 源码:${sourceText(hit.source)}`);
|
|
217
|
+
}
|
|
218
|
+
else if (report.operation === 'inspect') {
|
|
219
|
+
if (report.node)
|
|
220
|
+
lines.push(`## ${report.node.label} · ${report.node.key}`, '', `源码:${sourceText(report.node.source)}`, '', '```json', JSON.stringify(report.node.attrs, null, 2), '```', '', '## 关联原因与用途', '', ...report.relations.flatMap(relationMarkdown));
|
|
221
|
+
else
|
|
222
|
+
lines.push(`节点定位:${report.status};请从候选中复制完整 key 再执行 inspect。`, '', ...report.resolution.candidates.map((hit) => `- ${hit.label} \`${hit.key}\``));
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
lines.push(`路径状态:${report.status};方向:${report.direction};深度上限:${report.depth}。`, '');
|
|
226
|
+
if (report.status === 'ok') {
|
|
227
|
+
lines.push(report.nodes.map((n) => `${n.label}(${n.key})`).join(' → '), '');
|
|
228
|
+
for (const step of report.steps)
|
|
229
|
+
lines.push(`遍历:${step.from} → ${step.to}${step.traversal === 'reverse' ? '(逆向查看依赖,不表示执行方向)' : ''}`, ...relationMarkdown(step.relation), '');
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
lines.push('未得到路径;未命中时缩小到完整 key,有歧义时从以下候选选择。已定位两端时可提高 --depth,或使用 --direction both 探索反向依赖。', '', ...[report.from, report.to].flatMap((r) => [
|
|
233
|
+
`${r.selector}:${r.status}`,
|
|
234
|
+
...r.candidates.map((hit) => `- ${hit.label} \`${hit.key}\``),
|
|
235
|
+
]));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (report.status === 'not-found')
|
|
239
|
+
lines.push('', '未命中精确节点;检索基于已注册声明和名称,尝试更短的中文词或代码标识。');
|
|
240
|
+
return [...lines, ...reportFooter(report)].join('\n');
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=graph-query.js.map
|