prizmkit 1.1.165 → 1.1.167

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizmkit",
3
- "version": "1.1.165",
3
+ "version": "1.1.167",
4
4
  "description": "Create a new PrizmKit-powered project with clean initialization — no framework dev files, just what you need.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/clean.js CHANGED
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import fs from 'fs-extra';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { getAdaptersDir, loadMetadata, loadRulesMetadata } from './metadata.js';
6
- import { readManifest } from './manifest.js';
6
+ import { readManifestForLifecycle } from './manifest.js';
7
7
  import { privateProjectMemoryFile, projectMemoryFile } from './platforms.js';
8
8
 
9
9
  // Cleanup owns only deterministic private host-memory entries. Existing
@@ -202,7 +202,7 @@ export async function runClean(directory, options = {}) {
202
202
  ]);
203
203
 
204
204
  // Read manifest for accurate cleanup (covers skills from older versions)
205
- const manifest = await readManifest(projectRoot);
205
+ const manifest = await readManifestForLifecycle(projectRoot);
206
206
 
207
207
  // Validate and merge-remove Cursor hooks before any destructive cleanup.
208
208
  const cursorHookResults = await removeCursorHooks(projectRoot, dryRun);
package/src/config.js CHANGED
@@ -17,7 +17,7 @@ import { dirname, join } from 'path';
17
17
  import { fileURLToPath, pathToFileURL } from 'url';
18
18
  import { confirm } from '@inquirer/prompts';
19
19
 
