@unbrained/pm-cli 2026.5.2 → 2026.5.3-6

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.
Files changed (115) hide show
  1. package/AGENTS.md +8 -1
  2. package/CHANGELOG.md +58 -0
  3. package/README.md +9 -1
  4. package/dist/cli/bootstrap-args.d.ts +18 -0
  5. package/dist/cli/bootstrap-args.js +242 -0
  6. package/dist/cli/bootstrap-args.js.map +1 -0
  7. package/dist/cli/commander-usage.d.ts +17 -0
  8. package/dist/cli/commander-usage.js +178 -0
  9. package/dist/cli/commander-usage.js.map +1 -0
  10. package/dist/cli/commands/activity.js +1 -9
  11. package/dist/cli/commands/activity.js.map +1 -1
  12. package/dist/cli/commands/calendar.js +3 -29
  13. package/dist/cli/commands/calendar.js.map +1 -1
  14. package/dist/cli/commands/comments.js +1 -9
  15. package/dist/cli/commands/comments.js.map +1 -1
  16. package/dist/cli/commands/config.d.ts +21 -3
  17. package/dist/cli/commands/config.js +118 -2
  18. package/dist/cli/commands/config.js.map +1 -1
  19. package/dist/cli/commands/context.d.ts +90 -1
  20. package/dist/cli/commands/context.js +485 -23
  21. package/dist/cli/commands/context.js.map +1 -1
  22. package/dist/cli/commands/dedupe-audit.js +2 -11
  23. package/dist/cli/commands/dedupe-audit.js.map +1 -1
  24. package/dist/cli/commands/history.js +1 -9
  25. package/dist/cli/commands/history.js.map +1 -1
  26. package/dist/cli/commands/learnings.js +1 -9
  27. package/dist/cli/commands/learnings.js.map +1 -1
  28. package/dist/cli/commands/list.js +3 -29
  29. package/dist/cli/commands/list.js.map +1 -1
  30. package/dist/cli/commands/normalize.js +9 -6
  31. package/dist/cli/commands/normalize.js.map +1 -1
  32. package/dist/cli/commands/notes.js +1 -9
  33. package/dist/cli/commands/notes.js.map +1 -1
  34. package/dist/cli/commands/reindex.js +2 -7
  35. package/dist/cli/commands/reindex.js.map +1 -1
  36. package/dist/cli/commands/search.js +4 -35
  37. package/dist/cli/commands/search.js.map +1 -1
  38. package/dist/cli/commands/test-runs.js +1 -11
  39. package/dist/cli/commands/test-runs.js.map +1 -1
  40. package/dist/cli/error-guidance.d.ts +13 -0
  41. package/dist/cli/error-guidance.js +43 -4
  42. package/dist/cli/error-guidance.js.map +1 -1
  43. package/dist/cli/extension-command-help.d.ts +48 -0
  44. package/dist/cli/extension-command-help.js +389 -0
  45. package/dist/cli/extension-command-help.js.map +1 -0
  46. package/dist/cli/help-content.js +9 -3
  47. package/dist/cli/help-content.js.map +1 -1
  48. package/dist/cli/help-json-payload.d.ts +25 -0
  49. package/dist/cli/help-json-payload.js +265 -0
  50. package/dist/cli/help-json-payload.js.map +1 -0
  51. package/dist/cli/main.js +996 -4468
  52. package/dist/cli/main.js.map +1 -1
  53. package/dist/cli/migration-gates.d.ts +22 -0
  54. package/dist/cli/migration-gates.js +146 -0
  55. package/dist/cli/migration-gates.js.map +1 -0
  56. package/dist/cli/register-list-query.d.ts +2 -0
  57. package/dist/cli/register-list-query.js +317 -0
  58. package/dist/cli/register-list-query.js.map +1 -0
  59. package/dist/cli/register-mutation.d.ts +2 -0
  60. package/dist/cli/register-mutation.js +795 -0
  61. package/dist/cli/register-mutation.js.map +1 -0
  62. package/dist/cli/register-operations.d.ts +2 -0
  63. package/dist/cli/register-operations.js +610 -0
  64. package/dist/cli/register-operations.js.map +1 -0
  65. package/dist/cli/register-setup.d.ts +2 -0
  66. package/dist/cli/register-setup.js +334 -0
  67. package/dist/cli/register-setup.js.map +1 -0
  68. package/dist/cli/registration-helpers.d.ts +53 -0
  69. package/dist/cli/registration-helpers.js +669 -0
  70. package/dist/cli/registration-helpers.js.map +1 -0
  71. package/dist/cli/shared-parsers.d.ts +6 -0
  72. package/dist/cli/shared-parsers.js +40 -0
  73. package/dist/cli/shared-parsers.js.map +1 -0
  74. package/dist/core/search/http-client.d.ts +29 -0
  75. package/dist/core/search/http-client.js +64 -0
  76. package/dist/core/search/http-client.js.map +1 -0
  77. package/dist/core/search/providers.d.ts +3 -13
  78. package/dist/core/search/providers.js +19 -69
  79. package/dist/core/search/providers.js.map +1 -1
  80. package/dist/core/search/semantic-defaults.js +2 -7
  81. package/dist/core/search/semantic-defaults.js.map +1 -1
  82. package/dist/core/search/vector-stores.d.ts +3 -13
  83. package/dist/core/search/vector-stores.js +17 -66
  84. package/dist/core/search/vector-stores.js.map +1 -1
  85. package/dist/core/sentry/helpers.d.ts +23 -2
  86. package/dist/core/sentry/helpers.js +101 -3
  87. package/dist/core/sentry/helpers.js.map +1 -1
  88. package/dist/core/sentry/instrument.d.ts +21 -0
  89. package/dist/core/sentry/instrument.js +34 -3
  90. package/dist/core/sentry/instrument.js.map +1 -1
  91. package/dist/core/shared/constants.d.ts +3 -0
  92. package/dist/core/shared/constants.js +58 -1
  93. package/dist/core/shared/constants.js.map +1 -1
  94. package/dist/core/store/front-matter-cache.d.ts +6 -0
  95. package/dist/core/store/front-matter-cache.js +150 -0
  96. package/dist/core/store/front-matter-cache.js.map +1 -0
  97. package/dist/core/store/item-store.js +2 -1
  98. package/dist/core/store/item-store.js.map +1 -1
  99. package/dist/core/store/settings.js +36 -0
  100. package/dist/core/store/settings.js.map +1 -1
  101. package/dist/core/telemetry/observability.d.ts +24 -0
  102. package/dist/core/telemetry/observability.js +185 -0
  103. package/dist/core/telemetry/observability.js.map +1 -0
  104. package/dist/core/telemetry/runtime.d.ts +27 -3
  105. package/dist/core/telemetry/runtime.js +298 -13
  106. package/dist/core/telemetry/runtime.js.map +1 -1
  107. package/dist/sdk/cli-contracts.js +28 -0
  108. package/dist/sdk/cli-contracts.js.map +1 -1
  109. package/dist/types.d.ts +21 -0
  110. package/dist/types.js +11 -0
  111. package/dist/types.js.map +1 -1
  112. package/docs/ARCHITECTURE.md +7 -1
  113. package/docs/COMMANDS.md +11 -1
  114. package/docs/RELEASING.md +56 -29
  115. package/package.json +8 -3
@@ -1,11 +1,11 @@
1
1
  import os from "node:os";
2
2
  import { pathExists } from "../../core/fs/fs-utils.js";
3
- import { parseOptionalNumber } from "../../core/item/parse.js";
4
3
  import { EXIT_CODE } from "../../core/shared/constants.js";
5
4
  import { PmCliError } from "../../core/shared/errors.js";
6
5
  import { getBackgroundTestRunStatus, listBackgroundTestRuns, readBackgroundTestRunLogs, resumeBackgroundTestRun, runBackgroundTestRunWorker, spawnBackgroundTestRunWorker, startBackgroundTestRun, stopBackgroundTestRun, } from "../../core/test/background-runs.js";
7
6
  import { getSettingsPath, resolveGlobalPmRoot, resolvePmRoot } from "../../core/store/paths.js";
8
7
  import { readSettings } from "../../core/store/settings.js";
8
+ import { parseLimit } from "../shared-parsers.js";
9
9
  const BACKGROUND_STATUS_VALUES = ["queued", "running", "passed", "failed", "stopped", "canceled"];
10
10
  const BACKGROUND_STREAM_VALUES = ["stdout", "stderr", "both"];
11
11
  function normalizeStatus(value) {
@@ -28,16 +28,6 @@ function normalizeStream(value) {
28
28
  }
29
29
  throw new PmCliError(`Invalid --stream value "${value}"`, EXIT_CODE.USAGE);
30
30
  }
