@unbrained/pm-cli 2026.9.7 → 2026.9.8
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 +5 -0
- package/.agents/skills/pm-user/references/ECOSYSTEM_PLANNING.md +95 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +211 -181
- 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.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-3BZZA6A3.js +5 -0
- package/dist/cli-bundle/chunks/chunk-AMRDVX36.js +235 -0
- package/dist/cli-bundle/chunks/chunk-DAM4CBBR.js +2202 -0
- package/dist/cli-bundle/chunks/{chunk-WYRZZ5ZE.js → chunk-DEZPZOQ7.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-FLDWYEND.js +77 -0
- package/dist/cli-bundle/chunks/{chunk-NPN5I67J.js → chunk-G5ADGQ2D.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-JAAEYHUA.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-JX4DH4WC.js → chunk-KR3RP4FH.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-LEZOUXG6.js +2 -0
- package/dist/cli-bundle/chunks/chunk-NSAPNEYH.js +2 -0
- package/dist/cli-bundle/chunks/chunk-QOEKOECV.js +29 -0
- package/dist/cli-bundle/chunks/chunk-RHSFOMHU.js +2 -0
- package/dist/cli-bundle/chunks/chunk-XOD2PCB6.js +20 -0
- package/dist/cli-bundle/chunks/{chunk-JT6XF6GE.js → chunk-YVEQ2AMO.js} +4 -4
- package/dist/cli-bundle/chunks/register-list-query-KSK3R63M.js +11 -0
- package/dist/cli-bundle/chunks/register-mutation-IQ5C7U6O.js +20 -0
- package/dist/cli-bundle/chunks/{register-operations-I5W3KMGB.js → register-operations-DWVHR2NC.js} +2 -2
- package/dist/cli-bundle/chunks/register-setup-BQ5SVD4B.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-3WRPWLA7.js +3 -0
- package/dist/cli-bundle/focused-chunks/chunk-7MBUII7U.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-COPBO5HW.js +8 -0
- package/dist/cli-bundle/focused-chunks/chunk-DUN4IXYN.js +20 -0
- package/dist/cli-bundle/focused-chunks/{chunk-LIJIA4TY.js → chunk-EE5QSM4Z.js} +3 -3
- package/dist/cli-bundle/focused-chunks/chunk-HJVARYM3.js +6 -0
- package/dist/cli-bundle/focused-chunks/chunk-IAUOUGVR.js +177 -0
- package/dist/cli-bundle/focused-chunks/chunk-KOOMJ54F.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-MZDXX7JY.js +56 -0
- package/dist/cli-bundle/focused-chunks/{chunk-M6PBRFSH.js → chunk-OPFHFGDD.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-QHNETP77.js +9 -0
- package/dist/cli-bundle/focused-chunks/{chunk-3BZEOXLT.js → chunk-RMWES4M6.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-RXT4P5QH.js +10 -0
- package/dist/cli-bundle/focused-chunks/chunk-SDOL6FM2.js +12 -0
- package/dist/cli-bundle/focused-chunks/chunk-SQV4AAUC.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-PEFABF7E.js → chunk-WE3IUNIW.js} +3 -3
- package/dist/cli-bundle/focused-chunks/chunk-YALOUBWJ.js +2 -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 +29 -29
- 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/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.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.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 +157 -837
- 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.js +1 -2261
- package/dist/sdk/governance/workspace-position.js +1 -163
- package/dist/sdk/governance.d.ts +1 -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 -0
- 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.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.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.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.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.js +1 -4
- package/dist/sdk/runtime-stats-options.js +1 -38
- 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.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.js +1 -245
- package/docs/AGENT_GUIDE.md +1 -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 +3 -0
- package/docs/SCRIPTING.md +21 -0
- package/docs/TESTING.md +23 -0
- package/docs/generated/FLAG_LEXICON_BUDGETS.md +5 -5
- package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +2 -2
- package/marketplace.json +2 -2
- package/package.json +1 -1
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-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-BAX2BYUW.js +0 -2111
- package/dist/cli-bundle/chunks/chunk-CKOL5U7J.js +0 -77
- 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-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-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,965 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module sdk/query/calendar
|
|
3
|
-
*
|
|
4
|
-
* Implements the pm calendar command surface and its agent-facing runtime behavior.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
!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]="47de55f1-589f-5743-bcb8-3b7a6302dfbb")}catch(e){}}();
|
|
8
|
-
import { assertInitializedTracker } from "../environment/tracker-preflight.js";
|
|
9
|
-
import { encode as encodeToon } from "@toon-format/toon";
|
|
10
|
-
import { getActiveExtensionRegistrations, resolveItemTypeRegistry, normalizeStatusInput, collectRuntimeFilterValues, matchesRuntimeFilters, resolveRuntimeFieldRegistry, resolveRuntimeStatusRegistry, EXIT_CODE, PmCliError, levenshteinDistanceWithinLimit, compareTimestampStrings, nowIso, resolveIsoOrRelative, listAllItemMetadataLight, resolvePmRoot, readSettings, } from "../runtime-primitives.js";
|
|
11
|
-
import { parseIntegerLimit, parsePriority, parseType, } from "./parsers.js";
|
|
12
|
-
import { weekdayOrderIndex, } from "../../types/index.js";
|
|
13
|
-
const CALENDAR_VIEW_VALUES = ["agenda", "day", "week", "month"];
|
|
14
|
-
const CALENDAR_OUTPUT_VALUES = ["markdown", "toon", "json"];
|
|
15
|
-
const UTC_DAY_TO_WEEKDAY = [
|
|
16
|
-
"sun",
|
|
17
|
-
"mon",
|
|
18
|
-
"tue",
|
|
19
|
-
"wed",
|
|
20
|
-
"thu",
|
|
21
|
-
"fri",
|
|
22
|
-
"sat",
|
|
23
|
-
];
|
|
24
|
-
const DEFAULT_RECURRENCE_LOOKAHEAD_DAYS = 365;
|
|
25
|
-
const DEFAULT_RECURRENCE_LOOKBACK_DAYS = 365;
|
|
26
|
-
const DEFAULT_EVENTS_ONLY_LOOKAHEAD_DAYS = 28;
|
|
27
|
-
const MAX_RECURRENCE_OCCURRENCES = 1000;
|
|
28
|
-
function parseNonNegativeInteger(raw, label) {
|
|
29
|
-
if (raw === undefined)
|
|
30
|
-
return undefined;
|
|
31
|
-
const parsed = Number(raw);
|
|
32
|
-
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
33
|
-
throw new PmCliError(`${label} must be a non-negative integer`, EXIT_CODE.USAGE);
|
|
34
|
-
}
|
|
35
|
-
return parsed;
|
|
36
|
-
}
|
|
37
|
-
function parseIncludeSources(raw) {
|
|
38
|
-
if (!raw) {
|
|
39
|
-
return new Set(["deadlines", "reminders", "events"]);
|
|
40
|
-
}
|
|
41
|
-
const normalized = raw.trim().toLowerCase();
|
|
42
|
-
if (normalized === "all") {
|
|
43
|
-
return new Set(["deadlines", "reminders", "events"]);
|
|
44
|
-
}
|
|
45
|
-
const values = normalized
|
|
46
|
-
.split(/[|,]/)
|
|
47
|
-
.map((value) => value.trim())
|
|
48
|
-
.filter((value) => value.length > 0);
|
|
49
|
-
if (values.length === 0) {
|
|
50
|
-
throw new PmCliError("Calendar include filter must not be empty", EXIT_CODE.USAGE);
|
|
51
|
-
}
|
|
52
|
-
const include = new Set();
|
|
53
|
-
for (const value of values) {
|
|
54
|
-
if (value === "deadlines" || value === "deadline") {
|
|
55
|
-
include.add("deadlines");
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (value === "reminders" || value === "reminder") {
|
|
59
|
-
include.add("reminders");
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (value === "events" || value === "event" || value === "scheduled") {
|
|
63
|
-
include.add("events");
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
throw new PmCliError("Calendar include filter must be deadlines|reminders|events|scheduled|all", EXIT_CODE.USAGE);
|
|
67
|
-
}
|
|
68
|
-
return include;
|
|
69
|
-
}
|
|
70
|
-
/** Suggest the closest valid choice for a mistyped enum value (within edit distance 2) so an agent gets an actionable "did you mean" hint instead of just a list of choices (never-block UX). */
|
|
71
|
-
function suggestClosestChoice(value, choices) {
|
|
72
|
-
let best;
|
|
73
|
-
for (const choice of choices) {
|
|
74
|
-
const distance = levenshteinDistanceWithinLimit(value, choice, 2);
|
|
75
|
-
if (distance !== null && (best === undefined || distance < best.distance)) {
|
|
76
|
-
best = { choice, distance };
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return best?.choice;
|
|
80
|
-
}
|
|
81
|
-
function parseView(raw) {
|
|
82
|
-
if (!raw)
|
|
83
|
-
return "agenda";
|
|
84
|
-
const normalized = raw.trim().toLowerCase();
|
|
85
|
-
if (!CALENDAR_VIEW_VALUES.includes(normalized)) {
|
|
86
|
-
const suggestion = suggestClosestChoice(normalized, CALENDAR_VIEW_VALUES);
|
|
87
|
-
throw new PmCliError(`Calendar view must be one of ${CALENDAR_VIEW_VALUES.join("|")}${suggestion ? `. Did you mean "${suggestion}"?` : "."}`, EXIT_CODE.USAGE);
|
|
88
|
-
}
|
|
89
|
-
return normalized;
|
|
90
|
-
}
|
|
91
|
-
function parseOutputFormat(raw) {
|
|
92
|
-
if (!raw)
|
|
93
|
-
return undefined;
|
|
94
|
-
const normalized = raw.trim().toLowerCase();
|
|
95
|
-
if (!CALENDAR_OUTPUT_VALUES.includes(normalized)) {
|
|
96
|
-
const suggestion = suggestClosestChoice(normalized, CALENDAR_OUTPUT_VALUES);
|
|
97
|
-
throw new PmCliError(`Calendar format must be one of ${CALENDAR_OUTPUT_VALUES.join("|")}${suggestion ? `. Did you mean "${suggestion}"?` : "."}`, EXIT_CODE.USAGE);
|
|
98
|
-
}
|
|
99
|
-
return normalized;
|
|
100
|
-
}
|
|
101
|
-
/** Implements resolve calendar output format for the public runtime surface of this module. */
|
|
102
|
-
export function resolveCalendarOutputFormat(options, global) {
|
|
103
|
-
const commandFormat = parseOutputFormat(options.format);
|
|
104
|
-
if (global.json && commandFormat && commandFormat !== "json") {
|
|
105
|
-
throw new PmCliError("Cannot combine --json with --format markdown|toon", EXIT_CODE.USAGE);
|
|
106
|
-
}
|
|
107
|
-
if (global.json) {
|
|
108
|
-
return "json";
|
|
109
|
-
}
|
|
110
|
-
return commandFormat ?? "markdown";
|
|
111
|
-
}
|
|
112
|
-
function parseStatus(raw, statusRegistry) {
|
|
113
|
-
if (raw === undefined)
|
|
114
|
-
return undefined;
|
|
115
|
-
const normalized = normalizeStatusInput(raw, statusRegistry);
|
|
116
|
-
if (!normalized) {
|
|
117
|
-
const allowedStatuses = statusRegistry.definitions.map((definition) => definition.id);
|
|
118
|
-
throw new PmCliError(`Calendar status filter must be one of ${allowedStatuses.join("|")}`, EXIT_CODE.USAGE);
|
|
119
|
-
}
|
|
120
|
-
return normalized;
|
|
121
|
-
}
|
|
122
|
-
function parseAssigneeFilter(raw) {
|
|
123
|
-
if (raw === undefined) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
const normalized = raw.trim().toLowerCase();
|
|
127
|
-
if (!normalized) {
|
|
128
|
-
throw new PmCliError("Calendar assignee filter must be one of assigned|unassigned", EXIT_CODE.USAGE);
|
|
129
|
-
}
|
|
130
|
-
if (normalized !== "assigned" && normalized !== "unassigned") {
|
|
131
|
-
throw new PmCliError(`Invalid calendar assignee filter "${raw}". Allowed: assigned|unassigned`, EXIT_CODE.USAGE);
|
|
132
|
-
}
|
|
133
|
-
return normalized;
|
|
134
|
-
}
|
|
135
|
-
function toUtcDayKey(timestamp) {
|
|
136
|
-
return new Date(timestamp).toISOString().slice(0, 10);
|
|
137
|
-
}
|
|
138
|
-
/** Calendar day (YYYY-MM-DD) the instant falls on in the given IANA timezone. Events carry an optional `timezone`; bucketing and clock rendering use it so a 23:30Z instant tagged Asia/Tokyo correctly lands on the next local day rather than the UTC day. Falls back to the UTC day when no/invalid timezone is given, so existing UTC behavior is unchanged. Uses Intl (no timezone dependency). */
|
|
139
|
-
function toLocalDayKey(timestamp, timezone) {
|
|
140
|
-
if (!timezone || timezone === "UTC") {
|
|
141
|
-
return toUtcDayKey(timestamp);
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
145
|
-
timeZone: timezone,
|
|
146
|
-
year: "numeric",
|
|
147
|
-
month: "2-digit",
|
|
148
|
-
day: "2-digit",
|
|
149
|
-
}).formatToParts(new Date(timestamp));
|
|
150
|
-
const year = parts.find((part) => part.type === "year")?.value;
|
|
151
|
-
const month = parts.find((part) => part.type === "month")?.value;
|
|
152
|
-
const day = parts.find((part) => part.type === "day")?.value;
|
|
153
|
-
if (year && month && day) {
|
|
154
|
-
return `${year}-${month}-${day}`;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
// Invalid IANA zone — fall back to the UTC day key below.
|
|
159
|
-
}
|
|
160
|
-
return toUtcDayKey(timestamp);
|
|
161
|
-
}
|
|
162
|
-
function startOfUtcDay(timestamp) {
|
|
163
|
-
const date = new Date(timestamp);
|
|
164
|
-
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0, 0)).toISOString();
|
|
165
|
-
}
|
|
166
|
-
function addUtcDays(timestamp, days) {
|
|
167
|
-
const date = new Date(timestamp);
|
|
168
|
-
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000).toISOString();
|
|
169
|
-
}
|
|
170
|
-
function startOfUtcWeekMonday(timestamp) {
|
|
171
|
-
const base = new Date(startOfUtcDay(timestamp));
|
|
172
|
-
const day = base.getUTCDay();
|
|
173
|
-
const delta = day === 0 ? -6 : 1 - day;
|
|
174
|
-
return addUtcDays(base.toISOString(), delta);
|
|
175
|
-
}
|
|
176
|
-
function startOfUtcMonth(timestamp) {
|
|
177
|
-
const date = new Date(timestamp);
|
|
178
|
-
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), 1, 0, 0, 0, 0)).toISOString();
|
|
179
|
-
}
|
|
180
|
-
function startOfNextUtcMonth(timestamp) {
|
|
181
|
-
const date = new Date(timestamp);
|
|
182
|
-
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1, 0, 0, 0, 0)).toISOString();
|
|
183
|
-
}
|
|
184
|
-
function maxTimestamp(left, right) {
|
|
185
|
-
return compareTimestampStrings(left, right) >= 0 ? left : right;
|
|
186
|
-
}
|
|
187
|
-
function toSortedCountRecord(values) {
|
|
188
|
-
return Object.fromEntries([...values.entries()].sort(([left], [right]) => left.localeCompare(right)));
|
|
189
|
-
}
|
|
190
|
-
function incrementCount(values, key) {
|
|
191
|
-
values.set(key, (values.get(key) ?? 0) + 1);
|
|
192
|
-
}
|
|
193
|
-
function formatRecurrenceRuleForSummary(rule) {
|
|
194
|
-
if (!rule) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
const parts = [`freq=${rule.freq}`];
|
|
198
|
-
if (rule.interval !== undefined) {
|
|
199
|
-
parts.push(`interval=${rule.interval}`);
|
|
200
|
-
}
|
|
201
|
-
if (rule.count !== undefined) {
|
|
202
|
-
parts.push(`count=${rule.count}`);
|
|
203
|
-
}
|
|
204
|
-
if (rule.until) {
|
|
205
|
-
parts.push(`until=${rule.until}`);
|
|
206
|
-
}
|
|
207
|
-
if (rule.by_weekday && rule.by_weekday.length > 0) {
|
|
208
|
-
const weekdays = [...rule.by_weekday].sort((left, right) => weekdayOrderIndex(left) - weekdayOrderIndex(right));
|
|
209
|
-
parts.push(`by_weekday=${weekdays.join("|")}`);
|
|
210
|
-
}
|
|
211
|
-
if (rule.by_month_day && rule.by_month_day.length > 0) {
|
|
212
|
-
const monthDays = [...rule.by_month_day].sort((left, right) => left - right);
|
|
213
|
-
parts.push(`by_month_day=${monthDays.join("|")}`);
|
|
214
|
-
}
|
|
215
|
-
if (rule.exdates && rule.exdates.length > 0) {
|
|
216
|
-
const exdates = [...rule.exdates].sort((left, right) => left.localeCompare(right));
|
|
217
|
-
parts.push(`exdates=${exdates.join("|")}`);
|
|
218
|
-
}
|
|
219
|
-
return parts.join(",");
|
|
220
|
-
}
|
|
221
|
-
function buildUtcTimestamp(year, month, day, timeSource) {
|
|
222
|
-
const candidate = new Date(Date.UTC(year, month, day, timeSource.getUTCHours(), timeSource.getUTCMinutes(), timeSource.getUTCSeconds(), timeSource.getUTCMilliseconds()));
|
|
223
|
-
if (candidate.getUTCFullYear() !== year ||
|
|
224
|
-
candidate.getUTCMonth() !== month ||
|
|
225
|
-
candidate.getUTCDate() !== day) {
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
return candidate.toISOString();
|
|
229
|
-
}
|
|
230
|
-
function weekdayToken(timestamp) {
|
|
231
|
-
return UTC_DAY_TO_WEEKDAY[new Date(timestamp).getUTCDay()];
|
|
232
|
-
}
|
|
233
|
-
function normalizeInstantKey(timestamp) {
|
|
234
|
-
const parsed = Date.parse(timestamp);
|
|
235
|
-
return Number.isFinite(parsed) ? new Date(parsed).toISOString() : null;
|
|
236
|
-
}
|
|
237
|
-
function buildExcludedInstantSet(exdates) {
|
|
238
|
-
const excluded = new Set();
|
|
239
|
-
for (const exdate of exdates ?? []) {
|
|
240
|
-
const instantKey = normalizeInstantKey(exdate);
|
|
241
|
-
if (instantKey) {
|
|
242
|
-
excluded.add(instantKey);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return excluded;
|
|
246
|
-
}
|
|
247
|
-
function buildRecurringEventWindow(start, end, nowValue, lookbackDays, lookaheadDays) {
|
|
248
|
-
const windowStart = start ??
|
|
249
|
-
addUtcDays(nowValue, -(lookbackDays ?? DEFAULT_RECURRENCE_LOOKBACK_DAYS));
|
|
250
|
-
const windowEnd = end ??
|
|
251
|
-
addUtcDays(start ?? nowValue, lookaheadDays ?? DEFAULT_RECURRENCE_LOOKAHEAD_DAYS);
|
|
252
|
-
return {
|
|
253
|
-
start: windowStart,
|
|
254
|
-
end: compareTimestampStrings(windowEnd, windowStart) > 0
|
|
255
|
-
? windowEnd
|
|
256
|
-
: addUtcDays(windowStart, 1),
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
function buildRecurrenceExpansionContext(startAt, recurrence, window, occurrenceLimit) {
|
|
260
|
-
// Omitted filters default to the series start; explicit empty filters intentionally match no occurrences.
|
|
261
|
-
const recurrenceWeekdays = recurrence.by_weekday !== undefined
|
|
262
|
-
? [...recurrence.by_weekday]
|
|
263
|
-
: [weekdayToken(startAt)];
|
|
264
|
-
const recurrenceMonthDays = recurrence.by_month_day !== undefined
|
|
265
|
-
? [...recurrence.by_month_day]
|
|
266
|
-
: [new Date(startAt).getUTCDate()];
|
|
267
|
-
return {
|
|
268
|
-
startAt,
|
|
269
|
-
startDate: new Date(startAt),
|
|
270
|
-
window,
|
|
271
|
-
maxOccurrences: occurrenceLimit ?? MAX_RECURRENCE_OCCURRENCES,
|
|
272
|
-
interval: recurrence.interval ?? 1,
|
|
273
|
-
countLimit: recurrence.count ?? Number.POSITIVE_INFINITY,
|
|
274
|
-
until: recurrence.until,
|
|
275
|
-
excluded: buildExcludedInstantSet(recurrence.exdates),
|
|
276
|
-
weekdayFilter: recurrence.by_weekday !== undefined
|
|
277
|
-
? new Set(recurrence.by_weekday)
|
|
278
|
-
: undefined,
|
|
279
|
-
monthDayFilter: recurrence.by_month_day !== undefined
|
|
280
|
-
? new Set(recurrence.by_month_day)
|
|
281
|
-
: undefined,
|
|
282
|
-
sortedWeekdays: [...new Set(recurrenceWeekdays)].sort((left, right) => weekdayOrderIndex(left) - weekdayOrderIndex(right)),
|
|
283
|
-
sortedMonthDays: [...new Set(recurrenceMonthDays)].sort((left, right) => left - right),
|
|
284
|
-
occurrences: [],
|
|
285
|
-
produced: 0,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function consumeRecurrenceCandidate(context, candidateAt) {
|
|
289
|
-
if (compareTimestampStrings(candidateAt, context.startAt) < 0) {
|
|
290
|
-
return "continue";
|
|
291
|
-
}
|
|
292
|
-
if (context.until &&
|
|
293
|
-
compareTimestampStrings(candidateAt, context.until) > 0) {
|
|
294
|
-
return "stop";
|
|
295
|
-
}
|
|
296
|
-
if (compareTimestampStrings(candidateAt, context.window.end) >= 0) {
|
|
297
|
-
return "stop";
|
|
298
|
-
}
|
|
299
|
-
if (context.excluded.has(candidateAt)) {
|
|
300
|
-
return "continue";
|
|
301
|
-
}
|
|
302
|
-
context.produced += 1;
|
|
303
|
-
if (compareTimestampStrings(candidateAt, context.window.start) >= 0) {
|
|
304
|
-
context.occurrences.push(candidateAt);
|
|
305
|
-
}
|
|
306
|
-
return context.produced >= context.countLimit ||
|
|
307
|
-
context.occurrences.length >= context.maxOccurrences
|
|
308
|
-
? "stop"
|
|
309
|
-
: "continue";
|
|
310
|
-
}
|
|
311
|
-
function recurrenceDayMatchesFilters(context, candidateAt) {
|
|
312
|
-
const candidateWeekday = weekdayToken(candidateAt);
|
|
313
|
-
const candidateMonthDay = new Date(candidateAt).getUTCDate();
|
|
314
|
-
const weekdayMatches = !context.weekdayFilter || context.weekdayFilter.has(candidateWeekday);
|
|
315
|
-
const monthDayMatches = !context.monthDayFilter || context.monthDayFilter.has(candidateMonthDay);
|
|
316
|
-
return weekdayMatches && monthDayMatches;
|
|
317
|
-
}
|
|
318
|
-
function expandDailyOccurrences(context) {
|
|
319
|
-
let candidateAt = context.startAt;
|
|
320
|
-
for (let iteration = 0; iteration < context.maxOccurrences; iteration += 1) {
|
|
321
|
-
if (recurrenceDayMatchesFilters(context, candidateAt) &&
|
|
322
|
-
consumeRecurrenceCandidate(context, candidateAt) === "stop") {
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
candidateAt = addUtcDays(candidateAt, context.interval);
|
|
326
|
-
}
|
|
327
|
-
return context.occurrences;
|
|
328
|
-
}
|
|
329
|
-
function buildWeeklyCandidateAt(context, candidateWeekStart, weekday) {
|
|
330
|
-
const dayOffset = weekdayOrderIndex(weekday);
|
|
331
|
-
const candidateDay = addUtcDays(candidateWeekStart, dayOffset);
|
|
332
|
-
const dayDate = new Date(candidateDay);
|
|
333
|
-
return new Date(Date.UTC(dayDate.getUTCFullYear(), dayDate.getUTCMonth(), dayDate.getUTCDate(), context.startDate.getUTCHours(), context.startDate.getUTCMinutes(), context.startDate.getUTCSeconds(), context.startDate.getUTCMilliseconds())).toISOString();
|
|
334
|
-
}
|
|
335
|
-
function expandWeeklyOccurrences(context) {
|
|
336
|
-
const weekStart = startOfUtcWeekMonday(context.startAt);
|
|
337
|
-
for (let step = 0; step < context.maxOccurrences; step += 1) {
|
|
338
|
-
const candidateWeekStart = addUtcDays(weekStart, step * context.interval * 7);
|
|
339
|
-
for (const weekday of context.sortedWeekdays) {
|
|
340
|
-
const candidateAt = buildWeeklyCandidateAt(context, candidateWeekStart, weekday);
|
|
341
|
-
if (!recurrenceDayMatchesFilters(context, candidateAt)) {
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
if (consumeRecurrenceCandidate(context, candidateAt) === "stop") {
|
|
345
|
-
return context.occurrences;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return context.occurrences;
|
|
350
|
-
}
|
|
351
|
-
function expandMonthlyOccurrences(context) {
|
|
352
|
-
const startYear = context.startDate.getUTCFullYear();
|
|
353
|
-
const startMonth = context.startDate.getUTCMonth();
|
|
354
|
-
for (let step = 0; step < context.maxOccurrences; step += 1) {
|
|
355
|
-
const monthAnchor = new Date(Date.UTC(startYear, startMonth + step * context.interval, 1, 0, 0, 0, 0));
|
|
356
|
-
for (const monthDay of context.sortedMonthDays) {
|
|
357
|
-
const candidateAt = buildUtcTimestamp(monthAnchor.getUTCFullYear(), monthAnchor.getUTCMonth(), monthDay, context.startDate);
|
|
358
|
-
if (!candidateAt || !recurrenceDayMatchesFilters(context, candidateAt)) {
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
if (consumeRecurrenceCandidate(context, candidateAt) === "stop") {
|
|
362
|
-
return context.occurrences;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return context.occurrences;
|
|
367
|
-
}
|
|
368
|
-
function expandYearlyOccurrences(context) {
|
|
369
|
-
const year = context.startDate.getUTCFullYear();
|
|
370
|
-
const month = context.startDate.getUTCMonth();
|
|
371
|
-
for (let step = 0; step < context.maxOccurrences; step += 1) {
|
|
372
|
-
const candidateYear = year + step * context.interval;
|
|
373
|
-
for (const monthDay of context.sortedMonthDays) {
|
|
374
|
-
const candidateAt = buildUtcTimestamp(candidateYear, month, monthDay, context.startDate);
|
|
375
|
-
if (!candidateAt || !recurrenceDayMatchesFilters(context, candidateAt)) {
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
if (consumeRecurrenceCandidate(context, candidateAt) === "stop") {
|
|
379
|
-
return context.occurrences;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
return context.occurrences;
|
|
384
|
-
}
|
|
385
|
-
function expandRecurringOccurrences(startAt, recurrence, window, occurrenceLimit) {
|
|
386
|
-
const context = buildRecurrenceExpansionContext(startAt, recurrence, window, occurrenceLimit);
|
|
387
|
-
if (recurrence.freq === "daily") {
|
|
388
|
-
return expandDailyOccurrences(context);
|
|
389
|
-
}
|
|
390
|
-
if (recurrence.freq === "weekly") {
|
|
391
|
-
return expandWeeklyOccurrences(context);
|
|
392
|
-
}
|
|
393
|
-
if (recurrence.freq === "monthly") {
|
|
394
|
-
return expandMonthlyOccurrences(context);
|
|
395
|
-
}
|
|
396
|
-
return expandYearlyOccurrences(context);
|
|
397
|
-
}
|
|
398
|
-
function sortEvents(values) {
|
|
399
|
-
return [...values].sort((a, b) => {
|
|
400
|
-
const byAt = compareTimestampStrings(a.at, b.at);
|
|
401
|
-
if (byAt !== 0)
|
|
402
|
-
return byAt;
|
|
403
|
-
const byPriority = a.item_priority - b.item_priority;
|
|
404
|
-
if (byPriority !== 0)
|
|
405
|
-
return byPriority;
|
|
406
|
-
const byId = a.item_id.localeCompare(b.item_id);
|
|
407
|
-
if (byId !== 0)
|
|
408
|
-
return byId;
|
|
409
|
-
const byKind = a.kind.localeCompare(b.kind);
|
|
410
|
-
if (byKind !== 0)
|
|
411
|
-
return byKind;
|
|
412
|
-
const byEventTitle = String(a.event_title).localeCompare(String(b.event_title));
|
|
413
|
-
if (byEventTitle !== 0)
|
|
414
|
-
return byEventTitle;
|
|
415
|
-
return String(a.reminder_text).localeCompare(String(b.reminder_text));
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
function buildItemCalendarRowBase(item) {
|
|
419
|
-
return {
|
|
420
|
-
item_id: item.id,
|
|
421
|
-
item_title: item.title,
|
|
422
|
-
item_type: item.type,
|
|
423
|
-
item_status: item.status,
|
|
424
|
-
item_priority: item.priority,
|
|
425
|
-
item_assignee: item.assignee ?? null,
|
|
426
|
-
item_deadline: item.deadline ?? null,
|
|
427
|
-
item_tags: item.tags,
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
function buildDeadlineRow(item) {
|
|
431
|
-
if (!item.deadline) {
|
|
432
|
-
return null;
|
|
433
|
-
}
|
|
434
|
-
return {
|
|
435
|
-
at: item.deadline,
|
|
436
|
-
date: toUtcDayKey(item.deadline),
|
|
437
|
-
kind: "deadline",
|
|
438
|
-
reminder_text: null,
|
|
439
|
-
event_title: null,
|
|
440
|
-
event_end: null,
|
|
441
|
-
event_location: null,
|
|
442
|
-
event_all_day: null,
|
|
443
|
-
event_timezone: null,
|
|
444
|
-
event_recurring: null,
|
|
445
|
-
event_recurrence_rule: null,
|
|
446
|
-
...buildItemCalendarRowBase(item),
|
|
447
|
-
item_deadline: item.deadline,
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
function buildReminderRows(item) {
|
|
451
|
-
return (item.reminders ?? []).map((reminder) => ({
|
|
452
|
-
at: reminder.at,
|
|
453
|
-
date: toUtcDayKey(reminder.at),
|
|
454
|
-
kind: "reminder",
|
|
455
|
-
reminder_text: reminder.text,
|
|
456
|
-
event_title: null,
|
|
457
|
-
event_end: null,
|
|
458
|
-
event_location: null,
|
|
459
|
-
event_all_day: null,
|
|
460
|
-
event_timezone: null,
|
|
461
|
-
event_recurring: null,
|
|
462
|
-
event_recurrence_rule: null,
|
|
463
|
-
...buildItemCalendarRowBase(item),
|
|
464
|
-
}));
|
|
465
|
-
}
|
|
466
|
-
function recurringDurationMs(startAt, endAt) {
|
|
467
|
-
if (!endAt) {
|
|
468
|
-
return null;
|
|
469
|
-
}
|
|
470
|
-
const duration = Date.parse(endAt) - Date.parse(startAt);
|
|
471
|
-
return Number.isFinite(duration) && duration > 0 ? duration : null;
|
|
472
|
-
}
|
|
473
|
-
function eventOccurrenceEnd(occurrenceAt, event, durationMs) {
|
|
474
|
-
return event.recurrence && durationMs !== null
|
|
475
|
-
? new Date(new Date(occurrenceAt).getTime() + durationMs).toISOString()
|
|
476
|
-
: (event.end_at ?? null);
|
|
477
|
-
}
|
|
478
|
-
function buildScheduledEventRows(item, event, recurringWindow, occurrenceLimit) {
|
|
479
|
-
const recurrenceRuleSummary = formatRecurrenceRuleForSummary(event.recurrence);
|
|
480
|
-
const durationMs = recurringDurationMs(event.start_at, event.end_at);
|
|
481
|
-
const occurrences = event.recurrence
|
|
482
|
-
? expandRecurringOccurrences(event.start_at, event.recurrence, recurringWindow, occurrenceLimit)
|
|
483
|
-
: [event.start_at];
|
|
484
|
-
return occurrences.map((occurrenceAt) => ({
|
|
485
|
-
at: occurrenceAt,
|
|
486
|
-
// All-day events are timezone-agnostic calendar dates: bucket by the
|
|
487
|
-
// literal start date. Timed events bucket by their local day in the
|
|
488
|
-
// event's timezone (defaults to UTC when unset).
|
|
489
|
-
date: event.all_day === true
|
|
490
|
-
? occurrenceAt.slice(0, 10)
|
|
491
|
-
: toLocalDayKey(occurrenceAt, event.timezone),
|
|
492
|
-
kind: "event",
|
|
493
|
-
reminder_text: event.description ?? null,
|
|
494
|
-
event_title: event.title ?? item.title,
|
|
495
|
-
event_end: eventOccurrenceEnd(occurrenceAt, event, durationMs),
|
|
496
|
-
event_location: event.location ?? null,
|
|
497
|
-
event_all_day: event.all_day ?? null,
|
|
498
|
-
event_timezone: event.timezone ?? null,
|
|
499
|
-
event_recurring: event.recurrence ? true : false,
|
|
500
|
-
event_recurrence_rule: recurrenceRuleSummary,
|
|
501
|
-
...buildItemCalendarRowBase(item),
|
|
502
|
-
}));
|
|
503
|
-
}
|
|
504
|
-
function buildEventSeed(items, recurringWindow, includeSources, occurrenceLimit) {
|
|
505
|
-
const events = [];
|
|
506
|
-
for (const item of items) {
|
|
507
|
-
const deadlineRow = includeSources.has("deadlines")
|
|
508
|
-
? buildDeadlineRow(item)
|
|
509
|
-
: null;
|
|
510
|
-
if (deadlineRow) {
|
|
511
|
-
events.push(deadlineRow);
|
|
512
|
-
}
|
|
513
|
-
if (includeSources.has("reminders")) {
|
|
514
|
-
events.push(...buildReminderRows(item));
|
|
515
|
-
}
|
|
516
|
-
for (const event of includeSources.has("events")
|
|
517
|
-
? (item.events ?? [])
|
|
518
|
-
: []) {
|
|
519
|
-
events.push(...buildScheduledEventRows(item, event, recurringWindow, occurrenceLimit));
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return sortEvents(events);
|
|
523
|
-
}
|
|
524
|
-
function filterItems(items, options, typeRegistry, statusRegistry, runtimeFieldFilters) {
|
|
525
|
-
const typeFilter = parseType(options.type, typeRegistry);
|
|
526
|
-
const tagFilter = options.tag?.trim().toLowerCase();
|
|
527
|
-
const priorityFilter = parsePriority(options.priority);
|
|
528
|
-
const statusFilter = parseStatus(options.status, statusRegistry);
|
|
529
|
-
const assigneeFilter = options.assignee?.trim();
|
|
530
|
-
const assigneeModeFilter = parseAssigneeFilter(options.assigneeFilter);
|
|
531
|
-
const sprintFilter = options.sprint?.trim();
|
|
532
|
-
const releaseFilter = options.release?.trim();
|
|
533
|
-
if (assigneeFilter &&
|
|
534
|
-
(assigneeFilter.toLowerCase() === "none" ||
|
|
535
|
-
assigneeFilter.toLowerCase() === "null")) {
|
|
536
|
-
throw new PmCliError('--assignee no longer accepts "none" or "null". Use --assignee-filter unassigned.', EXIT_CODE.USAGE);
|
|
537
|
-
}
|
|
538
|
-
if (assigneeFilter !== undefined && assigneeModeFilter === "unassigned") {
|
|
539
|
-
throw new PmCliError("Cannot combine --assignee with --assignee-filter unassigned", EXIT_CODE.USAGE);
|
|
540
|
-
}
|
|
541
|
-
return items.filter((item) => itemMatchesCalendarFilters(item, {
|
|
542
|
-
typeFilter,
|
|
543
|
-
tagFilter,
|
|
544
|
-
priorityFilter,
|
|
545
|
-
statusFilter,
|
|
546
|
-
assigneeFilter,
|
|
547
|
-
assigneeModeFilter,
|
|
548
|
-
sprintFilter,
|
|
549
|
-
releaseFilter,
|
|
550
|
-
runtimeFieldFilters,
|
|
551
|
-
}));
|
|
552
|
-
}
|
|
553
|
-
function itemMatchesCalendarFilters(item, filters) {
|
|
554
|
-
return (itemMatchesCalendarIdentityFilters(item, filters) &&
|
|
555
|
-
itemMatchesCalendarOwnerFilters(item, filters) &&
|
|
556
|
-
matchesRuntimeFilters(item, filters.runtimeFieldFilters));
|
|
557
|
-
}
|
|
558
|
-
function itemMatchesCalendarIdentityFilters(item, filters) {
|
|
559
|
-
if (filters.typeFilter && item.type !== filters.typeFilter)
|
|
560
|
-
return false;
|
|
561
|
-
if (filters.tagFilter &&
|
|
562
|
-
!item.tags.some((tag) => tag.trim().toLowerCase() === filters.tagFilter))
|
|
563
|
-
return false;
|
|
564
|
-
if (filters.priorityFilter !== undefined &&
|
|
565
|
-
item.priority !== filters.priorityFilter)
|
|
566
|
-
return false;
|
|
567
|
-
if (filters.statusFilter && item.status !== filters.statusFilter)
|
|
568
|
-
return false;
|
|
569
|
-
return true;
|
|
570
|
-
}
|
|
571
|
-
function itemMatchesCalendarOwnerFilters(item, filters) {
|
|
572
|
-
if (filters.assigneeModeFilter === "assigned" && !item.assignee)
|
|
573
|
-
return false;
|
|
574
|
-
if (filters.assigneeModeFilter === "unassigned" && item.assignee)
|
|
575
|
-
return false;
|
|
576
|
-
if (filters.assigneeFilter !== undefined &&
|
|
577
|
-
item.assignee !== filters.assigneeFilter)
|
|
578
|
-
return false;
|
|
579
|
-
if (filters.sprintFilter !== undefined &&
|
|
580
|
-
item.sprint !== filters.sprintFilter)
|
|
581
|
-
return false;
|
|
582
|
-
if (filters.releaseFilter !== undefined &&
|
|
583
|
-
item.release !== filters.releaseFilter)
|
|
584
|
-
return false;
|
|
585
|
-
return true;
|
|
586
|
-
}
|
|
587
|
-
function includeEventInWindow(event, start, end) {
|
|
588
|
-
if (start && compareTimestampStrings(event.at, start) < 0) {
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
if (end && compareTimestampStrings(event.at, end) >= 0) {
|
|
592
|
-
return false;
|
|
593
|
-
}
|
|
594
|
-
return true;
|
|
595
|
-
}
|
|
596
|
-
function resolveCalendarBoundaryInput(raw, nowValue, fieldLabel) {
|
|
597
|
-
if (raw.trim().toLowerCase() === "today") {
|
|
598
|
-
return startOfUtcDay(nowValue);
|
|
599
|
-
}
|
|
600
|
-
return resolveIsoOrRelative(raw, new Date(nowValue), fieldLabel);
|
|
601
|
-
}
|
|
602
|
-
function buildRange(view, options, nowValue) {
|
|
603
|
-
const anchor = options.date
|
|
604
|
-
? resolveCalendarBoundaryInput(options.date, nowValue, "--date")
|
|
605
|
-
: nowValue;
|
|
606
|
-
const includePast = options.past === true;
|
|
607
|
-
const fullPeriodRequested = options.fullPeriod === true;
|
|
608
|
-
const from = options.from
|
|
609
|
-
? resolveCalendarBoundaryInput(options.from, nowValue, "--from")
|
|
610
|
-
: undefined;
|
|
611
|
-
const to = options.to
|
|
612
|
-
? resolveCalendarBoundaryInput(options.to, nowValue, "--to")
|
|
613
|
-
: undefined;
|
|
614
|
-
if (from && to && compareTimestampStrings(from, to) >= 0) {
|
|
615
|
-
throw new PmCliError("Calendar --from must be before --to", EXIT_CODE.USAGE);
|
|
616
|
-
}
|
|
617
|
-
if (view !== "agenda" &&
|
|
618
|
-
(options.from !== undefined || options.to !== undefined)) {
|
|
619
|
-
throw new PmCliError("--from and --to are only supported for --view agenda", EXIT_CODE.USAGE);
|
|
620
|
-
}
|
|
621
|
-
if (view === "agenda") {
|
|
622
|
-
return buildAgendaRange(anchor, options, nowValue, includePast, fullPeriodRequested, from, to);
|
|
623
|
-
}
|
|
624
|
-
if (view === "day") {
|
|
625
|
-
const dayStart = startOfUtcDay(anchor);
|
|
626
|
-
return buildFixedPeriodRange(anchor, nowValue, includePast, fullPeriodRequested, dayStart, addUtcDays(dayStart, 1));
|
|
627
|
-
}
|
|
628
|
-
if (view === "week") {
|
|
629
|
-
const weekStart = startOfUtcWeekMonday(anchor);
|
|
630
|
-
return buildFixedPeriodRange(anchor, nowValue, includePast, fullPeriodRequested, weekStart, addUtcDays(weekStart, 7));
|
|
631
|
-
}
|
|
632
|
-
const monthStart = startOfUtcMonth(anchor);
|
|
633
|
-
return buildFixedPeriodRange(anchor, nowValue, includePast, fullPeriodRequested, monthStart, startOfNextUtcMonth(anchor));
|
|
634
|
-
}
|
|
635
|
-
function buildAgendaRange(anchor, options, nowValue, includePast, fullPeriodRequested, from, to) {
|
|
636
|
-
if (fullPeriodRequested) {
|
|
637
|
-
throw new PmCliError("--full-period is only supported for --view day|week|month. For agenda windows, use --from and --to.", EXIT_CODE.USAGE);
|
|
638
|
-
}
|
|
639
|
-
return {
|
|
640
|
-
anchor,
|
|
641
|
-
start: from ?? (options.date ? anchor : includePast ? undefined : nowValue),
|
|
642
|
-
end: to,
|
|
643
|
-
fullPeriod: false,
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
function buildFixedPeriodRange(anchor, nowValue, includePast, fullPeriodRequested, periodStart, periodEnd) {
|
|
647
|
-
const fullPeriod = includePast || fullPeriodRequested;
|
|
648
|
-
return {
|
|
649
|
-
anchor,
|
|
650
|
-
start: fullPeriod ? periodStart : maxTimestamp(periodStart, nowValue),
|
|
651
|
-
end: periodEnd,
|
|
652
|
-
periodStart,
|
|
653
|
-
periodEnd,
|
|
654
|
-
fullPeriod,
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
function bucketEventsByDay(events) {
|
|
658
|
-
const dayMap = new Map();
|
|
659
|
-
for (const event of events) {
|
|
660
|
-
const list = dayMap.get(event.date) ?? [];
|
|
661
|
-
list.push(event);
|
|
662
|
-
dayMap.set(event.date, list);
|
|
663
|
-
}
|
|
664
|
-
return [...dayMap.entries()]
|
|
665
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
666
|
-
.map(([date, dayEvents]) => ({
|
|
667
|
-
date,
|
|
668
|
-
count: dayEvents.length,
|
|
669
|
-
events: sortEvents(dayEvents),
|
|
670
|
-
}));
|
|
671
|
-
}
|
|
672
|
-
function summarize(events) {
|
|
673
|
-
const itemIds = new Set();
|
|
674
|
-
const byType = new Map();
|
|
675
|
-
const byStatus = new Map();
|
|
676
|
-
let deadlines = 0;
|
|
677
|
-
let reminders = 0;
|
|
678
|
-
let scheduled = 0;
|
|
679
|
-
let recurringEvents = 0;
|
|
680
|
-
for (const event of events) {
|
|
681
|
-
itemIds.add(event.item_id);
|
|
682
|
-
incrementCount(byType, event.item_type);
|
|
683
|
-
incrementCount(byStatus, event.item_status);
|
|
684
|
-
if (event.kind === "deadline") {
|
|
685
|
-
deadlines += 1;
|
|
686
|
-
}
|
|
687
|
-
else if (event.kind === "reminder") {
|
|
688
|
-
reminders += 1;
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
scheduled += 1;
|
|
692
|
-
if (event.event_recurring === true) {
|
|
693
|
-
recurringEvents += 1;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return {
|
|
698
|
-
events: events.length,
|
|
699
|
-
items: itemIds.size,
|
|
700
|
-
deadlines,
|
|
701
|
-
reminders,
|
|
702
|
-
scheduled,
|
|
703
|
-
by_kind: {
|
|
704
|
-
deadline: deadlines,
|
|
705
|
-
reminder: reminders,
|
|
706
|
-
event: scheduled,
|
|
707
|
-
},
|
|
708
|
-
by_type: toSortedCountRecord(byType),
|
|
709
|
-
by_status: toSortedCountRecord(byStatus),
|
|
710
|
-
recurring_events: recurringEvents,
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
function formatWindow(range) {
|
|
714
|
-
const start = range.start ?? "unbounded";
|
|
715
|
-
const end = range.end ?? "unbounded";
|
|
716
|
-
return `${start} -> ${end}`;
|
|
717
|
-
}
|
|
718
|
-
function formatClock(timestamp, timezone) {
|
|
719
|
-
if (timezone && timezone !== "UTC") {
|
|
720
|
-
try {
|
|
721
|
-
const parts = new Intl.DateTimeFormat("en-GB", {
|
|
722
|
-
timeZone: timezone,
|
|
723
|
-
hour: "2-digit",
|
|
724
|
-
minute: "2-digit",
|
|
725
|
-
hourCycle: "h23",
|
|
726
|
-
}).formatToParts(new Date(timestamp));
|
|
727
|
-
const hour = parts.find((part) => part.type === "hour")?.value;
|
|
728
|
-
const minute = parts.find((part) => part.type === "minute")?.value;
|
|
729
|
-
if (hour && minute) {
|
|
730
|
-
// Local wall-clock time; the event line already prints `timezone=<zone>`.
|
|
731
|
-
return `${hour}:${minute}`;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
catch {
|
|
735
|
-
// Invalid IANA zone — fall back to the UTC clock below.
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return `${new Date(timestamp).toISOString().slice(11, 16)}Z`;
|
|
739
|
-
}
|
|
740
|
-
function formatSummaryCountRecord(values) {
|
|
741
|
-
const entries = Object.entries(values);
|
|
742
|
-
if (entries.length === 0) {
|
|
743
|
-
return "empty";
|
|
744
|
-
}
|
|
745
|
-
return entries.map(([key, value]) => `${key}=${value}`).join(", ");
|
|
746
|
-
}
|
|
747
|
-
function formatEventEnd(event) {
|
|
748
|
-
if (!event.event_end) {
|
|
749
|
-
return null;
|
|
750
|
-
}
|
|
751
|
-
if (event.event_all_day === true) {
|
|
752
|
-
return event.event_end.slice(0, 10);
|
|
753
|
-
}
|
|
754
|
-
if (event.date === toLocalDayKey(event.event_end, event.event_timezone)) {
|
|
755
|
-
return formatClock(event.event_end, event.event_timezone);
|
|
756
|
-
}
|
|
757
|
-
return event.event_end;
|
|
758
|
-
}
|
|
759
|
-
function formatEventLine(event) {
|
|
760
|
-
const core = `${formatClock(event.at, event.event_timezone)} [${event.kind}] ${event.item_id} type=${event.item_type} p${event.item_priority} ${event.item_status} ${event.item_title}`;
|
|
761
|
-
if (event.kind === "reminder") {
|
|
762
|
-
const reminderText = event.reminder_text ?? "";
|
|
763
|
-
return `${core} — ${reminderText} reminder=${JSON.stringify(reminderText)}`;
|
|
764
|
-
}
|
|
765
|
-
if (event.kind === "event") {
|
|
766
|
-
const details = [];
|
|
767
|
-
const title = event.event_title ?? event.item_title;
|
|
768
|
-
const titleDiffers = event.event_title !== null && event.event_title !== event.item_title;
|
|
769
|
-
if (titleDiffers) {
|
|
770
|
-
details.push(title);
|
|
771
|
-
details.push(`title=${JSON.stringify(title)}`);
|
|
772
|
-
}
|
|
773
|
-
if (event.event_recurring) {
|
|
774
|
-
details.push("(recurring)");
|
|
775
|
-
details.push("recurring=true");
|
|
776
|
-
}
|
|
777
|
-
const end = formatEventEnd(event);
|
|
778
|
-
if (end) {
|
|
779
|
-
details.push(`end=${end}`);
|
|
780
|
-
}
|
|
781
|
-
if (event.event_all_day !== null) {
|
|
782
|
-
details.push(`all_day=${event.event_all_day ? "true" : "false"}`);
|
|
783
|
-
}
|
|
784
|
-
if (event.event_timezone) {
|
|
785
|
-
details.push(`timezone=${event.event_timezone}`);
|
|
786
|
-
}
|
|
787
|
-
if (event.event_location) {
|
|
788
|
-
details.push(`@ ${event.event_location}`);
|
|
789
|
-
details.push(`location=${JSON.stringify(event.event_location)}`);
|
|
790
|
-
}
|
|
791
|
-
if (event.event_recurrence_rule) {
|
|
792
|
-
details.push(`recurrence=${event.event_recurrence_rule}`);
|
|
793
|
-
}
|
|
794
|
-
if (event.reminder_text) {
|
|
795
|
-
details.push(`description=${JSON.stringify(event.reminder_text)}`);
|
|
796
|
-
}
|
|
797
|
-
return `${core} — ${details.join(" ")}`;
|
|
798
|
-
}
|
|
799
|
-
return core;
|
|
800
|
-
}
|
|
801
|
-
/** Implements render calendar markdown for the public runtime surface of this module. */
|
|
802
|
-
export function renderCalendarMarkdown(result) {
|
|
803
|
-
const lines = [];
|
|
804
|
-
lines.push(`# pm calendar (${result.view})`);
|
|
805
|
-
lines.push("");
|
|
806
|
-
lines.push(`- now: ${result.now}`);
|
|
807
|
-
lines.push(`- window: ${formatWindow(result.range)}`);
|
|
808
|
-
if (result.range.period_start && result.range.period_end) {
|
|
809
|
-
lines.push(`- period: ${result.range.period_start} -> ${result.range.period_end}`);
|
|
810
|
-
lines.push(`- period-mode: ${result.range.full_period ? "full-period" : "active-window"}`);
|
|
811
|
-
}
|
|
812
|
-
lines.push(`- events: ${result.summary.events} (deadlines: ${result.summary.deadlines}, reminders: ${result.summary.reminders}, scheduled: ${result.summary.scheduled})`);
|
|
813
|
-
lines.push(`- items: ${result.summary.items}`);
|
|
814
|
-
lines.push(`- by-kind: ${formatSummaryCountRecord(result.summary.by_kind)}`);
|
|
815
|
-
lines.push(`- by-type: ${formatSummaryCountRecord(result.summary.by_type)}`);
|
|
816
|
-
lines.push(`- by-status: ${formatSummaryCountRecord(result.summary.by_status)}`);
|
|
817
|
-
lines.push(`- recurring-events: ${result.summary.recurring_events}`);
|
|
818
|
-
lines.push("");
|
|
819
|
-
if (result.events.length === 0) {
|
|
820
|
-
lines.push("No calendar events matched the selected filters.");
|
|
821
|
-
return lines.join("\n");
|
|
822
|
-
}
|
|
823
|
-
for (const day of result.days) {
|
|
824
|
-
lines.push(`## ${day.date} (${day.count})`);
|
|
825
|
-
for (const event of day.events) {
|
|
826
|
-
lines.push(`- ${formatEventLine(event)}`);
|
|
827
|
-
}
|
|
828
|
-
lines.push("");
|
|
829
|
-
}
|
|
830
|
-
if (result.warnings && result.warnings.length > 0) {
|
|
831
|
-
lines.push("### warnings");
|
|
832
|
-
for (const warning of result.warnings) {
|
|
833
|
-
lines.push(`- ${warning}`);
|
|
834
|
-
}
|
|
835
|
-
lines.push("");
|
|
836
|
-
}
|
|
837
|
-
return trimTrailingNewlines(lines.join("\n"));
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* Serializes a CalendarResult as TOON (the project's structured output format).
|
|
841
|
-
*
|
|
842
|
-
* The calendar result is JSON-serializable end-to-end (only strings, numbers,
|
|
843
|
-
* booleans, null, plain objects, and arrays), so the value is fed directly to
|
|
844
|
-
* `@toon-format/toon`'s encoder.
|
|
845
|
-
*/
|
|
846
|
-
export function renderCalendarToon(result) {
|
|
847
|
-
return encodeToon(result);
|
|
848
|
-
}
|
|
849
|
-
function trimTrailingNewlines(value) {
|
|
850
|
-
let end = value.length;
|
|
851
|
-
while (end > 0 && value[end - 1] === "\n") {
|
|
852
|
-
end -= 1;
|
|
853
|
-
}
|
|
854
|
-
return value.slice(0, end);
|
|
855
|
-
}
|
|
856
|
-
function resolveCalendarExecutionInputs(options) {
|
|
857
|
-
const nowValue = nowIso();
|
|
858
|
-
const view = parseView(options.view);
|
|
859
|
-
const rangeBounds = buildRange(view, options, nowValue);
|
|
860
|
-
const limit = parseIntegerLimit(options.limit);
|
|
861
|
-
const includeSources = parseIncludeSources(options.include);
|
|
862
|
-
const explicitLookahead = parseNonNegativeInteger(options.recurrenceLookaheadDays, "Calendar recurrence lookahead days");
|
|
863
|
-
const recurrenceLookbackDays = parseNonNegativeInteger(options.recurrenceLookbackDays, "Calendar recurrence lookback days");
|
|
864
|
-
const occurrenceLimit = parseNonNegativeInteger(options.occurrenceLimit, "Calendar occurrence limit");
|
|
865
|
-
if (occurrenceLimit !== undefined && occurrenceLimit < 1) {
|
|
866
|
-
throw new PmCliError("Calendar occurrence limit must be >= 1", EXIT_CODE.USAGE);
|
|
867
|
-
}
|
|
868
|
-
const eventsOnly = includeSources.has("events") &&
|
|
869
|
-
!includeSources.has("deadlines") &&
|
|
870
|
-
!includeSources.has("reminders");
|
|
871
|
-
const hasExplicitBounds = options.to !== undefined ||
|
|
872
|
-
explicitLookahead !== undefined ||
|
|
873
|
-
recurrenceLookbackDays !== undefined ||
|
|
874
|
-
occurrenceLimit !== undefined;
|
|
875
|
-
const eventsOnlyCapApplied = eventsOnly && !hasExplicitBounds;
|
|
876
|
-
return {
|
|
877
|
-
nowValue,
|
|
878
|
-
view,
|
|
879
|
-
rangeBounds,
|
|
880
|
-
limit,
|
|
881
|
-
includeSources,
|
|
882
|
-
occurrenceLimit,
|
|
883
|
-
recurrenceLookaheadDays: eventsOnlyCapApplied
|
|
884
|
-
? DEFAULT_EVENTS_ONLY_LOOKAHEAD_DAYS
|
|
885
|
-
: explicitLookahead,
|
|
886
|
-
recurrenceLookbackWindowDays: eventsOnlyCapApplied && recurrenceLookbackDays === undefined
|
|
887
|
-
? 0
|
|
888
|
-
: recurrenceLookbackDays,
|
|
889
|
-
eventsOnlyCapApplied,
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
function appendCalendarCapWarning(warnings, capApplied) {
|
|
893
|
-
if (!capApplied) {
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
warnings.push(`recurring_events_default_cap_applied:lookback=0d,lookahead=${DEFAULT_EVENTS_ONLY_LOOKAHEAD_DAYS}d -- use --recurrence-lookback-days/--recurrence-lookahead-days or --to for wider range`);
|
|
897
|
-
}
|
|
898
|
-
function buildCalendarFiltersResult(options, runtimeFieldFilters) {
|
|
899
|
-
return {
|
|
900
|
-
type: options.type ?? null,
|
|
901
|
-
tag: options.tag ?? null,
|
|
902
|
-
priority: options.priority ?? null,
|
|
903
|
-
status: options.status ?? null,
|
|
904
|
-
assignee: options.assignee ?? null,
|
|
905
|
-
assignee_filter: options.assigneeFilter ?? null,
|
|
906
|
-
sprint: options.sprint ?? null,
|
|
907
|
-
release: options.release ?? null,
|
|
908
|
-
runtime_filters: runtimeFieldFilters,
|
|
909
|
-
limit: options.limit ?? null,
|
|
910
|
-
include: options.include ?? null,
|
|
911
|
-
full_period: options.fullPeriod === true ? "true" : null,
|
|
912
|
-
recurrence_lookahead_days: options.recurrenceLookaheadDays ?? null,
|
|
913
|
-
recurrence_lookback_days: options.recurrenceLookbackDays ?? null,
|
|
914
|
-
occurrence_limit: options.occurrenceLimit ?? null,
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
function buildCalendarRangeResult(options, rangeBounds) {
|
|
918
|
-
return {
|
|
919
|
-
start: rangeBounds.start ?? null,
|
|
920
|
-
end: rangeBounds.end ?? null,
|
|
921
|
-
period_start: rangeBounds.periodStart ?? null,
|
|
922
|
-
period_end: rangeBounds.periodEnd ?? null,
|
|
923
|
-
full_period: rangeBounds.fullPeriod,
|
|
924
|
-
past: options.past === true,
|
|
925
|
-
from: options.from ?? null,
|
|
926
|
-
to: options.to ?? null,
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
/** Implements run calendar for the public runtime surface of this module. */
|
|
930
|
-
export async function runCalendar(options, global) {
|
|
931
|
-
const pmRoot = resolvePmRoot(process.cwd(), global.path);
|
|
932
|
-
await assertInitializedTracker(pmRoot);
|
|
933
|
-
const inputs = resolveCalendarExecutionInputs(options);
|
|
934
|
-
const settings = await readSettings(pmRoot);
|
|
935
|
-
const statusRegistry = resolveRuntimeStatusRegistry(settings.schema);
|
|
936
|
-
const runtimeFieldRegistry = resolveRuntimeFieldRegistry(settings.schema);
|
|
937
|
-
const runtimeFieldFilters = collectRuntimeFilterValues(options, runtimeFieldRegistry, "calendar");
|
|
938
|
-
const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());
|
|
939
|
-
const listWarnings = [];
|
|
940
|
-
appendCalendarCapWarning(listWarnings, inputs.eventsOnlyCapApplied);
|
|
941
|
-
const items = await listAllItemMetadataLight(pmRoot, settings.item_format, typeRegistry.type_to_folder, listWarnings, settings.schema);
|
|
942
|
-
const filteredItems = filterItems(items, options, typeRegistry, statusRegistry, runtimeFieldFilters);
|
|
943
|
-
const recurringWindow = buildRecurringEventWindow(inputs.rangeBounds.start, inputs.rangeBounds.end, inputs.nowValue, inputs.recurrenceLookbackWindowDays, inputs.recurrenceLookaheadDays);
|
|
944
|
-
const seededEvents = buildEventSeed(filteredItems, recurringWindow, inputs.includeSources, inputs.occurrenceLimit);
|
|
945
|
-
const rangedEvents = seededEvents.filter((event) => includeEventInWindow(event, inputs.rangeBounds.start, inputs.rangeBounds.end));
|
|
946
|
-
const limitedEvents = inputs.limit === undefined
|
|
947
|
-
? rangedEvents
|
|
948
|
-
: rangedEvents.slice(0, inputs.limit);
|
|
949
|
-
const days = bucketEventsByDay(limitedEvents);
|
|
950
|
-
const warnings = [...new Set(listWarnings)].sort((left, right) => left.localeCompare(right));
|
|
951
|
-
return {
|
|
952
|
-
view: inputs.view,
|
|
953
|
-
output_default: "markdown",
|
|
954
|
-
now: inputs.nowValue,
|
|
955
|
-
anchor: inputs.rangeBounds.anchor,
|
|
956
|
-
range: buildCalendarRangeResult(options, inputs.rangeBounds),
|
|
957
|
-
filters: buildCalendarFiltersResult(options, runtimeFieldFilters),
|
|
958
|
-
summary: summarize(limitedEvents),
|
|
959
|
-
events: limitedEvents,
|
|
960
|
-
days,
|
|
961
|
-
...(warnings.length > 0 ? { warnings } : {}),
|
|
962
|
-
};
|
|
963
|
-
}
|
|
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]="77dd912c-158f-5280-8112-dd971be4df3b")}catch(e2){}})();import{assertInitializedTracker}from"../environment/tracker-preflight.js";import{encode as encodeToon}from"@toon-format/toon";import{getActiveExtensionRegistrations,resolveItemTypeRegistry,normalizeStatusInput,collectRuntimeFilterValues,matchesRuntimeFilters,resolveRuntimeFieldRegistry,resolveRuntimeStatusRegistry,EXIT_CODE,PmCliError,levenshteinDistanceWithinLimit,compareTimestampStrings,nowIso,resolveIsoOrRelative,listAllItemMetadataLight,resolvePmRoot,readSettings}from"../runtime-primitives.js";import{parseIntegerLimit,parsePriority,parseType}from"./parsers.js";import{weekdayOrderIndex}from"../../types/index.js";const CALENDAR_VIEW_VALUES=["agenda","day","week","month"];const CALENDAR_OUTPUT_VALUES=["markdown","toon","json"];const UTC_DAY_TO_WEEKDAY=["sun","mon","tue","wed","thu","fri","sat"];const DEFAULT_RECURRENCE_LOOKAHEAD_DAYS=365;const DEFAULT_RECURRENCE_LOOKBACK_DAYS=365;const DEFAULT_EVENTS_ONLY_LOOKAHEAD_DAYS=28;const MAX_RECURRENCE_OCCURRENCES=1e3;function parseNonNegativeInteger(raw,label){if(raw===void 0)return void 0;const parsed=Number(raw);if(!Number.isInteger(parsed)||parsed<0){throw new PmCliError(`${label} must be a non-negative integer`,EXIT_CODE.USAGE)}return parsed}function parseIncludeSources(raw){if(!raw){return new Set(["deadlines","reminders","events"])}const normalized=raw.trim().toLowerCase();if(normalized==="all"){return new Set(["deadlines","reminders","events"])}const values=normalized.split(/[|,]/).map(value=>value.trim()).filter(value=>value.length>0);if(values.length===0){throw new PmCliError("Calendar include filter must not be empty",EXIT_CODE.USAGE)}const include=new Set;for(const value of values){if(value==="deadlines"||value==="deadline"){include.add("deadlines");continue}if(value==="reminders"||value==="reminder"){include.add("reminders");continue}if(value==="events"||value==="event"||value==="scheduled"){include.add("events");continue}throw new PmCliError("Calendar include filter must be deadlines|reminders|events|scheduled|all",EXIT_CODE.USAGE)}return include}function suggestClosestChoice(value,choices){let best;for(const choice of choices){const distance=levenshteinDistanceWithinLimit(value,choice,2);if(distance!==null&&(best===void 0||distance<best.distance)){best={choice,distance}}}return best?.choice}function parseView(raw){if(!raw)return"agenda";const normalized=raw.trim().toLowerCase();if(!CALENDAR_VIEW_VALUES.includes(normalized)){const suggestion=suggestClosestChoice(normalized,CALENDAR_VIEW_VALUES);throw new PmCliError(`Calendar view must be one of ${CALENDAR_VIEW_VALUES.join("|")}${suggestion?`. Did you mean "${suggestion}"?`:"."}`,EXIT_CODE.USAGE)}return normalized}function parseOutputFormat(raw){if(!raw)return void 0;const normalized=raw.trim().toLowerCase();if(!CALENDAR_OUTPUT_VALUES.includes(normalized)){const suggestion=suggestClosestChoice(normalized,CALENDAR_OUTPUT_VALUES);throw new PmCliError(`Calendar format must be one of ${CALENDAR_OUTPUT_VALUES.join("|")}${suggestion?`. Did you mean "${suggestion}"?`:"."}`,EXIT_CODE.USAGE)}return normalized}function resolveCalendarOutputFormat(options,global2){const commandFormat=parseOutputFormat(options.format);if(global2.json&&commandFormat&&commandFormat!=="json"){throw new PmCliError("Cannot combine --json with --format markdown|toon",EXIT_CODE.USAGE)}if(global2.json){return"json"}return commandFormat??"markdown"}function parseStatus(raw,statusRegistry){if(raw===void 0)return void 0;const normalized=normalizeStatusInput(raw,statusRegistry);if(!normalized){const allowedStatuses=statusRegistry.definitions.map(definition=>definition.id);throw new PmCliError(`Calendar status filter must be one of ${allowedStatuses.join("|")}`,EXIT_CODE.USAGE)}return normalized}function parseAssigneeFilter(raw){if(raw===void 0){return void 0}const normalized=raw.trim().toLowerCase();if(!normalized){throw new PmCliError("Calendar assignee filter must be one of assigned|unassigned",EXIT_CODE.USAGE)}if(normalized!=="assigned"&&normalized!=="unassigned"){throw new PmCliError(`Invalid calendar assignee filter "${raw}". Allowed: assigned|unassigned`,EXIT_CODE.USAGE)}return normalized}function toUtcDayKey(timestamp){return new Date(timestamp).toISOString().slice(0,10)}function toLocalDayKey(timestamp,timezone){if(!timezone||timezone==="UTC"){return toUtcDayKey(timestamp)}try{const parts=new Intl.DateTimeFormat("en-CA",{timeZone:timezone,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(timestamp));const year=parts.find(part=>part.type==="year")?.value;const month=parts.find(part=>part.type==="month")?.value;const day=parts.find(part=>part.type==="day")?.value;if(year&&month&&day){return`${year}-${month}-${day}`}}catch{}return toUtcDayKey(timestamp)}function startOfUtcDay(timestamp){const date=new Date(timestamp);return new Date(Date.UTC(date.getUTCFullYear(),date.getUTCMonth(),date.getUTCDate(),0,0,0,0)).toISOString()}function addUtcDays(timestamp,days){const date=new Date(timestamp);return new Date(date.getTime()+days*24*60*60*1e3).toISOString()}function startOfUtcWeekMonday(timestamp){const base=new Date(startOfUtcDay(timestamp));const day=base.getUTCDay();const delta=day===0?-6:1-day;return addUtcDays(base.toISOString(),delta)}function startOfUtcMonth(timestamp){const date=new Date(timestamp);return new Date(Date.UTC(date.getUTCFullYear(),date.getUTCMonth(),1,0,0,0,0)).toISOString()}function startOfNextUtcMonth(timestamp){const date=new Date(timestamp);return new Date(Date.UTC(date.getUTCFullYear(),date.getUTCMonth()+1,1,0,0,0,0)).toISOString()}function maxTimestamp(left,right){return compareTimestampStrings(left,right)>=0?left:right}function toSortedCountRecord(values){return Object.fromEntries([...values.entries()].sort(([left],[right])=>left.localeCompare(right)))}function incrementCount(values,key){values.set(key,(values.get(key)??0)+1)}function formatRecurrenceRuleForSummary(rule){if(!rule){return null}const parts=[`freq=${rule.freq}`];if(rule.interval!==void 0){parts.push(`interval=${rule.interval}`)}if(rule.count!==void 0){parts.push(`count=${rule.count}`)}if(rule.until){parts.push(`until=${rule.until}`)}if(rule.by_weekday&&rule.by_weekday.length>0){const weekdays=[...rule.by_weekday].sort((left,right)=>weekdayOrderIndex(left)-weekdayOrderIndex(right));parts.push(`by_weekday=${weekdays.join("|")}`)}if(rule.by_month_day&&rule.by_month_day.length>0){const monthDays=[...rule.by_month_day].sort((left,right)=>left-right);parts.push(`by_month_day=${monthDays.join("|")}`)}if(rule.exdates&&rule.exdates.length>0){const exdates=[...rule.exdates].sort((left,right)=>left.localeCompare(right));parts.push(`exdates=${exdates.join("|")}`)}return parts.join(",")}function buildUtcTimestamp(year,month,day,timeSource){const candidate=new Date(Date.UTC(year,month,day,timeSource.getUTCHours(),timeSource.getUTCMinutes(),timeSource.getUTCSeconds(),timeSource.getUTCMilliseconds()));if(candidate.getUTCFullYear()!==year||candidate.getUTCMonth()!==month||candidate.getUTCDate()!==day){return void 0}return candidate.toISOString()}function weekdayToken(timestamp){return UTC_DAY_TO_WEEKDAY[new Date(timestamp).getUTCDay()]}function normalizeInstantKey(timestamp){const parsed=Date.parse(timestamp);return Number.isFinite(parsed)?new Date(parsed).toISOString():null}function buildExcludedInstantSet(exdates){const excluded=new Set;for(const exdate of exdates??[]){const instantKey=normalizeInstantKey(exdate);if(instantKey){excluded.add(instantKey)}}return excluded}function buildRecurringEventWindow(start,end,nowValue,lookbackDays,lookaheadDays){const windowStart=start??addUtcDays(nowValue,-(lookbackDays??DEFAULT_RECURRENCE_LOOKBACK_DAYS));const windowEnd=end??addUtcDays(start??nowValue,lookaheadDays??DEFAULT_RECURRENCE_LOOKAHEAD_DAYS);return{start:windowStart,end:compareTimestampStrings(windowEnd,windowStart)>0?windowEnd:addUtcDays(windowStart,1)}}function buildRecurrenceExpansionContext(startAt,recurrence,window2,occurrenceLimit){const recurrenceWeekdays=recurrence.by_weekday!==void 0?[...recurrence.by_weekday]:[weekdayToken(startAt)];const recurrenceMonthDays=recurrence.by_month_day!==void 0?[...recurrence.by_month_day]:[new Date(startAt).getUTCDate()];return{startAt,startDate:new Date(startAt),window:window2,maxOccurrences:occurrenceLimit??MAX_RECURRENCE_OCCURRENCES,interval:recurrence.interval??1,countLimit:recurrence.count??Number.POSITIVE_INFINITY,until:recurrence.until,excluded:buildExcludedInstantSet(recurrence.exdates),weekdayFilter:recurrence.by_weekday!==void 0?new Set(recurrence.by_weekday):void 0,monthDayFilter:recurrence.by_month_day!==void 0?new Set(recurrence.by_month_day):void 0,sortedWeekdays:[...new Set(recurrenceWeekdays)].sort((left,right)=>weekdayOrderIndex(left)-weekdayOrderIndex(right)),sortedMonthDays:[...new Set(recurrenceMonthDays)].sort((left,right)=>left-right),occurrences:[],produced:0}}function consumeRecurrenceCandidate(context,candidateAt){if(compareTimestampStrings(candidateAt,context.startAt)<0){return"continue"}if(context.until&&compareTimestampStrings(candidateAt,context.until)>0){return"stop"}if(compareTimestampStrings(candidateAt,context.window.end)>=0){return"stop"}if(context.excluded.has(candidateAt)){return"continue"}context.produced+=1;if(compareTimestampStrings(candidateAt,context.window.start)>=0){context.occurrences.push(candidateAt)}return context.produced>=context.countLimit||context.occurrences.length>=context.maxOccurrences?"stop":"continue"}function recurrenceDayMatchesFilters(context,candidateAt){const candidateWeekday=weekdayToken(candidateAt);const candidateMonthDay=new Date(candidateAt).getUTCDate();const weekdayMatches=!context.weekdayFilter||context.weekdayFilter.has(candidateWeekday);const monthDayMatches=!context.monthDayFilter||context.monthDayFilter.has(candidateMonthDay);return weekdayMatches&&monthDayMatches}function expandDailyOccurrences(context){let candidateAt=context.startAt;for(let iteration=0;iteration<context.maxOccurrences;iteration+=1){if(recurrenceDayMatchesFilters(context,candidateAt)&&consumeRecurrenceCandidate(context,candidateAt)==="stop"){break}candidateAt=addUtcDays(candidateAt,context.interval)}return context.occurrences}function buildWeeklyCandidateAt(context,candidateWeekStart,weekday){const dayOffset=weekdayOrderIndex(weekday);const candidateDay=addUtcDays(candidateWeekStart,dayOffset);const dayDate=new Date(candidateDay);return new Date(Date.UTC(dayDate.getUTCFullYear(),dayDate.getUTCMonth(),dayDate.getUTCDate(),context.startDate.getUTCHours(),context.startDate.getUTCMinutes(),context.startDate.getUTCSeconds(),context.startDate.getUTCMilliseconds())).toISOString()}function expandWeeklyOccurrences(context){const weekStart=startOfUtcWeekMonday(context.startAt);for(let step=0;step<context.maxOccurrences;step+=1){const candidateWeekStart=addUtcDays(weekStart,step*context.interval*7);for(const weekday of context.sortedWeekdays){const candidateAt=buildWeeklyCandidateAt(context,candidateWeekStart,weekday);if(!recurrenceDayMatchesFilters(context,candidateAt)){continue}if(consumeRecurrenceCandidate(context,candidateAt)==="stop"){return context.occurrences}}}return context.occurrences}function expandMonthlyOccurrences(context){const startYear=context.startDate.getUTCFullYear();const startMonth=context.startDate.getUTCMonth();for(let step=0;step<context.maxOccurrences;step+=1){const monthAnchor=new Date(Date.UTC(startYear,startMonth+step*context.interval,1,0,0,0,0));for(const monthDay of context.sortedMonthDays){const candidateAt=buildUtcTimestamp(monthAnchor.getUTCFullYear(),monthAnchor.getUTCMonth(),monthDay,context.startDate);if(!candidateAt||!recurrenceDayMatchesFilters(context,candidateAt)){continue}if(consumeRecurrenceCandidate(context,candidateAt)==="stop"){return context.occurrences}}}return context.occurrences}function expandYearlyOccurrences(context){const year=context.startDate.getUTCFullYear();const month=context.startDate.getUTCMonth();for(let step=0;step<context.maxOccurrences;step+=1){const candidateYear=year+step*context.interval;for(const monthDay of context.sortedMonthDays){const candidateAt=buildUtcTimestamp(candidateYear,month,monthDay,context.startDate);if(!candidateAt||!recurrenceDayMatchesFilters(context,candidateAt)){continue}if(consumeRecurrenceCandidate(context,candidateAt)==="stop"){return context.occurrences}}}return context.occurrences}function expandRecurringOccurrences(startAt,recurrence,window2,occurrenceLimit){const context=buildRecurrenceExpansionContext(startAt,recurrence,window2,occurrenceLimit);if(recurrence.freq==="daily"){return expandDailyOccurrences(context)}if(recurrence.freq==="weekly"){return expandWeeklyOccurrences(context)}if(recurrence.freq==="monthly"){return expandMonthlyOccurrences(context)}return expandYearlyOccurrences(context)}function sortEvents(values){return[...values].sort((a,b)=>{const byAt=compareTimestampStrings(a.at,b.at);if(byAt!==0)return byAt;const byPriority=a.item_priority-b.item_priority;if(byPriority!==0)return byPriority;const byId=a.item_id.localeCompare(b.item_id);if(byId!==0)return byId;const byKind=a.kind.localeCompare(b.kind);if(byKind!==0)return byKind;const byEventTitle=String(a.event_title).localeCompare(String(b.event_title));if(byEventTitle!==0)return byEventTitle;return String(a.reminder_text).localeCompare(String(b.reminder_text))})}function buildItemCalendarRowBase(item){return{item_id:item.id,item_title:item.title,item_type:item.type,item_status:item.status,item_priority:item.priority,item_assignee:item.assignee??null,item_deadline:item.deadline??null,item_tags:item.tags}}function buildDeadlineRow(item){if(!item.deadline){return null}return{at:item.deadline,date:toUtcDayKey(item.deadline),kind:"deadline",reminder_text:null,event_title:null,event_end:null,event_location:null,event_all_day:null,event_timezone:null,event_recurring:null,event_recurrence_rule:null,...buildItemCalendarRowBase(item),item_deadline:item.deadline}}function buildReminderRows(item){return(item.reminders??[]).map(reminder=>({at:reminder.at,date:toUtcDayKey(reminder.at),kind:"reminder",reminder_text:reminder.text,event_title:null,event_end:null,event_location:null,event_all_day:null,event_timezone:null,event_recurring:null,event_recurrence_rule:null,...buildItemCalendarRowBase(item)}))}function recurringDurationMs(startAt,endAt){if(!endAt){return null}const duration=Date.parse(endAt)-Date.parse(startAt);return Number.isFinite(duration)&&duration>0?duration:null}function eventOccurrenceEnd(occurrenceAt,event,durationMs){return event.recurrence&&durationMs!==null?new Date(new Date(occurrenceAt).getTime()+durationMs).toISOString():event.end_at??null}function buildScheduledEventRows(item,event,recurringWindow,occurrenceLimit){const recurrenceRuleSummary=formatRecurrenceRuleForSummary(event.recurrence);const durationMs=recurringDurationMs(event.start_at,event.end_at);const occurrences=event.recurrence?expandRecurringOccurrences(event.start_at,event.recurrence,recurringWindow,occurrenceLimit):[event.start_at];return occurrences.map(occurrenceAt=>({at:occurrenceAt,date:event.all_day===true?occurrenceAt.slice(0,10):toLocalDayKey(occurrenceAt,event.timezone),kind:"event",reminder_text:event.description??null,event_title:event.title??item.title,event_end:eventOccurrenceEnd(occurrenceAt,event,durationMs),event_location:event.location??null,event_all_day:event.all_day??null,event_timezone:event.timezone??null,event_recurring:event.recurrence?true:false,event_recurrence_rule:recurrenceRuleSummary,...buildItemCalendarRowBase(item)}))}function buildEventSeed(items,recurringWindow,includeSources,occurrenceLimit){const events=[];for(const item of items){const deadlineRow=includeSources.has("deadlines")?buildDeadlineRow(item):null;if(deadlineRow){events.push(deadlineRow)}if(includeSources.has("reminders")){events.push(...buildReminderRows(item))}for(const event of includeSources.has("events")?item.events??[]:[]){events.push(...buildScheduledEventRows(item,event,recurringWindow,occurrenceLimit))}}return sortEvents(events)}function filterItems(items,options,typeRegistry,statusRegistry,runtimeFieldFilters){const typeFilter=parseType(options.type,typeRegistry);const tagFilter=options.tag?.trim().toLowerCase();const priorityFilter=parsePriority(options.priority);const statusFilter=parseStatus(options.status,statusRegistry);const assigneeFilter=options.assignee?.trim();const assigneeModeFilter=parseAssigneeFilter(options.assigneeFilter);const sprintFilter=options.sprint?.trim();const releaseFilter=options.release?.trim();if(assigneeFilter&&(assigneeFilter.toLowerCase()==="none"||assigneeFilter.toLowerCase()==="null")){throw new PmCliError('--assignee no longer accepts "none" or "null". Use --assignee-filter unassigned.',EXIT_CODE.USAGE)}if(assigneeFilter!==void 0&&assigneeModeFilter==="unassigned"){throw new PmCliError("Cannot combine --assignee with --assignee-filter unassigned",EXIT_CODE.USAGE)}return items.filter(item=>itemMatchesCalendarFilters(item,{typeFilter,tagFilter,priorityFilter,statusFilter,assigneeFilter,assigneeModeFilter,sprintFilter,releaseFilter,runtimeFieldFilters}))}function itemMatchesCalendarFilters(item,filters){return itemMatchesCalendarIdentityFilters(item,filters)&&itemMatchesCalendarOwnerFilters(item,filters)&&matchesRuntimeFilters(item,filters.runtimeFieldFilters)}function itemMatchesCalendarIdentityFilters(item,filters){if(filters.typeFilter&&item.type!==filters.typeFilter)return false;if(filters.tagFilter&&!item.tags.some(tag=>tag.trim().toLowerCase()===filters.tagFilter))return false;if(filters.priorityFilter!==void 0&&item.priority!==filters.priorityFilter)return false;if(filters.statusFilter&&item.status!==filters.statusFilter)return false;return true}function itemMatchesCalendarOwnerFilters(item,filters){if(filters.assigneeModeFilter==="assigned"&&!item.assignee)return false;if(filters.assigneeModeFilter==="unassigned"&&item.assignee)return false;if(filters.assigneeFilter!==void 0&&item.assignee!==filters.assigneeFilter)return false;if(filters.sprintFilter!==void 0&&item.sprint!==filters.sprintFilter)return false;if(filters.releaseFilter!==void 0&&item.release!==filters.releaseFilter)return false;return true}function includeEventInWindow(event,start,end){if(start&&compareTimestampStrings(event.at,start)<0){return false}if(end&&compareTimestampStrings(event.at,end)>=0){return false}return true}function resolveCalendarBoundaryInput(raw,nowValue,fieldLabel){if(raw.trim().toLowerCase()==="today"){return startOfUtcDay(nowValue)}return resolveIsoOrRelative(raw,new Date(nowValue),fieldLabel)}function buildRange(view,options,nowValue){const anchor=options.date?resolveCalendarBoundaryInput(options.date,nowValue,"--date"):nowValue;const includePast=options.past===true;const fullPeriodRequested=options.fullPeriod===true;const from=options.from?resolveCalendarBoundaryInput(options.from,nowValue,"--from"):void 0;const to=options.to?resolveCalendarBoundaryInput(options.to,nowValue,"--to"):void 0;if(from&&to&&compareTimestampStrings(from,to)>=0){throw new PmCliError("Calendar --from must be before --to",EXIT_CODE.USAGE)}if(view!=="agenda"&&(options.from!==void 0||options.to!==void 0)){throw new PmCliError("--from and --to are only supported for --view agenda",EXIT_CODE.USAGE)}if(view==="agenda"){return buildAgendaRange(anchor,options,nowValue,includePast,fullPeriodRequested,from,to)}if(view==="day"){const dayStart=startOfUtcDay(anchor);return buildFixedPeriodRange(anchor,nowValue,includePast,fullPeriodRequested,dayStart,addUtcDays(dayStart,1))}if(view==="week"){const weekStart=startOfUtcWeekMonday(anchor);return buildFixedPeriodRange(anchor,nowValue,includePast,fullPeriodRequested,weekStart,addUtcDays(weekStart,7))}const monthStart=startOfUtcMonth(anchor);return buildFixedPeriodRange(anchor,nowValue,includePast,fullPeriodRequested,monthStart,startOfNextUtcMonth(anchor))}function buildAgendaRange(anchor,options,nowValue,includePast,fullPeriodRequested,from,to){if(fullPeriodRequested){throw new PmCliError("--full-period is only supported for --view day|week|month. For agenda windows, use --from and --to.",EXIT_CODE.USAGE)}return{anchor,start:from??(options.date?anchor:includePast?void 0:nowValue),end:to,fullPeriod:false}}function buildFixedPeriodRange(anchor,nowValue,includePast,fullPeriodRequested,periodStart,periodEnd){const fullPeriod=includePast||fullPeriodRequested;return{anchor,start:fullPeriod?periodStart:maxTimestamp(periodStart,nowValue),end:periodEnd,periodStart,periodEnd,fullPeriod}}function bucketEventsByDay(events){const dayMap=new Map;for(const event of events){const list=dayMap.get(event.date)??[];list.push(event);dayMap.set(event.date,list)}return[...dayMap.entries()].sort(([left],[right])=>left.localeCompare(right)).map(([date,dayEvents])=>({date,count:dayEvents.length,events:sortEvents(dayEvents)}))}function summarize(events){const itemIds=new Set;const byType=new Map;const byStatus=new Map;let deadlines=0;let reminders=0;let scheduled=0;let recurringEvents=0;for(const event of events){itemIds.add(event.item_id);incrementCount(byType,event.item_type);incrementCount(byStatus,event.item_status);if(event.kind==="deadline"){deadlines+=1}else if(event.kind==="reminder"){reminders+=1}else{scheduled+=1;if(event.event_recurring===true){recurringEvents+=1}}}return{events:events.length,items:itemIds.size,deadlines,reminders,scheduled,by_kind:{deadline:deadlines,reminder:reminders,event:scheduled},by_type:toSortedCountRecord(byType),by_status:toSortedCountRecord(byStatus),recurring_events:recurringEvents}}function formatWindow(range){const start=range.start??"unbounded";const end=range.end??"unbounded";return`${start} -> ${end}`}function formatClock(timestamp,timezone){if(timezone&&timezone!=="UTC"){try{const parts=new Intl.DateTimeFormat("en-GB",{timeZone:timezone,hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(timestamp));const hour=parts.find(part=>part.type==="hour")?.value;const minute=parts.find(part=>part.type==="minute")?.value;if(hour&&minute){return`${hour}:${minute}`}}catch{}}return`${new Date(timestamp).toISOString().slice(11,16)}Z`}function formatSummaryCountRecord(values){const entries=Object.entries(values);if(entries.length===0){return"empty"}return entries.map(([key,value])=>`${key}=${value}`).join(", ")}function formatEventEnd(event){if(!event.event_end){return null}if(event.event_all_day===true){return event.event_end.slice(0,10)}if(event.date===toLocalDayKey(event.event_end,event.event_timezone)){return formatClock(event.event_end,event.event_timezone)}return event.event_end}function formatEventLine(event){const core=`${formatClock(event.at,event.event_timezone)} [${event.kind}] ${event.item_id} type=${event.item_type} p${event.item_priority} ${event.item_status} ${event.item_title}`;if(event.kind==="reminder"){const reminderText=event.reminder_text??"";return`${core} \u2014 ${reminderText} reminder=${JSON.stringify(reminderText)}`}if(event.kind==="event"){const details=[];const title=event.event_title??event.item_title;const titleDiffers=event.event_title!==null&&event.event_title!==event.item_title;if(titleDiffers){details.push(title);details.push(`title=${JSON.stringify(title)}`)}if(event.event_recurring){details.push("(recurring)");details.push("recurring=true")}const end=formatEventEnd(event);if(end){details.push(`end=${end}`)}if(event.event_all_day!==null){details.push(`all_day=${event.event_all_day?"true":"false"}`)}if(event.event_timezone){details.push(`timezone=${event.event_timezone}`)}if(event.event_location){details.push(`@ ${event.event_location}`);details.push(`location=${JSON.stringify(event.event_location)}`)}if(event.event_recurrence_rule){details.push(`recurrence=${event.event_recurrence_rule}`)}if(event.reminder_text){details.push(`description=${JSON.stringify(event.reminder_text)}`)}return`${core} \u2014 ${details.join(" ")}`}return core}function renderCalendarMarkdown(result){const lines=[];lines.push(`# pm calendar (${result.view})`);lines.push("");lines.push(`- now: ${result.now}`);lines.push(`- window: ${formatWindow(result.range)}`);if(result.range.period_start&&result.range.period_end){lines.push(`- period: ${result.range.period_start} -> ${result.range.period_end}`);lines.push(`- period-mode: ${result.range.full_period?"full-period":"active-window"}`)}lines.push(`- events: ${result.summary.events} (deadlines: ${result.summary.deadlines}, reminders: ${result.summary.reminders}, scheduled: ${result.summary.scheduled})`);lines.push(`- items: ${result.summary.items}`);lines.push(`- by-kind: ${formatSummaryCountRecord(result.summary.by_kind)}`);lines.push(`- by-type: ${formatSummaryCountRecord(result.summary.by_type)}`);lines.push(`- by-status: ${formatSummaryCountRecord(result.summary.by_status)}`);lines.push(`- recurring-events: ${result.summary.recurring_events}`);lines.push("");if(result.events.length===0){lines.push("No calendar events matched the selected filters.");return lines.join("\n")}for(const day of result.days){lines.push(`## ${day.date} (${day.count})`);for(const event of day.events){lines.push(`- ${formatEventLine(event)}`)}lines.push("")}if(result.warnings&&result.warnings.length>0){lines.push("### warnings");for(const warning of result.warnings){lines.push(`- ${warning}`)}lines.push("")}return trimTrailingNewlines(lines.join("\n"))}function renderCalendarToon(result){return encodeToon(result)}function trimTrailingNewlines(value){let end=value.length;while(end>0&&value[end-1]==="\n"){end-=1}return value.slice(0,end)}function resolveCalendarExecutionInputs(options){const nowValue=nowIso();const view=parseView(options.view);const rangeBounds=buildRange(view,options,nowValue);const limit=parseIntegerLimit(options.limit);const includeSources=parseIncludeSources(options.include);const explicitLookahead=parseNonNegativeInteger(options.recurrenceLookaheadDays,"Calendar recurrence lookahead days");const recurrenceLookbackDays=parseNonNegativeInteger(options.recurrenceLookbackDays,"Calendar recurrence lookback days");const occurrenceLimit=parseNonNegativeInteger(options.occurrenceLimit,"Calendar occurrence limit");if(occurrenceLimit!==void 0&&occurrenceLimit<1){throw new PmCliError("Calendar occurrence limit must be >= 1",EXIT_CODE.USAGE)}const eventsOnly=includeSources.has("events")&&!includeSources.has("deadlines")&&!includeSources.has("reminders");const hasExplicitBounds=options.to!==void 0||explicitLookahead!==void 0||recurrenceLookbackDays!==void 0||occurrenceLimit!==void 0;const eventsOnlyCapApplied=eventsOnly&&!hasExplicitBounds;return{nowValue,view,rangeBounds,limit,includeSources,occurrenceLimit,recurrenceLookaheadDays:eventsOnlyCapApplied?DEFAULT_EVENTS_ONLY_LOOKAHEAD_DAYS:explicitLookahead,recurrenceLookbackWindowDays:eventsOnlyCapApplied&&recurrenceLookbackDays===void 0?0:recurrenceLookbackDays,eventsOnlyCapApplied}}function appendCalendarCapWarning(warnings,capApplied){if(!capApplied){return}warnings.push(`recurring_events_default_cap_applied:lookback=0d,lookahead=${DEFAULT_EVENTS_ONLY_LOOKAHEAD_DAYS}d -- use --recurrence-lookback-days/--recurrence-lookahead-days or --to for wider range`)}function buildCalendarFiltersResult(options,runtimeFieldFilters){return{type:options.type??null,tag:options.tag??null,priority:options.priority??null,status:options.status??null,assignee:options.assignee??null,assignee_filter:options.assigneeFilter??null,sprint:options.sprint??null,release:options.release??null,runtime_filters:runtimeFieldFilters,limit:options.limit??null,include:options.include??null,full_period:options.fullPeriod===true?"true":null,recurrence_lookahead_days:options.recurrenceLookaheadDays??null,recurrence_lookback_days:options.recurrenceLookbackDays??null,occurrence_limit:options.occurrenceLimit??null}}function buildCalendarRangeResult(options,rangeBounds){return{start:rangeBounds.start??null,end:rangeBounds.end??null,period_start:rangeBounds.periodStart??null,period_end:rangeBounds.periodEnd??null,full_period:rangeBounds.fullPeriod,past:options.past===true,from:options.from??null,to:options.to??null}}async function runCalendar(options,global2){const pmRoot=resolvePmRoot(process.cwd(),global2.path);await assertInitializedTracker(pmRoot);const inputs=resolveCalendarExecutionInputs(options);const settings=await readSettings(pmRoot);const statusRegistry=resolveRuntimeStatusRegistry(settings.schema);const runtimeFieldRegistry=resolveRuntimeFieldRegistry(settings.schema);const runtimeFieldFilters=collectRuntimeFilterValues(options,runtimeFieldRegistry,"calendar");const typeRegistry=resolveItemTypeRegistry(settings,getActiveExtensionRegistrations());const listWarnings=[];appendCalendarCapWarning(listWarnings,inputs.eventsOnlyCapApplied);const items=await listAllItemMetadataLight(pmRoot,settings.item_format,typeRegistry.type_to_folder,listWarnings,settings.schema);const filteredItems=filterItems(items,options,typeRegistry,statusRegistry,runtimeFieldFilters);const recurringWindow=buildRecurringEventWindow(inputs.rangeBounds.start,inputs.rangeBounds.end,inputs.nowValue,inputs.recurrenceLookbackWindowDays,inputs.recurrenceLookaheadDays);const seededEvents=buildEventSeed(filteredItems,recurringWindow,inputs.includeSources,inputs.occurrenceLimit);const rangedEvents=seededEvents.filter(event=>includeEventInWindow(event,inputs.rangeBounds.start,inputs.rangeBounds.end));const limitedEvents=inputs.limit===void 0?rangedEvents:rangedEvents.slice(0,inputs.limit);const days=bucketEventsByDay(limitedEvents);const warnings=[...new Set(listWarnings)].sort((left,right)=>left.localeCompare(right));return{view:inputs.view,output_default:"markdown",now:inputs.nowValue,anchor:inputs.rangeBounds.anchor,range:buildCalendarRangeResult(options,inputs.rangeBounds),filters:buildCalendarFiltersResult(options,runtimeFieldFilters),summary:summarize(limitedEvents),events:limitedEvents,days,...warnings.length>0?{warnings}:{}}}export{renderCalendarMarkdown,renderCalendarToon,resolveCalendarOutputFormat,runCalendar};
|
|
964
2
|
//# sourceMappingURL=calendar.js.map
|
|
965
|
-
//# debugId=47de55f1-589f-5743-bcb8-3b7a6302dfbb
|