@unbrained/pm-cli 2026.3.12 → 2026.5.1-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/pm/extensions/.managed-extensions.json +42 -0
- package/.agents/pm/extensions/beads/index.js +109 -0
- package/.agents/pm/extensions/beads/manifest.json +7 -0
- package/{dist/cli/commands/beads.js → .agents/pm/extensions/beads/runtime.js} +31 -21
- package/.agents/pm/extensions/beads/runtime.ts +702 -0
- package/.agents/pm/extensions/todos/index.js +126 -0
- package/.agents/pm/extensions/todos/manifest.json +7 -0
- package/{dist/extensions/builtins/todos/import-export.js → .agents/pm/extensions/todos/runtime.js} +39 -29
- package/.agents/pm/extensions/todos/runtime.ts +568 -0
- package/AGENTS.md +196 -92
- package/CHANGELOG.md +404 -0
- package/CODE_OF_CONDUCT.md +42 -0
- package/CONTRIBUTING.md +144 -0
- package/PRD.md +512 -164
- package/README.md +1053 -2
- package/SECURITY.md +51 -0
- package/dist/cli/commands/activity.d.ts +5 -0
- package/dist/cli/commands/activity.js +66 -3
- package/dist/cli/commands/activity.js.map +1 -1
- package/dist/cli/commands/aggregate.d.ts +54 -0
- package/dist/cli/commands/aggregate.js +181 -0
- package/dist/cli/commands/aggregate.js.map +1 -0
- package/dist/cli/commands/append.js +4 -1
- package/dist/cli/commands/append.js.map +1 -1
- package/dist/cli/commands/calendar.d.ts +109 -0
- package/dist/cli/commands/calendar.js +797 -0
- package/dist/cli/commands/calendar.js.map +1 -0
- package/dist/cli/commands/claim.d.ts +5 -1
- package/dist/cli/commands/claim.js +42 -21
- package/dist/cli/commands/claim.js.map +1 -1
- package/dist/cli/commands/close.d.ts +1 -0
- package/dist/cli/commands/close.js +54 -5
- package/dist/cli/commands/close.js.map +1 -1
- package/dist/cli/commands/comments-audit.d.ts +91 -0
- package/dist/cli/commands/comments-audit.js +195 -0
- package/dist/cli/commands/comments-audit.js.map +1 -0
- package/dist/cli/commands/comments.d.ts +1 -0
- package/dist/cli/commands/comments.js +70 -21
- package/dist/cli/commands/comments.js.map +1 -1
- package/dist/cli/commands/completion.d.ts +10 -4
- package/dist/cli/commands/completion.js +1184 -137
- package/dist/cli/commands/completion.js.map +1 -1
- package/dist/cli/commands/config.d.ts +35 -3
- package/dist/cli/commands/config.js +968 -13
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/context.d.ts +86 -0
- package/dist/cli/commands/context.js +299 -0
- package/dist/cli/commands/context.js.map +1 -0
- package/dist/cli/commands/contracts.d.ts +78 -0
- package/dist/cli/commands/contracts.js +920 -0
- package/dist/cli/commands/contracts.js.map +1 -0
- package/dist/cli/commands/create.d.ts +48 -14
- package/dist/cli/commands/create.js +1331 -160
- package/dist/cli/commands/create.js.map +1 -1
- package/dist/cli/commands/dedupe-audit.d.ts +81 -0
- package/dist/cli/commands/dedupe-audit.js +330 -0
- package/dist/cli/commands/dedupe-audit.js.map +1 -0
- package/dist/cli/commands/deps.d.ts +52 -0
- package/dist/cli/commands/deps.js +204 -0
- package/dist/cli/commands/deps.js.map +1 -0
- package/dist/cli/commands/docs.d.ts +19 -0
- package/dist/cli/commands/docs.js +212 -13
- package/dist/cli/commands/docs.js.map +1 -1
- package/dist/cli/commands/extension.d.ts +122 -0
- package/dist/cli/commands/extension.js +1850 -0
- package/dist/cli/commands/extension.js.map +1 -0
- package/dist/cli/commands/files.d.ts +52 -1
- package/dist/cli/commands/files.js +455 -13
- package/dist/cli/commands/files.js.map +1 -1
- package/dist/cli/commands/gc.d.ts +11 -1
- package/dist/cli/commands/gc.js +89 -11
- package/dist/cli/commands/gc.js.map +1 -1
- package/dist/cli/commands/get.d.ts +13 -0
- package/dist/cli/commands/get.js +35 -3
- package/dist/cli/commands/get.js.map +1 -1
- package/dist/cli/commands/health.d.ts +10 -2
- package/dist/cli/commands/health.js +774 -23
- package/dist/cli/commands/health.js.map +1 -1
- package/dist/cli/commands/history.d.ts +20 -0
- package/dist/cli/commands/history.js +152 -6
- package/dist/cli/commands/history.js.map +1 -1
- package/dist/cli/commands/index.d.ts +16 -3
- package/dist/cli/commands/index.js +16 -3
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +7 -2
- package/dist/cli/commands/init.js +137 -5
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/learnings.d.ts +17 -0
- package/dist/cli/commands/learnings.js +129 -0
- package/dist/cli/commands/learnings.js.map +1 -0
- package/dist/cli/commands/list.d.ts +29 -1
- package/dist/cli/commands/list.js +289 -53
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/normalize.d.ts +51 -0
- package/dist/cli/commands/normalize.js +298 -0
- package/dist/cli/commands/normalize.js.map +1 -0
- package/dist/cli/commands/notes.d.ts +17 -0
- package/dist/cli/commands/notes.js +129 -0
- package/dist/cli/commands/notes.js.map +1 -0
- package/dist/cli/commands/reindex.d.ts +1 -0
- package/dist/cli/commands/reindex.js +208 -32
- package/dist/cli/commands/reindex.js.map +1 -1
- package/dist/cli/commands/restore.js +164 -30
- package/dist/cli/commands/restore.js.map +1 -1
- package/dist/cli/commands/search.d.ts +14 -1
- package/dist/cli/commands/search.js +475 -81
- package/dist/cli/commands/search.js.map +1 -1
- package/dist/cli/commands/stats.js +26 -10
- package/dist/cli/commands/stats.js.map +1 -1
- package/dist/cli/commands/templates.d.ts +26 -0
- package/dist/cli/commands/templates.js +179 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/commands/test-all.d.ts +19 -1
- package/dist/cli/commands/test-all.js +161 -13
- package/dist/cli/commands/test-all.js.map +1 -1
- package/dist/cli/commands/test-runs.d.ts +63 -0
- package/dist/cli/commands/test-runs.js +179 -0
- package/dist/cli/commands/test-runs.js.map +1 -0
- package/dist/cli/commands/test.d.ts +75 -1
- package/dist/cli/commands/test.js +1360 -41
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/commands/update-many.d.ts +57 -0
- package/dist/cli/commands/update-many.js +631 -0
- package/dist/cli/commands/update-many.js.map +1 -0
- package/dist/cli/commands/update.d.ts +30 -0
- package/dist/cli/commands/update.js +1393 -84
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +30 -0
- package/dist/cli/commands/validate.js +1151 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/error-guidance.d.ts +33 -0
- package/dist/cli/error-guidance.js +337 -0
- package/dist/cli/error-guidance.js.map +1 -0
- package/dist/cli/extension-command-options.d.ts +1 -0
- package/dist/cli/extension-command-options.js +92 -0
- package/dist/cli/extension-command-options.js.map +1 -1
- package/dist/cli/help-content.d.ts +20 -0
- package/dist/cli/help-content.js +543 -0
- package/dist/cli/help-content.js.map +1 -0
- package/dist/cli/main.js +3625 -445
- package/dist/cli/main.js.map +1 -1
- package/dist/core/extensions/index.d.ts +13 -1
- package/dist/core/extensions/index.js +108 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/item-fields.d.ts +2 -0
- package/dist/core/extensions/item-fields.js +79 -0
- package/dist/core/extensions/item-fields.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +322 -9
- package/dist/core/extensions/loader.js +911 -20
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runtime-registrations.d.ts +5 -0
- package/dist/core/extensions/runtime-registrations.js +51 -0
- package/dist/core/extensions/runtime-registrations.js.map +1 -0
- package/dist/core/history/history-stream-policy.d.ts +20 -0
- package/dist/core/history/history-stream-policy.js +53 -0
- package/dist/core/history/history-stream-policy.js.map +1 -0
- package/dist/core/history/history.js +90 -1
- package/dist/core/history/history.js.map +1 -1
- package/dist/core/item/id.js +4 -1
- package/dist/core/item/id.js.map +1 -1
- package/dist/core/item/index.d.ts +1 -0
- package/dist/core/item/index.js +1 -0
- package/dist/core/item/index.js.map +1 -1
- package/dist/core/item/item-format.d.ts +11 -5
- package/dist/core/item/item-format.js +507 -24
- package/dist/core/item/item-format.js.map +1 -1
- package/dist/core/item/parent-reference-policy.d.ts +6 -0
- package/dist/core/item/parent-reference-policy.js +32 -0
- package/dist/core/item/parent-reference-policy.js.map +1 -0
- package/dist/core/item/parse.d.ts +5 -0
- package/dist/core/item/parse.js +216 -19
- package/dist/core/item/parse.js.map +1 -1
- package/dist/core/item/sprint-release-format.d.ts +6 -0
- package/dist/core/item/sprint-release-format.js +33 -0
- package/dist/core/item/sprint-release-format.js.map +1 -0
- package/dist/core/item/status.d.ts +3 -0
- package/dist/core/item/status.js +24 -0
- package/dist/core/item/status.js.map +1 -0
- package/dist/core/item/type-registry.d.ts +37 -0
- package/dist/core/item/type-registry.js +706 -0
- package/dist/core/item/type-registry.js.map +1 -0
- package/dist/core/lock/lock.d.ts +1 -1
- package/dist/core/lock/lock.js +101 -12
- package/dist/core/lock/lock.js.map +1 -1
- package/dist/core/output/command-aware.d.ts +1 -0
- package/dist/core/output/command-aware.js +394 -0
- package/dist/core/output/command-aware.js.map +1 -0
- package/dist/core/output/output.d.ts +3 -0
- package/dist/core/output/output.js +124 -6
- package/dist/core/output/output.js.map +1 -1
- package/dist/core/schema/runtime-field-filters.d.ts +3 -0
- package/dist/core/schema/runtime-field-filters.js +39 -0
- package/dist/core/schema/runtime-field-filters.js.map +1 -0
- package/dist/core/schema/runtime-field-values.d.ts +8 -0
- package/dist/core/schema/runtime-field-values.js +154 -0
- package/dist/core/schema/runtime-field-values.js.map +1 -0
- package/dist/core/schema/runtime-schema.d.ts +68 -0
- package/dist/core/schema/runtime-schema.js +554 -0
- package/dist/core/schema/runtime-schema.js.map +1 -0
- package/dist/core/search/cache.d.ts +13 -1
- package/dist/core/search/cache.js +123 -14
- package/dist/core/search/cache.js.map +1 -1
- package/dist/core/search/semantic-defaults.d.ts +6 -0
- package/dist/core/search/semantic-defaults.js +120 -0
- package/dist/core/search/semantic-defaults.js.map +1 -0
- package/dist/core/search/vector-stores.js +3 -1
- package/dist/core/search/vector-stores.js.map +1 -1
- package/dist/core/shared/command-types.d.ts +2 -0
- package/dist/core/shared/conflict-markers.d.ts +7 -0
- package/dist/core/shared/conflict-markers.js +27 -0
- package/dist/core/shared/conflict-markers.js.map +1 -0
- package/dist/core/shared/constants.d.ts +15 -4
- package/dist/core/shared/constants.js +141 -1
- package/dist/core/shared/constants.js.map +1 -1
- package/dist/core/shared/errors.d.ts +10 -1
- package/dist/core/shared/errors.js +3 -1
- package/dist/core/shared/errors.js.map +1 -1
- package/dist/core/shared/text-normalization.d.ts +4 -0
- package/dist/core/shared/text-normalization.js +33 -0
- package/dist/core/shared/text-normalization.js.map +1 -0
- package/dist/core/shared/time.d.ts +1 -2
- package/dist/core/shared/time.js +98 -11
- package/dist/core/shared/time.js.map +1 -1
- package/dist/core/store/index.d.ts +1 -0
- package/dist/core/store/index.js +1 -0
- package/dist/core/store/index.js.map +1 -1
- package/dist/core/store/item-format-migration.d.ts +9 -0
- package/dist/core/store/item-format-migration.js +87 -0
- package/dist/core/store/item-format-migration.js.map +1 -0
- package/dist/core/store/item-store.d.ts +13 -4
- package/dist/core/store/item-store.js +238 -51
- package/dist/core/store/item-store.js.map +1 -1
- package/dist/core/store/paths.d.ts +21 -3
- package/dist/core/store/paths.js +59 -4
- package/dist/core/store/paths.js.map +1 -1
- package/dist/core/store/settings.d.ts +14 -1
- package/dist/core/store/settings.js +463 -7
- package/dist/core/store/settings.js.map +1 -1
- package/dist/core/telemetry/consent.d.ts +2 -0
- package/dist/core/telemetry/consent.js +79 -0
- package/dist/core/telemetry/consent.js.map +1 -0
- package/dist/core/telemetry/runtime.d.ts +38 -0
- package/dist/core/telemetry/runtime.js +733 -0
- package/dist/core/telemetry/runtime.js.map +1 -0
- package/dist/core/test/background-runs.d.ts +117 -0
- package/dist/core/test/background-runs.js +760 -0
- package/dist/core/test/background-runs.js.map +1 -0
- package/dist/core/test/item-test-run-tracking.d.ts +9 -0
- package/dist/core/test/item-test-run-tracking.js +50 -0
- package/dist/core/test/item-test-run-tracking.js.map +1 -0
- package/dist/sdk/cli-contracts.d.ts +92 -0
- package/dist/sdk/cli-contracts.js +2357 -0
- package/dist/sdk/cli-contracts.js.map +1 -0
- package/dist/sdk/index.d.ts +34 -0
- package/dist/sdk/index.js +23 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/types.d.ts +197 -3
- package/dist/types.js +48 -1
- package/dist/types.js.map +1 -1
- package/docs/ARCHITECTURE.md +368 -39
- package/docs/EXTENSIONS.md +454 -49
- package/docs/RELEASING.md +70 -19
- package/docs/SDK.md +123 -0
- package/docs/examples/starter-extension/README.md +48 -0
- package/docs/examples/starter-extension/index.js +191 -0
- package/docs/examples/starter-extension/manifest.json +17 -0
- package/docs/examples/starter-extension/package.json +10 -0
- package/package.json +41 -14
- package/.pi/extensions/pm-cli/index.ts +0 -778
- package/dist/cli/commands/beads.d.ts +0 -16
- package/dist/cli/commands/beads.js.map +0 -1
- package/dist/cli/commands/install.d.ts +0 -18
- package/dist/cli/commands/install.js +0 -87
- package/dist/cli/commands/install.js.map +0 -1
- package/dist/core/extensions/builtins.d.ts +0 -3
- package/dist/core/extensions/builtins.js +0 -47
- package/dist/core/extensions/builtins.js.map +0 -1
- package/dist/extensions/builtins/beads/index.d.ts +0 -8
- package/dist/extensions/builtins/beads/index.js +0 -33
- package/dist/extensions/builtins/beads/index.js.map +0 -1
- package/dist/extensions/builtins/todos/import-export.d.ts +0 -26
- package/dist/extensions/builtins/todos/import-export.js.map +0 -1
- package/dist/extensions/builtins/todos/index.d.ts +0 -8
- package/dist/extensions/builtins/todos/index.js +0 -38
- package/dist/extensions/builtins/todos/index.js.map +0 -1
|
@@ -1,14 +1,76 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import { pathExists } from "../../core/fs/fs-utils.js";
|
|
5
|
-
import { activateExtensions, loadExtensions, runActiveOnReadHooks } from "../../core/extensions/index.js";
|
|
6
|
-
import {
|
|
3
|
+
import { resolveItemTypeRegistry } from "../../core/item/type-registry.js";
|
|
4
|
+
import { pathExists, readFileIfExists } from "../../core/fs/fs-utils.js";
|
|
5
|
+
import { activateExtensions, getActiveExtensionRegistrations, loadExtensions, runActiveOnReadHooks } from "../../core/extensions/index.js";
|
|
6
|
+
import { EXTENSION_CAPABILITY_CONTRACT, KNOWN_EXTENSION_CAPABILITIES, parseLegacyExtensionCapabilityAliasWarning, parseUnknownExtensionCapabilityWarning, } from "../../core/extensions/loader.js";
|
|
7
|
+
import { hashDocument } from "../../core/history/history.js";
|
|
8
|
+
import { enforceHistoryStreamPolicyForItems } from "../../core/history/history-stream-policy.js";
|
|
9
|
+
import { readVectorizationStatusLedger, refreshSemanticEmbeddingsForMutatedItems, } from "../../core/search/cache.js";
|
|
10
|
+
import { resolveEmbeddingProviders } from "../../core/search/providers.js";
|
|
11
|
+
import { resolveSettingsWithSemanticRuntimeDefaults } from "../../core/search/semantic-defaults.js";
|
|
12
|
+
import { resolveVectorStores } from "../../core/search/vector-stores.js";
|
|
13
|
+
import { EXIT_CODE, PM_CORE_REQUIRED_SUBDIRS, PM_OPTIONAL_TYPE_SUBDIRS } from "../../core/shared/constants.js";
|
|
14
|
+
import { findFirstMergeConflictMarker } from "../../core/shared/conflict-markers.js";
|
|
7
15
|
import { PmCliError } from "../../core/shared/errors.js";
|
|
8
16
|
import { nowIso } from "../../core/shared/time.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
17
|
+
import { parseItemDocument } from "../../core/item/item-format.js";
|
|
18
|
+
import { listAllFrontMatterWithBody } from "../../core/store/item-store.js";
|
|
19
|
+
import { getHistoryPath, getItemFormatFromPath, getSettingsPath, ITEM_FILE_EXTENSIONS, resolveGlobalPmRoot, resolvePmRoot, } from "../../core/store/paths.js";
|
|
20
|
+
import { readSettingsWithMetadata } from "../../core/store/settings.js";
|
|
21
|
+
import { readManagedExtensionState } from "./extension.js";
|
|
22
|
+
const STALE_VECTORIZATION_SUMMARY_LIMIT = 25;
|
|
23
|
+
const TELEMETRY_QUEUE_RELATIVE_PATH = path.join("runtime", "telemetry", "events.jsonl");
|
|
24
|
+
const TELEMETRY_STATE_RELATIVE_PATH = path.join("runtime", "telemetry", "state.json");
|
|
25
|
+
const TELEMETRY_ENDPOINT_PROBE_TIMEOUT_MS = 2_500;
|
|
26
|
+
function warningCode(value) {
|
|
27
|
+
const normalized = value.trim();
|
|
28
|
+
const separator = normalized.indexOf(":");
|
|
29
|
+
if (separator === -1) {
|
|
30
|
+
return normalized;
|
|
31
|
+
}
|
|
32
|
+
return normalized.slice(0, separator);
|
|
33
|
+
}
|
|
34
|
+
function collectUnknownCapabilityGuidance(warnings) {
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
const guidance = [];
|
|
37
|
+
for (const warning of warnings) {
|
|
38
|
+
const parsedDetails = (() => {
|
|
39
|
+
const unknownWarning = parseUnknownExtensionCapabilityWarning(warning);
|
|
40
|
+
if (unknownWarning) {
|
|
41
|
+
return [unknownWarning];
|
|
42
|
+
}
|
|
43
|
+
return parseLegacyExtensionCapabilityAliasWarning(warning);
|
|
44
|
+
})();
|
|
45
|
+
for (const parsed of parsedDetails) {
|
|
46
|
+
const key = `${parsed.layer}:${parsed.name}:${parsed.capability}`;
|
|
47
|
+
if (seen.has(key)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
seen.add(key);
|
|
51
|
+
guidance.push(parsed);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return guidance;
|
|
55
|
+
}
|
|
56
|
+
function buildCapabilityContractMetadata() {
|
|
57
|
+
return {
|
|
58
|
+
version: EXTENSION_CAPABILITY_CONTRACT.version,
|
|
59
|
+
capabilities: [...EXTENSION_CAPABILITY_CONTRACT.capabilities],
|
|
60
|
+
legacy_aliases: { ...EXTENSION_CAPABILITY_CONTRACT.legacy_aliases },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function normalizeExtensionNameForMatch(value) {
|
|
64
|
+
return value.trim().toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
function isExpectedUnmanagedExtension(name, directory) {
|
|
67
|
+
const normalizedName = normalizeExtensionNameForMatch(name);
|
|
68
|
+
const normalizedDirectory = normalizeExtensionNameForMatch(directory);
|
|
69
|
+
if (normalizedName.startsWith("builtin-")) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return normalizedDirectory === "beads" || normalizedDirectory === "todos";
|
|
73
|
+
}
|
|
12
74
|
async function isDirectory(targetPath) {
|
|
13
75
|
try {
|
|
14
76
|
const stats = await fs.stat(targetPath);
|
|
@@ -41,6 +103,150 @@ async function countHistoryStreams(pmRoot) {
|
|
|
41
103
|
warnings,
|
|
42
104
|
};
|
|
43
105
|
}
|
|
106
|
+
function normalizeRelativePath(pmRoot, targetPath) {
|
|
107
|
+
return path.relative(pmRoot, targetPath).replaceAll("\\", "/");
|
|
108
|
+
}
|
|
109
|
+
async function listItemDocumentPaths(pmRoot, typeToFolder) {
|
|
110
|
+
const folders = [...new Set(Object.values(typeToFolder))].sort((left, right) => left.localeCompare(right));
|
|
111
|
+
const itemPaths = [];
|
|
112
|
+
for (const folder of folders) {
|
|
113
|
+
const directoryPath = path.join(pmRoot, folder);
|
|
114
|
+
let entries = [];
|
|
115
|
+
try {
|
|
116
|
+
entries = await fs.readdir(directoryPath);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
for (const entry of entries) {
|
|
125
|
+
if (!ITEM_FILE_EXTENSIONS.some((extension) => entry.toLowerCase().endsWith(extension))) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
itemPaths.push(path.join(directoryPath, entry));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
itemPaths.sort((left, right) => normalizeRelativePath(pmRoot, left).localeCompare(normalizeRelativePath(pmRoot, right)));
|
|
132
|
+
return itemPaths;
|
|
133
|
+
}
|
|
134
|
+
async function buildIntegrityCheck(pmRoot, typeToFolder, schema) {
|
|
135
|
+
const itemPaths = await listItemDocumentPaths(pmRoot, typeToFolder);
|
|
136
|
+
const itemUnreadable = [];
|
|
137
|
+
const itemConflictMarkers = [];
|
|
138
|
+
const itemParseFailures = [];
|
|
139
|
+
for (const itemPath of itemPaths) {
|
|
140
|
+
const relativePath = normalizeRelativePath(pmRoot, itemPath);
|
|
141
|
+
let raw = "";
|
|
142
|
+
try {
|
|
143
|
+
raw = await fs.readFile(itemPath, "utf8");
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
itemUnreadable.push(relativePath);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const conflictMarker = findFirstMergeConflictMarker(raw);
|
|
150
|
+
if (conflictMarker) {
|
|
151
|
+
itemConflictMarkers.push({
|
|
152
|
+
path: relativePath,
|
|
153
|
+
line: conflictMarker.line,
|
|
154
|
+
marker: conflictMarker.marker,
|
|
155
|
+
});
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
parseItemDocument(raw, { format: getItemFormatFromPath(itemPath), schema });
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
itemParseFailures.push(relativePath);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const historyDir = path.join(pmRoot, "history");
|
|
166
|
+
const historyUnreadable = [];
|
|
167
|
+
const historyConflictMarkers = [];
|
|
168
|
+
const historyInvalidJson = [];
|
|
169
|
+
let historyFiles = [];
|
|
170
|
+
try {
|
|
171
|
+
historyFiles = (await fs.readdir(historyDir)).filter((entry) => entry.endsWith(".jsonl")).sort((left, right) => left.localeCompare(right));
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")) {
|
|
175
|
+
historyUnreadable.push("history");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (const fileName of historyFiles) {
|
|
179
|
+
const itemId = fileName.slice(0, -".jsonl".length);
|
|
180
|
+
const historyPath = path.join(historyDir, fileName);
|
|
181
|
+
let raw = "";
|
|
182
|
+
try {
|
|
183
|
+
raw = await fs.readFile(historyPath, "utf8");
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
historyUnreadable.push(itemId);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const conflictMarker = findFirstMergeConflictMarker(raw);
|
|
190
|
+
if (conflictMarker) {
|
|
191
|
+
historyConflictMarkers.push({
|
|
192
|
+
id: itemId,
|
|
193
|
+
line: conflictMarker.line,
|
|
194
|
+
marker: conflictMarker.marker,
|
|
195
|
+
});
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const lines = raw.split(/\r?\n/);
|
|
199
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
200
|
+
const line = lines[index]?.trim();
|
|
201
|
+
if (!line) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
JSON.parse(line);
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
historyInvalidJson.push({
|
|
209
|
+
id: itemId,
|
|
210
|
+
line: index + 1,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const warnings = [
|
|
216
|
+
...itemUnreadable.map((entry) => `integrity_item_unreadable:${entry}`),
|
|
217
|
+
...itemConflictMarkers.map((entry) => `integrity_item_conflict_marker:${entry.path}:L${entry.line}`),
|
|
218
|
+
...itemParseFailures.map((entry) => `integrity_item_parse_failed:${entry}`),
|
|
219
|
+
...historyUnreadable.map((entry) => `integrity_history_unreadable:${entry}`),
|
|
220
|
+
...historyConflictMarkers.map((entry) => `integrity_history_conflict_marker:${entry.id}:L${entry.line}`),
|
|
221
|
+
...historyInvalidJson.map((entry) => `integrity_history_invalid_json:${entry.id}:L${entry.line}`),
|
|
222
|
+
];
|
|
223
|
+
const normalizedWarnings = [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
|
|
224
|
+
return {
|
|
225
|
+
check: {
|
|
226
|
+
name: "integrity",
|
|
227
|
+
status: normalizedWarnings.length === 0 ? "ok" : "warn",
|
|
228
|
+
details: {
|
|
229
|
+
checked_item_files: itemPaths.length,
|
|
230
|
+
checked_history_streams: historyFiles.length,
|
|
231
|
+
counts: {
|
|
232
|
+
item_unreadable: itemUnreadable.length,
|
|
233
|
+
item_conflict_markers: itemConflictMarkers.length,
|
|
234
|
+
item_parse_failures: itemParseFailures.length,
|
|
235
|
+
history_unreadable: historyUnreadable.length,
|
|
236
|
+
history_conflict_markers: historyConflictMarkers.length,
|
|
237
|
+
history_invalid_json: historyInvalidJson.length,
|
|
238
|
+
},
|
|
239
|
+
item_unreadable: itemUnreadable,
|
|
240
|
+
item_conflict_markers: itemConflictMarkers,
|
|
241
|
+
item_parse_failures: itemParseFailures,
|
|
242
|
+
history_unreadable: historyUnreadable,
|
|
243
|
+
history_conflict_markers: historyConflictMarkers,
|
|
244
|
+
history_invalid_json: historyInvalidJson,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
warnings: normalizedWarnings,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
44
250
|
function hasActivateExport(moduleRecord) {
|
|
45
251
|
if (typeof moduleRecord.activate === "function") {
|
|
46
252
|
return true;
|
|
@@ -159,6 +365,69 @@ function summarizeMigrationStatuses(migrations) {
|
|
|
159
365
|
warnings,
|
|
160
366
|
};
|
|
161
367
|
}
|
|
368
|
+
function buildExtensionHealthTriageSummary(warnings, loadFailureCount, activationFailureCount, migrationStatus, managedStateWarningCount, managedExtensionEntriesCount, unmanagedLoadedExtensions, unmanagedExpectedExtensions, unmanagedActionRequiredExtensions) {
|
|
369
|
+
const normalizedWarnings = [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
|
|
370
|
+
const warningCodes = [...new Set(normalizedWarnings.map((value) => warningCode(value)))].sort((left, right) => left.localeCompare(right));
|
|
371
|
+
const unknownCapabilityCount = normalizedWarnings.filter((warning) => warning.startsWith("extension_capability_unknown:")).length;
|
|
372
|
+
const updateHealthPartial = unmanagedActionRequiredExtensions.length > 0;
|
|
373
|
+
const updateHealthCoverage = updateHealthPartial ? "partial" : "full";
|
|
374
|
+
const remediation = [];
|
|
375
|
+
if (loadFailureCount > 0) {
|
|
376
|
+
remediation.push("Run pm extension --explore --project and pm extension --explore --global to inspect load failures.");
|
|
377
|
+
}
|
|
378
|
+
if (activationFailureCount > 0) {
|
|
379
|
+
remediation.push("Review checks[name=extensions].details.activation.failed in pm health --json for activation error details.");
|
|
380
|
+
}
|
|
381
|
+
if (migrationStatus.failed_count > 0 || migrationStatus.pending_count > 0) {
|
|
382
|
+
remediation.push("Resolve pending/failed extension migrations before write commands; use --force only when policy allows.");
|
|
383
|
+
}
|
|
384
|
+
if (managedStateWarningCount > 0) {
|
|
385
|
+
remediation.push("Run pm extension --manage --project and pm extension --manage --global to refresh managed-state diagnostics.");
|
|
386
|
+
}
|
|
387
|
+
if (unknownCapabilityCount > 0) {
|
|
388
|
+
remediation.push(`Unknown extension capabilities detected. Allowed capabilities: ${KNOWN_EXTENSION_CAPABILITIES.join(", ")}. ` +
|
|
389
|
+
"Review extension_capability_unknown warning details for suggested replacements.");
|
|
390
|
+
}
|
|
391
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_capability_legacy_alias:"))) {
|
|
392
|
+
remediation.push("Legacy extension capability aliases were auto-remapped to canonical capabilities. " +
|
|
393
|
+
"Update manifests to canonical names (migration/validation -> schema).");
|
|
394
|
+
}
|
|
395
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_command_definition_legacy_handler_alias:"))) {
|
|
396
|
+
remediation.push("Extension command definitions using legacy handler were auto-remapped. " +
|
|
397
|
+
"Update command definitions to use run: (context) => ... for forward compatibility.");
|
|
398
|
+
}
|
|
399
|
+
if (updateHealthPartial) {
|
|
400
|
+
remediation.push("Update-check coverage is partial because unmanaged extensions need adoption. Adopt existing installs via pm extension --manage --project/--global --fix-managed-state, pm extension --adopt-all --project/--global, or pm extension --adopt <name>.");
|
|
401
|
+
}
|
|
402
|
+
else if (unmanagedLoadedExtensions.length > 0) {
|
|
403
|
+
remediation.push("Loaded unmanaged extensions are currently treated as informational. Use pm extension --manage --project/--global --fix-managed-state to adopt them for update checks.");
|
|
404
|
+
}
|
|
405
|
+
if (remediation.length === 0) {
|
|
406
|
+
remediation.push("No immediate action required. Re-run pm health after extension configuration changes.");
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
status: normalizedWarnings.length === 0 ? "ok" : "warn",
|
|
410
|
+
warning_count: normalizedWarnings.length,
|
|
411
|
+
warning_codes: warningCodes,
|
|
412
|
+
load_failure_count: loadFailureCount,
|
|
413
|
+
activation_failure_count: activationFailureCount,
|
|
414
|
+
migration_failed_count: migrationStatus.failed_count,
|
|
415
|
+
migration_pending_count: migrationStatus.pending_count,
|
|
416
|
+
managed_state_warning_count: managedStateWarningCount,
|
|
417
|
+
managed_extension_entries_count: managedExtensionEntriesCount,
|
|
418
|
+
unmanaged_loaded_extension_count: unmanagedLoadedExtensions.length,
|
|
419
|
+
unmanaged_loaded_extensions: unmanagedLoadedExtensions,
|
|
420
|
+
unmanaged_expected_extension_count: unmanagedExpectedExtensions.length,
|
|
421
|
+
unmanaged_expected_extensions: unmanagedExpectedExtensions,
|
|
422
|
+
unmanaged_action_required_extension_count: unmanagedActionRequiredExtensions.length,
|
|
423
|
+
unmanaged_action_required_extensions: unmanagedActionRequiredExtensions,
|
|
424
|
+
update_health_coverage: updateHealthCoverage,
|
|
425
|
+
update_health_partial: updateHealthPartial,
|
|
426
|
+
unknown_capability_count: unknownCapabilityCount,
|
|
427
|
+
top_warnings: normalizedWarnings.slice(0, 8),
|
|
428
|
+
remediation,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
162
431
|
async function buildExtensionCheck(pmRoot, settings, noExtensionsFlag) {
|
|
163
432
|
const loadResult = await loadExtensions({
|
|
164
433
|
pmRoot,
|
|
@@ -166,14 +435,15 @@ async function buildExtensionCheck(pmRoot, settings, noExtensionsFlag) {
|
|
|
166
435
|
cwd: process.cwd(),
|
|
167
436
|
noExtensions: noExtensionsFlag,
|
|
168
437
|
});
|
|
169
|
-
const
|
|
170
|
-
? loadResult.loaded
|
|
171
|
-
: [...getEnabledBuiltInExtensions(settings), ...loadResult.loaded];
|
|
172
|
-
const loadedSummaries = loadedWithBuiltIns.map((extension) => summarizeLoadedExtension(extension));
|
|
438
|
+
const loadedSummaries = loadResult.loaded.map((extension) => summarizeLoadedExtension(extension));
|
|
173
439
|
const activationResult = await activateExtensions({
|
|
174
440
|
...loadResult,
|
|
175
|
-
loaded:
|
|
441
|
+
loaded: loadResult.loaded,
|
|
176
442
|
});
|
|
443
|
+
const [projectManagedState, globalManagedState] = await Promise.all([
|
|
444
|
+
readManagedExtensionState(loadResult.roots.project),
|
|
445
|
+
readManagedExtensionState(loadResult.roots.global),
|
|
446
|
+
]);
|
|
177
447
|
const migrationStatus = summarizeMigrationStatuses(activationResult.registrations.migrations);
|
|
178
448
|
const activationDetails = {
|
|
179
449
|
failed: activationResult.failed,
|
|
@@ -181,12 +451,72 @@ async function buildExtensionCheck(pmRoot, settings, noExtensionsFlag) {
|
|
|
181
451
|
hook_counts: activationResult.hook_counts,
|
|
182
452
|
command_override_count: activationResult.command_override_count,
|
|
183
453
|
command_handler_count: activationResult.command_handler_count,
|
|
454
|
+
parser_override_count: activationResult.parser_override_count,
|
|
455
|
+
preflight_override_count: activationResult.preflight_override_count,
|
|
456
|
+
service_override_count: activationResult.service_override_count,
|
|
184
457
|
renderer_override_count: activationResult.renderer_override_count,
|
|
185
458
|
registration_counts: activationResult.registration_counts,
|
|
186
459
|
registrations: activationResult.registrations,
|
|
187
460
|
migration_status: migrationStatus.summary,
|
|
461
|
+
managed_extensions: {
|
|
462
|
+
project: {
|
|
463
|
+
path: projectManagedState.path,
|
|
464
|
+
count: projectManagedState.state.entries.length,
|
|
465
|
+
entries: projectManagedState.state.entries,
|
|
466
|
+
},
|
|
467
|
+
global: {
|
|
468
|
+
path: globalManagedState.path,
|
|
469
|
+
count: globalManagedState.state.entries.length,
|
|
470
|
+
entries: globalManagedState.state.entries,
|
|
471
|
+
},
|
|
472
|
+
},
|
|
188
473
|
};
|
|
189
|
-
const
|
|
474
|
+
const managedProjectNames = new Set(projectManagedState.state.entries.map((entry) => normalizeExtensionNameForMatch(entry.name)));
|
|
475
|
+
const managedGlobalNames = new Set(globalManagedState.state.entries.map((entry) => normalizeExtensionNameForMatch(entry.name)));
|
|
476
|
+
const unmanagedLoadedEntries = [
|
|
477
|
+
...new Map(loadResult.loaded
|
|
478
|
+
.filter((entry) => {
|
|
479
|
+
const managedNames = entry.layer === "project" ? managedProjectNames : managedGlobalNames;
|
|
480
|
+
return !managedNames.has(normalizeExtensionNameForMatch(entry.name));
|
|
481
|
+
})
|
|
482
|
+
.map((entry) => [
|
|
483
|
+
`${entry.layer}:${entry.name}`,
|
|
484
|
+
{
|
|
485
|
+
layer: entry.layer,
|
|
486
|
+
name: entry.name,
|
|
487
|
+
directory: entry.directory,
|
|
488
|
+
},
|
|
489
|
+
])).values(),
|
|
490
|
+
].sort((left, right) => {
|
|
491
|
+
const leftKey = `${left.layer}:${left.name}`;
|
|
492
|
+
const rightKey = `${right.layer}:${right.name}`;
|
|
493
|
+
return leftKey.localeCompare(rightKey);
|
|
494
|
+
});
|
|
495
|
+
const unmanagedLoadedExtensions = unmanagedLoadedEntries
|
|
496
|
+
.map((entry) => `${entry.layer}:${entry.name}`)
|
|
497
|
+
.sort((left, right) => left.localeCompare(right));
|
|
498
|
+
const unmanagedExpectedExtensions = unmanagedLoadedEntries
|
|
499
|
+
.filter((entry) => isExpectedUnmanagedExtension(entry.name, entry.directory))
|
|
500
|
+
.map((entry) => `${entry.layer}:${entry.name}`)
|
|
501
|
+
.sort((left, right) => left.localeCompare(right));
|
|
502
|
+
const unmanagedActionRequiredExtensions = unmanagedLoadedEntries
|
|
503
|
+
.filter((entry) => !isExpectedUnmanagedExtension(entry.name, entry.directory))
|
|
504
|
+
.map((entry) => `${entry.layer}:${entry.name}`)
|
|
505
|
+
.sort((left, right) => left.localeCompare(right));
|
|
506
|
+
const updateCoverageWarnings = unmanagedActionRequiredExtensions.length > 0
|
|
507
|
+
? [`extension_update_health_partial_coverage:skipped_unmanaged:${unmanagedActionRequiredExtensions.length}`]
|
|
508
|
+
: [];
|
|
509
|
+
const extensionWarnings = [
|
|
510
|
+
...loadResult.warnings,
|
|
511
|
+
...activationDetails.warnings,
|
|
512
|
+
...migrationStatus.warnings,
|
|
513
|
+
...projectManagedState.warnings,
|
|
514
|
+
...globalManagedState.warnings,
|
|
515
|
+
...updateCoverageWarnings,
|
|
516
|
+
];
|
|
517
|
+
const capabilityGuidance = collectUnknownCapabilityGuidance(extensionWarnings);
|
|
518
|
+
const capabilityContract = buildCapabilityContractMetadata();
|
|
519
|
+
const extensionTriage = buildExtensionHealthTriageSummary(extensionWarnings, loadResult.failed.length, activationResult.failed.length, migrationStatus.summary, projectManagedState.warnings.length + globalManagedState.warnings.length, projectManagedState.state.entries.length + globalManagedState.state.entries.length, unmanagedLoadedExtensions, unmanagedExpectedExtensions, unmanagedActionRequiredExtensions);
|
|
190
520
|
return {
|
|
191
521
|
check: {
|
|
192
522
|
name: "extensions",
|
|
@@ -196,11 +526,362 @@ async function buildExtensionCheck(pmRoot, settings, noExtensionsFlag) {
|
|
|
196
526
|
loaded: loadedSummaries,
|
|
197
527
|
warnings: extensionWarnings,
|
|
198
528
|
activation: activationDetails,
|
|
529
|
+
triage: extensionTriage,
|
|
530
|
+
capability_contract: capabilityContract,
|
|
531
|
+
capability_guidance: capabilityGuidance,
|
|
199
532
|
},
|
|
200
533
|
},
|
|
201
534
|
warnings: extensionWarnings,
|
|
202
535
|
};
|
|
203
536
|
}
|
|
537
|
+
function collectStaleVectorizationIds(items, ledgerEntries) {
|
|
538
|
+
return items
|
|
539
|
+
.filter((item) => {
|
|
540
|
+
const trackedUpdatedAt = ledgerEntries[item.id];
|
|
541
|
+
return trackedUpdatedAt !== item.updated_at;
|
|
542
|
+
})
|
|
543
|
+
.map((item) => item.id)
|
|
544
|
+
.sort((left, right) => left.localeCompare(right));
|
|
545
|
+
}
|
|
546
|
+
function summarizeList(values, limit) {
|
|
547
|
+
if (values.length <= limit) {
|
|
548
|
+
return { values, truncated: false };
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
values: values.slice(0, limit),
|
|
552
|
+
truncated: true,
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function selectStaleItemDetail(values, verboseStaleItems) {
|
|
556
|
+
if (verboseStaleItems) {
|
|
557
|
+
return {
|
|
558
|
+
values,
|
|
559
|
+
truncated: false,
|
|
560
|
+
total: values.length,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
const summary = summarizeList(values, STALE_VECTORIZATION_SUMMARY_LIMIT);
|
|
564
|
+
return {
|
|
565
|
+
values: summary.values,
|
|
566
|
+
truncated: summary.truncated,
|
|
567
|
+
total: values.length,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function telemetryEnvFlagEnabled(envKey) {
|
|
571
|
+
const value = (process.env[envKey] ?? "").trim().toLowerCase();
|
|
572
|
+
return value === "1" || value === "true" || value === "yes" || value === "on";
|
|
573
|
+
}
|
|
574
|
+
function normalizeEndpointForDisplay(rawEndpoint) {
|
|
575
|
+
const trimmed = rawEndpoint.trim();
|
|
576
|
+
if (trimmed.length === 0) {
|
|
577
|
+
return "";
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
const parsed = new URL(trimmed);
|
|
581
|
+
parsed.username = "";
|
|
582
|
+
parsed.password = "";
|
|
583
|
+
parsed.search = "";
|
|
584
|
+
parsed.hash = "";
|
|
585
|
+
return parsed.toString();
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
return trimmed;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function parseTelemetryQueue(raw) {
|
|
592
|
+
let validEntries = 0;
|
|
593
|
+
let invalidRows = 0;
|
|
594
|
+
let totalRows = 0;
|
|
595
|
+
for (const line of raw.split("\n")) {
|
|
596
|
+
const trimmed = line.trim();
|
|
597
|
+
if (trimmed.length === 0) {
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
totalRows += 1;
|
|
601
|
+
try {
|
|
602
|
+
const parsed = JSON.parse(trimmed);
|
|
603
|
+
if (typeof parsed === "object" && parsed !== null && typeof parsed.attempts === "number") {
|
|
604
|
+
validEntries += 1;
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
invalidRows += 1;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
catch {
|
|
611
|
+
invalidRows += 1;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return {
|
|
615
|
+
validEntries,
|
|
616
|
+
invalidRows,
|
|
617
|
+
totalRows,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
async function probeTelemetryEndpointHealth(endpoint) {
|
|
621
|
+
let probeUrl = endpoint;
|
|
622
|
+
try {
|
|
623
|
+
const parsed = new URL(endpoint);
|
|
624
|
+
parsed.pathname = "/healthz";
|
|
625
|
+
parsed.search = "";
|
|
626
|
+
parsed.hash = "";
|
|
627
|
+
probeUrl = parsed.toString();
|
|
628
|
+
}
|
|
629
|
+
catch {
|
|
630
|
+
// keep original endpoint when URL parsing fails
|
|
631
|
+
}
|
|
632
|
+
try {
|
|
633
|
+
const response = await fetch(probeUrl, {
|
|
634
|
+
method: "GET",
|
|
635
|
+
signal: AbortSignal.timeout(TELEMETRY_ENDPOINT_PROBE_TIMEOUT_MS),
|
|
636
|
+
});
|
|
637
|
+
return {
|
|
638
|
+
probe_url: normalizeEndpointForDisplay(probeUrl),
|
|
639
|
+
ok: response.ok,
|
|
640
|
+
status: response.status,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
return {
|
|
645
|
+
probe_url: normalizeEndpointForDisplay(probeUrl),
|
|
646
|
+
ok: false,
|
|
647
|
+
error: error instanceof Error ? error.message : "probe_failed",
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
async function buildTelemetryCheck(settings, options) {
|
|
652
|
+
const globalPmRoot = resolveGlobalPmRoot(process.cwd());
|
|
653
|
+
const queuePath = path.join(globalPmRoot, TELEMETRY_QUEUE_RELATIVE_PATH);
|
|
654
|
+
const statePath = path.join(globalPmRoot, TELEMETRY_STATE_RELATIVE_PATH);
|
|
655
|
+
const queueRaw = await readFileIfExists(queuePath);
|
|
656
|
+
const queueExists = queueRaw !== null;
|
|
657
|
+
const queueSizeBytes = queueRaw ? Buffer.byteLength(queueRaw, "utf8") : 0;
|
|
658
|
+
const queueSummary = queueRaw ? parseTelemetryQueue(queueRaw) : { validEntries: 0, invalidRows: 0, totalRows: 0 };
|
|
659
|
+
const stateRaw = await readFileIfExists(statePath);
|
|
660
|
+
let runtimeState = {};
|
|
661
|
+
let stateParseFailed = false;
|
|
662
|
+
if (stateRaw && stateRaw.trim().length > 0) {
|
|
663
|
+
try {
|
|
664
|
+
const parsed = JSON.parse(stateRaw);
|
|
665
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
666
|
+
runtimeState = parsed;
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
stateParseFailed = true;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
catch {
|
|
673
|
+
stateParseFailed = true;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const endpoint = settings.telemetry.endpoint.trim();
|
|
677
|
+
const endpointDisplay = normalizeEndpointForDisplay(endpoint);
|
|
678
|
+
let endpointProbe;
|
|
679
|
+
if (options.checkTelemetry && settings.telemetry.enabled && endpoint.length > 0) {
|
|
680
|
+
const probe = await probeTelemetryEndpointHealth(endpoint);
|
|
681
|
+
endpointProbe = {
|
|
682
|
+
attempted: true,
|
|
683
|
+
...probe,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
const warnings = [];
|
|
687
|
+
if (stateParseFailed) {
|
|
688
|
+
warnings.push("telemetry_state_invalid_json");
|
|
689
|
+
}
|
|
690
|
+
if (queueSummary.invalidRows > 0) {
|
|
691
|
+
warnings.push(`telemetry_queue_invalid_rows:${queueSummary.invalidRows}`);
|
|
692
|
+
}
|
|
693
|
+
if (settings.telemetry.enabled && queueSummary.validEntries > 0) {
|
|
694
|
+
warnings.push(`telemetry_queue_pending:${queueSummary.validEntries}`);
|
|
695
|
+
}
|
|
696
|
+
if (endpointProbe && !endpointProbe.ok) {
|
|
697
|
+
if (typeof endpointProbe.status === "number") {
|
|
698
|
+
warnings.push(`telemetry_endpoint_probe_http_status:${endpointProbe.status}`);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
warnings.push("telemetry_endpoint_probe_failed");
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
check: {
|
|
706
|
+
name: "telemetry",
|
|
707
|
+
status: warnings.length === 0 ? "ok" : "warn",
|
|
708
|
+
details: {
|
|
709
|
+
enabled: settings.telemetry.enabled,
|
|
710
|
+
capture_level: settings.telemetry.capture_level,
|
|
711
|
+
endpoint: endpointDisplay,
|
|
712
|
+
global_pm_root: globalPmRoot,
|
|
713
|
+
queue_path: queuePath,
|
|
714
|
+
queue_exists: queueExists,
|
|
715
|
+
queue_entries: queueSummary.validEntries,
|
|
716
|
+
queue_invalid_rows: queueSummary.invalidRows,
|
|
717
|
+
queue_rows_total: queueSummary.totalRows,
|
|
718
|
+
queue_size_bytes: queueSizeBytes,
|
|
719
|
+
runtime_state_path: statePath,
|
|
720
|
+
last_attempted_flush_at: runtimeState.last_attempted_flush_at ?? null,
|
|
721
|
+
last_successful_flush_at: runtimeState.last_successful_flush_at ?? null,
|
|
722
|
+
last_failed_flush_at: runtimeState.last_failed_flush_at ?? null,
|
|
723
|
+
last_failed_flush_error: runtimeState.last_failed_flush_error ?? null,
|
|
724
|
+
endpoint_probe: endpointProbe ?? {
|
|
725
|
+
attempted: false,
|
|
726
|
+
},
|
|
727
|
+
env_overrides: {
|
|
728
|
+
telemetry_disabled: telemetryEnvFlagEnabled("PM_TELEMETRY_DISABLED"),
|
|
729
|
+
telemetry_otel_disabled: telemetryEnvFlagEnabled("PM_TELEMETRY_OTEL_DISABLED"),
|
|
730
|
+
},
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
warnings,
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
async function buildHistoryDriftCheck(pmRoot, items) {
|
|
737
|
+
const missingStreams = [];
|
|
738
|
+
const unreadableStreams = [];
|
|
739
|
+
const hashMismatches = [];
|
|
740
|
+
for (const item of items) {
|
|
741
|
+
const historyPath = getHistoryPath(pmRoot, item.id);
|
|
742
|
+
let latestAfterHash = null;
|
|
743
|
+
try {
|
|
744
|
+
const raw = await fs.readFile(historyPath, "utf8");
|
|
745
|
+
if (raw.trim().length === 0) {
|
|
746
|
+
missingStreams.push(item.id);
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
const lines = raw.split(/\r?\n/);
|
|
750
|
+
for (const line of lines) {
|
|
751
|
+
const trimmed = line.trim();
|
|
752
|
+
if (trimmed.length === 0) {
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
const parsed = JSON.parse(trimmed);
|
|
756
|
+
if (typeof parsed.after_hash !== "string" || parsed.after_hash.trim().length === 0) {
|
|
757
|
+
throw new Error("missing after_hash");
|
|
758
|
+
}
|
|
759
|
+
latestAfterHash = parsed.after_hash;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
catch (error) {
|
|
763
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
764
|
+
missingStreams.push(item.id);
|
|
765
|
+
}
|
|
766
|
+
else {
|
|
767
|
+
unreadableStreams.push(item.id);
|
|
768
|
+
}
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
if (!latestAfterHash) {
|
|
772
|
+
missingStreams.push(item.id);
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
const { body, ...frontMatter } = item;
|
|
776
|
+
const currentHash = hashDocument({
|
|
777
|
+
front_matter: frontMatter,
|
|
778
|
+
body,
|
|
779
|
+
});
|
|
780
|
+
if (latestAfterHash !== currentHash) {
|
|
781
|
+
hashMismatches.push(item.id);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const driftedItems = [...new Set([...missingStreams, ...unreadableStreams, ...hashMismatches])].sort((a, b) => a.localeCompare(b));
|
|
785
|
+
const warnings = [
|
|
786
|
+
...missingStreams.map((id) => `history_drift_missing_stream:${id}`),
|
|
787
|
+
...unreadableStreams.map((id) => `history_drift_unreadable_stream:${id}`),
|
|
788
|
+
...hashMismatches.map((id) => `history_drift_hash_mismatch:${id}`),
|
|
789
|
+
];
|
|
790
|
+
return {
|
|
791
|
+
check: {
|
|
792
|
+
name: "history_drift",
|
|
793
|
+
status: warnings.length === 0 ? "ok" : "warn",
|
|
794
|
+
details: {
|
|
795
|
+
checked_items: items.length,
|
|
796
|
+
drifted_items: driftedItems,
|
|
797
|
+
counts: {
|
|
798
|
+
drifted: driftedItems.length,
|
|
799
|
+
missing_streams: missingStreams.length,
|
|
800
|
+
unreadable_streams: unreadableStreams.length,
|
|
801
|
+
hash_mismatches: hashMismatches.length,
|
|
802
|
+
},
|
|
803
|
+
missing_streams: missingStreams,
|
|
804
|
+
unreadable_streams: unreadableStreams,
|
|
805
|
+
hash_mismatches: hashMismatches,
|
|
806
|
+
},
|
|
807
|
+
},
|
|
808
|
+
warnings,
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
async function buildVectorizationCheck(pmRoot, settings, items, refreshPolicy, verboseStaleItems) {
|
|
812
|
+
const runtimeDefaults = resolveSettingsWithSemanticRuntimeDefaults(settings);
|
|
813
|
+
const providerResolution = resolveEmbeddingProviders(runtimeDefaults.settings);
|
|
814
|
+
const vectorStoreResolution = resolveVectorStores(runtimeDefaults.settings);
|
|
815
|
+
const semanticRuntimeAvailable = Boolean(providerResolution.active && vectorStoreResolution.active);
|
|
816
|
+
const ledgerBefore = await readVectorizationStatusLedger(pmRoot);
|
|
817
|
+
const staleBefore = semanticRuntimeAvailable ? collectStaleVectorizationIds(items, ledgerBefore.entries) : [];
|
|
818
|
+
let refreshResult = {
|
|
819
|
+
refreshed: [],
|
|
820
|
+
skipped: [],
|
|
821
|
+
warnings: [],
|
|
822
|
+
};
|
|
823
|
+
if (refreshPolicy.enabled && semanticRuntimeAvailable && staleBefore.length > 0) {
|
|
824
|
+
refreshResult = await refreshSemanticEmbeddingsForMutatedItems(pmRoot, staleBefore, {
|
|
825
|
+
settings: runtimeDefaults.settings,
|
|
826
|
+
apply_runtime_defaults: false,
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
const ledgerAfter = await readVectorizationStatusLedger(pmRoot);
|
|
830
|
+
const staleAfter = semanticRuntimeAvailable ? collectStaleVectorizationIds(items, ledgerAfter.entries) : [];
|
|
831
|
+
const strictVectorizationWarnings = !runtimeDefaults.auto_ollama_defaults_applied;
|
|
832
|
+
const warningSet = new Set([...ledgerBefore.warnings, ...ledgerAfter.warnings]);
|
|
833
|
+
if (strictVectorizationWarnings) {
|
|
834
|
+
for (const warning of refreshResult.warnings) {
|
|
835
|
+
warningSet.add(warning);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (strictVectorizationWarnings && semanticRuntimeAvailable && staleAfter.length > 0) {
|
|
839
|
+
warningSet.add(`vectorization_stale_items_remaining:${staleAfter.length}`);
|
|
840
|
+
}
|
|
841
|
+
const warnings = [...warningSet].sort((left, right) => left.localeCompare(right));
|
|
842
|
+
const staleBeforeDetail = selectStaleItemDetail(staleBefore, verboseStaleItems);
|
|
843
|
+
const staleAfterDetail = selectStaleItemDetail(staleAfter, verboseStaleItems);
|
|
844
|
+
return {
|
|
845
|
+
check: {
|
|
846
|
+
name: "vectorization",
|
|
847
|
+
status: warnings.length === 0 ? "ok" : "warn",
|
|
848
|
+
details: {
|
|
849
|
+
semantic_runtime_available: semanticRuntimeAvailable,
|
|
850
|
+
compatibility_mode_auto_defaults: runtimeDefaults.auto_ollama_defaults_applied,
|
|
851
|
+
auto_ollama_defaults_applied: runtimeDefaults.auto_ollama_defaults_applied,
|
|
852
|
+
refresh_policy: {
|
|
853
|
+
enabled: refreshPolicy.enabled,
|
|
854
|
+
check_only: refreshPolicy.checkOnly,
|
|
855
|
+
no_refresh: refreshPolicy.noRefresh,
|
|
856
|
+
refresh_vectors: refreshPolicy.refreshVectors,
|
|
857
|
+
},
|
|
858
|
+
provider_active: providerResolution.active?.name ?? null,
|
|
859
|
+
vector_store_active: vectorStoreResolution.active?.name ?? null,
|
|
860
|
+
items: items.length,
|
|
861
|
+
ledger_entries_before: Object.keys(ledgerBefore.entries).length,
|
|
862
|
+
stale_items_detail_mode: verboseStaleItems ? "full" : "summary",
|
|
863
|
+
stale_items_summary_limit: STALE_VECTORIZATION_SUMMARY_LIMIT,
|
|
864
|
+
stale_items_before_total: staleBeforeDetail.total,
|
|
865
|
+
stale_items_before: staleBeforeDetail.values,
|
|
866
|
+
stale_items_before_truncated: staleBeforeDetail.truncated,
|
|
867
|
+
refresh_attempted: refreshPolicy.enabled && staleBefore.length > 0 && semanticRuntimeAvailable,
|
|
868
|
+
refresh_skipped_reason: refreshPolicy.enabled && semanticRuntimeAvailable && staleBefore.length > 0
|
|
869
|
+
? null
|
|
870
|
+
: !refreshPolicy.enabled
|
|
871
|
+
? "refresh_disabled"
|
|
872
|
+
: !semanticRuntimeAvailable
|
|
873
|
+
? "semantic_runtime_unavailable"
|
|
874
|
+
: "no_stale_items",
|
|
875
|
+
refresh_result: refreshResult,
|
|
876
|
+
ledger_entries_after: Object.keys(ledgerAfter.entries).length,
|
|
877
|
+
stale_items_after_total: staleAfterDetail.total,
|
|
878
|
+
stale_items_after: staleAfterDetail.values,
|
|
879
|
+
stale_items_after_truncated: staleAfterDetail.truncated,
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
warnings,
|
|
883
|
+
};
|
|
884
|
+
}
|
|
204
885
|
function validateSettingsValues(settings) {
|
|
205
886
|
const warnings = [];
|
|
206
887
|
if (settings.id_prefix.trim().length === 0) {
|
|
@@ -211,39 +892,93 @@ function validateSettingsValues(settings) {
|
|
|
211
892
|
}
|
|
212
893
|
return warnings;
|
|
213
894
|
}
|
|
214
|
-
|
|
895
|
+
function resolveVectorRefreshPolicy(options) {
|
|
896
|
+
const checkOnly = options.checkOnly === true;
|
|
897
|
+
const noRefresh = options.noRefresh === true || checkOnly;
|
|
898
|
+
const refreshVectors = options.refreshVectors === true;
|
|
899
|
+
if (refreshVectors && checkOnly) {
|
|
900
|
+
throw new PmCliError("--check-only cannot be combined with --refresh-vectors", EXIT_CODE.USAGE);
|
|
901
|
+
}
|
|
902
|
+
if (refreshVectors && options.noRefresh === true) {
|
|
903
|
+
throw new PmCliError("--no-refresh cannot be combined with --refresh-vectors", EXIT_CODE.USAGE);
|
|
904
|
+
}
|
|
905
|
+
return {
|
|
906
|
+
enabled: refreshVectors || !noRefresh,
|
|
907
|
+
checkOnly,
|
|
908
|
+
noRefresh,
|
|
909
|
+
refreshVectors,
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
export async function runHealth(global, options = {}) {
|
|
215
913
|
const pmRoot = resolvePmRoot(process.cwd(), global.path);
|
|
216
914
|
const settingsPath = getSettingsPath(pmRoot);
|
|
217
915
|
if (!(await pathExists(settingsPath))) {
|
|
218
916
|
throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);
|
|
219
917
|
}
|
|
220
|
-
const settings = await
|
|
221
|
-
const
|
|
222
|
-
const
|
|
918
|
+
const { settings, warnings: settingsReadWarnings } = await readSettingsWithMetadata(pmRoot);
|
|
919
|
+
const normalizedSettingsReadWarnings = [...new Set(settingsReadWarnings)];
|
|
920
|
+
const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());
|
|
921
|
+
const strictDirectories = options.strictDirectories === true;
|
|
922
|
+
const refreshPolicy = resolveVectorRefreshPolicy(options);
|
|
923
|
+
const optionalBuiltinDirs = new Set(PM_OPTIONAL_TYPE_SUBDIRS.filter((entry) => entry.length > 0));
|
|
924
|
+
const requiredDirSet = new Set(PM_CORE_REQUIRED_SUBDIRS.filter((entry) => entry.length > 0));
|
|
925
|
+
const optionalDirSet = new Set();
|
|
926
|
+
for (const folder of typeRegistry.folders) {
|
|
927
|
+
if (optionalBuiltinDirs.has(folder)) {
|
|
928
|
+
optionalDirSet.add(folder);
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
requiredDirSet.add(folder);
|
|
932
|
+
}
|
|
933
|
+
const requiredDirs = [...requiredDirSet].sort((left, right) => left.localeCompare(right));
|
|
934
|
+
const optionalDirs = [...optionalDirSet].sort((left, right) => left.localeCompare(right));
|
|
935
|
+
const missingRequiredDirs = [];
|
|
936
|
+
const missingOptionalDirs = [];
|
|
223
937
|
const hookWarnings = [];
|
|
224
|
-
for (const relativeDir of requiredDirs) {
|
|
938
|
+
for (const relativeDir of [...requiredDirs, ...optionalDirs]) {
|
|
225
939
|
const directoryPath = path.join(pmRoot, relativeDir);
|
|
226
940
|
hookWarnings.push(...(await runActiveOnReadHooks({
|
|
227
941
|
path: directoryPath,
|
|
228
942
|
scope: "project",
|
|
229
943
|
})));
|
|
230
944
|
if (!(await isDirectory(directoryPath))) {
|
|
231
|
-
|
|
945
|
+
if (optionalDirSet.has(relativeDir)) {
|
|
946
|
+
missingOptionalDirs.push(relativeDir);
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
missingRequiredDirs.push(relativeDir);
|
|
950
|
+
}
|
|
232
951
|
}
|
|
233
952
|
}
|
|
953
|
+
const missingDirs = strictDirectories ? [...missingRequiredDirs, ...missingOptionalDirs] : [...missingRequiredDirs];
|
|
234
954
|
const settingWarnings = validateSettingsValues(settings);
|
|
955
|
+
const telemetryCheck = await buildTelemetryCheck(settings, {
|
|
956
|
+
checkTelemetry: options.checkTelemetry === true,
|
|
957
|
+
});
|
|
235
958
|
const extensionCheck = await buildExtensionCheck(pmRoot, settings, Boolean(global.noExtensions));
|
|
236
|
-
const
|
|
959
|
+
const itemReadWarnings = [];
|
|
960
|
+
const items = await listAllFrontMatterWithBody(pmRoot, settings.item_format, typeRegistry.type_to_folder, itemReadWarnings, settings.schema);
|
|
961
|
+
const normalizedItemReadWarnings = [...new Set(itemReadWarnings)];
|
|
962
|
+
const historyPolicy = await enforceHistoryStreamPolicyForItems({
|
|
963
|
+
pmRoot,
|
|
964
|
+
settings,
|
|
965
|
+
itemIds: items.map((item) => item.id),
|
|
966
|
+
commandLabel: "health",
|
|
967
|
+
});
|
|
237
968
|
const historySummary = await countHistoryStreams(pmRoot);
|
|
969
|
+
const integrityCheck = await buildIntegrityCheck(pmRoot, typeRegistry.type_to_folder, settings.schema);
|
|
970
|
+
const historyDriftCheck = await buildHistoryDriftCheck(pmRoot, items);
|
|
971
|
+
const vectorizationCheck = await buildVectorizationCheck(pmRoot, settings, items, refreshPolicy, options.verboseStaleItems === true);
|
|
238
972
|
const checks = [
|
|
239
973
|
{
|
|
240
974
|
name: "settings",
|
|
241
|
-
status: "ok",
|
|
975
|
+
status: normalizedSettingsReadWarnings.length === 0 ? "ok" : "warn",
|
|
242
976
|
details: {
|
|
243
977
|
path: settingsPath,
|
|
244
978
|
version: settings.version,
|
|
245
979
|
id_prefix: settings.id_prefix,
|
|
246
980
|
locks_ttl_seconds: settings.locks.ttl_seconds,
|
|
981
|
+
warnings: normalizedSettingsReadWarnings,
|
|
247
982
|
},
|
|
248
983
|
},
|
|
249
984
|
{
|
|
@@ -251,7 +986,11 @@ export async function runHealth(global) {
|
|
|
251
986
|
status: missingDirs.length === 0 ? "ok" : "warn",
|
|
252
987
|
details: {
|
|
253
988
|
required: requiredDirs,
|
|
989
|
+
optional: optionalDirs,
|
|
990
|
+
missing_required: missingRequiredDirs,
|
|
991
|
+
missing_optional: missingOptionalDirs,
|
|
254
992
|
missing: missingDirs,
|
|
993
|
+
strict_directories: strictDirectories,
|
|
255
994
|
},
|
|
256
995
|
},
|
|
257
996
|
{
|
|
@@ -261,6 +1000,7 @@ export async function runHealth(global) {
|
|
|
261
1000
|
warnings: settingWarnings,
|
|
262
1001
|
},
|
|
263
1002
|
},
|
|
1003
|
+
telemetryCheck.check,
|
|
264
1004
|
extensionCheck.check,
|
|
265
1005
|
{
|
|
266
1006
|
name: "storage",
|
|
@@ -270,18 +1010,29 @@ export async function runHealth(global) {
|
|
|
270
1010
|
history_streams: historySummary.count,
|
|
271
1011
|
},
|
|
272
1012
|
},
|
|
1013
|
+
integrityCheck.check,
|
|
1014
|
+
historyDriftCheck.check,
|
|
1015
|
+
vectorizationCheck.check,
|
|
273
1016
|
];
|
|
274
1017
|
const warnings = [
|
|
275
1018
|
...missingDirs.map((dir) => `missing_directory:${dir}`),
|
|
1019
|
+
...normalizedSettingsReadWarnings,
|
|
276
1020
|
...settingWarnings,
|
|
1021
|
+
...normalizedItemReadWarnings,
|
|
1022
|
+
...telemetryCheck.warnings,
|
|
277
1023
|
...extensionCheck.warnings,
|
|
1024
|
+
...historyPolicy.warnings,
|
|
278
1025
|
...historySummary.warnings,
|
|
1026
|
+
...integrityCheck.warnings,
|
|
1027
|
+
...historyDriftCheck.warnings,
|
|
1028
|
+
...vectorizationCheck.warnings,
|
|
279
1029
|
...hookWarnings,
|
|
280
1030
|
];
|
|
1031
|
+
const normalizedWarnings = [...new Set(warnings)];
|
|
281
1032
|
return {
|
|
282
|
-
ok:
|
|
1033
|
+
ok: normalizedWarnings.length === 0,
|
|
283
1034
|
checks,
|
|
284
|
-
warnings,
|
|
1035
|
+
warnings: normalizedWarnings,
|
|
285
1036
|
generated_at: nowIso(),
|
|
286
1037
|
};
|
|
287
1038
|
}
|