31
- function parseLimit(value, label) {
32
- if (value === undefined) {
33
- return undefined;
34
- }
35
- const parsed = parseOptionalNumber(value, label);
36
- if (!Number.isFinite(parsed) || parsed < 0) {
37
- throw new PmCliError(`${label} must be a non-negative number`, EXIT_CODE.USAGE);
38
- }
39
- return Math.floor(parsed);
40
- }
41
31
  function resolveWhoamiFallback() {
42
32
  try {
43
33
  const username = os.userInfo().username.trim();
@@ -1 +1 @@
1
- {"version":3,"file":"test-runs.js","sourceRoot":"/","sources":["cli/commands/test-runs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAIL,0BAA0B,EAC1B,sBAAsB,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AM,CAAC,IAAI,CAAC,CAAC;IACzD,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAChF,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC;IACzG,OAAO;QACL,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,OAAO;KACb,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAa,EAAE,MAAqB;IAK1E,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACzD,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,MAAM,0BAA0B,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC;IAC/F,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,SAAS,EAAE,QAAQ,CAAC,SAAS;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import os from \"node:os\";\nimport { pathExists } from \"../../core/fs/fs-utils.js\";\nimport { parseOptionalNumber } from \"../../core/item/parse.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport {\n type BackgroundLogStream,\n type BackgroundTestRunKind,\n type BackgroundTestRunStatus,\n getBackgroundTestRunStatus,\n listBackgroundTestRuns,\n readBackgroundTestRunLogs,\n resumeBackgroundTestRun,\n runBackgroundTestRunWorker,\n spawnBackgroundTestRunWorker,\n startBackgroundTestRun,\n stopBackgroundTestRun,\n} from \"../../core/test/background-runs.js\";\nimport { getSettingsPath, resolveGlobalPmRoot, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\n\nconst BACKGROUND_STATUS_VALUES: readonly BackgroundTestRunStatus[] = [\"queued\", \"running\", \"passed\", \"failed\", \"stopped\", \"canceled\"];\nconst BACKGROUND_STREAM_VALUES: readonly BackgroundLogStream[] = [\"stdout\", \"stderr\", \"both\"];\n\nfunction normalizeStatus(value: string | undefined): BackgroundTestRunStatus | undefined {\n if (value === undefined) {\n return undefined;\n }\n const normalized = value.trim().toLowerCase();\n if ((BACKGROUND_STATUS_VALUES as readonly string[]).includes(normalized)) {\n return normalized as BackgroundTestRunStatus;\n }\n throw new PmCliError(`Invalid --status value \"${value}\"`, EXIT_CODE.USAGE);\n}\n\nfunction normalizeStream(value: string | undefined): BackgroundLogStream {\n if (value === undefined || value.trim().length === 0) {\n return \"stderr\";\n }\n const normalized = value.trim().toLowerCase();\n if ((BACKGROUND_STREAM_VALUES as readonly string[]).includes(normalized)) {\n return normalized as BackgroundLogStream;\n }\n throw new PmCliError(`Invalid --stream value \"${value}\"`, EXIT_CODE.USAGE);\n}\n\nfunction parseLimit(value: string | undefined, label: string): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n const parsed = parseOptionalNumber(value, label);\n if (!Number.isFinite(parsed) || parsed < 0) {\n throw new PmCliError(`${label} must be a non-negative number`, EXIT_CODE.USAGE);\n }\n return Math.floor(parsed);\n}\n\nfunction resolveWhoamiFallback(): string | undefined {\n try {\n const username = os.userInfo().username.trim();\n if (username.length > 0) {\n return username;\n }\n } catch {\n // Fall back to environment-derived attribution.\n }\n return undefined;\n}\n\nfunction resolveRequestedBy(author: string | undefined, fallback: string): string {\n const candidates = [\n author,\n process.env.PM_AUTHOR,\n fallback,\n process.env.USER,\n process.env.LOGNAME,\n process.env.USERNAME,\n resolveWhoamiFallback(),\n ];\n for (const candidate of candidates) {\n if (typeof candidate !== \"string\") {\n continue;\n }\n const trimmed = candidate.trim();\n if (trimmed.length > 0) {\n return trimmed;\n }\n }\n return \"unknown\";\n}\n\nasync function ensureInitialized(pmRoot: string): Promise<void> {\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n}\n\nexport interface StartBackgroundRunCommandOptions {\n kind: BackgroundTestRunKind;\n commandArgs: string[];\n targetId?: string;\n statusFilter?: string;\n author?: string;\n noExtensions?: boolean;\n}\n\nexport interface StartBackgroundRunResult {\n started: boolean;\n duplicate_of?: string;\n run: unknown;\n}\n\nexport async function runStartBackgroundRun(\n options: StartBackgroundRunCommandOptions,\n global: GlobalOptions,\n): Promise<StartBackgroundRunResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n const globalPmRoot = resolveGlobalPmRoot(process.cwd());\n await ensureInitialized(pmRoot);\n const settings = await readSettings(pmRoot);\n const requestedBy = resolveRequestedBy(options.author, settings.author_default);\n const started = await startBackgroundTestRun({\n pmRoot,\n globalPmRoot,\n kind: options.kind,\n commandArgs: options.commandArgs,\n requestedBy,\n targetId: options.targetId,\n statusFilter: options.statusFilter,\n });\n if (!started.started) {\n return {\n started: false,\n duplicate_of: started.duplicate_of,\n run: started.run,\n };\n }\n const spawned = await spawnBackgroundTestRunWorker({\n pmRoot,\n runId: started.run.id,\n noExtensions: options.noExtensions === true,\n });\n return {\n started: true,\n run: spawned,\n };\n}\n\nexport interface TestRunsListCommandOptions {\n status?: string;\n limit?: string;\n}\n\nexport async function runTestRunsList(options: TestRunsListCommandOptions, global: GlobalOptions): Promise<{\n runs: unknown[];\n count: number;\n filters: {\n status?: BackgroundTestRunStatus;\n limit?: number;\n };\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const status = normalizeStatus(options.status);\n const limit = parseLimit(options.limit, \"limit\");\n const runs = await listBackgroundTestRuns(pmRoot, { status, limit });\n return {\n runs,\n count: runs.length,\n filters: {\n status,\n limit,\n },\n };\n}\n\nexport async function runTestRunsStatus(runId: string, global: GlobalOptions): Promise<{\n run: unknown;\n health: unknown;\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const status = await getBackgroundTestRunStatus(pmRoot, runId);\n return {\n run: status.run,\n health: status.health,\n };\n}\n\nexport interface TestRunsLogsCommandOptions {\n stream?: string;\n tail?: string;\n}\n\nexport async function runTestRunsLogs(\n runId: string,\n options: TestRunsLogsCommandOptions,\n global: GlobalOptions,\n): Promise<{\n run: unknown;\n stream: BackgroundLogStream;\n tail: number;\n stdout: string[];\n stderr: string[];\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const stream = normalizeStream(options.stream);\n const tail = parseLimit(options.tail, \"tail\");\n const logs = await readBackgroundTestRunLogs(pmRoot, runId, stream, tail);\n return {\n run: logs.run,\n stream: logs.stream,\n tail: logs.tail,\n stdout: logs.stdout,\n stderr: logs.stderr,\n };\n}\n\nexport interface TestRunsStopCommandOptions {\n force?: boolean;\n}\n\nexport async function runTestRunsStop(\n runId: string,\n options: TestRunsStopCommandOptions,\n global: GlobalOptions,\n): Promise<{\n run: unknown;\n signal_sent: \"SIGTERM\" | \"SIGKILL\" | \"none\";\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const stopped = await stopBackgroundTestRun(pmRoot, runId, options.force === true);\n return {\n run: stopped.run,\n signal_sent: stopped.signal_sent,\n };\n}\n\nexport interface TestRunsResumeCommandOptions {\n author?: string;\n noExtensions?: boolean;\n}\n\nexport async function runTestRunsResume(\n runId: string,\n options: TestRunsResumeCommandOptions,\n global: GlobalOptions,\n): Promise<{\n resumed_from: string;\n run: unknown;\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const settings = await readSettings(pmRoot);\n const requestedBy = resolveRequestedBy(options.author, settings.author_default);\n const resumed = await resumeBackgroundTestRun(pmRoot, runId, requestedBy, options.noExtensions === true);\n return {\n resumed_from: runId,\n run: resumed,\n };\n}\n\nexport async function runTestRunsWorker(runId: string, global: GlobalOptions): Promise<{\n id: string;\n status: BackgroundTestRunStatus;\n exit_code?: number;\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const finished = await runBackgroundTestRunWorker(pmRoot, runId, global.noExtensions === true);\n return {\n id: finished.id,\n status: finished.status,\n exit_code: finished.exit_code,\n };\n}\n"]}
1
+ {"version":3,"file":"test-runs.js","sourceRoot":"/","sources":["cli/commands/test-runs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAIL,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,wBAAwB,GAAuC,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACtI,MAAM,wBAAwB,GAAmC,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AA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J,CAAC","sourcesContent":["import os from \"node:os\";\nimport { pathExists } from \"../../core/fs/fs-utils.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport {\n type BackgroundLogStream,\n type BackgroundTestRunKind,\n type BackgroundTestRunStatus,\n getBackgroundTestRunStatus,\n listBackgroundTestRuns,\n readBackgroundTestRunLogs,\n resumeBackgroundTestRun,\n runBackgroundTestRunWorker,\n spawnBackgroundTestRunWorker,\n startBackgroundTestRun,\n stopBackgroundTestRun,\n} from \"../../core/test/background-runs.js\";\nimport { getSettingsPath, resolveGlobalPmRoot, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { parseLimit } from \"../shared-parsers.js\";\n\nconst BACKGROUND_STATUS_VALUES: readonly BackgroundTestRunStatus[] = [\"queued\", \"running\", \"passed\", \"failed\", \"stopped\", \"canceled\"];\nconst BACKGROUND_STREAM_VALUES: readonly BackgroundLogStream[] = [\"stdout\", \"stderr\", \"both\"];\n\nfunction normalizeStatus(value: string | undefined): BackgroundTestRunStatus | undefined {\n if (value === undefined) {\n return undefined;\n }\n const normalized = value.trim().toLowerCase();\n if ((BACKGROUND_STATUS_VALUES as readonly string[]).includes(normalized)) {\n return normalized as BackgroundTestRunStatus;\n }\n throw new PmCliError(`Invalid --status value \"${value}\"`, EXIT_CODE.USAGE);\n}\n\nfunction normalizeStream(value: string | undefined): BackgroundLogStream {\n if (value === undefined || value.trim().length === 0) {\n return \"stderr\";\n }\n const normalized = value.trim().toLowerCase();\n if ((BACKGROUND_STREAM_VALUES as readonly string[]).includes(normalized)) {\n return normalized as BackgroundLogStream;\n }\n throw new PmCliError(`Invalid --stream value \"${value}\"`, EXIT_CODE.USAGE);\n}\n\nfunction resolveWhoamiFallback(): string | undefined {\n try {\n const username = os.userInfo().username.trim();\n if (username.length > 0) {\n return username;\n }\n } catch {\n // Fall back to environment-derived attribution.\n }\n return undefined;\n}\n\nfunction resolveRequestedBy(author: string | undefined, fallback: string): string {\n const candidates = [\n author,\n process.env.PM_AUTHOR,\n fallback,\n process.env.USER,\n process.env.LOGNAME,\n process.env.USERNAME,\n resolveWhoamiFallback(),\n ];\n for (const candidate of candidates) {\n if (typeof candidate !== \"string\") {\n continue;\n }\n const trimmed = candidate.trim();\n if (trimmed.length > 0) {\n return trimmed;\n }\n }\n return \"unknown\";\n}\n\nasync function ensureInitialized(pmRoot: string): Promise<void> {\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n}\n\nexport interface StartBackgroundRunCommandOptions {\n kind: BackgroundTestRunKind;\n commandArgs: string[];\n targetId?: string;\n statusFilter?: string;\n author?: string;\n noExtensions?: boolean;\n}\n\nexport interface StartBackgroundRunResult {\n started: boolean;\n duplicate_of?: string;\n run: unknown;\n}\n\nexport async function runStartBackgroundRun(\n options: StartBackgroundRunCommandOptions,\n global: GlobalOptions,\n): Promise<StartBackgroundRunResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n const globalPmRoot = resolveGlobalPmRoot(process.cwd());\n await ensureInitialized(pmRoot);\n const settings = await readSettings(pmRoot);\n const requestedBy = resolveRequestedBy(options.author, settings.author_default);\n const started = await startBackgroundTestRun({\n pmRoot,\n globalPmRoot,\n kind: options.kind,\n commandArgs: options.commandArgs,\n requestedBy,\n targetId: options.targetId,\n statusFilter: options.statusFilter,\n });\n if (!started.started) {\n return {\n started: false,\n duplicate_of: started.duplicate_of,\n run: started.run,\n };\n }\n const spawned = await spawnBackgroundTestRunWorker({\n pmRoot,\n runId: started.run.id,\n noExtensions: options.noExtensions === true,\n });\n return {\n started: true,\n run: spawned,\n };\n}\n\nexport interface TestRunsListCommandOptions {\n status?: string;\n limit?: string;\n}\n\nexport async function runTestRunsList(options: TestRunsListCommandOptions, global: GlobalOptions): Promise<{\n runs: unknown[];\n count: number;\n filters: {\n status?: BackgroundTestRunStatus;\n limit?: number;\n };\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const status = normalizeStatus(options.status);\n const limit = parseLimit(options.limit, \"limit\");\n const runs = await listBackgroundTestRuns(pmRoot, { status, limit });\n return {\n runs,\n count: runs.length,\n filters: {\n status,\n limit,\n },\n };\n}\n\nexport async function runTestRunsStatus(runId: string, global: GlobalOptions): Promise<{\n run: unknown;\n health: unknown;\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const status = await getBackgroundTestRunStatus(pmRoot, runId);\n return {\n run: status.run,\n health: status.health,\n };\n}\n\nexport interface TestRunsLogsCommandOptions {\n stream?: string;\n tail?: string;\n}\n\nexport async function runTestRunsLogs(\n runId: string,\n options: TestRunsLogsCommandOptions,\n global: GlobalOptions,\n): Promise<{\n run: unknown;\n stream: BackgroundLogStream;\n tail: number;\n stdout: string[];\n stderr: string[];\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const stream = normalizeStream(options.stream);\n const tail = parseLimit(options.tail, \"tail\");\n const logs = await readBackgroundTestRunLogs(pmRoot, runId, stream, tail);\n return {\n run: logs.run,\n stream: logs.stream,\n tail: logs.tail,\n stdout: logs.stdout,\n stderr: logs.stderr,\n };\n}\n\nexport interface TestRunsStopCommandOptions {\n force?: boolean;\n}\n\nexport async function runTestRunsStop(\n runId: string,\n options: TestRunsStopCommandOptions,\n global: GlobalOptions,\n): Promise<{\n run: unknown;\n signal_sent: \"SIGTERM\" | \"SIGKILL\" | \"none\";\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const stopped = await stopBackgroundTestRun(pmRoot, runId, options.force === true);\n return {\n run: stopped.run,\n signal_sent: stopped.signal_sent,\n };\n}\n\nexport interface TestRunsResumeCommandOptions {\n author?: string;\n noExtensions?: boolean;\n}\n\nexport async function runTestRunsResume(\n runId: string,\n options: TestRunsResumeCommandOptions,\n global: GlobalOptions,\n): Promise<{\n resumed_from: string;\n run: unknown;\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const settings = await readSettings(pmRoot);\n const requestedBy = resolveRequestedBy(options.author, settings.author_default);\n const resumed = await resumeBackgroundTestRun(pmRoot, runId, requestedBy, options.noExtensions === true);\n return {\n resumed_from: runId,\n run: resumed,\n };\n}\n\nexport async function runTestRunsWorker(runId: string, global: GlobalOptions): Promise<{\n id: string;\n status: BackgroundTestRunStatus;\n exit_code?: number;\n}> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n await ensureInitialized(pmRoot);\n const finished = await runBackgroundTestRunWorker(pmRoot, runId, global.noExtensions === true);\n return {\n id: finished.id,\n status: finished.status,\n exit_code: finished.exit_code,\n };\n}\n"]}
@@ -20,14 +20,27 @@ export interface JsonErrorEnvelope {
20
20
  examples?: string[];
21
21
  next_steps?: string[];
22
22
  }
23
+ export interface ErrorClassification {
24
+ type: string;
25
+ code: string;
26
+ title: string;
27
+ detail: string;
28
+ required: string;
29
+ why?: string;
30
+ examples?: string[];
31
+ next_steps?: string[];
32
+ }
23
33
  export interface CommanderGuidanceContext {
24
34
  unknownCommandExamples?: string[];
25
35
  unknownCommandNextSteps?: string[];
26
36
  }
27
37
  export declare function renderGuidanceMessage(message: GuidanceMessage): string;
28
38
  export declare function formatPmCliErrorForDisplay(rawMessage: string, context?: PmCliErrorContext): string;
39
+ export declare function classifyPmCliError(rawMessage: string, context?: PmCliErrorContext): ErrorClassification;
29
40
  export declare function formatPmCliErrorForJson(rawMessage: string, exitCode: number, context?: PmCliErrorContext): JsonErrorEnvelope;
30
41
  export declare function formatCommanderErrorForDisplay(rawMessage: string, commandName: string | undefined, allowedTypes: string, context?: CommanderGuidanceContext): string;
42
+ export declare function classifyCommanderError(rawMessage: string, commandName: string | undefined, allowedTypes: string, context?: CommanderGuidanceContext): ErrorClassification;
31
43
  export declare function formatCommanderErrorForJson(rawMessage: string, commandName: string | undefined, allowedTypes: string, exitCode: number, context?: CommanderGuidanceContext): JsonErrorEnvelope;
32
44
  export declare function formatUnknownErrorForJson(rawMessage: string, exitCode: number): JsonErrorEnvelope;
45
+ export declare function classifyUnknownError(rawMessage: string): ErrorClassification;
33
46
  export {};
@@ -57,6 +57,25 @@ function guidanceToJsonEnvelope(message, exitCode) {
57
57
  }
58
58
  return payload;
59
59
  }
60
+ function guidanceToClassification(message) {
61
+ const payload = {
62
+ type: message.type,
63
+ code: message.code,
64
+ title: message.title,
65
+ detail: message.happened,
66
+ required: message.required,
67
+ };
68
+ if (message.why) {
69
+ payload.why = message.why;
70
+ }
71
+ if (message.examples && message.examples.length > 0) {
72
+ payload.examples = message.examples;
73
+ }
74
+ if (message.nextSteps && message.nextSteps.length > 0) {
75
+ payload.next_steps = message.nextSteps;
76
+ }
77
+ return payload;
78
+ }
60
79
  function normalizeMessage(message) {
61
80
  return message.replace(/\(outputHelp\)/g, "").trim();
62
81
  }
@@ -203,9 +222,17 @@ function buildPmCliErrorGuidance(rawMessage, context) {
203
222
  code: "no_update_fields",
204
223
  title: "No update fields supplied",
205
224
  happened: "The update command was called without any field-changing flags.",
206
- required: "Provide at least one update field such as --status, --priority, --title, --tags, or --message.",
225
+ required: "Provide at least one field-changing flag such as --status, --priority, --title, --tags, --description, or --body. Use --message only to label a real mutation.",
207
226
  why: "pm update mutates existing item fields; no-op invocations are rejected to avoid ambiguous history.",
208
- examples: ['pm update pm-a1b2 --status in_progress --message "Start implementation"'],
227
+ examples: [
228
+ 'pm update pm-a1b2 --status in_progress --message "Start implementation"',
229
+ 'pm update pm-a1b2 --description "Clarified implementation scope" --message "Clarify task intent"',
230
+ 'pm append pm-a1b2 --body "Detailed progress notes" --message "Append progress notes"',
231
+ ],
232
+ nextSteps: [
233
+ "Choose the item field you intend to change, then pair that change with --message for history context.",
234
+ "Use pm comments, pm notes, pm learnings, or pm append when you only need to add narrative context.",
235
+ ],
209
236
  }), rawMessage, context);
