@unbrained/pm-cli 2026.7.17 → 2026.7.18
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +13 -0
- package/dist/cli/commands/close.d.ts +1 -1
- package/dist/cli/commands/close.js +3 -3
- package/dist/cli/commands/close.js.map +1 -1
- package/dist/cli/commands/completion.js +47 -5
- package/dist/cli/commands/completion.js.map +1 -1
- package/dist/cli/commands/context.d.ts +2 -2
- package/dist/cli/commands/context.js +42 -28
- package/dist/cli/commands/context.js.map +1 -1
- package/dist/cli/commands/contracts.js +5 -3
- package/dist/cli/commands/contracts.js.map +1 -1
- package/dist/cli/commands/graph.d.ts +7 -0
- package/dist/cli/commands/graph.js +11 -0
- package/dist/cli/commands/graph.js.map +1 -0
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +3 -2
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/next.d.ts +1 -1
- package/dist/cli/commands/next.js +3 -3
- package/dist/cli/commands/next.js.map +1 -1
- package/dist/cli/main.js +3 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/register-list-query.js +49 -7
- package/dist/cli/register-list-query.js.map +1 -1
- package/dist/cli/register-mutation.js +7 -3
- package/dist/cli/register-mutation.js.map +1 -1
- package/dist/cli-bundle/bundle-manifest.json +157 -149
- package/dist/cli-bundle/chunks/{chunk-N7I2DGLP.js → chunk-35FHWD4C.js} +4 -4
- package/dist/cli-bundle/chunks/{chunk-37V5MXAU.js.map → chunk-35FHWD4C.js.map} +1 -7
- package/dist/cli-bundle/chunks/{chunk-MSGETE6I.js → chunk-3CUQZNQ6.js} +67 -509
- package/dist/cli-bundle/chunks/chunk-3CUQZNQ6.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-3QDR6ZLU.js +800 -0
- package/dist/cli-bundle/chunks/chunk-3QDR6ZLU.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-QNUAZYGW.js → chunk-43UMFKCK.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-HF63SBLC.js → chunk-6VHUGVNP.js} +39 -16
- package/dist/cli-bundle/chunks/chunk-6VHUGVNP.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-B6SH2YNN.js → chunk-7R6UIHYY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-NCAFUBJX.js → chunk-7UCY6DR5.js} +183 -12
- package/dist/cli-bundle/chunks/chunk-7UCY6DR5.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-23TCGBRK.js → chunk-ADXDCAKP.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-7LTCLTRG.js → chunk-AXRT7K5V.js} +16 -3
- package/dist/cli-bundle/chunks/chunk-AXRT7K5V.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-P56LKFQX.js → chunk-BDA35QG5.js} +34 -4
- package/dist/cli-bundle/chunks/chunk-BDA35QG5.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-2MPMKJF2.js → chunk-DHNG452T.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-AFSV5HBB.js → chunk-E4FXM2XB.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-QKVVV6QO.js → chunk-EWIT5WIC.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-EX7OQT3Y.js +783 -0
- package/dist/cli-bundle/chunks/chunk-EX7OQT3Y.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-LLODAQMP.js → chunk-F3VC3GOV.js} +41 -18
- package/dist/cli-bundle/chunks/chunk-F3VC3GOV.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-S46R2M3W.js → chunk-GKPCTQYG.js} +1709 -5
- package/dist/cli-bundle/chunks/chunk-GKPCTQYG.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-HXVHBERL.js → chunk-HPAYDSR2.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-XNPMDSQQ.js → chunk-HYTOJW2Q.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-V3VBXQQV.js → chunk-I3INI567.js} +516 -429
- package/dist/cli-bundle/chunks/chunk-I3INI567.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-V7MP6YTN.js → chunk-IL5SPRMH.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-YQCWK2MB.js → chunk-L5BTTDU5.js} +68 -503
- package/dist/cli-bundle/chunks/chunk-L5BTTDU5.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-SIJV365F.js → chunk-NCVT6XEL.js} +17 -4
- package/dist/cli-bundle/chunks/chunk-NCVT6XEL.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-DCC2AQBD.js → chunk-OGVTB5VO.js} +32 -31
- package/dist/cli-bundle/chunks/chunk-OGVTB5VO.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-6XAZB6SE.js → chunk-QPGQNLPI.js} +1660 -7
- package/dist/cli-bundle/chunks/chunk-QPGQNLPI.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-KOEZCHRF.js → chunk-QRZNCRNA.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-G6KM4YKY.js → chunk-RXPQ5Q23.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-7CTQ7WW5.js → chunk-SIPOACV5.js} +514 -427
- package/dist/cli-bundle/chunks/chunk-SIPOACV5.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-XYJK6GIQ.js → chunk-TGBTLGPX.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-37V5MXAU.js → chunk-TLWJP5BF.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-TLWJP5BF.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-3D4YVTNG.js → chunk-TZAE66GQ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-S6FF7VW6.js → chunk-WQXRZMFN.js} +187 -16
- package/dist/cli-bundle/chunks/chunk-WQXRZMFN.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-SPFZV2GR.js → chunk-XPUTSGJU.js} +32 -31
- package/dist/cli-bundle/chunks/chunk-XPUTSGJU.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-CFSUNEL7.js → chunk-XWBD6DSR.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-MNV226E4.js → chunk-XWYQ2LT4.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-I7GY4X6Y.js → chunk-YFE7JHX3.js} +26 -5
- package/dist/cli-bundle/chunks/chunk-YFE7JHX3.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-FZGM3PNA.js → chunk-YIIIAKCE.js} +2 -2
- package/dist/cli-bundle/chunks/{close-BEP7MHF3.js → close-GPD7DTJV.js} +3 -3
- package/dist/cli-bundle/chunks/{close-Y6QFUJQN.js → close-X3CF6FQP.js} +3 -3
- package/dist/cli-bundle/chunks/{close-many-JJFW7KTT.js → close-many-J7A5EHOQ.js} +5 -5
- package/dist/cli-bundle/chunks/{close-many-QJ6FKJUE.js → close-many-NQLYGPYW.js} +5 -5
- package/dist/cli-bundle/chunks/{deps-EVTOQMKW.js → deps-MQ4ZIGZB.js} +13 -4
- package/dist/cli-bundle/chunks/{deps-5NC4IZH7.js → deps-NIIKXLPB.js} +13 -4
- package/dist/cli-bundle/chunks/{profile-U2B6Y7GE.js → profile-AVCIIZID.js} +3 -3
- package/dist/cli-bundle/chunks/{profile-AGUKS52S.js → profile-LFYO3HHX.js} +3 -3
- package/dist/cli-bundle/chunks/{register-list-query-A5KRJ5J2.js → register-list-query-MZUF2EEC.js} +41 -13
- package/dist/cli-bundle/chunks/register-list-query-MZUF2EEC.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-list-query-NEYP3TXO.js → register-list-query-UKMF55FT.js} +40 -12
- package/dist/cli-bundle/chunks/register-list-query-UKMF55FT.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-mutation-6LOPBAHC.js → register-mutation-2PBW2GEX.js} +15 -13
- package/dist/cli-bundle/chunks/register-mutation-2PBW2GEX.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-mutation-GCZOALNJ.js → register-mutation-T6RVNJC4.js} +14 -12
- package/dist/cli-bundle/chunks/{register-mutation-GCZOALNJ.js.map → register-mutation-T6RVNJC4.js.map} +2 -2
- package/dist/cli-bundle/chunks/{register-operations-6ZZIF27A.js → register-operations-KHZYR6MG.js} +11 -11
- package/dist/cli-bundle/chunks/{register-operations-REDIAEGI.js → register-operations-WPQ2LWZJ.js} +11 -11
- package/dist/cli-bundle/chunks/{register-setup-J3JS2ZVT.js → register-setup-PGDNOXDQ.js} +5 -5
- package/dist/cli-bundle/chunks/{register-setup-BHPMN5SK.js → register-setup-TDN7WAO6.js} +5 -5
- package/dist/cli-bundle/chunks/{update-SA6AG23P.js → update-SQYZA3ZW.js} +4 -4
- package/dist/cli-bundle/chunks/{update-PQQHLYCC.js → update-XZJYS5X7.js} +4 -4
- package/dist/cli-bundle/chunks/{update-many-RQVTFJPD.js → update-many-R24B3GBK.js} +6 -6
- package/dist/cli-bundle/chunks/{update-many-TV3L3KBX.js → update-many-WQ3R3J6N.js} +6 -6
- package/dist/cli-bundle/main.js +25 -9
- package/dist/cli-bundle/main.js.map +2 -2
- package/dist/cli-bundle/sdk-runtime.js +19 -16
- package/dist/cli-bundle/sdk.js +95 -305
- package/dist/cli-bundle/sdk.js.map +4 -4
- package/dist/core/item/actionability.d.ts +12 -0
- package/dist/core/item/actionability.js +39 -4
- package/dist/core/item/actionability.js.map +1 -1
- package/dist/core/sentry/instrument.d.ts +11 -0
- package/dist/core/sentry/instrument.js +21 -2
- package/dist/core/sentry/instrument.js.map +1 -1
- package/dist/mcp/server.d.ts +16 -18
- package/dist/mcp/server.js +84 -31
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-definitions.js +17 -4
- package/dist/mcp/tool-definitions.js.map +1 -1
- package/dist/sdk/actionability.d.ts +10 -0
- package/dist/sdk/actionability.js +14 -0
- package/dist/sdk/actionability.js.map +1 -0
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +6 -2
- package/dist/sdk/cli-contracts/enum-contracts.js +19 -2
- package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
- package/dist/sdk/cli-contracts/flag-contracts.js +21 -2
- package/dist/sdk/cli-contracts/flag-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-option-contracts.d.ts +2 -0
- package/dist/sdk/cli-contracts/tool-option-contracts.js +16 -2
- package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +80 -3
- package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-schema.d.ts +20 -0
- package/dist/sdk/cli-contracts/tool-schema.js +97 -9
- package/dist/sdk/cli-contracts/tool-schema.js.map +1 -1
- package/dist/sdk/cli-contracts.d.ts +2 -2
- package/dist/sdk/cli-contracts.js +4 -4
- package/dist/sdk/cli-contracts.js.map +1 -1
- package/dist/sdk/dependencies.d.ts +42 -53
- package/dist/sdk/dependencies.js +177 -125
- package/dist/sdk/dependencies.js.map +1 -1
- package/dist/sdk/governance/validate.js +3 -3
- package/dist/sdk/governance/validate.js.map +1 -1
- package/dist/sdk/graph/analytics.d.ts +124 -0
- package/dist/sdk/graph/analytics.js +464 -0
- package/dist/sdk/graph/analytics.js.map +1 -0
- package/dist/sdk/graph/assembly.d.ts +97 -0
- package/dist/sdk/graph/assembly.js +146 -0
- package/dist/sdk/graph/assembly.js.map +1 -0
- package/dist/sdk/graph/cache.d.ts +66 -0
- package/dist/sdk/graph/cache.js +148 -0
- package/dist/sdk/graph/cache.js.map +1 -0
- package/dist/sdk/graph/governance.d.ts +108 -0
- package/dist/sdk/graph/governance.js +360 -0
- package/dist/sdk/graph/governance.js.map +1 -0
- package/dist/sdk/graph/index.d.ts +16 -0
- package/dist/sdk/graph/index.js +20 -0
- package/dist/sdk/graph/index.js.map +1 -0
- package/dist/sdk/graph/remediation.d.ts +52 -0
- package/dist/sdk/graph/remediation.js +148 -0
- package/dist/sdk/graph/remediation.js.map +1 -0
- package/dist/sdk/graph/run.d.ts +295 -0
- package/dist/sdk/graph/run.js +468 -0
- package/dist/sdk/graph/run.js.map +1 -0
- package/dist/sdk/graph/traversal.d.ts +77 -0
- package/dist/sdk/graph/traversal.js +262 -0
- package/dist/sdk/graph/traversal.js.map +1 -0
- package/dist/sdk/index.d.ts +4 -2
- package/dist/sdk/index.js +6 -4
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/query/list.d.ts +8 -0
- package/dist/sdk/query/list.js +19 -3
- package/dist/sdk/query/list.js.map +1 -1
- package/dist/sdk/relationship-context.d.ts +42 -0
- package/dist/sdk/relationship-context.js +99 -20
- package/dist/sdk/relationship-context.js.map +1 -1
- package/dist/sdk/relationships.d.ts +13 -0
- package/dist/sdk/relationships.js +30 -2
- package/dist/sdk/relationships.js.map +1 -1
- package/dist/sdk/runtime-input.d.ts +41 -0
- package/dist/sdk/runtime-input.js +422 -2
- package/dist/sdk/runtime-input.js.map +1 -1
- package/dist/sdk/runtime.d.ts +12 -23
- package/dist/sdk/runtime.js +19 -371
- package/dist/sdk/runtime.js.map +1 -1
- package/dist/sdk/test/linked-command-detection.js +12 -3
- package/dist/sdk/test/linked-command-detection.js.map +1 -1
- package/docs/AGENT_GUIDE.md +1 -0
- package/docs/COMMANDS.md +19 -1
- package/docs/RELATIONSHIP_GRAPH.md +99 -3
- package/docs/SDK.md +17 -3
- package/marketplace.json +2 -2
- package/package.json +1 -1
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/dist/cli-bundle/chunks/chunk-6XAZB6SE.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-7CTQ7WW5.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-7LTCLTRG.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-DCC2AQBD.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-HF63SBLC.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-I7GY4X6Y.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-LLODAQMP.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-MSGETE6I.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-N7I2DGLP.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-NCAFUBJX.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-P56LKFQX.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-S46R2M3W.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-S6FF7VW6.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-SIJV365F.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-SPFZV2GR.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-V3VBXQQV.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-YQCWK2MB.js.map +0 -1
- package/dist/cli-bundle/chunks/register-list-query-A5KRJ5J2.js.map +0 -1
- package/dist/cli-bundle/chunks/register-list-query-NEYP3TXO.js.map +0 -7
- package/dist/cli-bundle/chunks/register-mutation-6LOPBAHC.js.map +0 -1
- /package/dist/cli-bundle/chunks/{chunk-QNUAZYGW.js.map → chunk-43UMFKCK.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-B6SH2YNN.js.map → chunk-7R6UIHYY.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-23TCGBRK.js.map → chunk-ADXDCAKP.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-2MPMKJF2.js.map → chunk-DHNG452T.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-AFSV5HBB.js.map → chunk-E4FXM2XB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-QKVVV6QO.js.map → chunk-EWIT5WIC.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-HXVHBERL.js.map → chunk-HPAYDSR2.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-XNPMDSQQ.js.map → chunk-HYTOJW2Q.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-V7MP6YTN.js.map → chunk-IL5SPRMH.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-KOEZCHRF.js.map → chunk-QRZNCRNA.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-G6KM4YKY.js.map → chunk-RXPQ5Q23.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-XYJK6GIQ.js.map → chunk-TGBTLGPX.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-3D4YVTNG.js.map → chunk-TZAE66GQ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-CFSUNEL7.js.map → chunk-XWBD6DSR.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-MNV226E4.js.map → chunk-XWYQ2LT4.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-FZGM3PNA.js.map → chunk-YIIIAKCE.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{close-BEP7MHF3.js.map → close-GPD7DTJV.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{close-Y6QFUJQN.js.map → close-X3CF6FQP.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{close-many-JJFW7KTT.js.map → close-many-J7A5EHOQ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{close-many-QJ6FKJUE.js.map → close-many-NQLYGPYW.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{deps-EVTOQMKW.js.map → deps-MQ4ZIGZB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{deps-5NC4IZH7.js.map → deps-NIIKXLPB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{profile-U2B6Y7GE.js.map → profile-AVCIIZID.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{profile-AGUKS52S.js.map → profile-LFYO3HHX.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{register-operations-6ZZIF27A.js.map → register-operations-KHZYR6MG.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{register-operations-REDIAEGI.js.map → register-operations-WPQ2LWZJ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{register-setup-J3JS2ZVT.js.map → register-setup-PGDNOXDQ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{register-setup-BHPMN5SK.js.map → register-setup-TDN7WAO6.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-SA6AG23P.js.map → update-SQYZA3ZW.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-PQQHLYCC.js.map → update-XZJYS5X7.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-many-RQVTFJPD.js.map → update-many-R24B3GBK.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-many-TV3L3KBX.js.map → update-many-WQ3R3J6N.js.map} +0 -0
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2289448d-a087-55eb-a092-70c2f25227d6")}catch(e){}}();
|
|
3
|
+
import {
|
|
4
|
+
computeWorkspaceGraphFingerprint,
|
|
5
|
+
parseDirection,
|
|
6
|
+
parseKinds,
|
|
7
|
+
parseMaxDepth,
|
|
8
|
+
parsePositiveInteger,
|
|
9
|
+
workspaceGraphCache
|
|
10
|
+
} from "./chunk-EX7OQT3Y.js";
|
|
3
11
|
import {
|
|
4
12
|
collectStaleVectorizationIds
|
|
5
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-XPUTSGJU.js";
|
|
14
|
+
import {
|
|
15
|
+
assembleWorkspaceRelationshipGraph,
|
|
16
|
+
createRelationshipKindRegistry
|
|
17
|
+
} from "./chunk-L5BTTDU5.js";
|
|
6
18
|
import {
|
|
7
19
|
buildListQueryFilters
|
|
8
20
|
} from "./chunk-N7V7TI6J.js";
|
|
@@ -21,7 +33,7 @@ import {
|
|
|
21
33
|
resolveContentFieldFilters,
|
|
22
34
|
resolveMissingMetadataFilters,
|
|
23
35
|
runList
|
|
24
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-NCVT6XEL.js";
|
|
25
37
|
import {
|
|
26
38
|
createQueryFingerprint,
|
|
27
39
|
paginateQueryRows
|
|
@@ -59,7 +71,10 @@ import {
|
|
|
59
71
|
resolveSearchCorpusFields,
|
|
60
72
|
resolveSettingsWithSemanticRuntimeDefaults,
|
|
61
73
|
resolveVectorStores
|
|
62
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-E4FXM2XB.js";
|
|
75
|
+
import {
|
|
76
|
+
GRAPH_SUBCOMMAND_VALUES
|
|
77
|
+
} from "./chunk-7UCY6DR5.js";
|
|
63
78
|
import {
|
|
64
79
|
splitCommaList
|
|
65
80
|
} from "./chunk-NETP4DY4.js";
|
|
@@ -3369,6 +3384,1626 @@ async function runGet(id, global, options = {}) {
|
|
|
3369
3384
|
return result;
|
|
3370
3385
|
}
|
|
3371
3386
|
|
|
3387
|
+
// dist/sdk/relationship-analytics.js
|
|
3388
|
+
function appendNeighbor(adjacency, source, target) {
|
|
3389
|
+
adjacency.get(source).add(target);
|
|
3390
|
+
}
|
|
3391
|
+
function createAdjacency(nodes) {
|
|
3392
|
+
return new Map(nodes.map((node) => [node, /* @__PURE__ */ new Set()]));
|
|
3393
|
+
}
|
|
3394
|
+
function sortComponents(components) {
|
|
3395
|
+
for (const component of components)
|
|
3396
|
+
component.sort();
|
|
3397
|
+
return components.sort((left, right) => right.length - left.length || left[0].localeCompare(right[0]));
|
|
3398
|
+
}
|
|
3399
|
+
function stableJsonValue(value) {
|
|
3400
|
+
if (Array.isArray(value))
|
|
3401
|
+
return value.map((entry) => stableJsonValue(entry));
|
|
3402
|
+
if (value === null || typeof value !== "object")
|
|
3403
|
+
return value;
|
|
3404
|
+
const toJSON = value.toJSON;
|
|
3405
|
+
if (typeof toJSON === "function")
|
|
3406
|
+
return stableJsonValue(toJSON.call(value));
|
|
3407
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => [key, stableJsonValue(entry)]));
|
|
3408
|
+
}
|
|
3409
|
+
function relationshipEdgeKey(edge) {
|
|
3410
|
+
return JSON.stringify(stableJsonValue(edge));
|
|
3411
|
+
}
|
|
3412
|
+
function appendFinishingOrder(start, adjacency, visited, order) {
|
|
3413
|
+
const stack = [{ id: start, expanded: false }];
|
|
3414
|
+
while (stack.length > 0) {
|
|
3415
|
+
const current = stack.pop();
|
|
3416
|
+
if (current.expanded) {
|
|
3417
|
+
order.push(current.id);
|
|
3418
|
+
continue;
|
|
3419
|
+
}
|
|
3420
|
+
if (visited.has(current.id))
|
|
3421
|
+
continue;
|
|
3422
|
+
visited.add(current.id);
|
|
3423
|
+
stack.push({ id: current.id, expanded: true });
|
|
3424
|
+
const neighbors = [...adjacency.get(current.id)].sort().reverse();
|
|
3425
|
+
for (const neighbor of neighbors)
|
|
3426
|
+
if (!visited.has(neighbor))
|
|
3427
|
+
stack.push({ id: neighbor, expanded: false });
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
function computeFinishingOrder(nodes, adjacency) {
|
|
3431
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3432
|
+
const order = [];
|
|
3433
|
+
for (const start of nodes)
|
|
3434
|
+
if (!visited.has(start))
|
|
3435
|
+
appendFinishingOrder(start, adjacency, visited, order);
|
|
3436
|
+
return order;
|
|
3437
|
+
}
|
|
3438
|
+
function collectReverseComponents(order, reverse) {
|
|
3439
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3440
|
+
const components = [];
|
|
3441
|
+
for (const start of [...order].reverse()) {
|
|
3442
|
+
if (visited.has(start))
|
|
3443
|
+
continue;
|
|
3444
|
+
const component = [];
|
|
3445
|
+
const stack = [start];
|
|
3446
|
+
visited.add(start);
|
|
3447
|
+
while (stack.length > 0) {
|
|
3448
|
+
const current = stack.pop();
|
|
3449
|
+
component.push(current);
|
|
3450
|
+
for (const neighbor of reverse.get(current)) {
|
|
3451
|
+
if (visited.has(neighbor))
|
|
3452
|
+
continue;
|
|
3453
|
+
visited.add(neighbor);
|
|
3454
|
+
stack.push(neighbor);
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
components.push(component);
|
|
3458
|
+
}
|
|
3459
|
+
return sortComponents(components);
|
|
3460
|
+
}
|
|
3461
|
+
function stronglyConnectedComponents(nodes, adjacency) {
|
|
3462
|
+
const reverse = createAdjacency(nodes);
|
|
3463
|
+
for (const [source, targets] of adjacency)
|
|
3464
|
+
for (const target of targets)
|
|
3465
|
+
appendNeighbor(reverse, target, source);
|
|
3466
|
+
return collectReverseComponents(computeFinishingOrder(nodes, adjacency), reverse);
|
|
3467
|
+
}
|
|
3468
|
+
function buildExecutionAdjacency(graph, registry) {
|
|
3469
|
+
const adjacency = createAdjacency(graph.nodes());
|
|
3470
|
+
for (const edge of graph.edges()) {
|
|
3471
|
+
const definition = registry.require(edge.kind);
|
|
3472
|
+
if (!definition.ordering)
|
|
3473
|
+
continue;
|
|
3474
|
+
const sourceFirst = (definition.precedence ?? "source_before_target") === "source_before_target";
|
|
3475
|
+
appendNeighbor(adjacency, sourceFirst ? edge.source : edge.target, sourceFirst ? edge.target : edge.source);
|
|
3476
|
+
}
|
|
3477
|
+
return adjacency;
|
|
3478
|
+
}
|
|
3479
|
+
function topologicalLayers(nodes, adjacency) {
|
|
3480
|
+
const indegree = new Map(nodes.map((node) => [node, 0]));
|
|
3481
|
+
for (const targets of adjacency.values())
|
|
3482
|
+
for (const target of targets)
|
|
3483
|
+
indegree.set(target, indegree.get(target) + 1);
|
|
3484
|
+
let frontier = nodes.filter((node) => indegree.get(node) === 0).sort();
|
|
3485
|
+
const layers = [];
|
|
3486
|
+
while (frontier.length > 0) {
|
|
3487
|
+
layers.push(frontier);
|
|
3488
|
+
const next = [];
|
|
3489
|
+
for (const source of frontier) {
|
|
3490
|
+
for (const target of adjacency.get(source)) {
|
|
3491
|
+
const remaining = indegree.get(target) - 1;
|
|
3492
|
+
indegree.set(target, remaining);
|
|
3493
|
+
if (remaining === 0)
|
|
3494
|
+
next.push(target);
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
frontier = next.sort();
|
|
3498
|
+
}
|
|
3499
|
+
return layers;
|
|
3500
|
+
}
|
|
3501
|
+
function longestPath(order, adjacency) {
|
|
3502
|
+
const depth = new Map(order.map((node) => [node, 0]));
|
|
3503
|
+
const parent = /* @__PURE__ */ new Map();
|
|
3504
|
+
for (const source of order) {
|
|
3505
|
+
for (const target of adjacency.get(source)) {
|
|
3506
|
+
if (!depth.has(target))
|
|
3507
|
+
continue;
|
|
3508
|
+
const candidate = depth.get(source) + 1;
|
|
3509
|
+
const currentParent = parent.get(target);
|
|
3510
|
+
if (candidate > depth.get(target) || candidate === depth.get(target) && (currentParent === void 0 || source.localeCompare(currentParent) < 0)) {
|
|
3511
|
+
depth.set(target, candidate);
|
|
3512
|
+
parent.set(target, source);
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
const end = [...order].sort((left, right) => depth.get(right) - depth.get(left) || left.localeCompare(right))[0];
|
|
3517
|
+
const path3 = end === void 0 ? [] : [end];
|
|
3518
|
+
while (path3[0] !== void 0 && parent.has(path3[0]))
|
|
3519
|
+
path3.unshift(parent.get(path3[0]));
|
|
3520
|
+
return { depth: Object.fromEntries(depth), path: path3 };
|
|
3521
|
+
}
|
|
3522
|
+
function reconstructImpactPath(root, target, parents) {
|
|
3523
|
+
const path3 = [target];
|
|
3524
|
+
let cursor = target;
|
|
3525
|
+
while (cursor !== root) {
|
|
3526
|
+
cursor = parents.get(cursor);
|
|
3527
|
+
path3.push(cursor);
|
|
3528
|
+
}
|
|
3529
|
+
return path3.reverse();
|
|
3530
|
+
}
|
|
3531
|
+
function analyzeRelationshipExecution(graph, options = {}) {
|
|
3532
|
+
const registry = options.registry ?? createRelationshipKindRegistry();
|
|
3533
|
+
const nodes = [...graph.nodes()];
|
|
3534
|
+
const adjacency = buildExecutionAdjacency(graph, registry);
|
|
3535
|
+
const layers = topologicalLayers(nodes, adjacency);
|
|
3536
|
+
const order = layers.flat();
|
|
3537
|
+
const acyclic = order.length === nodes.length;
|
|
3538
|
+
const cycles = acyclic ? [] : stronglyConnectedComponents(nodes, adjacency).filter((component) => component.length > 1 || adjacency.get(component[0]).has(component[0]));
|
|
3539
|
+
const longest = longestPath(order, adjacency);
|
|
3540
|
+
return {
|
|
3541
|
+
exact: true,
|
|
3542
|
+
acyclic,
|
|
3543
|
+
order,
|
|
3544
|
+
layers,
|
|
3545
|
+
frontier: layers[0] ?? [],
|
|
3546
|
+
depth: longest.depth,
|
|
3547
|
+
criticalPath: longest.path,
|
|
3548
|
+
criticalPathLength: Math.max(0, longest.path.length - 1),
|
|
3549
|
+
cycles,
|
|
3550
|
+
provenance: { algorithm: "kahn-longest-path", edgeFamily: "ordering" }
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
function analyzeGraphImpact(graph, root, options = {}) {
|
|
3554
|
+
const direction = options.direction ?? "outgoing";
|
|
3555
|
+
const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
3556
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
3557
|
+
const queue = [{ id: root, depth: 0 }];
|
|
3558
|
+
const seen = /* @__PURE__ */ new Set([root]);
|
|
3559
|
+
const parents = /* @__PURE__ */ new Map();
|
|
3560
|
+
const affected = [];
|
|
3561
|
+
let visitedNodes = 0;
|
|
3562
|
+
let inspectedEdges = 0;
|
|
3563
|
+
let truncated = false;
|
|
3564
|
+
traversal: for (let index = 0; index < queue.length; index += 1) {
|
|
3565
|
+
options.signal?.throwIfAborted();
|
|
3566
|
+
const current = queue[index];
|
|
3567
|
+
visitedNodes += 1;
|
|
3568
|
+
const adjacent = graph.adjacency(current.id, {
|
|
3569
|
+
direction,
|
|
3570
|
+
kinds: options.kinds,
|
|
3571
|
+
signal: options.signal
|
|
3572
|
+
});
|
|
3573
|
+
inspectedEdges += adjacent.meta.inspectedEdges;
|
|
3574
|
+
if (current.depth >= maxDepth) {
|
|
3575
|
+
if (adjacent.value.some((id) => !seen.has(id)))
|
|
3576
|
+
truncated = true;
|
|
3577
|
+
continue;
|
|
3578
|
+
}
|
|
3579
|
+
for (const id of adjacent.value) {
|
|
3580
|
+
if (seen.has(id))
|
|
3581
|
+
continue;
|
|
3582
|
+
if (affected.length >= limit) {
|
|
3583
|
+
truncated = true;
|
|
3584
|
+
break traversal;
|
|
3585
|
+
}
|
|
3586
|
+
seen.add(id);
|
|
3587
|
+
parents.set(id, current.id);
|
|
3588
|
+
const depth = current.depth + 1;
|
|
3589
|
+
affected.push({
|
|
3590
|
+
id,
|
|
3591
|
+
distance: depth,
|
|
3592
|
+
path: reconstructImpactPath(root, id, parents)
|
|
3593
|
+
});
|
|
3594
|
+
queue.push({ id, depth });
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
return {
|
|
3598
|
+
root,
|
|
3599
|
+
affected,
|
|
3600
|
+
exact: true,
|
|
3601
|
+
truncated,
|
|
3602
|
+
cost: { visitedNodes, inspectedEdges }
|
|
3603
|
+
};
|
|
3604
|
+
}
|
|
3605
|
+
function analyzeKnowledgeGraph(graph) {
|
|
3606
|
+
const nodes = [...graph.nodes()];
|
|
3607
|
+
const weak = createAdjacency(nodes);
|
|
3608
|
+
const directed = createAdjacency(nodes);
|
|
3609
|
+
for (const edge of graph.edges()) {
|
|
3610
|
+
appendNeighbor(weak, edge.source, edge.target);
|
|
3611
|
+
appendNeighbor(weak, edge.target, edge.source);
|
|
3612
|
+
appendNeighbor(directed, edge.source, edge.target);
|
|
3613
|
+
}
|
|
3614
|
+
const components = [];
|
|
3615
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3616
|
+
for (const start of nodes) {
|
|
3617
|
+
if (visited.has(start))
|
|
3618
|
+
continue;
|
|
3619
|
+
const component = [];
|
|
3620
|
+
const stack = [start];
|
|
3621
|
+
visited.add(start);
|
|
3622
|
+
while (stack.length > 0) {
|
|
3623
|
+
const current = stack.pop();
|
|
3624
|
+
component.push(current);
|
|
3625
|
+
for (const neighbor of weak.get(current)) {
|
|
3626
|
+
if (visited.has(neighbor))
|
|
3627
|
+
continue;
|
|
3628
|
+
visited.add(neighbor);
|
|
3629
|
+
stack.push(neighbor);
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
components.push(component);
|
|
3633
|
+
}
|
|
3634
|
+
const degrees = nodes.map((id) => ({ id, degree: weak.get(id).size }));
|
|
3635
|
+
const maximum = Math.max(0, ...degrees.map(({ degree }) => degree));
|
|
3636
|
+
return {
|
|
3637
|
+
components: sortComponents(components),
|
|
3638
|
+
stronglyConnected: stronglyConnectedComponents(nodes, directed),
|
|
3639
|
+
orphans: degrees.filter(({ degree }) => degree === 0).map(({ id }) => id),
|
|
3640
|
+
hubs: degrees.filter(({ degree }) => degree > 0 && degree === maximum),
|
|
3641
|
+
exact: true,
|
|
3642
|
+
provenance: { algorithm: "component-degree", edgeFamily: "all" }
|
|
3643
|
+
};
|
|
3644
|
+
}
|
|
3645
|
+
function compareRelationshipSnapshots(before, after) {
|
|
3646
|
+
const earlier = new Map(before.edges.map((edge) => [relationshipEdgeKey(edge), edge]));
|
|
3647
|
+
const later = new Map(after.edges.map((edge) => [relationshipEdgeKey(edge), edge]));
|
|
3648
|
+
return {
|
|
3649
|
+
fromVersion: before.version,
|
|
3650
|
+
toVersion: after.version,
|
|
3651
|
+
added: [...later].filter(([key]) => !earlier.has(key)).map(([, edge]) => edge),
|
|
3652
|
+
removed: [...earlier].filter(([key]) => !later.has(key)).map(([, edge]) => edge),
|
|
3653
|
+
unchangedCount: [...earlier.keys()].filter((key) => later.has(key)).length,
|
|
3654
|
+
exact: true
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
// dist/sdk/graph/traversal.js
|
|
3659
|
+
var DEFAULT_MAX_PATHS = 5;
|
|
3660
|
+
var DEFAULT_MAX_VISITED_PATHS = 1e4;
|
|
3661
|
+
var DEFAULT_PATH_MAX_DEPTH = 8;
|
|
3662
|
+
function assertPathBound(name, value) {
|
|
3663
|
+
if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0)
|
|
3664
|
+
throw new TypeError(`Invalid path ${name} bound: ${String(value)}`);
|
|
3665
|
+
}
|
|
3666
|
+
function hierarchyParentEndpoint(edge, definition) {
|
|
3667
|
+
return definition.hierarchyDirection === "target_parent" ? edge.target : edge.source;
|
|
3668
|
+
}
|
|
3669
|
+
function orderingPredecessorEndpoint(edge, definition) {
|
|
3670
|
+
return (definition.precedence ?? "source_before_target") === "target_before_source" ? edge.target : edge.source;
|
|
3671
|
+
}
|
|
3672
|
+
function resolveFamilyKinds(graph, kinds, family) {
|
|
3673
|
+
if (kinds === void 0)
|
|
3674
|
+
return void 0;
|
|
3675
|
+
const registry = graph.registry();
|
|
3676
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
3677
|
+
for (const kind of kinds) {
|
|
3678
|
+
const definition = registry.require(kind);
|
|
3679
|
+
if (!definition[family])
|
|
3680
|
+
throw new TypeError(`Relationship kind ${definition.kind} is not a ${family} kind`);
|
|
3681
|
+
resolved.add(definition.kind);
|
|
3682
|
+
}
|
|
3683
|
+
return resolved;
|
|
3684
|
+
}
|
|
3685
|
+
function expandSemanticNeighbors(graph, nodeId, familyKinds, family, matches) {
|
|
3686
|
+
const registry = graph.registry();
|
|
3687
|
+
const rows = graph.neighborEdges(nodeId, {
|
|
3688
|
+
direction: "both",
|
|
3689
|
+
...familyKinds === void 0 ? {} : { kinds: [...familyKinds] }
|
|
3690
|
+
});
|
|
3691
|
+
const neighbors = [];
|
|
3692
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3693
|
+
for (const row of rows.value) {
|
|
3694
|
+
const definition = registry.require(row.edge.kind);
|
|
3695
|
+
if (!definition[family])
|
|
3696
|
+
continue;
|
|
3697
|
+
if (!matches(row, definition, nodeId))
|
|
3698
|
+
continue;
|
|
3699
|
+
if (seen.has(row.id))
|
|
3700
|
+
continue;
|
|
3701
|
+
seen.add(row.id);
|
|
3702
|
+
neighbors.push(row.id);
|
|
3703
|
+
}
|
|
3704
|
+
return { neighbors, inspectedEdges: rows.meta.inspectedEdges };
|
|
3705
|
+
}
|
|
3706
|
+
function appendSemanticExpansion(expansion, currentDepth, maxDepth, limit, after, state) {
|
|
3707
|
+
if (currentDepth >= maxDepth) {
|
|
3708
|
+
if (expansion.neighbors.some((neighbor) => !state.seen.has(neighbor)))
|
|
3709
|
+
state.truncated = true;
|
|
3710
|
+
return false;
|
|
3711
|
+
}
|
|
3712
|
+
for (const neighbor of expansion.neighbors) {
|
|
3713
|
+
if (state.seen.has(neighbor))
|
|
3714
|
+
continue;
|
|
3715
|
+
state.seen.add(neighbor);
|
|
3716
|
+
state.queue.push({ id: neighbor, depth: currentDepth + 1 });
|
|
3717
|
+
if (!state.resumed) {
|
|
3718
|
+
if (neighbor === after)
|
|
3719
|
+
state.resumed = true;
|
|
3720
|
+
continue;
|
|
3721
|
+
}
|
|
3722
|
+
if (state.value.length >= limit) {
|
|
3723
|
+
state.truncated = true;
|
|
3724
|
+
return true;
|
|
3725
|
+
}
|
|
3726
|
+
state.value.push(neighbor);
|
|
3727
|
+
}
|
|
3728
|
+
return false;
|
|
3729
|
+
}
|
|
3730
|
+
function boundedSemanticWalk(graph, start, options, family, matches) {
|
|
3731
|
+
if (!graph.hasNode(start))
|
|
3732
|
+
throw new TypeError(`Relationship node not found: ${start}`);
|
|
3733
|
+
const familyKinds = resolveFamilyKinds(graph, options.kinds, family);
|
|
3734
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
3735
|
+
const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
3736
|
+
const after = options.after;
|
|
3737
|
+
const state = {
|
|
3738
|
+
seen: /* @__PURE__ */ new Set([start]),
|
|
3739
|
+
value: [],
|
|
3740
|
+
queue: [{ id: start, depth: 0 }],
|
|
3741
|
+
resumed: after === void 0,
|
|
3742
|
+
truncated: false
|
|
3743
|
+
};
|
|
3744
|
+
let visitedNodes = 0;
|
|
3745
|
+
let inspectedEdges = 0;
|
|
3746
|
+
for (let index = 0; index < state.queue.length; index += 1) {
|
|
3747
|
+
options.signal?.throwIfAborted();
|
|
3748
|
+
const current = state.queue[index];
|
|
3749
|
+
visitedNodes += 1;
|
|
3750
|
+
const expansion = expandSemanticNeighbors(graph, current.id, familyKinds, family, matches);
|
|
3751
|
+
inspectedEdges += expansion.inspectedEdges;
|
|
3752
|
+
if (appendSemanticExpansion(expansion, current.depth, maxDepth, limit, after, state))
|
|
3753
|
+
break;
|
|
3754
|
+
}
|
|
3755
|
+
if (!state.resumed)
|
|
3756
|
+
throw new TypeError(`Traversal cursor not found in sequence: ${after}`);
|
|
3757
|
+
return {
|
|
3758
|
+
value: state.value,
|
|
3759
|
+
meta: {
|
|
3760
|
+
visitedNodes,
|
|
3761
|
+
inspectedEdges,
|
|
3762
|
+
truncated: state.truncated,
|
|
3763
|
+
nextCursor: state.value.at(-1)
|
|
3764
|
+
}
|
|
3765
|
+
};
|
|
3766
|
+
}
|
|
3767
|
+
function assertPathEndpoint(graph, id) {
|
|
3768
|
+
if (!graph.hasNode(id))
|
|
3769
|
+
throw new TypeError(`Relationship node not found: ${id}`);
|
|
3770
|
+
}
|
|
3771
|
+
function readPathContinuations(graph, partial, options, direction, state) {
|
|
3772
|
+
const rows = graph.neighborEdges(partial.nodes.at(-1), {
|
|
3773
|
+
direction,
|
|
3774
|
+
...options.kinds === void 0 ? {} : { kinds: options.kinds }
|
|
3775
|
+
});
|
|
3776
|
+
state.inspectedEdges += rows.meta.inspectedEdges;
|
|
3777
|
+
return rows.value.filter((row) => !partial.nodeSet.has(row.id));
|
|
3778
|
+
}
|
|
3779
|
+
function expandPartialPath(graph, partial, target, options, direction, probeLimit, state) {
|
|
3780
|
+
for (const row of readPathContinuations(graph, partial, options, direction, state)) {
|
|
3781
|
+
const nodes = [...partial.nodes, row.id];
|
|
3782
|
+
const nodeSet = new Set(partial.nodeSet).add(row.id);
|
|
3783
|
+
const edges = [...partial.edges, row.edge];
|
|
3784
|
+
if (row.id === target) {
|
|
3785
|
+
state.value.push({ nodes, edges, length: edges.length });
|
|
3786
|
+
if (state.value.length >= probeLimit)
|
|
3787
|
+
return true;
|
|
3788
|
+
} else {
|
|
3789
|
+
state.queue.push({ nodes, nodeSet, edges });
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
return false;
|
|
3793
|
+
}
|
|
3794
|
+
function hierarchyAncestors(graph, id, options = {}) {
|
|
3795
|
+
return boundedSemanticWalk(graph, id, options, "hierarchy", (row, definition) => hierarchyParentEndpoint(row.edge, definition) === row.id);
|
|
3796
|
+
}
|
|
3797
|
+
function hierarchyDescendants(graph, id, options = {}) {
|
|
3798
|
+
return boundedSemanticWalk(graph, id, options, "hierarchy", (row, definition, nodeId) => hierarchyParentEndpoint(row.edge, definition) === nodeId);
|
|
3799
|
+
}
|
|
3800
|
+
function orderingPredecessors(graph, id, options = {}) {
|
|
3801
|
+
return boundedSemanticWalk(graph, id, options, "ordering", (row, definition) => orderingPredecessorEndpoint(row.edge, definition) === row.id);
|
|
3802
|
+
}
|
|
3803
|
+
function orderingSuccessors(graph, id, options = {}) {
|
|
3804
|
+
return boundedSemanticWalk(graph, id, options, "ordering", (row, definition, nodeId) => orderingPredecessorEndpoint(row.edge, definition) === nodeId);
|
|
3805
|
+
}
|
|
3806
|
+
function enumerateNonZeroRelationshipPaths(graph, source, target, options, maxPaths, maxVisitedPaths, maxDepth, direction) {
|
|
3807
|
+
const state = {
|
|
3808
|
+
value: [],
|
|
3809
|
+
queue: [{ nodes: [source], nodeSet: /* @__PURE__ */ new Set([source]), edges: [] }],
|
|
3810
|
+
inspectedEdges: 0
|
|
3811
|
+
};
|
|
3812
|
+
let visitedNodes = 0;
|
|
3813
|
+
let truncated = false;
|
|
3814
|
+
const probeLimit = maxPaths + 1;
|
|
3815
|
+
for (let index = 0; index < state.queue.length; index += 1) {
|
|
3816
|
+
options.signal?.throwIfAborted();
|
|
3817
|
+
if (state.value.length >= probeLimit || visitedNodes >= maxVisitedPaths) {
|
|
3818
|
+
truncated = true;
|
|
3819
|
+
break;
|
|
3820
|
+
}
|
|
3821
|
+
const partial = state.queue[index];
|
|
3822
|
+
visitedNodes += 1;
|
|
3823
|
+
if (partial.edges.length >= maxDepth) {
|
|
3824
|
+
if (readPathContinuations(graph, partial, options, direction, state).length > 0)
|
|
3825
|
+
truncated = true;
|
|
3826
|
+
continue;
|
|
3827
|
+
}
|
|
3828
|
+
if (expandPartialPath(graph, partial, target, options, direction, probeLimit, state)) {
|
|
3829
|
+
truncated = true;
|
|
3830
|
+
break;
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
return {
|
|
3834
|
+
value: state.value.slice(0, maxPaths),
|
|
3835
|
+
meta: { visitedNodes, inspectedEdges: state.inspectedEdges, truncated }
|
|
3836
|
+
};
|
|
3837
|
+
}
|
|
3838
|
+
function enumerateRelationshipPaths(graph, source, target, options = {}) {
|
|
3839
|
+
assertPathEndpoint(graph, source);
|
|
3840
|
+
assertPathEndpoint(graph, target);
|
|
3841
|
+
const maxPaths = options.maxPaths ?? DEFAULT_MAX_PATHS;
|
|
3842
|
+
const maxVisitedPaths = options.maxVisitedPaths ?? DEFAULT_MAX_VISITED_PATHS;
|
|
3843
|
+
const maxDepth = options.maxDepth ?? DEFAULT_PATH_MAX_DEPTH;
|
|
3844
|
+
assertPathBound("maxPaths", maxPaths);
|
|
3845
|
+
assertPathBound("maxVisitedPaths", maxVisitedPaths);
|
|
3846
|
+
assertPathBound("maxDepth", maxDepth);
|
|
3847
|
+
const direction = options.direction ?? "outgoing";
|
|
3848
|
+
options.signal?.throwIfAborted();
|
|
3849
|
+
for (const kind of options.kinds ?? [])
|
|
3850
|
+
graph.registry().require(kind);
|
|
3851
|
+
if (source === target) {
|
|
3852
|
+
if (maxPaths === 0) {
|
|
3853
|
+
return {
|
|
3854
|
+
value: [],
|
|
3855
|
+
meta: { visitedNodes: 1, inspectedEdges: 0, truncated: true }
|
|
3856
|
+
};
|
|
3857
|
+
}
|
|
3858
|
+
return {
|
|
3859
|
+
value: [{ nodes: [source], edges: [], length: 0 }],
|
|
3860
|
+
meta: { visitedNodes: 1, inspectedEdges: 0, truncated: false }
|
|
3861
|
+
};
|
|
3862
|
+
}
|
|
3863
|
+
return enumerateNonZeroRelationshipPaths(graph, source, target, options, maxPaths, maxVisitedPaths, maxDepth, direction);
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
// dist/sdk/graph/analytics.js
|
|
3867
|
+
var DEFAULT_MAX_ITERATIONS = 16;
|
|
3868
|
+
var DEFAULT_MIN_COMMUNITY_SIZE = 2;
|
|
3869
|
+
var DEFAULT_REDUNDANCY_MAX_DEPTH = 8;
|
|
3870
|
+
function assertPositiveBound(name, value) {
|
|
3871
|
+
if (!Number.isInteger(value) || value < 1)
|
|
3872
|
+
throw new TypeError(`Invalid ${name} bound: ${String(value)}`);
|
|
3873
|
+
}
|
|
3874
|
+
function buildUndirectedAdjacency(graph, kinds) {
|
|
3875
|
+
const registry = graph.registry();
|
|
3876
|
+
const wanted = kinds === void 0 ? void 0 : new Set(kinds.map((kind) => registry.require(kind).kind));
|
|
3877
|
+
const adjacency = /* @__PURE__ */ new Map();
|
|
3878
|
+
for (const edge of graph.edges()) {
|
|
3879
|
+
if (edge.source === edge.target)
|
|
3880
|
+
continue;
|
|
3881
|
+
if (wanted !== void 0) {
|
|
3882
|
+
const definition = registry.require(edge.kind);
|
|
3883
|
+
const matches = wanted.has(definition.kind) || definition.inverse !== void 0 && wanted.has(definition.inverse);
|
|
3884
|
+
if (!matches)
|
|
3885
|
+
continue;
|
|
3886
|
+
}
|
|
3887
|
+
appendAdjacency(adjacency, edge.source, edge.target);
|
|
3888
|
+
appendAdjacency(adjacency, edge.target, edge.source);
|
|
3889
|
+
}
|
|
3890
|
+
for (const neighbors of adjacency.values())
|
|
3891
|
+
neighbors.sort();
|
|
3892
|
+
return adjacency;
|
|
3893
|
+
}
|
|
3894
|
+
function appendAdjacency(adjacency, from, to) {
|
|
3895
|
+
const neighbors = adjacency.get(from);
|
|
3896
|
+
if (neighbors === void 0)
|
|
3897
|
+
adjacency.set(from, [to]);
|
|
3898
|
+
else
|
|
3899
|
+
neighbors.push(to);
|
|
3900
|
+
}
|
|
3901
|
+
function dominantNeighborLabel(neighbors, labels) {
|
|
3902
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3903
|
+
for (const neighbor of neighbors) {
|
|
3904
|
+
const label = labels.get(neighbor);
|
|
3905
|
+
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
3906
|
+
}
|
|
3907
|
+
let best;
|
|
3908
|
+
let bestCount = 0;
|
|
3909
|
+
for (const [label, count] of counts) {
|
|
3910
|
+
if (count > bestCount || count === bestCount && label < best) {
|
|
3911
|
+
best = label;
|
|
3912
|
+
bestCount = count;
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
return best;
|
|
3916
|
+
}
|
|
3917
|
+
function collectCommunities(labels, minSize) {
|
|
3918
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3919
|
+
for (const [id, label] of labels) {
|
|
3920
|
+
const members = groups.get(label);
|
|
3921
|
+
if (members === void 0)
|
|
3922
|
+
groups.set(label, [id]);
|
|
3923
|
+
else
|
|
3924
|
+
members.push(id);
|
|
3925
|
+
}
|
|
3926
|
+
const communities = [];
|
|
3927
|
+
for (const members of groups.values()) {
|
|
3928
|
+
if (members.length < minSize)
|
|
3929
|
+
continue;
|
|
3930
|
+
members.sort();
|
|
3931
|
+
communities.push({
|
|
3932
|
+
representative: members[0],
|
|
3933
|
+
size: members.length,
|
|
3934
|
+
members
|
|
3935
|
+
});
|
|
3936
|
+
}
|
|
3937
|
+
return communities.sort((left, right) => right.size - left.size || left.representative.localeCompare(right.representative));
|
|
3938
|
+
}
|
|
3939
|
+
function detectRelationshipCommunities(graph, options = {}) {
|
|
3940
|
+
const maxIterations = options.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
3941
|
+
const minSize = options.minSize ?? DEFAULT_MIN_COMMUNITY_SIZE;
|
|
3942
|
+
assertPositiveBound("maxIterations", maxIterations);
|
|
3943
|
+
assertPositiveBound("minSize", minSize);
|
|
3944
|
+
const adjacency = buildUndirectedAdjacency(graph, options.kinds);
|
|
3945
|
+
const nodes = graph.nodes();
|
|
3946
|
+
const labels = new Map(nodes.map((id) => [id, id]));
|
|
3947
|
+
let iterations = 0;
|
|
3948
|
+
let converged = false;
|
|
3949
|
+
let visitedNodes = 0;
|
|
3950
|
+
let inspectedEdges = 0;
|
|
3951
|
+
while (iterations < maxIterations && !converged) {
|
|
3952
|
+
options.signal?.throwIfAborted();
|
|
3953
|
+
iterations += 1;
|
|
3954
|
+
converged = true;
|
|
3955
|
+
for (const id of nodes) {
|
|
3956
|
+
visitedNodes += 1;
|
|
3957
|
+
const neighbors = adjacency.get(id);
|
|
3958
|
+
if (neighbors === void 0)
|
|
3959
|
+
continue;
|
|
3960
|
+
inspectedEdges += neighbors.length;
|
|
3961
|
+
const dominant = dominantNeighborLabel(neighbors, labels);
|
|
3962
|
+
if (dominant !== labels.get(id)) {
|
|
3963
|
+
labels.set(id, dominant);
|
|
3964
|
+
converged = false;
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
return {
|
|
3969
|
+
value: {
|
|
3970
|
+
communities: collectCommunities(labels, minSize),
|
|
3971
|
+
iterations,
|
|
3972
|
+
converged
|
|
3973
|
+
},
|
|
3974
|
+
meta: { visitedNodes, inspectedEdges, truncated: !converged }
|
|
3975
|
+
};
|
|
3976
|
+
}
|
|
3977
|
+
function isTransitiveKind(definition) {
|
|
3978
|
+
return definition.direction === "directed" && (definition.ordering || definition.hierarchy);
|
|
3979
|
+
}
|
|
3980
|
+
function transitiveFamilyKey(definition) {
|
|
3981
|
+
return definition.inverse !== void 0 && definition.inverse < definition.kind ? definition.inverse : definition.kind;
|
|
3982
|
+
}
|
|
3983
|
+
function orientTransitiveEdge(edge, definition) {
|
|
3984
|
+
const head = definition.hierarchy ? hierarchyParentEndpoint(edge, definition) : edge.source === orderingPredecessorEndpoint(edge, definition) ? edge.target : edge.source;
|
|
3985
|
+
return head === edge.target ? { from: edge.source, to: edge.target } : { from: edge.target, to: edge.source };
|
|
3986
|
+
}
|
|
3987
|
+
function resolveRedundancyFamilies(graph, kinds) {
|
|
3988
|
+
if (kinds === void 0)
|
|
3989
|
+
return void 0;
|
|
3990
|
+
const registry = graph.registry();
|
|
3991
|
+
const families = /* @__PURE__ */ new Set();
|
|
3992
|
+
for (const kind of kinds) {
|
|
3993
|
+
const definition = registry.require(kind);
|
|
3994
|
+
if (!isTransitiveKind(definition))
|
|
3995
|
+
throw new TypeError(`Relationship kind ${definition.kind} is not a directed ordering or hierarchy kind`);
|
|
3996
|
+
families.add(transitiveFamilyKey(definition));
|
|
3997
|
+
}
|
|
3998
|
+
return families;
|
|
3999
|
+
}
|
|
4000
|
+
function collectTransitiveFamilies(graph, wanted) {
|
|
4001
|
+
const registry = graph.registry();
|
|
4002
|
+
const families = /* @__PURE__ */ new Map();
|
|
4003
|
+
for (const edge of graph.edges()) {
|
|
4004
|
+
const definition = registry.require(edge.kind);
|
|
4005
|
+
if (!isTransitiveKind(definition))
|
|
4006
|
+
continue;
|
|
4007
|
+
const key = transitiveFamilyKey(definition);
|
|
4008
|
+
if (wanted !== void 0 && !wanted.has(key))
|
|
4009
|
+
continue;
|
|
4010
|
+
const oriented = orientTransitiveEdge(edge, definition);
|
|
4011
|
+
if (oriented.from === oriented.to)
|
|
4012
|
+
continue;
|
|
4013
|
+
let family = families.get(key);
|
|
4014
|
+
if (family === void 0) {
|
|
4015
|
+
family = { adjacency: /* @__PURE__ */ new Map(), records: [] };
|
|
4016
|
+
families.set(key, family);
|
|
4017
|
+
}
|
|
4018
|
+
const targets = family.adjacency.get(oriented.from);
|
|
4019
|
+
if (targets === void 0)
|
|
4020
|
+
family.adjacency.set(oriented.from, /* @__PURE__ */ new Set([oriented.to]));
|
|
4021
|
+
else
|
|
4022
|
+
targets.add(oriented.to);
|
|
4023
|
+
family.records.push({ ...oriented, edge });
|
|
4024
|
+
}
|
|
4025
|
+
return families;
|
|
4026
|
+
}
|
|
4027
|
+
function sortedFamilyAdjacency(family) {
|
|
4028
|
+
const sorted = /* @__PURE__ */ new Map();
|
|
4029
|
+
for (const [from, targets] of family.adjacency)
|
|
4030
|
+
sorted.set(from, [...targets].sort());
|
|
4031
|
+
return sorted;
|
|
4032
|
+
}
|
|
4033
|
+
function reconstructWitness(parents, from, tail, head) {
|
|
4034
|
+
const witness = [head];
|
|
4035
|
+
for (let node = tail; node !== from; node = parents.get(node))
|
|
4036
|
+
witness.push(node);
|
|
4037
|
+
witness.push(from);
|
|
4038
|
+
return witness.reverse();
|
|
4039
|
+
}
|
|
4040
|
+
function expandWitnessFrontier(adjacency, record, current, parents, queue, cost) {
|
|
4041
|
+
for (const next of adjacency.get(current.id) ?? []) {
|
|
4042
|
+
cost.inspectedEdges += 1;
|
|
4043
|
+
if (current.depth === 0 && next === record.to)
|
|
4044
|
+
continue;
|
|
4045
|
+
if (parents.has(next))
|
|
4046
|
+
continue;
|
|
4047
|
+
parents.set(next, current.id);
|
|
4048
|
+
if (next === record.to)
|
|
4049
|
+
return reconstructWitness(parents, record.from, current.id, next);
|
|
4050
|
+
queue.push({ id: next, depth: current.depth + 1 });
|
|
4051
|
+
}
|
|
4052
|
+
return void 0;
|
|
4053
|
+
}
|
|
4054
|
+
function findWitnessPath(adjacency, record, maxDepth, cost) {
|
|
4055
|
+
const parents = /* @__PURE__ */ new Map([[record.from, record.from]]);
|
|
4056
|
+
const queue = [{ id: record.from, depth: 0 }];
|
|
4057
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
4058
|
+
const current = queue[index];
|
|
4059
|
+
cost.visitedNodes += 1;
|
|
4060
|
+
if (current.depth >= maxDepth)
|
|
4061
|
+
continue;
|
|
4062
|
+
const witness = expandWitnessFrontier(adjacency, record, current, parents, queue, cost);
|
|
4063
|
+
if (witness !== void 0)
|
|
4064
|
+
return witness;
|
|
4065
|
+
}
|
|
4066
|
+
return void 0;
|
|
4067
|
+
}
|
|
4068
|
+
function findRedundantRelationshipEdges(graph, options = {}) {
|
|
4069
|
+
const maxDepth = options.maxDepth ?? DEFAULT_REDUNDANCY_MAX_DEPTH;
|
|
4070
|
+
assertPositiveBound("maxDepth", maxDepth);
|
|
4071
|
+
if (options.limit !== void 0)
|
|
4072
|
+
assertPositiveBound("limit", options.limit);
|
|
4073
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
4074
|
+
const wanted = resolveRedundancyFamilies(graph, options.kinds);
|
|
4075
|
+
const families = collectTransitiveFamilies(graph, wanted);
|
|
4076
|
+
const value = [];
|
|
4077
|
+
const cost = { visitedNodes: 0, inspectedEdges: 0 };
|
|
4078
|
+
let truncated = false;
|
|
4079
|
+
scan: for (const key of [...families.keys()].sort()) {
|
|
4080
|
+
const family = families.get(key);
|
|
4081
|
+
const adjacency = sortedFamilyAdjacency(family);
|
|
4082
|
+
for (const record of family.records) {
|
|
4083
|
+
options.signal?.throwIfAborted();
|
|
4084
|
+
const witness = findWitnessPath(adjacency, record, maxDepth, cost);
|
|
4085
|
+
if (witness === void 0)
|
|
4086
|
+
continue;
|
|
4087
|
+
if (value.length >= limit) {
|
|
4088
|
+
truncated = true;
|
|
4089
|
+
break scan;
|
|
4090
|
+
}
|
|
4091
|
+
value.push({ edge: record.edge, witness });
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
return {
|
|
4095
|
+
value,
|
|
4096
|
+
meta: {
|
|
4097
|
+
visitedNodes: cost.visitedNodes,
|
|
4098
|
+
inspectedEdges: cost.inspectedEdges,
|
|
4099
|
+
truncated
|
|
4100
|
+
}
|
|
4101
|
+
};
|
|
4102
|
+
}
|
|
4103
|
+
function expandReachableNode(id, depth, rows, maxDepth, state) {
|
|
4104
|
+
const nextSet = /* @__PURE__ */ new Set();
|
|
4105
|
+
const nexts = [];
|
|
4106
|
+
for (const row of rows) {
|
|
4107
|
+
if (row.id === id || nextSet.has(row.id))
|
|
4108
|
+
continue;
|
|
4109
|
+
if (!state.seen.has(row.id)) {
|
|
4110
|
+
if (depth >= maxDepth) {
|
|
4111
|
+
state.truncated = true;
|
|
4112
|
+
continue;
|
|
4113
|
+
}
|
|
4114
|
+
state.seen.add(row.id);
|
|
4115
|
+
state.queue.push({ id: row.id, depth: depth + 1 });
|
|
4116
|
+
}
|
|
4117
|
+
nextSet.add(row.id);
|
|
4118
|
+
nexts.push(row.id);
|
|
4119
|
+
let incoming = state.predecessors.get(row.id);
|
|
4120
|
+
if (incoming === void 0) {
|
|
4121
|
+
incoming = /* @__PURE__ */ new Set();
|
|
4122
|
+
state.predecessors.set(row.id, incoming);
|
|
4123
|
+
}
|
|
4124
|
+
incoming.add(id);
|
|
4125
|
+
}
|
|
4126
|
+
return nexts;
|
|
4127
|
+
}
|
|
4128
|
+
function indexReachableSubgraph(graph, root, options) {
|
|
4129
|
+
const direction = options.direction ?? "outgoing";
|
|
4130
|
+
const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
4131
|
+
const order = [];
|
|
4132
|
+
const successors = /* @__PURE__ */ new Map();
|
|
4133
|
+
const state = {
|
|
4134
|
+
seen: /* @__PURE__ */ new Set([root]),
|
|
4135
|
+
queue: [{ id: root, depth: 0 }],
|
|
4136
|
+
predecessors: /* @__PURE__ */ new Map(),
|
|
4137
|
+
truncated: false
|
|
4138
|
+
};
|
|
4139
|
+
let inspectedEdges = 0;
|
|
4140
|
+
for (let index = 0; index < state.queue.length; index += 1) {
|
|
4141
|
+
options.signal?.throwIfAborted();
|
|
4142
|
+
const { id, depth } = state.queue[index];
|
|
4143
|
+
order.push(id);
|
|
4144
|
+
const rows = graph.neighborEdges(id, {
|
|
4145
|
+
direction,
|
|
4146
|
+
...options.kinds === void 0 ? {} : { kinds: options.kinds }
|
|
4147
|
+
});
|
|
4148
|
+
inspectedEdges += rows.meta.inspectedEdges;
|
|
4149
|
+
successors.set(id, expandReachableNode(id, depth, rows.value, maxDepth, state));
|
|
4150
|
+
}
|
|
4151
|
+
return {
|
|
4152
|
+
order,
|
|
4153
|
+
successors,
|
|
4154
|
+
predecessors: state.predecessors,
|
|
4155
|
+
inspectedEdges,
|
|
4156
|
+
truncated: state.truncated
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
function reversePostorder(subgraph, root) {
|
|
4160
|
+
const postorder = [];
|
|
4161
|
+
const visited = /* @__PURE__ */ new Set([root]);
|
|
4162
|
+
const stack = [{ id: root, index: 0 }];
|
|
4163
|
+
while (stack.length > 0) {
|
|
4164
|
+
const frame = stack.at(-1);
|
|
4165
|
+
const nexts = subgraph.successors.get(frame.id);
|
|
4166
|
+
if (frame.index < nexts.length) {
|
|
4167
|
+
const next = nexts[frame.index];
|
|
4168
|
+
frame.index += 1;
|
|
4169
|
+
if (!visited.has(next)) {
|
|
4170
|
+
visited.add(next);
|
|
4171
|
+
stack.push({ id: next, index: 0 });
|
|
4172
|
+
}
|
|
4173
|
+
} else {
|
|
4174
|
+
postorder.push(frame.id);
|
|
4175
|
+
stack.pop();
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
return postorder.reverse();
|
|
4179
|
+
}
|
|
4180
|
+
function intersectDominators(left, right, idom, ordinal) {
|
|
4181
|
+
let first = left;
|
|
4182
|
+
let second = right;
|
|
4183
|
+
while (first !== second) {
|
|
4184
|
+
while (ordinal.get(first) > ordinal.get(second))
|
|
4185
|
+
first = idom.get(first);
|
|
4186
|
+
while (ordinal.get(second) > ordinal.get(first))
|
|
4187
|
+
second = idom.get(second);
|
|
4188
|
+
}
|
|
4189
|
+
return first;
|
|
4190
|
+
}
|
|
4191
|
+
function dominatorCandidate(predecessors, idom, ordinal) {
|
|
4192
|
+
let candidate;
|
|
4193
|
+
for (const pred of [...predecessors].sort()) {
|
|
4194
|
+
if (!idom.has(pred))
|
|
4195
|
+
continue;
|
|
4196
|
+
candidate = candidate === void 0 ? pred : intersectDominators(candidate, pred, idom, ordinal);
|
|
4197
|
+
}
|
|
4198
|
+
return candidate;
|
|
4199
|
+
}
|
|
4200
|
+
function solveImmediateDominators(subgraph, root, order, ordinal, signal) {
|
|
4201
|
+
const idom = /* @__PURE__ */ new Map([[root, root]]);
|
|
4202
|
+
let changed = true;
|
|
4203
|
+
while (changed) {
|
|
4204
|
+
changed = false;
|
|
4205
|
+
for (const id of order) {
|
|
4206
|
+
signal?.throwIfAborted();
|
|
4207
|
+
if (id === root)
|
|
4208
|
+
continue;
|
|
4209
|
+
const candidate = dominatorCandidate(subgraph.predecessors.get(id), idom, ordinal);
|
|
4210
|
+
if (candidate !== void 0 && idom.get(id) !== candidate) {
|
|
4211
|
+
idom.set(id, candidate);
|
|
4212
|
+
changed = true;
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
return idom;
|
|
4217
|
+
}
|
|
4218
|
+
function computeRelationshipDominators(graph, root, options = {}) {
|
|
4219
|
+
if (!graph.hasNode(root))
|
|
4220
|
+
throw new TypeError(`Relationship node not found: ${root}`);
|
|
4221
|
+
if (options.maxDepth !== void 0 && (!Number.isInteger(options.maxDepth) || options.maxDepth < 0))
|
|
4222
|
+
throw new TypeError(`Invalid maxDepth bound: ${String(options.maxDepth)}`);
|
|
4223
|
+
const subgraph = indexReachableSubgraph(graph, root, options);
|
|
4224
|
+
const order = reversePostorder(subgraph, root);
|
|
4225
|
+
const ordinal = new Map(order.map((id, index) => [id, index]));
|
|
4226
|
+
const idom = solveImmediateDominators(subgraph, root, order, ordinal, options.signal);
|
|
4227
|
+
const subtreeSizes = new Map(order.map((id) => [id, 1]));
|
|
4228
|
+
for (let index = order.length - 1; index >= 0; index -= 1) {
|
|
4229
|
+
const id = order[index];
|
|
4230
|
+
if (id === root)
|
|
4231
|
+
continue;
|
|
4232
|
+
const parent = idom.get(id);
|
|
4233
|
+
subtreeSizes.set(parent, subtreeSizes.get(parent) + subtreeSizes.get(id));
|
|
4234
|
+
}
|
|
4235
|
+
const rows = order.filter((id) => id !== root).map((id) => ({
|
|
4236
|
+
id,
|
|
4237
|
+
idom: idom.get(id),
|
|
4238
|
+
dominatedCount: subtreeSizes.get(id) - 1
|
|
4239
|
+
})).sort((left, right) => right.dominatedCount - left.dominatedCount || left.id.localeCompare(right.id));
|
|
4240
|
+
return {
|
|
4241
|
+
value: { root, reachableCount: subgraph.order.length, rows },
|
|
4242
|
+
meta: {
|
|
4243
|
+
visitedNodes: subgraph.order.length,
|
|
4244
|
+
inspectedEdges: subgraph.inspectedEdges,
|
|
4245
|
+
truncated: subgraph.truncated
|
|
4246
|
+
}
|
|
4247
|
+
};
|
|
4248
|
+
}
|
|
4249
|
+
|
|
4250
|
+
// dist/sdk/graph/governance.js
|
|
4251
|
+
var DEFAULT_MAX_SAMPLE_SIZE = 25;
|
|
4252
|
+
var SEVERITY_RANK = {
|
|
4253
|
+
error: 0,
|
|
4254
|
+
warning: 1,
|
|
4255
|
+
info: 2
|
|
4256
|
+
};
|
|
4257
|
+
function buildFinding(code, severity, policy, describe, subjects, maxSampleSize, remediation) {
|
|
4258
|
+
const sorted = [...subjects].sort((left, right) => left.localeCompare(right));
|
|
4259
|
+
return {
|
|
4260
|
+
code,
|
|
4261
|
+
severity,
|
|
4262
|
+
policy,
|
|
4263
|
+
message: describe(sorted.length),
|
|
4264
|
+
count: sorted.length,
|
|
4265
|
+
sample: sorted.slice(0, maxSampleSize),
|
|
4266
|
+
sample_truncated: sorted.length > maxSampleSize,
|
|
4267
|
+
remediation
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
function buildOrderingAdjacency(assembly) {
|
|
4271
|
+
const registry = assembly.graph.registry();
|
|
4272
|
+
const successors = /* @__PURE__ */ new Map();
|
|
4273
|
+
for (const edge of assembly.graph.edges()) {
|
|
4274
|
+
const definition = registry.require(edge.kind);
|
|
4275
|
+
if (!definition.ordering)
|
|
4276
|
+
continue;
|
|
4277
|
+
const [predecessor, successor] = (definition.precedence ?? "source_before_target") === "target_before_source" ? [edge.target, edge.source] : [edge.source, edge.target];
|
|
4278
|
+
const adjacent = successors.get(predecessor);
|
|
4279
|
+
if (adjacent)
|
|
4280
|
+
adjacent.push(successor);
|
|
4281
|
+
else
|
|
4282
|
+
successors.set(predecessor, [successor]);
|
|
4283
|
+
}
|
|
4284
|
+
for (const adjacent of successors.values())
|
|
4285
|
+
adjacent.sort((left, right) => left.localeCompare(right));
|
|
4286
|
+
return successors;
|
|
4287
|
+
}
|
|
4288
|
+
function registerTarjanNode(node, state) {
|
|
4289
|
+
state.indexes.set(node, state.nextIndex);
|
|
4290
|
+
state.lowLinks.set(node, state.nextIndex);
|
|
4291
|
+
state.nextIndex += 1;
|
|
4292
|
+
state.stack.push(node);
|
|
4293
|
+
state.onStack.add(node);
|
|
4294
|
+
}
|
|
4295
|
+
function visitNextTarjanNeighbor(frame, frames, successors, state) {
|
|
4296
|
+
const neighbors = successors.get(frame.node) ?? [];
|
|
4297
|
+
if (frame.neighborIndex >= neighbors.length)
|
|
4298
|
+
return false;
|
|
4299
|
+
const neighbor = neighbors[frame.neighborIndex];
|
|
4300
|
+
frame.neighborIndex += 1;
|
|
4301
|
+
if (!state.indexes.has(neighbor)) {
|
|
4302
|
+
registerTarjanNode(neighbor, state);
|
|
4303
|
+
frames.push({ node: neighbor, neighborIndex: 0 });
|
|
4304
|
+
} else if (state.onStack.has(neighbor)) {
|
|
4305
|
+
state.lowLinks.set(frame.node, Math.min(state.lowLinks.get(frame.node), state.indexes.get(neighbor)));
|
|
4306
|
+
}
|
|
4307
|
+
return true;
|
|
4308
|
+
}
|
|
4309
|
+
function completeTarjanFrame(frame, frames, successors, state) {
|
|
4310
|
+
frames.pop();
|
|
4311
|
+
const parent = frames.at(-1);
|
|
4312
|
+
if (parent)
|
|
4313
|
+
state.lowLinks.set(parent.node, Math.min(state.lowLinks.get(parent.node), state.lowLinks.get(frame.node)));
|
|
4314
|
+
if (state.lowLinks.get(frame.node) !== state.indexes.get(frame.node))
|
|
4315
|
+
return;
|
|
4316
|
+
const component = [];
|
|
4317
|
+
while (true) {
|
|
4318
|
+
const member = state.stack.pop();
|
|
4319
|
+
state.onStack.delete(member);
|
|
4320
|
+
component.push(member);
|
|
4321
|
+
if (member === frame.node)
|
|
4322
|
+
break;
|
|
4323
|
+
}
|
|
4324
|
+
if (component.length > 1 || component.length === 1 && successors.get(component[0])?.includes(component[0]))
|
|
4325
|
+
state.components.push(component.sort((left, right) => left.localeCompare(right)));
|
|
4326
|
+
}
|
|
4327
|
+
function collectOrderingCycles(successors) {
|
|
4328
|
+
const state = {
|
|
4329
|
+
indexes: /* @__PURE__ */ new Map(),
|
|
4330
|
+
lowLinks: /* @__PURE__ */ new Map(),
|
|
4331
|
+
onStack: /* @__PURE__ */ new Set(),
|
|
4332
|
+
stack: [],
|
|
4333
|
+
components: [],
|
|
4334
|
+
nextIndex: 0
|
|
4335
|
+
};
|
|
4336
|
+
const roots = [...successors.keys()].sort((left, right) => left.localeCompare(right));
|
|
4337
|
+
for (const root of roots) {
|
|
4338
|
+
if (state.indexes.has(root))
|
|
4339
|
+
continue;
|
|
4340
|
+
const frames = [{ node: root, neighborIndex: 0 }];
|
|
4341
|
+
registerTarjanNode(root, state);
|
|
4342
|
+
while (frames.length > 0) {
|
|
4343
|
+
const frame = frames.at(-1);
|
|
4344
|
+
if (visitNextTarjanNeighbor(frame, frames, successors, state))
|
|
4345
|
+
continue;
|
|
4346
|
+
completeTarjanFrame(frame, frames, successors, state);
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
return state.components.sort((left, right) => left[0].localeCompare(right[0]));
|
|
4350
|
+
}
|
|
4351
|
+
function formatDanglingReference(reference) {
|
|
4352
|
+
return `${reference.holder_id} -> ${reference.target_id} (${reference.kind})`;
|
|
4353
|
+
}
|
|
4354
|
+
function appendFinding(findings, subjects, maxSampleSize, code, severity, policy, describe, remediation) {
|
|
4355
|
+
if (subjects.length === 0)
|
|
4356
|
+
return;
|
|
4357
|
+
findings.push(buildFinding(code, severity, policy, describe, subjects, maxSampleSize, remediation));
|
|
4358
|
+
}
|
|
4359
|
+
function collectIntegrityFindings(assembly, isTerminal, maxSampleSize) {
|
|
4360
|
+
const findings = [];
|
|
4361
|
+
const references = [
|
|
4362
|
+
...assembly.dangling.active,
|
|
4363
|
+
...assembly.dangling.legacy_terminal
|
|
4364
|
+
].filter((reference) => !reference.no_active_blocker_sentinel);
|
|
4365
|
+
appendFinding(findings, references.filter((reference) => !isTerminal(reference.holder_status)).map(formatDanglingReference), maxSampleSize, "missing_reference_active", "error", "Active items must not reference absent targets; missing prerequisites distort scheduling.", (count) => `${count} active dangling reference(s) to absent items`, "Restore or re-create the referenced item, or remove/retype the reference on the holder.");
|
|
4366
|
+
appendFinding(findings, references.filter((reference) => isTerminal(reference.holder_status)).map(formatDanglingReference), maxSampleSize, "missing_reference_terminal", "info", "Terminal items may retain historical references, but absent targets remain unexplainable context.", (count) => `${count} terminal dangling reference(s) to absent items`, "Leave as history debt or clean up in a dedicated changelog-safe closed-item batch.");
|
|
4367
|
+
appendFinding(findings, assembly.dangling.no_active_blocker_sentinels.map(formatDanglingReference), maxSampleSize, "legacy_no_blocker_sentinel", "info", "The pre-structured-dependency no-active-blocker sentinel is retired; real edges carry blocker state.", (count) => `${count} legacy no-active-blocker sentinel reference(s)`, "Delete the sentinel reference; blocker state is derived from blocked_by edges.");
|
|
4368
|
+
return findings;
|
|
4369
|
+
}
|
|
4370
|
+
function isActiveAuditMember(member, nodeStates) {
|
|
4371
|
+
const state = nodeStates.get(member);
|
|
4372
|
+
if (!state)
|
|
4373
|
+
return true;
|
|
4374
|
+
return !state.terminal;
|
|
4375
|
+
}
|
|
4376
|
+
function collectOrderingFindings(assembly, nodeStates, isBlocked, maxSampleSize) {
|
|
4377
|
+
const findings = [];
|
|
4378
|
+
const orderingAdjacency = buildOrderingAdjacency(assembly);
|
|
4379
|
+
for (const cycle of collectOrderingCycles(orderingAdjacency)) {
|
|
4380
|
+
const active = cycle.some((member) => isActiveAuditMember(member, nodeStates));
|
|
4381
|
+
findings.push(active ? buildFinding("ordering_cycle", "error", "Order-bearing relationship kinds must stay acyclic; a cycle makes every member unschedulable.", (count) => `execution-order cycle across ${count} item(s)`, cycle, maxSampleSize, "Remove or retype one ordering edge inside the cycle, or split the work so precedence is linear.") : buildFinding("legacy_ordering_cycle", "info", "Ordering cycles between exclusively terminal items are historical contradictions with no scheduling effect.", (count) => `terminal-only execution-order cycle across ${count} item(s)`, cycle, maxSampleSize, "Leave as history debt, or clean up in a dedicated changelog-safe closed-item batch; never repair closed items ad hoc."));
|
|
4382
|
+
}
|
|
4383
|
+
const predecessorsByNode = /* @__PURE__ */ new Map();
|
|
4384
|
+
for (const [predecessor, adjacent] of orderingAdjacency)
|
|
4385
|
+
for (const successor of adjacent) {
|
|
4386
|
+
const predecessors = predecessorsByNode.get(successor);
|
|
4387
|
+
if (predecessors)
|
|
4388
|
+
predecessors.push(predecessor);
|
|
4389
|
+
else
|
|
4390
|
+
predecessorsByNode.set(successor, [predecessor]);
|
|
4391
|
+
}
|
|
4392
|
+
const staleLifecycleBlocks = [...nodeStates.values()].filter((state) => !state.missing && !state.terminal && isBlocked(state.status) && !(predecessorsByNode.get(state.id) ?? []).some((predecessor) => {
|
|
4393
|
+
const predecessorState = nodeStates.get(predecessor);
|
|
4394
|
+
return predecessorState === void 0 || !predecessorState.terminal;
|
|
4395
|
+
})).map((state) => state.id);
|
|
4396
|
+
appendFinding(findings, staleLifecycleBlocks, maxSampleSize, "stale_lifecycle_block", "warning", "A blocked lifecycle status must be backed by at least one open ordering predecessor.", (count) => `${count} status-blocked item(s) with no open blocker edge`, "Re-open the missing prerequisite as an edge, or move the item back to an active status.");
|
|
4397
|
+
return findings;
|
|
4398
|
+
}
|
|
4399
|
+
function formatDuplicateEdgeGroup(group) {
|
|
4400
|
+
const kinds = group.edges.map((edge) => edge.kind).sort((left, right) => left.localeCompare(right));
|
|
4401
|
+
return `${group.from} -> ${group.to} (${kinds.join(" + ")})`;
|
|
4402
|
+
}
|
|
4403
|
+
function collectDuplicateRelationshipEdgeGroups(assembly) {
|
|
4404
|
+
const registry = assembly.graph.registry();
|
|
4405
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4406
|
+
for (const edge of assembly.graph.edges()) {
|
|
4407
|
+
const definition = registry.require(edge.kind);
|
|
4408
|
+
if (!isTransitiveKind(definition))
|
|
4409
|
+
continue;
|
|
4410
|
+
const oriented = orientTransitiveEdge(edge, definition);
|
|
4411
|
+
if (oriented.from === oriented.to)
|
|
4412
|
+
continue;
|
|
4413
|
+
const key = `${transitiveFamilyKey(definition)}::${oriented.from}::${oriented.to}`;
|
|
4414
|
+
const group = groups.get(key);
|
|
4415
|
+
if (group)
|
|
4416
|
+
group.edges.push(edge);
|
|
4417
|
+
else
|
|
4418
|
+
groups.set(key, { ...oriented, edges: [edge] });
|
|
4419
|
+
}
|
|
4420
|
+
const duplicated = [...groups.values()].filter((group) => group.edges.length >= 2);
|
|
4421
|
+
for (const group of duplicated)
|
|
4422
|
+
group.edges.sort((left, right) => left.kind.localeCompare(right.kind));
|
|
4423
|
+
return duplicated.sort((left, right) => left.from.localeCompare(right.from) || left.to.localeCompare(right.to));
|
|
4424
|
+
}
|
|
4425
|
+
function collectDuplicateEdgeFindings(assembly, nodeStates, maxSampleSize) {
|
|
4426
|
+
const active = [];
|
|
4427
|
+
const legacy = [];
|
|
4428
|
+
for (const group of collectDuplicateRelationshipEdgeGroups(assembly)) {
|
|
4429
|
+
const subjects = isActiveAuditMember(group.from, nodeStates) || isActiveAuditMember(group.to, nodeStates) ? active : legacy;
|
|
4430
|
+
subjects.push(formatDuplicateEdgeGroup(group));
|
|
4431
|
+
}
|
|
4432
|
+
const findings = [];
|
|
4433
|
+
appendFinding(findings, active, maxSampleSize, "duplicate_edge", "info", "One semantic relationship should be stored once; parallel same-family spellings (reciprocal inverse pairs included) add no information and skew degree metrics.", (count) => `${count} duplicated relationship(s) between active endpoints`, "Remove all but one stored spelling of the relationship; keep the canonical direction the holder declared first.");
|
|
4434
|
+
appendFinding(findings, legacy, maxSampleSize, "legacy_duplicate_edge", "info", "Duplicated spellings between exclusively terminal items are historical noise with no scheduling effect.", (count) => `${count} duplicated relationship(s) between terminal endpoints`, "Leave as history debt or clean up in a dedicated changelog-safe closed-item batch.");
|
|
4435
|
+
return findings;
|
|
4436
|
+
}
|
|
4437
|
+
function collectCoverageReport(assembly, nodeStates, exemptIsolates, maxSampleSize, edgesByKind) {
|
|
4438
|
+
let activeNodes = 0;
|
|
4439
|
+
let missingNodes = 0;
|
|
4440
|
+
let isolatedActiveNodes = 0;
|
|
4441
|
+
let degreeLeqOneActive = 0;
|
|
4442
|
+
const isolates = [];
|
|
4443
|
+
const sparse = [];
|
|
4444
|
+
for (const id of assembly.graph.nodes()) {
|
|
4445
|
+
const state = nodeStates.get(id);
|
|
4446
|
+
if (!state)
|
|
4447
|
+
continue;
|
|
4448
|
+
if (state.missing) {
|
|
4449
|
+
missingNodes += 1;
|
|
4450
|
+
continue;
|
|
4451
|
+
}
|
|
4452
|
+
if (state.terminal)
|
|
4453
|
+
continue;
|
|
4454
|
+
activeNodes += 1;
|
|
4455
|
+
const degree = assembly.graph.incidentEdges(id).length;
|
|
4456
|
+
if (degree > 1)
|
|
4457
|
+
continue;
|
|
4458
|
+
degreeLeqOneActive += 1;
|
|
4459
|
+
if (degree === 0)
|
|
4460
|
+
isolatedActiveNodes += 1;
|
|
4461
|
+
if (exemptIsolates.has(id.toLowerCase()))
|
|
4462
|
+
continue;
|
|
4463
|
+
if (degree === 0)
|
|
4464
|
+
isolates.push(id);
|
|
4465
|
+
else
|
|
4466
|
+
sparse.push(id);
|
|
4467
|
+
}
|
|
4468
|
+
const findings = [];
|
|
4469
|
+
appendFinding(findings, isolates, maxSampleSize, "isolated_active_node", "warning", "Active work should be reachable from the graph unless explicitly declared a valid isolate.", (count) => `${count} active item(s) with no relationships`, "Link the item to its parent, prerequisite, or origin \u2014 or register it as an exempt isolate.");
|
|
4470
|
+
appendFinding(findings, sparse, maxSampleSize, "sparse_active_node", "info", "Active items with a single edge often miss an honest semantic partner; sparse is not automatically defective.", (count) => `${count} active item(s) with exactly one relationship`, "Investigate for an honest second edge (story->task, defect family, cross-epic complement); do not fabricate one.");
|
|
4471
|
+
return {
|
|
4472
|
+
findings,
|
|
4473
|
+
profile: {
|
|
4474
|
+
nodes: assembly.graph.nodes().length,
|
|
4475
|
+
edges: assembly.graph.edges().length,
|
|
4476
|
+
edges_by_kind: Object.fromEntries(Object.entries(edgesByKind).sort(([left], [right]) => left.localeCompare(right))),
|
|
4477
|
+
active_nodes: activeNodes,
|
|
4478
|
+
missing_nodes: missingNodes,
|
|
4479
|
+
isolated_active_nodes: isolatedActiveNodes,
|
|
4480
|
+
degree_leq_one_active_nodes: degreeLeqOneActive
|
|
4481
|
+
}
|
|
4482
|
+
};
|
|
4483
|
+
}
|
|
4484
|
+
function auditWorkspaceRelationshipGraph(assembly, options = {}) {
|
|
4485
|
+
const isTerminal = options.isTerminal ?? ((status) => status === "closed" || status === "canceled");
|
|
4486
|
+
const isBlocked = options.isBlocked ?? ((status) => status === "blocked");
|
|
4487
|
+
const maxSampleSize = options.maxSampleSize ?? DEFAULT_MAX_SAMPLE_SIZE;
|
|
4488
|
+
if (!Number.isInteger(maxSampleSize) || maxSampleSize < 1)
|
|
4489
|
+
throw new TypeError(`Invalid audit sample bound: ${String(options.maxSampleSize)}`);
|
|
4490
|
+
const exemptIsolates = new Set((options.exemptIsolates ?? []).filter((id) => typeof id === "string").map((id) => id.trim().toLowerCase()));
|
|
4491
|
+
const nodeStates = new Map(assembly.details.map((detail) => [
|
|
4492
|
+
detail.id,
|
|
4493
|
+
{
|
|
4494
|
+
id: detail.id,
|
|
4495
|
+
status: detail.status,
|
|
4496
|
+
missing: assembly.missingIdSet.has(detail.id.toLowerCase()),
|
|
4497
|
+
terminal: isTerminal(detail.status)
|
|
4498
|
+
}
|
|
4499
|
+
]));
|
|
4500
|
+
options.signal?.throwIfAborted();
|
|
4501
|
+
const edgesByKind = {};
|
|
4502
|
+
for (const edge of assembly.graph.edges())
|
|
4503
|
+
edgesByKind[edge.kind] = (edgesByKind[edge.kind] ?? 0) + 1;
|
|
4504
|
+
const findings = collectIntegrityFindings(assembly, isTerminal, maxSampleSize);
|
|
4505
|
+
options.signal?.throwIfAborted();
|
|
4506
|
+
findings.push(...collectOrderingFindings(assembly, nodeStates, isBlocked, maxSampleSize));
|
|
4507
|
+
options.signal?.throwIfAborted();
|
|
4508
|
+
findings.push(...collectDuplicateEdgeFindings(assembly, nodeStates, maxSampleSize));
|
|
4509
|
+
options.signal?.throwIfAborted();
|
|
4510
|
+
const coverage = collectCoverageReport(assembly, nodeStates, exemptIsolates, maxSampleSize, edgesByKind);
|
|
4511
|
+
findings.push(...coverage.findings);
|
|
4512
|
+
findings.sort((left, right) => SEVERITY_RANK[left.severity] - SEVERITY_RANK[right.severity] || left.code.localeCompare(right.code) || left.sample[0].localeCompare(right.sample[0]));
|
|
4513
|
+
return {
|
|
4514
|
+
findings,
|
|
4515
|
+
profile: coverage.profile
|
|
4516
|
+
};
|
|
4517
|
+
}
|
|
4518
|
+
|
|
4519
|
+
// dist/sdk/graph/remediation.js
|
|
4520
|
+
var FINDING_STEP_TEMPLATES = {
|
|
4521
|
+
missing_reference_active: {
|
|
4522
|
+
op: "investigate",
|
|
4523
|
+
confidence: "medium",
|
|
4524
|
+
rationale: "Restore or re-create the referenced item, or remove/retype the reference on the active holder; the correct fix depends on why the target is absent."
|
|
4525
|
+
},
|
|
4526
|
+
missing_reference_terminal: {
|
|
4527
|
+
op: "waive",
|
|
4528
|
+
confidence: "high",
|
|
4529
|
+
rationale: "Terminal-holder reference to an absent item is historical debt; waive it or clean it up only in a dedicated changelog-safe closed-item batch."
|
|
4530
|
+
},
|
|
4531
|
+
legacy_no_blocker_sentinel: {
|
|
4532
|
+
op: "remove",
|
|
4533
|
+
confidence: "high",
|
|
4534
|
+
rationale: "The pre-structured-dependency no-active-blocker sentinel is retired and carries no information; blocker state derives from blocked_by edges."
|
|
4535
|
+
},
|
|
4536
|
+
ordering_cycle: {
|
|
4537
|
+
op: "investigate",
|
|
4538
|
+
confidence: "low",
|
|
4539
|
+
rationale: "Every cycle member is unschedulable until one ordering edge is removed or retyped; the planner never chooses which edge to cut."
|
|
4540
|
+
},
|
|
4541
|
+
legacy_ordering_cycle: {
|
|
4542
|
+
op: "waive",
|
|
4543
|
+
confidence: "high",
|
|
4544
|
+
rationale: "Terminal-only ordering cycles have no scheduling effect; repairing them would mutate closed history (changelog drag)."
|
|
4545
|
+
},
|
|
4546
|
+
// duplicate_edge findings are expanded into per-stored-edge remove steps by
|
|
4547
|
+
// the planner itself (see stepsFromDuplicateGroup); this template documents
|
|
4548
|
+
// the family for exhaustiveness and backs any future sample-only fallback.
|
|
4549
|
+
duplicate_edge: {
|
|
4550
|
+
op: "remove",
|
|
4551
|
+
confidence: "high",
|
|
4552
|
+
rationale: "Parallel same-family spellings state one relationship twice; remove all but one stored spelling, keeping the holder's canonical direction."
|
|
4553
|
+
},
|
|
4554
|
+
legacy_duplicate_edge: {
|
|
4555
|
+
op: "waive",
|
|
4556
|
+
confidence: "high",
|
|
4557
|
+
rationale: "Duplicated spellings between terminal items are historical noise; waive or batch changelog-safe cleanup."
|
|
4558
|
+
},
|
|
4559
|
+
stale_lifecycle_block: {
|
|
4560
|
+
op: "investigate",
|
|
4561
|
+
confidence: "medium",
|
|
4562
|
+
rationale: "Re-open the missing prerequisite as an ordering edge, or move the item back to an active status; only the holder's owner knows which is true."
|
|
4563
|
+
},
|
|
4564
|
+
isolated_active_node: {
|
|
4565
|
+
op: "investigate",
|
|
4566
|
+
confidence: "medium",
|
|
4567
|
+
rationale: "Link the item to its parent, prerequisite, or origin \u2014 or register it as an explicitly exempt isolate; the audit never fabricates an edge."
|
|
4568
|
+
},
|
|
4569
|
+
sparse_active_node: {
|
|
4570
|
+
op: "investigate",
|
|
4571
|
+
confidence: "low",
|
|
4572
|
+
rationale: "Investigate for an honest second edge (story-to-task, defect family, cross-epic complement); sparse is not automatically defective."
|
|
4573
|
+
}
|
|
4574
|
+
};
|
|
4575
|
+
function formatStoredEdge(edge) {
|
|
4576
|
+
return `${edge.source} -${edge.kind}-> ${edge.target}`;
|
|
4577
|
+
}
|
|
4578
|
+
function stepsFromDuplicateGroup(group) {
|
|
4579
|
+
const [keeper, ...extras] = group.edges;
|
|
4580
|
+
return extras.map((edge) => ({
|
|
4581
|
+
op: "remove",
|
|
4582
|
+
code: "duplicate_edge",
|
|
4583
|
+
subject: formatStoredEdge(edge),
|
|
4584
|
+
rationale: "This stored spelling restates the kept canonical edge of the same semantic family; removing it leaves the relationship stated exactly once.",
|
|
4585
|
+
evidence: [
|
|
4586
|
+
`keep: ${formatStoredEdge(keeper)}`,
|
|
4587
|
+
`group: ${formatDuplicateEdgeGroup(group)}`
|
|
4588
|
+
],
|
|
4589
|
+
confidence: "high"
|
|
4590
|
+
}));
|
|
4591
|
+
}
|
|
4592
|
+
function stepsFromFinding(finding, duplicateGroups) {
|
|
4593
|
+
if (finding.code === "duplicate_edge") {
|
|
4594
|
+
return finding.sample.flatMap((subject) => stepsFromDuplicateGroup(duplicateGroups.get(subject)));
|
|
4595
|
+
}
|
|
4596
|
+
const template = FINDING_STEP_TEMPLATES[finding.code];
|
|
4597
|
+
return finding.sample.map((subject) => ({
|
|
4598
|
+
op: template.op,
|
|
4599
|
+
code: finding.code,
|
|
4600
|
+
subject,
|
|
4601
|
+
rationale: template.rationale,
|
|
4602
|
+
evidence: [finding.policy],
|
|
4603
|
+
confidence: template.confidence
|
|
4604
|
+
}));
|
|
4605
|
+
}
|
|
4606
|
+
function planRelationshipRemediation(assembly, options = {}) {
|
|
4607
|
+
const { redundancyLimit, ...auditOptions } = options;
|
|
4608
|
+
const report = auditWorkspaceRelationshipGraph(assembly, auditOptions);
|
|
4609
|
+
const duplicateGroups = new Map(collectDuplicateRelationshipEdgeGroups(assembly).map((group) => [
|
|
4610
|
+
formatDuplicateEdgeGroup(group),
|
|
4611
|
+
group
|
|
4612
|
+
]));
|
|
4613
|
+
const steps = report.findings.flatMap((finding) => stepsFromFinding(finding, duplicateGroups));
|
|
4614
|
+
let truncated = report.findings.some((finding) => finding.sample_truncated);
|
|
4615
|
+
options.signal?.throwIfAborted();
|
|
4616
|
+
const redundancy = findRedundantRelationshipEdges(assembly.graph, {
|
|
4617
|
+
limit: redundancyLimit ?? options.maxSampleSize ?? 25,
|
|
4618
|
+
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
4619
|
+
});
|
|
4620
|
+
for (const row of redundancy.value) {
|
|
4621
|
+
steps.push({
|
|
4622
|
+
op: "remove",
|
|
4623
|
+
code: "redundant_edge",
|
|
4624
|
+
subject: `${row.edge.source} -> ${row.edge.target} (${row.edge.kind})`,
|
|
4625
|
+
rationale: "The stored edge is implied by a longer same-family witness path; shortcut edges are sometimes deliberate emphasis, so confirm intent before removing.",
|
|
4626
|
+
evidence: [`witness: ${row.witness.join(" -> ")}`],
|
|
4627
|
+
confidence: "medium"
|
|
4628
|
+
});
|
|
4629
|
+
}
|
|
4630
|
+
truncated = truncated || redundancy.meta.truncated;
|
|
4631
|
+
return {
|
|
4632
|
+
steps,
|
|
4633
|
+
report,
|
|
4634
|
+
truncated,
|
|
4635
|
+
cost: {
|
|
4636
|
+
visitedNodes: redundancy.meta.visitedNodes,
|
|
4637
|
+
inspectedEdges: redundancy.meta.inspectedEdges
|
|
4638
|
+
}
|
|
4639
|
+
};
|
|
4640
|
+
}
|
|
4641
|
+
|
|
4642
|
+
// dist/sdk/graph/run.js
|
|
4643
|
+
var ROOTED_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
4644
|
+
"ancestors",
|
|
4645
|
+
"descendants",
|
|
4646
|
+
"predecessors",
|
|
4647
|
+
"successors",
|
|
4648
|
+
"paths",
|
|
4649
|
+
"impact",
|
|
4650
|
+
"dominators"
|
|
4651
|
+
]);
|
|
4652
|
+
var DEFAULT_SAMPLE_LIMIT = 10;
|
|
4653
|
+
function normalizeIdList(raw) {
|
|
4654
|
+
if (raw === void 0)
|
|
4655
|
+
return [];
|
|
4656
|
+
return (Array.isArray(raw) ? raw : [raw]).flatMap((value) => value.split(",")).map((value) => value.trim()).filter((value) => value.length > 0);
|
|
4657
|
+
}
|
|
4658
|
+
function parseGraphSubcommand(raw, id, target) {
|
|
4659
|
+
const candidate = raw.trim().toLowerCase();
|
|
4660
|
+
if (!GRAPH_SUBCOMMAND_VALUES.includes(candidate)) {
|
|
4661
|
+
throw new PmCliError(`Invalid graph subcommand "${raw}". Use one of: ${GRAPH_SUBCOMMAND_VALUES.join(", ")}.`, EXIT_CODE.USAGE);
|
|
4662
|
+
}
|
|
4663
|
+
const subcommand = candidate;
|
|
4664
|
+
if (ROOTED_SUBCOMMANDS.has(subcommand) && !id?.trim()) {
|
|
4665
|
+
throw new PmCliError(`graph ${subcommand} requires an item id.`, EXIT_CODE.USAGE);
|
|
4666
|
+
}
|
|
4667
|
+
if (subcommand === "paths" && !target?.trim()) {
|
|
4668
|
+
throw new PmCliError("graph paths requires a source and a target item id.", EXIT_CODE.USAGE);
|
|
4669
|
+
}
|
|
4670
|
+
return subcommand;
|
|
4671
|
+
}
|
|
4672
|
+
function rethrowGraphUsage(error) {
|
|
4673
|
+
if (error instanceof TypeError)
|
|
4674
|
+
throw new PmCliError(error.message, EXIT_CODE.USAGE);
|
|
4675
|
+
throw error;
|
|
4676
|
+
}
|
|
4677
|
+
function projectQueryMeta(meta) {
|
|
4678
|
+
return {
|
|
4679
|
+
truncated: meta.truncated,
|
|
4680
|
+
cost: {
|
|
4681
|
+
visited_nodes: meta.visitedNodes,
|
|
4682
|
+
inspected_edges: meta.inspectedEdges
|
|
4683
|
+
}
|
|
4684
|
+
};
|
|
4685
|
+
}
|
|
4686
|
+
function canonicalizeGraphId(assembly, raw) {
|
|
4687
|
+
const wanted = raw.trim().toLowerCase();
|
|
4688
|
+
for (const detail of assembly.details) {
|
|
4689
|
+
if (detail.id.trim().toLowerCase() === wanted && !assembly.missingIdSet.has(detail.id.toLowerCase())) {
|
|
4690
|
+
return detail.id;
|
|
4691
|
+
}
|
|
4692
|
+
}
|
|
4693
|
+
throw new PmCliError(`Item ${raw} not found`, EXIT_CODE.NOT_FOUND);
|
|
4694
|
+
}
|
|
4695
|
+
function runGraphTraversal(subcommand, root, invocation) {
|
|
4696
|
+
const walk = {
|
|
4697
|
+
ancestors: hierarchyAncestors,
|
|
4698
|
+
descendants: hierarchyDescendants,
|
|
4699
|
+
predecessors: orderingPredecessors,
|
|
4700
|
+
successors: orderingSuccessors
|
|
4701
|
+
}[subcommand];
|
|
4702
|
+
let result;
|
|
4703
|
+
try {
|
|
4704
|
+
result = walk(invocation.assembly.graph, root, {
|
|
4705
|
+
...invocation.kinds === void 0 ? {} : { kinds: invocation.kinds },
|
|
4706
|
+
...invocation.maxDepth === void 0 ? {} : { maxDepth: invocation.maxDepth },
|
|
4707
|
+
...invocation.limit === void 0 ? {} : { limit: invocation.limit },
|
|
4708
|
+
...invocation.after === void 0 ? {} : { after: invocation.after }
|
|
4709
|
+
});
|
|
4710
|
+
} catch (error) {
|
|
4711
|
+
rethrowGraphUsage(error);
|
|
4712
|
+
}
|
|
4713
|
+
const meta = projectQueryMeta(result.meta);
|
|
4714
|
+
return {
|
|
4715
|
+
subcommand,
|
|
4716
|
+
root,
|
|
4717
|
+
count: result.value.length,
|
|
4718
|
+
...meta,
|
|
4719
|
+
...result.meta.nextCursor === void 0 ? {} : { next_cursor: result.meta.nextCursor },
|
|
4720
|
+
...invocation.summary ? {} : { ids: result.value }
|
|
4721
|
+
};
|
|
4722
|
+
}
|
|
4723
|
+
function runGraphPaths(root, target, invocation) {
|
|
4724
|
+
const result = enumerateRelationshipPaths(invocation.assembly.graph, root, target, {
|
|
4725
|
+
direction: invocation.direction,
|
|
4726
|
+
...invocation.kinds === void 0 ? {} : { kinds: invocation.kinds },
|
|
4727
|
+
...invocation.maxDepth === void 0 ? {} : { maxDepth: invocation.maxDepth },
|
|
4728
|
+
...invocation.maxPaths === void 0 ? {} : { maxPaths: invocation.maxPaths }
|
|
4729
|
+
});
|
|
4730
|
+
return {
|
|
4731
|
+
subcommand: "paths",
|
|
4732
|
+
root,
|
|
4733
|
+
target,
|
|
4734
|
+
direction: invocation.direction,
|
|
4735
|
+
count: result.value.length,
|
|
4736
|
+
...projectQueryMeta(result.meta),
|
|
4737
|
+
...invocation.summary ? {} : {
|
|
4738
|
+
paths: result.value.map((path3) => ({
|
|
4739
|
+
nodes: path3.nodes,
|
|
4740
|
+
kinds: path3.edges.map((edge) => edge.kind),
|
|
4741
|
+
length: path3.length
|
|
4742
|
+
}))
|
|
4743
|
+
}
|
|
4744
|
+
};
|
|
4745
|
+
}
|
|
4746
|
+
function runGraphImpact(root, invocation) {
|
|
4747
|
+
const analysis = analyzeGraphImpact(invocation.assembly.graph, root, {
|
|
4748
|
+
direction: invocation.direction,
|
|
4749
|
+
...invocation.kinds === void 0 ? {} : { kinds: invocation.kinds },
|
|
4750
|
+
...invocation.maxDepth === void 0 ? {} : { maxDepth: invocation.maxDepth },
|
|
4751
|
+
...invocation.limit === void 0 ? {} : { limit: invocation.limit }
|
|
4752
|
+
});
|
|
4753
|
+
return {
|
|
4754
|
+
subcommand: "impact",
|
|
4755
|
+
root,
|
|
4756
|
+
direction: invocation.direction,
|
|
4757
|
+
count: analysis.affected.length,
|
|
4758
|
+
truncated: analysis.truncated,
|
|
4759
|
+
cost: {
|
|
4760
|
+
visited_nodes: analysis.cost.visitedNodes,
|
|
4761
|
+
inspected_edges: analysis.cost.inspectedEdges
|
|
4762
|
+
},
|
|
4763
|
+
...invocation.summary ? {} : { affected: analysis.affected }
|
|
4764
|
+
};
|
|
4765
|
+
}
|
|
4766
|
+
function runGraphAnalyze(invocation) {
|
|
4767
|
+
const graph = invocation.assembly.graph;
|
|
4768
|
+
const sampleLimit = invocation.limit ?? DEFAULT_SAMPLE_LIMIT;
|
|
4769
|
+
const execution = analyzeRelationshipExecution(graph, {
|
|
4770
|
+
registry: graph.registry()
|
|
4771
|
+
});
|
|
4772
|
+
const knowledge = analyzeKnowledgeGraph(graph);
|
|
4773
|
+
return {
|
|
4774
|
+
subcommand: "analyze",
|
|
4775
|
+
node_count: graph.nodes().length,
|
|
4776
|
+
edge_count: graph.edges().length,
|
|
4777
|
+
sample_limit: sampleLimit,
|
|
4778
|
+
execution: {
|
|
4779
|
+
acyclic: execution.acyclic,
|
|
4780
|
+
ordered_node_count: execution.order.length,
|
|
4781
|
+
layer_count: execution.layers.length,
|
|
4782
|
+
frontier_count: execution.frontier.length,
|
|
4783
|
+
critical_path_length: execution.criticalPathLength,
|
|
4784
|
+
cycle_count: execution.cycles.length,
|
|
4785
|
+
...invocation.summary ? {} : {
|
|
4786
|
+
frontier: execution.frontier.slice(0, sampleLimit),
|
|
4787
|
+
critical_path: execution.criticalPath.slice(0, sampleLimit),
|
|
4788
|
+
cycles: execution.cycles.slice(0, sampleLimit)
|
|
4789
|
+
}
|
|
4790
|
+
},
|
|
4791
|
+
knowledge: {
|
|
4792
|
+
component_count: knowledge.components.length,
|
|
4793
|
+
largest_component_size: knowledge.components[0]?.length ?? 0,
|
|
4794
|
+
orphan_count: knowledge.orphans.length,
|
|
4795
|
+
...invocation.summary ? {} : {
|
|
4796
|
+
orphans: knowledge.orphans.slice(0, sampleLimit),
|
|
4797
|
+
hubs: knowledge.hubs.slice(0, sampleLimit)
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4800
|
+
};
|
|
4801
|
+
}
|
|
4802
|
+
function runGraphAudit(invocation, isTerminal) {
|
|
4803
|
+
const report = auditWorkspaceRelationshipGraph(invocation.assembly, {
|
|
4804
|
+
isTerminal,
|
|
4805
|
+
...invocation.sample === void 0 ? {} : { maxSampleSize: invocation.sample },
|
|
4806
|
+
...invocation.exemptIsolates.length === 0 ? {} : { exemptIsolates: invocation.exemptIsolates }
|
|
4807
|
+
});
|
|
4808
|
+
const bySeverity = {};
|
|
4809
|
+
const byCode = {};
|
|
4810
|
+
for (const finding of report.findings) {
|
|
4811
|
+
bySeverity[finding.severity] = (bySeverity[finding.severity] ?? 0) + 1;
|
|
4812
|
+
byCode[finding.code] = (byCode[finding.code] ?? 0) + finding.count;
|
|
4813
|
+
}
|
|
4814
|
+
return {
|
|
4815
|
+
subcommand: "audit",
|
|
4816
|
+
finding_count: report.findings.length,
|
|
4817
|
+
findings_by_severity: bySeverity,
|
|
4818
|
+
findings_by_code: byCode,
|
|
4819
|
+
profile: report.profile,
|
|
4820
|
+
...invocation.summary ? {} : { findings: report.findings }
|
|
4821
|
+
};
|
|
4822
|
+
}
|
|
4823
|
+
function runGraphCommunities(invocation) {
|
|
4824
|
+
const sampleLimit = invocation.limit ?? DEFAULT_SAMPLE_LIMIT;
|
|
4825
|
+
const result = detectRelationshipCommunities(invocation.assembly.graph, {
|
|
4826
|
+
...invocation.kinds === void 0 ? {} : { kinds: invocation.kinds }
|
|
4827
|
+
});
|
|
4828
|
+
const analysis = result.value;
|
|
4829
|
+
return {
|
|
4830
|
+
subcommand: "communities",
|
|
4831
|
+
community_count: analysis.communities.length,
|
|
4832
|
+
largest_community_size: analysis.communities[0]?.size ?? 0,
|
|
4833
|
+
iterations: analysis.iterations,
|
|
4834
|
+
converged: analysis.converged,
|
|
4835
|
+
truncated: !analysis.converged || analysis.communities.length > sampleLimit,
|
|
4836
|
+
cost: {
|
|
4837
|
+
visited_nodes: result.meta.visitedNodes,
|
|
4838
|
+
inspected_edges: result.meta.inspectedEdges
|
|
4839
|
+
},
|
|
4840
|
+
...invocation.summary ? {} : {
|
|
4841
|
+
communities: analysis.communities.slice(0, sampleLimit).map((community) => ({
|
|
4842
|
+
representative: community.representative,
|
|
4843
|
+
size: community.size,
|
|
4844
|
+
members: community.members.slice(0, sampleLimit)
|
|
4845
|
+
}))
|
|
4846
|
+
}
|
|
4847
|
+
};
|
|
4848
|
+
}
|
|
4849
|
+
function runGraphRedundancy(invocation) {
|
|
4850
|
+
let result;
|
|
4851
|
+
try {
|
|
4852
|
+
result = findRedundantRelationshipEdges(invocation.assembly.graph, {
|
|
4853
|
+
...invocation.kinds === void 0 ? {} : { kinds: invocation.kinds },
|
|
4854
|
+
...invocation.maxDepth === void 0 ? {} : { maxDepth: invocation.maxDepth },
|
|
4855
|
+
...invocation.limit === void 0 ? {} : { limit: invocation.limit }
|
|
4856
|
+
});
|
|
4857
|
+
} catch (error) {
|
|
4858
|
+
rethrowGraphUsage(error);
|
|
4859
|
+
}
|
|
4860
|
+
return {
|
|
4861
|
+
subcommand: "redundancy",
|
|
4862
|
+
redundant_count: result.value.length,
|
|
4863
|
+
...projectQueryMeta(result.meta),
|
|
4864
|
+
...invocation.summary ? {} : {
|
|
4865
|
+
redundant: result.value.map((row) => ({
|
|
4866
|
+
source: row.edge.source,
|
|
4867
|
+
target: row.edge.target,
|
|
4868
|
+
kind: row.edge.kind,
|
|
4869
|
+
witness: row.witness
|
|
4870
|
+
}))
|
|
4871
|
+
}
|
|
4872
|
+
};
|
|
4873
|
+
}
|
|
4874
|
+
function runGraphDominators(root, invocation) {
|
|
4875
|
+
const limit = invocation.limit ?? DEFAULT_SAMPLE_LIMIT;
|
|
4876
|
+
const result = computeRelationshipDominators(invocation.assembly.graph, root, {
|
|
4877
|
+
direction: invocation.direction,
|
|
4878
|
+
...invocation.kinds === void 0 ? {} : { kinds: invocation.kinds },
|
|
4879
|
+
...invocation.maxDepth === void 0 ? {} : { maxDepth: invocation.maxDepth }
|
|
4880
|
+
});
|
|
4881
|
+
const bottlenecks = result.value.rows.filter((row) => row.dominatedCount > 0);
|
|
4882
|
+
return {
|
|
4883
|
+
subcommand: "dominators",
|
|
4884
|
+
root,
|
|
4885
|
+
direction: invocation.direction,
|
|
4886
|
+
reachable_count: result.value.reachableCount,
|
|
4887
|
+
bottleneck_count: bottlenecks.length,
|
|
4888
|
+
truncated: result.meta.truncated || bottlenecks.length > limit,
|
|
4889
|
+
cost: {
|
|
4890
|
+
visited_nodes: result.meta.visitedNodes,
|
|
4891
|
+
inspected_edges: result.meta.inspectedEdges
|
|
4892
|
+
},
|
|
4893
|
+
...invocation.summary ? {} : {
|
|
4894
|
+
bottlenecks: bottlenecks.slice(0, limit).map((row) => ({
|
|
4895
|
+
id: row.id,
|
|
4896
|
+
idom: row.idom,
|
|
4897
|
+
dominated_count: row.dominatedCount
|
|
4898
|
+
}))
|
|
4899
|
+
}
|
|
4900
|
+
};
|
|
4901
|
+
}
|
|
4902
|
+
function runGraphPlan(invocation, isTerminal) {
|
|
4903
|
+
const limit = invocation.limit ?? DEFAULT_SAMPLE_LIMIT;
|
|
4904
|
+
const plan = planRelationshipRemediation(invocation.assembly, {
|
|
4905
|
+
isTerminal,
|
|
4906
|
+
redundancyLimit: limit,
|
|
4907
|
+
...invocation.sample === void 0 ? {} : { maxSampleSize: invocation.sample },
|
|
4908
|
+
...invocation.exemptIsolates.length === 0 ? {} : { exemptIsolates: invocation.exemptIsolates }
|
|
4909
|
+
});
|
|
4910
|
+
const byOp = {};
|
|
4911
|
+
const byCode = {};
|
|
4912
|
+
for (const step of plan.steps) {
|
|
4913
|
+
byOp[step.op] = (byOp[step.op] ?? 0) + 1;
|
|
4914
|
+
byCode[step.code] = (byCode[step.code] ?? 0) + 1;
|
|
4915
|
+
}
|
|
4916
|
+
return {
|
|
4917
|
+
subcommand: "plan",
|
|
4918
|
+
step_count: plan.steps.length,
|
|
4919
|
+
steps_by_op: byOp,
|
|
4920
|
+
steps_by_code: byCode,
|
|
4921
|
+
finding_count: plan.report.findings.length,
|
|
4922
|
+
truncated: plan.truncated || plan.steps.length > limit,
|
|
4923
|
+
cost: {
|
|
4924
|
+
visited_nodes: plan.cost.visitedNodes,
|
|
4925
|
+
inspected_edges: plan.cost.inspectedEdges
|
|
4926
|
+
},
|
|
4927
|
+
...invocation.summary ? {} : { steps: plan.steps.slice(0, limit) }
|
|
4928
|
+
};
|
|
4929
|
+
}
|
|
4930
|
+
function buildGraphQueryKey(subcommand, root, pathsTarget, invocation) {
|
|
4931
|
+
return JSON.stringify({
|
|
4932
|
+
subcommand,
|
|
4933
|
+
root: root ?? null,
|
|
4934
|
+
target: pathsTarget ?? null,
|
|
4935
|
+
kinds: invocation.kinds ?? null,
|
|
4936
|
+
maxDepth: invocation.maxDepth ?? null,
|
|
4937
|
+
limit: invocation.limit ?? null,
|
|
4938
|
+
after: invocation.after ?? null,
|
|
4939
|
+
direction: invocation.direction,
|
|
4940
|
+
maxPaths: invocation.maxPaths ?? null,
|
|
4941
|
+
sample: invocation.sample ?? null,
|
|
4942
|
+
// The audit consumes exemptions as a case-insensitive set, so the key
|
|
4943
|
+
// must not distinguish logically identical spellings or orderings.
|
|
4944
|
+
exemptIsolates: [
|
|
4945
|
+
...new Set(invocation.exemptIsolates.map((id) => id.toLowerCase()))
|
|
4946
|
+
].sort(),
|
|
4947
|
+
summary: invocation.summary
|
|
4948
|
+
});
|
|
4949
|
+
}
|
|
4950
|
+
function executeGraphSubcommand(subcommand, root, pathsTarget, invocation, isTerminal) {
|
|
4951
|
+
if (subcommand === "analyze")
|
|
4952
|
+
return runGraphAnalyze(invocation);
|
|
4953
|
+
if (subcommand === "audit")
|
|
4954
|
+
return runGraphAudit(invocation, isTerminal);
|
|
4955
|
+
if (subcommand === "plan")
|
|
4956
|
+
return runGraphPlan(invocation, isTerminal);
|
|
4957
|
+
if (subcommand === "communities")
|
|
4958
|
+
return runGraphCommunities(invocation);
|
|
4959
|
+
if (subcommand === "redundancy")
|
|
4960
|
+
return runGraphRedundancy(invocation);
|
|
4961
|
+
if (subcommand === "dominators")
|
|
4962
|
+
return runGraphDominators(root, invocation);
|
|
4963
|
+
if (subcommand === "paths")
|
|
4964
|
+
return runGraphPaths(root, pathsTarget, invocation);
|
|
4965
|
+
if (subcommand === "impact")
|
|
4966
|
+
return runGraphImpact(root, invocation);
|
|
4967
|
+
return runGraphTraversal(subcommand, root, invocation);
|
|
4968
|
+
}
|
|
4969
|
+
async function runGraph(subcommandRaw, id, target, options, global) {
|
|
4970
|
+
const subcommand = parseGraphSubcommand(subcommandRaw, id, target);
|
|
4971
|
+
const pmRoot = resolvePmRoot(process.cwd(), global.path);
|
|
4972
|
+
if (!await pathExists(getSettingsPath(pmRoot))) {
|
|
4973
|
+
throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);
|
|
4974
|
+
}
|
|
4975
|
+
const settings = await readSettings(pmRoot);
|
|
4976
|
+
const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());
|
|
4977
|
+
const items = await listAllItemMetadataLight(pmRoot, settings.item_format, typeRegistry.type_to_folder, void 0, settings.schema);
|
|
4978
|
+
const statusRegistry = resolveRuntimeStatusRegistry(settings.schema);
|
|
4979
|
+
const isTerminal = (status) => isTerminalStatus(status, statusRegistry);
|
|
4980
|
+
const kinds = parseKinds(options.kind);
|
|
4981
|
+
const lookup = workspaceGraphCache().lookup(pmRoot, computeWorkspaceGraphFingerprint(items, isTerminal), () => assembleWorkspaceRelationshipGraph(items, isTerminal));
|
|
4982
|
+
const invocation = {
|
|
4983
|
+
assembly: lookup.assembly,
|
|
4984
|
+
...kinds === void 0 ? {} : { kinds },
|
|
4985
|
+
maxDepth: parseMaxDepth(options.maxDepth),
|
|
4986
|
+
limit: parsePositiveInteger(options.limit, "limit"),
|
|
4987
|
+
after: options.after?.trim() || void 0,
|
|
4988
|
+
direction: parseDirection(options.direction),
|
|
4989
|
+
maxPaths: parsePositiveInteger(options.maxPaths, "max-paths"),
|
|
4990
|
+
sample: parsePositiveInteger(options.sample, "sample"),
|
|
4991
|
+
exemptIsolates: normalizeIdList(options.exemptIsolate),
|
|
4992
|
+
summary: options.summary === true
|
|
4993
|
+
};
|
|
4994
|
+
const root = ROOTED_SUBCOMMANDS.has(subcommand) ? canonicalizeGraphId(invocation.assembly, id) : void 0;
|
|
4995
|
+
const pathsTarget = subcommand === "paths" ? canonicalizeGraphId(invocation.assembly, target) : void 0;
|
|
4996
|
+
const memo = lookup.memoize(buildGraphQueryKey(subcommand, root, pathsTarget, invocation), () => executeGraphSubcommand(subcommand, root, pathsTarget, invocation, isTerminal));
|
|
4997
|
+
return {
|
|
4998
|
+
...memo.value,
|
|
4999
|
+
cache: {
|
|
5000
|
+
fingerprint: lookup.fingerprint.slice(0, 12),
|
|
5001
|
+
assembly: lookup.assemblyReused ? "hit" : "miss",
|
|
5002
|
+
result: memo.reused ? "hit" : "miss"
|
|
5003
|
+
}
|
|
5004
|
+
};
|
|
5005
|
+
}
|
|
5006
|
+
|
|
3372
5007
|
export {
|
|
3373
5008
|
runAggregate,
|
|
3374
5009
|
runSearch,
|
|
@@ -3379,8 +5014,26 @@ export {
|
|
|
3379
5014
|
buildItemChildrenRollup,
|
|
3380
5015
|
itemHasSchedule,
|
|
3381
5016
|
buildItemSchedule,
|
|
3382
|
-
runGet
|
|
5017
|
+
runGet,
|
|
5018
|
+
analyzeRelationshipExecution,
|
|
5019
|
+
analyzeGraphImpact,
|
|
5020
|
+
analyzeKnowledgeGraph,
|
|
5021
|
+
compareRelationshipSnapshots,
|
|
5022
|
+
hierarchyAncestors,
|
|
5023
|
+
hierarchyDescendants,
|
|
5024
|
+
orderingPredecessors,
|
|
5025
|
+
orderingSuccessors,
|
|
5026
|
+
enumerateRelationshipPaths,
|
|
5027
|
+
detectRelationshipCommunities,
|
|
5028
|
+
findRedundantRelationshipEdges,
|
|
5029
|
+
computeRelationshipDominators,
|
|
5030
|
+
formatDuplicateEdgeGroup,
|
|
5031
|
+
collectDuplicateRelationshipEdgeGroups,
|
|
5032
|
+
auditWorkspaceRelationshipGraph,
|
|
5033
|
+
planRelationshipRemediation,
|
|
5034
|
+
parseGraphSubcommand,
|
|
5035
|
+
runGraph
|
|
3383
5036
|
};
|
|
3384
|
-
//# sourceMappingURL=chunk-
|
|
5037
|
+
//# sourceMappingURL=chunk-QPGQNLPI.js.map
|
|
3385
5038
|
|
|
3386
|
-
//# debugId=
|
|
5039
|
+
//# debugId=2289448d-a087-55eb-a092-70c2f25227d6
|