@mjasnikovs/pi-task 0.40.30 → 0.40.31

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.
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
3
3
  import * as os from 'node:os';
4
4
  import * as path from 'node:path';
5
5
  import { openCache as defaultOpenCache } from './docs-cache.js';
6
- import { ensureIndexed as defaultEnsureIndexed } from './docs-index.js';
6
+ import { collectFiles, ensureIndexed as defaultEnsureIndexed } from './docs-index.js';
7
7
  import { npmProfile, chooseEcosystem, defaultEcosystemIo, ECOSYSTEMS } from './docs-ecosystems.js';
8
8
  import { resolvePackage as defaultResolvePackage, ResolveError, resolveTypeSource, typesPackageName, splitRuntimeNamespace } from './docs-resolve.js';
9
9
  import { retrieveChunks as defaultRetrieveChunks, PACKAGE_RETRIEVE_LIMIT, RETRIEVE_CONTENT_BUDGET } from './docs-retrieve.js';
@@ -549,7 +549,7 @@ function docsRawCached(cache, pkg, profile, query, ensureIndexed, retrieveChunks
549
549
  }
550
550
  function docsRawUncached(pkg, profile, cacheError, autoInstalled) {
551
551
  const parts = [];
552
- const surfaceFiles = walkSurfaceAlpha(pkg.root, profile);
552
+ const surfaceFiles = collectFiles(pkg, profile).surface;
553
553
  const entryFirst = pkg.entry ? [pkg.entry, ...surfaceFiles.filter(f => f !== pkg.entry)] : surfaceFiles;
554
554
  for (const abs of entryFirst) {
555
555
  let raw;
@@ -596,30 +596,6 @@ function docsRawUncached(pkg, profile, cacheError, autoInstalled) {
596
596
  autoInstalled: autoInstalled ? true : undefined
597
597
  };
598
598
  }
599
- function walkSurfaceAlpha(root, profile) {
600
- const out = [];
601
- const stack = [root];
602
- while (stack.length) {
603
- const dir = stack.pop();
604
- let entries;
605
- try {
606
- entries = fs.readdirSync(dir, { withFileTypes: true });
607
- }
608
- catch {
609
- continue;
610
- }
611
- for (const entry of entries) {
612
- if (profile.skipDirs.includes(entry.name))
613
- continue;
614
- const full = path.join(dir, entry.name);
615
- if (entry.isDirectory())
616
- stack.push(full);
617
- else if (entry.isFile() && profile.isSurfaceFile(entry.name))
618
- out.push(full);
619
- }
620
- }
621
- return out.sort();
622
- }
623
599
  function truncateHeadTail(s) {
624
600
  if (s.length <= NO_CACHE_TOTAL)
625
601
  return s;
@@ -7,6 +7,10 @@ export interface IndexResult {
7
7
  chunksWritten: number;
8
8
  contentHash: string;
9
9
  }
10
+ export interface CollectedFiles {
11
+ surface: string[];
12
+ readme: string | null;
13
+ }
10
14
  /**
11
15
  * The gate that decides whether a package needs re-indexing.
12
16
  *
@@ -48,4 +52,13 @@ export declare function chunkerFingerprint(): string;
48
52
  * `.d.cts` still has to be readable, and all 123 of zod's had a `.d.ts` twin.
49
53
  */
50
54
  export declare function dropParallelDeclarations(files: readonly string[]): string[];
55
+ /**
56
+ * The files that make up a package's surface, after every selection rule.
57
+ *
58
+ * Exported because the uncached fallback assembles the same package by hand: a
59
+ * walk that skipped these rules put a Go module's whole subtree, and both halves
60
+ * of every parallel `.d.cts`, into the one degraded path where the budget is a
61
+ * single truncated blob.
62
+ */
63
+ export declare function collectFiles(pkg: ResolvedPackage, profile: EcosystemProfile): CollectedFiles;
51
64
  export declare function ensureIndexed(cache: CacheHandle, pkg: ResolvedPackage, profile?: EcosystemProfile, supplements?: readonly ResolvedPackage[]): IndexResult;
@@ -177,7 +177,15 @@ function dropDeadMajors(files, root, version) {
177
177
  // own version is not shipping a dead major — it is shipping its API there.
178
178
  return kept.length > 0 ? kept : files;
179
179
  }
180
- function collectFiles(pkg, profile) {
180
+ /**
181
+ * The files that make up a package's surface, after every selection rule.
182
+ *
183
+ * Exported because the uncached fallback assembles the same package by hand: a
184
+ * walk that skipped these rules put a Go module's whole subtree, and both halves
185
+ * of every parallel `.d.cts`, into the one degraded path where the budget is a
186
+ * single truncated blob.
187
+ */
188
+ export function collectFiles(pkg, profile) {
181
189
  const walked = walkSurface(pkg.root, profile);
182
190
  const surface = dropDeadMajors(walked, pkg.root, pkg.version);
183
191
  return {
@@ -201,9 +201,11 @@ export declare function selectBuildVariants(files: readonly string[]): string[];
201
201
  * cannot fire here because it reads the major with `/^(\d+)\./` and Go spells its
202
202
  * versions `v1.12.0` and `go1.25.14`.
203
203
  *
204
- * A module whose root holds no Go files is not a package at all — the aws-sdk shape
205
- * and keeps everything, for the same reason `dropDeadMajors` keeps a package whose
206
- * whole surface lives under one `vN/`.
204
+ * A root that declares nothing is not the API — the aws-sdk shape holds no Go files
205
+ * at all, and `cloud.google.com/go` holds a `doc.go` with a package clause and no
206
+ * imports while its whole surface lives in subdirectories. Either keeps everything,
207
+ * for the same reason `dropDeadMajors` keeps a package whose whole surface lives
208
+ * under one `vN/`.
207
209
  */
208
210
  export declare function selectOwnPackage(files: readonly string[], root: string, name: string, version: string): string[];
209
211
  /**
@@ -650,12 +650,21 @@ function holdsByDefault(src) {
650
650
  return true;
651
651
  return expr.split(/\s*&&\s*/).every(term => term.startsWith('!'));
652
652
  }
653
- /** The import paths a Go file's import block names. */
653
+ /**
654
+ * The import paths a Go file's import block names.
655
+ *
656
+ * Scoped to the import declaration, not the file: a sibling's import path also
657
+ * occurs as a plain string constant, in an error message and in a `go:generate`
658
+ * line, and reading those keeps the very subpackage `selectOwnPackage` exists to
659
+ * drop. An `ImportPath` is a `string_lit`, so the backtick form is legal Go and
660
+ * dropping it silently drops everything reachable only through it.
661
+ */
654
662
  function importsOf(src) {
655
663
  const out = [];
656
- for (const m of src.matchAll(/"([^"\n]+)"/g)) {
657
- if (/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.~-]+)*$/.test(m[1]))
658
- out.push(m[1]);
664
+ for (const decl of src.matchAll(/^import\s*(?:\(([\s\S]*?)^\)|(.*))$/gm)) {
665
+ const body = decl[1] ?? decl[2] ?? '';
666
+ for (const m of body.matchAll(/"([^"\n]+)"|`([^`]+)`/g))
667
+ out.push(m[1] ?? m[2]);
659
668
  }
660
669
  return out;
661
670
  }
@@ -674,6 +683,10 @@ function goMajor(name, version) {
674
683
  const inVersion = /^(?:v|go)?(\d+)\./.exec(version);
675
684
  return inVersion ? Number(inVersion[1]) : 1;
676
685
  }
686
+ /** Does this file declare anything a caller of the package could be handed? */
687
+ function declaresApi(src) {
688
+ return /^(?:func|type|var|const)\b/m.test(src);
689
+ }
677
690
  /**
678
691
  * Keep the package the caller asked for, and only the subpackages it can reach.
679
692
  *
@@ -701,9 +714,11 @@ function goMajor(name, version) {
701
714
  * cannot fire here because it reads the major with `/^(\d+)\./` and Go spells its
702
715
  * versions `v1.12.0` and `go1.25.14`.
703
716
  *
704
- * A module whose root holds no Go files is not a package at all — the aws-sdk shape
705
- * and keeps everything, for the same reason `dropDeadMajors` keeps a package whose
706
- * whole surface lives under one `vN/`.
717
+ * A root that declares nothing is not the API — the aws-sdk shape holds no Go files
718
+ * at all, and `cloud.google.com/go` holds a `doc.go` with a package clause and no
719
+ * imports while its whole surface lives in subdirectories. Either keeps everything,
720
+ * for the same reason `dropDeadMajors` keeps a package whose whole surface lives
721
+ * under one `vN/`.
707
722
  */
708
723
  export function selectOwnPackage(files, root, name, version) {
709
724
  const rel = (f) => path.relative(root, f).replace(/\\/g, '/');
@@ -714,7 +729,7 @@ export function selectOwnPackage(files, root, name, version) {
714
729
  const byDir = new Map();
715
730
  for (const f of files)
716
731
  byDir.set(dirOf(f), [...(byDir.get(dirOf(f)) ?? []), f]);
717
- if ((byDir.get('') ?? []).length === 0)
732
+ if (!(byDir.get('') ?? []).some(f => declaresApi(safeRead(f) ?? '')))
718
733
  return [...files];
719
734
  const major = goMajor(name, version);
720
735
  const reachable = new Set(['']);
@@ -748,6 +763,7 @@ export function goContentFingerprintParts() {
748
763
  String(holdsByDefault),
749
764
  String(isWantedEntry),
750
765
  String(selectOwnPackage),
766
+ String(declaresApi),
751
767
  String(goMajor),
752
768
  String(importsOf)
753
769
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjasnikovs/pi-task",
3
- "version": "0.40.30",
3
+ "version": "0.40.31",
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",