20
- import { readManifest, writeManifest, buildManifest, diffManifest } from './manifest.js';
20
+ import { readManifestForLifecycle, writeManifest, buildManifest, diffManifest } from './manifest.js';
21
21
  import {
22
22
  loadMetadata,
23
23
  loadRulesMetadata,
@@ -446,7 +446,7 @@ export async function runConfig(directory, options = {}) {
446
446
 
447
447
  // ── Phase 1: READ current state ──────────────────────────────────────────
448
448
 
449
- const oldManifest = await readManifest(projectRoot);
449
+ const oldManifest = await readManifestForLifecycle(projectRoot);
450
450
  if (!oldManifest) {
451
451
  console.log(chalk.red(' ✗ 未找到 .prizmkit/manifest.json'));
452
452
  console.log(chalk.gray(' 请先运行 `npx prizmkit install .` 安装 PrizmKit。'));
package/src/manifest.js CHANGED
@@ -42,13 +42,37 @@ function validateManifestFields(manifest) {
42
42
  assertKnownFields(manifest.files?.memory, MANIFEST_MEMORY_FIELDS, 'manifest.files.memory');
43
43
  }
44
44
 
45
- /**
46
- * Read the manifest from a project directory.
47
- * @param {string} projectRoot
48
- * @returns {Promise<Object|null>} parsed manifest or null if not found
49
- * @throws {Error} when a present manifest cannot be read or parsed
50
- */
51
- export async function readManifest(projectRoot) {
45
+ function selectKnownFields(value, allowed, label) {
46
+ if (value === undefined) return undefined;
47
+ if (value === null || Array.isArray(value) || typeof value !== 'object') {
48
+ throw new TypeError(`${label} must be a JSON object`);
49
+ }
50
+ return Object.fromEntries(Object.entries(value).filter(([key]) => allowed.has(key)));
51
+ }
52
+
53
+ function selectCurrentManifestFields(manifest) {
54
+ const selected = selectKnownFields(manifest, MANIFEST_FIELDS, 'manifest');
55
+ if (selected.options !== undefined) {
56
+ selected.options = selectKnownFields(
57
+ selected.options,
58
+ MANIFEST_OPTION_FIELDS,
59
+ 'manifest.options',
60
+ );
61
+ }
62
+ if (selected.files !== undefined) {
63
+ selected.files = selectKnownFields(selected.files, MANIFEST_FILE_FIELDS, 'manifest.files');
64
+ if (selected.files.memory !== undefined) {
65
+ selected.files.memory = selectKnownFields(
66
+ selected.files.memory,
67
+ MANIFEST_MEMORY_FIELDS,
68
+ 'manifest.files.memory',
69
+ );
70
+ }
71
+ }
72
+ return selected;
73
+ }
74
+
75
+ async function readManifestFile(projectRoot, transform) {
52
76
  const manifestPath = path.join(projectRoot, MANIFEST_DIR, MANIFEST_FILE);
53
77
  if (!await fs.pathExists(manifestPath)) {
54
78
  return null;
@@ -58,19 +82,47 @@ export async function readManifest(projectRoot) {
58
82
  if (manifest === null || Array.isArray(manifest) || typeof manifest !== 'object') {
59
83
  throw new TypeError('manifest root must be a JSON object');
60
84
  }
61
- validateManifestFields(manifest);
62
- return manifest;
85
+ return transform(manifest);
63
86
  } catch (error) {
64
87
  throw new Error(`Failed to read PrizmKit manifest at ${manifestPath}: ${error.message}`, { cause: error });
65
88
  }
66
89
  }
67
90
 
91
+ /**
92
+ * Read and strictly validate a current manifest from a project directory.
93
+ * @param {string} projectRoot
94
+ * @returns {Promise<Object|null>} parsed manifest or null if not found
95
+ * @throws {Error} when a present manifest cannot be read or validated
96
+ */
97
+ export async function readManifest(projectRoot) {
98
+ return readManifestFile(projectRoot, manifest => {
99
+ validateManifestFields(manifest);
100
+ return manifest;
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Read an installed manifest across a package-version boundary.
106
+ *
107
+ * Lifecycle commands consume only fields declared by the current manifest
108
+ * contract. Undeclared producer metadata is neither interpreted nor preserved;
109
+ * commands that write a manifest replace it with the current canonical shape.
110
+ *
111
+ * @param {string} projectRoot
112
+ * @returns {Promise<Object|null>} current manifest projection or null if absent
113
+ * @throws {Error} when a present manifest cannot be read or has malformed known containers
114
+ */
115
+ export async function readManifestForLifecycle(projectRoot) {
116
+ return readManifestFile(projectRoot, selectCurrentManifestFields);
117
+ }
118
+
68
119
  /**
69
120
  * Write the manifest to a project directory.
70
121
  * @param {string} projectRoot
71
122
  * @param {Object} data - manifest object
72
123
  */
73
124
  export async function writeManifest(projectRoot, data) {
125
+ validateManifestFields(data);
74
126
  const manifestDir = path.join(projectRoot, MANIFEST_DIR);
75
127
  await fs.ensureDir(manifestDir);
76
128
  const manifestPath = path.join(manifestDir, MANIFEST_FILE);
package/src/upgrade.js CHANGED
@@ -13,7 +13,7 @@ import { dirname, join } from 'path';
13
13
  import { fileURLToPath } from 'url';
14
14
  import { confirm } from '@inquirer/prompts';
15
15
 
16
- import { readManifest, writeManifest, buildManifest, diffManifest } from './manifest.js';
16
+ import { readManifestForLifecycle, writeManifest, buildManifest, diffManifest } from './manifest.js';
17
17
  import {
18
18
  loadRulesMetadata,
19
19
  } from './metadata.js';
@@ -195,7 +195,7 @@ export async function runUpgrade(directory, options = {}) {
195
195
  console.log('');
196
196
 
197
197
  // 1. Read old manifest
198
- const oldManifest = await readManifest(projectRoot);
198
+ const oldManifest = await readManifestForLifecycle(projectRoot);
199
199
  if (!oldManifest) {
200
200
  console.log(chalk.yellow(' ⚠ No manifest found at .prizmkit/manifest.json'));
201
201
  console.log(chalk.yellow(' This project may have been installed with an older PrizmKit version.'));