@unbrained/pm-cli 2026.5.11 → 2026.5.14

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 (171) hide show
  1. package/AGENTS.md +3 -116
  2. package/CHANGELOG.md +18 -0
  3. package/PRD.md +18 -39
  4. package/README.md +8 -5
  5. package/dist/cli/commander-usage.js +27 -0
  6. package/dist/cli/commander-usage.js.map +1 -1
  7. package/dist/cli/commands/activity.js +19 -4
  8. package/dist/cli/commands/activity.js.map +1 -1
  9. package/dist/cli/commands/calendar.js +5 -2
  10. package/dist/cli/commands/calendar.js.map +1 -1
  11. package/dist/cli/commands/contracts.js +63 -19
  12. package/dist/cli/commands/contracts.js.map +1 -1
  13. package/dist/cli/commands/create.js +58 -3
  14. package/dist/cli/commands/create.js.map +1 -1
  15. package/dist/cli/commands/extension.d.ts +14 -3
  16. package/dist/cli/commands/extension.js +481 -95
  17. package/dist/cli/commands/extension.js.map +1 -1
  18. package/dist/cli/commands/index.d.ts +1 -8
  19. package/dist/cli/commands/index.js +1 -8
  20. package/dist/cli/commands/index.js.map +1 -1
  21. package/dist/cli/commands/reindex.d.ts +8 -0
  22. package/dist/cli/commands/reindex.js +96 -23
  23. package/dist/cli/commands/reindex.js.map +1 -1
  24. package/dist/cli/commands/search.js +51 -25
  25. package/dist/cli/commands/search.js.map +1 -1
  26. package/dist/cli/commands/test.js +14 -6
  27. package/dist/cli/commands/test.js.map +1 -1
  28. package/dist/cli/commands/upgrade.d.ts +63 -0
  29. package/dist/cli/commands/upgrade.js +260 -0
  30. package/dist/cli/commands/upgrade.js.map +1 -0
  31. package/dist/cli/guide-topics.js +18 -16
  32. package/dist/cli/guide-topics.js.map +1 -1
  33. package/dist/cli/help-content.js +57 -18
  34. package/dist/cli/help-content.js.map +1 -1
  35. package/dist/cli/main.js +73 -7
  36. package/dist/cli/main.js.map +1 -1
  37. package/dist/cli/register-list-query.js +24 -142
  38. package/dist/cli/register-list-query.js.map +1 -1
  39. package/dist/cli/register-mutation.js +49 -257
  40. package/dist/cli/register-mutation.js.map +1 -1
  41. package/dist/cli/register-operations.js +29 -198
  42. package/dist/cli/register-operations.js.map +1 -1
  43. package/dist/cli/register-setup.js +181 -204
  44. package/dist/cli/register-setup.js.map +1 -1
  45. package/dist/cli/registration-helpers.d.ts +2 -2
  46. package/dist/cli/registration-helpers.js +1 -19
  47. package/dist/cli/registration-helpers.js.map +1 -1
  48. package/dist/core/extensions/loader.js +7 -1
  49. package/dist/core/extensions/loader.js.map +1 -1
  50. package/dist/core/packages/manifest.d.ts +38 -0
  51. package/dist/core/packages/manifest.js +221 -0
  52. package/dist/core/packages/manifest.js.map +1 -0
  53. package/dist/core/search/embedding-batches.d.ts +13 -1
  54. package/dist/core/search/embedding-batches.js +19 -1
  55. package/dist/core/search/embedding-batches.js.map +1 -1
  56. package/dist/core/store/front-matter-cache.d.ts +8 -1
  57. package/dist/core/store/front-matter-cache.js +20 -11
  58. package/dist/core/store/front-matter-cache.js.map +1 -1
  59. package/dist/mcp/server.d.ts +8 -0
  60. package/dist/mcp/server.js +100 -43
  61. package/dist/mcp/server.js.map +1 -1
  62. package/dist/sdk/cli-contracts/commander-mutation-options.d.ts +7 -0
  63. package/dist/sdk/cli-contracts/commander-mutation-options.js +477 -0
  64. package/dist/sdk/cli-contracts/commander-mutation-options.js.map +1 -0
  65. package/dist/sdk/cli-contracts/commander-types.d.ts +21 -0
  66. package/dist/sdk/cli-contracts/commander-types.js +92 -0
  67. package/dist/sdk/cli-contracts/commander-types.js.map +1 -0
  68. package/dist/sdk/cli-contracts.d.ts +22 -32
  69. package/dist/sdk/cli-contracts.js +155 -296
  70. package/dist/sdk/cli-contracts.js.map +1 -1
  71. package/dist/sdk/index.d.ts +2 -0
  72. package/dist/sdk/index.js +2 -0
  73. package/dist/sdk/index.js.map +1 -1
  74. package/dist/sdk/runtime.d.ts +29 -0
  75. package/dist/sdk/runtime.js +28 -0
  76. package/dist/sdk/runtime.js.map +1 -0
  77. package/docs/ARCHITECTURE.md +1 -1
  78. package/docs/COMMANDS.md +17 -1
  79. package/docs/EXTENSIONS.md +169 -61
  80. package/docs/QUICKSTART.md +11 -2
  81. package/docs/README.md +4 -6
  82. package/docs/RELEASING.md +4 -2
  83. package/docs/SDK.md +79 -438
  84. package/package.json +6 -23
  85. package/packages/pm-beads/README.md +10 -0
  86. package/packages/pm-beads/extensions/beads/index.js +113 -0
  87. package/{.agents/pm/extensions/beads/index.js → packages/pm-beads/extensions/beads/index.ts} +42 -20
  88. package/{.agents/pm → packages/pm-beads}/extensions/beads/runtime.js +2 -17
  89. package/{.agents/pm → packages/pm-beads}/extensions/beads/runtime.ts +41 -18
  90. package/packages/pm-beads/package.json +50 -0
  91. package/packages/pm-calendar/README.md +13 -0
  92. package/packages/pm-calendar/extensions/calendar/index.js +56 -0
  93. package/packages/pm-calendar/extensions/calendar/index.ts +62 -0
  94. package/packages/pm-calendar/extensions/calendar/manifest.json +7 -0
  95. package/packages/pm-calendar/extensions/calendar/runtime.js +95 -0
  96. package/packages/pm-calendar/extensions/calendar/runtime.ts +104 -0
  97. package/packages/pm-calendar/package.json +51 -0
  98. package/packages/pm-governance-audit/README.md +23 -0
  99. package/packages/pm-governance-audit/extensions/governance-audit/index.js +117 -0
  100. package/packages/pm-governance-audit/extensions/governance-audit/index.ts +118 -0
  101. package/packages/pm-governance-audit/extensions/governance-audit/manifest.json +7 -0
  102. package/packages/pm-governance-audit/extensions/governance-audit/runtime.js +159 -0
  103. package/packages/pm-governance-audit/extensions/governance-audit/runtime.ts +176 -0
  104. package/packages/pm-governance-audit/package.json +52 -0
  105. package/packages/pm-guide-shell/README.md +23 -0
  106. package/packages/pm-guide-shell/extensions/guide-shell/index.js +76 -0
  107. package/packages/pm-guide-shell/extensions/guide-shell/index.ts +81 -0
  108. package/packages/pm-guide-shell/extensions/guide-shell/manifest.json +7 -0
  109. package/packages/pm-guide-shell/extensions/guide-shell/runtime.js +263 -0
  110. package/packages/pm-guide-shell/extensions/guide-shell/runtime.ts +327 -0
  111. package/packages/pm-guide-shell/package.json +52 -0
  112. package/packages/pm-linked-test-adapters/README.md +24 -0
  113. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/index.js +101 -0
  114. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/index.ts +102 -0
  115. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/manifest.json +7 -0
  116. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/runtime.js +142 -0
  117. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/runtime.ts +173 -0
  118. package/packages/pm-linked-test-adapters/package.json +53 -0
  119. package/packages/pm-search-advanced/README.md +27 -0
  120. package/packages/pm-search-advanced/extensions/search-advanced/index.js +93 -0
  121. package/packages/pm-search-advanced/extensions/search-advanced/index.ts +94 -0
  122. package/packages/pm-search-advanced/extensions/search-advanced/manifest.json +7 -0
  123. package/packages/pm-search-advanced/extensions/search-advanced/runtime.js +120 -0
  124. package/packages/pm-search-advanced/extensions/search-advanced/runtime.ts +144 -0
  125. package/packages/pm-search-advanced/package.json +54 -0
  126. package/packages/pm-templates/README.md +20 -0
  127. package/packages/pm-templates/extensions/templates/index.js +101 -0
  128. package/packages/pm-templates/extensions/templates/index.ts +109 -0
  129. package/packages/pm-templates/extensions/templates/manifest.json +7 -0
  130. package/packages/pm-templates/extensions/templates/runtime.js +226 -0
  131. package/packages/pm-templates/extensions/templates/runtime.ts +283 -0
  132. package/packages/pm-templates/package.json +50 -0
  133. package/packages/pm-todos/README.md +11 -0
  134. package/packages/pm-todos/extensions/todos/index.js +130 -0
  135. package/{.agents/pm/extensions/todos/index.js → packages/pm-todos/extensions/todos/index.ts} +47 -23
  136. package/{.agents/pm → packages/pm-todos}/extensions/todos/runtime.js +3 -18
  137. package/{.agents/pm → packages/pm-todos}/extensions/todos/runtime.ts +42 -20
  138. package/packages/pm-todos/package.json +51 -0
  139. package/plugins/pm-cli-claude/README.md +1 -2
  140. package/plugins/pm-cli-claude/hooks/session-start.mjs +4 -55
  141. package/plugins/pm-cli-claude/scripts/pm-mcp-server.mjs +4 -2
  142. package/plugins/pm-cli-codex/scripts/pm-mcp-server.mjs +4 -2
  143. package/.agents/pm/extensions/.managed-extensions.json +0 -42
  144. package/.agents/skills/HARNESS_COMPATIBILITY.md +0 -45
  145. package/.agents/skills/README.md +0 -21
  146. package/.agents/skills/pm-developer/SKILL.md +0 -73
  147. package/.agents/skills/pm-developer/references/COMMAND_PLAYBOOK.md +0 -48
  148. package/.agents/skills/pm-developer/references/PROMPTS.md +0 -17
  149. package/.agents/skills/pm-extensions/SKILL.md +0 -57
  150. package/.agents/skills/pm-extensions/references/LIFECYCLE.md +0 -40
  151. package/.agents/skills/pm-extensions/references/TROUBLESHOOTING.md +0 -25
  152. package/.agents/skills/pm-sdk/SKILL.md +0 -50
  153. package/.agents/skills/pm-sdk/references/INTEGRATION_CHECKLIST.md +0 -31
  154. package/.agents/skills/pm-sdk/references/PROMPTS.md +0 -13
  155. package/.agents/skills/pm-user/SKILL.md +0 -59
  156. package/.agents/skills/pm-user/references/PROMPTS.md +0 -17
  157. package/.agents/skills/pm-user/references/WORKFLOWS.md +0 -35
  158. package/.pi/README.md +0 -35
  159. package/.pi/agents/pm-triage-agent.md +0 -19
  160. package/.pi/agents/pm-verification-agent.md +0 -21
  161. package/.pi/chains/pm-native-delivery.chain.md +0 -11
  162. package/.pi/extensions/pm-cli/index.js +0 -387
  163. package/.pi/prompts/pm-workflow.md +0 -5
  164. package/.pi/skills/pm-native/SKILL.md +0 -44
  165. package/.pi/skills/pm-release/SKILL.md +0 -35
  166. package/dist/pi/native.d.ts +0 -5
  167. package/dist/pi/native.js +0 -236
  168. package/dist/pi/native.js.map +0 -1
  169. package/docs/PI_PACKAGE.md +0 -141
  170. /package/{.agents/pm → packages/pm-beads}/extensions/beads/manifest.json +0 -0
  171. /package/{.agents/pm → packages/pm-todos}/extensions/todos/manifest.json +0 -0