210
237
  }
211
238
  if (message.startsWith("Invalid ") || message.includes(" must be ")) {
@@ -325,17 +352,27 @@ function buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, cont
325
352
  export function formatPmCliErrorForDisplay(rawMessage, context) {
326
353
  return renderGuidanceMessage(buildPmCliErrorGuidance(rawMessage, context));
327
354
  }
355
+ export function classifyPmCliError(rawMessage, context) {
356
+ return guidanceToClassification(buildPmCliErrorGuidance(rawMessage, context));
357
+ }
328
358
  export function formatPmCliErrorForJson(rawMessage, exitCode, context) {
329
359
  return guidanceToJsonEnvelope(buildPmCliErrorGuidance(rawMessage, context), exitCode);
330
360
  }
331
361
  export function formatCommanderErrorForDisplay(rawMessage, commandName, allowedTypes, context) {
332
362
  return renderGuidanceMessage(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context));
333
363
  }
364
+ export function classifyCommanderError(rawMessage, commandName, allowedTypes, context) {
365
+ return guidanceToClassification(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context));
366
+ }
334
367
  export function formatCommanderErrorForJson(rawMessage, commandName, allowedTypes, exitCode, context) {
335
368
  return guidanceToJsonEnvelope(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context), exitCode);
336
369
  }
