pi-harness-runtime 1.1.467 → 1.1.469

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.
Files changed (55) hide show
  1. package/AGENTS.md +52 -5
  2. package/CHANGELOG.md +93 -0
  3. package/package.json +1 -1
  4. package/packages/agent-policy/package.json +1 -1
  5. package/packages/auth/package.json +1 -1
  6. package/packages/autonomous-runtime/package.json +1 -1
  7. package/packages/checkpoint/package.json +1 -1
  8. package/packages/clipboard/package.json +1 -1
  9. package/packages/codex-watcher/package.json +1 -1
  10. package/packages/config-capture/package.json +1 -1
  11. package/packages/contracts/dist/workspace-env-format.d.ts +75 -0
  12. package/packages/contracts/dist/workspace-env-format.js +125 -12
  13. package/packages/contracts/dist/workspace-env.d.ts +24 -0
  14. package/packages/contracts/dist/workspace-env.js +439 -19
  15. package/packages/contracts/package.json +1 -1
  16. package/packages/contracts/src/workspace-env-format.ts +209 -12
  17. package/packages/contracts/src/workspace-env.ts +458 -20
  18. package/packages/cookie-sanitizer/package.json +1 -1
  19. package/packages/evaluation-engine/package.json +1 -1
  20. package/packages/event-bus/package.json +1 -1
  21. package/packages/event-store/package.json +1 -1
  22. package/packages/experience-replay/package.json +1 -1
  23. package/packages/file-copy-helper/package.json +1 -1
  24. package/packages/intent-analyzer/package.json +1 -1
  25. package/packages/jev-judge/dist/decision-context.d.ts +12 -0
  26. package/packages/jev-judge/dist/decision-context.d.ts.map +1 -1
  27. package/packages/jev-judge/dist/decision-context.js +144 -9
  28. package/packages/jev-judge/dist/decision-context.js.map +1 -1
  29. package/packages/jev-judge/package.json +1 -1
  30. package/packages/jev-judge/src/decision-context.ts +156 -8
  31. package/packages/knowledge-retrieval/package.json +1 -1
  32. package/packages/learning-engine/package.json +1 -1
  33. package/packages/logging/package.json +1 -1
  34. package/packages/memory-engine/package.json +1 -1
  35. package/packages/notification/package.json +1 -1
  36. package/packages/paperclip-integration/package.json +1 -1
  37. package/packages/performance-optimizer/package.json +1 -1
  38. package/packages/privilege-broker/package.json +1 -1
  39. package/packages/prompt-compiler/package.json +1 -1
  40. package/packages/providers/package.json +1 -1
  41. package/packages/qdrant-skills/package.json +1 -1
  42. package/packages/quota-manager/package.json +1 -1
  43. package/packages/relay/package.json +1 -1
  44. package/packages/skill-mcp-client/package.json +1 -1
  45. package/packages/skills/package.json +1 -1
  46. package/packages/todo-bd-sync/package.json +1 -1
  47. package/packages/token-estimation/package.json +1 -1
  48. package/packages/tooling-preference/package.json +1 -1
  49. package/packages/trajectory/package.json +1 -1
  50. package/packages/tui/package.json +1 -1
  51. package/packages/two-phase-review/package.json +1 -1
  52. package/packages/types/package.json +1 -1
  53. package/packages/webmcp-tester/package.json +1 -1
  54. package/packages/wiki/package.json +1 -1
  55. package/packages/write-review/package.json +1 -1
@@ -467,6 +467,16 @@ export interface ModeResolution {
467
467
  mode: WorkspaceMode;
468
468
  hint: DotenvVar | null;
469
469
  source: "process.env" | ".env file" | null;
470
+ /**
471
+ * The variable decides the mode.
472
+ *
473
+ * A variable whose value names a known mode always decides. A variable
474
+ * whose value names no known mode ("staging", a virtualenv path) only
475
+ * decides when it is an explicit NODE_ENV: the shape of the checkout may
476
+ * still name the mode, and a deliberate "staging" must not be replaced by
477
+ * it.
478
+ */
479
+ decides?: boolean;
470
480
  }
471
481
 
