@omercnet/paseo-omp 5.4.0 → 5.5.0-next.427.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/OVERVIEW.md +7 -1
- package/README.md +2 -1
- package/client/ast-edit.tsx +53 -0
- package/client/composer-pill-settings.tsx +0 -5
- package/client/config-sidebar.tsx +15 -0
- package/client/generated-image.tsx +79 -0
- package/client/lsp-diagnostics.tsx +69 -0
- package/client/omp-config-surface.tsx +438 -108
- package/client/omp-config-views.ts +32 -5
- package/client/omp-extensions-section.tsx +145 -0
- package/client/omp-local-models-section.tsx +215 -0
- package/client/omp-plugin-manager.tsx +198 -3
- package/client/omp-routing-editor.tsx +123 -2
- package/client/omp-rule-test.tsx +140 -0
- package/client/omp-rules-section.tsx +353 -0
- package/client/omp-security-section.tsx +99 -0
- package/client/omp-security-state.ts +14 -0
- package/client/omp-skills-section.tsx +195 -0
- package/client/omp-tool-config-section.tsx +204 -0
- package/client/omp-tool-policy-state.ts +101 -0
- package/client/omp-tool-policy.tsx +435 -0
- package/client/omp-update-row.tsx +87 -0
- package/client/provider-diagnostics-state.ts +38 -1
- package/client/provider-image.tsx +1 -1
- package/client/rule-notice.tsx +33 -0
- package/client/sidebar-compat.ts +0 -109
- package/client/web.ts +34 -0
- package/index.client.tsx +79 -46
- package/index.server.ts +77 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -4
- package/server/generated-images.ts +57 -0
- package/server/omp-agents.ts +170 -0
- package/server/omp-extensions.ts +235 -0
- package/server/omp-list-setting.ts +98 -0
- package/server/omp-local-models.ts +202 -0
- package/server/omp-models-file.ts +178 -0
- package/server/omp-plugins.ts +182 -0
- package/server/omp-prompt-files.ts +41 -0
- package/server/omp-rule-firings.ts +211 -0
- package/server/omp-rule-switch.ts +38 -0
- package/server/omp-rule-test.ts +82 -0
- package/server/omp-rules.ts +452 -0
- package/server/omp-security.ts +169 -0
- package/server/omp-settings.ts +92 -16
- package/server/omp-skills.ts +179 -0
- package/server/omp-tool-config.ts +144 -0
- package/server/omp-update.ts +203 -0
- package/server/package-version.ts +1 -1
- package/server/provider/connection.ts +1 -1
- package/server/provider/image-cache.ts +1 -1
- package/server/provider/omp-rpc-environment.ts +1 -1
- package/server/provider/session-descriptors.ts +3 -0
- package/server/provider-diagnostics.ts +26 -4
- package/server/regular-file.ts +30 -0
- package/server/rule-notices.ts +112 -0
- package/server/turn-rows.ts +59 -0
- package/server/turn-screenshots.ts +140 -0
- package/shared/ast-edit.ts +124 -0
- package/shared/composer-pill-settings.ts +0 -2
- package/shared/generated-image.ts +68 -0
- package/shared/lsp-diagnostics.ts +141 -0
- package/shared/omp-agents.ts +26 -0
- package/shared/omp-extensions.ts +45 -0
- package/shared/omp-local-models.ts +44 -0
- package/shared/omp-models-file.ts +30 -0
- package/shared/omp-plugins.ts +90 -0
- package/shared/omp-prompt-files.ts +24 -0
- package/shared/omp-rules.ts +134 -0
- package/shared/omp-security.ts +50 -0
- package/shared/omp-settings.ts +211 -2
- package/shared/omp-skills.ts +80 -0
- package/shared/omp-tool-config.ts +283 -0
- package/shared/omp-update.ts +27 -0
- package/shared/provider-image.ts +10 -3
- package/shared/rule-notices.ts +20 -0
- package/client/hub-sidebar.tsx +0 -99
- package/client/sessions-popover.tsx +0 -78
- package/server/sessions.ts +0 -58
- package/shared/sessions.ts +0 -24
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { mkdtemp, readdir, readFile, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
4
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
5
|
+
import { parse as parseYaml } from "yaml";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { type listOmpAgents, OMP_AGENT_LIMIT, type OmpAgent } from "../shared/omp-agents";
|
|
8
|
+
import { OmpAgentNameSchema } from "../shared/omp-settings";
|
|
9
|
+
import { resolveOmpExecutable } from "./omp-settings";
|
|
10
|
+
import { currentOmpEnvironment, ompAgentDir } from "./paths";
|
|
11
|
+
import { buildStatefulCommandEnv, defaultSpawn, runBounded } from "./provider-diagnostics";
|
|
12
|
+
|
|
13
|
+
const UNPACK_TIMEOUT_MS = 15_000;
|
|
14
|
+
const KILL_GRACE_MS = 1_000;
|
|
15
|
+
const UNPACK_OUTPUT_LIMIT = 64 * 1024;
|
|
16
|
+
const AGENT_FILE_LIMIT = 256 * 1024;
|
|
17
|
+
const FRONTMATTER = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---/u;
|
|
18
|
+
const BUNDLED_FAILURE = "Bundled agents could not be listed.";
|
|
19
|
+
|
|
20
|
+
/** Everything OMP would use to relocate its config, data, state, cache or agent directory. */
|
|
21
|
+
const OMP_LOCATION_ENV = [
|
|
22
|
+
"OMP_AGENT_DIR",
|
|
23
|
+
"OMP_PROFILE",
|
|
24
|
+
"OMP_SESSION_DIR",
|
|
25
|
+
"PASEO_OMP_AGENT_DIR",
|
|
26
|
+
"PI_CODING_AGENT_DIR",
|
|
27
|
+
"PI_CODING_AGENT_SESSION_DIR",
|
|
28
|
+
"PI_CONFIG_DIR",
|
|
29
|
+
"PI_PROFILE",
|
|
30
|
+
"XDG_CACHE_HOME",
|
|
31
|
+
"XDG_CONFIG_HOME",
|
|
32
|
+
"XDG_DATA_HOME",
|
|
33
|
+
"XDG_STATE_HOME",
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
const UnpackResultSchema = z.object({ written: z.array(z.string()) });
|
|
37
|
+
|
|
38
|
+
export interface OmpAgentDependencies {
|
|
39
|
+
/** Names of the agents OMP ships with. Rejects when OMP cannot list them. */
|
|
40
|
+
bundledNames(): Promise<string[]>;
|
|
41
|
+
userAgentsDir(): string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Names OMP reserves for itself and never registers from an agent file. */
|
|
45
|
+
const RESERVED_AGENT_NAMES: readonly string[] = ["main", "sub"];
|
|
46
|
+
|
|
47
|
+
/** The name OMP registers for an agent file: its frontmatter `name`, which needs a `description`. */
|
|
48
|
+
async function agentNameFromFile(path: string): Promise<string | null> {
|
|
49
|
+
const metadata = await stat(path);
|
|
50
|
+
if (!metadata.isFile() || metadata.size > AGENT_FILE_LIMIT) return null;
|
|
51
|
+
const frontmatter = FRONTMATTER.exec(await readFile(path, "utf8"));
|
|
52
|
+
if (!frontmatter?.[1]) return null;
|
|
53
|
+
let fields: unknown;
|
|
54
|
+
try {
|
|
55
|
+
fields = parseYaml(frontmatter[1]);
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (fields === null || typeof fields !== "object") return null;
|
|
60
|
+
const { name, description } = fields as Record<string, unknown>;
|
|
61
|
+
if (typeof description !== "string" || description.length === 0) return null;
|
|
62
|
+
if (typeof name !== "string" || RESERVED_AGENT_NAMES.includes(name.trim().toLowerCase())) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
// OMP keeps the name as written; one with surrounding whitespace cannot be routed, so skip it.
|
|
66
|
+
const parsed = OmpAgentNameSchema.safeParse(name);
|
|
67
|
+
return parsed.success ? parsed.data : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function agentNamesFrom(paths: readonly string[]): Promise<string[]> {
|
|
71
|
+
const names: string[] = [];
|
|
72
|
+
for (const path of paths.slice(0, OMP_AGENT_LIMIT)) {
|
|
73
|
+
if (!path.endsWith(".md")) continue;
|
|
74
|
+
const name = await agentNameFromFile(path).catch(() => null);
|
|
75
|
+
if (name) names.push(name);
|
|
76
|
+
}
|
|
77
|
+
return names;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function agentNamesIn(directory: string): Promise<string[]> {
|
|
81
|
+
try {
|
|
82
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
83
|
+
return agentNamesFrom(
|
|
84
|
+
entries.filter((entry) => entry.isFile()).map((entry) => join(directory, entry.name)),
|
|
85
|
+
);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A scratch-only OMP environment: nothing inherited can point OMP at a real directory. */
|
|
93
|
+
export function scratchOmpEnvironment(base: NodeJS.ProcessEnv, scratch: string): NodeJS.ProcessEnv {
|
|
94
|
+
const environment = { ...base };
|
|
95
|
+
for (const key of OMP_LOCATION_ENV) delete environment[key];
|
|
96
|
+
return {
|
|
97
|
+
...environment,
|
|
98
|
+
HOME: scratch,
|
|
99
|
+
USERPROFILE: scratch,
|
|
100
|
+
PI_CODING_AGENT_DIR: join(scratch, "agent"),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* OMP has no agent list command, but `agents unpack` writes the bundled set to a folder. The
|
|
106
|
+
* folder and the whole OMP home are throwaway, so an OMP that ignores `--dir` still writes
|
|
107
|
+
* nothing into a real agent directory.
|
|
108
|
+
*/
|
|
109
|
+
async function unpackBundledNames(): Promise<string[]> {
|
|
110
|
+
const executable = await resolveOmpExecutable();
|
|
111
|
+
if (!executable) throw new Error("The OMP executable could not be resolved.");
|
|
112
|
+
const scratch = await mkdtemp(join(tmpdir(), "paseo-omp-agents-"));
|
|
113
|
+
try {
|
|
114
|
+
const result = await runBounded(
|
|
115
|
+
defaultSpawn,
|
|
116
|
+
executable,
|
|
117
|
+
["agents", "unpack", "--dir", join(scratch, "out"), "--json"],
|
|
118
|
+
scratchOmpEnvironment(buildStatefulCommandEnv(currentOmpEnvironment()), scratch),
|
|
119
|
+
UNPACK_TIMEOUT_MS,
|
|
120
|
+
KILL_GRACE_MS,
|
|
121
|
+
UNPACK_OUTPUT_LIMIT,
|
|
122
|
+
scratch,
|
|
123
|
+
);
|
|
124
|
+
if (result.outcome !== "exited" || result.exitCode !== 0 || result.truncated) {
|
|
125
|
+
throw new Error("OMP could not unpack its bundled agents.");
|
|
126
|
+
}
|
|
127
|
+
const { written } = UnpackResultSchema.parse(JSON.parse(result.stdout));
|
|
128
|
+
const inside = written.filter((path) => {
|
|
129
|
+
const within = relative(scratch, path);
|
|
130
|
+
return isAbsolute(path) && !within.startsWith("..") && !isAbsolute(within);
|
|
131
|
+
});
|
|
132
|
+
return await agentNamesFrom(inside);
|
|
133
|
+
} finally {
|
|
134
|
+
await rm(scratch, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const DEFAULT_DEPENDENCIES: OmpAgentDependencies = {
|
|
139
|
+
bundledNames: unpackBundledNames,
|
|
140
|
+
userAgentsDir: () => join(ompAgentDir(), "agents"),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export async function listOmpAgentsWithDependencies(
|
|
144
|
+
input: RpcInput<typeof listOmpAgents>,
|
|
145
|
+
dependencies: OmpAgentDependencies,
|
|
146
|
+
): Promise<{ agents: OmpAgent[]; error?: string }> {
|
|
147
|
+
// The most specific source wins when a name exists in several places.
|
|
148
|
+
const bySource = new Map<string, OmpAgent["source"]>();
|
|
149
|
+
let error: string | undefined;
|
|
150
|
+
try {
|
|
151
|
+
for (const name of await dependencies.bundledNames()) bySource.set(name, "bundled");
|
|
152
|
+
} catch {
|
|
153
|
+
error = BUNDLED_FAILURE;
|
|
154
|
+
}
|
|
155
|
+
for (const name of await agentNamesIn(dependencies.userAgentsDir())) bySource.set(name, "user");
|
|
156
|
+
if (input.cwd && isAbsolute(input.cwd)) {
|
|
157
|
+
for (const name of await agentNamesIn(join(input.cwd, ".omp", "agents"))) {
|
|
158
|
+
bySource.set(name, "project");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const agents = [...bySource]
|
|
162
|
+
.map(([name, source]) => ({ name, source }))
|
|
163
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
164
|
+
.slice(0, OMP_AGENT_LIMIT);
|
|
165
|
+
return error ? { agents, error } : { agents };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function resolveListOmpAgents(input: RpcInput<typeof listOmpAgents>) {
|
|
169
|
+
return listOmpAgentsWithDependencies(input, DEFAULT_DEPENDENCIES);
|
|
170
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { Dirent } from "node:fs";
|
|
2
|
+
import { lstat, readdir } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import type {
|
|
7
|
+
listOmpExtensions,
|
|
8
|
+
OmpExtensionItem,
|
|
9
|
+
OmpExtensionsList,
|
|
10
|
+
setOmpExtensionEnabled,
|
|
11
|
+
} from "../shared/omp-extensions";
|
|
12
|
+
import {
|
|
13
|
+
type OmpListDependencies,
|
|
14
|
+
ompListDependencies,
|
|
15
|
+
readList,
|
|
16
|
+
requireOmpExecutable,
|
|
17
|
+
writeListEntry,
|
|
18
|
+
} from "./omp-list-setting";
|
|
19
|
+
import { inOmpScope, readRegularFile } from "./omp-rules";
|
|
20
|
+
import { runSettingsMutation } from "./omp-settings";
|
|
21
|
+
import { ompAgentDir } from "./paths";
|
|
22
|
+
import { OmpPublicError } from "./provider/security";
|
|
23
|
+
|
|
24
|
+
const MAX_ENTRIES_PER_DIR = 200;
|
|
25
|
+
const MAX_ITEMS = 500;
|
|
26
|
+
const MAX_NAME_CHARS = 256;
|
|
27
|
+
const SCRIPT_SUFFIX = /\.(ts|js)$/u;
|
|
28
|
+
const TOOL_SUFFIX = /\.(ts|js|sh|bash|py)$/u;
|
|
29
|
+
const DECLARATION = /\.d\.(ts|js)$/u;
|
|
30
|
+
const DeclaredEntries = z.object({ extensions: z.array(z.unknown()).min(1) });
|
|
31
|
+
const ManifestSchema = z.object({ omp: z.unknown().optional(), pi: z.unknown().optional() });
|
|
32
|
+
|
|
33
|
+
export class OmpExtensionsError extends OmpPublicError {}
|
|
34
|
+
|
|
35
|
+
type Found = Omit<OmpExtensionItem, "enabled">;
|
|
36
|
+
type Level = Found["level"];
|
|
37
|
+
|
|
38
|
+
interface Candidate {
|
|
39
|
+
name: string;
|
|
40
|
+
path: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function isRealDirectory(path: string): Promise<boolean> {
|
|
44
|
+
const info = await lstat(path).catch(() => null);
|
|
45
|
+
return info?.isDirectory() === true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function isRealFile(path: string): Promise<boolean> {
|
|
49
|
+
const info = await lstat(path).catch(() => null);
|
|
50
|
+
return info?.isFile() === true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The visible entries of a real directory, bounded. A symlinked directory or entry is never
|
|
55
|
+
* followed: a Dirent reports a link as a link, so it is neither a file nor a directory here.
|
|
56
|
+
*/
|
|
57
|
+
async function entriesOf(dir: string): Promise<Dirent[]> {
|
|
58
|
+
if (!(await isRealDirectory(dir))) return [];
|
|
59
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
60
|
+
return entries
|
|
61
|
+
.filter((entry) => !entry.name.startsWith("."))
|
|
62
|
+
.sort((a, b) => (a.name < b.name ? -1 : 1))
|
|
63
|
+
.slice(0, MAX_ENTRIES_PER_DIR);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function indexIn(dir: string): Promise<string | null> {
|
|
67
|
+
for (const name of ["index.ts", "index.js"]) {
|
|
68
|
+
if (await isRealFile(join(dir, name))) return join(dir, name);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* OMP loads the entries a folder's package.json declares instead of its index file, under names
|
|
75
|
+
* this scan cannot derive. Such a folder is left out, and so is one whose manifest cannot be read
|
|
76
|
+
* safely (a link, a pipe, an oversize file), rather than listing a switch that would turn off
|
|
77
|
+
* nothing.
|
|
78
|
+
*/
|
|
79
|
+
async function declaresExtensions(folder: string): Promise<boolean> {
|
|
80
|
+
const path = join(folder, "package.json");
|
|
81
|
+
const info = await lstat(path).catch(() => null);
|
|
82
|
+
if (!info) return false;
|
|
83
|
+
const text = info.isFile() ? await readRegularFile(path) : null;
|
|
84
|
+
if (text === null) return true;
|
|
85
|
+
try {
|
|
86
|
+
const manifest = ManifestSchema.safeParse(JSON.parse(text));
|
|
87
|
+
// OMP reads `omp` when the manifest has it and `pi` otherwise.
|
|
88
|
+
const selected = manifest.success ? (manifest.data.omp ?? manifest.data.pi) : undefined;
|
|
89
|
+
return DeclaredEntries.safeParse(selected).success;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* `extensions/<name>.ts|js` and `extensions/<name>/index.ts|js`, as OMP's native discovery. OMP
|
|
97
|
+
* lists direct files in path order before folder indexes and keeps the first of a name, so the
|
|
98
|
+
* order is the precedence: `a.js` beats `a.ts`, and a direct file beats a folder index.
|
|
99
|
+
*/
|
|
100
|
+
async function extensionCandidates(root: string): Promise<Candidate[]> {
|
|
101
|
+
const dir = join(root, "extensions");
|
|
102
|
+
const files: Candidate[] = [];
|
|
103
|
+
const folders: Candidate[] = [];
|
|
104
|
+
for (const entry of await entriesOf(dir)) {
|
|
105
|
+
if (entry.isFile() && SCRIPT_SUFFIX.test(entry.name) && !DECLARATION.test(entry.name)) {
|
|
106
|
+
files.push({ name: entry.name.replace(SCRIPT_SUFFIX, ""), path: join(dir, entry.name) });
|
|
107
|
+
} else if (entry.isDirectory() && !(await declaresExtensions(join(dir, entry.name)))) {
|
|
108
|
+
const index = await indexIn(join(dir, entry.name));
|
|
109
|
+
if (index) folders.push({ name: entry.name, path: index });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...files, ...folders];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `tools/<name>.<ts|js|sh|bash|py>` and `tools/<name>/index.ts`; files first, as for extensions. */
|
|
116
|
+
async function toolCandidates(root: string): Promise<Candidate[]> {
|
|
117
|
+
const dir = join(root, "tools");
|
|
118
|
+
const files: Candidate[] = [];
|
|
119
|
+
const folders: Candidate[] = [];
|
|
120
|
+
for (const entry of await entriesOf(dir)) {
|
|
121
|
+
if (entry.isFile() && TOOL_SUFFIX.test(entry.name) && !DECLARATION.test(entry.name)) {
|
|
122
|
+
files.push({ name: entry.name.replace(TOOL_SUFFIX, ""), path: join(dir, entry.name) });
|
|
123
|
+
} else if (entry.isDirectory() && (await isRealFile(join(dir, entry.name, "index.ts")))) {
|
|
124
|
+
folders.push({ name: entry.name, path: join(dir, entry.name, "index.ts") });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return [...files, ...folders];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function entryFor(
|
|
131
|
+
kind: Found["kind"],
|
|
132
|
+
level: Level,
|
|
133
|
+
name: string,
|
|
134
|
+
path: string,
|
|
135
|
+
id: string,
|
|
136
|
+
): Found {
|
|
137
|
+
return { kind, name: name.slice(0, MAX_NAME_CHARS), level, path, id };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function scanRoot(root: string, level: Level): Promise<Found[]> {
|
|
141
|
+
const items: Found[] = [];
|
|
142
|
+
for (const { name, path } of await extensionCandidates(root)) {
|
|
143
|
+
items.push(entryFor("extension", level, name, path, `extension-module:${name}`));
|
|
144
|
+
}
|
|
145
|
+
const hooksReal = await isRealDirectory(join(root, "hooks"));
|
|
146
|
+
for (const type of hooksReal ? ["pre", "post"] : []) {
|
|
147
|
+
const dir = join(root, "hooks", type);
|
|
148
|
+
for (const entry of await entriesOf(dir)) {
|
|
149
|
+
if (!entry.isFile()) continue;
|
|
150
|
+
const dot = entry.name.lastIndexOf(".");
|
|
151
|
+
const tool = dot < 0 ? entry.name : entry.name.slice(0, dot);
|
|
152
|
+
const id = `hook:${type}:${tool}:${entry.name}`;
|
|
153
|
+
items.push(entryFor("hook", level, `${type}/${entry.name}`, join(dir, entry.name), id));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
for (const { name, path } of await toolCandidates(root)) {
|
|
157
|
+
items.push(entryFor("tool", level, name, path, `tool:${name}`));
|
|
158
|
+
}
|
|
159
|
+
// OMP keys extensions and tools by name, so of two same-named entries only the first loads;
|
|
160
|
+
// the candidates are already in OMP's order. Keep one row per id.
|
|
161
|
+
const byId = new Map<string, Found>();
|
|
162
|
+
for (const item of items) {
|
|
163
|
+
if (!byId.has(item.id)) byId.set(item.id, item);
|
|
164
|
+
}
|
|
165
|
+
return [...byId.values()];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* What OMP would discover in the documented folders: the workspace's `.omp/` (project level) and
|
|
170
|
+
* the agent directory (user level). It does not read `.gitignore` or the `extensions` setting, and
|
|
171
|
+
* it leaves out folders whose `package.json` declares entries, so it is a close inventory, not
|
|
172
|
+
* OMP's own list.
|
|
173
|
+
*/
|
|
174
|
+
export async function scanExtensions(cwd: string | undefined, agentDir: string): Promise<Found[]> {
|
|
175
|
+
const projectRoot = cwd ? join(cwd, ".omp") : null;
|
|
176
|
+
const project =
|
|
177
|
+
projectRoot && (await isRealDirectory(projectRoot))
|
|
178
|
+
? await scanRoot(projectRoot, "project")
|
|
179
|
+
: [];
|
|
180
|
+
const user = await scanRoot(agentDir, "user");
|
|
181
|
+
return [...project, ...user].slice(0, MAX_ITEMS);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function listOmpExtensionsWithDependencies(
|
|
185
|
+
input: RpcInput<typeof listOmpExtensions>,
|
|
186
|
+
dependencies: OmpListDependencies,
|
|
187
|
+
): Promise<OmpExtensionsList> {
|
|
188
|
+
try {
|
|
189
|
+
const executable = await requireOmpExecutable(dependencies);
|
|
190
|
+
return await inOmpScope(input.cwd, dependencies, async (runIn) => {
|
|
191
|
+
const list = await readList(dependencies, executable, "disabledExtensions", runIn);
|
|
192
|
+
const disabled = new Set(list.map((entry) => entry.trim()));
|
|
193
|
+
const items = (await scanExtensions(input.cwd, ompAgentDir())).map((item) => ({
|
|
194
|
+
...item,
|
|
195
|
+
enabled: !disabled.has(item.id),
|
|
196
|
+
}));
|
|
197
|
+
return { status: "ready" as const, items };
|
|
198
|
+
});
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error instanceof OmpPublicError) return { status: "error", message: error.message };
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Only an id the scan finds right now can be written, so the list never collects stray entries. */
|
|
206
|
+
export async function setOmpExtensionEnabledWithDependencies(
|
|
207
|
+
input: RpcInput<typeof setOmpExtensionEnabled>,
|
|
208
|
+
dependencies: OmpListDependencies,
|
|
209
|
+
): Promise<{ status: "ok" } | { status: "error"; message: string }> {
|
|
210
|
+
try {
|
|
211
|
+
const executable = await requireOmpExecutable(dependencies);
|
|
212
|
+
await inOmpScope(input.cwd, dependencies, async (runIn) => {
|
|
213
|
+
const items = await scanExtensions(input.cwd, ompAgentDir());
|
|
214
|
+
if (!items.some((item) => item.id === input.id)) {
|
|
215
|
+
throw new OmpExtensionsError("OMP does not discover that extension, hook or tool here");
|
|
216
|
+
}
|
|
217
|
+
const change = { cwd: input.cwd, list: "disabledExtensions" as const, entry: input.id };
|
|
218
|
+
await runSettingsMutation(() =>
|
|
219
|
+
writeListEntry({ ...change, enabled: input.enabled }, dependencies, executable, runIn),
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
return { status: "ok" };
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (error instanceof OmpPublicError) return { status: "error", message: error.message };
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function resolveListOmpExtensions(input: RpcInput<typeof listOmpExtensions>) {
|
|
230
|
+
return listOmpExtensionsWithDependencies(input, ompListDependencies);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function resolveSetOmpExtensionEnabled(input: RpcInput<typeof setOmpExtensionEnabled>) {
|
|
234
|
+
return setOmpExtensionEnabledWithDependencies(input, ompListDependencies);
|
|
235
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type OmpRulesDependencies, ompCommandDependencies, readSetting } from "./omp-rules";
|
|
4
|
+
import {
|
|
5
|
+
type OmpSettingsDependencies,
|
|
6
|
+
ompSettingsDependencies,
|
|
7
|
+
readProjectConfigText,
|
|
8
|
+
writeProjectChanges,
|
|
9
|
+
} from "./omp-settings";
|
|
10
|
+
import { OmpPublicError } from "./provider/security";
|
|
11
|
+
|
|
12
|
+
export type OmpListName = "skills.ignoredSkills" | "disabledExtensions" | "ttsr.disabledRules";
|
|
13
|
+
|
|
14
|
+
export class OmpListError extends OmpPublicError {}
|
|
15
|
+
|
|
16
|
+
export interface OmpListDependencies extends OmpRulesDependencies {
|
|
17
|
+
validateProjectConfig: OmpSettingsDependencies["validateProjectConfig"];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ompListDependencies: OmpListDependencies = {
|
|
21
|
+
...ompCommandDependencies,
|
|
22
|
+
validateProjectConfig: ompSettingsDependencies.validateProjectConfig,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const ListSettingSchema = z.object({ value: z.array(z.string()) });
|
|
26
|
+
const UNREADABLE_CONFIG = "The workspace OMP configuration could not be read";
|
|
27
|
+
|
|
28
|
+
export async function requireOmpExecutable(dependencies: OmpListDependencies): Promise<string> {
|
|
29
|
+
const executable = await dependencies.resolveExecutable();
|
|
30
|
+
if (!executable) throw new OmpListError("The omp command was not found on this host");
|
|
31
|
+
return executable;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The effective list in `runIn`: a workspace's own list when it has one, else the user's. */
|
|
35
|
+
export function readList(
|
|
36
|
+
dependencies: OmpListDependencies,
|
|
37
|
+
executable: string,
|
|
38
|
+
list: OmpListName,
|
|
39
|
+
runIn: string,
|
|
40
|
+
): Promise<string[]> {
|
|
41
|
+
return readSetting(dependencies, executable, list, ListSettingSchema, runIn);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ListEntryChange {
|
|
45
|
+
cwd?: string;
|
|
46
|
+
list: OmpListName;
|
|
47
|
+
entry: string;
|
|
48
|
+
/** Enabled removes the entry from the list; disabled adds it. */
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A project list replaces the user list, so a workspace edit starts from the effective list and
|
|
54
|
+
* saves all of it to the project file. Starting from the project file alone would turn every
|
|
55
|
+
* entry the user turned off back on. Run it inside `runSettingsMutation`.
|
|
56
|
+
*/
|
|
57
|
+
export async function writeListEntry(
|
|
58
|
+
change: ListEntryChange,
|
|
59
|
+
dependencies: OmpListDependencies,
|
|
60
|
+
executable: string,
|
|
61
|
+
runIn: string,
|
|
62
|
+
): Promise<void> {
|
|
63
|
+
const projectPath = change.cwd ? join(change.cwd, ".omp", "config.yml") : null;
|
|
64
|
+
const snapshot = projectPath
|
|
65
|
+
? await readProjectConfigText(projectPath).catch(() => {
|
|
66
|
+
throw new OmpListError(UNREADABLE_CONFIG);
|
|
67
|
+
})
|
|
68
|
+
: "";
|
|
69
|
+
const current = await readList(dependencies, executable, change.list, runIn);
|
|
70
|
+
const kept = current.filter((entry) => entry.trim() !== change.entry);
|
|
71
|
+
const next = change.enabled ? kept : [...kept, change.entry];
|
|
72
|
+
if (change.cwd) {
|
|
73
|
+
const outcome = await writeProjectChanges(
|
|
74
|
+
change.cwd,
|
|
75
|
+
snapshot,
|
|
76
|
+
[{ operation: "set", path: change.list, value: next }],
|
|
77
|
+
executable,
|
|
78
|
+
dependencies,
|
|
79
|
+
).catch((error: unknown) => {
|
|
80
|
+
// The writer's messages are written for the user, as in the settings editor.
|
|
81
|
+
throw new OmpListError(
|
|
82
|
+
error instanceof Error ? error.message : "Could not update workspace settings.",
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
if (outcome === "conflict") {
|
|
86
|
+
throw new OmpListError("The workspace configuration changed. Try again");
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const run = await dependencies.run(
|
|
91
|
+
executable,
|
|
92
|
+
["config", "set", change.list, "--json", "--", JSON.stringify(next)],
|
|
93
|
+
runIn,
|
|
94
|
+
);
|
|
95
|
+
if (run.outcome !== "exited" || run.exitCode !== 0) {
|
|
96
|
+
throw new OmpListError("OMP rejected the change");
|
|
97
|
+
}
|
|
98
|
+
}
|