@ory/openclaw 1.9.2 → 1.10.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/README.md CHANGED
@@ -12,20 +12,35 @@ One command installs two independent halves:
12
12
  ## What you'll need
13
13
 
14
14
  - [OpenClaw](https://github.com/openclaw/openclaw), installed and configured
15
+ <!-- BEGIN GENERATED requirements -->
15
16
  - Node.js **22 or newer**
16
17
  - [Docker](https://docs.docker.com/get-docker/) — only if you want to run Ory locally
17
18
  - macOS or Linux (Windows works via WSL2)
19
+ <!-- END GENERATED requirements -->
18
20
 
19
21
  ## Get started
20
22
 
21
- OpenClaw loads in-process plugins by module name plus an entry in `.openclaw/config.json` — it doesn't scan `node_modules`, so the plugin has to be registered. Install the package, then register it.:
23
+ OpenClaw loads a plugin from a directory listed in its config — it doesn't scan `node_modules`, so the plugin has to be registered:
22
24
 
23
25
  ```bash
24
- npm install @ory/openclaw # so OpenClaw can resolve the package
25
- npx -y -p @ory/openclaw ory-openclaw install # register + enable in .openclaw/config.json
26
+ npx -y -p @ory/openclaw ory-openclaw install # register + enable in OpenClaw's config
26
27
  ```
27
28
 
28
- Registering also lays down the Ory skills (via `skills.load.extraDirs`) and the Ory MCP server. Confirm everything landed with:
29
+ The installer edits the one config file OpenClaw reads. It looks for it the way OpenClaw does:
30
+
31
+ 1. `OPENCLAW_CONFIG_PATH`, when set
32
+ 2. `$OPENCLAW_STATE_DIR/openclaw.json`, when `OPENCLAW_STATE_DIR` is set
33
+ 3. `~/.openclaw/openclaw.json` (`~` follows `OPENCLAW_HOME` when that is set)
34
+
35
+ OpenClaw has no project-level config, so there is nothing to commit to a repository. If you run OpenClaw with `--profile <name>`, set `OPENCLAW_STATE_DIR=~/.openclaw-<name>` for the install, because the profile flag only applies inside OpenClaw.
36
+
37
+ It writes three things there and leaves everything else as it was:
38
+
39
+ - `plugins.load.paths` and `plugins.entries["ory-agent-security"].enabled`, so OpenClaw finds and enables the plugin
40
+ - `mcp.servers.ory`, the Ory MCP server
41
+ - `skills.load.extraDirs`, pointing at the Ory skills under `~/.config/ory-agent-plugins/openclaw/skills`
42
+
43
+ Restart the OpenClaw Gateway if it does not pick up the change. Confirm everything landed with:
29
44
 
30
45
  ```bash
31
46
  npx -y -p @ory/openclaw ory-openclaw status
@@ -33,7 +48,13 @@ npx -y -p @ory/openclaw ory-openclaw status
33
48
 
34
49
  `status` is your one-stop check: what's configured, who's signed in, which tools are covered by permissions, plugin and skill registration, and recent activity. Until you connect Agent Security, the identity and permission rows say so and name what's missing.
35
50
 
36
- > Prefer OpenClaw's plugin ecosystem? Run `openclaw plugins install npm:@ory/openclaw` then `openclaw plugins enable ory-agent-security`. That registers the plugin the same way, with Agent Security not connected. Run `npx -y -p @ory/openclaw ory-openclaw install` afterwards to lay down the Ory skills and MCP server. Point the installer at another project with `install --project-dir <path>`.
51
+ `openclaw.json` is JSON5. The installer reads JSON with comments and trailing commas, and keeps your comments when it writes, except those inside the `plugins`, `mcp`, and `skills` sections it rewrites. It does not read other JSON5 syntax, such as unquoted keys or single-quoted strings: on a file like that it stops with an error and changes nothing. Add the three entries above by hand in that case, or with `openclaw config set`.
52
+
53
+ The installer also refuses to edit a config OpenClaw treats as read-only (`OPENCLAW_CONFIG_READONLY=1` or `OPENCLAW_NIX_MODE=1`); add the entries through whatever manages that file.
54
+
55
+ Versions before this one wrote `<project>/.openclaw/config.json`, which OpenClaw never reads, so the plugin was not loaded. Run `install` again from that project directory: it registers the plugin in the real config and removes the Ory entries from the old file.
56
+
57
+ > Prefer OpenClaw's plugin ecosystem? Run `openclaw plugins install npm:@ory/openclaw` then `openclaw plugins enable ory-agent-security`. The package declares its entry (`openclaw.extensions`) and config schema for that path, and `openclaw.compat.pluginApi` asks for OpenClaw 2026.11.3 or newer. Agent Security starts not connected. Run `npx -y -p @ory/openclaw ory-openclaw install` afterwards to lay down the Ory skills and MCP server.
37
58
 
38
59
  ## Skills and commands
39
60
 
@@ -119,13 +140,50 @@ collision-suffixed server name may resolve as uncatalogued. A server name that
119
140
  itself contains `__` splits at the wrong place. MCP calls made through
120
141
  OpenClaw's code mode arrive as one code-mode tool and are not identified.
121
142
 
122
- The tool hooks register through `api.on`. Current OpenClaw only invokes typed
123
- hooks such as `before_tool_call` that way and ignores `registerHook`
124
- registrations for them. On hosts without `api.on`, the plugin falls back to
125
- `registerHook`.
143
+ ### Lifecycle hooks
144
+
145
+ Every hook registers through `api.on`: `session_start`, `before_agent_run`,
146
+ `before_tool_call`, `after_tool_call`, `subagent_spawned`, and
147
+ `subagent_ended`. Current OpenClaw only invokes these typed hooks that way and
148
+ ignores `registerHook` registrations for them. On hosts without `api.on`, the
149
+ plugin falls back to `registerHook`.
150
+
151
+ `before_agent_run` refreshes your sign-in before each turn and never blocks a
152
+ run. OpenClaw gives that hook 15 seconds and rejects your message if a plugin
153
+ is still busy then, so the plugin does two things to stay clear of it. The
154
+ per-turn step only reuses or refreshes a stored token; it never opens the
155
+ browser. And it stops waiting after 5 seconds and lets the run continue while
156
+ the refresh finishes in the background. Browser sign-in happens at
157
+ `session_start` only, which OpenClaw does not time out. If you did not finish
158
+ signing in there, start a new session to be asked again.
159
+
160
+ OpenClaw only runs `before_agent_run` for a non-bundled plugin that has been
161
+ granted conversation access, so add this to `openclaw.json` to keep sign-in
162
+ fresh in long sessions:
163
+
164
+ ```json
165
+ {
166
+ "plugins": {
167
+ "entries": {
168
+ "ory-agent-security": {
169
+ "enabled": true,
170
+ "hooks": { "allowConversationAccess": true }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ The plugin never reads the prompt or messages that hook receives. Without the
178
+ grant, sign-in still runs at `session_start` and tool checks are unaffected.
179
+
180
+ Sub-agents get their identity at `subagent_spawned` (OpenClaw removed
181
+ `subagent_spawning`). That hook fires after the child starts, so a child's
182
+ first tool call can be checked before its sub-agent identity is registered.
126
183
 
127
184
  ## Connect to Ory Agent Security
128
185
 
186
+ <!-- BEGIN GENERATED connect -->
129
187
  Copy the connection details from the [Ory Console](https://console.ory.sh) under **Agent Security**:
130
188
 
131
189
  | Value | Flag | Environment variable |
@@ -148,12 +206,15 @@ npx -y -p @ory/openclaw ory-openclaw configure \
148
206
 
149
207
  Sign-in runs at the start of every session and never blocks — a declined, skipped, or timed-out login simply leaves that session without a user identity.
150
208
 
209
+ OpenClaw's plugin hooks have no way to show you a notice without blocking, so a sign-in that is declined or fails is logged as `Ory sign-in did not complete: <reason>. Tool calls may be denied this session.` in the gateway log.
210
+
151
211
  Settings are saved to `~/.config/ory-agent-plugins/config.json` and shared across all your Ory agent plugins; environment variables win when both are set. Running headless with an OAuth2 access token already? Set `ORY_USER_OAUTH2_TOKEN` and the browser step is skipped entirely.
212
+ <!-- END GENERATED connect -->
152
213
 
153
214
  ## Commands
154
215
 
155
216
  ```
156
- ory-openclaw install | uninstall Install (add --project-url to also connect Agent Security) / remove; --project-dir <path> targets another project
217
+ ory-openclaw install | uninstall Install (add --project-url to also connect Agent Security) / remove; edits OpenClaw's own config (see Get started)
157
218
  ory-openclaw status Show configuration, identities, native tool access, recent activity
158
219
  ory-openclaw permissions <cmd> status (read-only; blocks + posture live in the Ory Console)
159
220
  ory-openclaw configure <flags> Connect a project (--project-url) or --disconnect
@@ -166,13 +227,17 @@ All prefixed with `npx -y -p @ory/openclaw`.
166
227
 
167
228
  ## Troubleshooting
168
229
 
169
- - **`local-up` fails** — make sure Docker is running and ports `4000`, `4100`, `4455`, and `16686` are free.
230
+ - **`status` says `Plugin registered: NO` after installing** — check the `Config file` line. It must be the file your OpenClaw reads; set `OPENCLAW_CONFIG_PATH` or `OPENCLAW_STATE_DIR` to the same values OpenClaw runs with and install again.
231
+ - **`Cannot parse …/openclaw.json`** — the file uses JSON5 syntax beyond comments and trailing commas. Nothing was changed; add the entries listed under [Get started](#get-started) by hand.
232
+ - **`local-up` fails** — <!-- BEGIN GENERATED local-stack-ports -->make sure Docker is running and ports `4000`, `4100`, and `4455` are free.<!-- END GENERATED local-stack-ports -->
170
233
  - **Browser sign-in loops** (after connecting) — confirm the reserved login client has all four documented loopback redirect URIs; `agent unregister` only clears legacy agent OAuth state.
171
234
  - **Running an older CLI than expected** — `npx -p @ory/openclaw` (no version pin) reuses a previously-downloaded copy instead of re-resolving to the latest. The install banner prints the running version; confirm it with `npx -y -p @ory/openclaw ory-openclaw version`. To force the current release, clear the cache and reinstall: `rm -rf ~/.npm/_npx` then `npx -y -p @ory/openclaw ory-openclaw install`. Pinning an exact version (`@ory/openclaw@<version>`) also bypasses the cached copy.
172
235
 
173
236
  ## Learn more
174
237
 
238
+ <!-- BEGIN GENERATED ory-links -->
175
239
  - [Ory documentation](https://www.ory.com/docs/) · [Ory Console](https://console.ory.sh) · [Ory Elements](https://github.com/ory/elements)
240
+ <!-- END GENERATED ory-links -->
176
241
  - [OpenClaw documentation](https://github.com/openclaw/openclaw)
177
242
 
178
243
  ## License
@@ -1,12 +1,17 @@
1
1
  /**
2
2
  * Materialize / clean the Ory skill catalog and command-skills for the
3
- * OpenClaw plugin. The 4 guide skills (auth-setup, login-flow, social-login,
4
- * local-dev) plus the 2 local-stack commands (rendered as user-invocable
5
- * skills) land at `<projectDir>/.openclaw/skills/<name>/SKILL.md`.
3
+ * OpenClaw plugin. The guide skills plus the local-stack commands (rendered
4
+ * as user-invocable skills) land at `<skillsDir>/<name>/SKILL.md`.
6
5
  *
7
- * The skills directory's absolute path is registered in the OpenClaw config
8
- * under `skills.load.extraDirs` so the harness picks the skills up even when
9
- * its default workspace discovery doesn't cover this location.
6
+ * The skills live under the shared Ory data directory, not inside OpenClaw's
7
+ * state directory, and reach OpenClaw through `skills.load.extraDirs` in its
8
+ * config (see `plugin-config.ts`). This module only touches the skill files.
10
9
  */
11
- export declare function installOpenclawOryAssets(projectDir: string): void;
12
- export declare function uninstallOpenclawOryAssets(projectDir: string): void;
10
+ /** Where the Ory skills are written: `<Ory data dir>/openclaw/skills`. */
11
+ export declare function orySkillsDir(): string;
12
+ /** Skills directory earlier installer versions used: `<project>/.openclaw/skills`. */
13
+ export declare function legacyProjectSkillsDir(projectDir: string): string;
14
+ /** Write the Ory skills into `dir` and return it. */
15
+ export declare function installOpenclawOryAssets(dir?: string): string;
16
+ /** Remove the Ory skills from `dir`, and `dir` itself when that empties it. */
17
+ export declare function uninstallOpenclawOryAssets(dir?: string): void;
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
3
  * Materialize / clean the Ory skill catalog and command-skills for the
4
- * OpenClaw plugin. The 4 guide skills (auth-setup, login-flow, social-login,
5
- * local-dev) plus the 2 local-stack commands (rendered as user-invocable
6
- * skills) land at `<projectDir>/.openclaw/skills/<name>/SKILL.md`.
4
+ * OpenClaw plugin. The guide skills plus the local-stack commands (rendered
5
+ * as user-invocable skills) land at `<skillsDir>/<name>/SKILL.md`.
7
6
  *
8
- * The skills directory's absolute path is registered in the OpenClaw config
9
- * under `skills.load.extraDirs` so the harness picks the skills up even when
10
- * its default workspace discovery doesn't cover this location.
7
+ * The skills live under the shared Ory data directory, not inside OpenClaw's
8
+ * state directory, and reach OpenClaw through `skills.load.extraDirs` in its
9
+ * config (see `plugin-config.ts`). This module only touches the skill files.
11
10
  */
12
11
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
12
  if (k2 === undefined) k2 = k;
@@ -43,84 +42,38 @@ var __importStar = (this && this.__importStar) || (function () {
43
42
  };
44
43
  })();
45
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.orySkillsDir = orySkillsDir;
46
+ exports.legacyProjectSkillsDir = legacyProjectSkillsDir;
46
47
  exports.installOpenclawOryAssets = installOpenclawOryAssets;
47
48
  exports.uninstallOpenclawOryAssets = uninstallOpenclawOryAssets;
48
49
  const fs = __importStar(require("node:fs"));
49
50
  const path = __importStar(require("node:path"));
50
51
  const argus_1 = require("@ory/argus");
52
+ const install_1 = require("@ory/argus/install");
51
53
  const RENDER_OPTS = {
52
54
  binName: "ory-openclaw",
53
55
  packageName: "@ory/openclaw",
54
56
  };
55
- const CONFIG_DIR = ".openclaw";
56
- function configDir(projectDir) {
57
- return path.join(projectDir, CONFIG_DIR);
57
+ /** Where the Ory skills are written: `<Ory data dir>/openclaw/skills`. */
58
+ function orySkillsDir() {
59
+ return path.resolve((0, argus_1.getHarnessDataDir)("openclaw"), "skills");
58
60
  }
59
- function configPath(projectDir) {
60
- return path.join(configDir(projectDir), "config.json");
61
+ /** Skills directory earlier installer versions used: `<project>/.openclaw/skills`. */
62
+ function legacyProjectSkillsDir(projectDir) {
63
+ return path.resolve(projectDir, ".openclaw", "skills");
61
64
  }
62
- function skillsDir(projectDir) {
63
- return path.join(configDir(projectDir), "skills");
64
- }
65
- /** Write the absolute skills dir into `skills.load.extraDirs` (deduped). */
66
- function addExtraDir(projectDir, absDir) {
67
- const file = configPath(projectDir);
68
- const config = (0, argus_1.readJsonFile)(file);
69
- const skills = (config.skills ?? {});
70
- const load = (skills.load ?? {});
71
- const dirs = (load.extraDirs ?? []);
72
- const next = [...dirs.filter((d) => d !== absDir), absDir];
73
- load.extraDirs = next;
74
- skills.load = load;
75
- config.skills = skills;
76
- fs.mkdirSync(path.dirname(file), { recursive: true });
77
- fs.writeFileSync(file, JSON.stringify(config, null, 2) + "\n");
78
- }
79
- /** Remove the absolute skills dir from `skills.load.extraDirs`. */
80
- function removeExtraDir(projectDir, absDir) {
81
- const file = configPath(projectDir);
82
- if (!fs.existsSync(file))
83
- return;
84
- const config = (0, argus_1.readJsonFile)(file);
85
- const skills = (config.skills ?? {});
86
- const load = (skills.load ?? {});
87
- const dirs = (load.extraDirs ?? []);
88
- const next = dirs.filter((d) => d !== absDir);
89
- if (next.length === 0) {
90
- delete load.extraDirs;
91
- }
92
- else {
93
- load.extraDirs = next;
94
- }
95
- if (Object.keys(load).length === 0)
96
- delete skills.load;
97
- if (Object.keys(skills).length === 0)
98
- delete config.skills;
99
- fs.writeFileSync(file, JSON.stringify(config, null, 2) + "\n");
100
- }
101
- function installOpenclawOryAssets(projectDir) {
102
- const dir = skillsDir(projectDir);
65
+ /** Write the Ory skills into `dir` and return it. */
66
+ function installOpenclawOryAssets(dir = orySkillsDir()) {
103
67
  fs.mkdirSync(dir, { recursive: true });
104
- const guideSkills = (0, argus_1.renderOrySkills)("openclaw", RENDER_OPTS);
105
- const commandSkills = (0, argus_1.renderOryCommands)("openclaw", RENDER_OPTS).map(argus_1.commandToSkill);
106
- (0, argus_1.writeSkillTree)(dir, [...guideSkills, ...commandSkills]);
107
- addExtraDir(projectDir, path.resolve(dir));
68
+ const guideSkills = (0, install_1.renderOrySkills)("openclaw", RENDER_OPTS);
69
+ const commandSkills = (0, install_1.renderOryCommands)("openclaw", RENDER_OPTS).map(install_1.commandToSkill);
70
+ (0, install_1.writeSkillTree)(dir, [...guideSkills, ...commandSkills]);
71
+ return dir;
108
72
  }
109
- function safeRmEmpty(dir) {
110
- try {
111
- if (fs.existsSync(dir) && fs.readdirSync(dir).length === 0) {
112
- fs.rmdirSync(dir);
113
- }
114
- }
115
- catch {
116
- /* ignore */
117
- }
118
- }
119
- function uninstallOpenclawOryAssets(projectDir) {
120
- const dir = skillsDir(projectDir);
121
- if (fs.existsSync(dir)) {
122
- (0, argus_1.removeSkillDirs)(dir, [...argus_1.ORY_SKILL_NAMES, ...argus_1.ORY_COMMAND_SKILL_NAMES]);
123
- safeRmEmpty(dir);
124
- }
125
- removeExtraDir(projectDir, path.resolve(dir));
73
+ /** Remove the Ory skills from `dir`, and `dir` itself when that empties it. */
74
+ function uninstallOpenclawOryAssets(dir = orySkillsDir()) {
75
+ if (!fs.existsSync(dir))
76
+ return;
77
+ (0, install_1.removeSkillDirs)(dir, [...install_1.ORY_SKILL_NAMES, ...install_1.ORY_COMMAND_SKILL_NAMES]);
78
+ (0, install_1.removeDirIfEmpty)(dir);
126
79
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Install, uninstall, and status for the Ory OpenClaw plugin, shared by the
3
+ * `ory-openclaw` and `ory-openclaw-setup` bins.
4
+ *
5
+ * Everything OpenClaw needs goes into the one config file it loads (see
6
+ * `openclaw-config.ts`): the plugin's load path and enablement, the Ory MCP
7
+ * server under `mcp.servers`, and the Ory skills directory under
8
+ * `skills.load.extraDirs`. The file is read once and written once, through the
9
+ * shared JSONC-aware helpers, so unrelated settings and comments survive and
10
+ * an unparseable file stops the command untouched.
11
+ */
12
+ export interface InstallerOptions {
13
+ /** CLI arguments after the subcommand (`--runtime-dir`, `--project-dir`, …). */
14
+ args?: readonly string[];
15
+ /** Environment used to locate OpenClaw's config. Defaults to `process.env`. */
16
+ env?: NodeJS.ProcessEnv;
17
+ /** Package root of the running CLI; supplies the runtime version to install. */
18
+ packageRoot: string;
19
+ /** Directory checked for a legacy project config when `--project-dir` is absent. */
20
+ cwd?: string;
21
+ log?: (line: string) => void;
22
+ }
23
+ export interface InstallResult {
24
+ configPath: string;
25
+ pluginDir: string;
26
+ skillsDir: string;
27
+ mcpRegistered: boolean;
28
+ }
29
+ export interface UninstallResult {
30
+ configPath: string;
31
+ /** False when OpenClaw has no config file, so there was nothing to edit. */
32
+ configChanged: boolean;
33
+ }
34
+ /** Register the plugin, the MCP server, and the skills in OpenClaw's config. */
35
+ export declare function installOpenclaw(opts: InstallerOptions): InstallResult;
36
+ /** Remove only the Ory entries from OpenClaw's config, plus the Ory skills and runtime. */
37
+ export declare function uninstallOpenclaw(opts: Omit<InstallerOptions, "packageRoot">): UninstallResult;
38
+ export interface OpenclawPluginStatus {
39
+ configPath: string;
40
+ configExists: boolean;
41
+ /** Set when the config exists but could not be parsed. */
42
+ configError?: string;
43
+ /** `plugins.entries["ory-agent-security"].enabled` is true. */
44
+ enabled: boolean;
45
+ /** The `plugins.load.paths` entry that holds this plugin's manifest. */
46
+ pluginDir?: string;
47
+ mcpRegistered: boolean;
48
+ skillsRegistered: boolean;
49
+ }
50
+ /** Read what OpenClaw's config says about the Ory plugin. Never throws. */
51
+ export declare function openclawPluginStatus(env?: NodeJS.ProcessEnv): OpenclawPluginStatus;
52
+ /** The "Hooks & plugin" section of `ory-openclaw status`. */
53
+ export declare function openclawPluginStatusLines(env?: NodeJS.ProcessEnv): string[];
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ /**
3
+ * Install, uninstall, and status for the Ory OpenClaw plugin, shared by the
4
+ * `ory-openclaw` and `ory-openclaw-setup` bins.
5
+ *
6
+ * Everything OpenClaw needs goes into the one config file it loads (see
7
+ * `openclaw-config.ts`): the plugin's load path and enablement, the Ory MCP
8
+ * server under `mcp.servers`, and the Ory skills directory under
9
+ * `skills.load.extraDirs`. The file is read once and written once, through the
10
+ * shared JSONC-aware helpers, so unrelated settings and comments survive and
11
+ * an unparseable file stops the command untouched.
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.installOpenclaw = installOpenclaw;
48
+ exports.uninstallOpenclaw = uninstallOpenclaw;
49
+ exports.openclawPluginStatus = openclawPluginStatus;
50
+ exports.openclawPluginStatusLines = openclawPluginStatusLines;
51
+ const fs = __importStar(require("node:fs"));
52
+ const path = __importStar(require("node:path"));
53
+ const install_1 = require("@ory/argus/install");
54
+ const assets_js_1 = require("./assets.js");
55
+ const openclaw_config_js_1 = require("./openclaw-config.js");
56
+ const plugin_config_js_1 = require("./plugin-config.js");
57
+ function sameJson(a, b) {
58
+ return JSON.stringify(a) === JSON.stringify(b);
59
+ }
60
+ function projectDirFrom(args, cwd) {
61
+ const idx = args.indexOf("--project-dir");
62
+ return idx !== -1 && args[idx + 1] ? args[idx + 1] : cwd;
63
+ }
64
+ function assertConfigWritable(configPath, env) {
65
+ const reason = (0, openclaw_config_js_1.openClawConfigReadOnlyReason)(env);
66
+ if (reason)
67
+ throw new openclaw_config_js_1.OpenClawConfigReadOnlyError(configPath, reason);
68
+ }
69
+ /**
70
+ * Earlier versions of this installer wrote `<project>/.openclaw/config.json`
71
+ * and `<project>/.openclaw/skills`, which OpenClaw never reads. Remove the Ory
72
+ * entries from that file (deleting it once nothing else is left) and the Ory
73
+ * skills beside it, so a stale copy cannot be mistaken for a working install.
74
+ */
75
+ function cleanLegacyProjectInstall(projectDir, activeConfigPath, log) {
76
+ const legacyDir = path.resolve(projectDir, ".openclaw");
77
+ const legacyConfig = path.join(legacyDir, "config.json");
78
+ if (!fs.existsSync(legacyConfig) || legacyConfig === path.resolve(activeConfigPath))
79
+ return;
80
+ let config;
81
+ try {
82
+ config = (0, install_1.readJsonFile)(legacyConfig);
83
+ }
84
+ catch (err) {
85
+ if (!(err instanceof install_1.ConfigParseError))
86
+ throw err;
87
+ log(` Left ${legacyConfig} alone: it is not readable JSON, and OpenClaw does not read it.`);
88
+ return;
89
+ }
90
+ const skillsDir = (0, assets_js_1.legacyProjectSkillsDir)(projectDir);
91
+ let cleaned = (0, plugin_config_js_1.unregisterPluginFromConfig)(config);
92
+ cleaned = (0, install_1.removeMcpServer)(cleaned);
93
+ cleaned = (0, plugin_config_js_1.removeSkillsExtraDir)(cleaned, skillsDir);
94
+ if (sameJson(cleaned, config))
95
+ return;
96
+ (0, assets_js_1.uninstallOpenclawOryAssets)(skillsDir);
97
+ if (Object.keys(cleaned).length === 0) {
98
+ fs.rmSync(legacyConfig, { force: true });
99
+ (0, install_1.removeDirIfEmpty)(legacyDir);
100
+ }
101
+ else {
102
+ (0, install_1.writeJsonFile)(legacyConfig, cleaned);
103
+ }
104
+ log(` Removed the Ory entries from ${legacyConfig}; OpenClaw does not read that file.`);
105
+ }
106
+ /**
107
+ * Forget the runtime wiring without deleting the plugin's entry file.
108
+ *
109
+ * The shared `removeRuntimeWiring` deletes the wiring's hook shim. An
110
+ * in-process harness has no shim: the recorded path is the runtime's own
111
+ * `dist/index.js`. Deleting it would break a linked runtime (`--runtime-dir`,
112
+ * a workspace build, an administrator-managed package directory) and a store
113
+ * other Ory plugins still share, so the file is put back when it was removed.
114
+ */
115
+ function removeOpenclawRuntimeWiring() {
116
+ const entry = (0, install_1.getRuntimeWiring)("openclaw")?.hookShim;
117
+ let saved;
118
+ try {
119
+ if (entry)
120
+ saved = { body: fs.readFileSync(entry), mode: fs.statSync(entry).mode };
121
+ }
122
+ catch {
123
+ /* nothing to preserve */
124
+ }
125
+ (0, install_1.removeRuntimeWiring)("openclaw");
126
+ if (entry && saved && !fs.existsSync(entry)) {
127
+ fs.writeFileSync(entry, saved.body, { mode: saved.mode });
128
+ }
129
+ }
130
+ /** Register the plugin, the MCP server, and the skills in OpenClaw's config. */
131
+ function installOpenclaw(opts) {
132
+ const args = opts.args ?? [];
133
+ const env = opts.env ?? process.env;
134
+ const log = opts.log ?? console.log;
135
+ const configPath = (0, openclaw_config_js_1.resolveOpenClawConfigPath)(env);
136
+ assertConfigWritable(configPath, env);
137
+ // Read before resolving the runtime so an unparseable config stops the
138
+ // install before anything is written.
139
+ const config = (0, install_1.readJsonFile)(configPath);
140
+ // OpenClaw loads the plugin in-process from a directory on
141
+ // `plugins.load.paths`, so the runtime dir *is* the registration — there is
142
+ // no hook subprocess and no hook shim.
143
+ const runtime = (0, install_1.wireRuntime)({
144
+ harness: "openclaw",
145
+ packageName: "@ory/openclaw",
146
+ packageRoot: opts.packageRoot,
147
+ installCommand: "npx -y -p @ory/openclaw ory-openclaw install",
148
+ args,
149
+ entryRelPath: "dist/index.js",
150
+ inProcess: true,
151
+ });
152
+ log(runtime.target.kind === "linked"
153
+ ? `Runtime: linked to ${runtime.target.packageDir} (dev)`
154
+ : `Runtime: ${runtime.target.packageName}@${runtime.target.version} in ${runtime.target.storeDir}`);
155
+ for (const pruned of runtime.prunedStores) {
156
+ log(` Removed stale runtime: ${pruned}`);
157
+ }
158
+ const skillsDir = (0, assets_js_1.installOpenclawOryAssets)((0, assets_js_1.orySkillsDir)());
159
+ let merged = (0, plugin_config_js_1.registerPluginInConfig)(config, runtime.target.packageDir);
160
+ // Without a resolvable MCP server package only the root `mcpServers.ory`
161
+ // key from earlier installer versions is dropped: OpenClaw's strict root
162
+ // schema rejects it.
163
+ merged = runtime.mcpServer
164
+ ? (0, plugin_config_js_1.mergeOpenClawMcpServer)(merged, runtime.mcpServer)
165
+ : (0, install_1.removeMcpServer)(merged);
166
+ merged = (0, plugin_config_js_1.addSkillsExtraDir)(merged, skillsDir);
167
+ if (!fs.existsSync(configPath) || !sameJson(merged, config)) {
168
+ (0, install_1.writeJsonFile)(configPath, merged);
169
+ }
170
+ cleanLegacyProjectInstall(projectDirFrom(args, opts.cwd ?? process.cwd()), configPath, log);
171
+ return {
172
+ configPath,
173
+ pluginDir: path.resolve(runtime.target.packageDir),
174
+ skillsDir,
175
+ mcpRegistered: !!runtime.mcpServer,
176
+ };
177
+ }
178
+ /** Remove only the Ory entries from OpenClaw's config, plus the Ory skills and runtime. */
179
+ function uninstallOpenclaw(opts) {
180
+ const args = opts.args ?? [];
181
+ const env = opts.env ?? process.env;
182
+ const log = opts.log ?? console.log;
183
+ const configPath = (0, openclaw_config_js_1.resolveOpenClawConfigPath)(env);
184
+ assertConfigWritable(configPath, env);
185
+ const skillsDir = (0, assets_js_1.orySkillsDir)();
186
+ let configChanged = false;
187
+ if (fs.existsSync(configPath)) {
188
+ const config = (0, install_1.readJsonFile)(configPath);
189
+ // Resolves the registered load path from the runtime wiring, so this runs
190
+ // before the wiring is removed below.
191
+ let updated = (0, plugin_config_js_1.unregisterPluginFromConfig)(config);
192
+ updated = (0, plugin_config_js_1.removeOpenClawMcpServer)(updated);
193
+ updated = (0, plugin_config_js_1.removeSkillsExtraDir)(updated, skillsDir);
194
+ if (!sameJson(updated, config)) {
195
+ (0, install_1.writeJsonFile)(configPath, updated);
196
+ configChanged = true;
197
+ }
198
+ }
199
+ (0, assets_js_1.uninstallOpenclawOryAssets)(skillsDir);
200
+ cleanLegacyProjectInstall(projectDirFrom(args, opts.cwd ?? process.cwd()), configPath, log);
201
+ removeOpenclawRuntimeWiring();
202
+ for (const pruned of (0, install_1.pruneRuntimeStores)()) {
203
+ log(` Removed runtime: ${pruned}`);
204
+ }
205
+ return { configPath, configChanged };
206
+ }
207
+ /** Read what OpenClaw's config says about the Ory plugin. Never throws. */
208
+ function openclawPluginStatus(env = process.env) {
209
+ const configPath = (0, openclaw_config_js_1.resolveOpenClawConfigPath)(env);
210
+ const configExists = fs.existsSync(configPath);
211
+ let config = {};
212
+ let configError;
213
+ try {
214
+ config = (0, install_1.readJsonFile)(configPath);
215
+ }
216
+ catch (err) {
217
+ configError = err instanceof Error ? err.message : String(err);
218
+ }
219
+ const servers = (config.mcp?.servers ?? {});
220
+ const extraDirs = config.skills?.load?.extraDirs;
221
+ return {
222
+ configPath,
223
+ configExists,
224
+ ...(configError ? { configError } : {}),
225
+ enabled: (0, plugin_config_js_1.isPluginRegistered)(config),
226
+ pluginDir: (0, plugin_config_js_1.registeredPluginDir)(config),
227
+ mcpRegistered: !!servers[plugin_config_js_1.MCP_SERVER_NAME],
228
+ skillsRegistered: Array.isArray(extraDirs) && extraDirs.includes((0, assets_js_1.orySkillsDir)()),
229
+ };
230
+ }
231
+ /** The "Hooks & plugin" section of `ory-openclaw status`. */
232
+ function openclawPluginStatusLines(env = process.env) {
233
+ const status = openclawPluginStatus(env);
234
+ const lines = ["Hooks & plugin:"];
235
+ lines.push(` Config file: ${status.configPath}${status.configExists ? "" : " (not found)"}`);
236
+ if (status.configError)
237
+ lines.push(` Config error: ${status.configError}`);
238
+ lines.push(` Plugin registered: ${status.enabled ? "yes" : "NO"}`);
239
+ if (status.enabled) {
240
+ lines.push(` Plugin id: ${plugin_config_js_1.PLUGIN_ID}`);
241
+ lines.push(` Loads from: ${status.pluginDir ??
242
+ "no plugins.load.paths entry (expected only after `openclaw plugins install`)"}`);
243
+ }
244
+ lines.push(` MCP server: ${status.mcpRegistered ? "yes (mcp.servers.ory)" : "NO"}`);
245
+ lines.push(` Skills: ${status.skillsRegistered ? "yes (skills.load.extraDirs)" : "NO"}`);
246
+ lines.push(" Blocking support: yes (before_tool_call can deny tool execution)");
247
+ lines.push(" Hooks registered: session_start, before_agent_run, before_tool_call, after_tool_call, subagent_spawned, subagent_ended");
248
+ return lines;
249
+ }
@@ -3,9 +3,12 @@
3
3
  * Main CLI for @ory/openclaw.
4
4
  *
5
5
  * Usage:
6
- * npx ory-openclaw install [--project-dir <path>] Register plugin in OpenClaw config
7
- * npx ory-openclaw uninstall Remove plugin from OpenClaw config
8
- * npx ory-openclaw configure Set or view Ory project URL and API key
9
- * npx ory-openclaw status Show plugin status
6
+ * npx ory-openclaw install Register the plugin in OpenClaw's config
7
+ * npx ory-openclaw uninstall Remove the plugin from OpenClaw's config
8
+ * npx ory-openclaw configure Set or view Ory project URL and API key
9
+ * npx ory-openclaw status Show plugin status
10
+ *
11
+ * OpenClaw's config is `OPENCLAW_CONFIG_PATH`, else
12
+ * `$OPENCLAW_STATE_DIR/openclaw.json`, else `~/.openclaw/openclaw.json`.
10
13
  */
11
14
  export {};