@unbrained/pm-cli 2026.9.7 → 2026.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/pm-developer/SKILL.md +12 -4
- package/.agents/skills/pm-developer/references/MULTI_AGENT_MERGE.md +19 -10
- package/.agents/skills/pm-extensions/SKILL.md +6 -0
- package/.agents/skills/pm-sdk/SKILL.md +11 -2
- package/.agents/skills/pm-user/SKILL.md +7 -2
- package/.agents/skills/pm-user/references/ECOSYSTEM_PLANNING.md +95 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +231 -182
- package/dist/cli/after-command-context-usage.js +1 -48
- package/dist/cli/argv-utils.js +1 -40
- package/dist/cli/bootstrap-args.js +1 -9
- package/dist/cli/bundle-integrity.js +2 -110
- package/dist/cli/commander-usage.js +11 -771
- package/dist/cli/commands/activity.js +1 -9
- package/dist/cli/commands/aggregate.js +1 -5
- package/dist/cli/commands/append.js +1 -5
- package/dist/cli/commands/claim.js +1 -5
- package/dist/cli/commands/close-many.js +1 -5
- package/dist/cli/commands/close.js +1 -9
- package/dist/cli/commands/comments.js +1 -5
- package/dist/cli/commands/config.js +1 -9
- package/dist/cli/commands/context.js +1 -9
- package/dist/cli/commands/contracts.js +1 -5
- package/dist/cli/commands/copy.js +1 -9
- package/dist/cli/commands/create.js +1 -9
- package/dist/cli/commands/delete.js +1 -9
- package/dist/cli/commands/deps.js +1 -9
- package/dist/cli/commands/docs.js +1 -9
- package/dist/cli/commands/duplicates.js +1 -9
- package/dist/cli/commands/eval.js +1 -9
- package/dist/cli/commands/extension/describe.js +1 -5
- package/dist/cli/commands/extension/scaffold.js +1 -5
- package/dist/cli/commands/extension/shared.js +1 -5
- package/dist/cli/commands/extension.js +1 -9
- package/dist/cli/commands/files.js +1 -9
- package/dist/cli/commands/focus.js +1 -9
- package/dist/cli/commands/gc.js +1 -9
- package/dist/cli/commands/get.js +1 -9
- package/dist/cli/commands/graph.js +1 -10
- package/dist/cli/commands/health.js +1 -9
- package/dist/cli/commands/history-compact.js +1 -10
- package/dist/cli/commands/history-redact.js +1 -11
- package/dist/cli/commands/history-repair.js +1 -10
- package/dist/cli/commands/history.js +1 -5
- package/dist/cli/commands/index.js +1 -58
- package/dist/cli/commands/init-agent-guidance.js +1 -9
- package/dist/cli/commands/init.js +1 -9
- package/dist/cli/commands/learnings.js +1 -5
- package/dist/cli/commands/lifecycle-transitions.js +1 -5
- package/dist/cli/commands/list.js +1 -9
- package/dist/cli/commands/merge.js +1 -11
- package/dist/cli/commands/next.js +1 -9
- package/dist/cli/commands/notes.js +1 -5
- package/dist/cli/commands/plan.js +1 -9
- package/dist/cli/commands/profile.js +1 -9
- package/dist/cli/commands/restore.js +1 -9
- package/dist/cli/commands/scheduling-shortcuts.js +1 -9
- package/dist/cli/commands/schema.js +1 -10
- package/dist/cli/commands/search.js +1 -9
- package/dist/cli/commands/stats.js +1 -9
- package/dist/cli/commands/telemetry.js +1 -9
- package/dist/cli/commands/test-all.js +1 -9
- package/dist/cli/commands/test-runs.js +1 -9
- package/dist/cli/commands/test.js +1 -9
- package/dist/cli/commands/update-many.js +1 -5
- package/dist/cli/commands/update.js +1 -9
- package/dist/cli/commands/upgrade.js +1 -5
- package/dist/cli/commands/validate.js +1 -15
- package/dist/cli/context-intent-invocation.js +1 -20
- package/dist/cli/description-stdin.js +1 -17
- package/dist/cli/error-guidance.js +1 -1353
- package/dist/cli/extension-command-help.js +5 -636
- package/dist/cli/extension-command-options.js +1 -427
- package/dist/cli/extension-recovery.js +1 -126
- package/dist/cli/help-content.js +2 -1001
- package/dist/cli/help-json-payload.js +4 -570
- package/dist/cli/main.d.ts +4 -0
- package/dist/cli/main.js +5 -2573
- package/dist/cli/migration-gates.js +1 -289
- package/dist/cli/public.js +1 -20
- package/dist/cli/register-annotations.js +1 -270
- package/dist/cli/register-assurance.js +1 -62
- package/dist/cli/register-files-lookup.js +1 -56
- package/dist/cli/register-history-activity.d.ts +8 -0
- package/dist/cli/register-history-activity.js +2 -0
- package/dist/cli/register-history-author.js +1 -38
- package/dist/cli/register-history-maintenance.d.ts +9 -0
- package/dist/cli/register-history-maintenance.js +2 -0
- package/dist/cli/register-list-query.js +10 -943
- package/dist/cli/register-mutation-options.js +1 -9
- package/dist/cli/register-mutation.d.ts +0 -5
- package/dist/cli/register-mutation.js +19 -1893
- package/dist/cli/register-operations.js +1 -920
- package/dist/cli/register-setup.js +1 -716
- package/dist/cli/register-structured-mutation.js +1 -196
- package/dist/cli/registration-helpers.js +1 -5
- package/dist/cli/runtime-compatibility-boundary.js +4 -42
- package/dist/cli/schema-registration-helpers.js +1 -73
- package/dist/cli/search-refresh.js +1 -13
- package/dist/cli/stats-analytics-json.js +1 -68
- package/dist/cli/telemetry-flush.js +1 -10
- package/dist/cli-bundle/bundle-manifest.json +164 -156
- package/dist/cli-bundle/chunks/{chunk-NPN5I67J.js → chunk-3IPRM75M.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-4VL5P22L.js +2 -0
- package/dist/cli-bundle/chunks/chunk-AAFBV3U3.js +29 -0
- package/dist/cli-bundle/chunks/chunk-D3YVILJJ.js +20 -0
- package/dist/cli-bundle/chunks/{chunk-WYRZZ5ZE.js → chunk-DEZPZOQ7.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-ECBLPN7B.js +3 -0
- package/dist/cli-bundle/chunks/chunk-J6ERHBV2.js +235 -0
- package/dist/cli-bundle/chunks/chunk-JUNJ5EKI.js +2 -0
- package/dist/cli-bundle/chunks/chunk-L5RCDKQ2.js +2 -0
- package/dist/cli-bundle/chunks/chunk-NSAPNEYH.js +2 -0
- package/dist/cli-bundle/chunks/chunk-OHNLSGGV.js +79 -0
- package/dist/cli-bundle/chunks/chunk-WQKMSFBV.js +5 -0
- package/dist/cli-bundle/chunks/{chunk-BAX2BYUW.js → chunk-XZ6T7YPP.js} +256 -150
- package/dist/cli-bundle/chunks/{chunk-JT6XF6GE.js → chunk-Z3XVXUVF.js} +4 -4
- package/dist/cli-bundle/chunks/register-list-query-UIHRCS6D.js +11 -0
- package/dist/cli-bundle/chunks/register-mutation-WHWMGRVX.js +20 -0
- package/dist/cli-bundle/chunks/register-operations-64YZYTC5.js +2 -0
- package/dist/cli-bundle/chunks/register-setup-PERI45EM.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-2W4XIYOB.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-2WSBXIGF.js +12 -0
- package/dist/cli-bundle/focused-chunks/chunk-5FHTCOHS.js +3 -0
- package/dist/cli-bundle/focused-chunks/chunk-7N6DOREF.js +26 -0
- package/dist/cli-bundle/focused-chunks/{chunk-3BZEOXLT.js → chunk-7PC4R5QB.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-BUCJUZVG.js +6 -0
- package/dist/cli-bundle/focused-chunks/chunk-FE3BABLJ.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-IWITF53W.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-OQUGRHKV.js +10 -0
- package/dist/cli-bundle/focused-chunks/{chunk-M6PBRFSH.js → chunk-PNKIANFZ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-LIJIA4TY.js → chunk-QQQ4SAUO.js} +3 -3
- package/dist/cli-bundle/focused-chunks/chunk-TTYXF5YD.js +177 -0
- package/dist/cli-bundle/focused-chunks/chunk-XNR3DM6J.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-XSS3APUF.js +9 -0
- package/dist/cli-bundle/focused-chunks/chunk-YCDQ2N23.js +8 -0
- package/dist/cli-bundle/focused-chunks/chunk-YJUXGS57.js +20 -0
- package/dist/cli-bundle/focused-chunks/chunk-ZTCE4UO6.js +58 -0
- package/dist/cli-bundle/main.js +20 -20
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +2 -2
- package/dist/cli-bundle/sdk-core.js +37 -37
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +42 -42
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +11 -11
- package/dist/cli.js +1 -104
- package/dist/core/checkpoint/checkpoint-gc.js +1 -169
- package/dist/core/checkpoint/mutation-checkpoint.js +2 -133
- package/dist/core/config/nested-settings.js +1 -534
- package/dist/core/config/positional-value.js +1 -109
- package/dist/core/diagnostics/remediation.js +1 -506
- package/dist/core/extensions/activation-summary-markdown.js +2 -145
- package/dist/core/extensions/activation-summary.js +1 -92
- package/dist/core/extensions/activation-transaction.js +1 -46
- package/dist/core/extensions/capability-usage.js +1 -173
- package/dist/core/extensions/command-hook-context.js +1 -13
- package/dist/core/extensions/command-metadata-contract.js +1 -22
- package/dist/core/extensions/command-visibility-tier.js +1 -29
- package/dist/core/extensions/contribution-inventory.js +1 -173
- package/dist/core/extensions/exporter-output-contract.js +1 -66
- package/dist/core/extensions/extension-candidate.js +1 -18
- package/dist/core/extensions/extension-capability-aliases.js +1 -158
- package/dist/core/extensions/extension-hook-runtime.js +1 -699
- package/dist/core/extensions/extension-policy.js +1 -599
- package/dist/core/extensions/extension-registries.js +1 -62
- package/dist/core/extensions/extension-runtime-helpers.js +1 -33
- package/dist/core/extensions/extension-types.js +1 -102
- package/dist/core/extensions/flag-definition-validation.js +1 -52
- package/dist/core/extensions/flag-value-types.js +1 -64
- package/dist/core/extensions/index.js +1 -526
- package/dist/core/extensions/item-field-types.js +1 -39
- package/dist/core/extensions/item-fields.js +1 -261
- package/dist/core/extensions/loader.js +1 -2223
- package/dist/core/extensions/manifest-schema.js +1 -69
- package/dist/core/extensions/module-graph-snapshot.js +1 -33
- package/dist/core/extensions/preflight-ownership.js +1 -41
- package/dist/core/extensions/registration-validation.js +1 -82
- package/dist/core/extensions/registration-values.js +1 -209
- package/dist/core/extensions/reserved-host-flags.js +1 -36
- package/dist/core/extensions/runtime-registrations.js +1 -67
- package/dist/core/extensions/service-ownership.js +1 -19
- package/dist/core/extensions/version-compat.js +1 -216
- package/dist/core/fs/fs-utils.js +2 -158
- package/dist/core/fs/host-environment-errors.js +1 -141
- package/dist/core/fs/index.js +1 -9
- package/dist/core/fs/path-utils.js +1 -17
- package/dist/core/governance/content-fields.js +1 -160
- package/dist/core/governance/issue-codes.js +1 -151
- package/dist/core/governance/metadata-coverage.js +1 -358
- package/dist/core/history/drift-cache.js +3 -72
- package/dist/core/history/drift-scan.js +1 -342
- package/dist/core/history/event-classification.js +1 -109
- package/dist/core/history/event-index.js +8 -784
- package/dist/core/history/history-compact-bulk.js +1 -104
- package/dist/core/history/history-diff.js +1 -158
- package/dist/core/history/history-rewrite.d.ts +6 -1
- package/dist/core/history/history-rewrite.js +1 -107
- package/dist/core/history/history-storage-stats.js +1 -102
- package/dist/core/history/history-stream-policy.js +1 -62
- package/dist/core/history/history.js +2 -617
- package/dist/core/history/identity.js +1 -30
- package/dist/core/history/index.js +1 -9
- package/dist/core/history/projection.js +1 -196
- package/dist/core/history/read.d.ts +9 -0
- package/dist/core/history/read.js +1 -57
- package/dist/core/history/replay.js +2 -439
- package/dist/core/history/version-address.js +1 -32
- package/dist/core/history/workspace-history.js +2 -433
- package/dist/core/io/body-file.js +1 -62
- package/dist/core/io/bulk-ids-input.js +1 -112
- package/dist/core/item/actionability.js +1 -327
- package/dist/core/item/dependency-reference.js +1 -20
- package/dist/core/item/id.js +1 -112
- package/dist/core/item/index.js +1 -12
- package/dist/core/item/item-format-version.js +1 -78
- package/dist/core/item/item-format.js +5 -1473
- package/dist/core/item/item-record.js +1 -23
- package/dist/core/item/item-type-definition.js +1 -133
- package/dist/core/item/parent-reference-policy.js +1 -57
- package/dist/core/item/parse.js +2 -603
- package/dist/core/item/plan-lifecycle.js +1 -19
- package/dist/core/item/priority.js +1 -61
- package/dist/core/item/sprint-release-format.js +1 -38
- package/dist/core/item/status-filter.js +1 -115
- package/dist/core/item/status.js +1 -43
- package/dist/core/item/toon-decode.js +1 -29
- package/dist/core/item/type-registry.js +1 -715
- package/dist/core/item/type-synonyms.js +1 -38
- package/dist/core/lock/index.js +1 -9
- package/dist/core/lock/lock-gc.js +1 -240
- package/dist/core/lock/lock.js +3 -590
- package/dist/core/output/mutation-projection.js +1 -217
- package/dist/core/output/output-control.js +1 -25
- package/dist/core/output/output.js +11 -494
- package/dist/core/output/query-summary.js +1 -58
- package/dist/core/output/tabular.js +1 -77
- package/dist/core/packages/manifest.js +1 -244
- package/dist/core/packages/root.js +1 -84
- package/dist/core/policy/workflow-policy-schema.d.ts +312 -0
- package/dist/core/policy/workflow-policy-schema.js +2 -0
- package/dist/core/policy/workflow-policy-store.d.ts +24 -0
- package/dist/core/policy/workflow-policy-store.js +2 -0
- package/dist/core/policy/workflow-policy.d.ts +139 -0
- package/dist/core/policy/workflow-policy.js +2 -0
- package/dist/core/profile/profile-describe.js +1 -83
- package/dist/core/profile/profile-lint.js +1 -415
- package/dist/core/profile/profile-plan.js +0 -0
- package/dist/core/profile/profile-presets.js +1 -370
- package/dist/core/reproducibility/context.js +1 -82
- package/dist/core/schema/fields-file.js +2 -288
- package/dist/core/schema/item-types-file.js +2 -296
- package/dist/core/schema/runtime-field-filters.js +1 -49
- package/dist/core/schema/runtime-field-values.js +1 -313
- package/dist/core/schema/runtime-schema.js +2 -826
- package/dist/core/schema/status-defs-file.js +2 -227
- package/dist/core/schema/status-token.js +1 -31
- package/dist/core/schema/type-inference.js +1 -95
- package/dist/core/schema/type-presets.js +1 -87
- package/dist/core/schema/type-workflows.js +1 -104
- package/dist/core/search/background-refresh.js +2 -286
- package/dist/core/search/bm25.js +1 -146
- package/dist/core/search/cache.js +2 -534
- package/dist/core/search/corpus.js +1 -311
- package/dist/core/search/embedding-batches.js +1 -163
- package/dist/core/search/eval.js +1 -225
- package/dist/core/search/http-client.js +1 -75
- package/dist/core/search/providers.js +1 -242
- package/dist/core/search/relevance.js +1 -244
- package/dist/core/search/semantic-defaults.js +1 -199
- package/dist/core/search/staleness.js +1 -30
- package/dist/core/search/vector-stores.js +2 -664
- package/dist/core/search/vectorization-metadata.js +1 -81
- package/dist/core/sentry/helpers.js +1 -272
- package/dist/core/sentry/instrument.js +1 -387
- package/dist/core/session/session-state.js +1 -260
- package/dist/core/shared/agent-session-context.js +1 -133
- package/dist/core/shared/author.js +1 -1172
- package/dist/core/shared/command-types.js +1 -4
- package/dist/core/shared/conflict-markers.js +1 -31
- package/dist/core/shared/constants.js +1 -405
- package/dist/core/shared/errors.js +1 -20
- package/dist/core/shared/html-entity-decode.js +1 -131
- package/dist/core/shared/index.js +1 -12
- package/dist/core/shared/item-metadata-contract.js +1 -89
- package/dist/core/shared/lazy-module.js +1 -16
- package/dist/core/shared/levenshtein.js +1 -61
- package/dist/core/shared/memo.js +1 -19
- package/dist/core/shared/numeric-parsers.js +1 -20
- package/dist/core/shared/option-alias-visibility.js +1 -67
- package/dist/core/shared/primitives.js +1 -127
- package/dist/core/shared/serial-queue.js +1 -79
- package/dist/core/shared/serialization.js +1 -210
- package/dist/core/shared/split-comma-list.js +1 -30
- package/dist/core/shared/text-normalization.js +1 -38
- package/dist/core/shared/time.js +1 -306
- package/dist/core/store/index.js +1 -12
- package/dist/core/store/item-format-migration.js +1 -125
- package/dist/core/store/item-metadata-cache.js +1 -1116
- package/dist/core/store/item-metadata-query-index.js +9 -394
- package/dist/core/store/item-metadata-read-work.js +1 -43
- package/dist/core/store/item-store.js +1 -693
- package/dist/core/store/paths.d.ts +1 -1
- package/dist/core/store/paths.js +1 -214
- package/dist/core/store/settings-read-cache.js +1 -85
- package/dist/core/store/settings-validator.d.ts +1 -0
- package/dist/core/store/settings-validator.js +1 -421
- package/dist/core/store/settings.js +3 -1309
- package/dist/core/store/tracker-preflight.js +1 -141
- package/dist/core/telemetry/consent.js +5 -108
- package/dist/core/telemetry/observability.js +1 -246
- package/dist/core/telemetry/runtime.js +4 -1988
- package/dist/core/test/background-runs.js +4 -945
- package/dist/core/test/item-test-run-tracking.js +1 -63
- package/dist/core/test/run-selectors.js +1 -120
- package/dist/core/validate/estimate-defaults.js +1 -89
- package/dist/core/validate/fix-planning.js +1 -189
- package/dist/core/validate/linked-artifact-reference.js +1 -36
- package/dist/core/validate/missing-by-type.js +1 -34
- package/dist/core/validate/missing-link-owners.js +1 -95
- package/dist/core/validate/stale-file-classification.js +1 -82
- package/dist/mcp/http-server.js +5 -448
- package/dist/mcp/legacy-adapter.js +1 -77
- package/dist/mcp/runtime-capabilities.js +1 -200
- package/dist/mcp/server.js +4 -1233
- package/dist/mcp/tool-definitions.js +1 -804
- package/dist/sdk/actionability.js +1 -13
- package/dist/sdk/agent/closed-domain-contracts.js +1 -161
- package/dist/sdk/agent/command-recovery.js +1 -59
- package/dist/sdk/agent/command-suggestions.js +1 -66
- package/dist/sdk/agent/create-option-policy.js +1 -31
- package/dist/sdk/agent/identity-config.js +1 -106
- package/dist/sdk/agent/item-addressing.js +1 -207
- package/dist/sdk/agent/refusal-closure-census.js +1 -151
- package/dist/sdk/agent/refusal-closure.js +1 -133
- package/dist/sdk/agent/refusal-corpus-contracts.js +1 -193
- package/dist/sdk/agent/refusal-reachability.js +1 -593
- package/dist/sdk/agent/subcommand-recovery.js +1 -83
- package/dist/sdk/agent/task-transcript-contracts.js +1 -197
- package/dist/sdk/agent/tracker-preflight-contracts.js +1 -126
- package/dist/sdk/agent-capability-contracts.js +1 -428
- package/dist/sdk/agent-session-context.js +1 -9
- package/dist/sdk/annotations.js +1 -448
- package/dist/sdk/author-attribution.js +1 -468
- package/dist/sdk/authoring.js +1 -20
- package/dist/sdk/cli-bootstrap.js +1 -838
- package/dist/sdk/cli-contracts/agent-output-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts/agent-output-contracts.js +4 -476
- package/dist/sdk/cli-contracts/bootstrap-command-scanner.js +1 -79
- package/dist/sdk/cli-contracts/command-aliases.d.ts +4 -0
- package/dist/sdk/cli-contracts/command-aliases.js +1 -107
- package/dist/sdk/cli-contracts/command-exit-contracts.js +1 -151
- package/dist/sdk/cli-contracts/commander-mutation-options.js +1 -1081
- package/dist/sdk/cli-contracts/commander-types.js +1 -159
- package/dist/sdk/cli-contracts/completeness.js +1 -393
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts/enum-contracts.js +1 -222
- package/dist/sdk/cli-contracts/flag-contracts.js +1 -1947
- package/dist/sdk/cli-contracts/flag-lexicon-contracts.js +1 -347
- package/dist/sdk/cli-contracts/grammar-contracts.js +1 -986
- package/dist/sdk/cli-contracts/registration-helpers.js +7 -990
- package/dist/sdk/cli-contracts/runtime-contracts.d.ts +5 -0
- package/dist/sdk/cli-contracts/runtime-contracts.js +1 -2090
- package/dist/sdk/cli-contracts/schemas/assurance-definition.js +1 -324
- package/dist/sdk/cli-contracts/string-lists.js +1 -16
- package/dist/sdk/cli-contracts/tool-option-contracts.js +1 -461
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +1 -2167
- package/dist/sdk/cli-contracts/tool-schema.d.ts +3 -1
- package/dist/sdk/cli-contracts/tool-schema.js +1 -1664
- package/dist/sdk/cli-contracts/typed-action-inputs.js +1 -4
- package/dist/sdk/cli-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts.js +1 -17
- package/dist/sdk/cli-program.js +1 -49
- package/dist/sdk/command-line.d.ts +2 -5
- package/dist/sdk/command-line.js +1 -78
- package/dist/sdk/comments.js +1 -133
- package/dist/sdk/compile-cache.js +1 -73
- package/dist/sdk/completion.js +174 -839
- package/dist/sdk/compose.js +1 -1090
- package/dist/sdk/config.js +1 -1204
- package/dist/sdk/context/recency.js +1 -33
- package/dist/sdk/context/semantic-session-attribution.js +1 -82
- package/dist/sdk/context/usage-egress.js +1 -29
- package/dist/sdk/context/usage-ledger.js +3 -185
- package/dist/sdk/context-intent-contracts.js +1 -709
- package/dist/sdk/context-intent-runtime.js +1 -115
- package/dist/sdk/context-packing.js +1 -218
- package/dist/sdk/context-relevance.js +1 -503
- package/dist/sdk/context-signal-store.js +2 -426
- package/dist/sdk/context-usage.js +1 -367
- package/dist/sdk/contracts.js +1 -23
- package/dist/sdk/core-governance.js +1 -14
- package/dist/sdk/core.js +1 -14
- package/dist/sdk/corpus-shape.js +1 -401
- package/dist/sdk/define.js +1 -220
- package/dist/sdk/dependencies.js +1 -718
- package/dist/sdk/dependency-flag-validation.js +1 -156
- package/dist/sdk/dependency-provenance.js +1 -135
- package/dist/sdk/docs.js +1 -14
- package/dist/sdk/duplicates.js +1 -40
- package/dist/sdk/environment/agent-environment.js +1 -466
- package/dist/sdk/environment/host-environment-errors.js +1 -8
- package/dist/sdk/environment/project-runtime-compatibility.js +1 -481
- package/dist/sdk/environment/source-context.js +1 -28
- package/dist/sdk/environment/tracker-preflight.js +1 -9
- package/dist/sdk/error-code-catalog.js +1 -153
- package/dist/sdk/error-runtime.js +1 -58
- package/dist/sdk/errors.js +1 -58
- package/dist/sdk/eval.js +1 -190
- package/dist/sdk/extension/author-manifest.js +1 -92
- package/dist/sdk/extension/bundled-catalog.js +1 -332
- package/dist/sdk/extension/concurrency.js +1 -25
- package/dist/sdk/extension/copy-scope.d.ts +2 -0
- package/dist/sdk/extension/copy-scope.js +2 -0
- package/dist/sdk/extension/custom-field-collisions.js +1 -30
- package/dist/sdk/extension/describe.js +3 -189
- package/dist/sdk/extension/doctor.js +1 -606
- package/dist/sdk/extension/install-plan.d.ts +69 -0
- package/dist/sdk/extension/install-plan.js +2 -0
- package/dist/sdk/extension/install-receipts.d.ts +7 -0
- package/dist/sdk/extension/install-receipts.js +2 -0
- package/dist/sdk/extension/install-runtime.js +3 -313
- package/dist/sdk/extension/install-snapshot.js +1 -66
- package/dist/sdk/extension/install-sources.js +5 -1057
- package/dist/sdk/extension/managed-state.js +2 -252
- package/dist/sdk/extension/migrations.js +2 -174
- package/dist/sdk/extension/output-ownership.js +1 -25
- package/dist/sdk/extension/runtime-summary.js +1 -18
- package/dist/sdk/extension/scaffold.js +4 -2308
- package/dist/sdk/extension/shared.js +1 -147
- package/dist/sdk/extension/source-resolution.js +1 -65
- package/dist/sdk/extension/update-check.js +1 -67
- package/dist/sdk/extension-command-context.js +1 -44
- package/dist/sdk/extension-contracts.js +1 -73
- package/dist/sdk/extension.d.ts +7 -2
- package/dist/sdk/extension.js +1 -2196
- package/dist/sdk/files.js +1 -535
- package/dist/sdk/flag-invocation-contracts.d.ts +0 -5
- package/dist/sdk/flag-invocation-contracts.js +1 -344
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -2224
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +1 -2236
- package/dist/sdk/generated-error-code-catalog.js +1 -16
- package/dist/sdk/governance/assurance-action-contracts.js +1 -4
- package/dist/sdk/governance/assurance-action.js +1 -411
- package/dist/sdk/governance/assurance-limits.js +1 -10
- package/dist/sdk/governance/assurance-mutation-error.js +1 -81
- package/dist/sdk/governance/assurance-presets.js +1 -135
- package/dist/sdk/governance/assurance-runtime.js +1 -238
- package/dist/sdk/governance/assurance.js +4 -1182
- package/dist/sdk/governance/boundary-fixtures.js +1 -200
- package/dist/sdk/governance/coverage-assurance.js +1 -60
- package/dist/sdk/governance/defect-recurrence-coverage.js +1 -188
- package/dist/sdk/governance/defect-recurrence-graph.js +1 -120
- package/dist/sdk/governance/defect-recurrence-signals.js +1 -24
- package/dist/sdk/governance/defect-recurrence.js +1 -623
- package/dist/sdk/governance/extension-host-version.js +1 -115
- package/dist/sdk/governance/gc.js +1 -368
- package/dist/sdk/governance/health.js +1 -2367
- package/dist/sdk/governance/hierarchy-validation.js +1 -108
- package/dist/sdk/governance/linked-file-report.js +1 -71
- package/dist/sdk/governance/merge-receipt-history.js +1 -206
- package/dist/sdk/governance/provenance-health.js +1 -282
- package/dist/sdk/governance/reindex.js +4 -761
- package/dist/sdk/governance/stale-work.js +1 -82
- package/dist/sdk/governance/status-role-diagnostics.js +1 -35
- package/dist/sdk/governance/storage-integrity.js +1 -280
- package/dist/sdk/governance/tracked-runtime-cache.js +1 -106
- package/dist/sdk/governance/upgrade.js +2 -327
- package/dist/sdk/governance/validate-history-drift.js +1 -81
- package/dist/sdk/governance/validate-item-reader.js +1 -17
- package/dist/sdk/governance/validate-normalization.js +1 -36
- package/dist/sdk/governance/validate.d.ts +3 -1
- package/dist/sdk/governance/validate.js +1 -2261
- package/dist/sdk/governance/workflow-completeness.d.ts +32 -0
- package/dist/sdk/governance/workflow-completeness.js +2 -0
- package/dist/sdk/governance/workflow-policy.d.ts +47 -0
- package/dist/sdk/governance/workflow-policy.js +4 -0
- package/dist/sdk/governance/workspace-position.js +1 -163
- package/dist/sdk/governance.d.ts +2 -0
- package/dist/sdk/governance.js +1 -31
- package/dist/sdk/graph/adapter.js +1 -181
- package/dist/sdk/graph/analytics.js +1 -474
- package/dist/sdk/graph/assembly.js +1 -377
- package/dist/sdk/graph/cache.js +1 -160
- package/dist/sdk/graph/centrality.js +1 -258
- package/dist/sdk/graph/conformance.js +1 -130
- package/dist/sdk/graph/deadline-scheduling.d.ts +90 -0
- package/dist/sdk/graph/deadline-scheduling.js +2 -0
- package/dist/sdk/graph/durable-cache.d.ts +1 -1
- package/dist/sdk/graph/durable-cache.js +1 -361
- package/dist/sdk/graph/governance-contracts.js +1 -34
- package/dist/sdk/graph/governance.d.ts +13 -1
- package/dist/sdk/graph/governance.js +1 -735
- package/dist/sdk/graph/hierarchy-integrity.js +1 -310
- package/dist/sdk/graph/index.d.ts +3 -2
- package/dist/sdk/graph/index.js +1 -26
- package/dist/sdk/graph/lifecycle-coverage.d.ts +32 -0
- package/dist/sdk/graph/lifecycle-coverage.js +2 -0
- package/dist/sdk/graph/mutation-advisory.js +1 -176
- package/dist/sdk/graph/remediation.js +1 -197
- package/dist/sdk/graph/run.d.ts +15 -1
- package/dist/sdk/graph/run.js +1 -768
- package/dist/sdk/graph/scheduling.js +1 -124
- package/dist/sdk/graph/traversal.js +1 -284
- package/dist/sdk/graph/workspace-relationship-kind-registry.js +1 -27
- package/dist/sdk/graph.js +1 -15
- package/dist/sdk/guide-topics.js +1 -707
- package/dist/sdk/guide.js +1 -279
- package/dist/sdk/history/maintenance.d.ts +71 -0
- package/dist/sdk/history/maintenance.js +2 -0
- package/dist/sdk/history/salvage.js +2 -247
- package/dist/sdk/history/subject.d.ts +19 -0
- package/dist/sdk/history/subject.js +2 -0
- package/dist/sdk/history-analytics.js +1 -282
- package/dist/sdk/history-compact.js +1 -527
- package/dist/sdk/history-mcp.js +1 -68
- package/dist/sdk/history-provenance.js +1 -182
- package/dist/sdk/history-read.js +1 -96
- package/dist/sdk/history-redact.d.ts +1 -14
- package/dist/sdk/history-redact.js +1 -643
- package/dist/sdk/history-repair.d.ts +5 -0
- package/dist/sdk/history-repair.js +1 -657
- package/dist/sdk/improvement-ledger-validation.js +1 -62
- package/dist/sdk/improvement-ledger.js +2 -257
- package/dist/sdk/index.d.ts +4 -1
- package/dist/sdk/index.js +1 -183
- package/dist/sdk/init-agent-guidance.js +2 -496
- package/dist/sdk/init.js +2 -820
- package/dist/sdk/invocation-author.js +1 -39
- package/dist/sdk/item-children.js +1 -90
- package/dist/sdk/item-metadata-index.js +1 -15
- package/dist/sdk/item-schedule.js +1 -27
- package/dist/sdk/item-transaction.js +1 -396
- package/dist/sdk/learnings.js +1 -29
- package/dist/sdk/lifecycle/append.js +2 -53
- package/dist/sdk/lifecycle/claim.d.ts +2 -0
- package/dist/sdk/lifecycle/claim.js +1 -242
- package/dist/sdk/lifecycle/close-many.js +1 -438
- package/dist/sdk/lifecycle/close.js +1 -468
- package/dist/sdk/lifecycle/copy.js +1 -212
- package/dist/sdk/lifecycle/create.js +1 -1949
- package/dist/sdk/lifecycle/delete.js +1 -45
- package/dist/sdk/lifecycle/event-validation-messages.js +1 -91
- package/dist/sdk/lifecycle/focus.js +1 -91
- package/dist/sdk/lifecycle/hierarchy-mutation-lock.js +1 -24
- package/dist/sdk/lifecycle/legacy-none-tokens.js +1 -149
- package/dist/sdk/lifecycle/lifecycle-transitions.js +1 -40
- package/dist/sdk/lifecycle/mcp-actions.d.ts +2 -0
- package/dist/sdk/lifecycle/mcp-actions.js +1 -51
- package/dist/sdk/lifecycle/metadata-normalizers.js +1 -46
- package/dist/sdk/lifecycle/mutation-command-options.js +1 -9
- package/dist/sdk/lifecycle/plan.js +1 -1606
- package/dist/sdk/lifecycle/recurrence-parsers.d.ts +1 -1
- package/dist/sdk/lifecycle/recurrence-parsers.js +1 -147
- package/dist/sdk/lifecycle/reopen.js +1 -68
- package/dist/sdk/lifecycle/repeatable-metadata-parsers.js +1 -143
- package/dist/sdk/lifecycle/restore.d.ts +1 -0
- package/dist/sdk/lifecycle/restore.js +1 -330
- package/dist/sdk/lifecycle/shared-unset-fields.js +1 -295
- package/dist/sdk/lifecycle/update-many.js +1 -861
- package/dist/sdk/lifecycle/update.js +1 -2136
- package/dist/sdk/lifecycle-completion.js +1 -92
- package/dist/sdk/lifecycle-policy.js +1 -120
- package/dist/sdk/linked-artifacts.js +1 -530
- package/dist/sdk/mcp/apps.js +4 -133
- package/dist/sdk/mcp/authorization.js +1 -404
- package/dist/sdk/mcp/discovery.js +1 -494
- package/dist/sdk/mcp/interactions.js +1 -336
- package/dist/sdk/mcp/protocol.d.ts +7 -0
- package/dist/sdk/mcp/protocol.js +1 -184
- package/dist/sdk/mcp/skills.js +1 -389
- package/dist/sdk/mcp/subscriptions.js +1 -211
- package/dist/sdk/mcp/tasks.js +2 -430
- package/dist/sdk/mcp/transport.js +1 -260
- package/dist/sdk/merge/abandoned-receipts.js +1 -46
- package/dist/sdk/merge/driver.js +1 -212
- package/dist/sdk/merge/index.js +1 -16
- package/dist/sdk/merge/install.js +3 -561
- package/dist/sdk/merge/receipt-file-boundary.js +1 -46
- package/dist/sdk/merge/receipt-operation.js +1 -96
- package/dist/sdk/merge/receipt-schema.js +1 -397
- package/dist/sdk/merge/receipts.js +4 -525
- package/dist/sdk/merge/reconcile.js +1 -352
- package/dist/sdk/merge/three-way.js +3 -775
- package/dist/sdk/merge.js +1 -10
- package/dist/sdk/mutation-events.js +1 -292
- package/dist/sdk/mutation-guard.js +1 -216
- package/dist/sdk/notes.js +1 -139
- package/dist/sdk/output-contracts.js +1 -172
- package/dist/sdk/output-projection.js +1 -430
- package/dist/sdk/output-token-accounting.js +1 -140
- package/dist/sdk/output.js +1 -64
- package/dist/sdk/ownership-source.js +1 -21
- package/dist/sdk/package-import-adapters.js +1 -442
- package/dist/sdk/package-migrations.js +1 -20
- package/dist/sdk/package-runtime-options.js +1 -80
- package/dist/sdk/pagination.js +1 -162
- package/dist/sdk/profile.js +1 -454
- package/dist/sdk/provenance.js +1 -258
- package/dist/sdk/public-surface.json +1 -1
- package/dist/sdk/query/activity.js +1 -401
- package/dist/sdk/query/aggregate.d.ts +16 -0
- package/dist/sdk/query/aggregate.js +1 -390
- package/dist/sdk/query/calendar.js +1 -964
- package/dist/sdk/query/complete-list.js +1 -215
- package/dist/sdk/query/context.js +1 -1702
- package/dist/sdk/query/duplicate-candidates.js +1 -70
- package/dist/sdk/query/get.js +1 -450
- package/dist/sdk/query/history.js +1 -186
- package/dist/sdk/query/item-filter-options.js +1 -9
- package/dist/sdk/query/light-metadata.js +1 -18
- package/dist/sdk/query/list-filter-shared.js +1 -81
- package/dist/sdk/query/list.js +1 -1304
- package/dist/sdk/query/multi-value-filters.js +1 -78
- package/dist/sdk/query/next.js +1 -513
- package/dist/sdk/query/parsers.js +1 -44
- package/dist/sdk/query/projection-contracts.js +1 -184
- package/dist/sdk/query/search-contracts.d.ts +27 -0
- package/dist/sdk/query/search-contracts.js +1 -230
- package/dist/sdk/query/search-pagination.js +1 -35
- package/dist/sdk/query/search-rendering.js +1 -105
- package/dist/sdk/query/search.d.ts +6 -4
- package/dist/sdk/query/search.js +2 -1987
- package/dist/sdk/query.js +1 -35
- package/dist/sdk/read-output/continuation.js +1 -194
- package/dist/sdk/read-output-budget.js +1 -135
- package/dist/sdk/read-output-contracts.d.ts +1 -1
- package/dist/sdk/read-output-contracts.js +1 -1225
- package/dist/sdk/read-output-rows.js +1 -186
- package/dist/sdk/read-output-session.js +1 -208
- package/dist/sdk/relationship-analytics.js +1 -410
- package/dist/sdk/relationship-context.js +1 -284
- package/dist/sdk/relationship-history.js +4 -519
- package/dist/sdk/relationship-kinds/contract.js +1 -22
- package/dist/sdk/relationship-migration.js +1 -77
- package/dist/sdk/relationships.js +1 -579
- package/dist/sdk/reproducibility/process.js +1 -87
- package/dist/sdk/runtime-action-aliases.js +1 -59
- package/dist/sdk/runtime-extended-actions.js +1 -177
- package/dist/sdk/runtime-input.js +1 -614
- package/dist/sdk/runtime-primitives.js +1 -84
- package/dist/sdk/runtime-public-contracts.d.ts +2 -1
- package/dist/sdk/runtime-public-contracts.js +1 -4
- package/dist/sdk/runtime-stats-options.js +1 -38
- package/dist/sdk/runtime.d.ts +4 -0
- package/dist/sdk/runtime.js +1 -1928
- package/dist/sdk/scheduling-shortcuts.js +1 -63
- package/dist/sdk/schema-migration.js +3 -856
- package/dist/sdk/schema.d.ts +2 -1
- package/dist/sdk/schema.js +1 -1376
- package/dist/sdk/search-refresh-worker.js +1 -18
- package/dist/sdk/similarity-scoring.js +1 -53
- package/dist/sdk/similarity.js +1 -326
- package/dist/sdk/start-task-status.js +1 -14
- package/dist/sdk/stats.js +1 -270
- package/dist/sdk/structured-mutations.js +1 -580
- package/dist/sdk/telemetry-flush.js +1 -13
- package/dist/sdk/telemetry.js +1 -405
- package/dist/sdk/templates.js +2 -292
- package/dist/sdk/test/batch.js +2 -509
- package/dist/sdk/test/entry.js +1 -70
- package/dist/sdk/test/execution.js +6 -2211
- package/dist/sdk/test/linked-command-detection.js +1 -546
- package/dist/sdk/test/measurements.js +1 -91
- package/dist/sdk/test/parsers.js +1 -545
- package/dist/sdk/test/runs.js +1 -193
- package/dist/sdk/test/trust.js +2 -206
- package/dist/sdk/testing.js +4 -1391
- package/dist/sdk/traceability/runtime-files-lookup.js +1 -32
- package/dist/sdk/traceability/source-traceability.js +1 -292
- package/dist/sdk/tracker-root-discovery.js +1 -9
- package/dist/sdk/workspace-contracts-cache.js +1 -28
- package/dist/sdk/workspace-contracts.js +1 -33
- package/dist/sdk/workspace-memory.js +2 -318
- package/dist/sdk/workspace-recipe.js +1 -71
- package/dist/sdk/workspace-snapshot.js +4 -613
- package/dist/sdk/workspace-transaction-gc.js +1 -149
- package/dist/sdk/workspace-transaction.js +2 -363
- package/dist/sdk/workspace.js +3 -127
- package/dist/types/index.js +1 -9
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -245
- package/docs/AGENT_GUIDE.md +1 -1
- package/docs/COMMANDS.md +10 -0
- package/docs/CONFIGURATION.md +12 -1
- package/docs/CONTEXT_ALGORITHM_PORTFOLIO.md +167 -0
- package/docs/DIAGNOSTIC_OUTPUT_CONTRACTS.md +9 -3
- package/docs/EXTENSIONS.md +1 -0
- package/docs/HISTORY_MAINTENANCE.md +125 -0
- package/docs/MCP_2026_07_28_CONFORMANCE.md +20 -10
- package/docs/PACKAGE_EVIDENCE.md +92 -0
- package/docs/PLANNING_MEASUREMENTS.md +183 -0
- package/docs/README.md +4 -0
- package/docs/READ_OUTPUT_CONTRACTS.md +5 -0
- package/docs/SCRIPTING.md +21 -0
- package/docs/TESTING.md +33 -0
- package/docs/WORKFLOW_POLICIES.md +129 -0
- package/docs/generated/FLAG_LEXICON_BUDGETS.md +7 -7
- package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +11 -5
- package/marketplace.json +2 -2
- package/package.json +5 -5
- 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-digital-twin/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/packages/pm-vcs/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/scripts/finalize-build.mjs +45 -3
- package/dist/cli-bundle/chunks/chunk-AZDFJGH6.js +0 -9
- package/dist/cli-bundle/chunks/chunk-CKOL5U7J.js +0 -77
- package/dist/cli-bundle/chunks/chunk-JX4DH4WC.js +0 -3
- package/dist/cli-bundle/chunks/chunk-OF76PSDQ.js +0 -5
- package/dist/cli-bundle/chunks/chunk-QUWFABDM.js +0 -232
- package/dist/cli-bundle/chunks/chunk-QWRRFYK3.js +0 -2
- package/dist/cli-bundle/chunks/chunk-RWWBOWJ5.js +0 -2
- package/dist/cli-bundle/chunks/chunk-WGAOYSYH.js +0 -40
- package/dist/cli-bundle/chunks/chunk-WI2AYPA7.js +0 -2
- package/dist/cli-bundle/chunks/register-list-query-5JL52D33.js +0 -11
- package/dist/cli-bundle/chunks/register-mutation-ZPG7KMVP.js +0 -20
- package/dist/cli-bundle/chunks/register-operations-I5W3KMGB.js +0 -2
- package/dist/cli-bundle/chunks/register-setup-H4SVAVX7.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-AL5ON6K6.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-CHC2IDXA.js +0 -6
- package/dist/cli-bundle/focused-chunks/chunk-CK6QFAPZ.js +0 -20
- package/dist/cli-bundle/focused-chunks/chunk-EZR3GHFE.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-H2WJWK7L.js +0 -56
- package/dist/cli-bundle/focused-chunks/chunk-NTPY5GSO.js +0 -3
- package/dist/cli-bundle/focused-chunks/chunk-P5O7MP5Y.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-PDMW2E36.js +0 -177
- package/dist/cli-bundle/focused-chunks/chunk-PEFABF7E.js +0 -26
- package/dist/cli-bundle/focused-chunks/chunk-QTVCLMSZ.js +0 -6
- package/dist/cli-bundle/focused-chunks/chunk-QTZRBUYA.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-SGQST3PQ.js +0 -12
- package/dist/cli-bundle/focused-chunks/chunk-UKHASMMP.js +0 -10
- package/dist/cli-bundle/focused-chunks/chunk-ZPEKQHOC.js +0 -2
|
@@ -1,710 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module sdk/context-intent-contracts
|
|
3
|
-
*
|
|
4
|
-
* Declares composable, intent-scoped read projections for core commands,
|
|
5
|
-
* workspace configuration, and packages.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
!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]="d6fc4c70-c955-5fb5-ab4b-5dfa1200d58d")}catch(e){}}();
|
|
9
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
-
import { renderPmCommand } from "./command-line.js";
|
|
11
|
-
import { attachOutputOmissionReceipt } from "./output-projection.js";
|
|
12
|
-
import { encodeQueryCursor } from "./pagination.js";
|
|
13
|
-
import { applyReadOutputDimensions, stabilizeReadOutputReceiptEstimates, } from "./read-output-contracts.js";
|
|
14
|
-
import { propagateContextUsageServingReceipt } from "./context-usage.js";
|
|
15
|
-
import { EXIT_CODE } from "../core/shared/constants.js";
|
|
16
|
-
import { PmCliError } from "../core/shared/errors.js";
|
|
17
|
-
/** Built-in intent projections shared by CLI, SDK, MCP, and package authors. */
|
|
18
|
-
export const PM_CONTEXT_INTENT_CONTRACTS = Object.freeze([
|
|
19
|
-
{
|
|
20
|
-
command: "context",
|
|
21
|
-
intent: "orient",
|
|
22
|
-
description: "Bounded active hierarchy, ownership, blockers, and recent progress.",
|
|
23
|
-
included_field_groups: [
|
|
24
|
-
"summary",
|
|
25
|
-
"focus",
|
|
26
|
-
"hierarchy",
|
|
27
|
-
"blockers",
|
|
28
|
-
"activity",
|
|
29
|
-
],
|
|
30
|
-
token_budget: 3000,
|
|
31
|
-
source: "core",
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
command: "context",
|
|
35
|
-
intent: "handoff",
|
|
36
|
-
description: "Active ownership, evidence, decisions, and immediate continuation context.",
|
|
37
|
-
included_field_groups: [
|
|
38
|
-
"summary",
|
|
39
|
-
"focus",
|
|
40
|
-
"in_progress",
|
|
41
|
-
"decisions",
|
|
42
|
-
"activity",
|
|
43
|
-
],
|
|
44
|
-
token_budget: 2200,
|
|
45
|
-
source: "core",
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
command: "get",
|
|
49
|
-
intent: "inspect",
|
|
50
|
-
description: "Standard-depth item metadata, relationships, evidence, and lifecycle state.",
|
|
51
|
-
included_field_groups: ["item", "children", "claim_state", "linked"],
|
|
52
|
-
token_budget: 3200,
|
|
53
|
-
source: "core",
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
command: "list",
|
|
57
|
-
intent: "triage",
|
|
58
|
-
description: "A budget-derived page of compact governance, ownership, priority, and blocker rows for triage.",
|
|
59
|
-
included_field_groups: [
|
|
60
|
-
"identity",
|
|
61
|
-
"governance",
|
|
62
|
-
"ownership",
|
|
63
|
-
"dependencies",
|
|
64
|
-
],
|
|
65
|
-
token_budget: 3200,
|
|
66
|
-
source: "core",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
command: "next",
|
|
70
|
-
intent: "execute",
|
|
71
|
-
description: "The highest-ranked actionable work with concise ranking evidence.",
|
|
72
|
-
included_field_groups: ["recommended"],
|
|
73
|
-
token_budget: 1200,
|
|
74
|
-
source: "core",
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
command: "search",
|
|
78
|
-
intent: "discover",
|
|
79
|
-
description: "A budget-derived page of ranked canonical lineage candidates with compact match evidence.",
|
|
80
|
-
included_field_groups: ["identity", "status", "lineage", "match"],
|
|
81
|
-
token_budget: 1800,
|
|
82
|
-
source: "core",
|
|
83
|
-
},
|
|
84
|
-
]);
|
|
85
|
-
const activeContextIntentContracts = new AsyncLocalStorage();
|
|
86
|
-
/** Return the request-scoped intent registry, or the immutable built-in registry outside a configured scope. */
|
|
87
|
-
export function getActiveContextIntentContracts() {
|
|
88
|
-
return activeContextIntentContracts.getStore() ?? PM_CONTEXT_INTENT_CONTRACTS;
|
|
89
|
-
}
|
|
90
|
-
/** Execute asynchronous work with isolated workspace and package intent declarations. */
|
|
91
|
-
export function runWithContextIntentContracts(layers, run) {
|
|
92
|
-
return activeContextIntentContracts.run(composeContextIntentContracts(layers.workspaceContracts, layers.packageContracts), run);
|
|
93
|
-
}
|
|
94
|
-
function normalizeContextIntentDeclaration(declaration, source) {
|
|
95
|
-
const command = declaration.command.trim().toLowerCase();
|
|
96
|
-
const intent = declaration.intent.trim().toLowerCase();
|
|
97
|
-
const key = `${command}:${intent}`;
|
|
98
|
-
if (!/^[a-z0-9][a-z0-9-]*$/.test(command) ||
|
|
99
|
-
!/^[a-z0-9][a-z0-9-]*$/.test(intent)) {
|
|
100
|
-
throw new TypeError(`Invalid context intent command or name: ${key}`);
|
|
101
|
-
}
|
|
102
|
-
if (declaration.description.trim().length === 0) {
|
|
103
|
-
throw new TypeError(`Context intent ${key} requires a non-empty description`);
|
|
104
|
-
}
|
|
105
|
-
if (!Number.isSafeInteger(declaration.token_budget) ||
|
|
106
|
-
declaration.token_budget <= 0) {
|
|
107
|
-
throw new TypeError(`Context intent ${key} requires a positive integer token_budget`);
|
|
108
|
-
}
|
|
109
|
-
const includedFieldGroups = [
|
|
110
|
-
...new Set(declaration.included_field_groups
|
|
111
|
-
.map((field) => field.trim())
|
|
112
|
-
.filter(Boolean)),
|
|
113
|
-
];
|
|
114
|
-
if (includedFieldGroups.length === 0) {
|
|
115
|
-
throw new TypeError(`Context intent ${key} requires included_field_groups`);
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
command,
|
|
119
|
-
intent,
|
|
120
|
-
description: declaration.description.trim(),
|
|
121
|
-
included_field_groups: includedFieldGroups,
|
|
122
|
-
token_budget: declaration.token_budget,
|
|
123
|
-
source,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/** Validate and compose core, package, and workspace intent declarations. Later layers override earlier layers by command and intent. */
|
|
127
|
-
export function composeContextIntentContracts(workspaceContracts = [], packageContracts = []) {
|
|
128
|
-
const layers = [
|
|
129
|
-
{
|
|
130
|
-
source: "core",
|
|
131
|
-
contracts: PM_CONTEXT_INTENT_CONTRACTS,
|
|
132
|
-
allowOverride: false,
|
|
133
|
-
},
|
|
134
|
-
{ source: "package", contracts: packageContracts, allowOverride: false },
|
|
135
|
-
{ source: "workspace", contracts: workspaceContracts, allowOverride: true },
|
|
136
|
-
];
|
|
137
|
-
const composed = new Map();
|
|
138
|
-
const keysSeenWithinLayer = new Set();
|
|
139
|
-
for (const layer of layers) {
|
|
140
|
-
keysSeenWithinLayer.clear();
|
|
141
|
-
for (const declaration of layer.contracts) {
|
|
142
|
-
const normalized = normalizeContextIntentDeclaration(declaration, layer.source);
|
|
143
|
-
const key = `${normalized.command}:${normalized.intent}`;
|
|
144
|
-
if (keysSeenWithinLayer.has(key)) {
|
|
145
|
-
throw new TypeError(`Duplicate context intent declaration: ${key}`);
|
|
146
|
-
}
|
|
147
|
-
keysSeenWithinLayer.add(key);
|
|
148
|
-
if (!layer.allowOverride && composed.has(key)) {
|
|
149
|
-
throw new TypeError(`Duplicate context intent declaration: ${key}`);
|
|
150
|
-
}
|
|
151
|
-
composed.set(key, normalized);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return [...composed.values()].sort((left, right) => left.command.localeCompare(right.command) ||
|
|
155
|
-
left.intent.localeCompare(right.intent));
|
|
156
|
-
}
|
|
157
|
-
/** Resolve one intent declaration or fail with the nearest command-local intent. */
|
|
158
|
-
export function resolveContextIntentContract(command, intent, contracts = getActiveContextIntentContracts(), positionalArguments = []) {
|
|
159
|
-
const normalizedCommand = command.trim().toLowerCase();
|
|
160
|
-
const normalizedIntent = intent.trim().toLowerCase();
|
|
161
|
-
const exact = contracts.find((entry) => entry.command === normalizedCommand && entry.intent === normalizedIntent);
|
|
162
|
-
if (exact)
|
|
163
|
-
return { ...exact, source: exact.source ?? "core" };
|
|
164
|
-
const candidates = contracts
|
|
165
|
-
.filter((entry) => entry.command === normalizedCommand)
|
|
166
|
-
.map((entry) => entry.intent);
|
|
167
|
-
if (candidates.length === 0)
|
|
168
|
-
return undefined;
|
|
169
|
-
const suggestion = candidates
|
|
170
|
-
.map((candidate) => {
|
|
171
|
-
const rows = Array.from({ length: normalizedIntent.length + 1 }, (_, index) => index);
|
|
172
|
-
for (let candidateIndex = 1; candidateIndex <= candidate.length; candidateIndex += 1) {
|
|
173
|
-
let previous = rows[0];
|
|
174
|
-
rows[0] = candidateIndex;
|
|
175
|
-
for (let intentIndex = 1; intentIndex <= normalizedIntent.length; intentIndex += 1) {
|
|
176
|
-
const prior = rows[intentIndex];
|
|
177
|
-
rows[intentIndex] = Math.min(rows[intentIndex] + 1, rows[intentIndex - 1] + 1, previous +
|
|
178
|
-
(candidate[candidateIndex - 1] ===
|
|
179
|
-
normalizedIntent[intentIndex - 1]
|
|
180
|
-
? 0
|
|
181
|
-
: 1));
|
|
182
|
-
previous = prior;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return { candidate, distance: rows[normalizedIntent.length] };
|
|
186
|
-
})
|
|
187
|
-
.sort((left, right) => left.distance - right.distance ||
|
|
188
|
-
left.candidate.localeCompare(right.candidate))[0].candidate;
|
|
189
|
-
const attemptedArguments = [
|
|
190
|
-
normalizedCommand,
|
|
191
|
-
...positionalArguments,
|
|
192
|
-
"--for",
|
|
193
|
-
normalizedIntent,
|
|
194
|
-
];
|
|
195
|
-
const suggestedRetryArguments = [
|
|
196
|
-
normalizedCommand,
|
|
197
|
-
...positionalArguments,
|
|
198
|
-
"--for",
|
|
199
|
-
suggestion,
|
|
200
|
-
];
|
|
201
|
-
const suggestedCommand = renderPmCommand(suggestedRetryArguments);
|
|
202
|
-
throw new PmCliError(`Unknown context intent "${normalizedIntent}" for ${normalizedCommand}. Did you mean "${suggestion}"?`, EXIT_CODE.USAGE, {
|
|
203
|
-
code: "unknown_context_intent",
|
|
204
|
-
reason: "unknown_intent",
|
|
205
|
-
field: "for",
|
|
206
|
-
flag: "--for",
|
|
207
|
-
value: normalizedIntent,
|
|
208
|
-
required: `Use a declared ${normalizedCommand} intent.`,
|
|
209
|
-
why: "Intent names are command-local contracts and cannot be inferred from output section names.",
|
|
210
|
-
nextSteps: [suggestedCommand],
|
|
211
|
-
recovery: {
|
|
212
|
-
recovery_mode: "compact",
|
|
213
|
-
attempted_command: renderPmCommand(attemptedArguments),
|
|
214
|
-
allowed_values: [...candidates].sort(),
|
|
215
|
-
suggested_retry: suggestedCommand,
|
|
216
|
-
suggested_retry_args: suggestedRetryArguments,
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
const CONTEXT_INTENT_DEFAULT_APPLIERS = {
|
|
221
|
-
context: (projected, contract, explicitTokenBudget) => {
|
|
222
|
-
if (projected.depth === undefined) {
|
|
223
|
-
projected.depth = contract.intent === "handoff" ? "deep" : "standard";
|
|
224
|
-
}
|
|
225
|
-
if (projected.section === undefined) {
|
|
226
|
-
projected.section =
|
|
227
|
-
contract.intent === "handoff"
|
|
228
|
-
? ["activity", "progress", "blockers"]
|
|
229
|
-
: ["hierarchy", "blockers", "activity"];
|
|
230
|
-
}
|
|
231
|
-
const tokenBudget = resolveIntentTokenBudget(projected.tokenBudget, contract.token_budget);
|
|
232
|
-
const budgetDerivedLimit = resolveIntentRowBudget("context", contract.intent, tokenBudget, explicitTokenBudget);
|
|
233
|
-
const requestedLimit = parsePositiveIntentTokenBudget(projected.limit);
|
|
234
|
-
const derivedLimit = String(requestedLimit === undefined
|
|
235
|
-
? budgetDerivedLimit
|
|
236
|
-
: Math.min(requestedLimit, budgetDerivedLimit));
|
|
237
|
-
if (projected.limit === undefined || requestedLimit !== undefined) {
|
|
238
|
-
projected.limit = derivedLimit;
|
|
239
|
-
}
|
|
240
|
-
if (projected.activityLimit === undefined) {
|
|
241
|
-
projected.activityLimit = derivedLimit;
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
get: (projected) => {
|
|
245
|
-
if (projected.depth === undefined && projected.fields === undefined) {
|
|
246
|
-
projected.depth = "standard";
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
list: (projected, contract, explicitTokenBudget) => {
|
|
250
|
-
if (projected.brief === undefined &&
|
|
251
|
-
projected.compact === undefined &&
|
|
252
|
-
projected.full === undefined &&
|
|
253
|
-
projected.fields === undefined) {
|
|
254
|
-
projected.fields =
|
|
255
|
-
"id,title,status,type,priority,parent,assignee,risk,blocked_by";
|
|
256
|
-
}
|
|
257
|
-
const tokenBudget = resolveIntentTokenBudget(projected.tokenBudget, contract.token_budget);
|
|
258
|
-
const budgetDerivedLimit = resolveIntentRowBudget("list", contract.intent, tokenBudget, explicitTokenBudget);
|
|
259
|
-
const requestedLimit = parsePositiveIntentTokenBudget(projected.limit);
|
|
260
|
-
if (projected.limit === undefined || requestedLimit !== undefined) {
|
|
261
|
-
projected.limit = String(requestedLimit === undefined
|
|
262
|
-
? budgetDerivedLimit
|
|
263
|
-
: Math.min(requestedLimit, budgetDerivedLimit));
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
next: (projected) => {
|
|
267
|
-
if (projected.readyOnly === undefined)
|
|
268
|
-
projected.readyOnly = true;
|
|
269
|
-
},
|
|
270
|
-
search: (projected, contract, explicitTokenBudget) => {
|
|
271
|
-
if (projected.compact === undefined &&
|
|
272
|
-
projected.full === undefined &&
|
|
273
|
-
projected.fields === undefined) {
|
|
274
|
-
projected.compact = true;
|
|
275
|
-
}
|
|
276
|
-
const tokenBudget = resolveIntentTokenBudget(projected.tokenBudget, contract.token_budget);
|
|
277
|
-
const budgetDerivedLimit = resolveIntentRowBudget("search", contract.intent, tokenBudget, explicitTokenBudget);
|
|
278
|
-
const requestedLimit = parsePositiveIntentTokenBudget(projected.limit);
|
|
279
|
-
if (projected.limit === undefined || requestedLimit !== undefined) {
|
|
280
|
-
projected.limit = String(requestedLimit === undefined
|
|
281
|
-
? budgetDerivedLimit
|
|
282
|
-
: Math.min(requestedLimit, budgetDerivedLimit));
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
/** Apply one declared read intent's defaults while preserving explicit caller options. */
|
|
287
|
-
export function applyContextIntentProjection(command, options, positionalArguments = []) {
|
|
288
|
-
const tokenBudget = options.tokenBudget ?? options.token_budget;
|
|
289
|
-
if (typeof options.for !== "string") {
|
|
290
|
-
if (tokenBudget !== undefined &&
|
|
291
|
-
(command === "get" || command === "list" || command === "search")) {
|
|
292
|
-
throw new PmCliError("--token-budget requires a declared context intent selected with --for", EXIT_CODE.USAGE, {
|
|
293
|
-
code: "missing_required_option",
|
|
294
|
-
field: "for",
|
|
295
|
-
required: "Select a context intent with --for when setting --token-budget.",
|
|
296
|
-
why: "A token-budget override has no projection contract to constrain without a selected intent.",
|
|
297
|
-
nextSteps: [
|
|
298
|
-
"Retry with --for <intent> --token-budget <n>, or omit --token-budget.",
|
|
299
|
-
],
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
if (options.tokenBudget !== undefined ||
|
|
303
|
-
options.token_budget === undefined) {
|
|
304
|
-
return options;
|
|
305
|
-
}
|
|
306
|
-
const projected = { ...options, tokenBudget };
|
|
307
|
-
delete projected.token_budget;
|
|
308
|
-
return projected;
|
|
309
|
-
}
|
|
310
|
-
const contract = resolveContextIntentContract(command, options.for, undefined, positionalArguments);
|
|
311
|
-
const explicitTokenBudget = parsePositiveIntentTokenBudget(tokenBudget) !== undefined;
|
|
312
|
-
const projected = { ...options };
|
|
313
|
-
if (projected.tokenBudget === undefined && tokenBudget !== undefined) {
|
|
314
|
-
projected.tokenBudget = tokenBudget;
|
|
315
|
-
}
|
|
316
|
-
delete projected.token_budget;
|
|
317
|
-
if (projected.tokenBudget === undefined) {
|
|
318
|
-
projected.tokenBudget = String(contract.token_budget);
|
|
319
|
-
}
|
|
320
|
-
CONTEXT_INTENT_DEFAULT_APPLIERS[command](projected, contract, explicitTokenBudget);
|
|
321
|
-
return projected;
|
|
322
|
-
}
|
|
323
|
-
const CONTEXT_INTENT_DEGRADATIONS = {
|
|
324
|
-
context: "bounded_sections",
|
|
325
|
-
get: "standard_item",
|
|
326
|
-
list: "bounded_fields_and_rows",
|
|
327
|
-
next: "bounded_ranked_rows",
|
|
328
|
-
search: "bounded_ranked_rows",
|
|
329
|
-
};
|
|
330
|
-
const MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET = 256;
|
|
331
|
-
/** Bound explanatory strings without dropping rows or invalidating pagination metadata. */
|
|
332
|
-
function compactContextIntentValue(value) {
|
|
333
|
-
if (Array.isArray(value)) {
|
|
334
|
-
return value.map(compactContextIntentValue);
|
|
335
|
-
}
|
|
336
|
-
if (value !== null && typeof value === "object") {
|
|
337
|
-
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
338
|
-
key,
|
|
339
|
-
compactContextIntentValue(entry),
|
|
340
|
-
]));
|
|
341
|
-
}
|
|
342
|
-
return typeof value === "string" && value.length > 240
|
|
343
|
-
? `${value.slice(0, 240)}…`
|
|
344
|
-
: value;
|
|
345
|
-
}
|
|
346
|
-
function parsePositiveIntentTokenBudget(value) {
|
|
347
|
-
const parsed = typeof value === "number"
|
|
348
|
-
? value
|
|
349
|
-
: typeof value === "string" && /^\d+$/u.test(value.trim())
|
|
350
|
-
? Number(value)
|
|
351
|
-
: Number.NaN;
|
|
352
|
-
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
353
|
-
}
|
|
354
|
-
function resolveIntentTokenBudget(value, declaredBudget) {
|
|
355
|
-
const parsed = parsePositiveIntentTokenBudget(value);
|
|
356
|
-
if (parsed === undefined)
|
|
357
|
-
return declaredBudget;
|
|
358
|
-
if (parsed < MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET) {
|
|
359
|
-
throw new PmCliError(`Context intent token budget must be at least ${MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET}`, EXIT_CODE.USAGE, {
|
|
360
|
-
code: "invalid_argument_value",
|
|
361
|
-
reason: "below_minimum",
|
|
362
|
-
field: "tokenBudget",
|
|
363
|
-
required: `Use an integer token budget of at least ${MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET}.`,
|
|
364
|
-
why: "Smaller ceilings cannot contain the minimum machine-readable intent receipt.",
|
|
365
|
-
nextSteps: [
|
|
366
|
-
`Retry with --token-budget ${MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET} or omit the override.`,
|
|
367
|
-
],
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
return parsed;
|
|
371
|
-
}
|
|
372
|
-
function resolveIntentRowBudget(command, intent, tokenBudget, explicitTokenBudget) {
|
|
373
|
-
if (command === "get" || command === "next")
|
|
374
|
-
return undefined;
|
|
375
|
-
const contextOrient = command === "context" && intent === "orient";
|
|
376
|
-
const overhead = command === "context"
|
|
377
|
-
? contextOrient
|
|
378
|
-
? 1200
|
|
379
|
-
: 800
|
|
380
|
-
: command === "list"
|
|
381
|
-
? 520
|
|
382
|
-
: 480;
|
|
383
|
-
const rowCost = command === "context" ? (contextOrient ? 600 : 500) : 16;
|
|
384
|
-
const calculatedLimit = Math.max(command === "context" ? 1 : 2, Math.floor((tokenBudget - overhead) / rowCost));
|
|
385
|
-
return explicitTokenBudget
|
|
386
|
-
? calculatedLimit
|
|
387
|
-
: Math.min(command === "context" ? 20 : 100, calculatedLimit);
|
|
388
|
-
}
|
|
389
|
-
/** Update a receipt until its estimate matches the serialized projection that contains it. */
|
|
390
|
-
function updateContextIntentEstimate(projected, receipt) {
|
|
391
|
-
let measuredTokens = receipt.estimated_tokens;
|
|
392
|
-
for (;;) {
|
|
393
|
-
receipt.estimated_tokens = measuredTokens;
|
|
394
|
-
const nextMeasurement = Math.ceil(Buffer.byteLength(JSON.stringify(projected), "utf8") / 4);
|
|
395
|
-
if (nextMeasurement === measuredTokens)
|
|
396
|
-
return;
|
|
397
|
-
measuredTokens = nextMeasurement;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
const CONTEXT_INTENT_ROW_KEYS = {
|
|
401
|
-
context: [
|
|
402
|
-
"high_level",
|
|
403
|
-
"low_level",
|
|
404
|
-
"blocked_fallback",
|
|
405
|
-
"recently_created",
|
|
406
|
-
"unparented",
|
|
407
|
-
"hierarchy",
|
|
408
|
-
"activity",
|
|
409
|
-
"blockers",
|
|
410
|
-
],
|
|
411
|
-
get: ["children"],
|
|
412
|
-
list: ["items"],
|
|
413
|
-
next: ["ready", "decision_needed", "gate_needed", "containers", "blocked", "held_by_others"],
|
|
414
|
-
search: ["items"],
|
|
415
|
-
};
|
|
416
|
-
/** Decode the cursor fields required to preserve a row-compacted continuation. */
|
|
417
|
-
export function decodeContextIntentCursor(cursor) {
|
|
418
|
-
try {
|
|
419
|
-
const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
420
|
-
if (typeof parsed.fingerprint !== "string" ||
|
|
421
|
-
!Number.isSafeInteger(parsed.after_index)) {
|
|
422
|
-
return undefined;
|
|
423
|
-
}
|
|
424
|
-
return {
|
|
425
|
-
fingerprint: parsed.fingerprint,
|
|
426
|
-
after_index: parsed.after_index,
|
|
427
|
-
...(typeof parsed.snapshot === "string"
|
|
428
|
-
? { snapshot: parsed.snapshot }
|
|
429
|
-
: {}),
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
catch {
|
|
433
|
-
return undefined;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
/** Resolve the stable item id carried by list rows and nested search hits. */
|
|
437
|
-
export function contextIntentRowId(row) {
|
|
438
|
-
if (row === null || typeof row !== "object")
|
|
439
|
-
return undefined;
|
|
440
|
-
if (typeof row.id === "string") {
|
|
441
|
-
return row.id;
|
|
442
|
-
}
|
|
443
|
-
const nestedId = row.item?.id;
|
|
444
|
-
return typeof nestedId === "string" ? nestedId : undefined;
|
|
445
|
-
}
|
|
446
|
-
function shrinkContextIntentRowsToBudget(projected, receipt, rows) {
|
|
447
|
-
let compacted = false;
|
|
448
|
-
for (;;) {
|
|
449
|
-
updateContextIntentEstimate(projected, receipt);
|
|
450
|
-
if (receipt.estimated_tokens <= receipt.token_budget || rows.length <= 1) {
|
|
451
|
-
return compacted;
|
|
452
|
-
}
|
|
453
|
-
const rowBytes = Buffer.byteLength(JSON.stringify(rows), "utf8");
|
|
454
|
-
const excessBytes = (receipt.estimated_tokens - receipt.token_budget) * 4;
|
|
455
|
-
rows.splice(-Math.min(rows.length - 1, Math.max(1, Math.ceil(excessBytes / Math.max(1, Math.ceil(rowBytes / rows.length))))));
|
|
456
|
-
compacted = true;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
function compactPaginatedContextIntentRows(projected, receipt, options) {
|
|
460
|
-
const rows = projected.items;
|
|
461
|
-
const cursorContinuesExistingPage = typeof projected.next_cursor === "string";
|
|
462
|
-
const cursorSource = cursorContinuesExistingPage
|
|
463
|
-
? projected.next_cursor
|
|
464
|
-
: options.after;
|
|
465
|
-
if (!Array.isArray(rows) || typeof cursorSource !== "string")
|
|
466
|
-
return false;
|
|
467
|
-
const cursorEnvelope = decodeContextIntentCursor(cursorSource);
|
|
468
|
-
if (cursorEnvelope === undefined)
|
|
469
|
-
return false;
|
|
470
|
-
const originalRowCount = rows.length;
|
|
471
|
-
const originalRows = [...rows];
|
|
472
|
-
let compacted = false;
|
|
473
|
-
for (;;) {
|
|
474
|
-
compacted =
|
|
475
|
-
shrinkContextIntentRowsToBudget(projected, receipt, rows) || compacted;
|
|
476
|
-
if (!compacted)
|
|
477
|
-
return false;
|
|
478
|
-
const lastId = contextIntentRowId(rows.at(-1));
|
|
479
|
-
if (lastId === undefined) {
|
|
480
|
-
rows.splice(0, rows.length, ...originalRows);
|
|
481
|
-
updateContextIntentEstimate(projected, receipt);
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
projected.next_cursor = encodeQueryCursor(cursorEnvelope.fingerprint, lastId, cursorContinuesExistingPage
|
|
485
|
-
? cursorEnvelope.after_index - (originalRowCount - rows.length)
|
|
486
|
-
: cursorEnvelope.after_index + rows.length, cursorEnvelope.snapshot);
|
|
487
|
-
updateContextIntentEstimate(projected, receipt);
|
|
488
|
-
if (receipt.estimated_tokens <= receipt.token_budget || rows.length <= 1) {
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
if (typeof projected.count === "number")
|
|
493
|
-
projected.count = rows.length;
|
|
494
|
-
if (typeof projected.applied_limit === "number") {
|
|
495
|
-
projected.applied_limit = rows.length;
|
|
496
|
-
}
|
|
497
|
-
return true;
|
|
498
|
-
}
|
|
499
|
-
/** Reduce root row collections deterministically while retaining at least one useful row. */
|
|
500
|
-
function compactContextIntentRows(command, projected, receipt, options) {
|
|
501
|
-
if (command === "list" || command === "search") {
|
|
502
|
-
return compactPaginatedContextIntentRows(projected, receipt, options);
|
|
503
|
-
}
|
|
504
|
-
if (command !== "next" || typeof projected.next_cursor === "string") {
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
let compacted = false;
|
|
508
|
-
for (;;) {
|
|
509
|
-
updateContextIntentEstimate(projected, receipt);
|
|
510
|
-
if (receipt.estimated_tokens <= receipt.token_budget)
|
|
511
|
-
return compacted;
|
|
512
|
-
const candidate = CONTEXT_INTENT_ROW_KEYS[command]
|
|
513
|
-
.map((key) => ({
|
|
514
|
-
key,
|
|
515
|
-
rows: Array.isArray(projected[key]) ? projected[key] : [],
|
|
516
|
-
}))
|
|
517
|
-
.filter(({ rows }) => rows.length > 0)
|
|
518
|
-
.sort((left, right) => right.rows.length - left.rows.length ||
|
|
519
|
-
left.key.localeCompare(right.key))[0];
|
|
520
|
-
if (candidate === undefined)
|
|
521
|
-
return compacted;
|
|
522
|
-
const retainedTotal = CONTEXT_INTENT_ROW_KEYS[command].reduce((total, key) => total + (Array.isArray(projected[key]) ? projected[key].length : 0), 0);
|
|
523
|
-
if (retainedTotal <= 1)
|
|
524
|
-
return compacted;
|
|
525
|
-
const removableRows = Math.min(candidate.rows.length, retainedTotal - 1);
|
|
526
|
-
const candidateBytes = Buffer.byteLength(JSON.stringify(candidate.rows), "utf8");
|
|
527
|
-
const estimatedBytesPerRow = Math.max(1, Math.ceil(candidateBytes / candidate.rows.length));
|
|
528
|
-
const excessBytes = (receipt.estimated_tokens - receipt.token_budget) * 4;
|
|
529
|
-
const removalCount = Math.min(removableRows, Math.max(1, Math.ceil(excessBytes / estimatedBytesPerRow)));
|
|
530
|
-
candidate.rows.splice(-removalCount, removalCount);
|
|
531
|
-
compacted = true;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
/** Attach budget and degradation evidence for a selected built-in read intent. */
|
|
535
|
-
export function attachContextIntentReceipt(command, options, result) {
|
|
536
|
-
if (typeof options.for !== "string")
|
|
537
|
-
return result;
|
|
538
|
-
const normalizedCommand = command.startsWith("list-") ? "list" : command;
|
|
539
|
-
if (!(normalizedCommand in CONTEXT_INTENT_DEFAULT_APPLIERS))
|
|
540
|
-
return result;
|
|
541
|
-
const builtInCommand = normalizedCommand;
|
|
542
|
-
const contract = resolveContextIntentContract(builtInCommand, options.for);
|
|
543
|
-
const effectiveTokenBudget = resolveIntentTokenBudget(options.tokenBudget ?? options.token_budget, contract.token_budget);
|
|
544
|
-
const receipt = {
|
|
545
|
-
command: builtInCommand,
|
|
546
|
-
intent: contract.intent,
|
|
547
|
-
source: contract.source,
|
|
548
|
-
included_field_groups: [...contract.included_field_groups],
|
|
549
|
-
token_budget: effectiveTokenBudget,
|
|
550
|
-
declared_token_budget: contract.token_budget,
|
|
551
|
-
token_budget_override: effectiveTokenBudget - contract.token_budget,
|
|
552
|
-
estimated_tokens: 0,
|
|
553
|
-
within_budget: true,
|
|
554
|
-
degradation: CONTEXT_INTENT_DEGRADATIONS[builtInCommand],
|
|
555
|
-
declaration_feasible: true,
|
|
556
|
-
result_omitted: false,
|
|
557
|
-
};
|
|
558
|
-
const resultWithDiagnostics = { ...result };
|
|
559
|
-
const budgetDerivedLimit = resolveIntentRowBudget(builtInCommand, contract.intent, receipt.token_budget, parsePositiveIntentTokenBudget(options.tokenBudget ?? options.token_budget) !== undefined);
|
|
560
|
-
if (budgetDerivedLimit !== undefined) {
|
|
561
|
-
const effectiveLimit = parsePositiveIntentTokenBudget(options.limit);
|
|
562
|
-
const explicitLimitBinds = effectiveLimit !== undefined && effectiveLimit < budgetDerivedLimit;
|
|
563
|
-
receipt.budget_derived_limit = budgetDerivedLimit;
|
|
564
|
-
receipt.binding_constraint = explicitLimitBinds
|
|
565
|
-
? "explicit_limit"
|
|
566
|
-
: "token_budget";
|
|
567
|
-
receipt.limit_reason = explicitLimitBinds
|
|
568
|
-
? "The caller supplied a smaller row limit than the budget-derived ceiling."
|
|
569
|
-
: "The selected intent token budget constrains the effective row ceiling.";
|
|
570
|
-
resultWithDiagnostics.budget_derived_limit = budgetDerivedLimit;
|
|
571
|
-
}
|
|
572
|
-
let projected = {
|
|
573
|
-
...resultWithDiagnostics,
|
|
574
|
-
context_intent: receipt,
|
|
575
|
-
};
|
|
576
|
-
updateContextIntentEstimate(projected, receipt);
|
|
577
|
-
if (receipt.estimated_tokens > receipt.token_budget) {
|
|
578
|
-
receipt.degradation = "recursive_budget_compaction";
|
|
579
|
-
projected = {
|
|
580
|
-
...compactContextIntentValue(resultWithDiagnostics),
|
|
581
|
-
context_intent: receipt,
|
|
582
|
-
};
|
|
583
|
-
updateContextIntentEstimate(projected, receipt);
|
|
584
|
-
}
|
|
585
|
-
if (receipt.estimated_tokens > receipt.token_budget &&
|
|
586
|
-
compactContextIntentRows(builtInCommand, projected, receipt, options)) {
|
|
587
|
-
receipt.degradation = "budget_row_compaction";
|
|
588
|
-
updateContextIntentEstimate(projected, receipt);
|
|
589
|
-
}
|
|
590
|
-
receipt.declaration_feasible =
|
|
591
|
-
receipt.estimated_tokens <= receipt.declared_token_budget;
|
|
592
|
-
if (receipt.estimated_tokens > receipt.token_budget) {
|
|
593
|
-
receipt.degradation = "budget_receipt_only";
|
|
594
|
-
receipt.result_omitted = true;
|
|
595
|
-
receipt.within_budget = false;
|
|
596
|
-
projected = {
|
|
597
|
-
budget_exceeded: {
|
|
598
|
-
omitted_result: true,
|
|
599
|
-
reason: receipt.token_budget_override === 0
|
|
600
|
-
? "declared_budget_infeasible"
|
|
601
|
-
: "effective_budget_infeasible",
|
|
602
|
-
restore_with: buildContextIntentRecoveryCommand(command, builtInCommand, contract.intent, receipt, resultWithDiagnostics),
|
|
603
|
-
},
|
|
604
|
-
context_intent: receipt,
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
return projected;
|
|
608
|
-
}
|
|
609
|
-
function collapseContinuationMetadata(options, result) {
|
|
610
|
-
if (typeof options.after !== "string" || options.after.length === 0) {
|
|
611
|
-
return result;
|
|
612
|
-
}
|
|
613
|
-
const fingerprint = decodeContextIntentCursor(options.after)?.fingerprint ?? "opaque_cursor";
|
|
614
|
-
const projected = { ...result };
|
|
615
|
-
for (const key of [
|
|
616
|
-
"applied_limit",
|
|
617
|
-
"completeness",
|
|
618
|
-
"context_intent",
|
|
619
|
-
"count",
|
|
620
|
-
"filters",
|
|
621
|
-
"has_more",
|
|
622
|
-
"now",
|
|
623
|
-
"omission_receipt",
|
|
624
|
-
"projection",
|
|
625
|
-
"row_contract",
|
|
626
|
-
"sorting",
|
|
627
|
-
"total",
|
|
628
|
-
"truncated",
|
|
629
|
-
]) {
|
|
630
|
-
delete projected[key];
|
|
631
|
-
}
|
|
632
|
-
projected.continuation_contract = {
|
|
633
|
-
fingerprint,
|
|
634
|
-
metadata: "reference",
|
|
635
|
-
restore_with: "omit --after",
|
|
636
|
-
};
|
|
637
|
-
return projected;
|
|
638
|
-
}
|
|
639
|
-
/** Return whether one projected value is a mutable output record. */
|
|
640
|
-
function isOutputRecord(value) {
|
|
641
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
642
|
-
}
|
|
643
|
-
/** Build a shell-safe bounded retry while retaining required read positionals. */
|
|
644
|
-
function buildContextIntentRecoveryCommand(command, builtInCommand, intent, receipt, result) {
|
|
645
|
-
const recoveryTarget = builtInCommand === "get" &&
|
|
646
|
-
isOutputRecord(result.item) &&
|
|
647
|
-
typeof result.item.id === "string"
|
|
648
|
-
? result.item.id
|
|
649
|
-
: builtInCommand === "search" && typeof result.query === "string"
|
|
650
|
-
? result.query
|
|
651
|
-
: undefined;
|
|
652
|
-
const recoveryPositional = recoveryTarget === undefined
|
|
653
|
-
? ""
|
|
654
|
-
: ` '${recoveryTarget.replaceAll("'", `'"'"'`)}'`;
|
|
655
|
-
const boundedRowLimit = builtInCommand === "get"
|
|
656
|
-
? ""
|
|
657
|
-
: ` --limit ${receipt.budget_derived_limit ?? 1}`;
|
|
658
|
-
return `pm ${command}${recoveryPositional} --for ${intent} --token-budget ${Math.ceil(receipt.estimated_tokens / 100) * 100}${boundedRowLimit}`;
|
|
659
|
-
}
|
|
660
|
-
/** Read one numeric fixed-point estimate from an optional receipt. */
|
|
661
|
-
function receiptEstimate(value, field) {
|
|
662
|
-
if (!isOutputRecord(value))
|
|
663
|
-
return undefined;
|
|
664
|
-
return typeof value[field] === "number" ? value[field] : undefined;
|
|
665
|
-
}
|
|
666
|
-
/** Stabilize every token receipt after suppressing discovery-only metadata. */
|
|
667
|
-
function stabilizeSuppressedRowContractReceipts(result, options) {
|
|
668
|
-
let finalized = result;
|
|
669
|
-
for (let iteration = 0; iteration < 8; iteration += 1) {
|
|
670
|
-
const previousContextEstimate = receiptEstimate(finalized.context_intent, "estimated_tokens");
|
|
671
|
-
const previousReadEstimate = receiptEstimate(finalized.read_output, "estimated_tokens");
|
|
672
|
-
const previousSessionEstimate = receiptEstimate(finalized.read_session, "spent_this_call_tokens");
|
|
673
|
-
if (isOutputRecord(finalized.context_intent)) {
|
|
674
|
-
updateContextIntentEstimate(finalized, finalized.context_intent);
|
|
675
|
-
}
|
|
676
|
-
finalized = stabilizeReadOutputReceiptEstimates(finalized, options);
|
|
677
|
-
if (receiptEstimate(finalized.context_intent, "estimated_tokens") ===
|
|
678
|
-
previousContextEstimate &&
|
|
679
|
-
receiptEstimate(finalized.read_output, "estimated_tokens") ===
|
|
680
|
-
previousReadEstimate &&
|
|
681
|
-
receiptEstimate(finalized.read_session, "spent_this_call_tokens") ===
|
|
682
|
-
previousSessionEstimate) {
|
|
683
|
-
break;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
return finalized;
|
|
687
|
-
}
|
|
688
|
-
/** Attach universal row, omission, and optional intent-budget contracts in rendering order. */
|
|
689
|
-
export function attachReadOutputContracts(command, options, result) {
|
|
690
|
-
const disclosedResult = attachOutputOmissionReceipt(command, result);
|
|
691
|
-
const projected = typeof disclosedResult === "object" &&
|
|
692
|
-
disclosedResult !== null &&
|
|
693
|
-
!Array.isArray(disclosedResult)
|
|
694
|
-
? applyReadOutputDimensions(command ?? "", options, collapseContinuationMetadata(options, attachContextIntentReceipt(command ?? "", options, disclosedResult)))
|
|
695
|
-
: disclosedResult;
|
|
696
|
-
propagateContextUsageServingReceipt(result, projected);
|
|
697
|
-
if (options.outputRowContract === true ||
|
|
698
|
-
options.output_row_contract === true ||
|
|
699
|
-
typeof projected !== "object" ||
|
|
700
|
-
projected === null ||
|
|
701
|
-
Array.isArray(projected) ||
|
|
702
|
-
!Object.hasOwn(projected, "row_contract")) {
|
|
703
|
-
return projected;
|
|
704
|
-
}
|
|
705
|
-
const suppressed = stabilizeSuppressedRowContractReceipts(Object.fromEntries(Object.entries(projected).filter(([key]) => key !== "row_contract")), options);
|
|
706
|
-
propagateContextUsageServingReceipt(projected, suppressed);
|
|
707
|
-
return suppressed;
|
|
708
|
-
}
|
|
1
|
+
!(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]="6436107d-eedc-5c97-9d8f-6f119c9bbe29")}catch(e2){}})();import{AsyncLocalStorage}from"node:async_hooks";import{renderPmCommand}from"./command-line.js";import{attachOutputOmissionReceipt}from"./output-projection.js";import{encodeQueryCursor}from"./pagination.js";import{applyReadOutputDimensions,stabilizeReadOutputReceiptEstimates}from"./read-output-contracts.js";import{propagateContextUsageServingReceipt}from"./context-usage.js";import{EXIT_CODE}from"../core/shared/constants.js";import{PmCliError}from"../core/shared/errors.js";const PM_CONTEXT_INTENT_CONTRACTS=Object.freeze([{command:"context",intent:"orient",description:"Bounded active hierarchy, ownership, blockers, and recent progress.",included_field_groups:["summary","focus","hierarchy","blockers","activity"],token_budget:3e3,source:"core"},{command:"context",intent:"handoff",description:"Active ownership, evidence, decisions, and immediate continuation context.",included_field_groups:["summary","focus","in_progress","decisions","activity"],token_budget:2200,source:"core"},{command:"get",intent:"inspect",description:"Standard-depth item metadata, relationships, evidence, and lifecycle state.",included_field_groups:["item","children","claim_state","linked"],token_budget:3200,source:"core"},{command:"list",intent:"triage",description:"A budget-derived page of compact governance, ownership, priority, and blocker rows for triage.",included_field_groups:["identity","governance","ownership","dependencies"],token_budget:3200,source:"core"},{command:"next",intent:"execute",description:"The highest-ranked actionable work with concise ranking evidence.",included_field_groups:["recommended"],token_budget:1200,source:"core"},{command:"search",intent:"discover",description:"A budget-derived page of ranked canonical lineage candidates with compact match evidence.",included_field_groups:["identity","status","lineage","match"],token_budget:1800,source:"core"}]);const activeContextIntentContracts=new AsyncLocalStorage;function getActiveContextIntentContracts(){return activeContextIntentContracts.getStore()??PM_CONTEXT_INTENT_CONTRACTS}function runWithContextIntentContracts(layers,run){return activeContextIntentContracts.run(composeContextIntentContracts(layers.workspaceContracts,layers.packageContracts),run)}function normalizeContextIntentDeclaration(declaration,source){const command=declaration.command.trim().toLowerCase();const intent=declaration.intent.trim().toLowerCase();const key=`${command}:${intent}`;if(!/^[a-z0-9][a-z0-9-]*$/.test(command)||!/^[a-z0-9][a-z0-9-]*$/.test(intent)){throw new TypeError(`Invalid context intent command or name: ${key}`)}if(declaration.description.trim().length===0){throw new TypeError(`Context intent ${key} requires a non-empty description`)}if(!Number.isSafeInteger(declaration.token_budget)||declaration.token_budget<=0){throw new TypeError(`Context intent ${key} requires a positive integer token_budget`)}const includedFieldGroups=[...new Set(declaration.included_field_groups.map(field=>field.trim()).filter(Boolean))];if(includedFieldGroups.length===0){throw new TypeError(`Context intent ${key} requires included_field_groups`)}return{command,intent,description:declaration.description.trim(),included_field_groups:includedFieldGroups,token_budget:declaration.token_budget,source}}function composeContextIntentContracts(workspaceContracts=[],packageContracts=[]){const layers=[{source:"core",contracts:PM_CONTEXT_INTENT_CONTRACTS,allowOverride:false},{source:"package",contracts:packageContracts,allowOverride:false},{source:"workspace",contracts:workspaceContracts,allowOverride:true}];const composed=new Map;const keysSeenWithinLayer=new Set;for(const layer of layers){keysSeenWithinLayer.clear();for(const declaration of layer.contracts){const normalized=normalizeContextIntentDeclaration(declaration,layer.source);const key=`${normalized.command}:${normalized.intent}`;if(keysSeenWithinLayer.has(key)){throw new TypeError(`Duplicate context intent declaration: ${key}`)}keysSeenWithinLayer.add(key);if(!layer.allowOverride&&composed.has(key)){throw new TypeError(`Duplicate context intent declaration: ${key}`)}composed.set(key,normalized)}}return[...composed.values()].sort((left,right)=>left.command.localeCompare(right.command)||left.intent.localeCompare(right.intent))}function resolveContextIntentContract(command,intent,contracts=getActiveContextIntentContracts(),positionalArguments=[]){const normalizedCommand=command.trim().toLowerCase();const normalizedIntent=intent.trim().toLowerCase();const exact=contracts.find(entry=>entry.command===normalizedCommand&&entry.intent===normalizedIntent);if(exact)return{...exact,source:exact.source??"core"};const candidates=contracts.filter(entry=>entry.command===normalizedCommand).map(entry=>entry.intent);if(candidates.length===0)return void 0;const suggestion=candidates.map(candidate=>{const rows=Array.from({length:normalizedIntent.length+1},(_,index)=>index);for(let candidateIndex=1;candidateIndex<=candidate.length;candidateIndex+=1){let previous=rows[0];rows[0]=candidateIndex;for(let intentIndex=1;intentIndex<=normalizedIntent.length;intentIndex+=1){const prior=rows[intentIndex];rows[intentIndex]=Math.min(rows[intentIndex]+1,rows[intentIndex-1]+1,previous+(candidate[candidateIndex-1]===normalizedIntent[intentIndex-1]?0:1));previous=prior}}return{candidate,distance:rows[normalizedIntent.length]}}).sort((left,right)=>left.distance-right.distance||left.candidate.localeCompare(right.candidate))[0].candidate;const attemptedArguments=[normalizedCommand,...positionalArguments,"--for",normalizedIntent];const suggestedRetryArguments=[normalizedCommand,...positionalArguments,"--for",suggestion];const suggestedCommand=renderPmCommand(suggestedRetryArguments);throw new PmCliError(`Unknown context intent "${normalizedIntent}" for ${normalizedCommand}. Did you mean "${suggestion}"?`,EXIT_CODE.USAGE,{code:"unknown_context_intent",reason:"unknown_intent",field:"for",flag:"--for",value:normalizedIntent,required:`Use a declared ${normalizedCommand} intent.`,why:"Intent names are command-local contracts and cannot be inferred from output section names.",nextSteps:[suggestedCommand],recovery:{recovery_mode:"compact",attempted_command:renderPmCommand(attemptedArguments),allowed_values:[...candidates].sort(),suggested_retry:suggestedCommand,suggested_retry_args:suggestedRetryArguments}})}const CONTEXT_INTENT_DEFAULT_APPLIERS={context:(projected,contract,explicitTokenBudget)=>{if(projected.depth===void 0){projected.depth=contract.intent==="handoff"?"deep":"standard"}if(projected.section===void 0){projected.section=contract.intent==="handoff"?["activity","progress","blockers"]:["hierarchy","blockers","activity"]}const tokenBudget=resolveIntentTokenBudget(projected.tokenBudget,contract.token_budget);const budgetDerivedLimit=resolveIntentRowBudget("context",contract.intent,tokenBudget,explicitTokenBudget);const requestedLimit=parsePositiveIntentTokenBudget(projected.limit);const derivedLimit=String(requestedLimit===void 0?budgetDerivedLimit:Math.min(requestedLimit,budgetDerivedLimit));if(projected.limit===void 0||requestedLimit!==void 0){projected.limit=derivedLimit}if(projected.activityLimit===void 0){projected.activityLimit=derivedLimit}},get:projected=>{if(projected.depth===void 0&&projected.fields===void 0){projected.depth="standard"}},list:(projected,contract,explicitTokenBudget)=>{if(projected.brief===void 0&&projected.compact===void 0&&projected.full===void 0&&projected.fields===void 0){projected.fields="id,title,status,type,priority,parent,assignee,risk,blocked_by"}const tokenBudget=resolveIntentTokenBudget(projected.tokenBudget,contract.token_budget);const budgetDerivedLimit=resolveIntentRowBudget("list",contract.intent,tokenBudget,explicitTokenBudget);const requestedLimit=parsePositiveIntentTokenBudget(projected.limit);if(projected.limit===void 0||requestedLimit!==void 0){projected.limit=String(requestedLimit===void 0?budgetDerivedLimit:Math.min(requestedLimit,budgetDerivedLimit))}},next:projected=>{if(projected.readyOnly===void 0)projected.readyOnly=true},search:(projected,contract,explicitTokenBudget)=>{if(projected.compact===void 0&&projected.full===void 0&&projected.fields===void 0){projected.compact=true}const tokenBudget=resolveIntentTokenBudget(projected.tokenBudget,contract.token_budget);const budgetDerivedLimit=resolveIntentRowBudget("search",contract.intent,tokenBudget,explicitTokenBudget);const requestedLimit=parsePositiveIntentTokenBudget(projected.limit);if(projected.limit===void 0||requestedLimit!==void 0){projected.limit=String(requestedLimit===void 0?budgetDerivedLimit:Math.min(requestedLimit,budgetDerivedLimit))}}};function applyContextIntentProjection(command,options,positionalArguments=[]){const tokenBudget=options.tokenBudget??options.token_budget;if(typeof options.for!=="string"){if(tokenBudget!==void 0&&(command==="get"||command==="list"||command==="search")){throw new PmCliError("--token-budget requires a declared context intent selected with --for",EXIT_CODE.USAGE,{code:"missing_required_option",field:"for",required:"Select a context intent with --for when setting --token-budget.",why:"A token-budget override has no projection contract to constrain without a selected intent.",nextSteps:["Retry with --for <intent> --token-budget <n>, or omit --token-budget."]})}if(options.tokenBudget!==void 0||options.token_budget===void 0){return options}const projected2={...options,tokenBudget};delete projected2.token_budget;return projected2}const contract=resolveContextIntentContract(command,options.for,void 0,positionalArguments);const explicitTokenBudget=parsePositiveIntentTokenBudget(tokenBudget)!==void 0;const projected={...options};if(projected.tokenBudget===void 0&&tokenBudget!==void 0){projected.tokenBudget=tokenBudget}delete projected.token_budget;if(projected.tokenBudget===void 0){projected.tokenBudget=String(contract.token_budget)}CONTEXT_INTENT_DEFAULT_APPLIERS[command](projected,contract,explicitTokenBudget);return projected}const CONTEXT_INTENT_DEGRADATIONS={context:"bounded_sections",get:"standard_item",list:"bounded_fields_and_rows",next:"bounded_ranked_rows",search:"bounded_ranked_rows"};const MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET=256;function compactContextIntentValue(value){if(Array.isArray(value)){return value.map(compactContextIntentValue)}if(value!==null&&typeof value==="object"){return Object.fromEntries(Object.entries(value).map(([key,entry])=>[key,compactContextIntentValue(entry)]))}return typeof value==="string"&&value.length>240?`${value.slice(0,240)}\u2026`:value}function parsePositiveIntentTokenBudget(value){const parsed=typeof value==="number"?value:typeof value==="string"&&/^\d+$/u.test(value.trim())?Number(value):Number.NaN;return Number.isSafeInteger(parsed)&&parsed>0?parsed:void 0}function resolveIntentTokenBudget(value,declaredBudget){const parsed=parsePositiveIntentTokenBudget(value);if(parsed===void 0)return declaredBudget;if(parsed<MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET){throw new PmCliError(`Context intent token budget must be at least ${MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET}`,EXIT_CODE.USAGE,{code:"invalid_argument_value",reason:"below_minimum",field:"tokenBudget",required:`Use an integer token budget of at least ${MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET}.`,why:"Smaller ceilings cannot contain the minimum machine-readable intent receipt.",nextSteps:[`Retry with --token-budget ${MINIMUM_CONTEXT_INTENT_TOKEN_BUDGET} or omit the override.`]})}return parsed}function resolveIntentRowBudget(command,intent,tokenBudget,explicitTokenBudget){if(command==="get"||command==="next")return void 0;const contextOrient=command==="context"&&intent==="orient";const overhead=command==="context"?contextOrient?1200:800:command==="list"?520:480;const rowCost=command==="context"?contextOrient?600:500:16;const calculatedLimit=Math.max(command==="context"?1:2,Math.floor((tokenBudget-overhead)/rowCost));return explicitTokenBudget?calculatedLimit:Math.min(command==="context"?20:100,calculatedLimit)}function updateContextIntentEstimate(projected,receipt){let measuredTokens=receipt.estimated_tokens;for(;;){receipt.estimated_tokens=measuredTokens;const nextMeasurement=Math.ceil(Buffer.byteLength(JSON.stringify(projected),"utf8")/4);if(nextMeasurement===measuredTokens)return;measuredTokens=nextMeasurement}}const CONTEXT_INTENT_ROW_KEYS={context:["high_level","low_level","blocked_fallback","recently_created","unparented","hierarchy","activity","blockers"],get:["children"],list:["items"],next:["ready","decision_needed","gate_needed","containers","blocked","held_by_others"],search:["items"]};function decodeContextIntentCursor(cursor){try{const parsed=JSON.parse(Buffer.from(cursor,"base64url").toString("utf8"));if(typeof parsed.fingerprint!=="string"||!Number.isSafeInteger(parsed.after_index)){return void 0}return{fingerprint:parsed.fingerprint,after_index:parsed.after_index,...typeof parsed.snapshot==="string"?{snapshot:parsed.snapshot}:{}}}catch{return void 0}}function contextIntentRowId(row){if(row===null||typeof row!=="object")return void 0;if(typeof row.id==="string"){return row.id}const nestedId=row.item?.id;return typeof nestedId==="string"?nestedId:void 0}function shrinkContextIntentRowsToBudget(projected,receipt,rows){let compacted=false;for(;;){updateContextIntentEstimate(projected,receipt);if(receipt.estimated_tokens<=receipt.token_budget||rows.length<=1){return compacted}const rowBytes=Buffer.byteLength(JSON.stringify(rows),"utf8");const excessBytes=(receipt.estimated_tokens-receipt.token_budget)*4;rows.splice(-Math.min(rows.length-1,Math.max(1,Math.ceil(excessBytes/Math.max(1,Math.ceil(rowBytes/rows.length))))));compacted=true}}function compactPaginatedContextIntentRows(projected,receipt,options){const rows=projected.items;const cursorContinuesExistingPage=typeof projected.next_cursor==="string";const cursorSource=cursorContinuesExistingPage?projected.next_cursor:options.after;if(!Array.isArray(rows)||typeof cursorSource!=="string")return false;const cursorEnvelope=decodeContextIntentCursor(cursorSource);if(cursorEnvelope===void 0)return false;const originalRowCount=rows.length;const originalRows=[...rows];let compacted=false;for(;;){compacted=shrinkContextIntentRowsToBudget(projected,receipt,rows)||compacted;if(!compacted)return false;const lastId=contextIntentRowId(rows.at(-1));if(lastId===void 0){rows.splice(0,rows.length,...originalRows);updateContextIntentEstimate(projected,receipt);return false}projected.next_cursor=encodeQueryCursor(cursorEnvelope.fingerprint,lastId,cursorContinuesExistingPage?cursorEnvelope.after_index-(originalRowCount-rows.length):cursorEnvelope.after_index+rows.length,cursorEnvelope.snapshot);updateContextIntentEstimate(projected,receipt);if(receipt.estimated_tokens<=receipt.token_budget||rows.length<=1){break}}if(typeof projected.count==="number")projected.count=rows.length;if(typeof projected.applied_limit==="number"){projected.applied_limit=rows.length}return true}function compactContextIntentRows(command,projected,receipt,options){if(command==="list"||command==="search"){return compactPaginatedContextIntentRows(projected,receipt,options)}if(command!=="next"||typeof projected.next_cursor==="string"){return false}let compacted=false;for(;;){updateContextIntentEstimate(projected,receipt);if(receipt.estimated_tokens<=receipt.token_budget)return compacted;const candidate=CONTEXT_INTENT_ROW_KEYS[command].map(key=>({key,rows:Array.isArray(projected[key])?projected[key]:[]})).filter(({rows})=>rows.length>0).sort((left,right)=>right.rows.length-left.rows.length||left.key.localeCompare(right.key))[0];if(candidate===void 0)return compacted;const retainedTotal=CONTEXT_INTENT_ROW_KEYS[command].reduce((total,key)=>total+(Array.isArray(projected[key])?projected[key].length:0),0);if(retainedTotal<=1)return compacted;const removableRows=Math.min(candidate.rows.length,retainedTotal-1);const candidateBytes=Buffer.byteLength(JSON.stringify(candidate.rows),"utf8");const estimatedBytesPerRow=Math.max(1,Math.ceil(candidateBytes/candidate.rows.length));const excessBytes=(receipt.estimated_tokens-receipt.token_budget)*4;const removalCount=Math.min(removableRows,Math.max(1,Math.ceil(excessBytes/estimatedBytesPerRow)));candidate.rows.splice(-removalCount,removalCount);compacted=true}}function attachContextIntentReceipt(command,options,result){if(typeof options.for!=="string")return result;const normalizedCommand=command.startsWith("list-")?"list":command;if(!(normalizedCommand in CONTEXT_INTENT_DEFAULT_APPLIERS))return result;const builtInCommand=normalizedCommand;const contract=resolveContextIntentContract(builtInCommand,options.for);const effectiveTokenBudget=resolveIntentTokenBudget(options.tokenBudget??options.token_budget,contract.token_budget);const receipt={command:builtInCommand,intent:contract.intent,source:contract.source,included_field_groups:[...contract.included_field_groups],token_budget:effectiveTokenBudget,declared_token_budget:contract.token_budget,token_budget_override:effectiveTokenBudget-contract.token_budget,estimated_tokens:0,within_budget:true,degradation:CONTEXT_INTENT_DEGRADATIONS[builtInCommand],declaration_feasible:true,result_omitted:false};const resultWithDiagnostics={...result};const budgetDerivedLimit=resolveIntentRowBudget(builtInCommand,contract.intent,receipt.token_budget,parsePositiveIntentTokenBudget(options.tokenBudget??options.token_budget)!==void 0);if(budgetDerivedLimit!==void 0){const effectiveLimit=parsePositiveIntentTokenBudget(options.limit);const explicitLimitBinds=effectiveLimit!==void 0&&effectiveLimit<budgetDerivedLimit;receipt.budget_derived_limit=budgetDerivedLimit;receipt.binding_constraint=explicitLimitBinds?"explicit_limit":"token_budget";receipt.limit_reason=explicitLimitBinds?"The caller supplied a smaller row limit than the budget-derived ceiling.":"The selected intent token budget constrains the effective row ceiling.";resultWithDiagnostics.budget_derived_limit=budgetDerivedLimit}let projected={...resultWithDiagnostics,context_intent:receipt};updateContextIntentEstimate(projected,receipt);if(receipt.estimated_tokens>receipt.token_budget){receipt.degradation="recursive_budget_compaction";projected={...compactContextIntentValue(resultWithDiagnostics),context_intent:receipt};updateContextIntentEstimate(projected,receipt)}if(receipt.estimated_tokens>receipt.token_budget&&compactContextIntentRows(builtInCommand,projected,receipt,options)){receipt.degradation="budget_row_compaction";updateContextIntentEstimate(projected,receipt)}receipt.declaration_feasible=receipt.estimated_tokens<=receipt.declared_token_budget;if(receipt.estimated_tokens>receipt.token_budget){receipt.degradation="budget_receipt_only";receipt.result_omitted=true;receipt.within_budget=false;projected={budget_exceeded:{omitted_result:true,reason:receipt.token_budget_override===0?"declared_budget_infeasible":"effective_budget_infeasible",restore_with:buildContextIntentRecoveryCommand(command,builtInCommand,contract.intent,receipt,resultWithDiagnostics)},context_intent:receipt}}return projected}function collapseContinuationMetadata(options,result){if(typeof options.after!=="string"||options.after.length===0){return result}const fingerprint=decodeContextIntentCursor(options.after)?.fingerprint??"opaque_cursor";const projected={...result};for(const key of["applied_limit","completeness","context_intent","count","filters","has_more","now","omission_receipt","projection","row_contract","sorting","total","truncated"]){delete projected[key]}projected.continuation_contract={fingerprint,metadata:"reference",restore_with:"omit --after"};return projected}function isOutputRecord(value){return value!==null&&typeof value==="object"&&!Array.isArray(value)}function buildContextIntentRecoveryCommand(command,builtInCommand,intent,receipt,result){const recoveryTarget=builtInCommand==="get"&&isOutputRecord(result.item)&&typeof result.item.id==="string"?result.item.id:builtInCommand==="search"&&typeof result.query==="string"?result.query:void 0;const recoveryPositional=recoveryTarget===void 0?"":` '${recoveryTarget.replaceAll("'",`'"'"'`)}'`;const boundedRowLimit=builtInCommand==="get"?"":` --limit ${receipt.budget_derived_limit??1}`;return`pm ${command}${recoveryPositional} --for ${intent} --token-budget ${Math.ceil(receipt.estimated_tokens/100)*100}${boundedRowLimit}`}function receiptEstimate(value,field){if(!isOutputRecord(value))return void 0;return typeof value[field]==="number"?value[field]:void 0}function stabilizeSuppressedRowContractReceipts(result,options){let finalized=result;for(let iteration=0;iteration<8;iteration+=1){const previousContextEstimate=receiptEstimate(finalized.context_intent,"estimated_tokens");const previousReadEstimate=receiptEstimate(finalized.read_output,"estimated_tokens");const previousSessionEstimate=receiptEstimate(finalized.read_session,"spent_this_call_tokens");if(isOutputRecord(finalized.context_intent)){updateContextIntentEstimate(finalized,finalized.context_intent)}finalized=stabilizeReadOutputReceiptEstimates(finalized,options);if(receiptEstimate(finalized.context_intent,"estimated_tokens")===previousContextEstimate&&receiptEstimate(finalized.read_output,"estimated_tokens")===previousReadEstimate&&receiptEstimate(finalized.read_session,"spent_this_call_tokens")===previousSessionEstimate){break}}return finalized}function attachReadOutputContracts(command,options,result){const disclosedResult=attachOutputOmissionReceipt(command,result);const projected=typeof disclosedResult==="object"&&disclosedResult!==null&&!Array.isArray(disclosedResult)?applyReadOutputDimensions(command??"",options,collapseContinuationMetadata(options,attachContextIntentReceipt(command??"",options,disclosedResult))):disclosedResult;propagateContextUsageServingReceipt(result,projected);if(options.outputRowContract===true||options.output_row_contract===true||typeof projected!=="object"||projected===null||Array.isArray(projected)||!Object.hasOwn(projected,"row_contract")){return projected}const suppressed=stabilizeSuppressedRowContractReceipts(Object.fromEntries(Object.entries(projected).filter(([key])=>key!=="row_contract")),options);propagateContextUsageServingReceipt(projected,suppressed);return suppressed}export{PM_CONTEXT_INTENT_CONTRACTS,applyContextIntentProjection,attachContextIntentReceipt,attachReadOutputContracts,composeContextIntentContracts,contextIntentRowId,decodeContextIntentCursor,getActiveContextIntentContracts,resolveContextIntentContract,runWithContextIntentContracts};
|
|
709
2
|
//# sourceMappingURL=context-intent-contracts.js.map
|
|
710
|
-
//# debugId=d6fc4c70-c955-5fb5-ab4b-5dfa1200d58d
|