@mjasnikovs/pi-task 0.29.0 → 0.29.1

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.
@@ -106,9 +106,24 @@ export async function runAutoInstall(spawn, packageName, signal, versionRange) {
106
106
  // `shell: false` in runChild, so a `^`/`~`/space in the range stays a single
107
107
  // literal arg — no glob/expansion risk from `<pkg>@<range>`.
108
108
  const target = versionRange ? `${packageName}@${versionRange}` : packageName;
109
+ // `--ignore-scripts` is not optional here. The package NAME is model-chosen —
110
+ // it comes out of a worker's question, or out of a `/// <reference types="X" />`
111
+ // line in someone else's declaration file — so a hallucinated or typosquatted
112
+ // name would otherwise run its preinstall/postinstall as the user. This cache
113
+ // has already run install hooks for `node`, `argon2`, `onnxruntime-node` and
114
+ // `sharp`, next to fetched names like `app.ts`, `pkg.json` and `tsconfig.json`.
115
+ // Nothing is lost: the docs worker only ever READS `.d.ts` files and the README
116
+ // out of the installed tree, and those ship in the tarball.
109
117
  const result = await runChild(spawn, {
110
118
  command: 'npm',
111
- args: ['install', '--no-audit', '--no-fund', '--loglevel=error', target]
119
+ args: [
120
+ 'install',
121
+ '--ignore-scripts',
122
+ '--no-audit',
123
+ '--no-fund',
124
+ '--loglevel=error',
125
+ target
126
+ ]
112
127
  }, installDir, signal, { mode: 'text', discardStdout: true });
113
128
  return { success: result.exitCode === 0 && !result.aborted, installDir, stderr: result.stderr };
114
129
  }
@@ -30,9 +30,27 @@ export declare function resolvePackage(moduleName: string, cwd: string): Resolve
30
30
  export declare function typesPackageName(moduleName: string): string | null;
31
31
  /** True if the package ships at least one declaration file. */
32
32
  export declare function hasTypeFiles(root: string): boolean;
33
+ /**
34
+ * Count declarations in a declaration file's text, ignoring comments, blank
35
+ * lines, and the pointer lines a redirect stub is made of (`/// <reference .. />`
36
+ * and `export * from "X"`).
37
+ *
38
+ * This is the discriminator `detectTypesRedirect` needs: a redirect stub is a
39
+ * file with essentially nothing in it but the pointer, while an API surface that
40
+ * merely *declares an ambient dependency* on another types package (the
41
+ * `sharp` -> `/// <reference types="node" />` shape) carries its own
42
+ * declarations. Counting `.d.ts` FILES cannot tell those apart — sharp ships one
43
+ * 1971-line file and `@types/bun` ships one 1-line file, and both count as 1.
44
+ *
45
+ * Deliberately lexical, not a TypeScript parse: this runs in the shipped worker,
46
+ * which has no compiler dependency. Over-counting is the safe direction (a
47
+ * declaration found ⇒ not a stub ⇒ keep the package's own types).
48
+ */
49
+ export declare function countEntryDeclarations(content: string): number;
33
50
  /** When a package is a pure pointer to another types package — a single-file
34
51
  * `/// <reference types="X" />` (the `@types/bun -> bun-types` shape) or a lone
35
52
  * `export * from "X"` re-export — return the target package name. Returns null
36
- * for packages that ship their own declarations (more than one .d.ts file, or a
37
- * local `/// <reference path=... />` aggregator entry). */
53
+ * for packages that ship their own declarations (more than one .d.ts file, a
54
+ * local `/// <reference path=... />` aggregator entry, or an entry file that
55
+ * declares anything of its own). */
38
56
  export declare function detectTypesRedirect(pkg: ResolvedPackage): string | null;
@@ -223,11 +223,55 @@ function isBareSpecifier(spec) {
223
223
  }
224
224
  const REFERENCE_TYPES_RE = /\/\/\/\s*<reference\s+types=["']([^"']+)["']\s*\/>/;
225
225
  const REEXPORT_ALL_RE = /^\s*export\s+(?:type\s+)?\*\s+from\s+["']([^"']+)["'];?\s*$/m;
