pm-brief 2026.10.21 → 2026.10.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +243 -2
- package/dist/alternatives.d.ts +45 -0
- package/dist/alternatives.d.ts.map +1 -0
- package/dist/alternatives.js +103 -0
- package/dist/alternatives.js.map +1 -0
- package/dist/disclosure.d.ts +70 -0
- package/dist/disclosure.d.ts.map +1 -0
- package/dist/disclosure.js +227 -0
- package/dist/disclosure.js.map +1 -0
- package/dist/handoff.d.ts +102 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +352 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +116 -57
- package/dist/index.js.map +1 -1
- package/docs/examples/alternatives.md +22 -0
- package/docs/examples/disclosure.md +127 -0
- package/docs/examples/handoff.json +6 -0
- package/manifest.json +1 -1
- package/package.json +12 -6
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { registerDecisionAlternativesCommand } from "./alternatives.js";
|
|
2
|
+
import { registerDisclosureCommand } from "./disclosure.js";
|
|
3
|
+
export { buildDisclosureBrief, renderDisclosureBrief, parseDisclosurePolicy, DisclosureError } from "./disclosure.js";
|
|
4
|
+
export { buildDecisionAlternatives, DecisionAlternativesError } from "./alternatives.js";
|
|
5
|
+
import { registerHandoffCommands } from "./handoff.js";
|
|
6
|
+
export { previewHandoff, createHandoff, acknowledgeHandoff, inspectHandoff, parseHandoffContract, parseHandoffResponse, HandoffError } from "./handoff.js";
|
|
1
7
|
import { spawnSync } from "node:child_process";
|
|
2
8
|
import { writeFileSync } from "node:fs";
|
|
3
9
|
import { fileURLToPath } from "node:url";
|
|
@@ -6,7 +12,7 @@ import { defineExtension } from "@unbrained/pm-cli/sdk/authoring";
|
|
|
6
12
|
import { certifyCompleteListResult, findSimilarItems, inspectCompleteListResult } from "@unbrained/pm-cli/sdk";
|
|
7
13
|
import { findDuplicateClusters, scanStaleInProgressItems, scanStorageIntegrity, scanMutationSecrets, } from "@unbrained/pm-cli/sdk/governance";
|
|
8
14
|
import { listMergeReceipts, findGitWorkspaceRoot } from "@unbrained/pm-cli/sdk/merge";
|
|
9
|
-
import { readSettings, resolveItemTypeRegistry } from "@unbrained/pm-cli/sdk";
|
|
15
|
+
import { readSettings, SETTINGS_DEFAULTS, resolveItemTypeRegistry, resolveRuntimeStatusRegistry, statusIsTerminal, normalizeStatusInput, indexBlockedByIds, resolveItemBlockers, isExternalDependencyReference, isExternalDependencySourceKind, estimatePmOutputTokens, } from "@unbrained/pm-cli/sdk";
|
|
10
16
|
const PM_CLI_ENTRY = fileURLToPath(new URL("./dist/cli.js", import.meta.resolve("@unbrained/pm-cli/package.json")));
|
|
11
17
|
const PM_PATH_OPTION = "--pm-path";
|
|
12
18
|
const SAFE_PM_ID = /^[a-zA-Z0-9._-]+$/;
|
|
@@ -181,13 +187,22 @@ function typeOf(item) {
|
|
|
181
187
|
function titleOf(item) {
|
|
182
188
|
return text(item.title) || "(untitled)";
|
|
183
189
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
const DEFAULT_STATUS_REGISTRY = resolveRuntimeStatusRegistry(SETTINGS_DEFAULTS.schema);
|
|
191
|
+
/** Classify lifecycle state using the workspace registry and SDK alias normalization. */
|
|
192
|
+
function isClosed(item, registry = DEFAULT_STATUS_REGISTRY) {
|
|
193
|
+
return isClosedStatus(statusOf(item), registry);
|
|
194
|
+
}
|
|
195
|
+
/** Apply SDK terminal roles to a status, including configured aliases. */
|
|
196
|
+
function isClosedStatus(status, registry = DEFAULT_STATUS_REGISTRY) {
|
|
197
|
+
return statusIsTerminal(normalizeLifecycleStatus(status, registry), registry);
|
|
198
|
+
}
|
|
199
|
+
/** Preserve legacy done only when the workspace has not assigned it its own role. */
|
|
200
|
+
function normalizeLifecycleStatus(status, registry) {
|
|
201
|
+
return normalizeStatusInput(status, registry) ?? (status.trim().toLowerCase() === "done" ? registry.close_status : status);
|
|
187
202
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return
|
|
203
|
+
/** Resolve workspace lifecycle roles once at a command boundary. */
|
|
204
|
+
async function readStatusRegistry(pmRoot) {
|
|
205
|
+
return resolveRuntimeStatusRegistry((await readSettings(pmRoot)).schema);
|
|
191
206
|
}
|
|
192
207
|
/** Normalize string, array, and object relationship values into item IDs. */
|
|
193
208
|
function parseRelationshipValue(value, fallbackKind) {
|
|
@@ -202,7 +217,7 @@ function parseRelationshipValue(value, fallbackKind) {
|
|
|
202
217
|
const to = text(record.id) || text(record.to) || text(record.target) || text(record.target_id) || text(record.item_id);
|
|
203
218
|
if (!to)
|
|
204
219
|
return [];
|
|
205
|
-
return [{ to, kind: text(record.kind) || text(record.type) || fallbackKind }];
|
|
220
|
+
return [{ to, kind: text(record.kind) || text(record.type) || fallbackKind, ...(text(record.source_kind) ? { source_kind: text(record.source_kind) } : {}) }];
|
|
206
221
|
}
|
|
207
222
|
return [];
|
|
208
223
|
}
|
|
@@ -213,15 +228,15 @@ export function extractRelationships(item) {
|
|
|
213
228
|
...parseRelationshipValue(item.dependencies, "depends_on"),
|
|
214
229
|
...parseRelationshipValue(item.blocked_by, "blocked_by"),
|
|
215
230
|
...parseRelationshipValue(item.blockedBy, "blocked_by"),
|
|
216
|
-
].filter((rel) => rel.to && rel.to !== item.id).map((rel) => ({ from: item.id,
|
|
231
|
+
].filter((rel) => rel.to && (rel.to !== item.id || isExternalRelationship(rel) || isBlockingRelationship(rel) || rel.kind === "blocks")).map((rel) => ({ from: item.id, ...rel }));
|
|
217
232
|
// pm's `update --blocked-by <id>` denormalizes the edge into BOTH item.dependencies
|
|
218
233
|
// (a blocked_by-kind object) AND item.blocked_by (a string), so the same edge is
|
|
219
|
-
// parsed twice.
|
|
220
|
-
//
|
|
221
|
-
//
|
|
234
|
+
// parsed twice. Include provenance in the identity so an external reference
|
|
235
|
+
// never hides a local edge with the same ID. Only duplicate identities collapse;
|
|
236
|
+
// edges stored once retain their context.
|
|
222
237
|
const seen = new Set();
|
|
223
238
|
return rels.filter((rel) => {
|
|
224
|
-
const key = JSON.stringify([rel.from, rel.to, rel.kind]);
|
|
239
|
+
const key = JSON.stringify([rel.from, rel.to, rel.kind, isExternalRelationship(rel)]);
|
|
225
240
|
if (seen.has(key))
|
|
226
241
|
return false;
|
|
227
242
|
seen.add(key);
|
|
@@ -229,7 +244,8 @@ export function extractRelationships(item) {
|
|
|
229
244
|
});
|
|
230
245
|
}
|
|
231
246
|
function estimateTokens(value) {
|
|
232
|
-
|
|
247
|
+
// Delta/divergence retain the stricter JSON-string bound, including escaping.
|
|
248
|
+
return Math.max(1, estimatePmOutputTokens(Buffer.byteLength(JSON.stringify(value), "utf8")));
|
|
233
249
|
}
|
|
234
250
|
function itemUpdatedAt(item) {
|
|
235
251
|
return text(item.updated_at) || text(item.created_at);
|
|
@@ -268,8 +284,39 @@ function uniqueStrings(values) {
|
|
|
268
284
|
function isBlockingRelationship(rel) {
|
|
269
285
|
return rel.kind === "blocked_by" || rel.kind === "depends_on";
|
|
270
286
|
}
|
|
271
|
-
|
|
272
|
-
|
|
287
|
+
/** Keep external targets distinct from local IDs in every relationship projection. */
|
|
288
|
+
function isExternalRelationship(rel) {
|
|
289
|
+
return rel.external === true || isExternalDependencyReference(rel.to) || isExternalDependencySourceKind(rel.source_kind);
|
|
290
|
+
}
|
|
291
|
+
/** Adapt legacy relationship aliases to the SDK, then retain canonical blocker orientation and unresolved targets. */
|
|
292
|
+
function blockerRelationships(items, registry = DEFAULT_STATUS_REGISTRY) {
|
|
293
|
+
const corpus = items.map((item) => ({
|
|
294
|
+
id: item.id, title: titleOf(item), description: "", type: typeOf(item),
|
|
295
|
+
status: normalizeLifecycleStatus(statusOf(item), registry), priority: 2, tags: [], created_at: "", updated_at: itemUpdatedAt(item),
|
|
296
|
+
dependencies: extractRelationships(item).map((rel) => ({
|
|
297
|
+
id: rel.to, kind: rel.kind === "depends_on" ? "blocked_by" : rel.kind, source_kind: rel.source_kind,
|
|
298
|
+
})),
|
|
299
|
+
}));
|
|
300
|
+
const byId = new Map(corpus.map((item) => [item.id.trim().toLowerCase(), item]));
|
|
301
|
+
// The pinned SDK reverse index drops provenance. Only local reverse edges
|
|
302
|
+
// belong in that index; direct blockers retain their original metadata below.
|
|
303
|
+
const blockers = indexBlockedByIds(corpus.map((item) => ({ ...item,
|
|
304
|
+
dependencies: item.dependencies.filter((dep) => dep.kind === "blocks" &&
|
|
305
|
+
!isExternalRelationship({ to: dep.id, source_kind: dep.source_kind })),
|
|
306
|
+
})));
|
|
307
|
+
return corpus.flatMap((item) => {
|
|
308
|
+
const dependencies = [...item.dependencies, ...(blockers.get(item.id.trim().toLowerCase()) ?? []).map((id) => ({ id, kind: "blocked_by", source_kind: undefined }))];
|
|
309
|
+
// Resolve namespaces independently: the pinned SDK otherwise marks both
|
|
310
|
+
// local and external references external when they share a target ID.
|
|
311
|
+
return [false, true].flatMap((external) => resolveItemBlockers({ updated_at: item.updated_at,
|
|
312
|
+
dependencies: dependencies.filter((dep) => isExternalRelationship({ to: dep.id, source_kind: dep.source_kind }) === external),
|
|
313
|
+
}, byId, registry).filter((blocker) => !blocker.resolved).map((blocker) => ({
|
|
314
|
+
from: item.id, to: blocker.id, kind: "blocked_by", external: blocker.external,
|
|
315
|
+
})));
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function activeItemIds(items, registry = DEFAULT_STATUS_REGISTRY) {
|
|
319
|
+
return new Set(items.filter((item) => !isClosed(item, registry)).map((item) => item.id));
|
|
273
320
|
}
|
|
274
321
|
/** Weight approaching deadlines in the next-work ranking against the supplied clock. */
|
|
275
322
|
function deadlineScore(item, now) {
|
|
@@ -296,9 +343,9 @@ function rankItem(item, rels, activeIds, now) {
|
|
|
296
343
|
const priorityScore = Math.max(0, 100 - priority * 15);
|
|
297
344
|
score += priorityScore;
|
|
298
345
|
reasons.push(`priority:${priority}`);
|
|
299
|
-
const deps = activeDependencyCount(item, rels
|
|
346
|
+
const deps = activeDependencyCount(item, rels);
|
|
300
347
|
const fanout = activeDependentCount(item, rels, activeIds);
|
|
301
|
-
const blocked = deps > 0
|
|
348
|
+
const blocked = deps > 0;
|
|
302
349
|
if (blocked) {
|
|
303
350
|
score -= 80;
|
|
304
351
|
reasons.push(`blocked_by_active_dependency:${deps}`);
|
|
@@ -345,8 +392,9 @@ function rankItem(item, rels, activeIds, now) {
|
|
|
345
392
|
}
|
|
346
393
|
/** Project ranked tracker metadata into the compact agent-facing brief item. */
|
|
347
394
|
function toBriefItem(item, rels, allItems, now, activeIds, rankOverride) {
|
|
348
|
-
const
|
|
349
|
-
const
|
|
395
|
+
const contextRelationships = [...allItems.flatMap(extractRelationships).map((rel) => rel.kind === "blocks" && !isExternalRelationship(rel) ? { ...rel, from: rel.to, to: rel.from, kind: "blocked_by" } : rel), ...rels];
|
|
396
|
+
const dependencyIds = uniqueStrings(contextRelationships.filter((rel) => rel.from === item.id).map((rel) => rel.to));
|
|
397
|
+
const dependentIds = uniqueStrings(contextRelationships.filter((rel) => rel.to === item.id && !isExternalRelationship(rel)).map((rel) => rel.from));
|
|
350
398
|
const stale = ageDays(item, now);
|
|
351
399
|
const requiredContext = uniqueStrings([
|
|
352
400
|
...dependencyIds.map((id) => `dependency:${id}`),
|
|
@@ -414,21 +462,21 @@ function scoreBreakdown(item, rels, activeIds, now, rank = rankItem(item, rels,
|
|
|
414
462
|
deadline,
|
|
415
463
|
};
|
|
416
464
|
}
|
|
417
|
-
function activeDependencyCount(item, rels
|
|
418
|
-
return uniqueStrings(rels.filter((rel) => rel.from === item.id && isBlockingRelationship(rel)
|
|
465
|
+
function activeDependencyCount(item, rels) {
|
|
466
|
+
return uniqueStrings(rels.filter((rel) => rel.from === item.id && isBlockingRelationship(rel)).map((rel) => JSON.stringify([rel.to, isExternalRelationship(rel)]))).length;
|
|
419
467
|
}
|
|
420
468
|
function activeDependentCount(item, rels, activeIds) {
|
|
421
|
-
return uniqueStrings(rels.filter((rel) => rel.to === item.id && isBlockingRelationship(rel) && activeIds.has(rel.from)).map((rel) => rel.from)).length;
|
|
469
|
+
return uniqueStrings(rels.filter((rel) => rel.to === item.id && !isExternalRelationship(rel) && isBlockingRelationship(rel) && activeIds.has(rel.from)).map((rel) => rel.from)).length;
|
|
422
470
|
}
|
|
423
471
|
/** Keep active work matching the requested assignee before ranking it. */
|
|
424
472
|
function filterCandidates(items, options) {
|
|
425
473
|
return items
|
|
426
|
-
.filter((item) => !isClosed(item))
|
|
474
|
+
.filter((item) => !isClosed(item, options.statusRegistry))
|
|
427
475
|
.filter((item) => !options.assignee || text(item.assignee) === options.assignee)
|
|
428
476
|
.filter((item) => !options.statuses?.length || options.statuses.includes(statusOf(item)));
|
|
429
477
|
}
|
|
430
478
|
/** Rank eligible work deterministically, respecting explicit dependency ordering. */
|
|
431
|
-
function rankCandidates(items, options, now, rels, activeIds = activeItemIds(items)) {
|
|
479
|
+
function rankCandidates(items, options, now, rels, activeIds = activeItemIds(items, options.statusRegistry)) {
|
|
432
480
|
const candidates = filterCandidates(items, options);
|
|
433
481
|
// When `pm next` supplied a canonical order, it is the authoritative ranking
|
|
434
482
|
// so `brief next` agrees with `pm next`. Unranked candidates fall after ranked
|
|
@@ -467,13 +515,13 @@ function rankCandidates(items, options, now, rels, activeIds = activeItemIds(ite
|
|
|
467
515
|
return b.activeDependents - a.activeDependents;
|
|
468
516
|
}
|
|
469
517
|
return b.score.total - a.score.total || itemUpdatedAt(b.item).localeCompare(itemUpdatedAt(a.item)) || a.item.id.localeCompare(b.item.id);
|
|
470
|
-
});
|
|
518
|
+
}).filter((candidate) => !candidate.rank.blocked);
|
|
471
519
|
}
|
|
472
520
|
/** Select the requested number of ranked work items from the full tracker corpus. */
|
|
473
521
|
export function selectNextItems(items, options = {}) {
|
|
474
522
|
const now = new Date(options.generatedAt ?? Date.now());
|
|
475
|
-
const rels = items.
|
|
476
|
-
const activeIds = activeItemIds(items);
|
|
523
|
+
const rels = blockerRelationships(items, options.statusRegistry);
|
|
524
|
+
const activeIds = activeItemIds(items, options.statusRegistry);
|
|
477
525
|
return rankCandidates(items, options, now, rels, activeIds)
|
|
478
526
|
.slice(0, options.nextCount ?? 5)
|
|
479
527
|
.map((candidate) => toBriefItem(candidate.item, rels, items, now, activeIds, candidate.rank));
|
|
@@ -481,8 +529,8 @@ export function selectNextItems(items, options = {}) {
|
|
|
481
529
|
/** Pair each selected work item with its ranking evidence and active dependency counts. */
|
|
482
530
|
export function explainNextItems(items, options = {}) {
|
|
483
531
|
const now = new Date(options.generatedAt ?? Date.now());
|
|
484
|
-
const rels = items.
|
|
485
|
-
const activeIds = activeItemIds(items);
|
|
532
|
+
const rels = blockerRelationships(items, options.statusRegistry);
|
|
533
|
+
const activeIds = activeItemIds(items, options.statusRegistry);
|
|
486
534
|
return rankCandidates(items, options, now, rels, activeIds)
|
|
487
535
|
.slice(0, options.nextCount ?? 5)
|
|
488
536
|
.map((candidate, index) => ({
|
|
@@ -498,7 +546,7 @@ export function detectStaleContext(items, options = {}) {
|
|
|
498
546
|
const now = new Date(options.generatedAt ?? Date.now());
|
|
499
547
|
const staleDays = options.staleDays ?? 7;
|
|
500
548
|
return items
|
|
501
|
-
.filter((item) => !isClosed(item))
|
|
549
|
+
.filter((item) => !isClosed(item, options.statusRegistry))
|
|
502
550
|
.map((item) => ({ item, days: ageDays(item, now) }))
|
|
503
551
|
.filter(({ days }) => days >= staleDays)
|
|
504
552
|
.sort((a, b) => b.days - a.days || a.item.id.localeCompare(b.item.id))
|
|
@@ -539,7 +587,7 @@ export function summarizeMomentum(items, options = {}) {
|
|
|
539
587
|
const windowDays = Math.max(0, options.completedDays ?? 7);
|
|
540
588
|
const cutoff = now.getTime() - windowDays * 86_400_000;
|
|
541
589
|
const closed = items
|
|
542
|
-
.filter((item) => isClosed(item))
|
|
590
|
+
.filter((item) => isClosed(item, options.statusRegistry))
|
|
543
591
|
.map((item) => {
|
|
544
592
|
const closedRaw = itemClosedAt(item);
|
|
545
593
|
return { item, closedRaw, closedTime: Date.parse(closedRaw) };
|
|
@@ -574,8 +622,8 @@ export function summarizeMomentum(items, options = {}) {
|
|
|
574
622
|
export function summarizeRisks(items, options = {}) {
|
|
575
623
|
const now = new Date(options.generatedAt ?? Date.now());
|
|
576
624
|
const risks = [];
|
|
577
|
-
const rels = items.
|
|
578
|
-
for (const item of items.filter((candidate) => !isClosed(candidate))) {
|
|
625
|
+
const rels = blockerRelationships(items, options.statusRegistry);
|
|
626
|
+
for (const item of items.filter((candidate) => !isClosed(candidate, options.statusRegistry))) {
|
|
579
627
|
if (rels.some((rel) => rel.from === item.id && (rel.kind === "blocked_by" || rel.kind === "depends_on"))) {
|
|
580
628
|
risks.push({ itemId: item.id, severity: "high", reason: "blocked by visible dependency" });
|
|
581
629
|
}
|
|
@@ -611,7 +659,7 @@ function selectedFocus(items, options) {
|
|
|
611
659
|
const keep = (item, explicitId = false) => {
|
|
612
660
|
if (seenIds.has(item.id))
|
|
613
661
|
return;
|
|
614
|
-
if (options.includeClosed || !isClosed(item)) {
|
|
662
|
+
if (options.includeClosed || !isClosed(item, options.statusRegistry)) {
|
|
615
663
|
seenIds.add(item.id);
|
|
616
664
|
selected.push(item);
|
|
617
665
|
}
|
|
@@ -667,7 +715,7 @@ function buildInsights(items, options, focusSelection, next) {
|
|
|
667
715
|
suggestion: "pm brief --include-closed --format markdown",
|
|
668
716
|
});
|
|
669
717
|
}
|
|
670
|
-
const openItems = items.filter((item) => !isClosed(item));
|
|
718
|
+
const openItems = items.filter((item) => !isClosed(item, options.statusRegistry));
|
|
671
719
|
const candidates = filterCandidates(items, options);
|
|
672
720
|
if (next.length === 0) {
|
|
673
721
|
if (openItems.length === 0) {
|
|
@@ -1101,14 +1149,14 @@ function renderBriefContent(brief, format) {
|
|
|
1101
1149
|
/**
|
|
1102
1150
|
* Settle the estimate's own digit count before measuring the complete rendering.
|
|
1103
1151
|
* Increasing from zero reaches a fixed point after at most the number of digits
|
|
1104
|
-
* in
|
|
1152
|
+
* in the rendered UTF-8 byte count; disclosure can never create a silent overrun.
|
|
1105
1153
|
*/
|
|
1106
1154
|
function measureRenderedBrief(brief, format) {
|
|
1107
1155
|
const measured = { ...brief, budget: { ...brief.budget, estimatedTokens: 0 } };
|
|
1108
|
-
let estimate =
|
|
1156
|
+
let estimate = estimatePmOutputTokens(Buffer.byteLength(renderBriefContent(measured, format), "utf8"));
|
|
1109
1157
|
while (estimate !== measured.budget.estimatedTokens) {
|
|
1110
1158
|
measured.budget.estimatedTokens = estimate;
|
|
1111
|
-
estimate =
|
|
1159
|
+
estimate = estimatePmOutputTokens(Buffer.byteLength(renderBriefContent(measured, format), "utf8"));
|
|
1112
1160
|
}
|
|
1113
1161
|
return measured;
|
|
1114
1162
|
}
|
|
@@ -1238,8 +1286,8 @@ function compactToBudget(brief, format) {
|
|
|
1238
1286
|
export function buildBrief(items, options = {}) {
|
|
1239
1287
|
const generatedAt = options.generatedAt ?? new Date().toISOString();
|
|
1240
1288
|
const now = new Date(generatedAt);
|
|
1241
|
-
const rels = items.
|
|
1242
|
-
const activeIds = activeItemIds(items);
|
|
1289
|
+
const rels = blockerRelationships(items, options.statusRegistry);
|
|
1290
|
+
const activeIds = activeItemIds(items, options.statusRegistry);
|
|
1243
1291
|
const focusSelection = selectedFocus(items, options);
|
|
1244
1292
|
const focus = focusSelection.items.map((item) => toBriefItem(item, rels, items, now, activeIds));
|
|
1245
1293
|
const next = selectNextItems(items, options);
|
|
@@ -1251,11 +1299,11 @@ export function buildBrief(items, options = {}) {
|
|
|
1251
1299
|
const blockers = rels
|
|
1252
1300
|
.filter((rel) => rel.kind === "blocked_by" || rel.kind === "depends_on")
|
|
1253
1301
|
.map((rel) => {
|
|
1254
|
-
const blocker = items.find((item) => item.id === rel.to);
|
|
1302
|
+
const blocker = rel.external ? undefined : items.find((item) => item.id === rel.to);
|
|
1255
1303
|
return { itemId: rel.from, blockedBy: rel.to, kind: rel.kind, title: blocker ? titleOf(blocker) : undefined, status: blocker ? statusOf(blocker) : undefined };
|
|
1256
1304
|
});
|
|
1257
1305
|
const decisionsNeeded = items
|
|
1258
|
-
.filter((item) => !isClosed(item) && typeOf(item).toLowerCase() === "decision")
|
|
1306
|
+
.filter((item) => !isClosed(item, options.statusRegistry) && typeOf(item).toLowerCase() === "decision")
|
|
1259
1307
|
.slice(0, 5)
|
|
1260
1308
|
.map((item) => toBriefItem(item, rels, items, now, activeIds));
|
|
1261
1309
|
const markedFocus = mark(focus);
|
|
@@ -2184,7 +2232,6 @@ export function parseActivitySinceOutput(output) {
|
|
|
2184
2232
|
normalized.sort((a, b) => (a.ts < b.ts ? -1 : a.ts > b.ts ? 1 : 0));
|
|
2185
2233
|
return normalized;
|
|
2186
2234
|
}
|
|
2187
|
-
const OPEN_STATUSES = new Set(["open", "in_progress", "ready"]);
|
|
2188
2235
|
/** JSON-Patch paths that represent a dependency/relationship edit, across pm
|
|
2189
2236
|
* versions and extension schemas. Real pm 2026.7.22 uses `/metadata/dependencies`. */
|
|
2190
2237
|
function isDependencyPath(path) {
|
|
@@ -2202,6 +2249,7 @@ function isDependencyPath(path) {
|
|
|
2202
2249
|
*/
|
|
2203
2250
|
export function buildDelta(entries, itemsById, options = { since: "" }) {
|
|
2204
2251
|
const generatedAt = options.generatedAt ?? new Date().toISOString();
|
|
2252
|
+
const statusRegistry = options.statusRegistry ?? DEFAULT_STATUS_REGISTRY;
|
|
2205
2253
|
const byId = new Map();
|
|
2206
2254
|
for (const entry of entries) {
|
|
2207
2255
|
let bucket = byId.get(entry.id);
|
|
@@ -2268,11 +2316,10 @@ export function buildDelta(entries, itemsById, options = { since: "" }) {
|
|
|
2268
2316
|
if (path === "/metadata/status") {
|
|
2269
2317
|
if (typeof p.value === "string") {
|
|
2270
2318
|
statusValues.push(p.value);
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
else if (OPEN_STATUSES.has(p.value) && (latestLifecycle === "closed" || latestLifecycle === "canceled"))
|
|
2319
|
+
const status = normalizeLifecycleStatus(p.value, statusRegistry);
|
|
2320
|
+
if (isClosedStatus(status, statusRegistry))
|
|
2321
|
+
latestLifecycle = statusRegistry.terminal_canceled_statuses.has(status) ? "canceled" : "closed";
|
|
2322
|
+
else if (statusRegistry.active_statuses.has(status) && (latestLifecycle === "closed" || latestLifecycle === "canceled"))
|
|
2276
2323
|
latestLifecycle = "reopened";
|
|
2277
2324
|
}
|
|
2278
2325
|
}
|
|
@@ -3595,9 +3642,9 @@ function duplicatePairItem(item) {
|
|
|
3595
3642
|
* `created_at`) as canonical and relate the newer to it, falling back to id
|
|
3596
3643
|
* ordering when creation timestamps are missing.
|
|
3597
3644
|
*/
|
|
3598
|
-
export function duplicateRemediationCommand(a, b) {
|
|
3599
|
-
const aClosed = isClosedStatus(a.status);
|
|
3600
|
-
const bClosed = isClosedStatus(b.status);
|
|
3645
|
+
export function duplicateRemediationCommand(a, b, statusRegistry = DEFAULT_STATUS_REGISTRY) {
|
|
3646
|
+
const aClosed = isClosedStatus(a.status, statusRegistry);
|
|
3647
|
+
const bClosed = isClosedStatus(b.status, statusRegistry);
|
|
3601
3648
|
if (aClosed !== bClosed) {
|
|
3602
3649
|
const open = aClosed ? b : a;
|
|
3603
3650
|
const closed = aClosed ? a : b;
|
|
@@ -3637,7 +3684,7 @@ export function duplicateRemediationCommand(a, b) {
|
|
|
3637
3684
|
* emitted and keeps the highest score (and that score's reason) seen in either
|
|
3638
3685
|
* direction. Pairs are ranked by score descending then pair id for stable output.
|
|
3639
3686
|
*/
|
|
3640
|
-
export function collapseDuplicatePairs(candidates, matchesByCandidate, itemsById) {
|
|
3687
|
+
export function collapseDuplicatePairs(candidates, matchesByCandidate, itemsById, statusRegistry = DEFAULT_STATUS_REGISTRY) {
|
|
3641
3688
|
const best = new Map();
|
|
3642
3689
|
for (const candidate of candidates) {
|
|
3643
3690
|
const matches = matchesByCandidate.get(candidate.id);
|
|
@@ -3672,7 +3719,7 @@ export function collapseDuplicatePairs(candidates, matchesByCandidate, itemsById
|
|
|
3672
3719
|
items: [a, b],
|
|
3673
3720
|
score: Math.round(entry.score * 1000) / 1000,
|
|
3674
3721
|
reason: entry.reason,
|
|
3675
|
-
remediation: duplicateRemediationCommand(a, b),
|
|
3722
|
+
remediation: duplicateRemediationCommand(a, b, statusRegistry),
|
|
3676
3723
|
});
|
|
3677
3724
|
}
|
|
3678
3725
|
pairs.sort((x, y) => (y.score - x.score) || (x.id < y.id ? -1 : x.id > y.id ? 1 : 0));
|
|
@@ -3734,7 +3781,7 @@ export function buildDuplicateSweep(items, matchesByCandidate, options = {}) {
|
|
|
3734
3781
|
// pass that exact list through. Re-deriving it here would run the same filter a
|
|
3735
3782
|
// second time and leave two places that must agree about what a candidate is.
|
|
3736
3783
|
const candidates = options.candidates ?? selectDuplicateCandidates(items, options);
|
|
3737
|
-
const ranked = collapseDuplicatePairs(candidates, matchesByCandidate, itemsById);
|
|
3784
|
+
const ranked = collapseDuplicatePairs(candidates, matchesByCandidate, itemsById, options.statusRegistry);
|
|
3738
3785
|
const pairs = ranked.slice(0, limit);
|
|
3739
3786
|
return {
|
|
3740
3787
|
pairs,
|
|
@@ -3863,6 +3910,9 @@ export function renderMarkdownGovernance(g) {
|
|
|
3863
3910
|
* @param api - Extension API the commands are registered against.
|
|
3864
3911
|
*/
|
|
3865
3912
|
function registerCommands(api) {
|
|
3913
|
+
registerHandoffCommands(api);
|
|
3914
|
+
registerDecisionAlternativesCommand(api);
|
|
3915
|
+
registerDisclosureCommand(api);
|
|
3866
3916
|
const commonFlags = [
|
|
3867
3917
|
{ long: "--token-budget", value_name: "n", description: "Approximate maximum output token budget (alias: --max-tokens; default: 4000 for brief, 2500 for prompt)", type: "string" },
|
|
3868
3918
|
{ long: "--max-tokens", value_name: "n", description: "Alias for --token-budget (default: 4000 for brief, 2500 for prompt)", type: "string" },
|
|
@@ -3917,6 +3967,7 @@ function registerCommands(api) {
|
|
|
3917
3967
|
// ok: true and never mentions receipts (unbraind/pm-cli#770).
|
|
3918
3968
|
const mergeDecisions = await collectPendingMergeDecisions(ctx.pm_root);
|
|
3919
3969
|
const brief = buildBrief(items, {
|
|
3970
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
3920
3971
|
format,
|
|
3921
3972
|
tokenBudget: readInt(options, ["token-budget", "tokenBudget", "max-tokens", "maxTokens"], 4000),
|
|
3922
3973
|
dependencyOrder: briefDependencyOrder,
|
|
@@ -3971,6 +4022,7 @@ function registerCommands(api) {
|
|
|
3971
4022
|
});
|
|
3972
4023
|
const mergeDecisions = await collectPendingMergeDecisions(ctx.pm_root);
|
|
3973
4024
|
const brief = buildBrief(items, {
|
|
4025
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
3974
4026
|
format: "prompt",
|
|
3975
4027
|
tokenBudget: readInt(options, ["token-budget", "tokenBudget", "max-tokens", "maxTokens"], 2500),
|
|
3976
4028
|
dependencyOrder: readBool(options, "dependency-order", "dependencyOrder"),
|
|
@@ -4021,6 +4073,7 @@ function registerCommands(api) {
|
|
|
4021
4073
|
const assignee = readString(options, "assignee");
|
|
4022
4074
|
const dependencyOrder = readBool(options, "dependency-order", "dependencyOrder");
|
|
4023
4075
|
const nextOptions = {
|
|
4076
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
4024
4077
|
nextCount,
|
|
4025
4078
|
assignee,
|
|
4026
4079
|
dependencyOrder,
|
|
@@ -4069,6 +4122,7 @@ function registerCommands(api) {
|
|
|
4069
4122
|
if (format !== "text" && format !== "json")
|
|
4070
4123
|
throw new CommandError("--format must be text or json", EXIT_CODE.USAGE);
|
|
4071
4124
|
const stale = detectStaleContext(readPmItems(ctx.pm_root), {
|
|
4125
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
4072
4126
|
staleDays: readNonNegativeInt(options, ["days"], 7),
|
|
4073
4127
|
generatedAt: new Date().toISOString(),
|
|
4074
4128
|
});
|
|
@@ -4095,6 +4149,7 @@ function registerCommands(api) {
|
|
|
4095
4149
|
if (format !== "text" && format !== "json")
|
|
4096
4150
|
throw new CommandError("--format must be text or json", EXIT_CODE.USAGE);
|
|
4097
4151
|
const momentum = summarizeMomentum(readPmItems(ctx.pm_root), {
|
|
4152
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
4098
4153
|
completedDays: readInt(options, ["days"], 7),
|
|
4099
4154
|
generatedAt: new Date().toISOString(),
|
|
4100
4155
|
});
|
|
@@ -4165,6 +4220,7 @@ function registerCommands(api) {
|
|
|
4165
4220
|
for (const item of items)
|
|
4166
4221
|
itemsById.set(item.id, item);
|
|
4167
4222
|
const summary = buildDelta(entries, itemsById, {
|
|
4223
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
4168
4224
|
since: checkpoint,
|
|
4169
4225
|
until,
|
|
4170
4226
|
author,
|
|
@@ -4379,7 +4435,10 @@ function registerCommands(api) {
|
|
|
4379
4435
|
// remaining cost needs an SDK-side batch primitive (filed upstream as
|
|
4380
4436
|
// pm-cli#709); `--since` remains the mitigation that actually matters.
|
|
4381
4437
|
const matchesByCandidate = await scanCandidatesForDuplicates(candidates, workspace, threshold);
|
|
4382
|
-
const summary = buildDuplicateSweep(items, matchesByCandidate, {
|
|
4438
|
+
const summary = buildDuplicateSweep(items, matchesByCandidate, {
|
|
4439
|
+
statusRegistry: await readStatusRegistry(ctx.pm_root),
|
|
4440
|
+
threshold, limit, statuses, since, generatedAt: new Date().toISOString(), candidates,
|
|
4441
|
+
});
|
|
4383
4442
|
if (format === "json") {
|
|
4384
4443
|
const output = `${JSON.stringify(summary, null, 2)}\n`;
|
|
4385
4444
|
const outputPath = readString(options, "output");
|
|
@@ -4494,7 +4553,7 @@ function classifyPaths(paths, pmRootRel, historyIds, toonIds) {
|
|
|
4494
4553
|
}
|
|
4495
4554
|
export default defineExtension({
|
|
4496
4555
|
name: "pm-brief",
|
|
4497
|
-
version: "2026.10.
|
|
4556
|
+
version: "2026.10.24",
|
|
4498
4557
|
description: "Token-budgeted agent briefs and next-work plans for pm workspaces",
|
|
4499
4558
|
activate(api) {
|
|
4500
4559
|
registerCommands(api);
|