@@ -0,0 +1,263 @@
1
+ import path from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+
4
+ const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
5
+ let runtimeBundle = null;
6
+ let runtimeBundlePromise = null;
7
+
8
+ async function ensureRuntimeBundle() {
9
+ if (runtimeBundle) {
10
+ return runtimeBundle;
11
+ }
12
+ if (!runtimeBundlePromise) {
13
+ runtimeBundlePromise = loadRuntimeBundle();
14
+ }
15
+ runtimeBundle = await runtimeBundlePromise;
16
+ return runtimeBundle;
17
+ }
18
+
19
+ async function loadRuntimeBundle() {
20
+ const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
21
+ if (typeof envRoot !== "string" || envRoot.trim().length === 0) {
22
+ throw new Error(
23
+ `builtin-guide-shell requires ${PM_PACKAGE_ROOT_ENV} to locate core SDK runtime exports.`,
24
+ );
25
+ }
26
+ const modulePath = path.join(path.resolve(envRoot.trim()), "dist", "sdk", "runtime.js");
27
+ try {
28
+ const sdkLoaded = await import(pathToFileURL(modulePath).href);
29
+ if (
30
+ typeof sdkLoaded.runGuide === "function" &&
31
+ typeof sdkLoaded.resolveGuideOutputFormat === "function" &&
32
+ typeof sdkLoaded.renderGuideMarkdown === "function" &&
33
+ typeof sdkLoaded.runCompletion === "function" &&
34
+ typeof sdkLoaded.pathExists === "function" &&
35
+ typeof sdkLoaded.getSettingsPath === "function" &&
36
+ typeof sdkLoaded.resolvePmRoot === "function" &&
37
+ typeof sdkLoaded.readSettings === "function" &&
38
+ typeof sdkLoaded.resolveItemTypeRegistry === "function" &&
39
+ typeof sdkLoaded.resolveRuntimeStatusRegistry === "function" &&
40
+ typeof sdkLoaded.resolveRuntimeFieldRegistry === "function" &&
41
+ typeof sdkLoaded.listAllFrontMatter === "function" &&
42
+ typeof sdkLoaded.getActiveExtensionRegistrations === "function"
43
+ ) {
44
+ return {
45
+ sdk: sdkLoaded,
46
+ };
47
+ }
48
+ } catch {
49
+ // Fall through to deterministic failure message below.
50
+ }
51
+ throw new Error(
52
+ `builtin-guide-shell failed to load guide/completion SDK runtime exports from ${modulePath}.`,
53
+ );
54
+ }
55
+
56
+ function readStringOption(options, key, aliases = []) {
57
+ const keys = [key, ...aliases];
58
+ for (const candidate of keys) {
59
+ const value = options[candidate];
60
+ if (typeof value === "string" && value.trim().length > 0) {
61
+ return value;
62
+ }
63
+ }
64
+ return undefined;
65
+ }
66
+
67
+ function readBooleanOption(options, key, aliases = []) {
68
+ const keys = [key, ...aliases];
69
+ for (const candidate of keys) {
70
+ const value = options[candidate];
71
+ if (value === undefined) {
72
+ continue;
73
+ }
74
+ if (typeof value === "boolean") {
75
+ return value;
76
+ }
77
+ if (typeof value === "string") {
78
+ const normalized = value.trim().toLowerCase();
79
+ if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
80
+ return true;
81
+ }
82
+ if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
83
+ return false;
84
+ }
85
+ }
86
+ }
87
+ return undefined;
88
+ }
89
+
90
+ function readCsvListOption(options, key, aliases = []) {
91
+ const value = readStringOption(options, key, aliases);
92
+ if (!value) {
93
+ return [];
94
+ }
95
+ return value
96
+ .split(",")
97
+ .map((entry) => entry.trim())
98
+ .filter((entry) => entry.length > 0);
99
+ }
100
+
101
+ function normalizeGuideOptions(args, options) {
102
+ const topicFromArgs = args[0];
103
+ return {
104
+ topic: readStringOption(options, "topic") ?? (typeof topicFromArgs === "string" && topicFromArgs.trim().length > 0 ? topicFromArgs : undefined),
105
+ list: readBooleanOption(options, "list") === true ? true : undefined,
106
+ format: readStringOption(options, "format"),
107
+ depth: readStringOption(options, "depth"),
108
+ };
109
+ }
110
+
111
+ function normalizeCompletionOptions(args, options) {
112
+ const shellFromOptions = readStringOption(options, "shell");
113
+ const shellFromArgs = typeof args[0] === "string" && args[0].trim().length > 0 ? args[0].trim() : undefined;
114
+ return {
115
+ shell: shellFromOptions ?? shellFromArgs ?? "bash",
116
+ itemTypes: readCsvListOption(options, "itemTypes", ["item_types"]),
117
+ tags: readCsvListOption(options, "tags"),
118
+ eagerTags: readBooleanOption(options, "eagerTags", ["eager_tags"]) === true,
119
+ };
120
+ }
121
+
122
+ async function buildCompletionRuntimeConfig(bundle, global) {
123
+ const pmRoot = bundle.sdk.resolvePmRoot(process.cwd(), global.path);
124
+ if (!(await bundle.sdk.pathExists(bundle.sdk.getSettingsPath(pmRoot)))) {
125
+ return {};
126
+ }
127
+ const settings = await bundle.sdk.readSettings(pmRoot);
128
+ const schema = settings.schema;
129
+ const statuses = bundle.sdk.resolveRuntimeStatusRegistry(schema).definitions
130
+ .map((definition) => definition.id)
131
+ .filter((status) => typeof status === "string" && status.trim().length > 0)
132
+ .sort((left, right) => left.localeCompare(right));
133
+ const fieldRegistry = bundle.sdk.resolveRuntimeFieldRegistry(schema);
134
+ const runtimeCommands = ["list", "create", "update", "update-many", "search", "calendar", "context"];
135
+ const commandFlags = {};
136
+ for (const command of runtimeCommands) {
137
+ const definitions = fieldRegistry.command_to_fields.get(command) ?? [];
138
+ const flags = [
139
+ ...new Set(
140
+ definitions
141
+ .map((definition) => definition.cli_flag)
142
+ .filter((value) => typeof value === "string" && value.trim().length > 0)
143
+ .map((value) => `--${value.trim().replaceAll("_", "-")}`),
144
+ ),
145
+ ].sort((left, right) => left.localeCompare(right));
146
+ if (flags.length > 0) {
147
+ commandFlags[command] = flags;
148
+ }
149
+ }
150
+ return {
151
+ statuses: statuses.length > 0 ? statuses : undefined,
152
+ command_flags: Object.keys(commandFlags).length > 0 ? commandFlags : undefined,
153
+ };
154
+ }
155
+
156
+ function readPayloadFormat(payload) {
157
+ if (typeof payload === "object" && payload !== null) {
158
+ const format = payload.format;
159
+ if (format === "json") {
160
+ return "json";
161
+ }
162
+ }
163
+ return "toon";
164
+ }
165
+
166
+ function readPayloadResult(payload) {
167
+ if (typeof payload === "object" && payload !== null && "result" in payload) {
168
+ return payload.result;
169
+ }
170
+ return payload;
171
+ }
172
+
173
+ function collectTagsFromItems(items) {
174
+ const tagSet = new Set();
175
+ for (const item of items) {
176
+ const tags = Array.isArray(item.metadata.tags) ? item.metadata.tags : [];
177
+ for (const tag of tags) {
178
+ if (typeof tag === "string" && tag.trim().length > 0) {
179
+ tagSet.add(tag.trim());
180
+ }
181
+ }
182
+ }
183
+ return [...tagSet].sort((left, right) => left.localeCompare(right));
184
+ }
185
+
186
+ export async function runGuidePackage(args, options, global) {
187
+ const bundle = await ensureRuntimeBundle();
188
+ return bundle.sdk.runGuide(normalizeGuideOptions(args, options), global);
189
+ }
190
+
191
+ export async function runCompletionPackage(args, options, global) {
192
+ const bundle = await ensureRuntimeBundle();
193
+ const normalized = normalizeCompletionOptions(args, options);
194
+ const runtimeConfig = await buildCompletionRuntimeConfig(bundle, global);
195
+ return bundle.sdk.runCompletion(
196
+ normalized.shell,
197
+ normalized.itemTypes,
198
+ normalized.tags,
199
+ normalized.eagerTags,
200
+ runtimeConfig,
201
+ );
202
+ }
203
+
204
+ export async function runCompletionTagsPackage(global) {
205
+ const bundle = await ensureRuntimeBundle();
206
+ const pmRoot = bundle.sdk.resolvePmRoot(process.cwd(), global.path);
207
+ if (!(await bundle.sdk.pathExists(bundle.sdk.getSettingsPath(pmRoot)))) {
208
+ return { tags: [], count: 0 };
209
+ }
210
+ const settings = await bundle.sdk.readSettings(pmRoot);
211
+ const registrations = bundle.sdk.getActiveExtensionRegistrations();
212
+ const typeRegistry = bundle.sdk.resolveItemTypeRegistry(settings, registrations);
213
+ const typeToFolder = Object.fromEntries(
214
+ typeRegistry.definitions.map((definition) => [definition.name, definition.folder]),
215
+ );
216
+ const schema = settings.schema;
217
+ const itemFormat = settings.item_format === "json_markdown" ? "json_markdown" : "toon";
218
+ const items = await bundle.sdk.listAllFrontMatter(pmRoot, itemFormat, typeToFolder, undefined, schema);
219
+ const tags = collectTagsFromItems(items);
220
+ return {
221
+ tags,
222
+ count: tags.length,
223
+ };
224
+ }
225
+
226
+ export function renderGuideShellPackageOutput(context) {
227
+ if (!runtimeBundle) {
228
+ return null;
229
+ }
230
+ const result = readPayloadResult(context.payload);
231
+ if (context.command === "guide") {
232
+ const options = context.options ?? {};
233
+ const global = context.global ?? {};
234
+ const outputFormat = runtimeBundle.sdk.resolveGuideOutputFormat(options, global);
235
+ if (outputFormat === "markdown") {
236
+ return `${runtimeBundle.sdk.renderGuideMarkdown(result)}\n`;
237
+ }
238
+ if (outputFormat === "json" || readPayloadFormat(context.payload) === "json") {
239
+ return `${JSON.stringify(result, null, 2)}\n`;
240
+ }
241
+ return null;
242
+ }
243
+ if (context.command === "completion") {
244
+ if (readPayloadFormat(context.payload) === "json") {
245
+ return `${JSON.stringify(result, null, 2)}\n`;
246
+ }
247
+ if (typeof result === "object" && result !== null && typeof result.script === "string") {
248
+ const script = result.script;
249
+ return script.endsWith("\n") ? script : `${script}\n`;
250
+ }
251
+ return null;
252
+ }
253
+ if (context.command === "completion-tags") {
254
+ if (readPayloadFormat(context.payload) === "json") {
255
+ return `${JSON.stringify(result, null, 2)}\n`;
256
+ }
257
+ const tags = typeof result === "object" && result !== null && Array.isArray(result.tags)
258
+ ? result.tags.filter((entry) => typeof entry === "string")
259
+ : [];
260
+ return `${tags.join(" ")}\n`;
261
+ }
262
+ return null;
263
+ }
@@ -0,0 +1,327 @@
1
+ import path from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ import type { GlobalOptions, ServiceOverrideContext } from "../../../../src/sdk/index.js";
4
+
5
+ const PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
6
+
7
+ interface RuntimeSdkModule {
8
+ runGuide: (options: Record<string, unknown>, global: GlobalOptions) => Promise<unknown>;
9
+ resolveGuideOutputFormat: (options: Record<string, unknown>, global: GlobalOptions) => "markdown" | "toon" | "json";
10
+ renderGuideMarkdown: (result: unknown) => string;
11
+ runCompletion: (
12
+ shell: string,
13
+ itemTypes?: string[],
14
+ tags?: string[],
15
+ eagerTagExpansion?: boolean,
16
+ runtime?: {
17
+ statuses?: string[];
18
+ command_flags?: Partial<Record<"list" | "create" | "update" | "update-many" | "search" | "calendar" | "context", string[]>>;
19
+ },
20
+ ) => {
21
+ shell: string;
22
+ script: string;
23
+ setup_hint: string;
24
+ };
25
+ pathExists: (targetPath: string) => Promise<boolean>;
26
+ getSettingsPath: (pmRoot: string) => string;
27
+ resolvePmRoot: (cwd: string, overridePath?: string) => string;
28
+ readSettings: (pmRoot: string) => Promise<Record<string, unknown>>;
29
+ resolveItemTypeRegistry: (settings: unknown, registrations: unknown) => { definitions: Array<{ name: string; folder: string }> };
30
+ resolveRuntimeStatusRegistry: (schema: unknown) => { definitions: Array<{ id: string }> };
31
+ resolveRuntimeFieldRegistry: (schema: unknown) => {
32
+ command_to_fields: Map<string, Array<{ cli_flag: string }>>;
33
+ };
34
+ listAllFrontMatter: (
35
+ pmRoot: string,
36
+ itemFormat: "toon" | "json_markdown",
37
+ typeToFolder: Record<string, string>,
38
+ status?: unknown,
39
+ schema?: unknown,
40
+ ) => Promise<Array<{ metadata: { tags?: string[] } }>>;
41
+ getActiveExtensionRegistrations: () => unknown;
42
+ }
43
+
44
+ interface RuntimeBundle {
45
+ sdk: RuntimeSdkModule;
46
+ }
47
+
48
+ let runtimeBundle: RuntimeBundle | null = null;
49
+ let runtimeBundlePromise: Promise<RuntimeBundle> | null = null;
50
+
51
+ async function ensureRuntimeBundle(): Promise<RuntimeBundle> {
52
+ if (runtimeBundle) {
53
+ return runtimeBundle;
54
+ }
55
+ if (!runtimeBundlePromise) {
56
+ runtimeBundlePromise = loadRuntimeBundle();
57
+ }
58
+ runtimeBundle = await runtimeBundlePromise;
59
+ return runtimeBundle;
60
+ }
61
+
62
+ async function loadRuntimeBundle(): Promise<RuntimeBundle> {
63
+ const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
64
+ if (typeof envRoot !== "string" || envRoot.trim().length === 0) {
65
+ throw new Error(
66
+ `builtin-guide-shell requires ${PM_PACKAGE_ROOT_ENV} to locate core SDK runtime exports.`,
67
+ );
68
+ }
69
+ const modulePath = path.join(path.resolve(envRoot.trim()), "dist", "sdk", "runtime.js");
70
+ try {
71
+ const sdkLoaded = (await import(pathToFileURL(modulePath).href)) as Partial<RuntimeSdkModule>;
72
+ if (
73
+ typeof sdkLoaded.runGuide === "function" &&
74
+ typeof sdkLoaded.resolveGuideOutputFormat === "function" &&
75
+ typeof sdkLoaded.renderGuideMarkdown === "function" &&
76
+ typeof sdkLoaded.runCompletion === "function" &&
77
+ typeof sdkLoaded.pathExists === "function" &&
78
+ typeof sdkLoaded.getSettingsPath === "function" &&
79
+ typeof sdkLoaded.resolvePmRoot === "function" &&
80
+ typeof sdkLoaded.readSettings === "function" &&
81
+ typeof sdkLoaded.resolveItemTypeRegistry === "function" &&
82
+ typeof sdkLoaded.resolveRuntimeStatusRegistry === "function" &&
83
+ typeof sdkLoaded.resolveRuntimeFieldRegistry === "function" &&
84
+ typeof sdkLoaded.listAllFrontMatter === "function" &&
85
+ typeof sdkLoaded.getActiveExtensionRegistrations === "function"
86
+ ) {
87
+ return {
88
+ sdk: sdkLoaded as RuntimeSdkModule,
89
+ };
90
+ }
91
+ } catch {
92
+ // Fall through to deterministic failure message below.
93
+ }
94
+ throw new Error(
95
+ `builtin-guide-shell failed to load guide/completion SDK runtime exports from ${modulePath}.`,
96
+ );
97
+ }
98
+
99
+ function readStringOption(options: Record<string, unknown>, key: string, aliases: string[] = []): string | undefined {
100
+ const keys = [key, ...aliases];
101
+ for (const candidate of keys) {
102
+ const value = options[candidate];
103
+ if (typeof value === "string" && value.trim().length > 0) {
104
+ return value;
105
+ }
106
+ }
107
+ return undefined;
108
+ }
109
+
110
+ function readBooleanOption(options: Record<string, unknown>, key: string, aliases: string[] = []): boolean | undefined {
111
+ const keys = [key, ...aliases];
112
+ for (const candidate of keys) {
113
+ const value = options[candidate];
114
+ if (value === undefined) {
115
+ continue;
116
+ }
117
+ if (typeof value === "boolean") {
118
+ return value;
119
+ }
120
+ if (typeof value === "string") {
121
+ const normalized = value.trim().toLowerCase();
122
+ if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
123
+ return true;
124
+ }
125
+ if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
126
+ return false;
127
+ }
128
+ }
129
+ }
130
+ return undefined;
131
+ }
132
+
133
+ function readCsvListOption(options: Record<string, unknown>, key: string, aliases: string[] = []): string[] {
134
+ const value = readStringOption(options, key, aliases);
135
+ if (!value) {
136
+ return [];
137
+ }
138
+ return value
139
+ .split(",")
140
+ .map((entry) => entry.trim())
141
+ .filter((entry) => entry.length > 0);
142
+ }
143
+
144
+ function normalizeGuideOptions(args: string[], options: Record<string, unknown>): Record<string, unknown> {
145
+ const topicFromArgs = args[0];
146
+ return {
147
+ topic: readStringOption(options, "topic") ?? (typeof topicFromArgs === "string" && topicFromArgs.trim().length > 0 ? topicFromArgs : undefined),
148
+ list: readBooleanOption(options, "list") === true ? true : undefined,
149
+ format: readStringOption(options, "format"),
150
+ depth: readStringOption(options, "depth"),
151
+ };
152
+ }
153
+
154
+ function normalizeCompletionOptions(args: string[], options: Record<string, unknown>): {
155
+ shell: string;
156
+ itemTypes: string[];
157
+ tags: string[];
158
+ eagerTags: boolean;
159
+ } {
160
+ const shellFromOptions = readStringOption(options, "shell");
161
+ const shellFromArgs = typeof args[0] === "string" && args[0].trim().length > 0 ? args[0].trim() : undefined;
162
+ return {
163
+ shell: shellFromOptions ?? shellFromArgs ?? "bash",
164
+ itemTypes: readCsvListOption(options, "itemTypes", ["item_types"]),
165
+ tags: readCsvListOption(options, "tags"),
166
+ eagerTags: readBooleanOption(options, "eagerTags", ["eager_tags"]) === true,
167
+ };
168
+ }
169
+
170
+ async function buildCompletionRuntimeConfig(
171
+ bundle: RuntimeBundle,
172
+ global: GlobalOptions,
173
+ ): Promise<{
174
+ statuses?: string[];
175
+ command_flags?: Partial<Record<"list" | "create" | "update" | "update-many" | "search" | "calendar" | "context", string[]>>;
176
+ }> {
177
+ const pmRoot = bundle.sdk.resolvePmRoot(process.cwd(), global.path);
178
+ if (!(await bundle.sdk.pathExists(bundle.sdk.getSettingsPath(pmRoot)))) {
179
+ return {};
180
+ }
181
+ const settings = await bundle.sdk.readSettings(pmRoot);
182
+ const schema = (settings as { schema?: unknown }).schema;
183
+ const statuses = bundle.sdk.resolveRuntimeStatusRegistry(schema).definitions
184
+ .map((definition) => definition.id)
185
+ .filter((status) => typeof status === "string" && status.trim().length > 0)
186
+ .sort((left, right) => left.localeCompare(right));
187
+ const fieldRegistry = bundle.sdk.resolveRuntimeFieldRegistry(schema);
188
+ const runtimeCommands = ["list", "create", "update", "update-many", "search", "calendar", "context"] as const;
189
+ const commandFlags: Partial<Record<(typeof runtimeCommands)[number], string[]>> = {};
190
+ for (const command of runtimeCommands) {
191
+ const definitions = fieldRegistry.command_to_fields.get(command) ?? [];
192
+ const flags = [
193
+ ...new Set(
194
+ definitions
195
+ .map((definition) => definition.cli_flag)
196
+ .filter((value): value is string => typeof value === "string" && value.trim().length > 0)
197
+ .map((value) => `--${value.trim().replaceAll("_", "-")}`),
198
+ ),
199
+ ].sort((left, right) => left.localeCompare(right));
200
+ if (flags.length > 0) {
201
+ commandFlags[command] = flags;
202
+ }
203
+ }
204
+ return {
205
+ statuses: statuses.length > 0 ? statuses : undefined,
206
+ command_flags: Object.keys(commandFlags).length > 0 ? commandFlags : undefined,
207
+ };
208
+ }
209
+
210
+ function readPayloadFormat(payload: unknown): "toon" | "json" {
211
+ if (typeof payload === "object" && payload !== null) {
212
+ const format = (payload as { format?: unknown }).format;
213
+ if (format === "json") {
214
+ return "json";
215
+ }
216
+ }
217
+ return "toon";
218
+ }
219
+
220
+ function readPayloadResult(payload: unknown): unknown {
221
+ if (typeof payload === "object" && payload !== null && "result" in payload) {
222
+ return (payload as { result?: unknown }).result;
223
+ }
224
+ return payload;
225
+ }
226
+
227
+ function collectTagsFromItems(items: Array<{ metadata: { tags?: string[] } }>): string[] {
228
+ const tagSet = new Set<string>();
229
+ for (const item of items) {
230
+ const tags = Array.isArray(item.metadata.tags) ? item.metadata.tags : [];
231
+ for (const tag of tags) {
232
+ if (typeof tag === "string" && tag.trim().length > 0) {
233
+ tagSet.add(tag.trim());
234
+ }
235
+ }
236
+ }
237
+ return [...tagSet].sort((left, right) => left.localeCompare(right));
238
+ }
239
+
240
+ export async function runGuidePackage(
241
+ args: string[],
242
+ options: Record<string, unknown>,
243
+ global: GlobalOptions,
244
+ ): Promise<unknown> {
245
+ const bundle = await ensureRuntimeBundle();
246
+ return bundle.sdk.runGuide(normalizeGuideOptions(args, options), global);
247
+ }
248
+
249
+ export async function runCompletionPackage(
250
+ args: string[],
251
+ options: Record<string, unknown>,
252
+ global: GlobalOptions,
253
+ ): Promise<unknown> {
254
+ const bundle = await ensureRuntimeBundle();
255
+ const normalized = normalizeCompletionOptions(args, options);
256
+ const runtimeConfig = await buildCompletionRuntimeConfig(bundle, global);
257
+ return bundle.sdk.runCompletion(
258
+ normalized.shell,
259
+ normalized.itemTypes,
260
+ normalized.tags,
261
+ normalized.eagerTags,
262
+ runtimeConfig,
263
+ );
264
+ }
265
+
266
+ export async function runCompletionTagsPackage(global: GlobalOptions): Promise<{ tags: string[]; count: number }> {
267
+ const bundle = await ensureRuntimeBundle();
268
+ const pmRoot = bundle.sdk.resolvePmRoot(process.cwd(), global.path);
269
+ if (!(await bundle.sdk.pathExists(bundle.sdk.getSettingsPath(pmRoot)))) {
270
+ return { tags: [], count: 0 };
271
+ }
272
+ const settings = await bundle.sdk.readSettings(pmRoot);
273
+ const registrations = bundle.sdk.getActiveExtensionRegistrations();
274
+ const typeRegistry = bundle.sdk.resolveItemTypeRegistry(settings, registrations);
275
+ const typeToFolder = Object.fromEntries(
276
+ typeRegistry.definitions.map((definition) => [definition.name, definition.folder]),
277
+ );
278
+ const schema = (settings as { schema?: unknown }).schema;
279
+ const itemFormat = ((settings as { item_format?: unknown }).item_format === "json_markdown" ? "json_markdown" : "toon") as
280
+ | "toon"
281
+ | "json_markdown";
282
+ const items = await bundle.sdk.listAllFrontMatter(pmRoot, itemFormat, typeToFolder, undefined, schema);
283
+ const tags = collectTagsFromItems(items);
284
+ return {
285
+ tags,
286
+ count: tags.length,
287
+ };
288
+ }
289
+
290
+ export function renderGuideShellPackageOutput(context: ServiceOverrideContext): string | null {
291
+ if (!runtimeBundle) {
292
+ return null;
293
+ }
294
+ const result = readPayloadResult(context.payload);
295
+ if (context.command === "guide") {
296
+ const options = (context.options ?? {}) as Record<string, unknown>;
297
+ const global = (context.global ?? {}) as GlobalOptions;
298
+ const outputFormat = runtimeBundle.sdk.resolveGuideOutputFormat(options, global);
299
+ if (outputFormat === "markdown") {
300
+ return `${runtimeBundle.sdk.renderGuideMarkdown(result)}\n`;
301
+ }
302
+ if (outputFormat === "json" || readPayloadFormat(context.payload) === "json") {
303
+ return `${JSON.stringify(result, null, 2)}\n`;
304
+ }
305
+ return null;
306
+ }
307
+ if (context.command === "completion") {
308
+ if (readPayloadFormat(context.payload) === "json") {
309
+ return `${JSON.stringify(result, null, 2)}\n`;
310
+ }
311
+ if (typeof result === "object" && result !== null && typeof (result as { script?: unknown }).script === "string") {
312
+ const script = (result as { script: string }).script;
313
+ return script.endsWith("\n") ? script : `${script}\n`;
314
+ }
315
+ return null;
316
+ }
317
+ if (context.command === "completion-tags") {
318
+ if (readPayloadFormat(context.payload) === "json") {
319
+ return `${JSON.stringify(result, null, 2)}\n`;
320
+ }
321
+ const tags = typeof result === "object" && result !== null && Array.isArray((result as { tags?: unknown }).tags)
322
+ ? ((result as { tags: unknown[] }).tags.filter((entry): entry is string => typeof entry === "string"))
323
+ : [];
324
+ return `${tags.join(" ")}\n`;
325
+ }
326
+ return null;
327
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@unbrained/pm-package-guide-shell",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "First-party pm package for guide and shell completion workflows.",
7
+ "homepage": "https://github.com/unbraind/pm-cli/tree/main/packages/pm-guide-shell#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/unbraind/pm-cli.git",
11
+ "directory": "packages/pm-guide-shell"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/unbraind/pm-cli/issues"
15
+ },
16
+ "keywords": [
17
+ "pm-package",
18
+ "project-management",
19
+ "guide",
20
+ "completion",
21
+ "shell"
22
+ ],
23
+ "pm": {
24
+ "aliases": [
25
+ "guide-shell"
26
+ ],
27
+ "extensions": [
28
+ "extensions/guide-shell"
29
+ ],
30
+ "catalog": {
31
+ "display_name": "Guide + Shell UX",
32
+ "category": "workflow",
33
+ "summary": "Restore guide documentation and shell completion commands as package-owned UX surfaces.",
34
+ "tags": [
35
+ "guide",
36
+ "completion",
37
+ "shell"
38
+ ],
39
+ "links": {
40
+ "docs": "https://github.com/unbraind/pm-cli/tree/main/packages/pm-guide-shell#readme",
41
+ "repository": "https://github.com/unbraind/pm-cli/tree/main/packages/pm-guide-shell",
42
+ "report": "https://github.com/unbraind/pm-cli/issues"
43
+ }
44
+ },
45
+ "docs": [
46
+ "README.md"
47
+ ],
48
+ "examples": [
49
+ "README.md"
50
+ ]
51
+ }
52
+ }
@@ -0,0 +1,24 @@
1
+ # pm-linked-test-adapters
2
+
3
+ First-party package that restores optional linked-test background run management surfaces in bare-core `pm`.
4
+
5
+ ## Commands
6
+
7
+ - `pm test-runs`
8
+ - `pm test-runs list`
9
+ - `pm test-runs status <runId>`
10
+ - `pm test-runs logs <runId>`
11
+ - `pm test-runs stop <runId>`
12
+ - `pm test-runs resume <runId>`
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pm install linked-test-adapters --project
18
+ ```
19
+
20
+ ## Verify
21
+
22
+ ```bash
23
+ pm test-runs list --json
24
+ ```