@shrkcrft/packs 0.1.0-alpha.2 → 0.1.0-alpha.21

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.
@@ -17,12 +17,27 @@ export interface DiscoverPacksOptions {
17
17
  verifySignatures?: boolean;
18
18
  /** Override the secret used for signature verification. */
19
19
  packSecret?: string;
20
+ /**
21
+ * Skip the process-level discovery cache. The cache is keyed by
22
+ * projectRoot + lockfile mtime, so installs/upgrades invalidate it
23
+ * automatically. Pass `noCache: true` to force a fresh scan (e.g.
24
+ * after editing a manifest in place during a long-running process).
25
+ */
26
+ noCache?: boolean;
20
27
  }
28
+ /** Clear the process-level pack-discovery cache. Tests use this. */
29
+ export declare function clearPackDiscoveryCache(): void;
21
30
  /**
22
31
  * Walk `<projectRoot>/node_modules/` (+ any extra roots) and surface every
23
32
  * package whose `package.json` declares a `sharkcraft` field. For each, load
24
33
  * the manifest and run validatePackManifest. Returns a structured discovery
25
34
  * result; never throws on individual pack failures.
35
+ *
36
+ * The result is cached at process-level keyed by projectRoot + lock-file
37
+ * mtime, so repeated calls within a single CLI invocation (or MCP server
38
+ * session) skip the node_modules walk. The cache invalidates automatically
39
+ * on any install/upgrade and is bypassed entirely when signature
40
+ * verification is requested or extra roots are supplied.
26
41
  */
27
42
  export declare function discoverPacks(options: DiscoverPacksOptions): Promise<IPackDiscoveryResult>;
28
43
  //# sourceMappingURL=discover-packs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discover-packs.d.ts","sourceRoot":"","sources":["../../src/discovery/discover-packs.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAqHxF,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,6EAA6E;IAC7E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAoIhG"}
1
+ {"version":3,"file":"discover-packs.d.ts","sourceRoot":"","sources":["../../src/discovery/discover-packs.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAuHxF,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,6EAA6E;IAC7E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAmDD,oEAAoE;AACpE,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqJhG"}
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
9
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
10
10
  import * as nodePath from 'node:path';
11
11
  import { pathToFileURL } from 'node:url';
12
12
  import { PACK_SECRET_ENV, validatePackManifest, verifyPackManifest, } from '@shrkcrft/plugin-api';
@@ -43,6 +43,7 @@ function emptyCounts() {
43
43
  constructFiles: 0,
44
44
  constructFacetFiles: 0,
45
45
  playbookFiles: 0,
46
+ delegateRecipeFiles: 0,
46
47
  };
47
48
  }
