@operad-io/engine 0.2.0 → 0.3.1
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/package.json +1 -1
- package/src/http/plugins.ts +2 -0
- package/src/platform/git-program.ts +108 -0
- package/src/platform/index.ts +1 -0
- package/src/platform/sqlite-open.ts +4 -1
- package/src/plugin/registry.ts +7 -0
- package/src/plugin/types.ts +9 -0
- package/src/plugin/validate.ts +6 -0
- package/src/views/types.ts +5 -0
package/package.json
CHANGED
package/src/http/plugins.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface PluginInfo {
|
|
|
26
26
|
* client that reads only `list` keeps working.
|
|
27
27
|
*/
|
|
28
28
|
readonly models?: HarnessModels | undefined;
|
|
29
|
+
/** A loaded harness plugin's access levels it can carry, by id; empty when it carries none. */
|
|
30
|
+
readonly accessLevels?: readonly string[] | undefined;
|
|
29
31
|
/**
|
|
30
32
|
* The latest line the package install printed, while this plugin is being
|
|
31
33
|
* installed. A plugin being installed is listed before `config.json` names
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding the git program without running it where running it could open a
|
|
3
|
+
* dialog. On macOS `/usr/bin/git` is a stub that exists on every Mac; without
|
|
4
|
+
* the command line tools it opens Apple's install dialog. So it is trusted only
|
|
5
|
+
* when `xcode-select -p` names a developer directory that holds a git.
|
|
6
|
+
*
|
|
7
|
+
* The answer is an absolute path, because a PATH that changed after the process
|
|
8
|
+
* started (a `winget install`, a Homebrew install under a GUI-started serve) is
|
|
9
|
+
* not seen by a spawn of the word `git`. Nothing is cached: "not installed" must
|
|
10
|
+
* be looked up again on every call, and a lookup is a few file checks.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
|
|
16
|
+
/** What the finder needs from the machine; a test injects each part. */
|
|
17
|
+
export interface GitFinderHost {
|
|
18
|
+
readonly platform: NodeJS.Platform;
|
|
19
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
20
|
+
/** Resolves a command through PATH without running it. */
|
|
21
|
+
which(command: string, path: string | undefined): string | null;
|
|
22
|
+
/** True when a file exists. */
|
|
23
|
+
exists(path: string): boolean;
|
|
24
|
+
/** Runs a program with no shell; returns its exit code and output. */
|
|
25
|
+
run(cmd: readonly string[], env: Readonly<Record<string, string | undefined>>): {
|
|
26
|
+
readonly code: number;
|
|
27
|
+
readonly out: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The message every caller shows when no git program is found. */
|
|
32
|
+
export const GIT_NOT_INSTALLED = "git is not installed";
|
|
33
|
+
|
|
34
|
+
const MACOS_STUB = "/usr/bin/git";
|
|
35
|
+
|
|
36
|
+
function defaultRun(
|
|
37
|
+
cmd: readonly string[],
|
|
38
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
39
|
+
): { readonly code: number; readonly out: string } {
|
|
40
|
+
try {
|
|
41
|
+
const result = Bun.spawnSync({
|
|
42
|
+
cmd: [...cmd],
|
|
43
|
+
stdin: "ignore",
|
|
44
|
+
stdout: "pipe",
|
|
45
|
+
stderr: "ignore",
|
|
46
|
+
env: { ...env },
|
|
47
|
+
timeout: 10_000,
|
|
48
|
+
killSignal: "SIGKILL",
|
|
49
|
+
});
|
|
50
|
+
return { code: result.exitCode ?? 1, out: result.stdout.toString().trim() };
|
|
51
|
+
} catch {
|
|
52
|
+
return { code: 1, out: "" };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The machine this process runs on. */
|
|
57
|
+
export function realGitFinderHost(): GitFinderHost {
|
|
58
|
+
return {
|
|
59
|
+
platform: process.platform,
|
|
60
|
+
env: process.env,
|
|
61
|
+
which: (command, path) => Bun.which(command, path === undefined ? {} : { PATH: path }),
|
|
62
|
+
exists: existsSync,
|
|
63
|
+
run: defaultRun,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** True when the selected developer directory on a Mac holds a git. */
|
|
68
|
+
function macToolsInstalled(host: GitFinderHost): boolean {
|
|
69
|
+
const selected = host.run(["/usr/bin/xcode-select", "-p"], host.env);
|
|
70
|
+
if (selected.code !== 0 || selected.out.length === 0) return false;
|
|
71
|
+
return host.exists(join(selected.out, "usr", "bin", "git"));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function windowsCandidates(env: GitFinderHost["env"]): string[] {
|
|
75
|
+
const roots = [env.ProgramFiles, env["ProgramFiles(x86)"]].filter(
|
|
76
|
+
(value): value is string => value !== undefined && value.length > 0,
|
|
77
|
+
);
|
|
78
|
+
const found = roots.map((root) => join(root, "Git", "cmd", "git.exe"));
|
|
79
|
+
const local = env.LOCALAPPDATA;
|
|
80
|
+
if (local !== undefined && local.length > 0) {
|
|
81
|
+
found.push(join(local, "Programs", "Git", "cmd", "git.exe"));
|
|
82
|
+
}
|
|
83
|
+
return found;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The absolute path of a git program that can be run, or undefined when there
|
|
88
|
+
* is none. It never runs git itself and never opens an installer.
|
|
89
|
+
*/
|
|
90
|
+
export function findGit(host: GitFinderHost = realGitFinderHost()): string | undefined {
|
|
91
|
+
const onPath = host.which("git", host.env.PATH);
|
|
92
|
+
if (host.platform === "darwin") {
|
|
93
|
+
if (onPath !== null && onPath !== MACOS_STUB) return onPath;
|
|
94
|
+
// A GUI-started process has a short PATH: look where Homebrew installs.
|
|
95
|
+
for (const candidate of ["/opt/homebrew/bin/git", "/usr/local/bin/git"]) {
|
|
96
|
+
if (host.exists(candidate)) return candidate;
|
|
97
|
+
}
|
|
98
|
+
// Only the stub is left: it is real only when the tools are selected.
|
|
99
|
+
return (onPath === MACOS_STUB || host.exists(MACOS_STUB)) && macToolsInstalled(host)
|
|
100
|
+
? MACOS_STUB
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
if (onPath !== null) return onPath;
|
|
104
|
+
if (host.platform === "win32") {
|
|
105
|
+
return windowsCandidates(host.env).find((path) => host.exists(path));
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
package/src/platform/index.ts
CHANGED
|
@@ -48,7 +48,10 @@ export function isBusy(error: unknown): boolean {
|
|
|
48
48
|
* until the other writer commits, so nothing has to sleep and poll.
|
|
49
49
|
*/
|
|
50
50
|
function waitForWriter(database: Database): void {
|
|
51
|
-
|
|
51
|
+
// A writer that keeps committing (a first open creating the schema on a slow
|
|
52
|
+
// disk) can hold the lock past the busy timeout with nothing stuck, so the
|
|
53
|
+
// wait goes on while the data version moves, as for any other write.
|
|
54
|
+
writeImmediate(database, () => undefined);
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
/**
|
package/src/plugin/registry.ts
CHANGED
|
@@ -586,6 +586,11 @@ export class PluginRegistry {
|
|
|
586
586
|
return this.byName.get(plugin)?.objectsUnderSettings === true;
|
|
587
587
|
}
|
|
588
588
|
|
|
589
|
+
/** The title a plugin gives its list, if it declares one. */
|
|
590
|
+
listTitleOf(plugin: string): string | undefined {
|
|
591
|
+
return this.byName.get(plugin)?.listTitle;
|
|
592
|
+
}
|
|
593
|
+
|
|
589
594
|
/** The trigger rules plugins ship, in load order, with their plugin. */
|
|
590
595
|
triggerRules(): readonly {
|
|
591
596
|
readonly plugin: string;
|
|
@@ -1319,6 +1324,7 @@ export class PluginRegistry {
|
|
|
1319
1324
|
harnesses: this.loadedHarnesses(),
|
|
1320
1325
|
models: this.loadedModels(),
|
|
1321
1326
|
efforts: this.loadedEfforts(),
|
|
1327
|
+
capabilities: this.loadedCapabilities(),
|
|
1322
1328
|
stepLoaded: (use) => this.stepIndex.has(use),
|
|
1323
1329
|
...(this.onCancelRun === undefined ? {} : { runs: this.runControl() }),
|
|
1324
1330
|
};
|
|
@@ -1457,6 +1463,7 @@ export class PluginRegistry {
|
|
|
1457
1463
|
stepLoaded: (use) => this.stepIndex.has(use),
|
|
1458
1464
|
models: this.loadedModels(),
|
|
1459
1465
|
efforts: this.loadedEfforts(),
|
|
1466
|
+
capabilities: this.loadedCapabilities(),
|
|
1460
1467
|
actions: object === undefined ? [] : await this.actionInfosFor(object),
|
|
1461
1468
|
...(object === undefined
|
|
1462
1469
|
? {}
|
package/src/plugin/types.ts
CHANGED
|
@@ -1164,6 +1164,8 @@ export interface ActionEnv {
|
|
|
1164
1164
|
readonly models?: Readonly<Record<string, HarnessModels>> | undefined;
|
|
1165
1165
|
/** The efforts each loaded harness plugin declares, by plugin name. */
|
|
1166
1166
|
readonly efforts?: Readonly<Record<string, HarnessEfforts>> | undefined;
|
|
1167
|
+
/** What each loaded harness plugin declares it can do, by plugin name. */
|
|
1168
|
+
readonly capabilities?: Readonly<Record<string, HarnessCapabilities>> | undefined;
|
|
1167
1169
|
/** Whether a plugin that declares this step is loaded now. */
|
|
1168
1170
|
readonly stepLoaded?: ((use: string) => boolean) | undefined;
|
|
1169
1171
|
/**
|
|
@@ -1386,6 +1388,8 @@ export interface ActionEvent {
|
|
|
1386
1388
|
export interface ActionContext extends PluginBaseContext {
|
|
1387
1389
|
/** The names of the loaded plugins of kind `harness`. */
|
|
1388
1390
|
readonly harnesses: readonly string[];
|
|
1391
|
+
/** What each loaded harness plugin declares it can do, by plugin name. */
|
|
1392
|
+
readonly capabilities?: Readonly<Record<string, HarnessCapabilities>> | undefined;
|
|
1389
1393
|
/** The kernel's runs, when the host supplies them; a plugin can avoid starting a second one. */
|
|
1390
1394
|
readonly runLookup?: RunLookup | undefined;
|
|
1391
1395
|
/** Whether a plugin that declares this step is loaded now. */
|
|
@@ -1651,6 +1655,11 @@ export interface PluginShape {
|
|
|
1651
1655
|
* types `settings: true`.
|
|
1652
1656
|
*/
|
|
1653
1657
|
readonly objectsUnderSettings?: boolean | undefined;
|
|
1658
|
+
/**
|
|
1659
|
+
* The title a client gives this plugin's list (its tab); absent: the
|
|
1660
|
+
* plugin's name. Served as `pluginTitle` on each of its types.
|
|
1661
|
+
*/
|
|
1662
|
+
readonly listTitle?: string | undefined;
|
|
1654
1663
|
/** Settings files this plugin keeps under a registered repository's `.operad/`. */
|
|
1655
1664
|
readonly projectSettings?: ProjectSettingsDeclaration | undefined;
|
|
1656
1665
|
/**
|
package/src/plugin/validate.ts
CHANGED
|
@@ -74,6 +74,7 @@ export interface NormalizedPlugin {
|
|
|
74
74
|
readonly settingsSchema: ActionArgsSchema | undefined;
|
|
75
75
|
/** The plugin's objects belong under a client's settings view. */
|
|
76
76
|
readonly objectsUnderSettings: boolean;
|
|
77
|
+
readonly listTitle: string | undefined;
|
|
77
78
|
readonly projectSettings: ProjectSettingsDeclaration | undefined;
|
|
78
79
|
readonly enforces: readonly string[];
|
|
79
80
|
readonly models:
|
|
@@ -820,6 +821,10 @@ export function normalizePlugin(raw: unknown, index: number): NormalizedPlugin {
|
|
|
820
821
|
throw new PluginError(`${at}: objectsUnderSettings: must be a boolean`);
|
|
821
822
|
}
|
|
822
823
|
|
|
824
|
+
if (raw.listTitle !== undefined && (typeof raw.listTitle !== "string" || raw.listTitle === "")) {
|
|
825
|
+
throw new PluginError(`${at}: listTitle: must be a non-empty string`);
|
|
826
|
+
}
|
|
827
|
+
|
|
823
828
|
const projectSettings = normalizeProjectSettings(
|
|
824
829
|
raw.projectSettings,
|
|
825
830
|
`${at}: projectSettings`,
|
|
@@ -848,6 +853,7 @@ export function normalizePlugin(raw: unknown, index: number): NormalizedPlugin {
|
|
|
848
853
|
guide,
|
|
849
854
|
settingsSchema,
|
|
850
855
|
objectsUnderSettings: raw.objectsUnderSettings === true,
|
|
856
|
+
listTitle: raw.listTitle,
|
|
851
857
|
projectSettings,
|
|
852
858
|
enforces: normalizeEnforces(raw.enforces, `${at}: enforces`) ?? [],
|
|
853
859
|
models: normalizeModels(raw.models, kind, at),
|
package/src/views/types.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface ViewTypeInfo {
|
|
|
13
13
|
readonly title: string;
|
|
14
14
|
/** The plugin the type belongs to; a client groups types by it. */
|
|
15
15
|
readonly plugin: string;
|
|
16
|
+
/** The title the plugin gives its list; absent when it declares none (a client shows the plugin name). */
|
|
17
|
+
readonly pluginTitle?: string | undefined;
|
|
16
18
|
/**
|
|
17
19
|
* True when the plugin's objects belong under a client's settings view
|
|
18
20
|
* instead of a tab of their own. Present only when it holds.
|
|
@@ -63,6 +65,9 @@ export function listTypes(registry: PluginRegistry): readonly ViewTypeInfo[] {
|
|
|
63
65
|
type: entry.type,
|
|
64
66
|
title: displayNameOf(entry.type),
|
|
65
67
|
plugin: entry.plugin,
|
|
68
|
+
...(registry.listTitleOf(entry.plugin) === undefined
|
|
69
|
+
? {}
|
|
70
|
+
: { pluginTitle: registry.listTitleOf(entry.plugin) }),
|
|
66
71
|
...(registry.objectsUnderSettings(entry.plugin) ? { settings: true } : {}),
|
|
67
72
|
...(filters === undefined
|
|
68
73
|
? {}
|