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.
- package/AGENTS.md +52 -5
- package/CHANGELOG.md +93 -0
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/dist/workspace-env-format.d.ts +75 -0
- package/packages/contracts/dist/workspace-env-format.js +125 -12
- package/packages/contracts/dist/workspace-env.d.ts +24 -0
- package/packages/contracts/dist/workspace-env.js +439 -19
- package/packages/contracts/package.json +1 -1
- package/packages/contracts/src/workspace-env-format.ts +209 -12
- package/packages/contracts/src/workspace-env.ts +458 -20
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/decision-context.d.ts +12 -0
- package/packages/jev-judge/dist/decision-context.d.ts.map +1 -1
- package/packages/jev-judge/dist/decision-context.js +144 -9
- package/packages/jev-judge/dist/decision-context.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/decision-context.ts +156 -8
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -15,9 +15,9 @@ import { homedir as osHomedir } from "node:os";
|
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
16
|
import { execSync } from "child_process";
|
|
17
17
|
import { existsSync, readFileSync, readdirSync, mkdirSync, readlinkSync, realpathSync } from "fs";
|
|
18
|
-
import { join } from "path";
|
|
18
|
+
import { dirname, join, resolve, sep } from "path";
|
|
19
19
|
import { platform, totalmem, freemem } from "os";
|
|
20
|
-
import { canShowModeValue, collectDotenvVars, collectProcessEnvVars, describeCwdCommand, describeOs, describeServerState, describeWorkspaceMode, detectModeHint, DEPLOYMENT_MARKER_FILES, filterOwnPids, formatEnvForAgentResult, formatEnvStatusLine as formatStatusLine, formatWorkspacePath, isLauncherCommand, isLowRamWarning, MASKED_MODE_VALUE, MIN_BUILD_HEADROOM_GB, modeFromRepositoryFacts, modeFromValue, orderDotenvFileNames, parseDotenvVars, resolveWorkspaceMode, } from "./workspace-env-format.js";
|
|
20
|
+
import { canShowModeValue, collectDotenvVars, collectProcessEnvVars, describeCwdCommand, describeOs, describeServerState, describeWorkspaceMode, detectModeHint, DEPLOYMENT_MARKER_FILES, filterOwnPids, formatEnvForAgentResult, formatEnvStatusLine as formatStatusLine, formatWorkspacePath, isLauncherCommand, isLowRamWarning, MASKED_MODE_VALUE, MIN_BUILD_HEADROOM_GB, modeFromFrappeBenchFacts, modeFromRepositoryFacts, modeFromValue, orderDotenvFileNames, parseDotenvVars, resolveWorkspaceMode, } from "./workspace-env-format.js";
|
|
21
21
|
import { readDotenvFiles } from "./workspace-dotenv.js";
|
|
22
22
|
const STORE_DIR = join(process.env.HOME || osHomedir(), ".pi-harness-runtime");
|
|
23
23
|
/**
|
|
@@ -541,26 +541,164 @@ function detectPackageManager(workspacePath) {
|
|
|
541
541
|
return null;
|
|
542
542
|
}
|
|
543
543
|
/**
|
|
544
|
-
* The
|
|
544
|
+
* The directories that never hold a repository of their own.
|
|
545
545
|
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
546
|
+
* A search for a repository below the workspace must not walk into a build
|
|
547
|
+
* output or a dependency tree: those directories hold thousands of files and
|
|
548
|
+
* no repository.
|
|
549
549
|
*/
|
|
550
|
-
|
|
550
|
+
const REPOSITORY_SEARCH_SKIP = new Set([
|
|
551
|
+
".git",
|
|
552
|
+
"node_modules",
|
|
553
|
+
".venv",
|
|
554
|
+
"venv",
|
|
555
|
+
"env",
|
|
556
|
+
"dist",
|
|
557
|
+
"build",
|
|
558
|
+
"out",
|
|
559
|
+
"target",
|
|
560
|
+
".next",
|
|
561
|
+
".nuxt",
|
|
562
|
+
".cache",
|
|
563
|
+
".tox",
|
|
564
|
+
"vendor",
|
|
565
|
+
"__pycache__",
|
|
566
|
+
".mypy_cache",
|
|
567
|
+
".pytest_cache",
|
|
568
|
+
]);
|
|
569
|
+
/**
|
|
570
|
+
* The deepest level below the workspace that is searched for a repository.
|
|
571
|
+
*
|
|
572
|
+
* Two levels cover the shapes that matter: a folder of applications
|
|
573
|
+
* ("apps/store") and a repository inside one of them ("apps/store/web"
|
|
574
|
+
* with the repository one level above).
|
|
575
|
+
*/
|
|
576
|
+
const REPOSITORY_SEARCH_DEPTH = 2;
|
|
577
|
+
/**
|
|
578
|
+
* The most directories that are read during the search.
|
|
579
|
+
*
|
|
580
|
+
* The search is bounded so a workspace with many folders cannot slow the
|
|
581
|
+
* startup down. A directory that holds a repository is found whatever its
|
|
582
|
+
* position is, as long as the search has not read that many directories.
|
|
583
|
+
*/
|
|
584
|
+
const REPOSITORY_SEARCH_CANDIDATES = 64;
|
|
585
|
+
/**
|
|
586
|
+
* The branch of a checkout ("" when it cannot be read).
|
|
587
|
+
*/
|
|
588
|
+
function gitBranch(directory) {
|
|
551
589
|
try {
|
|
552
|
-
const out = execSync("git rev-parse --
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
590
|
+
const out = execSync("git rev-parse --abbrev-ref HEAD 2>/dev/null", {
|
|
591
|
+
cwd: directory,
|
|
592
|
+
encoding: "utf8",
|
|
593
|
+
timeout: 1500,
|
|
594
|
+
});
|
|
595
|
+
const branch = out.trim();
|
|
556
596
|
// A detached HEAD reports "HEAD" - that is not a branch name.
|
|
557
|
-
return
|
|
597
|
+
return branch === "HEAD" ? "" : branch;
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
return "";
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* The repository of a directory, through its parents.
|
|
605
|
+
*/
|
|
606
|
+
function gitFactsIn(directory) {
|
|
607
|
+
try {
|
|
608
|
+
const out = execSync("git rev-parse --show-toplevel 2>/dev/null", {
|
|
609
|
+
cwd: directory,
|
|
610
|
+
encoding: "utf8",
|
|
611
|
+
timeout: 1500,
|
|
612
|
+
});
|
|
613
|
+
const root = out.trim();
|
|
614
|
+
if (!root)
|
|
615
|
+
return { root: "", branch: "" };
|
|
616
|
+
return { root, branch: gitBranch(root) };
|
|
558
617
|
}
|
|
559
618
|
catch {
|
|
560
619
|
// No git, no repository, or a timeout: nothing is known.
|
|
561
620
|
return { root: "", branch: "" };
|
|
562
621
|
}
|
|
563
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* The child of a workspace that holds a repository.
|
|
625
|
+
*
|
|
626
|
+
* A workspace is often the folder above the repository: the root of a
|
|
627
|
+
* monorepo, a directory of applications, a directory of workspaces. The
|
|
628
|
+
* repository of such a workspace is below it, and the search finds the
|
|
629
|
+
* nearest one in a stable order.
|
|
630
|
+
*
|
|
631
|
+
* @param workspacePath The workspace
|
|
632
|
+
* @returns The directory that holds the repository ("" when there is none)
|
|
633
|
+
*/
|
|
634
|
+
export function findRepositoryChild(workspacePath) {
|
|
635
|
+
return findChildDirectory(workspacePath, (directory) => existsSync(join(directory, ".git")));
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* The child of a workspace that matches a predicate.
|
|
639
|
+
*
|
|
640
|
+
* A workspace is often the folder above the repository: the root of a
|
|
641
|
+
* monorepo, a directory of applications, a directory of workspaces. The
|
|
642
|
+
* nearest match in a stable order is returned.
|
|
643
|
+
*
|
|
644
|
+
* @param workspacePath The workspace
|
|
645
|
+
* @param matches The predicate of a directory
|
|
646
|
+
* @returns The directory that matches ("" when there is none)
|
|
647
|
+
*/
|
|
648
|
+
export function findChildDirectory(workspacePath, matches) {
|
|
649
|
+
let candidates = 0;
|
|
650
|
+
let level = [workspacePath];
|
|
651
|
+
for (let depth = 0; depth < REPOSITORY_SEARCH_DEPTH && level.length > 0; depth += 1) {
|
|
652
|
+
const next = [];
|
|
653
|
+
for (const directory of level) {
|
|
654
|
+
let names;
|
|
655
|
+
try {
|
|
656
|
+
names = readdirSync(directory, { withFileTypes: true })
|
|
657
|
+
.filter((entry) => entry.isDirectory() && !REPOSITORY_SEARCH_SKIP.has(entry.name))
|
|
658
|
+
.map((entry) => entry.name)
|
|
659
|
+
.sort();
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
// An unreadable directory proves nothing.
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
for (const name of names) {
|
|
666
|
+
if (candidates >= REPOSITORY_SEARCH_CANDIDATES)
|
|
667
|
+
return "";
|
|
668
|
+
candidates += 1;
|
|
669
|
+
const child = join(directory, name);
|
|
670
|
+
if (matches(child))
|
|
671
|
+
return child;
|
|
672
|
+
next.push(child);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
level = next;
|
|
676
|
+
}
|
|
677
|
+
return "";
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* The git repository of a workspace.
|
|
681
|
+
*
|
|
682
|
+
* The repository is looked for in three places:
|
|
683
|
+
* 1. the workspace itself - `git rev-parse` walks up, so a folder inside a
|
|
684
|
+
* repository finds the repository of its parent
|
|
685
|
+
* 2. a child of the workspace, when the workspace is not in a repository
|
|
686
|
+
*
|
|
687
|
+
* The root of the repository is the unit of the detection: a package
|
|
688
|
+
* published from a monorepo is described by the root, not by the folder
|
|
689
|
+
* the harness happens to run in.
|
|
690
|
+
*/
|
|
691
|
+
function detectGitFacts(workspacePath) {
|
|
692
|
+
const own = gitFactsIn(workspacePath);
|
|
693
|
+
if (own.root)
|
|
694
|
+
return own;
|
|
695
|
+
// The workspace is not in a repository. It may hold one: a directory of
|
|
696
|
+
// applications, a monorepo root.
|
|
697
|
+
const child = findRepositoryChild(workspacePath);
|
|
698
|
+
if (!child)
|
|
699
|
+
return { root: "", branch: "" };
|
|
700
|
+
return { root: child, branch: gitBranch(child) };
|
|
701
|
+
}
|
|
564
702
|
/**
|
|
565
703
|
* True when the package is published to a registry.
|
|
566
704
|
*
|
|
@@ -631,6 +769,266 @@ function detectRepositoryFacts(workspacePath, hasRunningServer) {
|
|
|
631
769
|
hasRunningServer,
|
|
632
770
|
};
|
|
633
771
|
}
|
|
772
|
+
/**
|
|
773
|
+
* The configuration file of a Frappe bench.
|
|
774
|
+
*
|
|
775
|
+
* The file is the marker of a bench: every bench has one, and it holds the
|
|
776
|
+
* configuration that is shared by all its sites.
|
|
777
|
+
*/
|
|
778
|
+
const FRAPPE_BENCH_CONFIG = join("sites", "common_site_config.json");
|
|
779
|
+
/**
|
|
780
|
+
* The deepest level of parents that is searched for a bench.
|
|
781
|
+
*/
|
|
782
|
+
const MAX_PARENT_DEPTH = 12;
|
|
783
|
+
/**
|
|
784
|
+
* The directories that hold the configuration of a supervisor program group.
|
|
785
|
+
*/
|
|
786
|
+
const SUPERVISOR_CONFIG_DIRS = ["/etc/supervisor/conf.d", "/etc/supervisor"];
|
|
787
|
+
/**
|
|
788
|
+
* The directories that hold the configuration of an nginx site.
|
|
789
|
+
*/
|
|
790
|
+
const NGINX_CONFIG_DIRS = ["/etc/nginx/conf.d", "/etc/nginx/sites-enabled"];
|
|
791
|
+
/**
|
|
792
|
+
* The most site configurations of a bench that are read.
|
|
793
|
+
*/
|
|
794
|
+
const MAX_BENCH_SITES = 10;
|
|
795
|
+
/**
|
|
796
|
+
* The workspace and its parents.
|
|
797
|
+
*
|
|
798
|
+
* The workspace of a bench is usually inside the bench (the bench holds its
|
|
799
|
+
* apps), so the parents have to be searched as well.
|
|
800
|
+
*/
|
|
801
|
+
function workspaceAndParents(workspacePath) {
|
|
802
|
+
const directories = [];
|
|
803
|
+
let current = resolve(workspacePath);
|
|
804
|
+
for (let depth = 0; depth < MAX_PARENT_DEPTH; depth += 1) {
|
|
805
|
+
directories.push(current);
|
|
806
|
+
const parent = dirname(current);
|
|
807
|
+
if (parent === current)
|
|
808
|
+
break;
|
|
809
|
+
current = parent;
|
|
810
|
+
}
|
|
811
|
+
return directories;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* A JSON file as an object (null when it cannot be read or parsed).
|
|
815
|
+
*/
|
|
816
|
+
function readJsonFile(path) {
|
|
817
|
+
try {
|
|
818
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
819
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
820
|
+
return null;
|
|
821
|
+
return parsed;
|
|
822
|
+
}
|
|
823
|
+
catch {
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* A boolean field of a configuration file.
|
|
829
|
+
*
|
|
830
|
+
* Frappe writes "1" and "0", but a JSON file may hold a real boolean. A
|
|
831
|
+
* field that is absent or holds anything else is no claim.
|
|
832
|
+
*/
|
|
833
|
+
function booleanField(config, key) {
|
|
834
|
+
if (!config)
|
|
835
|
+
return null;
|
|
836
|
+
const value = config[key];
|
|
837
|
+
if (value === true || value === 1)
|
|
838
|
+
return true;
|
|
839
|
+
if (value === false || value === 0)
|
|
840
|
+
return false;
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* The sites of a bench.
|
|
845
|
+
*/
|
|
846
|
+
function frappeSiteNames(benchRoot) {
|
|
847
|
+
try {
|
|
848
|
+
return readdirSync(join(benchRoot, "sites"), { withFileTypes: true })
|
|
849
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
850
|
+
.map((entry) => entry.name)
|
|
851
|
+
.sort()
|
|
852
|
+
.slice(0, MAX_BENCH_SITES);
|
|
853
|
+
}
|
|
854
|
+
catch {
|
|
855
|
+
return [];
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* A site of the bench is in maintenance mode.
|
|
860
|
+
*/
|
|
861
|
+
function siteMaintenanceMode(benchRoot) {
|
|
862
|
+
for (const site of frappeSiteNames(benchRoot)) {
|
|
863
|
+
const config = readJsonFile(join(benchRoot, "sites", site, "site_config.json"));
|
|
864
|
+
if (booleanField(config, "maintenance_mode") === true)
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
return null;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Does a configuration directory mention one of the needles?
|
|
871
|
+
*
|
|
872
|
+
* The production setup of a bench is written into the configuration of the
|
|
873
|
+
* process manager (supervisor) and of the web server (nginx): those files
|
|
874
|
+
* name the bench, not the other way round.
|
|
875
|
+
*/
|
|
876
|
+
function configMentions(directories, needles) {
|
|
877
|
+
const wanted = needles.filter((needle) => needle.length > 0);
|
|
878
|
+
if (wanted.length === 0)
|
|
879
|
+
return false;
|
|
880
|
+
for (const directory of directories) {
|
|
881
|
+
let entries;
|
|
882
|
+
try {
|
|
883
|
+
entries = readdirSync(directory);
|
|
884
|
+
}
|
|
885
|
+
catch {
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
for (const entry of entries.slice(0, 64)) {
|
|
889
|
+
if (!entry.endsWith(".conf"))
|
|
890
|
+
continue;
|
|
891
|
+
let content;
|
|
892
|
+
try {
|
|
893
|
+
content = readFileSync(join(directory, entry), "utf8");
|
|
894
|
+
}
|
|
895
|
+
catch {
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (wanted.some((needle) => content.includes(needle)))
|
|
899
|
+
return true;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Does a process belong to a bench?
|
|
906
|
+
*
|
|
907
|
+
* The working directory of the process is the strongest evidence (Linux
|
|
908
|
+
* exposes it); otherwise the command line must name the bench.
|
|
909
|
+
*/
|
|
910
|
+
function processBelongsToBench(pid, benchRoot) {
|
|
911
|
+
if (platform() === "linux") {
|
|
912
|
+
try {
|
|
913
|
+
const cwd = readlinkSync(`/proc/${pid}/cwd`);
|
|
914
|
+
return cwd === benchRoot || cwd.startsWith(benchRoot + sep);
|
|
915
|
+
}
|
|
916
|
+
catch {
|
|
917
|
+
// The process is gone or its directory cannot be read.
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const cmdline = processCmdline(pid);
|
|
921
|
+
return cmdline.includes(benchRoot);
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* The processes of a bench.
|
|
925
|
+
*
|
|
926
|
+
* "bench serve" is the development server of a bench, "bench start" runs it
|
|
927
|
+
* the way a server runs it (web, workers, scheduler).
|
|
928
|
+
*/
|
|
929
|
+
function benchProcesses(benchRoot) {
|
|
930
|
+
const none = { dev: false, production: false };
|
|
931
|
+
const os = platform();
|
|
932
|
+
if (os !== "linux" && os !== "darwin")
|
|
933
|
+
return none;
|
|
934
|
+
if (!hasProcessTool())
|
|
935
|
+
return none;
|
|
936
|
+
try {
|
|
937
|
+
const script = `echo $$; pgrep -f ${JSON.stringify("bench (serve|start)|frappe\\.serve")} 2>/dev/null || true`;
|
|
938
|
+
const out = execSync(script, {
|
|
939
|
+
encoding: "utf8",
|
|
940
|
+
timeout: 1000,
|
|
941
|
+
});
|
|
942
|
+
const lines = out.split("\n");
|
|
943
|
+
const ownPids = [
|
|
944
|
+
String(process.pid),
|
|
945
|
+
String(process.ppid),
|
|
946
|
+
(lines[0] ?? "").trim(),
|
|
947
|
+
...ancestorPids(String(process.pid)),
|
|
948
|
+
];
|
|
949
|
+
const pids = filterOwnPids(lines.slice(1), ownPids);
|
|
950
|
+
let dev = false;
|
|
951
|
+
let production = false;
|
|
952
|
+
for (const pid of pids) {
|
|
953
|
+
const cmdline = processCmdline(pid);
|
|
954
|
+
if (!cmdline)
|
|
955
|
+
continue;
|
|
956
|
+
if (isShellExe(processExe(pid)) && /(^|\s)-c(\s|$)/.test(cmdline))
|
|
957
|
+
continue;
|
|
958
|
+
if (!processBelongsToBench(pid, benchRoot))
|
|
959
|
+
continue;
|
|
960
|
+
if (/frappe\.serve|bench\s+serve/.test(cmdline))
|
|
961
|
+
dev = true;
|
|
962
|
+
else if (/bench\s+start/.test(cmdline))
|
|
963
|
+
production = true;
|
|
964
|
+
}
|
|
965
|
+
return { dev, production };
|
|
966
|
+
}
|
|
967
|
+
catch {
|
|
968
|
+
return none;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* The bench of a workspace.
|
|
973
|
+
*
|
|
974
|
+
* The bench is the workspace itself, one of its parents (a bench holds its
|
|
975
|
+
* apps, so a workspace inside a bench is below it), or one of its children
|
|
976
|
+
* (a directory of workspaces).
|
|
977
|
+
*/
|
|
978
|
+
function findFrappeBench(workspacePath) {
|
|
979
|
+
for (const directory of workspaceAndParents(workspacePath)) {
|
|
980
|
+
if (existsSync(join(directory, FRAPPE_BENCH_CONFIG)))
|
|
981
|
+
return directory;
|
|
982
|
+
}
|
|
983
|
+
return findChildDirectory(workspacePath, (directory) => existsSync(join(directory, FRAPPE_BENCH_CONFIG)));
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* The facts about the Frappe bench of a workspace.
|
|
987
|
+
*
|
|
988
|
+
* A bench says much more about the environment than one flag: the flag says
|
|
989
|
+
* that the developer conveniences are on, the way the bench runs says
|
|
990
|
+
* whether it is a development or a deployed bench.
|
|
991
|
+
*/
|
|
992
|
+
function detectFrappeBenchFacts(workspacePath, branch) {
|
|
993
|
+
const facts = {
|
|
994
|
+
benchRoot: "",
|
|
995
|
+
developerMode: null,
|
|
996
|
+
maintenanceMode: null,
|
|
997
|
+
liveReload: false,
|
|
998
|
+
pauseScheduler: false,
|
|
999
|
+
supervisorManaged: false,
|
|
1000
|
+
nginxManaged: false,
|
|
1001
|
+
deploymentMarker: false,
|
|
1002
|
+
devServerRunning: false,
|
|
1003
|
+
productionRun: false,
|
|
1004
|
+
branch,
|
|
1005
|
+
};
|
|
1006
|
+
const benchRoot = findFrappeBench(workspacePath);
|
|
1007
|
+
if (!benchRoot)
|
|
1008
|
+
return facts;
|
|
1009
|
+
facts.benchRoot = benchRoot;
|
|
1010
|
+
const config = readJsonFile(join(benchRoot, FRAPPE_BENCH_CONFIG));
|
|
1011
|
+
facts.developerMode = booleanField(config, "developer_mode");
|
|
1012
|
+
facts.liveReload = booleanField(config, "live_reload") === true;
|
|
1013
|
+
facts.pauseScheduler = booleanField(config, "pause_scheduler") === true;
|
|
1014
|
+
// The common configuration may declare the maintenance mode, and a site
|
|
1015
|
+
// may declare it for itself.
|
|
1016
|
+
facts.maintenanceMode =
|
|
1017
|
+
booleanField(config, "maintenance_mode") === true
|
|
1018
|
+
? true
|
|
1019
|
+
: siteMaintenanceMode(benchRoot);
|
|
1020
|
+
facts.deploymentMarker = hasDeploymentConfiguration(benchRoot);
|
|
1021
|
+
const needles = [
|
|
1022
|
+
benchRoot,
|
|
1023
|
+
...frappeSiteNames(benchRoot).filter((site) => site.length >= 4),
|
|
1024
|
+
];
|
|
1025
|
+
facts.supervisorManaged = configMentions(SUPERVISOR_CONFIG_DIRS, needles);
|
|
1026
|
+
facts.nginxManaged = configMentions(NGINX_CONFIG_DIRS, needles);
|
|
1027
|
+
const processes = benchProcesses(benchRoot);
|
|
1028
|
+
facts.devServerRunning = processes.dev;
|
|
1029
|
+
facts.productionRun = processes.production;
|
|
1030
|
+
return facts;
|
|
1031
|
+
}
|
|
634
1032
|
/**
|
|
635
1033
|
* Determine workspace mode with proper precedence
|
|
636
1034
|
* Never assume production - unknown requires investigation
|
|
@@ -642,11 +1040,12 @@ function detectRepositoryFacts(workspacePath, hasRunningServer) {
|
|
|
642
1040
|
* key whose value names a known mode, then any other environment shaped
|
|
643
1041
|
* key
|
|
644
1042
|
* 3. an environment shaped key of the process env (the files are silent)
|
|
645
|
-
* 4. the facts about the
|
|
1043
|
+
* 4. the facts about a Frappe bench - the bench is the runtime of a site
|
|
1044
|
+
* 5. the facts about the repository (only when NO variable names the
|
|
646
1045
|
* environment at all) - a published source repository without a runtime
|
|
647
1046
|
* of its own is a development checkout
|
|
648
1047
|
*/
|
|
649
|
-
function determineMode(processVars, dotenvVars, evidence, repositoryFacts) {
|
|
1048
|
+
function determineMode(processVars, dotenvVars, evidence, repositoryFacts, frappeBenchFacts) {
|
|
650
1049
|
const resolved = resolveWorkspaceMode(processVars, dotenvVars);
|
|
651
1050
|
if (resolved.hint && resolved.source) {
|
|
652
1051
|
// The value is only kept when it is provably not a secret: the
|
|
@@ -660,11 +1059,31 @@ function determineMode(processVars, dotenvVars, evidence, repositoryFacts) {
|
|
|
660
1059
|
timestamp: Date.now(),
|
|
661
1060
|
file: resolved.hint.file,
|
|
662
1061
|
});
|
|
663
|
-
//
|
|
664
|
-
|
|
665
|
-
|
|
1062
|
+
// A variable whose value names a known mode decides.
|
|
1063
|
+
if (resolved.mode !== "unknown")
|
|
1064
|
+
return resolved.mode;
|
|
1065
|
+
// An explicit NODE_ENV decides even when it names no known mode
|
|
1066
|
+
// ("staging"). A deliberate value must not be replaced by the shape
|
|
1067
|
+
// of the checkout.
|
|
1068
|
+
if (resolved.decides === true)
|
|
1069
|
+
return resolved.mode;
|
|
1070
|
+
}
|
|
1071
|
+
// No variable names a known mode: the facts about the workspace may still
|
|
1072
|
+
// name it. A variable that names no known mode (VIRTUAL_ENV, a path) is a
|
|
1073
|
+
// fact about the machine, not a declaration of the environment, so it does
|
|
1074
|
+
// not keep the mode unknown when the checkout names it.
|
|
1075
|
+
// A Frappe bench comes first: the bench is the runtime of a site, so its
|
|
1076
|
+
// facts say more about the environment than the shape of a checkout.
|
|
1077
|
+
const benchDetection = modeFromFrappeBenchFacts(frappeBenchFacts);
|
|
1078
|
+
if (benchDetection) {
|
|
1079
|
+
evidence.push({
|
|
1080
|
+
source: "detection",
|
|
1081
|
+
key: benchDetection.key,
|
|
1082
|
+
value: benchDetection.mode,
|
|
1083
|
+
timestamp: Date.now(),
|
|
1084
|
+
});
|
|
1085
|
+
return benchDetection.mode;
|
|
666
1086
|
}
|
|
667
|
-
// No variable names the environment: the repository may still name it.
|
|
668
1087
|
const detection = modeFromRepositoryFacts(repositoryFacts);
|
|
669
1088
|
if (!detection)
|
|
670
1089
|
return resolved.mode;
|
|
@@ -722,7 +1141,8 @@ export function detectWorkspaceEnv(workspacePath) {
|
|
|
722
1141
|
const { dev: devServerState, build: buildServerState } = detectServerStates(workspacePath);
|
|
723
1142
|
// Determine mode - NEVER assume production
|
|
724
1143
|
const repositoryFacts = detectRepositoryFacts(workspacePath, devServerState === "running" || buildServerState === "running");
|
|
725
|
-
const
|
|
1144
|
+
const frappeBenchFacts = detectFrappeBenchFacts(workspacePath, repositoryFacts.branch);
|
|
1145
|
+
const mode = determineMode(processVars, dotenvVars, evidence, repositoryFacts, frappeBenchFacts);
|
|
726
1146
|
// Determine build permission
|
|
727
1147
|
let buildAllowed = false;
|
|
728
1148
|
if (mode === "production") {
|