@mjasnikovs/pi-task 0.40.33 → 0.40.35

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/README.md CHANGED
@@ -268,7 +268,7 @@ bun run lint # prettier + eslint + tsc --noEmit
268
268
  bun run build # tsc → dist/
269
269
  ```
270
270
 
271
- Built with [Bun](https://bun.sh), TypeScript (strict), and [TypeBox](https://github.com/sinclairzx81/typebox) for tool schemas. Design plans live in [`plans/`](./plans).
271
+ Built with [Bun](https://bun.sh), TypeScript (strict), and [TypeBox](https://github.com/sinclairzx81/typebox) for tool schemas.
272
272
 
273
273
  ## License
274
274
 
@@ -65,7 +65,7 @@ export declare function verifyExcerpt(excerpt: string, content: string): Excerpt
65
65
  * fabrication. An excerpt assembled from several real spans is a stitched quote,
66
66
  * which is what the extraction prompt produces — and calling that a possible
67
67
  * hallucination was wrong on 21 of 21 measured cases, on a fifth of every run's
68
- * answers. See "Defect 18" in DOC_REGRESSINONS.md.
68
+ * answers.
69
69
  */
70
70
  export declare function formatResultText(header: string, parsed: {
71
71
  answer: string;
@@ -112,7 +112,7 @@ export function verifyExcerpt(excerpt, content) {
112
112
  * fabrication. An excerpt assembled from several real spans is a stitched quote,
113
113
  * which is what the extraction prompt produces — and calling that a possible
114
114
  * hallucination was wrong on 21 of 21 measured cases, on a fifth of every run's
115
- * answers. See "Defect 18" in DOC_REGRESSINONS.md.
115
+ * answers.
116
116
  */
117
117
  export function formatResultText(header, parsed, check) {
118
118
  if (!parsed.excerpt) {
@@ -70,7 +70,8 @@ export interface SessionRequest {
70
70
  failed: boolean;
71
71
  /** CDP resource type, collapsed: what ISSUED this request. */
72
72
  initiator: 'xhr' | 'document' | 'other';
73
- /** Relative to the sign-in request: before it, it, or after it. */
73
+ /** Before the submit, the sign-in request itself, or issued at or after the
74
+ * submit. */
74
75
  phase: 'pre' | 'auth' | 'post';
75
76
  }
76
77
  export interface DeepSessionFacts {
@@ -93,8 +94,8 @@ export interface DeepSessionFacts {
93
94
  status: number | null;
94
95
  failed: boolean;
95
96
  } | null;
96
- /** Same-origin XHR/fetch requests issued AFTER the sign-in response, excluding
97
- * the sign-in request itself. Derived: `sessionRequests` in phase 'post'. */
97
+ /** Same-origin XHR/fetch requests issued at or after the submit, excluding the
98
+ * sign-in request itself. Derived: `sessionRequests` in phase 'post'. */
98
99
  postAuthDataAttempted: number;
99
100
  postAuthData2xx: number;
100
101
  /** Origins the client called that are not the app's own, whose requests failed
@@ -112,8 +113,9 @@ export interface DeepSessionFacts {
112
113
  * The three request-shaped facts, computed from the log and from nothing else. The
113
114
  * driver records `sessionRequests` and calls this; the values are exactly what the
114
115
  * pre-log driver computed by filtering the same map (the sign-in request is the
115
- * first same-origin non-GET after submit; the data requests are the same-origin
116
- * XHR/fetch issued at or after it, itself excluded).
116
+ * first same-origin non-GET issued at or after the submit; the data requests are the
117
+ * same-origin
118
+ * XHR/fetch issued at or after the submit, the sign-in request itself excluded).
117
119
  */
118
120
  export declare function deriveLegacyFacts(log: SessionRequest[]): Pick<DeepSessionFacts, 'authRequest' | 'postAuthDataAttempted' | 'postAuthData2xx'>;
119
121
  /**
@@ -225,7 +227,7 @@ export interface DriveSessionOptions {
225
227
  /**
226
228
  * The session over an already-connected browser: navigate, inspect, sign in if the
227
229
  * landing is a wall and credentials exist, settle, phase the same-origin request
228
- * log against the sign-in request, re-enter once the sign-in was accepted, and
230
+ * log against the submit, re-enter once the sign-in was accepted, and
229
231
  * hand the facts to `judge`. Pure protocol logic — no process, no filesystem, no
230
232
  * socket — so every branch is testable against a fake `CdpLike`.
231
233
  *
@@ -202,8 +202,9 @@ export function pinnedLocalPort(vars) {
202
202
  * The three request-shaped facts, computed from the log and from nothing else. The
203
203
  * driver records `sessionRequests` and calls this; the values are exactly what the
204
204
  * pre-log driver computed by filtering the same map (the sign-in request is the
205
- * first same-origin non-GET after submit; the data requests are the same-origin
206
- * XHR/fetch issued at or after it, itself excluded).
205
+ * first same-origin non-GET issued at or after the submit; the data requests are the
206
+ * same-origin
207
+ * XHR/fetch issued at or after the submit, the sign-in request itself excluded).
207
208
  */
208
209
  export function deriveLegacyFacts(log) {
209
210
  const auth = log.find(r => r.phase === 'auth') ?? null;
@@ -290,8 +291,12 @@ export function judgeDeepSession(f) {
290
291
  // `GET /*` → index.html fallback returns 200 for a route it does not have, so
291
292
  // the status is healthy and the body is the app shell. A document navigation
292
293
  // answered with HTML is normal; an XHR asking for data and getting HTML is a
293
- // call that reached nothing.
294
- const swallowed = (f.sessionRequests ?? []).find(r => r.initiator === 'xhr' && (r.mimeType ?? '').startsWith('text/html'));
294
+ // call that reached nothing. The sign-in request is exempt: it keeps the first
295
+ // hop but carries the LAST hop's mime, so a fetch login that 302s to a page
296
+ // reads as HTML here while being a sign-in that worked.
297
+ const swallowed = (f.sessionRequests ?? []).find(r => r.initiator === 'xhr'
298
+ && r.phase !== 'auth'
299
+ && (r.mimeType ?? '').startsWith('text/html'));
295
300
  if (swallowed) {
296
301
  return {
297
302
  outcome: 'fail',
@@ -636,7 +641,7 @@ export async function launchBrowser(bin, userDataDir, { signal } = {}) {
636
641
  /**
637
642
  * The session over an already-connected browser: navigate, inspect, sign in if the
638
643
  * landing is a wall and credentials exist, settle, phase the same-origin request
639
- * log against the sign-in request, re-enter once the sign-in was accepted, and
644
+ * log against the submit, re-enter once the sign-in was accepted, and
640
645
  * hand the facts to `judge`. Pure protocol logic — no process, no filesystem, no
641
646
  * socket — so every branch is testable against a fake `CdpLike`.
642
647
  *
@@ -645,18 +650,27 @@ export async function launchBrowser(bin, userDataDir, { signal } = {}) {
645
650
  export async function driveSession(cdp, { url, credentials, judge, quietMs }) {
646
651
  const origin = new URL(url).origin;
647
652
  const requests = new Map();
653
+ let nextSeq = 0;
648
654
  let lastActivity = Date.now();
649
655
  cdp.on('Network.requestWillBeSent', p => {
650
- const req = p.request;
651
- requests.set(String(p.requestId), {
652
- url: String(req?.url ?? ''),
653
- method: String(req?.method ?? 'GET'),
654
- type: String(p.type ?? ''),
655
- status: null,
656
- mimeType: null,
657
- failed: false,
658
- at: Date.now()
659
- });
656
+ const id = String(p.requestId);
657
+ // A redirect hop reuses the requestId, carrying the NEXT hop's method and
658
+ // url. The request the client made is the first hop and the status that
659
+ // judges it is the chain's last, so the first hop stays and the eventual
660
+ // response lands on it. Overwriting reads a POST that 302s as a GET, and
661
+ // then no sign-in request is ever found.
662
+ if (p.redirectResponse === undefined || !requests.has(id)) {
663
+ const req = p.request;
664
+ requests.set(id, {
665
+ url: String(req?.url ?? ''),
666
+ method: String(req?.method ?? 'GET'),
667
+ type: String(p.type ?? ''),
668
+ status: null,
669
+ mimeType: null,
670
+ failed: false,
671
+ seq: nextSeq++
672
+ });
673
+ }
660
674
  lastActivity = Date.now();
661
675
  });
662
676
  cdp.on('Network.responseReceived', p => {
@@ -711,27 +725,23 @@ export async function driveSession(cdp, { url, credentials, judge, quietMs }) {
711
725
  const initiatorOf = (r) => isData(r) ? 'xhr'
712
726
  : r.type === 'Document' ? 'document'
713
727
  : 'other';
714
- /** The same-origin request log, phased against the sign-in request. `authAt` is
715
- * Infinity before the submit, so every request so far is 'pre'. */
716
- const sessionLog = (authId, authAt) => {
717
- const out = [];
718
- for (const [id, r] of requests) {
719
- if (!sameOrigin(r))
720
- continue;
721
- out.push({
722
- method: r.method,
723
- path: pathOf(r.url),
724
- status: r.status,
725
- mimeType: r.mimeType,
726
- failed: r.failed,
727
- initiator: initiatorOf(r),
728
- phase: id === authId ? 'auth'
729
- : r.at >= authAt ? 'post'
730
- : 'pre'
731
- });
732
- }
733
- return out;
734
- };
728
+ /** The same-origin request log, phased against the submit. `postSeq` is the
729
+ * first `seq` the submit could issue Infinity while no submit has happened —
730
+ * so before a submit every request so far is 'pre'; the sign-in request sits at
731
+ * or after the boundary but is 'auth', not 'post'. */
732
+ const sessionLog = (authId, postSeq) => [...requests]
733
+ .filter(([, r]) => sameOrigin(r))
734
+ .map(([id, r]) => ({
735
+ method: r.method,
736
+ path: pathOf(r.url),
737
+ status: r.status,
738
+ mimeType: r.mimeType,
739
+ failed: r.failed,
740
+ initiator: initiatorOf(r),
741
+ phase: id === authId ? 'auth'
742
+ : r.seq >= postSeq ? 'post'
743
+ : 'pre'
744
+ }));
735
745
  const facts = (log, over) => ({
736
746
  sessionRequests: log,
737
747
  ...deriveLegacyFacts(log),
@@ -749,13 +759,15 @@ export async function driveSession(cdp, { url, credentials, judge, quietMs }) {
749
759
  const unsubmitted = (over) => facts(sessionLog(null, Number.POSITIVE_INFINITY), over);
750
760
  if (!before.hasPassword || credentials === null)
751
761
  return judge(unsubmitted({}));
752
- const submitMark = Date.now();
753
762
  const filled = await evaluate(fillExpr(credentials.identifier, credentials.password));
754
763
  if (!filled?.ok)
755
764
  return judge(unsubmitted({ submitted: false }));
756
765
  // Separate turn: the fill's input events schedule framework state updates that
757
766
  // the submit handler must already see.
758
767
  await sleep(300);
768
+ // Captured after the fill: background traffic before the submit must not be
769
+ // eligible as the sign-in request.
770
+ const submitSeq = nextSeq;
759
771
  const submitted = await evaluate(SUBMIT_EXPR);
760
772
  if (!submitted?.ok)
761
773
  return judge(unsubmitted({ submitted: false }));
@@ -765,16 +777,14 @@ export async function driveSession(cdp, { url, credentials, judge, quietMs }) {
765
777
  // own 2xx is the precondition for judging anything, and it is EXCLUDED from the
766
778
  // data evidence — a broken build satisfies "at least one same-origin 2xx" with
767
779
  // exactly this request and nothing else.
768
- const after = new Map([...requests].filter(([, r]) => r.at >= submitMark));
769
780
  let authId = null;
770
- for (const [id, r] of after) {
771
- if (sameOrigin(r) && r.method !== 'GET') {
781
+ for (const [id, r] of requests) {
782
+ if (r.seq >= submitSeq && sameOrigin(r) && r.method !== 'GET') {
772
783
  authId = id;
773
784
  break;
774
785
  }
775
786
  }
776
- const authReq = authId !== null ? after.get(authId) : null;
777
- const authAt = authReq?.at ?? submitMark;
787
+ const authReq = authId === null ? null : requests.get(authId);
778
788
  const now = await evaluate(INSPECT_EXPR);
779
789
  const domJudgment = judgeRenderedDom(now?.html ?? '');
780
790
  const leftAuthWall = !(now?.hasPassword ?? false) || (now?.pathname ?? '') !== before.pathname;
@@ -795,7 +805,7 @@ export async function driveSession(cdp, { url, credentials, judge, quietMs }) {
795
805
  lastActivity = Date.now();
796
806
  await settle(() => lastActivity, RE_NAV_CAP_MS, quietMs);
797
807
  }
798
- return judge(facts(sessionLog(authId, authAt), {
808
+ return judge(facts(sessionLog(authId, submitSeq), {
799
809
  submitted: true,
800
810
  foreignOriginFailures: foreignOriginFailures(),
801
811
  leftAuthWall,
@@ -87,7 +87,7 @@ export interface EcosystemProfile {
87
87
  /**
88
88
  * Packages whose declarations belong in THIS package's index, because this
89
89
  * package exports names it does not declare — `hspec`/`hspec-core`,
90
- * `axum`/`axum-core`; see DEFECT-12-STOPPING-RULE.md.
90
+ * `axum`/`axum-core`.
91
91
  */
92
92
  supplements?: (pkg: ResolvedPackage, cwd: string, io: EcosystemIo) => Promise<ResolvedPackage[]>;
93
93
  /**
@@ -312,8 +312,9 @@ function ingestBody(cache, pkg, profile, contentHash, supplements = []) {
312
312
  }
313
313
  }
314
314
  // A facade package indexes to a table of contents: `hspec` is 14 chunks of
315
- // export lists and every signature is in `hspec-core`. Fill only the holes
316
- // see DEFECT-12-STOPPING-RULE.md for the boundary and why it stops here.
315
+ // export lists and every signature is in `hspec-core`. Fill only the holes,
316
+ // and only one hop out: after one hop hspec has zero unresolved names left,
317
+ // and no package measured had anything for a second hop to fetch.
317
318
  const found = supplements.length > 0 ? (profile.exportGap?.(pkg.root) ?? null) : null;
318
319
  const gap = found !== null && !found.empty ? found : null;
319
320
  for (const sup of gap === null ? [] : supplements) {
@@ -122,7 +122,7 @@ export declare function manifestCrates(cwd: string): Set<string> | undefined;
122
122
  * The trigger is the hole, with no threshold — measured, and for the same reason
123
123
  * as hackage: across twenty-two crates the unresolved fraction reads 100% on a
124
124
  * crate with one re-export and 0% on a crate with none, so a ratio separates
125
- * nothing. See "Defect 16" in DOC_REGRESSINONS.md for the sweep.
125
+ * nothing.
126
126
  */
127
127
  export declare function cargoExportGap(root: string): ExportGap;
128
128
  /**
@@ -869,7 +869,7 @@ export function manifestCrates(cwd) {
869
869
  }
870
870
  return out;
871
871
  }
872
- // ── the facade gap (DEFECT-12-STOPPING-RULE.md, cargo half) ─────────────────
872
+ // ── the facade gap, cargo half ──────────────────────────────────────────────
873
873
  /** A `pub use …;` statement, attributes and line breaks included. */
874
874
  const PUB_USE_RE = /\bpub\s+use\s+([^;]+);/g;
875
875
  /** Every item head that introduces a name, visibility ignored — a facade may
@@ -995,7 +995,7 @@ function moduleOfPath(relPath) {
995
995
  * The trigger is the hole, with no threshold — measured, and for the same reason
996
996
  * as hackage: across twenty-two crates the unresolved fraction reads 100% on a
997
997
  * crate with one re-export and 0% on a crate with none, so a ratio separates
998
- * nothing. See "Defect 16" in DOC_REGRESSINONS.md for the sweep.
998
+ * nothing.
999
999
  */
1000
1000
  export function cargoExportGap(root) {
1001
1001
  const deps = runtimeDeps(root);
@@ -600,8 +600,9 @@ export function manifestPackages(cwd) {
600
600
  * re-export puts the name in the export list; a `module X` re-export puts
601
601
  * nothing there at all, which is why `shouldBe` is invisible to the first.
602
602
  *
603
- * See DEFECT-12-STOPPING-RULE.md for why this triggers on the hole itself
604
- * rather than on a fraction of the export list.
603
+ * The trigger is the hole, with no threshold. Swept over the 299 modules with
604
+ * 5+ exports, the trigger count reads 33 at 50% and 18 at 95%, so the fraction
605
+ * is not carrying the decision and any value picked would just sound right.
605
606
  */
606
607
  const EXPORT_NAME_RE = /^[A-Za-z_][\w']*$/;
607
608
  /** `module X` inside an export list is a re-export; `Prelude` is base, and base is not fetched. */
@@ -4,8 +4,8 @@
4
4
  * `hspec` indexes to a table of contents and every signature is in `hspec-core`;
5
5
  * `axum` re-exports `IntoResponse` and the trait lives in `axum-core`. Both are
6
6
  * the same failure — a query retrieves the package's own chunks and not one of
7
- * them defines the thing asked about — and DEFECT-12-STOPPING-RULE.md fixes the
8
- * boundary for following the re-export.
7
+ * them defines the thing asked about — so the re-export is followed exactly one
8
+ * hop, to a dependency the package's own name prefixes.
9
9
  *
10
10
  * The boundary is shared; the parsing is not. Haskell states the gap in an export
11
11
  * list, Rust in `pub use`, so each ecosystem answers the same three questions in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjasnikovs/pi-task",
3
- "version": "0.40.33",
3
+ "version": "0.40.35",
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",