472
482
  /**
@@ -561,6 +571,166 @@ export function modeFromRepositoryFacts(facts: RepositoryFacts): RepositoryModeD
561
571
  return null;
562
572
  }
563
573
 
574
+ /**
575
+ * The facts about a Frappe bench the workspace belongs to.
576
+ *
577
+ * A bench is the runtime of a Frappe site, and it says much more about the
578
+ * environment than a single flag. `developer_mode` in
579
+ * `sites/common_site_config.json` says that the developer conveniences are
580
+ * on - it does NOT say that the server is a development server. A bench that
581
+ * supervisor and nginx manage is a deployed bench, a bench that runs a
582
+ * development server is a bench somebody works on.
583
+ */
584
+ export interface FrappeBenchFacts {
585
+ /** The bench root ("" when the workspace is not inside a bench). */
586
+ benchRoot: string;
587
+ /**
588
+ * The `developer_mode` of the bench.
589
+ *
590
+ * null when the bench does not declare it.
591
+ */
592
+ developerMode: boolean | null;
593
+ /** A site of the bench is in maintenance mode. */
594
+ maintenanceMode: boolean | null;
595
+ /** The bench reloads the code on a change ("live_reload"). */
596
+ liveReload: boolean;
597
+ /** The scheduled jobs of the bench are paused ("pause_scheduler"). */
598
+ pauseScheduler: boolean;
599
+ /** A supervisor program group manages the bench. */
600
+ supervisorManaged: boolean;
601
+ /** Nginx serves the bench. */
602
+ nginxManaged: boolean;
603
+ /** The bench carries a deployment configuration (Dockerfile, compose, ...). */
604
+ deploymentMarker: boolean;
605
+ /** A development server of the bench runs ("bench serve"). */
606
+ devServerRunning: boolean;
607
+ /** A production-style run of the bench is active ("bench start"). */
608
+ productionRun: boolean;
609
+ /** The branch of the checkout the workspace belongs to ("" when unknown). */
610
+ branch: string;
611
+ }
612
+
613
+ /**
614
+ * A mode that the facts about a Frappe bench named.
615
+ */
616
+ export interface FrappeBenchModeDetection {
617
+ mode: WorkspaceMode;
618
+ /** The phrase that names the detection ("frappe bench: supervisor, nginx"). */
619
+ key: string;
620
+ }
621
+
622
+ /**
623
+ * The strength of a signal of a bench.
624
+ *
625
+ * A strong signal is a fact about the way the bench RUNS (supervisor
626
+ * manages it, nginx serves it, a development server runs). A medium signal
627
+ * is a fact about its configuration (developer_mode on, a site in
628
+ * maintenance, a deployment configuration). A weak signal is a fact that a
629
+ * developer may change without noticing (developer_mode off).
630
+ */
631
+ type BenchSignalStrength = "weak" | "medium" | "strong";
632
+
633
+ const BENCH_SIGNAL_WEIGHT: Record<BenchSignalStrength, number> = {
634
+ weak: 1,
635
+ medium: 2,
636
+ strong: 3,
637
+ };
638
+
639
+ interface BenchSignal {
640
+ reason: string;
641
+ strength: BenchSignalStrength;
642
+ }
643
+
644
+ /**
645
+ * Name the mode of a workspace from the facts about its Frappe bench.
646
+ *
647
+ * The bench is the runtime of a site, so its facts are stronger than the
648
+ * shape of the checkout. The signals are weighed:
649
+ *
650
+ * - a strong signal decides (supervisor, nginx, a running development
651
+ * server). Two strong signals of opposite kinds are a conflict: no mode is
652
+ * claimed, because the facts contradict each other.
653
+ * - otherwise the sum of the weights decides: the configuration of the bench
654
+ * (developer_mode, a site in maintenance, a deployment configuration, the
655
+ * branch) against the way it runs.
656
+ * - a tie is no claim: the bench does not say which environment it is.
657
+ *
658
+ * `developer_mode` is deliberately not a strong signal: a production bench
659
+ * with the flag left on is still a production bench, and a development bench
660
+ * with the flag off is still a development bench.
661
+ */
662
+ export function modeFromFrappeBenchFacts(
663
+ facts: FrappeBenchFacts,
664
+ ): FrappeBenchModeDetection | null {
665
+ if (!facts.benchRoot) return null;
666
+
667
+ const { development, production } = benchSignals(facts);
668
+ const strongDevelopment = development.filter((signal) => signal.strength === "strong");
669
+ const strongProduction = production.filter((signal) => signal.strength === "strong");
670
+ // A contradiction is not a mode: the facts say both, so nothing is claimed.
671
+ if (strongDevelopment.length > 0 && strongProduction.length > 0) return null;
672
+
673
+ const score = (signals: BenchSignal[]): number =>
674
+ signals.reduce((total, signal) => total + BENCH_SIGNAL_WEIGHT[signal.strength], 0);
675
+ const developmentScore = score(development);
676
+ const productionScore = score(production);
677
+ if (developmentScore === productionScore) return null;
678
+
679
+ const deciding = developmentScore > productionScore ? development : production;
680
+ const mode = developmentScore > productionScore ? "development" : "production";
681
+ return {
682
+ mode,
683
+ key: `frappe bench: ${deciding.map((signal) => signal.reason).join(", ")}`,
684
+ };
685
+ }
686
+
687
+ /**
688
+ * The signals of a bench, grouped by the environment they name.
689
+ */
690
+ function benchSignals(facts: FrappeBenchFacts): {
691
+ development: BenchSignal[];
692
+ production: BenchSignal[];
693
+ } {
694
+ const development: BenchSignal[] = [];
695
+ const production: BenchSignal[] = [];
696
+
697
+ if (facts.developerMode === true) {
698
+ development.push({ reason: "developer_mode on", strength: "medium" });
699
+ }
700
+ if (facts.developerMode === false) {
701
+ production.push({ reason: "developer_mode off", strength: "weak" });
702
+ }
703
+ if (facts.devServerRunning) {
704
+ development.push({ reason: "development server running", strength: "strong" });
705
+ }
706
+ if (facts.productionRun) {
707
+ production.push({ reason: "bench start running", strength: "medium" });
708
+ }
709
+ if (facts.supervisorManaged) {
710
+ production.push({ reason: "supervisor", strength: "strong" });
711
+ }
712
+ if (facts.nginxManaged) {
713
+ production.push({ reason: "nginx", strength: "strong" });
714
+ }
715
+ if (facts.maintenanceMode === true) {
716
+ production.push({ reason: "site in maintenance mode", strength: "medium" });
717
+ }
718
+ if (facts.liveReload) {
719
+ development.push({ reason: "live reload on", strength: "medium" });
720
+ }
721
+ if (facts.pauseScheduler) {
722
+ development.push({ reason: "scheduler paused", strength: "weak" });
723
+ }
724
+ if (facts.deploymentMarker) {
725
+ production.push({ reason: "deployment configuration", strength: "medium" });
726
+ }
727
+ const branch = facts.branch.trim().toLowerCase();
728
+ if (DEVELOPMENT_BRANCHES.has(branch)) {
729
+ development.push({ reason: `git branch ${branch}`, strength: "medium" });
730
+ }
731
+ return { development, production };
732
+ }
733
+
564
734
  /**
565
735
  * Resolve the workspace mode from the variables that were found.
566
736
  *
@@ -580,19 +750,26 @@ export function resolveWorkspaceMode(
580
750
  const processNodeEnv = processVars.find((v) => v.key === "NODE_ENV");
581
751
  if (processNodeEnv) {
582
752
  const mode = modeFromValue(processNodeEnv.value);
583
- if (mode) return { mode, hint: processNodeEnv, source: "process.env" };
753
+ if (mode) return { mode, hint: processNodeEnv, source: "process.env", decides: true };
584
754
  // An explicit NODE_ENV that names no known mode decides: the mode
585
755
  // stays unknown instead of falling through to the files.
586
- return { mode: "unknown", hint: processNodeEnv, source: "process.env" };
756
+ return { mode: "unknown", hint: processNodeEnv, source: "process.env", decides: true };
587
757
  }
588
758
  const dotenvHint = detectModeHint(dotenvVars, { allowValueMatch: true });
589
759
  if (dotenvHint) {
590
760
  const mode = modeFromValue(dotenvHint.value);
591
- if (mode) return { mode, hint: dotenvHint, source: ".env file" };
592
- // The workspace file is explicit - even when its value names no known
593
- // mode ("APP_MODE=staging"). It must not be replaced by an unrelated
594
- // variable of the process env.
595
- return { mode: "unknown", hint: dotenvHint, source: ".env file" };
761
+ if (mode) return { mode, hint: dotenvHint, source: ".env file", decides: true };
762
+ // The workspace file is the declaration of the workspace: a value that
763
+ // names a known mode decides. A value that names no known mode
764
+ // ("APP_MODE=staging") does not decide - unless it is an explicit
765
+ // NODE_ENV, which is a deliberate value.
766
+ const explicit = dotenvHint.key === "NODE_ENV";
767
+ return {
768
+ mode: "unknown",
769
+ hint: dotenvHint,
770
+ source: ".env file",
771
+ decides: explicit,
772
+ };
596
773
  }
597
774
  // Last resort: an environment shaped key of the process env (the files
598
775
  // are silent).
@@ -601,10 +778,14 @@ export function resolveWorkspaceMode(
601
778
  );
602
779
  if (processEnvHint) {
603
780
  const mode = modeFromValue(processEnvHint.value);
604
- if (mode) return { mode, hint: processEnvHint, source: "process.env" };
605
- return { mode: "unknown", hint: processEnvHint, source: "process.env" };
781
+ if (mode) return { mode, hint: processEnvHint, source: "process.env", decides: true };
782
+ // The value names no known mode, so the variable does not decide: a
783
+ // virtualenv path (VIRTUAL_ENV) says nothing about the environment
784
+ // of the workspace, and the facts about the repository may still
785
+ // name the mode.
786
+ return { mode: "unknown", hint: processEnvHint, source: "process.env", decides: false };
606
787
  }
607
- return { mode: "unknown", hint: null, source: null };
788
+ return { mode: "unknown", hint: null, source: null, decides: false };
608
789
  }
609
790
 
610
791
  /**
@@ -643,11 +824,28 @@ function findDetectionEvidence(env: WorkspaceEnvResult): EnvEvidence | undefined
643
824
  export function describeWorkspaceMode(env: WorkspaceEnvResult): string {
644
825
  const hint = findModeEvidence(env);
645
826
  const where = hint?.file ? ` in ${hint.file}` : "";
827
+ const detection = findDetectionEvidence(env);
828
+ // A variable decides only when its value names a known mode. When the
829
+ // repository named the mode instead, the variable was seen but did not
830
+ // decide, and the label says so.
831
+ const hintDecides = hint ? modeFromValue(hint.value) !== null : false;
646
832
  if (env.mode !== "unknown") {
833
+ if (detection && !hintDecides) {
834
+ const named = modeFromValue(detection.value);
835
+ if (named) {
836
+ // The variable was seen but did not decide: the label names it,
837
+ // so the reason for the mode stays visible.
838
+ let note = "";
839
+ if (hint) {
840
+ const state = hint.value ? "names no known mode" : "is empty";
841
+ note = `; ${hint.key}${where} ${state}`;
842
+ }
843
+ return `${env.mode.toUpperCase()} (${detection.key}${note})`;
844
+ }
845
+ }
647
846
  if (hint) return `${env.mode.toUpperCase()} (from ${hint.key}${where})`;
648
847
  // The mode came from the repository, not from a variable: the label
649
848
  // names the reason ("DEVELOPMENT (source-only repository)").
650
- const detection = findDetectionEvidence(env);
651
849
  if (detection) return `${env.mode.toUpperCase()} (${detection.key})`;
652
850
  return env.mode.toUpperCase();
653
851
  }
@@ -668,7 +866,6 @@ export function describeWorkspaceMode(env: WorkspaceEnvResult): string {
668
866
  }
669
867
  // A stale cache row can carry a detection next to an unknown mode: the
670
868
  // detection names a mode, so the mode is shown.
671
- const detection = findDetectionEvidence(env);
672
869
  if (detection) {
673
870
  const named = modeFromValue(detection.value);
674
871
  if (named) return `${named.toUpperCase()} (${detection.key})`;