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
|
@@ -16,7 +16,7 @@ import { homedir as osHomedir } from "node:os";
|
|
|
16
16
|
import { createRequire } from "node:module";
|
|
17
17
|
import { execSync } from "child_process";
|
|
18
18
|
import { existsSync, readFileSync, readdirSync, mkdirSync, readlinkSync, realpathSync } from "fs";
|
|
19
|
-
import { join } from "path";
|
|
19
|
+
import { dirname, join, resolve, sep } from "path";
|
|
20
20
|
import { platform, totalmem, freemem } from "os";
|
|
21
21
|
import {
|
|
22
22
|
canShowModeValue,
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
isLowRamWarning,
|
|
37
37
|
MASKED_MODE_VALUE,
|
|
38
38
|
MIN_BUILD_HEADROOM_GB,
|
|
39
|
+
modeFromFrappeBenchFacts,
|
|
39
40
|
modeFromRepositoryFacts,
|
|
40
41
|
modeFromValue,
|
|
41
42
|
orderDotenvFileNames,
|
|
@@ -46,6 +47,7 @@ import { readDotenvFiles } from "./workspace-dotenv.js";
|
|
|
46
47
|
import type {
|
|
47
48
|
DotenvVar,
|
|
48
49
|
EnvEvidence,
|
|
50
|
+
FrappeBenchFacts,
|
|
49
51
|
RepositoryFacts,
|
|
50
52
|
ServerState,
|
|
51
53
|
WorkspaceEnvResult,
|
|
@@ -590,29 +592,172 @@ function detectPackageManager(workspacePath: string): string | null {
|
|
|
590
592
|
}
|
|
591
593
|
|
|
592
594
|
/**
|
|
593
|
-
* The
|
|
595
|
+
* The directories that never hold a repository of their own.
|
|
594
596
|
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
597
|
+
* A search for a repository below the workspace must not walk into a build
|
|
598
|
+
* output or a dependency tree: those directories hold thousands of files and
|
|
599
|
+
* no repository.
|
|
598
600
|
*/
|
|
599
|
-
|
|
601
|
+
const REPOSITORY_SEARCH_SKIP = new Set([
|
|
602
|
+
".git",
|
|
603
|
+
"node_modules",
|
|
604
|
+
".venv",
|
|
605
|
+
"venv",
|
|
606
|
+
"env",
|
|
607
|
+
"dist",
|
|
608
|
+
"build",
|
|
609
|
+
"out",
|
|
610
|
+
"target",
|
|
611
|
+
".next",
|
|
612
|
+
".nuxt",
|
|
613
|
+
".cache",
|
|
614
|
+
".tox",
|
|
615
|
+
"vendor",
|
|
616
|
+
"__pycache__",
|
|
617
|
+
".mypy_cache",
|
|
618
|
+
".pytest_cache",
|
|
619
|
+
]);
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* The deepest level below the workspace that is searched for a repository.
|
|
623
|
+
*
|
|
624
|
+
* Two levels cover the shapes that matter: a folder of applications
|
|
625
|
+
* ("apps/store") and a repository inside one of them ("apps/store/web"
|
|
626
|
+
* with the repository one level above).
|
|
627
|
+
*/
|
|
628
|
+
const REPOSITORY_SEARCH_DEPTH = 2;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* The most directories that are read during the search.
|
|
632
|
+
*
|
|
633
|
+
* The search is bounded so a workspace with many folders cannot slow the
|
|
634
|
+
* startup down. A directory that holds a repository is found whatever its
|
|
635
|
+
* position is, as long as the search has not read that many directories.
|
|
636
|
+
*/
|
|
637
|
+
const REPOSITORY_SEARCH_CANDIDATES = 64;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* The branch of a checkout ("" when it cannot be read).
|
|
641
|
+
*/
|
|
642
|
+
function gitBranch(directory: string): string {
|
|
600
643
|
try {
|
|
601
|
-
const out = execSync(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
const branch = lines[1] ?? "";
|
|
644
|
+
const out = execSync("git rev-parse --abbrev-ref HEAD 2>/dev/null", {
|
|
645
|
+
cwd: directory,
|
|
646
|
+
encoding: "utf8",
|
|
647
|
+
timeout: 1500,
|
|
648
|
+
});
|
|
649
|
+
const branch = out.trim();
|
|
608
650
|
// A detached HEAD reports "HEAD" - that is not a branch name.
|
|
609
|
-
return
|
|
651
|
+
return branch === "HEAD" ? "" : branch;
|
|
652
|
+
} catch {
|
|
653
|
+
return "";
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* The repository of a directory, through its parents.
|
|
659
|
+
*/
|
|
660
|
+
function gitFactsIn(directory: string): { root: string; branch: string } {
|
|
661
|
+
try {
|
|
662
|
+
const out = execSync("git rev-parse --show-toplevel 2>/dev/null", {
|
|
663
|
+
cwd: directory,
|
|
664
|
+
encoding: "utf8",
|
|
665
|
+
timeout: 1500,
|
|
666
|
+
});
|
|
667
|
+
const root = out.trim();
|
|
668
|
+
if (!root) return { root: "", branch: "" };
|
|
669
|
+
return { root, branch: gitBranch(root) };
|
|
610
670
|
} catch {
|
|
611
671
|
// No git, no repository, or a timeout: nothing is known.
|
|
612
672
|
return { root: "", branch: "" };
|
|
613
673
|
}
|
|
614
674
|
}
|
|
615
675
|
|
|
676
|
+
/**
|
|
677
|
+
* The child of a workspace that holds a repository.
|
|
678
|
+
*
|
|
679
|
+
* A workspace is often the folder above the repository: the root of a
|
|
680
|
+
* monorepo, a directory of applications, a directory of workspaces. The
|
|
681
|
+
* repository of such a workspace is below it, and the search finds the
|
|
682
|
+
* nearest one in a stable order.
|
|
683
|
+
*
|
|
684
|
+
* @param workspacePath The workspace
|
|
685
|
+
* @returns The directory that holds the repository ("" when there is none)
|
|
686
|
+
*/
|
|
687
|
+
export function findRepositoryChild(workspacePath: string): string {
|
|
688
|
+
return findChildDirectory(workspacePath, (directory) =>
|
|
689
|
+
existsSync(join(directory, ".git")),
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* The child of a workspace that matches a predicate.
|
|
695
|
+
*
|
|
696
|
+
* A workspace is often the folder above the repository: the root of a
|
|
697
|
+
* monorepo, a directory of applications, a directory of workspaces. The
|
|
698
|
+
* nearest match in a stable order is returned.
|
|
699
|
+
*
|
|
700
|
+
* @param workspacePath The workspace
|
|
701
|
+
* @param matches The predicate of a directory
|
|
702
|
+
* @returns The directory that matches ("" when there is none)
|
|
703
|
+
*/
|
|
704
|
+
export function findChildDirectory(
|
|
705
|
+
workspacePath: string,
|
|
706
|
+
matches: (directory: string) => boolean,
|
|
707
|
+
): string {
|
|
708
|
+
let candidates = 0;
|
|
709
|
+
let level = [workspacePath];
|
|
710
|
+
for (let depth = 0; depth < REPOSITORY_SEARCH_DEPTH && level.length > 0; depth += 1) {
|
|
711
|
+
const next: string[] = [];
|
|
712
|
+
for (const directory of level) {
|
|
713
|
+
let names: string[];
|
|
714
|
+
try {
|
|
715
|
+
names = readdirSync(directory, { withFileTypes: true })
|
|
716
|
+
.filter(
|
|
717
|
+
(entry) =>
|
|
718
|
+
entry.isDirectory() && !REPOSITORY_SEARCH_SKIP.has(entry.name),
|
|
719
|
+
)
|
|
720
|
+
.map((entry) => entry.name)
|
|
721
|
+
.sort();
|
|
722
|
+
} catch {
|
|
723
|
+
// An unreadable directory proves nothing.
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
for (const name of names) {
|
|
727
|
+
if (candidates >= REPOSITORY_SEARCH_CANDIDATES) return "";
|
|
728
|
+
candidates += 1;
|
|
729
|
+
const child = join(directory, name);
|
|
730
|
+
if (matches(child)) return child;
|
|
731
|
+
next.push(child);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
level = next;
|
|
735
|
+
}
|
|
736
|
+
return "";
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* The git repository of a workspace.
|
|
741
|
+
*
|
|
742
|
+
* The repository is looked for in three places:
|
|
743
|
+
* 1. the workspace itself - `git rev-parse` walks up, so a folder inside a
|
|
744
|
+
* repository finds the repository of its parent
|
|
745
|
+
* 2. a child of the workspace, when the workspace is not in a repository
|
|
746
|
+
*
|
|
747
|
+
* The root of the repository is the unit of the detection: a package
|
|
748
|
+
* published from a monorepo is described by the root, not by the folder
|
|
749
|
+
* the harness happens to run in.
|
|
750
|
+
*/
|
|
751
|
+
function detectGitFacts(workspacePath: string): { root: string; branch: string } {
|
|
752
|
+
const own = gitFactsIn(workspacePath);
|
|
753
|
+
if (own.root) return own;
|
|
754
|
+
// The workspace is not in a repository. It may hold one: a directory of
|
|
755
|
+
// applications, a monorepo root.
|
|
756
|
+
const child = findRepositoryChild(workspacePath);
|
|
757
|
+
if (!child) return { root: "", branch: "" };
|
|
758
|
+
return { root: child, branch: gitBranch(child) };
|
|
759
|
+
}
|
|
760
|
+
|
|
616
761
|
/**
|
|
617
762
|
* True when the package is published to a registry.
|
|
618
763
|
*
|
|
@@ -682,6 +827,269 @@ function detectRepositoryFacts(
|
|
|
682
827
|
};
|
|
683
828
|
}
|
|
684
829
|
|
|
830
|
+
/**
|
|
831
|
+
* The configuration file of a Frappe bench.
|
|
832
|
+
*
|
|
833
|
+
* The file is the marker of a bench: every bench has one, and it holds the
|
|
834
|
+
* configuration that is shared by all its sites.
|
|
835
|
+
*/
|
|
836
|
+
const FRAPPE_BENCH_CONFIG = join("sites", "common_site_config.json");
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* The deepest level of parents that is searched for a bench.
|
|
840
|
+
*/
|
|
841
|
+
const MAX_PARENT_DEPTH = 12;
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* The directories that hold the configuration of a supervisor program group.
|
|
845
|
+
*/
|
|
846
|
+
const SUPERVISOR_CONFIG_DIRS = ["/etc/supervisor/conf.d", "/etc/supervisor"];
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* The directories that hold the configuration of an nginx site.
|
|
850
|
+
*/
|
|
851
|
+
const NGINX_CONFIG_DIRS = ["/etc/nginx/conf.d", "/etc/nginx/sites-enabled"];
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* The most site configurations of a bench that are read.
|
|
855
|
+
*/
|
|
856
|
+
const MAX_BENCH_SITES = 10;
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* The workspace and its parents.
|
|
860
|
+
*
|
|
861
|
+
* The workspace of a bench is usually inside the bench (the bench holds its
|
|
862
|
+
* apps), so the parents have to be searched as well.
|
|
863
|
+
*/
|
|
864
|
+
function workspaceAndParents(workspacePath: string): string[] {
|
|
865
|
+
const directories: string[] = [];
|
|
866
|
+
let current = resolve(workspacePath);
|
|
867
|
+
for (let depth = 0; depth < MAX_PARENT_DEPTH; depth += 1) {
|
|
868
|
+
directories.push(current);
|
|
869
|
+
const parent = dirname(current);
|
|
870
|
+
if (parent === current) break;
|
|
871
|
+
current = parent;
|
|
872
|
+
}
|
|
873
|
+
return directories;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* A JSON file as an object (null when it cannot be read or parsed).
|
|
878
|
+
*/
|
|
879
|
+
function readJsonFile(path: string): Record<string, unknown> | null {
|
|
880
|
+
try {
|
|
881
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
882
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
883
|
+
return parsed as Record<string, unknown>;
|
|
884
|
+
} catch {
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* A boolean field of a configuration file.
|
|
891
|
+
*
|
|
892
|
+
* Frappe writes "1" and "0", but a JSON file may hold a real boolean. A
|
|
893
|
+
* field that is absent or holds anything else is no claim.
|
|
894
|
+
*/
|
|
895
|
+
function booleanField(
|
|
896
|
+
config: Record<string, unknown> | null,
|
|
897
|
+
key: string,
|
|
898
|
+
): boolean | null {
|
|
899
|
+
if (!config) return null;
|
|
900
|
+
const value = config[key];
|
|
901
|
+
if (value === true || value === 1) return true;
|
|
902
|
+
if (value === false || value === 0) return false;
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* The sites of a bench.
|
|
908
|
+
*/
|
|
909
|
+
function frappeSiteNames(benchRoot: string): string[] {
|
|
910
|
+
try {
|
|
911
|
+
return readdirSync(join(benchRoot, "sites"), { withFileTypes: true })
|
|
912
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
913
|
+
.map((entry) => entry.name)
|
|
914
|
+
.sort()
|
|
915
|
+
.slice(0, MAX_BENCH_SITES);
|
|
916
|
+
} catch {
|
|
917
|
+
return [];
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* A site of the bench is in maintenance mode.
|
|
923
|
+
*/
|
|
924
|
+
function siteMaintenanceMode(benchRoot: string): boolean | null {
|
|
925
|
+
for (const site of frappeSiteNames(benchRoot)) {
|
|
926
|
+
const config = readJsonFile(
|
|
927
|
+
join(benchRoot, "sites", site, "site_config.json"),
|
|
928
|
+
);
|
|
929
|
+
if (booleanField(config, "maintenance_mode") === true) return true;
|
|
930
|
+
}
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Does a configuration directory mention one of the needles?
|
|
936
|
+
*
|
|
937
|
+
* The production setup of a bench is written into the configuration of the
|
|
938
|
+
* process manager (supervisor) and of the web server (nginx): those files
|
|
939
|
+
* name the bench, not the other way round.
|
|
940
|
+
*/
|
|
941
|
+
function configMentions(directories: string[], needles: string[]): boolean {
|
|
942
|
+
const wanted = needles.filter((needle) => needle.length > 0);
|
|
943
|
+
if (wanted.length === 0) return false;
|
|
944
|
+
for (const directory of directories) {
|
|
945
|
+
let entries: string[];
|
|
946
|
+
try {
|
|
947
|
+
entries = readdirSync(directory);
|
|
948
|
+
} catch {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
for (const entry of entries.slice(0, 64)) {
|
|
952
|
+
if (!entry.endsWith(".conf")) continue;
|
|
953
|
+
let content: string;
|
|
954
|
+
try {
|
|
955
|
+
content = readFileSync(join(directory, entry), "utf8");
|
|
956
|
+
} catch {
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (wanted.some((needle) => content.includes(needle))) return true;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return false;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Does a process belong to a bench?
|
|
967
|
+
*
|
|
968
|
+
* The working directory of the process is the strongest evidence (Linux
|
|
969
|
+
* exposes it); otherwise the command line must name the bench.
|
|
970
|
+
*/
|
|
971
|
+
function processBelongsToBench(pid: string, benchRoot: string): boolean {
|
|
972
|
+
if (platform() === "linux") {
|
|
973
|
+
try {
|
|
974
|
+
const cwd = readlinkSync(`/proc/${pid}/cwd`);
|
|
975
|
+
return cwd === benchRoot || cwd.startsWith(benchRoot + sep);
|
|
976
|
+
} catch {
|
|
977
|
+
// The process is gone or its directory cannot be read.
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
const cmdline = processCmdline(pid);
|
|
981
|
+
return cmdline.includes(benchRoot);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* The processes of a bench.
|
|
986
|
+
*
|
|
987
|
+
* "bench serve" is the development server of a bench, "bench start" runs it
|
|
988
|
+
* the way a server runs it (web, workers, scheduler).
|
|
989
|
+
*/
|
|
990
|
+
function benchProcesses(benchRoot: string): { dev: boolean; production: boolean } {
|
|
991
|
+
const none = { dev: false, production: false };
|
|
992
|
+
const os = platform();
|
|
993
|
+
if (os !== "linux" && os !== "darwin") return none;
|
|
994
|
+
if (!hasProcessTool()) return none;
|
|
995
|
+
try {
|
|
996
|
+
const script = `echo $$; pgrep -f ${JSON.stringify(
|
|
997
|
+
"bench (serve|start)|frappe\\.serve",
|
|
998
|
+
)} 2>/dev/null || true`;
|
|
999
|
+
const out = execSync(script, {
|
|
1000
|
+
encoding: "utf8",
|
|
1001
|
+
timeout: 1000,
|
|
1002
|
+
});
|
|
1003
|
+
const lines = out.split("\n");
|
|
1004
|
+
const ownPids = [
|
|
1005
|
+
String(process.pid),
|
|
1006
|
+
String(process.ppid),
|
|
1007
|
+
(lines[0] ?? "").trim(),
|
|
1008
|
+
...ancestorPids(String(process.pid)),
|
|
1009
|
+
];
|
|
1010
|
+
const pids = filterOwnPids(lines.slice(1), ownPids);
|
|
1011
|
+
let dev = false;
|
|
1012
|
+
let production = false;
|
|
1013
|
+
for (const pid of pids) {
|
|
1014
|
+
const cmdline = processCmdline(pid);
|
|
1015
|
+
if (!cmdline) continue;
|
|
1016
|
+
if (isShellExe(processExe(pid)) && /(^|\s)-c(\s|$)/.test(cmdline)) continue;
|
|
1017
|
+
if (!processBelongsToBench(pid, benchRoot)) continue;
|
|
1018
|
+
if (/frappe\.serve|bench\s+serve/.test(cmdline)) dev = true;
|
|
1019
|
+
else if (/bench\s+start/.test(cmdline)) production = true;
|
|
1020
|
+
}
|
|
1021
|
+
return { dev, production };
|
|
1022
|
+
} catch {
|
|
1023
|
+
return none;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* The bench of a workspace.
|
|
1029
|
+
*
|
|
1030
|
+
* The bench is the workspace itself, one of its parents (a bench holds its
|
|
1031
|
+
* apps, so a workspace inside a bench is below it), or one of its children
|
|
1032
|
+
* (a directory of workspaces).
|
|
1033
|
+
*/
|
|
1034
|
+
function findFrappeBench(workspacePath: string): string {
|
|
1035
|
+
for (const directory of workspaceAndParents(workspacePath)) {
|
|
1036
|
+
if (existsSync(join(directory, FRAPPE_BENCH_CONFIG))) return directory;
|
|
1037
|
+
}
|
|
1038
|
+
return findChildDirectory(workspacePath, (directory) =>
|
|
1039
|
+
existsSync(join(directory, FRAPPE_BENCH_CONFIG)),
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* The facts about the Frappe bench of a workspace.
|
|
1045
|
+
*
|
|
1046
|
+
* A bench says much more about the environment than one flag: the flag says
|
|
1047
|
+
* that the developer conveniences are on, the way the bench runs says
|
|
1048
|
+
* whether it is a development or a deployed bench.
|
|
1049
|
+
*/
|
|
1050
|
+
function detectFrappeBenchFacts(
|
|
1051
|
+
workspacePath: string,
|
|
1052
|
+
branch: string,
|
|
1053
|
+
): FrappeBenchFacts {
|
|
1054
|
+
const facts: FrappeBenchFacts = {
|
|
1055
|
+
benchRoot: "",
|
|
1056
|
+
developerMode: null,
|
|
1057
|
+
maintenanceMode: null,
|
|
1058
|
+
liveReload: false,
|
|
1059
|
+
pauseScheduler: false,
|
|
1060
|
+
supervisorManaged: false,
|
|
1061
|
+
nginxManaged: false,
|
|
1062
|
+
deploymentMarker: false,
|
|
1063
|
+
devServerRunning: false,
|
|
1064
|
+
productionRun: false,
|
|
1065
|
+
branch,
|
|
1066
|
+
};
|
|
1067
|
+
const benchRoot = findFrappeBench(workspacePath);
|
|
1068
|
+
if (!benchRoot) return facts;
|
|
1069
|
+
facts.benchRoot = benchRoot;
|
|
1070
|
+
const config = readJsonFile(join(benchRoot, FRAPPE_BENCH_CONFIG));
|
|
1071
|
+
facts.developerMode = booleanField(config, "developer_mode");
|
|
1072
|
+
facts.liveReload = booleanField(config, "live_reload") === true;
|
|
1073
|
+
facts.pauseScheduler = booleanField(config, "pause_scheduler") === true;
|
|
1074
|
+
// The common configuration may declare the maintenance mode, and a site
|
|
1075
|
+
// may declare it for itself.
|
|
1076
|
+
facts.maintenanceMode =
|
|
1077
|
+
booleanField(config, "maintenance_mode") === true
|
|
1078
|
+
? true
|
|
1079
|
+
: siteMaintenanceMode(benchRoot);
|
|
1080
|
+
facts.deploymentMarker = hasDeploymentConfiguration(benchRoot);
|
|
1081
|
+
const needles = [
|
|
1082
|
+
benchRoot,
|
|
1083
|
+
...frappeSiteNames(benchRoot).filter((site) => site.length >= 4),
|
|
1084
|
+
];
|
|
1085
|
+
facts.supervisorManaged = configMentions(SUPERVISOR_CONFIG_DIRS, needles);
|
|
1086
|
+
facts.nginxManaged = configMentions(NGINX_CONFIG_DIRS, needles);
|
|
1087
|
+
const processes = benchProcesses(benchRoot);
|
|
1088
|
+
facts.devServerRunning = processes.dev;
|
|
1089
|
+
facts.productionRun = processes.production;
|
|
1090
|
+
return facts;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
685
1093
|
/**
|
|
686
1094
|
* Determine workspace mode with proper precedence
|
|
687
1095
|
* Never assume production - unknown requires investigation
|
|
@@ -693,7 +1101,8 @@ function detectRepositoryFacts(
|
|
|
693
1101
|
* key whose value names a known mode, then any other environment shaped
|
|
694
1102
|
* key
|
|
695
1103
|
* 3. an environment shaped key of the process env (the files are silent)
|
|
696
|
-
* 4. the facts about the
|
|
1104
|
+
* 4. the facts about a Frappe bench - the bench is the runtime of a site
|
|
1105
|
+
* 5. the facts about the repository (only when NO variable names the
|
|
697
1106
|
* environment at all) - a published source repository without a runtime
|
|
698
1107
|
* of its own is a development checkout
|
|
699
1108
|
*/
|
|
@@ -702,6 +1111,7 @@ function determineMode(
|
|
|
702
1111
|
dotenvVars: DotenvVar[],
|
|
703
1112
|
evidence: EnvEvidence[],
|
|
704
1113
|
repositoryFacts: RepositoryFacts,
|
|
1114
|
+
frappeBenchFacts: FrappeBenchFacts,
|
|
705
1115
|
): WorkspaceMode {
|
|
706
1116
|
const resolved = resolveWorkspaceMode(processVars, dotenvVars);
|
|
707
1117
|
if (resolved.hint && resolved.source) {
|
|
@@ -720,11 +1130,29 @@ function determineMode(
|
|
|
720
1130
|
timestamp: Date.now(),
|
|
721
1131
|
file: resolved.hint.file,
|
|
722
1132
|
});
|
|
723
|
-
//
|
|
724
|
-
|
|
725
|
-
|
|
1133
|
+
// A variable whose value names a known mode decides.
|
|
1134
|
+
if (resolved.mode !== "unknown") return resolved.mode;
|
|
1135
|
+
// An explicit NODE_ENV decides even when it names no known mode
|
|
1136
|
+
// ("staging"). A deliberate value must not be replaced by the shape
|
|
1137
|
+
// of the checkout.
|
|
1138
|
+
if (resolved.decides === true) return resolved.mode;
|
|
1139
|
+
}
|
|
1140
|
+
// No variable names a known mode: the facts about the workspace may still
|
|
1141
|
+
// name it. A variable that names no known mode (VIRTUAL_ENV, a path) is a
|
|
1142
|
+
// fact about the machine, not a declaration of the environment, so it does
|
|
1143
|
+
// not keep the mode unknown when the checkout names it.
|
|
1144
|
+
// A Frappe bench comes first: the bench is the runtime of a site, so its
|
|
1145
|
+
// facts say more about the environment than the shape of a checkout.
|
|
1146
|
+
const benchDetection = modeFromFrappeBenchFacts(frappeBenchFacts);
|
|
1147
|
+
if (benchDetection) {
|
|
1148
|
+
evidence.push({
|
|
1149
|
+
source: "detection",
|
|
1150
|
+
key: benchDetection.key,
|
|
1151
|
+
value: benchDetection.mode,
|
|
1152
|
+
timestamp: Date.now(),
|
|
1153
|
+
});
|
|
1154
|
+
return benchDetection.mode;
|
|
726
1155
|
}
|
|
727
|
-
// No variable names the environment: the repository may still name it.
|
|
728
1156
|
const detection = modeFromRepositoryFacts(repositoryFacts);
|
|
729
1157
|
if (!detection) return resolved.mode;
|
|
730
1158
|
evidence.push({
|
|
@@ -792,7 +1220,17 @@ export function detectWorkspaceEnv(workspacePath: string): WorkspaceEnvResult {
|
|
|
792
1220
|
workspacePath,
|
|
793
1221
|
devServerState === "running" || buildServerState === "running",
|
|
794
1222
|
);
|
|
795
|
-
const
|
|
1223
|
+
const frappeBenchFacts = detectFrappeBenchFacts(
|
|
1224
|
+
workspacePath,
|
|
1225
|
+
repositoryFacts.branch,
|
|
1226
|
+
);
|
|
1227
|
+
const mode = determineMode(
|
|
1228
|
+
processVars,
|
|
1229
|
+
dotenvVars,
|
|
1230
|
+
evidence,
|
|
1231
|
+
repositoryFacts,
|
|
1232
|
+
frappeBenchFacts,
|
|
1233
|
+
);
|
|
796
1234
|
|
|
797
1235
|
// Determine build permission
|
|
798
1236
|
let buildAllowed = false;
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
* - Nothing here decides: the module never selects an option and never
|
|
16
16
|
* invents an approval. Missing information is surfaced as an uncertainty
|
|
17
17
|
* so that a wait outcome stays possible.
|
|
18
|
+
* - A comparison is never dropped: a statement that names two options
|
|
19
|
+
* ("Unlike A, B must connect every server") is kept with the option it
|
|
20
|
+
* constrains, and a comparison whose subject is not established is
|
|
21
|
+
* reported as an uncertainty.
|
|
18
22
|
* - Every bound is declared and every cut is reported, so a reader can tell
|
|
19
23
|
* what the evaluation did not see.
|
|
20
24
|
*/
|
|
@@ -145,6 +149,14 @@ export interface ExtractedOption {
|
|
|
145
149
|
* belongs to.
|
|
146
150
|
*/
|
|
147
151
|
descriptionConstraint: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The comparisons that could not be attributed to one option.
|
|
154
|
+
*
|
|
155
|
+
* A statement that compares the options without saying which one it
|
|
156
|
+
* constrains is kept with every option it names, and it is reported here
|
|
157
|
+
* so that the comparison does not disappear silently.
|
|
158
|
+
*/
|
|
159
|
+
comparative: string[];
|
|
148
160
|
}
|
|
149
161
|
/** What the extraction needs to know about one option. */
|
|
150
162
|
export interface OptionExtractionInput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision-context.d.ts","sourceRoot":"","sources":["../src/decision-context.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decision-context.d.ts","sourceRoot":"","sources":["../src/decision-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,gEAAgE;AAChE,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,uDAAuD;AACvD,eAAO,MAAM,yBAAy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