@unbrained/pm-cli 2026.5.18 → 2026.5.27
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/CHANGELOG.md +953 -472
- package/README.md +4 -11
- package/dist/cli/bootstrap-args.d.ts +18 -1
- package/dist/cli/bootstrap-args.js +143 -3
- package/dist/cli/bootstrap-args.js.map +1 -1
- package/dist/cli/commander-usage.js +147 -10
- package/dist/cli/commander-usage.js.map +1 -1
- package/dist/cli/commands/annotation-command.d.ts +49 -0
- package/dist/cli/commands/annotation-command.js +135 -0
- package/dist/cli/commands/annotation-command.js.map +1 -0
- package/dist/cli/commands/append.js +5 -8
- package/dist/cli/commands/append.js.map +1 -1
- package/dist/cli/commands/calendar.js +3 -6
- package/dist/cli/commands/calendar.js.map +1 -1
- package/dist/cli/commands/claim.js +15 -24
- package/dist/cli/commands/claim.js.map +1 -1
- package/dist/cli/commands/close.js +63 -10
- package/dist/cli/commands/close.js.map +1 -1
- package/dist/cli/commands/comments.d.ts +5 -0
- package/dist/cli/commands/comments.js +27 -117
- package/dist/cli/commands/comments.js.map +1 -1
- package/dist/cli/commands/completion.d.ts +2 -2
- package/dist/cli/commands/completion.js +203 -63
- package/dist/cli/commands/completion.js.map +1 -1
- package/dist/cli/commands/config.d.ts +1 -1
- package/dist/cli/commands/config.js +82 -4
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/context.js +4 -10
- package/dist/cli/commands/context.js.map +1 -1
- package/dist/cli/commands/contracts.js +168 -36
- package/dist/cli/commands/contracts.js.map +1 -1
- package/dist/cli/commands/create.js +53 -313
- package/dist/cli/commands/create.js.map +1 -1
- package/dist/cli/commands/dedupe-audit.js +7 -4
- package/dist/cli/commands/dedupe-audit.js.map +1 -1
- package/dist/cli/commands/delete.d.ts +3 -0
- package/dist/cli/commands/delete.js +11 -9
- package/dist/cli/commands/delete.js.map +1 -1
- package/dist/cli/commands/docs.d.ts +2 -12
- package/dist/cli/commands/docs.js +8 -316
- package/dist/cli/commands/docs.js.map +1 -1
- package/dist/cli/commands/event-validation-messages.d.ts +3 -0
- package/dist/cli/commands/event-validation-messages.js +44 -0
- package/dist/cli/commands/event-validation-messages.js.map +1 -0
- package/dist/cli/commands/extension/bundled-catalog.d.ts +14 -0
- package/dist/cli/commands/extension/bundled-catalog.js +268 -0
- package/dist/cli/commands/extension/bundled-catalog.js.map +1 -0
- package/dist/cli/commands/extension/doctor.d.ts +31 -0
- package/dist/cli/commands/extension/doctor.js +345 -0
- package/dist/cli/commands/extension/doctor.js.map +1 -0
- package/dist/cli/commands/extension/install-sources.d.ts +37 -0
- package/dist/cli/commands/extension/install-sources.js +384 -0
- package/dist/cli/commands/extension/install-sources.js.map +1 -0
- package/dist/cli/commands/extension/managed-state.d.ts +48 -0
- package/dist/cli/commands/extension/managed-state.js +172 -0
- package/dist/cli/commands/extension/managed-state.js.map +1 -0
- package/dist/cli/commands/extension/scaffold.d.ts +14 -0
- package/dist/cli/commands/extension/scaffold.js +169 -0
- package/dist/cli/commands/extension/scaffold.js.map +1 -0
- package/dist/cli/commands/extension/shared.d.ts +14 -0
- package/dist/cli/commands/extension/shared.js +106 -0
- package/dist/cli/commands/extension/shared.js.map +1 -0
- package/dist/cli/commands/extension.d.ts +37 -68
- package/dist/cli/commands/extension.js +157 -1319
- package/dist/cli/commands/extension.js.map +1 -1
- package/dist/cli/commands/files.d.ts +1 -12
- package/dist/cli/commands/files.js +14 -318
- package/dist/cli/commands/files.js.map +1 -1
- package/dist/cli/commands/gc.js +17 -4
- package/dist/cli/commands/gc.js.map +1 -1
- package/dist/cli/commands/get.d.ts +3 -2
- package/dist/cli/commands/get.js +52 -9
- package/dist/cli/commands/get.js.map +1 -1
- package/dist/cli/commands/health.d.ts +10 -0
- package/dist/cli/commands/health.js +269 -76
- package/dist/cli/commands/health.js.map +1 -1
- package/dist/cli/commands/history-redact.d.ts +8 -0
- package/dist/cli/commands/history-redact.js +35 -113
- package/dist/cli/commands/history-redact.js.map +1 -1
- package/dist/cli/commands/history-repair.d.ts +33 -0
- package/dist/cli/commands/history-repair.js +172 -0
- package/dist/cli/commands/history-repair.js.map +1 -0
- package/dist/cli/commands/history.d.ts +4 -4
- package/dist/cli/commands/history.js +10 -88
- package/dist/cli/commands/history.js.map +1 -1
- package/dist/cli/commands/index.d.ts +3 -1
- package/dist/cli/commands/index.js +5 -3
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +28 -0
- package/dist/cli/commands/init.js +23 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/learnings.js +20 -119
- package/dist/cli/commands/learnings.js.map +1 -1
- package/dist/cli/commands/legacy-none-tokens.d.ts +3 -0
- package/dist/cli/commands/legacy-none-tokens.js +39 -0
- package/dist/cli/commands/legacy-none-tokens.js.map +1 -0
- package/dist/cli/commands/linked-artifacts.d.ts +96 -0
- package/dist/cli/commands/linked-artifacts.js +335 -0
- package/dist/cli/commands/linked-artifacts.js.map +1 -0
- package/dist/cli/commands/linked-test-entry.d.ts +3 -0
- package/dist/cli/commands/linked-test-entry.js +62 -0
- package/dist/cli/commands/linked-test-entry.js.map +1 -0
- package/dist/cli/commands/linked-test-parsers.d.ts +28 -0
- package/dist/cli/commands/linked-test-parsers.js +192 -0
- package/dist/cli/commands/linked-test-parsers.js.map +1 -0
- package/dist/cli/commands/list.js +49 -24
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/normalize.js +4 -3
- package/dist/cli/commands/normalize.js.map +1 -1
- package/dist/cli/commands/notes.js +20 -119
- package/dist/cli/commands/notes.js.map +1 -1
- package/dist/cli/commands/plan.d.ts +3 -0
- package/dist/cli/commands/plan.js +184 -22
- package/dist/cli/commands/plan.js.map +1 -1
- package/dist/cli/commands/recurrence-parsers.d.ts +26 -0
- package/dist/cli/commands/recurrence-parsers.js +98 -0
- package/dist/cli/commands/recurrence-parsers.js.map +1 -0
- package/dist/cli/commands/restore.js +24 -56
- package/dist/cli/commands/restore.js.map +1 -1
- package/dist/cli/commands/schema.d.ts +31 -0
- package/dist/cli/commands/schema.js +98 -0
- package/dist/cli/commands/schema.js.map +1 -0
- package/dist/cli/commands/search.js +154 -42
- package/dist/cli/commands/search.js.map +1 -1
- package/dist/cli/commands/templates.d.ts +4 -0
- package/dist/cli/commands/templates.js +89 -17
- package/dist/cli/commands/templates.js.map +1 -1
- package/dist/cli/commands/test/linked-command-detection.d.ts +37 -0
- package/dist/cli/commands/test/linked-command-detection.js +200 -0
- package/dist/cli/commands/test/linked-command-detection.js.map +1 -0
- package/dist/cli/commands/test-all.js +4 -8
- package/dist/cli/commands/test-all.js.map +1 -1
- package/dist/cli/commands/test.d.ts +2 -2
- package/dist/cli/commands/test.js +12 -357
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/commands/update-many.js +6 -9
- package/dist/cli/commands/update-many.js.map +1 -1
- package/dist/cli/commands/update.js +167 -401
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +3 -1
- package/dist/cli/commands/validate.js +23 -71
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/error-guidance.d.ts +1 -0
- package/dist/cli/error-guidance.js +100 -6
- package/dist/cli/error-guidance.js.map +1 -1
- package/dist/cli/extension-command-help.d.ts +0 -1
- package/dist/cli/extension-command-help.js +2 -13
- package/dist/cli/extension-command-help.js.map +1 -1
- package/dist/cli/extension-command-options.d.ts +1 -0
- package/dist/cli/extension-command-options.js +106 -7
- package/dist/cli/extension-command-options.js.map +1 -1
- package/dist/cli/help-content.d.ts +0 -1
- package/dist/cli/help-content.js +13 -9
- package/dist/cli/help-content.js.map +1 -1
- package/dist/cli/help-json-payload.d.ts +1 -0
- package/dist/cli/help-json-payload.js +33 -3
- package/dist/cli/help-json-payload.js.map +1 -1
- package/dist/cli/main.d.ts +11 -0
- package/dist/cli/main.js +109 -55
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/register-list-query.d.ts +5 -2
- package/dist/cli/register-list-query.js +254 -192
- package/dist/cli/register-list-query.js.map +1 -1
- package/dist/cli/register-mutation.d.ts +1 -1
- package/dist/cli/register-mutation.js +247 -64
- package/dist/cli/register-mutation.js.map +1 -1
- package/dist/cli/register-operations.js +17 -12
- package/dist/cli/register-operations.js.map +1 -1
- package/dist/cli/register-setup.js +33 -16
- package/dist/cli/register-setup.js.map +1 -1
- package/dist/cli/registration-helpers.d.ts +0 -2
- package/dist/cli/registration-helpers.js +14 -40
- package/dist/cli/registration-helpers.js.map +1 -1
- package/dist/cli.js +25 -4
- package/dist/cli.js.map +1 -1
- package/dist/core/config/positional-value.d.ts +44 -0
- package/dist/core/config/positional-value.js +109 -0
- package/dist/core/config/positional-value.js.map +1 -0
- package/dist/core/extensions/extension-capability-aliases.d.ts +14 -0
- package/dist/core/extensions/extension-capability-aliases.js +159 -0
- package/dist/core/extensions/extension-capability-aliases.js.map +1 -0
- package/dist/core/extensions/extension-hook-runtime.d.ts +13 -0
- package/dist/core/extensions/extension-hook-runtime.js +414 -0
- package/dist/core/extensions/extension-hook-runtime.js.map +1 -0
- package/dist/core/extensions/extension-policy.d.ts +69 -0
- package/dist/core/extensions/extension-policy.js +481 -0
- package/dist/core/extensions/extension-policy.js.map +1 -0
- package/dist/core/extensions/extension-registries.d.ts +8 -0
- package/dist/core/extensions/extension-registries.js +52 -0
- package/dist/core/extensions/extension-registries.js.map +1 -0
- package/dist/core/extensions/extension-runtime-helpers.d.ts +6 -0
- package/dist/core/extensions/extension-runtime-helpers.js +29 -0
- package/dist/core/extensions/extension-runtime-helpers.js.map +1 -0
- package/dist/core/extensions/extension-types.d.ts +13 -39
- package/dist/core/extensions/extension-types.js +34 -2
- package/dist/core/extensions/extension-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +7 -1
- package/dist/core/extensions/index.js +11 -14
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +4 -22
- package/dist/core/extensions/loader.js +23 -1146
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/fs/path-utils.d.ts +1 -0
- package/dist/core/fs/path-utils.js +12 -0
- package/dist/core/fs/path-utils.js.map +1 -0
- package/dist/core/history/drift-scan.d.ts +22 -0
- package/dist/core/history/drift-scan.js +149 -0
- package/dist/core/history/drift-scan.js.map +1 -0
- package/dist/core/history/history-rewrite.d.ts +43 -0
- package/dist/core/history/history-rewrite.js +48 -0
- package/dist/core/history/history-rewrite.js.map +1 -0
- package/dist/core/history/history.js +5 -4
- package/dist/core/history/history.js.map +1 -1
- package/dist/core/history/replay.d.ts +82 -0
- package/dist/core/history/replay.js +250 -0
- package/dist/core/history/replay.js.map +1 -0
- package/dist/core/item/item-format.js +11 -8
- package/dist/core/item/item-format.js.map +1 -1
- package/dist/core/item/item-record.d.ts +19 -0
- package/dist/core/item/item-record.js +24 -0
- package/dist/core/item/item-record.js.map +1 -0
- package/dist/core/item/item-type-definition.d.ts +52 -0
- package/dist/core/item/item-type-definition.js +123 -0
- package/dist/core/item/item-type-definition.js.map +1 -0
- package/dist/core/item/parse.js +3 -2
- package/dist/core/item/parse.js.map +1 -1
- package/dist/core/item/priority.d.ts +23 -0
- package/dist/core/item/priority.js +55 -0
- package/dist/core/item/priority.js.map +1 -0
- package/dist/core/item/status.d.ts +14 -1
- package/dist/core/item/status.js +22 -2
- package/dist/core/item/status.js.map +1 -1
- package/dist/core/item/toon-decode.d.ts +19 -0
- package/dist/core/item/toon-decode.js +69 -0
- package/dist/core/item/toon-decode.js.map +1 -0
- package/dist/core/item/type-registry.js +13 -84
- package/dist/core/item/type-registry.js.map +1 -1
- package/dist/core/output/mutation-projection.d.ts +31 -0
- package/dist/core/output/mutation-projection.js +103 -0
- package/dist/core/output/mutation-projection.js.map +1 -0
- package/dist/core/output/output.d.ts +2 -0
- package/dist/core/output/output.js +5 -3
- package/dist/core/output/output.js.map +1 -1
- package/dist/core/packages/manifest.js +3 -9
- package/dist/core/packages/manifest.js.map +1 -1
- package/dist/core/schema/item-types-file.d.ts +85 -0
- package/dist/core/schema/item-types-file.js +243 -0
- package/dist/core/schema/item-types-file.js.map +1 -0
- package/dist/core/schema/runtime-schema.d.ts +2 -1
- package/dist/core/schema/runtime-schema.js +17 -45
- package/dist/core/schema/runtime-schema.js.map +1 -1
- package/dist/core/search/semantic-defaults.js +3 -3
- package/dist/core/search/semantic-defaults.js.map +1 -1
- package/dist/core/search/vector-stores.js +46 -9
- package/dist/core/search/vector-stores.js.map +1 -1
- package/dist/core/sentry/helpers.d.ts +1 -1
- package/dist/core/sentry/helpers.js +20 -3
- package/dist/core/sentry/helpers.js.map +1 -1
- package/dist/core/shared/author.d.ts +1 -0
- package/dist/core/shared/author.js +9 -0
- package/dist/core/shared/author.js.map +1 -0
- package/dist/core/shared/command-types.d.ts +1 -0
- package/dist/core/shared/command-types.js +2 -2
- package/dist/core/shared/command-types.js.map +1 -1
- package/dist/core/shared/constants.d.ts +10 -1
- package/dist/core/shared/constants.js +56 -58
- package/dist/core/shared/constants.js.map +1 -1
- package/dist/core/shared/lazy-module.d.ts +1 -0
- package/dist/core/shared/lazy-module.js +11 -0
- package/dist/core/shared/lazy-module.js.map +1 -0
- package/dist/core/shared/option-alias-visibility.d.ts +44 -0
- package/dist/core/shared/option-alias-visibility.js +76 -0
- package/dist/core/shared/option-alias-visibility.js.map +1 -0
- package/dist/core/shared/primitives.d.ts +23 -0
- package/dist/core/shared/primitives.js +39 -2
- package/dist/core/shared/primitives.js.map +1 -1
- package/dist/core/shared/text-normalization.d.ts +0 -1
- package/dist/core/shared/text-normalization.js +2 -5
- package/dist/core/shared/text-normalization.js.map +1 -1
- package/dist/core/store/front-matter-cache.d.ts +16 -2
- package/dist/core/store/front-matter-cache.js +99 -33
- package/dist/core/store/front-matter-cache.js.map +1 -1
- package/dist/core/store/item-store.d.ts +2 -0
- package/dist/core/store/item-store.js +76 -110
- package/dist/core/store/item-store.js.map +1 -1
- package/dist/core/store/settings-validator.d.ts +106 -0
- package/dist/core/store/settings-validator.js +279 -0
- package/dist/core/store/settings-validator.js.map +1 -0
- package/dist/core/store/settings.js +6 -343
- package/dist/core/store/settings.js.map +1 -1
- package/dist/core/telemetry/runtime.js +5 -3
- package/dist/core/telemetry/runtime.js.map +1 -1
- package/dist/mcp/server.js +138 -39
- package/dist/mcp/server.js.map +1 -1
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +20 -0
- package/dist/sdk/cli-contracts/enum-contracts.js +156 -0
- package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -0
- package/dist/sdk/cli-contracts/tool-option-contracts.d.ts +14 -0
- package/dist/sdk/cli-contracts/tool-option-contracts.js +243 -0
- package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -0
- package/dist/sdk/cli-contracts/tool-parameter-tables.d.ts +11 -0
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +901 -0
- package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -0
- package/dist/sdk/cli-contracts.d.ts +18 -33
- package/dist/sdk/cli-contracts.js +96 -1238
- package/dist/sdk/cli-contracts.js.map +1 -1
- package/dist/sdk/package-import-adapters.d.ts +74 -0
- package/dist/sdk/package-import-adapters.js +186 -0
- package/dist/sdk/package-import-adapters.js.map +1 -0
- package/dist/sdk/package-runtime-options.d.ts +26 -0
- package/dist/sdk/package-runtime-options.js +71 -0
- package/dist/sdk/package-runtime-options.js.map +1 -0
- package/dist/sdk/runtime.d.ts +27 -1
- package/dist/sdk/runtime.js +48 -3
- package/dist/sdk/runtime.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.js +10 -2
- package/dist/types.js.map +1 -1
- package/docs/AGENT_GUIDE.md +13 -11
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CLAUDE_CODE_PLUGIN.md +5 -28
- package/docs/CODEX_PLUGIN.md +5 -5
- package/docs/COMMANDS.md +58 -9
- package/docs/CONFIGURATION.md +16 -1
- package/docs/EXTENSIONS.md +4 -63
- package/docs/RELEASING.md +12 -8
- package/docs/SDK.md +11 -2
- package/marketplace.json +7 -3
- package/package.json +18 -14
- package/packages/pm-beads/extensions/beads/index.js +2 -49
- package/packages/pm-beads/extensions/beads/index.ts +2 -54
- package/packages/pm-beads/extensions/beads/runtime-loader.js +86 -0
- package/packages/pm-beads/extensions/beads/runtime-loader.ts +88 -0
- package/packages/pm-beads/extensions/beads/runtime.js +26 -115
- package/packages/pm-beads/extensions/beads/runtime.ts +33 -132
- package/packages/pm-calendar/README.md +3 -1
- package/packages/pm-calendar/extensions/calendar/index.js +66 -2
- package/packages/pm-calendar/extensions/calendar/index.ts +71 -2
- package/packages/pm-calendar/extensions/calendar/runtime.js +1 -0
- package/packages/pm-calendar/extensions/calendar/runtime.ts +1 -0
- package/packages/pm-governance-audit/extensions/governance-audit/runtime.js +14 -41
- package/packages/pm-governance-audit/extensions/governance-audit/runtime.ts +25 -41
- package/packages/pm-guide-shell/extensions/guide-shell/runtime.js +10 -50
- package/packages/pm-guide-shell/extensions/guide-shell/runtime.ts +17 -50
- package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/runtime.js +8 -40
- package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/runtime.ts +10 -40
- package/packages/pm-search-advanced/README.md +8 -0
- package/packages/pm-search-advanced/extensions/search-advanced/index.js +75 -1
- package/packages/pm-search-advanced/extensions/search-advanced/index.ts +74 -0
- package/packages/pm-search-advanced/extensions/search-advanced/runtime.js +58 -33
- package/packages/pm-search-advanced/extensions/search-advanced/runtime.ts +60 -33
- package/packages/pm-templates/extensions/templates/runtime.js +11 -202
- package/packages/pm-templates/extensions/templates/runtime.ts +38 -230
- package/packages/pm-todos/extensions/todos/index.js +3 -50
- package/packages/pm-todos/extensions/todos/index.ts +3 -55
- package/packages/pm-todos/extensions/todos/runtime-loader.js +86 -0
- package/packages/pm-todos/extensions/todos/runtime-loader.ts +88 -0
- package/packages/pm-todos/extensions/todos/runtime.js +24 -117
- package/packages/pm-todos/extensions/todos/runtime.ts +32 -129
- package/plugins/pm-claude/README.md +2 -2
- package/plugins/pm-claude/commands/pm-planner.md +1 -15
- package/plugins/pm-claude/scripts/pm-mcp-server.mjs +5 -2
- package/plugins/pm-claude/skills/pm-planner/SKILL.md +3 -21
- package/plugins/pm-codex/scripts/pm-mcp-server.mjs +15 -6
- package/plugins/pm-codex/skills/pm-native/SKILL.md +1 -13
- package/PRD.md +0 -1734
- package/dist/core/output/command-aware.d.ts +0 -1
- package/dist/core/output/command-aware.js +0 -397
- package/dist/core/output/command-aware.js.map +0 -1
|
@@ -1,81 +1,12 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { pathToFileURL } from "node:url";
|
|
4
3
|
import type { GlobalOptions } from "../../../../src/sdk/index.js";
|
|
5
4
|
|
|
6
5
|
const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
|
|
7
6
|
|
|
8
|
-
interface TemplatesSdkModule {
|
|
9
|
-
CREATE_COMMANDER_REPEATABLE_OPTION_CONTRACTS: Array<{ target: string }>;
|
|
10
|
-
EXIT_CODE: {
|
|
11
|
-
USAGE: number;
|
|
12
|
-
NOT_FOUND: number;
|
|
13
|
-
GENERIC_FAILURE: number;
|
|
14
|
-
};
|
|
15
|
-
PmCliError: new (message: string, exitCode?: number) => Error;
|
|
16
|
-
getSettingsPath: (pmRoot: string) => string;
|
|
17
|
-
nowIso: () => string;
|
|
18
|
-
pathExists: (targetPath: string) => Promise<boolean>;
|
|
19
|
-
readFileIfExists: (targetPath: string) => Promise<string | null>;
|
|
20
|
-
resolvePmRoot: (cwd: string, overridePath?: string) => string;
|
|
21
|
-
writeFileAtomic: (targetPath: string, contents: string) => Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const sdk = await loadTemplatesSdkModule();
|
|
25
|
-
const {
|
|
26
|
-
CREATE_COMMANDER_REPEATABLE_OPTION_CONTRACTS,
|
|
27
|
-
EXIT_CODE,
|
|
28
|
-
PmCliError,
|
|
29
|
-
getSettingsPath,
|
|
30
|
-
nowIso,
|
|
31
|
-
pathExists,
|
|
32
|
-
readFileIfExists,
|
|
33
|
-
resolvePmRoot,
|
|
34
|
-
writeFileAtomic,
|
|
35
|
-
} = sdk;
|
|
36
|
-
|
|
37
|
-
async function loadTemplatesSdkModule(): Promise<TemplatesSdkModule> {
|
|
38
|
-
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
39
|
-
if (typeof envRoot !== "string" || envRoot.trim().length === 0) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
`builtin-templates requires ${PM_PACKAGE_ROOT_ENV} to locate core SDK runtime exports.`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
const modulePath = path.join(path.resolve(envRoot.trim()), "dist", "sdk", "index.js");
|
|
45
|
-
try {
|
|
46
|
-
const loaded = (await import(pathToFileURL(modulePath).href)) as Partial<TemplatesSdkModule>;
|
|
47
|
-
if (
|
|
48
|
-
typeof loaded.resolvePmRoot === "function" &&
|
|
49
|
-
typeof loaded.pathExists === "function" &&
|
|
50
|
-
typeof loaded.PmCliError === "function" &&
|
|
51
|
-
Array.isArray(loaded.CREATE_COMMANDER_REPEATABLE_OPTION_CONTRACTS)
|
|
52
|
-
) {
|
|
53
|
-
return loaded as TemplatesSdkModule;
|
|
54
|
-
}
|
|
55
|
-
} catch {
|
|
56
|
-
// Fall through to deterministic failure message below.
|
|
57
|
-
}
|
|
58
|
-
throw new Error(
|
|
59
|
-
`builtin-templates failed to load SDK runtime exports from ${modulePath}.`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const TEMPLATE_DIRECTORY_NAME = "templates";
|
|
64
|
-
const TEMPLATE_FILE_EXTENSION = ".json";
|
|
65
|
-
const TEMPLATE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
66
|
-
const TEMPLATE_OPTION_REPEATABLE_KEYS = CREATE_COMMANDER_REPEATABLE_OPTION_CONTRACTS.map((entry) => entry.target);
|
|
67
|
-
const TEMPLATE_OPTION_REPEATABLE_KEY_SET = new Set<string>(TEMPLATE_OPTION_REPEATABLE_KEYS);
|
|
68
|
-
|
|
69
7
|
type TemplateOptionValue = string | string[];
|
|
70
8
|
export type CreateTemplateOptions = Record<string, TemplateOptionValue>;
|
|
71
9
|
|
|
72
|
-
interface StoredCreateTemplateDocument {
|
|
73
|
-
name: string;
|
|
74
|
-
created_at: string;
|
|
75
|
-
updated_at: string;
|
|
76
|
-
options: CreateTemplateOptions;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
10
|
export interface TemplatesSaveResult {
|
|
80
11
|
name: string;
|
|
81
12
|
created_at: string;
|
|
@@ -87,128 +18,60 @@ export interface TemplatesSaveResult {
|
|
|
87
18
|
export interface TemplatesListResult {
|
|
88
19
|
templates: string[];
|
|
89
20
|
count: number;
|
|
21
|
+
builtin_templates: string[];
|
|
22
|
+
user_templates: string[];
|
|
90
23
|
}
|
|
91
24
|
|
|
92
25
|
export interface TemplatesShowResult {
|
|
93
26
|
name: string;
|
|
27
|
+
source: "builtin" | "user";
|
|
94
28
|
created_at: string;
|
|
95
29
|
updated_at: string;
|
|
96
30
|
path: string;
|
|
97
31
|
options: CreateTemplateOptions;
|
|
98
32
|
}
|
|
99
33
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function templatesDirectory(pmRoot: string): string {
|
|
112
|
-
return path.join(pmRoot, TEMPLATE_DIRECTORY_NAME);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function templatePath(pmRoot: string, normalizedName: string): string {
|
|
116
|
-
return path.join(templatesDirectory(pmRoot), `${normalizedName}${TEMPLATE_FILE_EXTENSION}`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function ensureTrackerInitialized(pmRoot: string): Promise<void> {
|
|
120
|
-
if (!(await pathExists(getSettingsPath(pmRoot)))) {
|
|
121
|
-
throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function sortTemplateOptions(options: CreateTemplateOptions): CreateTemplateOptions {
|
|
126
|
-
return Object.fromEntries(
|
|
127
|
-
Object.entries(options).sort(([left], [right]) => left.localeCompare(right)),
|
|
128
|
-
) as CreateTemplateOptions;
|
|
34
|
+
interface TemplatesSdkModule {
|
|
35
|
+
loadCreateTemplateOptions: (pmRoot: string, rawTemplateName: string) => Promise<CreateTemplateOptions>;
|
|
36
|
+
runTemplatesList: (global: GlobalOptions) => Promise<TemplatesListResult>;
|
|
37
|
+
runTemplatesSave: (
|
|
38
|
+
rawTemplateName: string,
|
|
39
|
+
options: Record<string, unknown>,
|
|
40
|
+
global: GlobalOptions,
|
|
41
|
+
) => Promise<TemplatesSaveResult>;
|
|
42
|
+
runTemplatesShow: (rawTemplateName: string, global: GlobalOptions) => Promise<TemplatesShowResult>;
|
|
129
43
|
}
|
|
130
44
|
|
|
131
|
-
|
|
132
|
-
const next: CreateTemplateOptions = {};
|
|
133
|
-
for (const [key, value] of Object.entries(rawOptions)) {
|
|
134
|
-
if (value === undefined) {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (TEMPLATE_OPTION_REPEATABLE_KEY_SET.has(key)) {
|
|
138
|
-
if (typeof value === "string") {
|
|
139
|
-
next[key] = [value];
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (!Array.isArray(value)) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
const values = value.filter((entry): entry is string => typeof entry === "string");
|
|
146
|
-
if (values.length > 0) {
|
|
147
|
-
next[key] = values;
|
|
148
|
-
}
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (typeof value === "string") {
|
|
152
|
-
next[key] = value;
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
|
|
156
|
-
next[key] = [...value];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return sortTemplateOptions(next);
|
|
160
|
-
}
|
|
45
|
+
const sdk = await loadTemplatesSdkModule();
|
|
161
46
|
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const normalizedKey = key.trim();
|
|
169
|
-
if (normalizedKey.length === 0) {
|
|
170
|
-
throw new PmCliError(`Template "${templateName}" contains an empty option key.`, EXIT_CODE.GENERIC_FAILURE);
|
|
171
|
-
}
|
|
172
|
-
if (typeof value === "string") {
|
|
173
|
-
normalized[normalizedKey] = value;
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
|
|
177
|
-
normalized[normalizedKey] = [...value];
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
throw new PmCliError(`Template "${templateName}" contains invalid value for option "${normalizedKey}".`, EXIT_CODE.GENERIC_FAILURE);
|
|
47
|
+
async function loadTemplatesSdkModule(): Promise<TemplatesSdkModule> {
|
|
48
|
+
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
49
|
+
if (typeof envRoot !== "string" || envRoot.trim().length === 0) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`builtin-templates requires ${PM_PACKAGE_ROOT_ENV} to locate core SDK runtime exports.`,
|
|
52
|
+
);
|
|
181
53
|
}
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function parseStoredTemplateDocument(raw: string, normalizedName: string): StoredCreateTemplateDocument {
|
|
186
|
-
let parsed: unknown;
|
|
54
|
+
const modulePath = path.join(path.resolve(envRoot.trim()), "dist", "sdk", "index.js");
|
|
187
55
|
try {
|
|
188
|
-
|
|
56
|
+
const loaded = (await import(pathToFileURL(modulePath).href)) as Partial<TemplatesSdkModule>;
|
|
57
|
+
if (
|
|
58
|
+
typeof loaded.loadCreateTemplateOptions === "function" &&
|
|
59
|
+
typeof loaded.runTemplatesList === "function" &&
|
|
60
|
+
typeof loaded.runTemplatesSave === "function" &&
|
|
61
|
+
typeof loaded.runTemplatesShow === "function"
|
|
62
|
+
) {
|
|
63
|
+
return loaded as TemplatesSdkModule;
|
|
64
|
+
}
|
|
189
65
|
} catch {
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
193
|
-
throw new PmCliError(`Template "${normalizedName}" has invalid document shape.`, EXIT_CODE.GENERIC_FAILURE);
|
|
66
|
+
// Fall through to deterministic failure message below.
|
|
194
67
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return {
|
|
199
|
-
name: typeof record.name === "string" && record.name.trim().length > 0 ? record.name.trim() : normalizedName,
|
|
200
|
-
created_at: typeof record.created_at === "string" ? record.created_at : now,
|
|
201
|
-
updated_at: typeof record.updated_at === "string" ? record.updated_at : now,
|
|
202
|
-
options,
|
|
203
|
-
};
|
|
68
|
+
throw new Error(
|
|
69
|
+
`builtin-templates failed to load template runtime exports from ${modulePath}.`,
|
|
70
|
+
);
|
|
204
71
|
}
|
|
205
72
|
|
|
206
|
-
async function
|
|
207
|
-
|
|
208
|
-
if (raw === null) {
|
|
209
|
-
throw new PmCliError(`Template "${normalizedName}" not found`, EXIT_CODE.NOT_FOUND);
|
|
210
|
-
}
|
|
211
|
-
return parseStoredTemplateDocument(raw, normalizedName);
|
|
73
|
+
export async function loadCreateTemplateOptions(pmRoot: string, rawTemplateName: string): Promise<CreateTemplateOptions> {
|
|
74
|
+
return sdk.loadCreateTemplateOptions(pmRoot, rawTemplateName);
|
|
212
75
|
}
|
|
213
76
|
|
|
214
77
|
export async function runTemplatesSave(
|
|
@@ -216,68 +79,13 @@ export async function runTemplatesSave(
|
|
|
216
79
|
options: Record<string, unknown>,
|
|
217
80
|
global: GlobalOptions,
|
|
218
81
|
): Promise<TemplatesSaveResult> {
|
|
219
|
-
|
|
220
|
-
await ensureTrackerInitialized(pmRoot);
|
|
221
|
-
const normalizedName = normalizeTemplateName(rawTemplateName);
|
|
222
|
-
const nextOptions = extractTemplateOptions(options);
|
|
223
|
-
if (Object.keys(nextOptions).length === 0) {
|
|
224
|
-
throw new PmCliError("templates save requires at least one create option flag", EXIT_CODE.USAGE);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const now = nowIso();
|
|
228
|
-
const storedPath = templatePath(pmRoot, normalizedName);
|
|
229
|
-
let createdAt = now;
|
|
230
|
-
if (await pathExists(storedPath)) {
|
|
231
|
-
const existing = await readStoredTemplateDocument(pmRoot, normalizedName);
|
|
232
|
-
createdAt = existing.created_at;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const document: StoredCreateTemplateDocument = {
|
|
236
|
-
name: normalizedName,
|
|
237
|
-
created_at: createdAt,
|
|
238
|
-
updated_at: now,
|
|
239
|
-
options: nextOptions,
|
|
240
|
-
};
|
|
241
|
-
await fs.mkdir(templatesDirectory(pmRoot), { recursive: true });
|
|
242
|
-
await writeFileAtomic(storedPath, `${JSON.stringify(document, null, 2)}\n`);
|
|
243
|
-
return {
|
|
244
|
-
name: document.name,
|
|
245
|
-
created_at: document.created_at,
|
|
246
|
-
updated_at: document.updated_at,
|
|
247
|
-
path: storedPath,
|
|
248
|
-
options: document.options,
|
|
249
|
-
};
|
|
82
|
+
return sdk.runTemplatesSave(rawTemplateName, options, global);
|
|
250
83
|
}
|
|
251
84
|
|
|
252
85
|
export async function runTemplatesList(global: GlobalOptions): Promise<TemplatesListResult> {
|
|
253
|
-
|
|
254
|
-
await ensureTrackerInitialized(pmRoot);
|
|
255
|
-
const dirPath = templatesDirectory(pmRoot);
|
|
256
|
-
if (!(await pathExists(dirPath))) {
|
|
257
|
-
return { templates: [], count: 0 };
|
|
258
|
-
}
|
|
259
|
-
const entries = await fs.readdir(dirPath);
|
|
260
|
-
const templates = entries
|
|
261
|
-
.filter((entry) => entry.toLowerCase().endsWith(TEMPLATE_FILE_EXTENSION))
|
|
262
|
-
.map((entry) => entry.slice(0, -TEMPLATE_FILE_EXTENSION.length))
|
|
263
|
-
.filter((entry) => TEMPLATE_NAME_PATTERN.test(entry))
|
|
264
|
-
.sort((left, right) => left.localeCompare(right));
|
|
265
|
-
return {
|
|
266
|
-
templates,
|
|
267
|
-
count: templates.length,
|
|
268
|
-
};
|
|
86
|
+
return sdk.runTemplatesList(global);
|
|
269
87
|
}
|
|
270
88
|
|
|
271
89
|
export async function runTemplatesShow(rawTemplateName: string, global: GlobalOptions): Promise<TemplatesShowResult> {
|
|
272
|
-
|
|
273
|
-
await ensureTrackerInitialized(pmRoot);
|
|
274
|
-
const normalizedName = normalizeTemplateName(rawTemplateName);
|
|
275
|
-
const stored = await readStoredTemplateDocument(pmRoot, normalizedName);
|
|
276
|
-
return {
|
|
277
|
-
name: stored.name,
|
|
278
|
-
created_at: stored.created_at,
|
|
279
|
-
updated_at: stored.updated_at,
|
|
280
|
-
path: templatePath(pmRoot, normalizedName),
|
|
281
|
-
options: stored.options,
|
|
282
|
-
};
|
|
90
|
+
return sdk.runTemplatesShow(rawTemplateName, global);
|
|
283
91
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
-
const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
|
|
4
|
-
const CURRENT_EXTENSION_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
1
|
+
import { loadPackageRuntimeModule } from "./runtime-loader.js";
|
|
5
2
|
export const manifest = {
|
|
6
3
|
name: "builtin-todos-import-export",
|
|
7
4
|
version: "0.1.0",
|
|
@@ -24,59 +21,15 @@ function toExportOptions(options) {
|
|
|
24
21
|
folder: asOptionalString(options.folder),
|
|
25
22
|
};
|
|
26
23
|
}
|
|
27
|
-
function resolvePackageRootCandidates() {
|
|
28
|
-
const candidates = [];
|
|
29
|
-
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
30
|
-
if (typeof envRoot === "string" && envRoot.trim().length > 0) {
|
|
31
|
-
candidates.push(path.resolve(envRoot.trim()));
|
|
32
|
-
}
|
|
33
|
-
const argvEntry = typeof process.argv[1] === "string" ? process.argv[1].trim() : "";
|
|
34
|
-
if (argvEntry.length > 0) {
|
|
35
|
-
const resolvedEntry = path.resolve(argvEntry);
|
|
36
|
-
const entryDir = path.dirname(resolvedEntry);
|
|
37
|
-
candidates.push(path.resolve(entryDir, ".."));
|
|
38
|
-
candidates.push(path.resolve(entryDir, "../.."));
|
|
39
|
-
candidates.push(path.resolve(entryDir, "../../.."));
|
|
40
|
-
}
|
|
41
|
-
return [...new Set(candidates)];
|
|
42
|
-
}
|
|
43
|
-
async function loadRuntimeModule() {
|
|
44
|
-
const attempted = [];
|
|
45
|
-
for (const packageRoot of resolvePackageRootCandidates()) {
|
|
46
|
-
const modulePaths = [
|
|
47
|
-
path.join(packageRoot, ".agents", "pm", "extensions", "todos", "runtime.js"),
|
|
48
|
-
path.join(packageRoot, "packages", "pm-todos", "extensions", "todos", "runtime.js"),
|
|
49
|
-
];
|
|
50
|
-
for (const modulePath of modulePaths) {
|
|
51
|
-
attempted.push(modulePath);
|
|
52
|
-
try {
|
|
53
|
-
return await import(pathToFileURL(modulePath).href);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
// Try the next package-root candidate.
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const localRuntimePath = path.join(CURRENT_EXTENSION_ROOT, "runtime.js");
|
|
61
|
-
attempted.push(localRuntimePath);
|
|
62
|
-
try {
|
|
63
|
-
return await import(pathToFileURL(localRuntimePath).href);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
// Fall through to the diagnostic below.
|
|
67
|
-
}
|
|
68
|
-
throw new Error("Unable to resolve packaged todos extension runtime module. " +
|
|
69
|
-
`Tried: ${attempted.join(", ")}. Ensure the installed extension includes runtime.js or PM_CLI_PACKAGE_ROOT points to an installed pm package root.`);
|
|
70
|
-
}
|
|
71
24
|
async function runTodosImportFromRuntime(options, global) {
|
|
72
|
-
const runtime = await
|
|
25
|
+
const runtime = await loadPackageRuntimeModule();
|
|
73
26
|
if (typeof runtime.runTodosImport !== "function") {
|
|
74
27
|
throw new Error("Bundled todos runtime module is missing runTodosImport().");
|
|
75
28
|
}
|
|
76
29
|
return runtime.runTodosImport(options, global);
|
|
77
30
|
}
|
|
78
31
|
async function runTodosExportFromRuntime(options, global) {
|
|
79
|
-
const runtime = await
|
|
32
|
+
const runtime = await loadPackageRuntimeModule();
|
|
80
33
|
if (typeof runtime.runTodosExport !== "function") {
|
|
81
34
|
throw new Error("Bundled todos runtime module is missing runTodosExport().");
|
|
82
35
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
1
|
import type { CommandDefinition, ExtensionApi, GlobalOptions } from "../../../../src/sdk/index.js";
|
|
4
2
|
import type { TodosExportOptions, TodosExportResult, TodosImportOptions, TodosImportResult } from "./runtime.js";
|
|
5
|
-
|
|
6
|
-
const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
|
|
7
|
-
const CURRENT_EXTENSION_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
3
|
+
import { loadPackageRuntimeModule } from "./runtime-loader.js";
|
|
8
4
|
|
|
9
5
|
export const manifest = {
|
|
10
6
|
name: "builtin-todos-import-export",
|
|
@@ -37,56 +33,8 @@ function toExportOptions(options: Record<string, unknown>): TodosExportOptions {
|
|
|
37
33
|
};
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
function resolvePackageRootCandidates(): string[] {
|
|
41
|
-
const candidates: string[] = [];
|
|
42
|
-
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
43
|
-
if (typeof envRoot === "string" && envRoot.trim().length > 0) {
|
|
44
|
-
candidates.push(path.resolve(envRoot.trim()));
|
|
45
|
-
}
|
|
46
|
-
const argvEntry = typeof process.argv[1] === "string" ? process.argv[1].trim() : "";
|
|
47
|
-
if (argvEntry.length > 0) {
|
|
48
|
-
const resolvedEntry = path.resolve(argvEntry);
|
|
49
|
-
const entryDir = path.dirname(resolvedEntry);
|
|
50
|
-
candidates.push(path.resolve(entryDir, ".."));
|
|
51
|
-
candidates.push(path.resolve(entryDir, "../.."));
|
|
52
|
-
candidates.push(path.resolve(entryDir, "../../.."));
|
|
53
|
-
}
|
|
54
|
-
return [...new Set(candidates)];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function loadRuntimeModule(): Promise<RuntimeModule> {
|
|
58
|
-
const attempted: string[] = [];
|
|
59
|
-
for (const packageRoot of resolvePackageRootCandidates()) {
|
|
60
|
-
const modulePaths = [
|
|
61
|
-
path.join(packageRoot, ".agents", "pm", "extensions", "todos", "runtime.js"),
|
|
62
|
-
path.join(packageRoot, "packages", "pm-todos", "extensions", "todos", "runtime.js"),
|
|
63
|
-
];
|
|
64
|
-
for (const modulePath of modulePaths) {
|
|
65
|
-
attempted.push(modulePath);
|
|
66
|
-
try {
|
|
67
|
-
return await import(pathToFileURL(modulePath).href) as RuntimeModule;
|
|
68
|
-
} catch {
|
|
69
|
-
// Try the next package-root candidate.
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const localRuntimePath = path.join(CURRENT_EXTENSION_ROOT, "runtime.js");
|
|
75
|
-
attempted.push(localRuntimePath);
|
|
76
|
-
try {
|
|
77
|
-
return await import(pathToFileURL(localRuntimePath).href) as RuntimeModule;
|
|
78
|
-
} catch {
|
|
79
|
-
// Fall through to the diagnostic below.
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
throw new Error(
|
|
83
|
-
"Unable to resolve packaged todos extension runtime module. " +
|
|
84
|
-
`Tried: ${attempted.join(", ")}. Ensure the installed extension includes runtime.js or PM_CLI_PACKAGE_ROOT points to an installed pm package root.`,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
36
|
async function runTodosImportFromRuntime(options: TodosImportOptions, global: GlobalOptions): Promise<TodosImportResult> {
|
|
89
|
-
const runtime = await
|
|
37
|
+
const runtime = await loadPackageRuntimeModule() as RuntimeModule;
|
|
90
38
|
if (typeof runtime.runTodosImport !== "function") {
|
|
91
39
|
throw new Error("Bundled todos runtime module is missing runTodosImport().");
|
|
92
40
|
}
|
|
@@ -94,7 +42,7 @@ async function runTodosImportFromRuntime(options: TodosImportOptions, global: Gl
|
|
|
94
42
|
}
|
|
95
43
|
|
|
96
44
|
async function runTodosExportFromRuntime(options: TodosExportOptions, global: GlobalOptions): Promise<TodosExportResult> {
|
|
97
|
-
const runtime = await
|
|
45
|
+
const runtime = await loadPackageRuntimeModule() as RuntimeModule;
|
|
98
46
|
if (typeof runtime.runTodosExport !== "function") {
|
|
99
47
|
throw new Error("Bundled todos runtime module is missing runTodosExport().");
|
|
100
48
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GENERATED by scripts/gen-package-runtime-loaders.mjs - do not edit directly.
|
|
7
|
+
* This file is shipped with the package extension and intentionally avoids
|
|
8
|
+
* static SDK imports so project-local installed extensions can load it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
|
|
12
|
+
const CURRENT_EXTENSION_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const EXTENSION_NAME = "todos";
|
|
14
|
+
const PACKAGE_NAME = "pm-todos";
|
|
15
|
+
const DIAGNOSTIC_NAME = "todos";
|
|
16
|
+
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === "object" && value !== null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isMissingRuntimeModuleError(error, modulePath) {
|
|
22
|
+
if (!isRecord(error) || error.code !== "ERR_MODULE_NOT_FOUND") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const message = typeof error.message === "string" ? error.message : "";
|
|
26
|
+
const moduleUrl = pathToFileURL(modulePath).href;
|
|
27
|
+
return message.includes(modulePath) || message.includes(moduleUrl);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolvePackageRootCandidates() {
|
|
31
|
+
const candidates = [];
|
|
32
|
+
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
33
|
+
if (typeof envRoot === "string" && envRoot.trim().length > 0) {
|
|
34
|
+
candidates.push(path.resolve(envRoot.trim()));
|
|
35
|
+
}
|
|
36
|
+
const argvEntry = typeof process.argv[1] === "string" ? process.argv[1].trim() : "";
|
|
37
|
+
if (argvEntry.length > 0) {
|
|
38
|
+
const resolvedEntry = path.resolve(argvEntry);
|
|
39
|
+
const entryDir = path.dirname(resolvedEntry);
|
|
40
|
+
candidates.push(path.resolve(entryDir, ".."));
|
|
41
|
+
candidates.push(path.resolve(entryDir, "../.."));
|
|
42
|
+
candidates.push(path.resolve(entryDir, "../../.."));
|
|
43
|
+
}
|
|
44
|
+
return [...new Set(candidates)];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function loadPackageRuntimeModule() {
|
|
48
|
+
const attempted = [];
|
|
49
|
+
for (const packageRoot of resolvePackageRootCandidates()) {
|
|
50
|
+
const modulePaths = [
|
|
51
|
+
path.join(packageRoot, ".agents", "pm", "extensions", EXTENSION_NAME, "runtime.js"),
|
|
52
|
+
path.join(packageRoot, "packages", PACKAGE_NAME, "extensions", EXTENSION_NAME, "runtime.js"),
|
|
53
|
+
];
|
|
54
|
+
for (const modulePath of modulePaths) {
|
|
55
|
+
attempted.push(modulePath);
|
|
56
|
+
if (!existsSync(modulePath)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return await import(pathToFileURL(modulePath).href);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (isMissingRuntimeModuleError(error, modulePath)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const localRuntimePath = path.join(CURRENT_EXTENSION_ROOT, "runtime.js");
|
|
71
|
+
attempted.push(localRuntimePath);
|
|
72
|
+
if (existsSync(localRuntimePath)) {
|
|
73
|
+
try {
|
|
74
|
+
return await import(pathToFileURL(localRuntimePath).href);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (!isMissingRuntimeModuleError(error, localRuntimePath)) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Unable to resolve packaged ${DIAGNOSTIC_NAME} extension runtime module. ` +
|
|
84
|
+
`Tried: ${attempted.join(", ")}. Ensure the installed extension includes runtime.js or PM_CLI_PACKAGE_ROOT points to an installed pm package root.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GENERATED by scripts/gen-package-runtime-loaders.mjs - do not edit directly.
|
|
7
|
+
* This file is shipped with the package extension and intentionally avoids
|
|
8
|
+
* static SDK imports so project-local installed extensions can load it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
|
|
12
|
+
const CURRENT_EXTENSION_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const EXTENSION_NAME = "todos";
|
|
14
|
+
const PACKAGE_NAME = "pm-todos";
|
|
15
|
+
const DIAGNOSTIC_NAME = "todos";
|
|
16
|
+
|
|
17
|
+
export type PackageRuntimeModule = Record<string, unknown>;
|
|
18
|
+
|
|
19
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
20
|
+
return typeof value === "object" && value !== null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isMissingRuntimeModuleError(error: unknown, modulePath: string): boolean {
|
|
24
|
+
if (!isRecord(error) || error.code !== "ERR_MODULE_NOT_FOUND") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const message = typeof error.message === "string" ? error.message : "";
|
|
28
|
+
const moduleUrl = pathToFileURL(modulePath).href;
|
|
29
|
+
return message.includes(modulePath) || message.includes(moduleUrl);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolvePackageRootCandidates(): string[] {
|
|
33
|
+
const candidates: string[] = [];
|
|
34
|
+
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
35
|
+
if (typeof envRoot === "string" && envRoot.trim().length > 0) {
|
|
36
|
+
candidates.push(path.resolve(envRoot.trim()));
|
|
37
|
+
}
|
|
38
|
+
const argvEntry = typeof process.argv[1] === "string" ? process.argv[1].trim() : "";
|
|
39
|
+
if (argvEntry.length > 0) {
|
|
40
|
+
const resolvedEntry = path.resolve(argvEntry);
|
|
41
|
+
const entryDir = path.dirname(resolvedEntry);
|
|
42
|
+
candidates.push(path.resolve(entryDir, ".."));
|
|
43
|
+
candidates.push(path.resolve(entryDir, "../.."));
|
|
44
|
+
candidates.push(path.resolve(entryDir, "../../.."));
|
|
45
|
+
}
|
|
46
|
+
return [...new Set(candidates)];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function loadPackageRuntimeModule(): Promise<PackageRuntimeModule> {
|
|
50
|
+
const attempted: string[] = [];
|
|
51
|
+
for (const packageRoot of resolvePackageRootCandidates()) {
|
|
52
|
+
const modulePaths = [
|
|
53
|
+
path.join(packageRoot, ".agents", "pm", "extensions", EXTENSION_NAME, "runtime.js"),
|
|
54
|
+
path.join(packageRoot, "packages", PACKAGE_NAME, "extensions", EXTENSION_NAME, "runtime.js"),
|
|
55
|
+
];
|
|
56
|
+
for (const modulePath of modulePaths) {
|
|
57
|
+
attempted.push(modulePath);
|
|
58
|
+
if (!existsSync(modulePath)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return await import(pathToFileURL(modulePath).href) as PackageRuntimeModule;
|
|
63
|
+
} catch (error: unknown) {
|
|
64
|
+
if (isMissingRuntimeModuleError(error, modulePath)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const localRuntimePath = path.join(CURRENT_EXTENSION_ROOT, "runtime.js");
|
|
73
|
+
attempted.push(localRuntimePath);
|
|
74
|
+
if (existsSync(localRuntimePath)) {
|
|
75
|
+
try {
|
|
76
|
+
return await import(pathToFileURL(localRuntimePath).href) as PackageRuntimeModule;
|
|
77
|
+
} catch (error: unknown) {
|
|
78
|
+
if (!isMissingRuntimeModuleError(error, localRuntimePath)) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Unable to resolve packaged ${DIAGNOSTIC_NAME} extension runtime module. ` +
|
|
86
|
+
`Tried: ${attempted.join(", ")}. Ensure the installed extension includes runtime.js or PM_CLI_PACKAGE_ROOT points to an installed pm package root.`,
|
|
87
|
+
);
|
|
88
|
+
}
|