48
49
  function countContributions(c) {
@@ -61,6 +62,7 @@ function countContributions(c) {
61
62
  out.constructFiles = c.constructFiles?.length ?? 0;
62
63
  out.constructFacetFiles = c.constructFacetFiles?.length ?? 0;
63
64
  out.playbookFiles = c.playbookFiles?.length ?? 0;
65
+ out.delegateRecipeFiles = c.delegateRecipeFiles?.length ?? 0;
64
66
  return out;
65
67
  }
66
68
  /**
@@ -120,16 +122,72 @@ function* scanNodeModules(nodeModulesPath) {
120
122
  }
121
123
  }
122
124
  }
125
+ const discoveryCache = new Map();
126
+ function lockFingerprintFor(projectRoot) {
127
+ // Try each known lock file in order; first existing one wins. mtimeMs
128
+ // changes every install, so it's a tight invalidation signal.
129
+ const candidates = ['bun.lockb', 'bun.lock', 'package-lock.json', 'pnpm-lock.yaml', 'yarn.lock'];
130
+ for (const name of candidates) {
131
+ const p = nodePath.join(projectRoot, name);
132
+ if (existsSync(p)) {
133
+ try {
134
+ const st = statSync(p);
135
+ return `${name}:${st.mtimeMs}:${st.size}`;
136
+ }
137
+ catch {
138
+ // fall through and try the next candidate
139
+ }
140
+ }
141
+ }
142
+ // No lock file — also cache by node_modules mtime as a fallback.
143
+ const nm = nodePath.join(projectRoot, 'node_modules');
144
+ if (existsSync(nm)) {
145
+ try {
146
+ const st = statSync(nm);
147
+ return `node_modules:${st.mtimeMs}`;
148
+ }
149
+ catch {
150
+ // ignore
151
+ }
152
+ }
153
+ return 'none';
154
+ }
155
+ function cacheKeyOf(key) {
156
+ return `${key.projectRoot}::${key.lockFingerprint}`;
157
+ }
158
+ /** Clear the process-level pack-discovery cache. Tests use this. */
159
+ export function clearPackDiscoveryCache() {
160
+ discoveryCache.clear();
161
+ }
123
162
  /**
124
163
  * Walk `<projectRoot>/node_modules/` (+ any extra roots) and surface every
125
164
  * package whose `package.json` declares a `sharkcraft` field. For each, load
126
165
  * the manifest and run validatePackManifest. Returns a structured discovery
127
166
  * result; never throws on individual pack failures.
167
+ *
168
+ * The result is cached at process-level keyed by projectRoot + lock-file
169
+ * mtime, so repeated calls within a single CLI invocation (or MCP server
170
+ * session) skip the node_modules walk. The cache invalidates automatically
171
+ * on any install/upgrade and is bypassed entirely when signature
172
+ * verification is requested or extra roots are supplied.
128
173
  */
129
174
  export async function discoverPacks(options) {
130
175
  const projectRoot = nodePath.resolve(options.projectRoot);
131
176
  const nodeModulesPath = nodePath.join(projectRoot, 'node_modules');
132
177
  const nodeModulesExists = existsSync(nodeModulesPath);
178
+ // Cache lookup — only when the caller doesn't disable it AND when no
179
+ // signature-verification or extra-root option might change the answer.
180
+ const cacheable = !options.noCache &&
181
+ !options.verifySignatures &&
182
+ (!options.extraRoots || options.extraRoots.length === 0);
183
+ const cacheKey = cacheable
184
+ ? cacheKeyOf({ projectRoot, lockFingerprint: lockFingerprintFor(projectRoot) })
185
+ : null;
186
+ if (cacheKey) {
187
+ const cached = discoveryCache.get(cacheKey);
188
+ if (cached)
189
+ return cached;
190
+ }
133
191
  const result = {
134
192
  projectRoot,
135
193
  nodeModulesPath,
@@ -247,5 +305,8 @@ export async function discoverPacks(options) {
247
305
  }
248
306
  }
249
307
  }
308
+ if (cacheKey) {
309
+ discoveryCache.set(cacheKey, result);
310
+ }
250
311
  return result;
251
312
  }
@@ -23,6 +23,7 @@ export interface IDiscoveredPack {
23
23
  constructFiles: number;
24
24
  constructFacetFiles: number;
25
25
  playbookFiles: number;
26
+ delegateRecipeFiles: number;
26
27
  };
27
28
  /**
28
29
  * Number of **resolved objects** loaded from this pack's contributions, after
@@ -1 +1 @@
1
- {"version":3,"file":"pack-discovery.d.ts","sourceRoot":"","sources":["../../src/model/pack-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;I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ha.2",
3
+ "version": "0.1.0-alpha.21",
4
4
  "description": "SharkCraft pack discovery + loading: scan node_modules for sharkcraft manifests and surface contributions.",
5
5
  "license": "MIT",
6
6
  "author": "SharkCraft contributors",
7
7
  "type": "module",
8
8
  "main": "./dist/index.js",
9
- "types": "./dist/index.d.d.ts",
9
+ "types": "./dist/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "typecheck": "tsc --noEmit -p tsconfig.json"
43
43
  },
44
44
  "dependencies": {
45
- "@shrkcrft/core": "^0.1.0-alpha.2",
46
- "@shrkcrft/plugin-api": "^0.1.0-alpha.2"
45
+ "@shrkcrft/core": "^0.1.0-alpha.21",
46
+ "@shrkcrft/plugin-api": "^0.1.0-alpha.21"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"