337
370
  export function formatUnknownErrorForJson(rawMessage, exitCode) {
338
- const guidance = makeGuidanceMessage({
371
+ const guidance = buildUnknownErrorGuidance(rawMessage);
372
+ return guidanceToJsonEnvelope(guidance, exitCode);
373
+ }
374
+ function buildUnknownErrorGuidance(rawMessage) {
375
+ return makeGuidanceMessage({
339
376
  code: "unknown_error",
340
377
  title: "Unhandled error",
341
378
  happened: normalizeMessage(rawMessage),
@@ -343,6 +380,8 @@ export function formatUnknownErrorForJson(rawMessage, exitCode) {
343
380
  why: "Unexpected runtime failures can occur from environment or extension-level issues.",
344
381
  examples: ["pm --help", "pm health --json"],
345
382
  });
346
- return guidanceToJsonEnvelope(guidance, exitCode);
383
+ }
384
+ export function classifyUnknownError(rawMessage) {
385
+ return guidanceToClassification(buildUnknownErrorGuidance(rawMessage));
347
386
  }
348
387
  //# sourceMappingURL=error-guidance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-guidance.js","sourceRoot":"/","sources":["cli/error-guidance.ts"],"names":[],"mappings":"AA8BA,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,oBAAoB,IAAI,EAAE,CAAC;AACpC,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAqC;IAChE,OAAO;QACL,GAAG,MAAM;QACT,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,OAAiB;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAwB;IAC5D,MAAM,KAAK,GAAa;QACtB,UAAU,OAAO,CAAC,KAAK,EAAE;QACzB,EAAE;QACF,gBAAgB;QAChB,KAAK,OAAO,CAAC,QAAQ,EAAE;QACvB,EAAE;QACF,mBAAmB;QACnB,KAAK,OAAO,CAAC,QAAQ,EAAE;KACxB,CAAC;IACF,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjC,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACp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UAAkB,EAClB,WAA+B,EAC/B,YAAoB,EACpB,QAAgB,EAChB,OAAkC;IAElC,OAAO,sBAAsB,CAAC,2BAA2B,CAAC,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AACvH,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,UAAkB,EAAE,QAAgB;IAC5E,MAAM,QAAQ,GAAG,mBAAmB,CAAC;QACnC,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,iBAAiB;QACxB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACtC,QAAQ,EAAE,sDAAsD;QAChE,GAAG,EAAE,mFAAmF;QACxF,QAAQ,EAAE,CAAC,WAAW,EAAE,kBAAkB,CAAC;KAC5C,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { PmCliErrorContext } from \"../core/shared/errors.js\";\n\ninterface GuidanceMessage {\n code: string;\n type: string;\n title: string;\n happened: string;\n required: string;\n why?: string;\n examples?: string[];\n nextSteps?: string[];\n}\n\nexport interface JsonErrorEnvelope {\n type: string;\n code: string;\n title: string;\n detail: string;\n required: string;\n exit_code: number;\n why?: string;\n examples?: string[];\n next_steps?: string[];\n}\n\nexport interface CommanderGuidanceContext {\n unknownCommandExamples?: string[];\n unknownCommandNextSteps?: string[];\n}\n\nfunction errorType(code: string): string {\n return `urn:pm-cli:error:${code}`;\n}\n\nfunction makeGuidanceMessage(params: Omit<GuidanceMessage, \"type\">): GuidanceMessage {\n return {\n ...params,\n type: errorType(params.code),\n };\n}\n\nfunction renderList(title: string, entries: string[]): string[] {\n if (entries.length === 0) {\n return [];\n }\n return [title, ...entries.map((entry) => ` - ${entry}`)];\n}\n\nexport function renderGuidanceMessage(message: GuidanceMessage): string {\n const lines: string[] = [\n `Error: ${message.title}`,\n \"\",\n \"What happened:\",\n ` ${message.happened}`,\n \"\",\n \"What is required:\",\n ` ${message.required}`,\n ];\n if (message.why) {\n lines.push(\"\", \"Why:\");\n lines.push(` ${message.why}`);\n }\n if (message.examples && message.examples.length > 0) {\n lines.push(\"\");\n lines.push(...renderList(\"Examples:\", message.examples));\n }\n if (message.nextSteps && message.nextSteps.length > 0) {\n lines.push(\"\");\n lines.push(...renderList(\"Next steps:\", message.nextSteps));\n }\n return lines.join(\"\\n\");\n}\n\nfunction guidanceToJsonEnvelope(message: GuidanceMessage, exitCode: number): JsonErrorEnvelope {\n const payload: JsonErrorEnvelope = {\n type: message.type,\n code: message.code,\n title: message.title,\n detail: message.happened,\n required: message.required,\n exit_code: exitCode,\n };\n if (message.why) {\n payload.why = message.why;\n }\n if (message.examples && message.examples.length > 0) {\n payload.examples = message.examples;\n }\n if (message.nextSteps && message.nextSteps.length > 0) {\n payload.next_steps = message.nextSteps;\n }\n return payload;\n}\n\nfunction normalizeMessage(message: string): string {\n return message.replace(/\\(outputHelp\\)/g, \"\").trim();\n}\n\nfunction normalizeContextList(values: string[] | undefined): string[] | undefined {\n if (!Array.isArray(values)) {\n return undefined;\n }\n const normalized = values.map((value) => value.trim()).filter((value) => value.length > 0);\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction buildFallbackTitleFromMessage(message: string): string | undefined {\n const firstLine = message.split(/\\r?\\n/)[0]?.trim() ?? \"\";\n if (firstLine.length === 0) {\n return undefined;\n }\n if (firstLine.length <= 120) {\n return firstLine;\n }\n return `${firstLine.slice(0, 117)}...`;\n}\n\nfunction applyPmCliErrorContext(\n guidance: GuidanceMessage,\n rawMessage: string,\n context: PmCliErrorContext | undefined,\n): GuidanceMessage {\n if (!context) {\n return guidance;\n }\n const normalizedRawMessage = normalizeMessage(rawMessage);\n const code = typeof context.code === \"string\" && context.code.trim().length > 0 ? context.code.trim() : guidance.code;\n const type = typeof context.type === \"string\" && context.type.trim().length > 0 ? context.type.trim() : errorType(code);\n const examples = normalizeContextList(context.examples) ?? guidance.examples;\n const nextSteps = normalizeContextList(context.nextSteps) ?? guidance.nextSteps;\n const fallbackTitle = guidance.code === \"command_failed\" && context.code ? buildFallbackTitleFromMessage(normalizedRawMessage) : undefined;\n return {\n ...guidance,\n code,\n type,\n title: fallbackTitle ?? guidance.title,\n happened: normalizedRawMessage.length > 0 ? normalizedRawMessage : guidance.happened,\n required: typeof context.required === \"string\" && context.required.trim().length > 0 ? context.required.trim() : guidance.required,\n why: typeof context.why === \"string\" && context.why.trim().length > 0 ? context.why.trim() : guidance.why,\n examples,\n nextSteps,\n };\n}\n\nfunction buildPmCliErrorGuidance(rawMessage: string, context?: PmCliErrorContext): GuidanceMessage {\n const message = normalizeMessage(rawMessage);\n\n const trackerNotInitialized = message.match(/^Tracker is not initialized at (.+)\\. Run pm init first\\.$/);\n if (trackerNotInitialized) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"tracker_not_initialized\",\n title: \"Tracker is not initialized\",\n happened: `pm data path does not contain initialized tracker metadata (${trackerNotInitialized[1]}).`,\n required: \"Initialize tracker storage before running this command.\",\n why: \"Most commands require settings and tracker directories created by pm init.\",\n examples: [\"pm init\", \"pm init acme\"],\n nextSteps: ['Run \"pm init\", then rerun your original command.'],\n }),\n rawMessage,\n context,\n );\n }\n\n const itemNotFound = message.match(/^Item ([^ ]+) not found$/);\n if (itemNotFound) {\n const badId = itemNotFound[1];\n const isPlaceholder = /^(undefined|null|<.*>|\\[.*\\]|{.*}|)$/.test(badId);\n const happened = isPlaceholder\n ? `The item ID \"${badId}\" looks like a placeholder or unresolved variable. Ensure the ID argument is resolved before calling pm.`\n : `No item with id \"${badId}\" exists in the active tracker scope.`;\n const nextSteps = isPlaceholder\n ? [\n \"Check that the variable holding the item ID is defined before passing it to pm.\",\n 'Use \"pm list-open --limit 20\" to find valid IDs.',\n ]\n : [\"Confirm the active --path/PM_PATH scope, then retry with a valid id.\"];\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"item_not_found\",\n title: \"Item ID not found\",\n happened,\n required: \"Use an existing item ID from current tracker data.\",\n why: \"Mutation and read commands operate only on known IDs.\",\n examples: ['pm list-open --limit 20', 'pm search \"<keyword>\" --limit 10'],\n nextSteps,\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.includes(\"is assigned to\") && message.includes(\"Use --force to override\")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"ownership_conflict\",\n title: \"Ownership conflict\",\n happened: message,\n required:\n \"Run as assigned owner, use audit flags for safe non-owner updates, or use --force only for approved override scenarios.\",\n why: \"Ownership checks prevent accidental concurrent mutations on claimed items and protect against conflicting writes.\",\n examples: [\n 'pm update pm-a1b2 --allow-audit-update --description \"...\" --author \"audit-agent\"',\n 'pm update pm-a1b2 --allow-audit-dep-update --dep \"...\" --author \"audit-agent\"',\n 'pm comments pm-a1b2 \"...\" --allow-audit-comment --author \"audit-agent\"',\n 'pm claim pm-a1b2 --author \"codex-agent\"',\n 'pm release pm-a1b2 --allow-audit-release --author \"reviewer\"',\n 'pm update pm-a1b2 --status in_progress --force',\n ],\n nextSteps: [\n \"Use --allow-audit-update for metadata-only non-owner updates (excludes lifecycle/ownership fields).\",\n \"Use --allow-audit-dep-update for dependency-only non-owner additions.\",\n \"Use --allow-audit-comment on comments/notes/learnings for append-only audit entries.\",\n \"Use --force for PM audits and systematic metadata updates performed by leads/maintainers.\",\n \"Use --force when correcting known stale metadata after coordinating ownership changes.\",\n 'For non-terminal reassignment, prefer \"pm claim <ID> --author <you>\" before running other mutations.',\n 'For assignee handoff release workflows, prefer \"pm release <ID> --allow-audit-release --author <you>\" before using --force.',\n ],\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.includes(\"is locked\")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"lock_conflict\",\n title: \"Lock conflict\",\n happened: message,\n required: \"Wait for lock release, or use --force where supported if lock is stale and safe to override.\",\n why: \"Locking protects item files from concurrent write races.\",\n examples: ['pm update pm-a1b2 --status in_progress --force --author \"codex-agent\"'],\n }),\n rawMessage,\n context,\n );\n }\n\n const missingRequiredOption = message.match(/^Missing required option /);\n const missingRequiredOptions = message.match(/^Missing required options /);\n if (missingRequiredOption || missingRequiredOptions) {\n const plural = Boolean(missingRequiredOptions);\n const missingOptionFlag = !plural ? message.replace(/^Missing required option\\s+/, \"\").trim() : null;\n const missingOptionRequired = missingOptionFlag\n ? `Pass ${missingOptionFlag} with a valid value before running the command.`\n : \"Provide the required option for this command invocation.\";\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"missing_required_option\",\n title: plural ? \"Missing required options\" : missingOptionFlag ? `Missing required option ${missingOptionFlag}` : \"Missing required option\",\n happened: message,\n required: plural\n ? \"Provide every required option for this command invocation.\"\n : missingOptionRequired,\n why: \"Required options define command intent and enforce deterministic write contracts.\",\n examples: [\n 'pm create --title \"Task title\" --description \"Task details\" --type Task --create-mode progressive',\n 'pm create --title \"Task title\" --description \"Task details\" --type Task --status open --priority 1 --message \"Create task\" --dep \"id=pm-epic01,kind=parent,author=codex-agent,created_at=now\" --comment \"author=codex-agent,created_at=now,text=Why this task exists.\" --note \"author=codex-agent,created_at=now,text=Initial implementation note.\" --learning \"author=codex-agent,created_at=now,text=Durable lesson placeholder.\" --file \"path=src/example.ts,scope=project\" --test \"command=node scripts/run-tests.mjs test,scope=project,timeout_seconds=240\" --doc \"path=README.md,scope=project\"',\n ],\n nextSteps: [\n 'Run \"pm <command> --help\" to view required and recommended flags.',\n \"For staged triage without placeholder linkage values, use --create-mode progressive.\",\n ],\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.startsWith(\"No update flags provided\")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"no_update_fields\",\n title: \"No update fields supplied\",\n happened: \"The update command was called without any field-changing flags.\",\n required: \"Provide at least one update field such as --status, --priority, --title, --tags, or --message.\",\n why: \"pm update mutates existing item fields; no-op invocations are rejected to avoid ambiguous history.\",\n examples: ['pm update pm-a1b2 --status in_progress --message \"Start implementation\"'],\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.startsWith(\"Invalid \") || message.includes(\" must be \")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"invalid_argument_value\",\n title: \"Invalid argument value\",\n happened: message,\n required: \"Use values that match documented command constraints.\",\n why: \"Validation protects data consistency and deterministic behavior across commands.\",\n examples: [\"pm create --help\", \"pm update --help\", \"pm calendar --help\"],\n nextSteps: [\"Check allowed values in command help, then rerun with corrected input.\"],\n }),\n rawMessage,\n context,\n );\n }\n\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"command_failed\",\n title: \"Command failed\",\n happened: message,\n required: \"Adjust command input or tracker state and retry.\",\n why: \"pm enforces explicit, deterministic contracts for data and command semantics.\",\n examples: [\"pm --help\", \"pm <command> --help\"],\n }),\n rawMessage,\n context,\n );\n}\n\nfunction commandExampleForRequiredOption(commandName: string | undefined, optionFlag: string, allowedTypes: string): string[] {\n if (commandName === \"create\" && optionFlag.startsWith(\"--type\")) {\n const firstAllowed = allowedTypes.split(\"|\")[0] || \"Task\";\n return [\n `pm create --title \"Example title\" --description \"Example description\" --type ${firstAllowed} --status open --priority 1 --message \"Create item\" --create-mode progressive`,\n ];\n }\n if (commandName === \"update\") {\n return ['pm update pm-a1b2 --status in_progress --message \"Start implementation\"'];\n }\n return [`pm ${commandName ?? \"<command>\"} --help`];\n}\n\nfunction buildCommanderErrorGuidance(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n context?: CommanderGuidanceContext,\n): GuidanceMessage {\n const message = normalizeMessage(rawMessage);\n\n const requiredOption = message.match(/required option '([^']+)' not specified/);\n if (requiredOption) {\n const optionFlag = requiredOption[1];\n const isType = optionFlag.startsWith(\"--type\");\n return makeGuidanceMessage({\n code: \"missing_required_option\",\n title: `Missing required option ${optionFlag}`,\n happened: `Commander rejected the command because ${optionFlag} was not provided.`,\n required: `Pass ${optionFlag} with a valid value before running the command.`,\n why: isType\n ? \"--type selects item contract and policy routing, including required/disabled option rules.\"\n : \"Required flags define mandatory command intent and prevent ambiguous execution.\",\n examples: commandExampleForRequiredOption(commandName, optionFlag, allowedTypes),\n nextSteps: isType\n ? [`Allowed type values: ${allowedTypes}`, `Run \"pm ${commandName ?? \"create\"} --help --type <value>\" for type-aware policy details.`]\n : [`Run \"pm ${commandName ?? \"<command>\"} --help\" for required option guidance.`],\n });\n }\n\n const missingArgument = message.match(/missing required argument '([^']+)'/);\n if (missingArgument) {\n const argumentName = missingArgument[1];\n return makeGuidanceMessage({\n code: \"missing_required_argument\",\n title: `Missing required argument ${argumentName}`,\n happened: `Command invocation omitted positional argument ${argumentName}.`,\n required: `Provide ${argumentName} in the expected command position.`,\n why: \"Positional arguments identify the target entity or action context for the command.\",\n examples: [`pm ${commandName ?? \"<command>\"} --help`],\n });\n }\n\n const unknownOption = message.match(/unknown option '([^']+)'/);\n if (unknownOption) {\n const optionName = unknownOption[1];\n if (commandName === \"update\" && (optionName === \"--file\" || optionName === \"--doc\")) {\n return makeGuidanceMessage({\n code: \"unsupported_update_option\",\n title: `Unsupported option ${optionName} for update`,\n happened: `pm update does not accept ${optionName} for linked artifact mutations.`,\n required: \"Use dedicated linked-artifact commands instead of pm update for files/docs changes.\",\n why: \"pm update manages scalar item metadata, while linked files/docs are managed by pm files and pm docs.\",\n examples: [\n 'pm files pm-a1b2 --add \"path=src/cli/main.ts,scope=project,note=implementation surface\"',\n 'pm docs pm-a1b2 --add \"path=README.md,scope=project,note=user-facing contract\"',\n ],\n nextSteps: ['Run \"pm files --help\" and \"pm docs --help\" for add/remove payload formats.'],\n });\n }\n return makeGuidanceMessage({\n code: \"unknown_option\",\n title: `Unknown option ${optionName}`,\n happened: `Commander does not recognize option ${optionName} for this command path.`,\n required: \"Use supported options only, or move option to the correct subcommand.\",\n why: \"Option contracts are command-specific and intentionally validated.\",\n examples: [`pm ${commandName ?? \"<command>\"} --help`],\n });\n }\n\n const unknownCommand = message.match(/unknown command '([^']+)'/);\n if (unknownCommand) {\n const commandToken = unknownCommand[1];\n const runtimeExamples = normalizeContextList(context?.unknownCommandExamples);\n const runtimeNextSteps = normalizeContextList(context?.unknownCommandNextSteps);\n return makeGuidanceMessage({\n code: \"unknown_command\",\n title: `Unknown command ${commandToken}`,\n happened: `pm does not expose command path \"${commandToken}\" in current runtime configuration.`,\n required: \"Use a valid command name or subcommand path.\",\n why: \"Command registry includes core commands plus active extension command handlers.\",\n examples: runtimeExamples ?? [\"pm --help\"],\n nextSteps: runtimeNextSteps ?? [\"Verify spelling and active extensions, then rerun.\"],\n });\n }\n\n return makeGuidanceMessage({\n code: \"invalid_command_usage\",\n title: \"Invalid command usage\",\n happened: message,\n required: \"Use the command with valid arguments and options.\",\n why: \"Commander validates CLI contracts before execution.\",\n examples: [\"pm --help\", `pm ${commandName ?? \"<command>\"} --help`],\n });\n}\n\nexport function formatPmCliErrorForDisplay(rawMessage: string, context?: PmCliErrorContext): string {\n return renderGuidanceMessage(buildPmCliErrorGuidance(rawMessage, context));\n}\n\nexport function formatPmCliErrorForJson(rawMessage: string, exitCode: number, context?: PmCliErrorContext): JsonErrorEnvelope {\n return guidanceToJsonEnvelope(buildPmCliErrorGuidance(rawMessage, context), exitCode);\n}\n\nexport function formatCommanderErrorForDisplay(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n context?: CommanderGuidanceContext,\n): string {\n return renderGuidanceMessage(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context));\n}\n\nexport function formatCommanderErrorForJson(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n exitCode: number,\n context?: CommanderGuidanceContext,\n): JsonErrorEnvelope {\n return guidanceToJsonEnvelope(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context), exitCode);\n}\n\nexport function formatUnknownErrorForJson(rawMessage: string, exitCode: number): JsonErrorEnvelope {\n const guidance = makeGuidanceMessage({\n code: \"unknown_error\",\n title: \"Unhandled error\",\n happened: normalizeMessage(rawMessage),\n required: \"Inspect command input and runtime state, then retry.\",\n why: \"Unexpected runtime failures can occur from environment or extension-level issues.\",\n examples: [\"pm --help\", \"pm health --json\"],\n });\n return guidanceToJsonEnvelope(guidance, exitCode);\n}\n"]}
1
+ {"version":3,"file":"error-guidance.js","sourceRoot":"/","sources":["cli/error-guidance.ts"],"names":[],"mappings":"AAyCA,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,oBAAoB,IAAI,EAAE,CAAC;AACpC,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAqC;IAChE,OAAO;QACL,GAAG,MAAM;QACT,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,OAAiB;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAwB;IAC5D,MAAM,KAAK,GAAa;QACtB,UAAU,OAAO,CAAC,KAAK,EAAE;QACzB,EAAE;QACF,gBAAgB;QAChB,KAAK,OAAO,CAAC,QAAQ,EAAE;QACvB,EAAE;QACF,mBAAmB;QACnB,KAAK,OAAO,CAAC,QAAQ,EAAE;KACxB,CAAC;IACF,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjC,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf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AAE,QAAQ,CAAC,CAAC;AACvH,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,UAAkB,EAAE,QAAgB;IAC5E,MAAM,QAAQ,GAAG,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACvD,OAAO,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,yBAAyB,CAAC,UAAkB;IACnD,OAAO,mBAAmB,CAAC;QACzB,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,iBAAiB;QACxB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACtC,QAAQ,EAAE,sDAAsD;QAChE,GAAG,EAAE,mFAAmF;QACxF,QAAQ,EAAE,CAAC,WAAW,EAAE,kBAAkB,CAAC;KAC5C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAkB;IACrD,OAAO,wBAAwB,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import type { PmCliErrorContext } from \"../core/shared/errors.js\";\n\ninterface GuidanceMessage {\n code: string;\n type: string;\n title: string;\n happened: string;\n required: string;\n why?: string;\n examples?: string[];\n nextSteps?: string[];\n}\n\nexport interface JsonErrorEnvelope {\n type: string;\n code: string;\n title: string;\n detail: string;\n required: string;\n exit_code: number;\n why?: string;\n examples?: string[];\n next_steps?: string[];\n}\n\nexport interface ErrorClassification {\n type: string;\n code: string;\n title: string;\n detail: string;\n required: string;\n why?: string;\n examples?: string[];\n next_steps?: string[];\n}\n\nexport interface CommanderGuidanceContext {\n unknownCommandExamples?: string[];\n unknownCommandNextSteps?: string[];\n}\n\nfunction errorType(code: string): string {\n return `urn:pm-cli:error:${code}`;\n}\n\nfunction makeGuidanceMessage(params: Omit<GuidanceMessage, \"type\">): GuidanceMessage {\n return {\n ...params,\n type: errorType(params.code),\n };\n}\n\nfunction renderList(title: string, entries: string[]): string[] {\n if (entries.length === 0) {\n return [];\n }\n return [title, ...entries.map((entry) => ` - ${entry}`)];\n}\n\nexport function renderGuidanceMessage(message: GuidanceMessage): string {\n const lines: string[] = [\n `Error: ${message.title}`,\n \"\",\n \"What happened:\",\n ` ${message.happened}`,\n \"\",\n \"What is required:\",\n ` ${message.required}`,\n ];\n if (message.why) {\n lines.push(\"\", \"Why:\");\n lines.push(` ${message.why}`);\n }\n if (message.examples && message.examples.length > 0) {\n lines.push(\"\");\n lines.push(...renderList(\"Examples:\", message.examples));\n }\n if (message.nextSteps && message.nextSteps.length > 0) {\n lines.push(\"\");\n lines.push(...renderList(\"Next steps:\", message.nextSteps));\n }\n return lines.join(\"\\n\");\n}\n\nfunction guidanceToJsonEnvelope(message: GuidanceMessage, exitCode: number): JsonErrorEnvelope {\n const payload: JsonErrorEnvelope = {\n type: message.type,\n code: message.code,\n title: message.title,\n detail: message.happened,\n required: message.required,\n exit_code: exitCode,\n };\n if (message.why) {\n payload.why = message.why;\n }\n if (message.examples && message.examples.length > 0) {\n payload.examples = message.examples;\n }\n if (message.nextSteps && message.nextSteps.length > 0) {\n payload.next_steps = message.nextSteps;\n }\n return payload;\n}\n\nfunction guidanceToClassification(message: GuidanceMessage): ErrorClassification {\n const payload: ErrorClassification = {\n type: message.type,\n code: message.code,\n title: message.title,\n detail: message.happened,\n required: message.required,\n };\n if (message.why) {\n payload.why = message.why;\n }\n if (message.examples && message.examples.length > 0) {\n payload.examples = message.examples;\n }\n if (message.nextSteps && message.nextSteps.length > 0) {\n payload.next_steps = message.nextSteps;\n }\n return payload;\n}\n\nfunction normalizeMessage(message: string): string {\n return message.replace(/\\(outputHelp\\)/g, \"\").trim();\n}\n\nfunction normalizeContextList(values: string[] | undefined): string[] | undefined {\n if (!Array.isArray(values)) {\n return undefined;\n }\n const normalized = values.map((value) => value.trim()).filter((value) => value.length > 0);\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction buildFallbackTitleFromMessage(message: string): string | undefined {\n const firstLine = message.split(/\\r?\\n/)[0]?.trim() ?? \"\";\n if (firstLine.length === 0) {\n return undefined;\n }\n if (firstLine.length <= 120) {\n return firstLine;\n }\n return `${firstLine.slice(0, 117)}...`;\n}\n\nfunction applyPmCliErrorContext(\n guidance: GuidanceMessage,\n rawMessage: string,\n context: PmCliErrorContext | undefined,\n): GuidanceMessage {\n if (!context) {\n return guidance;\n }\n const normalizedRawMessage = normalizeMessage(rawMessage);\n const code = typeof context.code === \"string\" && context.code.trim().length > 0 ? context.code.trim() : guidance.code;\n const type = typeof context.type === \"string\" && context.type.trim().length > 0 ? context.type.trim() : errorType(code);\n const examples = normalizeContextList(context.examples) ?? guidance.examples;\n const nextSteps = normalizeContextList(context.nextSteps) ?? guidance.nextSteps;\n const fallbackTitle = guidance.code === \"command_failed\" && context.code ? buildFallbackTitleFromMessage(normalizedRawMessage) : undefined;\n return {\n ...guidance,\n code,\n type,\n title: fallbackTitle ?? guidance.title,\n happened: normalizedRawMessage.length > 0 ? normalizedRawMessage : guidance.happened,\n required: typeof context.required === \"string\" && context.required.trim().length > 0 ? context.required.trim() : guidance.required,\n why: typeof context.why === \"string\" && context.why.trim().length > 0 ? context.why.trim() : guidance.why,\n examples,\n nextSteps,\n };\n}\n\nfunction buildPmCliErrorGuidance(rawMessage: string, context?: PmCliErrorContext): GuidanceMessage {\n const message = normalizeMessage(rawMessage);\n\n const trackerNotInitialized = message.match(/^Tracker is not initialized at (.+)\\. Run pm init first\\.$/);\n if (trackerNotInitialized) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"tracker_not_initialized\",\n title: \"Tracker is not initialized\",\n happened: `pm data path does not contain initialized tracker metadata (${trackerNotInitialized[1]}).`,\n required: \"Initialize tracker storage before running this command.\",\n why: \"Most commands require settings and tracker directories created by pm init.\",\n examples: [\"pm init\", \"pm init acme\"],\n nextSteps: ['Run \"pm init\", then rerun your original command.'],\n }),\n rawMessage,\n context,\n );\n }\n\n const itemNotFound = message.match(/^Item ([^ ]+) not found$/);\n if (itemNotFound) {\n const badId = itemNotFound[1];\n const isPlaceholder = /^(undefined|null|<.*>|\\[.*\\]|{.*}|)$/.test(badId);\n const happened = isPlaceholder\n ? `The item ID \"${badId}\" looks like a placeholder or unresolved variable. Ensure the ID argument is resolved before calling pm.`\n : `No item with id \"${badId}\" exists in the active tracker scope.`;\n const nextSteps = isPlaceholder\n ? [\n \"Check that the variable holding the item ID is defined before passing it to pm.\",\n 'Use \"pm list-open --limit 20\" to find valid IDs.',\n ]\n : [\"Confirm the active --path/PM_PATH scope, then retry with a valid id.\"];\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"item_not_found\",\n title: \"Item ID not found\",\n happened,\n required: \"Use an existing item ID from current tracker data.\",\n why: \"Mutation and read commands operate only on known IDs.\",\n examples: ['pm list-open --limit 20', 'pm search \"<keyword>\" --limit 10'],\n nextSteps,\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.includes(\"is assigned to\") && message.includes(\"Use --force to override\")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"ownership_conflict\",\n title: \"Ownership conflict\",\n happened: message,\n required:\n \"Run as assigned owner, use audit flags for safe non-owner updates, or use --force only for approved override scenarios.\",\n why: \"Ownership checks prevent accidental concurrent mutations on claimed items and protect against conflicting writes.\",\n examples: [\n 'pm update pm-a1b2 --allow-audit-update --description \"...\" --author \"audit-agent\"',\n 'pm update pm-a1b2 --allow-audit-dep-update --dep \"...\" --author \"audit-agent\"',\n 'pm comments pm-a1b2 \"...\" --allow-audit-comment --author \"audit-agent\"',\n 'pm claim pm-a1b2 --author \"codex-agent\"',\n 'pm release pm-a1b2 --allow-audit-release --author \"reviewer\"',\n 'pm update pm-a1b2 --status in_progress --force',\n ],\n nextSteps: [\n \"Use --allow-audit-update for metadata-only non-owner updates (excludes lifecycle/ownership fields).\",\n \"Use --allow-audit-dep-update for dependency-only non-owner additions.\",\n \"Use --allow-audit-comment on comments/notes/learnings for append-only audit entries.\",\n \"Use --force for PM audits and systematic metadata updates performed by leads/maintainers.\",\n \"Use --force when correcting known stale metadata after coordinating ownership changes.\",\n 'For non-terminal reassignment, prefer \"pm claim <ID> --author <you>\" before running other mutations.',\n 'For assignee handoff release workflows, prefer \"pm release <ID> --allow-audit-release --author <you>\" before using --force.',\n ],\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.includes(\"is locked\")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"lock_conflict\",\n title: \"Lock conflict\",\n happened: message,\n required: \"Wait for lock release, or use --force where supported if lock is stale and safe to override.\",\n why: \"Locking protects item files from concurrent write races.\",\n examples: ['pm update pm-a1b2 --status in_progress --force --author \"codex-agent\"'],\n }),\n rawMessage,\n context,\n );\n }\n\n const missingRequiredOption = message.match(/^Missing required option /);\n const missingRequiredOptions = message.match(/^Missing required options /);\n if (missingRequiredOption || missingRequiredOptions) {\n const plural = Boolean(missingRequiredOptions);\n const missingOptionFlag = !plural ? message.replace(/^Missing required option\\s+/, \"\").trim() : null;\n const missingOptionRequired = missingOptionFlag\n ? `Pass ${missingOptionFlag} with a valid value before running the command.`\n : \"Provide the required option for this command invocation.\";\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"missing_required_option\",\n title: plural ? \"Missing required options\" : missingOptionFlag ? `Missing required option ${missingOptionFlag}` : \"Missing required option\",\n happened: message,\n required: plural\n ? \"Provide every required option for this command invocation.\"\n : missingOptionRequired,\n why: \"Required options define command intent and enforce deterministic write contracts.\",\n examples: [\n 'pm create --title \"Task title\" --description \"Task details\" --type Task --create-mode progressive',\n 'pm create --title \"Task title\" --description \"Task details\" --type Task --status open --priority 1 --message \"Create task\" --dep \"id=pm-epic01,kind=parent,author=codex-agent,created_at=now\" --comment \"author=codex-agent,created_at=now,text=Why this task exists.\" --note \"author=codex-agent,created_at=now,text=Initial implementation note.\" --learning \"author=codex-agent,created_at=now,text=Durable lesson placeholder.\" --file \"path=src/example.ts,scope=project\" --test \"command=node scripts/run-tests.mjs test,scope=project,timeout_seconds=240\" --doc \"path=README.md,scope=project\"',\n ],\n nextSteps: [\n 'Run \"pm <command> --help\" to view required and recommended flags.',\n \"For staged triage without placeholder linkage values, use --create-mode progressive.\",\n ],\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.startsWith(\"No update flags provided\")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"no_update_fields\",\n title: \"No update fields supplied\",\n happened: \"The update command was called without any field-changing flags.\",\n required:\n \"Provide at least one field-changing flag such as --status, --priority, --title, --tags, --description, or --body. Use --message only to label a real mutation.\",\n why: \"pm update mutates existing item fields; no-op invocations are rejected to avoid ambiguous history.\",\n examples: [\n 'pm update pm-a1b2 --status in_progress --message \"Start implementation\"',\n 'pm update pm-a1b2 --description \"Clarified implementation scope\" --message \"Clarify task intent\"',\n 'pm append pm-a1b2 --body \"Detailed progress notes\" --message \"Append progress notes\"',\n ],\n nextSteps: [\n \"Choose the item field you intend to change, then pair that change with --message for history context.\",\n \"Use pm comments, pm notes, pm learnings, or pm append when you only need to add narrative context.\",\n ],\n }),\n rawMessage,\n context,\n );\n }\n\n if (message.startsWith(\"Invalid \") || message.includes(\" must be \")) {\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"invalid_argument_value\",\n title: \"Invalid argument value\",\n happened: message,\n required: \"Use values that match documented command constraints.\",\n why: \"Validation protects data consistency and deterministic behavior across commands.\",\n examples: [\"pm create --help\", \"pm update --help\", \"pm calendar --help\"],\n nextSteps: [\"Check allowed values in command help, then rerun with corrected input.\"],\n }),\n rawMessage,\n context,\n );\n }\n\n return applyPmCliErrorContext(\n makeGuidanceMessage({\n code: \"command_failed\",\n title: \"Command failed\",\n happened: message,\n required: \"Adjust command input or tracker state and retry.\",\n why: \"pm enforces explicit, deterministic contracts for data and command semantics.\",\n examples: [\"pm --help\", \"pm <command> --help\"],\n }),\n rawMessage,\n context,\n );\n}\n\nfunction commandExampleForRequiredOption(commandName: string | undefined, optionFlag: string, allowedTypes: string): string[] {\n if (commandName === \"create\" && optionFlag.startsWith(\"--type\")) {\n const firstAllowed = allowedTypes.split(\"|\")[0] || \"Task\";\n return [\n `pm create --title \"Example title\" --description \"Example description\" --type ${firstAllowed} --status open --priority 1 --message \"Create item\" --create-mode progressive`,\n ];\n }\n if (commandName === \"update\") {\n return ['pm update pm-a1b2 --status in_progress --message \"Start implementation\"'];\n }\n return [`pm ${commandName ?? \"<command>\"} --help`];\n}\n\nfunction buildCommanderErrorGuidance(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n context?: CommanderGuidanceContext,\n): GuidanceMessage {\n const message = normalizeMessage(rawMessage);\n\n const requiredOption = message.match(/required option '([^']+)' not specified/);\n if (requiredOption) {\n const optionFlag = requiredOption[1];\n const isType = optionFlag.startsWith(\"--type\");\n return makeGuidanceMessage({\n code: \"missing_required_option\",\n title: `Missing required option ${optionFlag}`,\n happened: `Commander rejected the command because ${optionFlag} was not provided.`,\n required: `Pass ${optionFlag} with a valid value before running the command.`,\n why: isType\n ? \"--type selects item contract and policy routing, including required/disabled option rules.\"\n : \"Required flags define mandatory command intent and prevent ambiguous execution.\",\n examples: commandExampleForRequiredOption(commandName, optionFlag, allowedTypes),\n nextSteps: isType\n ? [`Allowed type values: ${allowedTypes}`, `Run \"pm ${commandName ?? \"create\"} --help --type <value>\" for type-aware policy details.`]\n : [`Run \"pm ${commandName ?? \"<command>\"} --help\" for required option guidance.`],\n });\n }\n\n const missingArgument = message.match(/missing required argument '([^']+)'/);\n if (missingArgument) {\n const argumentName = missingArgument[1];\n return makeGuidanceMessage({\n code: \"missing_required_argument\",\n title: `Missing required argument ${argumentName}`,\n happened: `Command invocation omitted positional argument ${argumentName}.`,\n required: `Provide ${argumentName} in the expected command position.`,\n why: \"Positional arguments identify the target entity or action context for the command.\",\n examples: [`pm ${commandName ?? \"<command>\"} --help`],\n });\n }\n\n const unknownOption = message.match(/unknown option '([^']+)'/);\n if (unknownOption) {\n const optionName = unknownOption[1];\n if (commandName === \"update\" && (optionName === \"--file\" || optionName === \"--doc\")) {\n return makeGuidanceMessage({\n code: \"unsupported_update_option\",\n title: `Unsupported option ${optionName} for update`,\n happened: `pm update does not accept ${optionName} for linked artifact mutations.`,\n required: \"Use dedicated linked-artifact commands instead of pm update for files/docs changes.\",\n why: \"pm update manages scalar item metadata, while linked files/docs are managed by pm files and pm docs.\",\n examples: [\n 'pm files pm-a1b2 --add \"path=src/cli/main.ts,scope=project,note=implementation surface\"',\n 'pm docs pm-a1b2 --add \"path=README.md,scope=project,note=user-facing contract\"',\n ],\n nextSteps: ['Run \"pm files --help\" and \"pm docs --help\" for add/remove payload formats.'],\n });\n }\n return makeGuidanceMessage({\n code: \"unknown_option\",\n title: `Unknown option ${optionName}`,\n happened: `Commander does not recognize option ${optionName} for this command path.`,\n required: \"Use supported options only, or move option to the correct subcommand.\",\n why: \"Option contracts are command-specific and intentionally validated.\",\n examples: [`pm ${commandName ?? \"<command>\"} --help`],\n });\n }\n\n const unknownCommand = message.match(/unknown command '([^']+)'/);\n if (unknownCommand) {\n const commandToken = unknownCommand[1];\n const runtimeExamples = normalizeContextList(context?.unknownCommandExamples);\n const runtimeNextSteps = normalizeContextList(context?.unknownCommandNextSteps);\n return makeGuidanceMessage({\n code: \"unknown_command\",\n title: `Unknown command ${commandToken}`,\n happened: `pm does not expose command path \"${commandToken}\" in current runtime configuration.`,\n required: \"Use a valid command name or subcommand path.\",\n why: \"Command registry includes core commands plus active extension command handlers.\",\n examples: runtimeExamples ?? [\"pm --help\"],\n nextSteps: runtimeNextSteps ?? [\"Verify spelling and active extensions, then rerun.\"],\n });\n }\n\n return makeGuidanceMessage({\n code: \"invalid_command_usage\",\n title: \"Invalid command usage\",\n happened: message,\n required: \"Use the command with valid arguments and options.\",\n why: \"Commander validates CLI contracts before execution.\",\n examples: [\"pm --help\", `pm ${commandName ?? \"<command>\"} --help`],\n });\n}\n\nexport function formatPmCliErrorForDisplay(rawMessage: string, context?: PmCliErrorContext): string {\n return renderGuidanceMessage(buildPmCliErrorGuidance(rawMessage, context));\n}\n\nexport function classifyPmCliError(rawMessage: string, context?: PmCliErrorContext): ErrorClassification {\n return guidanceToClassification(buildPmCliErrorGuidance(rawMessage, context));\n}\n\nexport function formatPmCliErrorForJson(rawMessage: string, exitCode: number, context?: PmCliErrorContext): JsonErrorEnvelope {\n return guidanceToJsonEnvelope(buildPmCliErrorGuidance(rawMessage, context), exitCode);\n}\n\nexport function formatCommanderErrorForDisplay(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n context?: CommanderGuidanceContext,\n): string {\n return renderGuidanceMessage(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context));\n}\n\nexport function classifyCommanderError(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n context?: CommanderGuidanceContext,\n): ErrorClassification {\n return guidanceToClassification(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context));\n}\n\nexport function formatCommanderErrorForJson(\n rawMessage: string,\n commandName: string | undefined,\n allowedTypes: string,\n exitCode: number,\n context?: CommanderGuidanceContext,\n): JsonErrorEnvelope {\n return guidanceToJsonEnvelope(buildCommanderErrorGuidance(rawMessage, commandName, allowedTypes, context), exitCode);\n}\n\nexport function formatUnknownErrorForJson(rawMessage: string, exitCode: number): JsonErrorEnvelope {\n const guidance = buildUnknownErrorGuidance(rawMessage);\n return guidanceToJsonEnvelope(guidance, exitCode);\n}\n\nfunction buildUnknownErrorGuidance(rawMessage: string): GuidanceMessage {\n return makeGuidanceMessage({\n code: \"unknown_error\",\n title: \"Unhandled error\",\n happened: normalizeMessage(rawMessage),\n required: \"Inspect command input and runtime state, then retry.\",\n why: \"Unexpected runtime failures can occur from environment or extension-level issues.\",\n examples: [\"pm --help\", \"pm health --json\"],\n });\n}\n\nexport function classifyUnknownError(rawMessage: string): ErrorClassification {\n return guidanceToClassification(buildUnknownErrorGuidance(rawMessage));\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import { Command } from "commander";
2
+ import type { RegisteredExtensionCommandDefinition, RegisteredExtensionFlagDefinitions } from "../core/extensions/index.js";
3
+ export interface ExtensionCommandArgumentHelpDescriptor {
4
+ name: string;
5
+ required: boolean;
6
+ variadic: boolean;
7
+ description?: string;
8
+ }
9
+ export interface ExtensionCommandHelpDescriptor {
10
+ command: string;
11
+ action: string;
12
+ description?: string;
13
+ intent?: string;
14
+ examples: string[];
15
+ failure_hints: string[];
16
+ arguments: ExtensionCommandArgumentHelpDescriptor[];
17
+ flags: Array<Record<string, unknown>>;
18
+ source?: {
19
+ layer: "global" | "project";
20
+ name: string;
21
+ };
22
+ }
23
+ export interface HelpOptionSummary {
24
+ flags: string;
25
+ long: string | null;
26
+ short: string | null;
27
+ description: string;
28
+ takes_value: boolean;
29
+ value_required: boolean;
30
+ value_name: string | null;
31
+ variadic: boolean;
32
+ required: boolean;
33
+ aliases: string[];
34
+ alias_for: string | null;
35
+ default_value?: unknown;
36
+ }
37
+ export declare function normalizeExtensionCommandPath(commandPath: string): string;
38
+ export declare function collectDynamicExtensionFlagHelpByCommand(registrations: RegisteredExtensionFlagDefinitions[]): Map<string, string>;
39
+ export declare function collectExtensionCommandHelpDescriptors(commandHandlers: string[], commandDefinitions: RegisteredExtensionCommandDefinition[], flagRegistrations: RegisteredExtensionFlagDefinitions[]): Map<string, ExtensionCommandHelpDescriptor>;
40
+ export declare function applyDynamicExtensionArguments(command: Command, descriptor: ExtensionCommandHelpDescriptor): void;
41
+ export declare function applyDynamicExtensionOptions(command: Command, descriptor: ExtensionCommandHelpDescriptor): void;
42
+ export declare function buildDynamicExtensionHelpOptionSummaries(descriptor: ExtensionCommandHelpDescriptor | undefined): HelpOptionSummary[];
43
+ export declare function mergeHelpOptionSummaries(base: HelpOptionSummary[], extension: HelpOptionSummary[]): HelpOptionSummary[];
44
+ export declare function buildDynamicExtensionCommandMetadataHelp(descriptor: ExtensionCommandHelpDescriptor): string | null;
45
+ export declare function commandAliases(command: Command): string[];
46
+ export declare function findDirectChildCommand(parent: Command, name: string): Command | null;
47
+ export declare function findCommandByPath(root: Command, pathParts: string[]): Command | null;
48
+ export declare function ensureCommandPath(root: Command, pathParts: string[]): Command | null;