226
+ const BLOCK_COMMENT_RE = /\/\*[\s\S]*?\*\//g;
227
+ const DECLARATION_RE = /^\s*(?:export\s+(?:default\s+)?)?(?:declare\s+)?(?:abstract\s+|async\s+)?(?:interface|type|class|function|const|let|var|namespace|module|enum)\b/;
228
+ /**
229
+ * Count declarations in a declaration file's text, ignoring comments, blank
230
+ * lines, and the pointer lines a redirect stub is made of (`/// <reference .. />`
231
+ * and `export * from "X"`).
232
+ *
233
+ * This is the discriminator `detectTypesRedirect` needs: a redirect stub is a
234
+ * file with essentially nothing in it but the pointer, while an API surface that
235
+ * merely *declares an ambient dependency* on another types package (the
236
+ * `sharp` -> `/// <reference types="node" />` shape) carries its own
237
+ * declarations. Counting `.d.ts` FILES cannot tell those apart — sharp ships one
238
+ * 1971-line file and `@types/bun` ships one 1-line file, and both count as 1.
239
+ *
240
+ * Deliberately lexical, not a TypeScript parse: this runs in the shipped worker,
241
+ * which has no compiler dependency. Over-counting is the safe direction (a
242
+ * declaration found ⇒ not a stub ⇒ keep the package's own types).
243
+ */
244
+ export function countEntryDeclarations(content) {
245
+ const stripped = content.replace(BLOCK_COMMENT_RE, '');
246
+ let n = 0;
247
+ for (const raw of stripped.split('\n')) {
248
+ const line = raw.trim();
249
+ if (!line || line.startsWith('//'))
250
+ continue;
251
+ if (REEXPORT_ALL_RE.test(line))
252
+ continue;
253
+ if (DECLARATION_RE.test(line))
254
+ n++;
255
+ }
256
+ return n;
257
+ }
258
+ /** The package a declaration file points at: a triple-slash `<reference types>`
259
+ * or a whole-module `export * from`. Null when the file points nowhere. */
260
+ function pointerTarget(content) {
261
+ const ref = REFERENCE_TYPES_RE.exec(content);
262
+ if (ref && isBareSpecifier(ref[1]))
263
+ return parentPackageName(ref[1]);
264
+ const rex = REEXPORT_ALL_RE.exec(content);
265
+ if (rex && isBareSpecifier(rex[1]))
266
+ return parentPackageName(rex[1]);
267
+ return null;
268
+ }
226
269
  /** When a package is a pure pointer to another types package — a single-file
227
270
  * `/// <reference types="X" />` (the `@types/bun -> bun-types` shape) or a lone
228
271
  * `export * from "X"` re-export — return the target package name. Returns null
229
- * for packages that ship their own declarations (more than one .d.ts file, or a
230
- * local `/// <reference path=... />` aggregator entry). */
272
+ * for packages that ship their own declarations (more than one .d.ts file, a
273
+ * local `/// <reference path=... />` aggregator entry, or an entry file that
274
+ * declares anything of its own). */
231
275
  export function detectTypesRedirect(pkg) {
232
276
  // A package that ships multiple declaration files is an aggregator, not a
233
277
  // redirect stub — use its own types.
@@ -247,11 +291,16 @@ export function detectTypesRedirect(pkg) {
247
291
  // declarations (e.g. bun-types) — not a redirect to another package.
248
292
  if (/\/\/\/\s*<reference\s+path=/.test(content))
249
293
  return null;
250
- const ref = REFERENCE_TYPES_RE.exec(content);
251
- if (ref && isBareSpecifier(ref[1]))
252
- return parentPackageName(ref[1]);
253
- const rex = REEXPORT_ALL_RE.exec(content);
254
- if (rex && isBareSpecifier(rex[1]))
255
- return parentPackageName(rex[1]);
256
- return null;
294
+ const target = pointerTarget(content);
295
+ if (!target)
296
+ return null;
297
+ // A pointer line is not a redirect when the file it sits in also declares an
298
+ // API. `/// <reference types="node" />` in a package like sharp is an AMBIENT
299
+ // DEPENDENCY declaration — "my types need node's" — not "my types ARE node's";
300
+ // following it answered every sharp question out of @types/node (tty.d.ts,
301
+ // zlib.d.ts) while sharp's own 1971-line surface sat one file away. The .d.ts
302
+ // FILE count cannot see this: sharp ships one file and so does @types/bun.
303
+ if (countEntryDeclarations(content) > 0)
304
+ return null;
305
+ return target;
257
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjasnikovs/pi-task",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Deterministic task planning and spec-orchestration for local models — crash-safe /task pipelines with verify/enforce gates, a real-time remote web view, and web/docs/fetch/worker subagent tools.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",