@ory/goose 1.9.1 → 1.10.0

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
@@ -9,14 +9,16 @@ One command installs two independent halves:
9
9
  - **Developer experience** — the Ory skill catalog, the local Ory dev stack, and activity logging. No account, no keys, nothing to configure: it works the moment it's installed.
10
10
  - **Ory Agent Security** — browser sign-in, brokered permission checks before tool calls, and the delegation trail. Opt-in connection details from the [Ory Console](https://console.ory.sh) switch it on, and it takes nothing away from the half above. See [Connect to Ory Agent Security](#connect-to-ory-agent-security).
11
11
 
12
- Verified against the `goose` binary (v1.39.0): the plugin layout, the `hooks.json` schema, and the discovery paths all match Goose's shell-hook plugin contract (see [block/goose#9304](https://github.com/block/goose/pull/9304)).
12
+ Verified against Goose v1.59.0: the plugin layout, the `hooks.json` rule schema, the hook payloads and responses, and the discovery paths all match Goose's [lifecycle hooks](https://goose-docs.ai/docs/guides/context-engineering/hooks) contract.
13
13
 
14
14
  ## What you'll need
15
15
 
16
16
  - [Goose](https://github.com/block/goose), installed
17
+ <!-- BEGIN GENERATED requirements -->
17
18
  - Node.js **22 or newer**
18
19
  - [Docker](https://docs.docker.com/get-docker/) — only if you want to run Ory locally
19
20
  - macOS or Linux (Windows works via WSL2)
21
+ <!-- END GENERATED requirements -->
20
22
 
21
23
  ## Get started
22
24
 
@@ -74,7 +76,7 @@ Once you connect to Ory Agent Security, two more things happen automatically:
74
76
  - **Who's driving.** You sign in once in your browser; Goose (and any sub-agents it spawns) each get their own identity. No tokens to copy around, and the "who acted on whose behalf" trail stays queryable later.
75
77
  - **What it's allowed to do.** Before a tool runs, Ory checks whether it's permitted. It starts in **observe mode** — nothing is blocked, you just *see* what would be — so it never gets in your way on day one.
76
78
 
77
- Under the hood, Goose runs the plugin as a small program for each thing it does, handing it the event and reading back a decision. The `hooks.json` file maps that: **SessionStart** signs you in (once connected), **PreToolUse** (the one point that can block) runs the permission check, and the rest — **PostToolUse, BeforeReadFile, AfterFileEdit, BeforeShellExecution, Stop, SessionEnd** — just record activity. If Ory is ever unreachable, the plugin gets out of the way and lets Goose keep working, so it can't lock you out.
79
+ Under the hood, Goose runs the plugin as a small program for each thing it does, handing it the event and reading back a decision. The `hooks.json` file maps that: **SessionStart** signs you in (once connected), **PreToolUse** (the one point that can block) runs the permission check, and the rest — **PostToolUse, PostToolUseFailure, UserPromptSubmit, BeforeReadFile, AfterFileEdit, BeforeShellExecution, AfterShellExecution, Stop** (end of each turn), **SessionEnd** — just record activity. A denied tool call returns Ory's reason to the model. SessionStart is given a 300-second hook timeout so Goose's 30-second default cannot cut off the browser sign-in; the other hooks get 60 seconds. If Ory is ever unreachable, the plugin gets out of the way and lets Goose keep working, so it can't lock you out.
78
80
 
79
81
  ### MCP extensions
80
82
 
@@ -119,6 +121,7 @@ Then a denied tool is actually blocked and Goose shows why.
119
121
 
120
122
  ## Connect to Ory Agent Security
121
123
 
124
+ <!-- BEGIN GENERATED connect -->
122
125
  Copy the connection details from the [Ory Console](https://console.ory.sh) under **Agent Security**:
123
126
 
124
127
  | Value | Flag | Environment variable |
@@ -141,7 +144,10 @@ npx -y -p @ory/goose ory-goose configure \
141
144
 
142
145
  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.
143
146
 
147
+ When sign-in is declined or fails, the interactive `goose` CLI shows a banner before the first prompt (`Ory sign-in did not complete: <reason>. Tool calls may be denied this session.`); the banner is not shown to the model.
148
+
144
149
  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.
150
+ <!-- END GENERATED connect -->
145
151
 
146
152
  ## Commands
147
153
 
@@ -159,14 +165,16 @@ All prefixed with `npx -y -p @ory/goose`.
159
165
 
160
166
  ## Troubleshooting
161
167
 
162
- - **The local Ory fails to start** — make sure Docker is running and ports `4000`, `4100`, `4455`, and `16686` are free.
168
+ - **The local Ory fails to start** — <!-- BEGIN GENERATED local-stack-ports -->make sure Docker is running and ports `4000`, `4100`, and `4455` are free.<!-- END GENERATED local-stack-ports -->
163
169
  - **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.
164
170
  - **Running an older CLI than expected** — `npx -p @ory/goose` (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/goose ory-goose version`. To force the current release, clear the cache and reinstall: `rm -rf ~/.npm/_npx` then `npx -y -p @ory/goose ory-goose install`. Pinning an exact version (`@ory/goose@<version>`) also bypasses the cached copy.
165
171
  - **Goose isn't picking up the plugin** — confirm the tree at `<project>/.agents/plugins/ory/` exists (or re-run the installer), and restart Goose.
166
172
 
167
173
  ## Learn more
168
174
 
175
+ <!-- BEGIN GENERATED ory-links -->
169
176
  - [Ory documentation](https://www.ory.com/docs/) · [Ory Console](https://console.ory.sh) · [Ory Elements](https://github.com/ory/elements)
177
+ <!-- END GENERATED ory-links -->
170
178
  - [Goose repository](https://github.com/block/goose)
171
179
 
172
180
  ## License
@@ -48,7 +48,7 @@ exports.installGooseOryAssets = installGooseOryAssets;
48
48
  exports.uninstallGooseOryAssets = uninstallGooseOryAssets;
49
49
  const fs = __importStar(require("node:fs"));
50
50
  const path = __importStar(require("node:path"));
51
- const argus_1 = require("@ory/argus");
51
+ const install_1 = require("@ory/argus/install");
52
52
  const RENDER_OPTS = {
53
53
  binName: "ory-goose",
54
54
  packageName: "@ory/goose",
@@ -66,25 +66,15 @@ function installGooseOryAssets(pluginRoot) {
66
66
  const dir = skillsDir(pluginRoot);
67
67
  fs.rmSync(dir, { recursive: true, force: true });
68
68
  fs.mkdirSync(dir, { recursive: true });
69
- const guideSkills = (0, argus_1.renderOrySkills)("goose", RENDER_OPTS);
70
- const commandSkills = (0, argus_1.renderOryCommands)("goose", RENDER_OPTS).map(argus_1.commandToSkill);
71
- (0, argus_1.writeSkillTree)(dir, [...guideSkills, ...commandSkills]);
72
- }
73
- function safeRmEmpty(dir) {
74
- try {
75
- if (fs.existsSync(dir) && fs.readdirSync(dir).length === 0) {
76
- fs.rmdirSync(dir);
77
- }
78
- }
79
- catch {
80
- /* ignore — leave the dir if removal fails. */
81
- }
69
+ const guideSkills = (0, install_1.renderOrySkills)("goose", RENDER_OPTS);
70
+ const commandSkills = (0, install_1.renderOryCommands)("goose", RENDER_OPTS).map(install_1.commandToSkill);
71
+ (0, install_1.writeSkillTree)(dir, [...guideSkills, ...commandSkills]);
82
72
  }
83
73
  /** Remove every skill + command-skill this plugin installed under `pluginRoot`. */
84
74
  function uninstallGooseOryAssets(pluginRoot) {
85
75
  const dir = skillsDir(pluginRoot);
86
76
  if (fs.existsSync(dir)) {
87
- (0, argus_1.removeSkillDirs)(dir, [...argus_1.ORY_SKILL_NAMES, ...argus_1.ORY_COMMAND_SKILL_NAMES]);
88
- safeRmEmpty(dir);
77
+ (0, install_1.removeSkillDirs)(dir, [...install_1.ORY_SKILL_NAMES, ...install_1.ORY_COMMAND_SKILL_NAMES]);
78
+ (0, install_1.removeDirIfEmpty)(dir);
89
79
  }
90
80
  }
package/dist/cli/main.js CHANGED
@@ -51,93 +51,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
51
51
  const os = __importStar(require("node:os"));
52
52
  const path = __importStar(require("node:path"));
53
53
  const fs = __importStar(require("node:fs"));
54
- const argus_1 = require("@ory/argus");
54
+ const cli_1 = require("@ory/argus/cli");
55
+ const install_1 = require("@ory/argus/install");
55
56
  const setup_js_1 = require("./setup.js");
56
57
  const PLUGIN_NAME = "ory";
57
58
  const PACKAGE_ROOT = path.resolve(__dirname, "..", "..");
58
- function main() {
59
- const [command, ...args] = process.argv.slice(2);
60
- // `--help` after a matched subcommand: print usage, do nothing else.
61
- // Without this the switch below ignores the flag and `install --help`
62
- // performs a real install (#221).
63
- if ((0, argus_1.shouldPrintHelp)(command, args))
64
- return help();
65
- switch (command) {
66
- case "install":
67
- (0, argus_1.beginDeferNextSteps)();
68
- install(args);
69
- (0, argus_1.runPostInstall)("ory-goose", "goose", args).then(() => process.exit(0), (err) => {
70
- console.error(err.message ?? err);
71
- process.exit(1);
72
- });
73
- break;
74
- case "uninstall":
75
- uninstall(args);
76
- (0, argus_1.clearCredentialsForUninstall)({
77
- harness: "goose",
78
- purge: args.includes("--purge"),
79
- }).then(() => process.exit(0), (err) => {
80
- console.error(err.message ?? err);
81
- process.exit(1);
82
- });
83
- break;
84
- case "configure":
85
- (0, argus_1.runConfigureCommand)("ory-goose", args);
86
- break;
87
- case "agent":
88
- (0, argus_1.runAgentCommand)("ory-goose", "goose", args).then((code) => process.exit(code), (err) => {
89
- console.error(err.message ?? err);
90
- process.exit(1);
91
- });
92
- break;
93
- case "permissions":
94
- (0, argus_1.runPermissionsCommand)("ory-goose", "goose", args).then((code) => process.exit(code), (err) => {
95
- console.error(err.message ?? err);
96
- process.exit(1);
97
- });
98
- break;
99
- case "setup":
100
- (0, setup_js_1.runSetup)((0, argus_1.parseSetupArgs)({ supportsGlobal: true }));
101
- break;
102
- case "status":
103
- status().then(() => process.exit(0), (err) => {
104
- console.error(err.message ?? err);
105
- process.exit(1);
106
- });
107
- break;
108
- case "watch":
109
- (0, argus_1.runWatchCommand)("ory-goose", "goose", args).then((code) => process.exit(code), (err) => { console.error(err.message ?? err); process.exit(1); });
110
- break;
111
- case "local":
112
- (0, argus_1.runLocalCommand)("ory-goose", args).catch((err) => {
113
- console.error(err.message ?? err);
114
- process.exit(1);
115
- });
116
- break;
117
- case "version":
118
- case "--version":
119
- case "-v":
120
- process.exit((0, argus_1.runVersionCommand)("ory-goose", args, { packageRoot: PACKAGE_ROOT }));
121
- break;
122
- case "help":
123
- case "--help":
124
- case "-h":
125
- case undefined:
126
- help();
127
- break;
128
- default:
129
- console.error(`Unknown command: ${command}`);
130
- help();
131
- process.exit(1);
132
- }
133
- }
134
59
  function install(_args) {
135
60
  console.log("Materializing the Ory plugin tree for Goose...");
136
- (0, setup_js_1.runSetup)((0, argus_1.parseSetupArgs)({ supportsGlobal: true }));
137
- (0, argus_1.printEnvHelp)("ory-goose");
61
+ (0, setup_js_1.runSetup)((0, install_1.parseSetupArgs)({ supportsGlobal: true }));
62
+ (0, cli_1.printEnvHelp)("ory-goose");
138
63
  }
139
64
  function uninstall(_args) {
140
- const setupArgs = (0, argus_1.parseSetupArgs)({ supportsGlobal: true });
65
+ const setupArgs = (0, install_1.parseSetupArgs)({ supportsGlobal: true });
141
66
  (0, setup_js_1.runSetup)({ ...setupArgs, uninstall: true });
142
67
  }
143
68
  function pluginRoots() {
@@ -147,7 +72,7 @@ function pluginRoots() {
147
72
  };
148
73
  }
149
74
  async function status() {
150
- await (0, argus_1.runStatusCommand)("ory-goose", "goose", {
75
+ await (0, cli_1.runStatusCommand)("ory-goose", "goose", {
151
76
  title: "Goose",
152
77
  printPluginSection: () => {
153
78
  const roots = pluginRoots();
@@ -196,4 +121,13 @@ Examples:
196
121
  npx -y -p @ory/goose ory-goose uninstall # Remove the plugin
197
122
  `);
198
123
  }
199
- main();
124
+ (0, cli_1.runHarnessCli)({
125
+ bin: "ory-goose",
126
+ harness: "goose",
127
+ packageRoot: PACKAGE_ROOT,
128
+ help,
129
+ install,
130
+ uninstall,
131
+ setup: () => (0, setup_js_1.runSetup)((0, install_1.parseSetupArgs)({ supportsGlobal: true })),
132
+ status: () => status(),
133
+ });
@@ -13,7 +13,7 @@
13
13
  * discovery is purely directory-based.
14
14
  *
15
15
  * The plugin dir layout (plugin.json + hooks/hooks.json) and discovery paths
16
- * are verified against goose v1.39.0.
16
+ * are verified against goose v1.59.0.
17
17
  *
18
18
  * Usage:
19
19
  * npx ory-goose-setup # Install into <cwd>/.agents/plugins/ory
@@ -22,5 +22,36 @@
22
22
  * npx ory-goose-setup --print # Print plugin.json + hooks.json to stdout
23
23
  * npx ory-goose-setup --uninstall # Remove the ory plugin dir
24
24
  */
25
- import { type SetupArgs } from "@ory/argus";
25
+ import { type SetupArgs } from "@ory/argus/install";
26
+ interface HookCommand {
27
+ type: "command";
28
+ command: string;
29
+ /** Seconds; Goose defaults to 30 when absent. */
30
+ timeout: number;
31
+ }
32
+ /** One `RawHookRule`: an optional matcher regex and the actions it runs. */
33
+ interface HookRule {
34
+ matcher?: string;
35
+ hooks: HookCommand[];
36
+ }
37
+ /**
38
+ * Render hooks/hooks.json. Each event maps to one rule with no matcher (every
39
+ * occurrence fires) whose single command action runs the runtime shim resolved
40
+ * at install time, so no package resolution happens per tool call. PreToolUse
41
+ * is the only event the plugin blocks; Stop is a blocking event in Goose too,
42
+ * but the plugin always answers it with a clean allow.
43
+ *
44
+ * Goose parses each event's array as rules `{ matcher?, hooks: [action] }` and
45
+ * drops a rule with no actions, so a flat `{ type, command }` entry loads
46
+ * nothing. Timeouts are in seconds (`Duration::from_secs`). SessionStart gets
47
+ * the session-start window so Goose's 30s default cannot kill the interactive
48
+ * login mid-flow; the rest get the tool-hook window.
49
+ *
50
+ * Verified against goose v1.59.0 (`load_hooks_file` in
51
+ * `crates/goose/src/hooks/mod.rs`).
52
+ */
53
+ export declare function renderHooks(command: string): {
54
+ hooks: Record<string, HookRule[]>;
55
+ };
26
56
  export declare function runSetup(args: SetupArgs): void;
57
+ export {};
package/dist/cli/setup.js CHANGED
@@ -14,7 +14,7 @@
14
14
  * discovery is purely directory-based.
15
15
  *
16
16
  * The plugin dir layout (plugin.json + hooks/hooks.json) and discovery paths
17
- * are verified against goose v1.39.0.
17
+ * are verified against goose v1.59.0.
18
18
  *
19
19
  * Usage:
20
20
  * npx ory-goose-setup # Install into <cwd>/.agents/plugins/ory
@@ -57,11 +57,14 @@ var __importStar = (this && this.__importStar) || (function () {
57
57
  };
58
58
  })();
59
59
  Object.defineProperty(exports, "__esModule", { value: true });
60
+ exports.renderHooks = renderHooks;
60
61
  exports.runSetup = runSetup;
61
62
  const fs = __importStar(require("node:fs"));
62
63
  const os = __importStar(require("node:os"));
63
64
  const path = __importStar(require("node:path"));
65
+ const cli_1 = require("@ory/argus/cli");
64
66
  const argus_1 = require("@ory/argus");
67
+ const install_1 = require("@ory/argus/install");
65
68
  const assets_js_1 = require("./assets.js");
66
69
  const PACKAGE_NAME = "@ory/goose";
67
70
  const PLUGIN_NAME = "ory";
@@ -79,16 +82,6 @@ function getPluginRoot(args) {
79
82
  * dist/cli to the package root. Used to version-pin the npx invocation in
80
83
  * hooks.json so installs keep running against the version they registered.
81
84
  */
82
- function readPackageVersion() {
83
- try {
84
- const pkgPath = path.resolve(__dirname, "..", "..", "package.json");
85
- const parsed = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
86
- return parsed.version ?? "0.0.0";
87
- }
88
- catch {
89
- return "0.0.0";
90
- }
91
- }
92
85
  /**
93
86
  * Render plugin.json — Goose's plugin manifest. Names and describes the
94
87
  * plugin so `goose` can list it.
@@ -100,30 +93,43 @@ function renderManifest(version) {
100
93
  description: "Ory authentication, authorization, and activity auditing for Goose",
101
94
  };
102
95
  }
96
+ const HOOK_EVENTS = [
97
+ "SessionStart",
98
+ "SessionEnd",
99
+ "Stop",
100
+ "UserPromptSubmit",
101
+ "PreToolUse",
102
+ "PostToolUse",
103
+ "PostToolUseFailure",
104
+ "BeforeReadFile",
105
+ "AfterFileEdit",
106
+ "BeforeShellExecution",
107
+ "AfterShellExecution",
108
+ ];
103
109
  /**
104
- * Render hooks/hooks.json. Each event maps to the runtime shim resolved at
105
- * install time, so no package resolution happens per tool call. PreToolUse is
106
- * the only event that can block; the rest are observability hooks.
110
+ * Render hooks/hooks.json. Each event maps to one rule with no matcher (every
111
+ * occurrence fires) whose single command action runs the runtime shim resolved
112
+ * at install time, so no package resolution happens per tool call. PreToolUse
113
+ * is the only event the plugin blocks; Stop is a blocking event in Goose too,
114
+ * but the plugin always answers it with a clean allow.
115
+ *
116
+ * Goose parses each event's array as rules `{ matcher?, hooks: [action] }` and
117
+ * drops a rule with no actions, so a flat `{ type, command }` entry loads
118
+ * nothing. Timeouts are in seconds (`Duration::from_secs`). SessionStart gets
119
+ * the session-start window so Goose's 30s default cannot kill the interactive
120
+ * login mid-flow; the rest get the tool-hook window.
107
121
  *
108
- * The hooks.json schema (per-event arrays of `{ type, command }`, optional
109
- * regex `matcher`/`pattern`) is verified against goose v1.39.0.
122
+ * Verified against goose v1.59.0 (`load_hooks_file` in
123
+ * `crates/goose/src/hooks/mod.rs`).
110
124
  */
111
125
  function renderHooks(command) {
112
- const entry = [{ type: "command", command }];
126
+ const rule = (timeout) => [
127
+ { hooks: [{ type: "command", command, timeout }] },
128
+ ];
129
+ const sessionStart = (0, argus_1.sessionStartHookTimeout)("goose", "seconds");
130
+ const tool = (0, argus_1.toolHookTimeout)("goose", "seconds");
113
131
  return {
114
- hooks: {
115
- SessionStart: entry,
116
- SessionEnd: entry,
117
- Stop: entry,
118
- UserPromptSubmit: entry,
119
- PreToolUse: entry,
120
- PostToolUse: entry,
121
- PostToolUseFailure: entry,
122
- BeforeReadFile: entry,
123
- AfterFileEdit: entry,
124
- BeforeShellExecution: entry,
125
- AfterShellExecution: entry,
126
- },
132
+ hooks: Object.fromEntries(HOOK_EVENTS.map((event) => [event, rule(event === "SessionStart" ? sessionStart : tool)])),
127
133
  };
128
134
  }
129
135
  function writePluginTree(pluginRoot, version, runtime) {
@@ -131,11 +137,11 @@ function writePluginTree(pluginRoot, version, runtime) {
131
137
  fs.writeFileSync(path.join(pluginRoot, "plugin.json"), JSON.stringify(renderManifest(version), null, 2) + "\n");
132
138
  const hooksDir = path.join(pluginRoot, "hooks");
133
139
  fs.mkdirSync(hooksDir, { recursive: true });
134
- fs.writeFileSync(path.join(hooksDir, "hooks.json"), JSON.stringify(renderHooks((0, argus_1.requireHookCommand)(runtime)), null, 2) + "\n");
140
+ fs.writeFileSync(path.join(hooksDir, "hooks.json"), JSON.stringify(renderHooks((0, install_1.requireHookCommand)(runtime)), null, 2) + "\n");
135
141
  (0, assets_js_1.installGooseOryAssets)(pluginRoot);
136
142
  }
137
143
  function runSetup(args) {
138
- const version = readPackageVersion();
144
+ const version = (0, install_1.readPackageVersion)(PACKAGE_ROOT) ?? "0.0.0";
139
145
  if (args.print) {
140
146
  // Nothing is resolved or written on a --print run, so the hook command is
141
147
  // shown as the shim path it will point at.
@@ -154,13 +160,13 @@ function runSetup(args) {
154
160
  (0, assets_js_1.uninstallGooseOryAssets)(pluginRoot);
155
161
  fs.rmSync(pluginRoot, { recursive: true, force: true });
156
162
  console.log(`Removed Ory plugin from ${pluginRoot}`);
157
- (0, argus_1.removeRuntimeWiring)("goose");
158
- for (const pruned of (0, argus_1.pruneRuntimeStores)()) {
163
+ (0, install_1.removeRuntimeWiring)("goose");
164
+ for (const pruned of (0, install_1.pruneRuntimeStores)()) {
159
165
  console.log(` Removed runtime: ${pruned}`);
160
166
  }
161
167
  return;
162
168
  }
163
- const runtime = (0, argus_1.wireRuntime)({
169
+ const runtime = (0, install_1.wireRuntime)({
164
170
  harness: "goose",
165
171
  packageName: PACKAGE_NAME,
166
172
  packageRoot: PACKAGE_ROOT,
@@ -176,17 +182,17 @@ function runSetup(args) {
176
182
  writePluginTree(pluginRoot, version, runtime);
177
183
  console.log(`Ory plugin installed to ${pluginRoot}`);
178
184
  console.log(` plugin.json + hooks/hooks.json + skills/ written.`);
179
- (0, argus_1.printNextSteps)("Goose", "npx -y -p @ory/goose ory-goose-setup --uninstall", {
185
+ (0, install_1.printNextSteps)("Goose", "npx -y -p @ory/goose ory-goose-setup --uninstall", {
180
186
  binName: "ory-goose",
181
187
  harness: "goose",
182
188
  });
183
189
  }
184
190
  function main() {
185
191
  if (process.argv.includes("--help") || process.argv.includes("-h")) {
186
- (0, argus_1.printSetupHelp)("ory-goose-setup", "Goose");
192
+ (0, install_1.printSetupHelp)("ory-goose-setup", "Goose");
187
193
  process.exit(0);
188
194
  }
189
- const args = (0, argus_1.parseSetupArgs)({ supportsGlobal: true });
195
+ const args = (0, install_1.parseSetupArgs)({ supportsGlobal: true });
190
196
  runSetup(args);
191
197
  }
192
198
  if (require.main === module) {
@@ -194,7 +200,7 @@ if (require.main === module) {
194
200
  // Direct `-setup --uninstall` path: also clear stored Ory credentials.
195
201
  // (The `ory-goose uninstall` command handles this itself.)
196
202
  if (process.argv.includes("--uninstall")) {
197
- (0, argus_1.clearCredentialsForUninstall)({
203
+ (0, cli_1.clearCredentialsForUninstall)({
198
204
  harness: "goose",
199
205
  purge: process.argv.includes("--purge"),
200
206
  }).then(() => process.exit(0), (err) => {
@@ -1,8 +1,14 @@
1
- import { OryAgentClient, ensureAgentIdentity, ensureUserAuthenticated } from "@ory/argus";
1
+ import { ensureAgentIdentity, ensureUserAuthenticated } from "@ory/argus";
2
2
  import type { GooseHookInput, GooseHookOutput } from "./types.js";
3
+ /**
4
+ * The SessionStart banner for a sign-in that did not complete. Goose's
5
+ * interactive CLI shows a banner to the user only; it never reaches the model,
6
+ * and Goose has no model-visible SessionStart context field.
7
+ */
8
+ export declare function signInFailureBanner(reason: string): string;
3
9
  export interface HandleHookEventDeps {
4
10
  userLogin?: typeof ensureUserAuthenticated;
5
11
  agentGate?: typeof ensureAgentIdentity;
6
12
  }
7
13
  /** Route a Goose hook event to the appropriate Ory integration. */
8
- export declare function handleHookEvent(input: GooseHookInput, client: OryAgentClient, deps?: HandleHookEventDeps): Promise<GooseHookOutput>;
14
+ export declare const handleHookEvent: import("@ory/argus").HookDispatcher<GooseHookInput, GooseHookOutput, HandleHookEventDeps>;
package/dist/handlers.js CHANGED
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleHookEvent = handleHookEvent;
3
+ exports.handleHookEvent = void 0;
4
+ exports.signInFailureBanner = signInFailureBanner;
4
5
  const argus_1 = require("@ory/argus");
5
6
  const HARNESS = "goose";
7
+ /** Login outcomes that leave the session without a user identity by failure. */
8
+ const FAILED_SIGN_IN_MODES = new Set(["declined", "error"]);
9
+ /**
10
+ * The SessionStart banner for a sign-in that did not complete. Goose's
11
+ * interactive CLI shows a banner to the user only; it never reaches the model,
12
+ * and Goose has no model-visible SessionStart context field.
13
+ */
14
+ function signInFailureBanner(reason) {
15
+ const trimmed = reason.replace(/[.\s]+$/, "");
16
+ return `Ory sign-in did not complete: ${trimmed}. Tool calls may be denied this session.`;
17
+ }
6
18
  /**
7
19
  * Goose's in-process platform extensions (`PLATFORM_EXTENSIONS` in
8
20
  * `crates/goose/src/agents/platform_extensions/mod.rs`, v1.39.0). Developer,
@@ -38,98 +50,117 @@ function identifyMcpTool(toolName) {
38
50
  return undefined;
39
51
  return parsed;
40
52
  }
41
- /** Route a Goose hook event to the appropriate Ory integration. */
42
- async function handleHookEvent(input, client, deps = {}) {
43
- const event = input.event;
44
- client.logger.debug("hook.received", {
53
+ const recordSessionEnd = async (input, client, _deps, event) => {
54
+ client.logger.info("lifecycle.session_end", {
55
+ sessionId: input.session_id,
45
56
  event,
57
+ });
58
+ client.logger.activity("session.end", "ok", { attributes: { event } });
59
+ return {};
60
+ };
61
+ // Goose puts the file path (file events) in `matcher_context`; `tool_input`
62
+ // holds the triggering tool's arguments.
63
+ const recordFileActivity = async (input, client, _deps, event) => {
64
+ const filePath = input.matcher_context || undefined;
65
+ client.logger.info("lifecycle.observe", {
46
66
  sessionId: input.session_id,
47
- toolName: input.tool_name,
67
+ event,
68
+ filePath,
48
69
  });
49
- return (0, argus_1.withHookContext)(client, { sessionId: input.session_id }, async () => {
50
- switch (event) {
51
- case "SessionStart":
52
- client.logger.info("lifecycle.session_start", {
53
- sessionId: input.session_id,
54
- cwd: input.working_dir,
55
- });
56
- await (0, argus_1.sessionStart)(client, { harness: HARNESS, ...deps });
57
- return {};
58
- case "PreToolUse": {
59
- const toolName = input.tool_name ?? "unknown";
60
- client.logger.info("lifecycle.pre_tool_use", {
61
- sessionId: input.session_id,
62
- toolName,
63
- toolInput: input.tool_input,
64
- });
65
- const result = await (0, argus_1.gate)(client, {
66
- harness: HARNESS,
67
- toolName,
68
- toolArgs: input.tool_input,
69
- subjectFallback: `session:${input.session_id}`,
70
- mcpTool: identifyMcpTool(toolName),
71
- });
72
- return result.blocked
73
- ? { action: "block", message: result.denialMessage }
74
- : {};
75
- }
76
- case "PostToolUse": {
77
- const toolName = input.tool_name ?? "unknown";
78
- client.logger.info("lifecycle.post_tool_use", {
79
- sessionId: input.session_id,
80
- toolName,
81
- error: input.error,
82
- });
83
- (0, argus_1.complete)(client, {
84
- toolName,
85
- input: input.tool_input,
86
- output: input.tool_output,
87
- });
88
- return {};
89
- }
90
- case "PostToolUseFailure": {
91
- const toolName = input.tool_name ?? "unknown";
92
- client.logger.info("lifecycle.post_tool_use", {
93
- sessionId: input.session_id,
94
- toolName,
95
- error: input.error,
96
- });
97
- (0, argus_1.fail)(client, { toolName, input: input.tool_input, error: input.error });
98
- return {};
99
- }
100
- case "SessionEnd":
101
- case "Stop":
102
- client.logger.info("lifecycle.session_end", {
103
- sessionId: input.session_id,
104
- event,
105
- });
106
- client.logger.activity("session.end", "ok", { attributes: { event } });
107
- return {};
108
- case "UserPromptSubmit":
109
- client.logger.info("lifecycle.user_prompt_submit", { sessionId: input.session_id });
110
- client.logger.activity("user.prompt", "ok", { attributes: { event } });
111
- return {};
112
- case "BeforeReadFile":
113
- case "AfterFileEdit":
114
- case "BeforeShellExecution":
115
- case "AfterShellExecution":
116
- client.logger.info("lifecycle.observe", {
117
- sessionId: input.session_id,
118
- event,
119
- filePath: input.file_path,
120
- });
121
- client.logger.activity("notification", "ok", {
122
- attributes: {
123
- event,
124
- ...(input.file_path ? { filePath: input.file_path } : {}),
125
- ...(input.command ? { hasCommand: true } : {}),
126
- },
127
- });
128
- return {};
129
- default:
130
- client.logger.debug("hook.passthrough", { event });
131
- client.logger.activity("hook.passthrough", "skipped", { attributes: { event } });
132
- return {};
133
- }
70
+ client.logger.activity("notification", "ok", {
71
+ attributes: { event, ...(filePath ? { filePath } : {}) },
134
72
  });
135
- }
73
+ return {};
74
+ };
75
+ // Goose puts the shell command (shell events) in `matcher_context`.
76
+ const recordShellActivity = async (input, client, _deps, event) => {
77
+ client.logger.info("lifecycle.observe", { sessionId: input.session_id, event });
78
+ client.logger.activity("notification", "ok", {
79
+ attributes: { event, ...(input.matcher_context ? { hasCommand: true } : {}) },
80
+ });
81
+ return {};
82
+ };
83
+ const routes = {
84
+ SessionStart: async (input, client, deps) => {
85
+ client.logger.info("lifecycle.session_start", {
86
+ sessionId: input.session_id,
87
+ cwd: input.working_dir,
88
+ });
89
+ const result = await (0, argus_1.sessionStart)(client, { harness: HARNESS, ...deps });
90
+ return FAILED_SIGN_IN_MODES.has(result.userMode)
91
+ ? { banner: signInFailureBanner(result.userReason) }
92
+ : {};
93
+ },
94
+ PreToolUse: async (input, client) => {
95
+ const toolName = input.tool_name ?? "unknown";
96
+ client.logger.info("lifecycle.pre_tool_use", {
97
+ sessionId: input.session_id,
98
+ toolName,
99
+ toolInput: input.tool_input,
100
+ });
101
+ const result = await (0, argus_1.gate)(client, {
102
+ harness: HARNESS,
103
+ toolName,
104
+ toolArgs: input.tool_input,
105
+ subjectFallback: `session:${input.session_id}`,
106
+ mcpTool: identifyMcpTool(toolName),
107
+ });
108
+ return result.blocked
109
+ ? { decision: "block", reason: result.denialMessage }
110
+ : {};
111
+ },
112
+ PostToolUse: async (input, client) => {
113
+ const toolName = input.tool_name ?? "unknown";
114
+ // Goose sends no tool output on PostToolUse.
115
+ client.logger.info("lifecycle.post_tool_use", {
116
+ sessionId: input.session_id,
117
+ toolName,
118
+ });
119
+ (0, argus_1.complete)(client, { toolName, input: input.tool_input });
120
+ return {};
121
+ },
122
+ PostToolUseFailure: async (input, client) => {
123
+ const toolName = input.tool_name ?? "unknown";
124
+ // Goose sends no error text on PostToolUseFailure; the event itself is
125
+ // the failure signal (an `is_error` result or a transport error).
126
+ client.logger.info("lifecycle.post_tool_use_failure", {
127
+ sessionId: input.session_id,
128
+ toolName,
129
+ });
130
+ (0, argus_1.fail)(client, { toolName, input: input.tool_input });
131
+ return {};
132
+ },
133
+ SessionEnd: recordSessionEnd,
134
+ // Stop fires at the end of every turn, not the session. It is a blocking
135
+ // event in Goose, so the empty result (a clean allow) is load-bearing.
136
+ Stop: async (input, client) => {
137
+ client.logger.info("lifecycle.stop", { sessionId: input.session_id });
138
+ client.logger.activity("turn.stop", "ok", {
139
+ attributes: { responseLen: input.last_assistant_message?.length },
140
+ });
141
+ return {};
142
+ },
143
+ UserPromptSubmit: async (input, client, _deps, event) => {
144
+ client.logger.info("lifecycle.user_prompt_submit", {
145
+ sessionId: input.session_id,
146
+ promptLen: input.message?.length,
147
+ });
148
+ client.logger.activity("user.prompt", "ok", {
149
+ attributes: { event, promptLen: input.message?.length },
150
+ });
151
+ return {};
152
+ },
153
+ BeforeReadFile: recordFileActivity,
154
+ AfterFileEdit: recordFileActivity,
155
+ BeforeShellExecution: recordShellActivity,
156
+ AfterShellExecution: recordShellActivity,
157
+ };
158
+ /** Route a Goose hook event to the appropriate Ory integration. */
159
+ exports.handleHookEvent = (0, argus_1.createHookDispatcher)({
160
+ harness: HARNESS,
161
+ event: (input) => input.event,
162
+ sessionId: (input) => input.session_id,
163
+ log: (input) => ({ sessionId: input.session_id, toolName: input.tool_name }),
164
+ routes,
165
+ passthrough: () => ({}),
166
+ });
package/dist/hook.d.ts CHANGED
@@ -3,10 +3,11 @@
3
3
  * Goose hook entry point.
4
4
  * This script is invoked by Goose for each hook event.
5
5
  * Input: JSON on stdin
6
- * Output: JSON on stdout (the `RawHookAction` shape — `{ action, message }`).
7
- * A `{"action":"block"}` payload blocks the action (PreToolUse only); we also
8
- * exit with code 2 as a defensive secondary block signal.
6
+ * Output: see `renderHookResponse`. A PreToolUse deny writes
7
+ * `{"decision":"block","reason"}` to stdout, the reason to stderr, and exits 2;
8
+ * a SessionStart banner writes `{"banner"}`; everything else writes nothing and
9
+ * exits 0. Diagnostics go to stderr only.
9
10
  *
10
- * Verified against goose v1.39.0.
11
+ * Verified against goose v1.59.0.
11
12
  */
12
13
  export {};
package/dist/hook.js CHANGED
@@ -4,82 +4,22 @@
4
4
  * Goose hook entry point.
5
5
  * This script is invoked by Goose for each hook event.
6
6
  * Input: JSON on stdin
7
- * Output: JSON on stdout (the `RawHookAction` shape — `{ action, message }`).
8
- * A `{"action":"block"}` payload blocks the action (PreToolUse only); we also
9
- * exit with code 2 as a defensive secondary block signal.
7
+ * Output: see `renderHookResponse`. A PreToolUse deny writes
8
+ * `{"decision":"block","reason"}` to stdout, the reason to stderr, and exits 2;
9
+ * a SessionStart banner writes `{"banner"}`; everything else writes nothing and
10
+ * exits 0. Diagnostics go to stderr only.
10
11
  *
11
- * Verified against goose v1.39.0.
12
+ * Verified against goose v1.59.0.
12
13
  */
13
14
  Object.defineProperty(exports, "__esModule", { value: true });
14
15
  const argus_1 = require("@ory/argus");
15
16
  const handlers_js_1 = require("./handlers.js");
16
- const EVENT_FLUSH_TIMEOUT_MS = 750;
17
- let client;
18
- async function flushEvents() {
19
- try {
20
- await client?.flushEvents(EVENT_FLUSH_TIMEOUT_MS);
21
- }
22
- catch {
23
- // The hook decision must not depend on activity delivery.
24
- }
25
- }
26
- /**
27
- * Read all of stdin as a string.
28
- *
29
- * Uses event listeners instead of `for await` so that we don't depend on the
30
- * parent process closing stdin (sending EOF). If no EOF arrives, we resolve
31
- * after a short idle gap once data has been received.
32
- */
33
- function readStdin() {
34
- return new Promise((resolve, reject) => {
35
- const chunks = [];
36
- let resolved = false;
37
- function done() {
38
- if (!resolved) {
39
- resolved = true;
40
- resolve(Buffer.concat(chunks).toString("utf-8"));
41
- }
42
- }
43
- process.stdin.on("data", (chunk) => {
44
- chunks.push(chunk);
45
- clearTimeout(idleTimer);
46
- idleTimer = setTimeout(done, 100);
47
- });
48
- process.stdin.on("end", done);
49
- process.stdin.on("error", (err) => {
50
- if (!resolved) {
51
- resolved = true;
52
- reject(err);
53
- }
54
- });
55
- let idleTimer;
56
- });
57
- }
58
- async function main() {
59
- client = argus_1.OryAgentClient.fromEnv("goose");
60
- const raw = await readStdin();
61
- let input;
62
- try {
63
- input = JSON.parse(raw);
64
- }
65
- catch {
66
- client.logger.error("hook.stdin.parse_failed", { raw: raw.slice(0, 200) });
67
- process.exit(0); // Don't block on parse errors
68
- }
69
- const output = await (0, handlers_js_1.handleHookEvent)(input, client);
70
- if (output.action === "block") {
71
- // Goose stops execution on the first explicit deny. The structured block
72
- // signal is the `action` key; emit it on stdout and exit 2 as a defensive
73
- // secondary signal — both indicate a hard deny.
74
- process.stdout.write(JSON.stringify(output));
75
- await flushEvents();
76
- process.exit(2);
77
- }
78
- await flushEvents();
79
- process.exit(0);
80
- }
81
- main().catch(async (err) => {
82
- process.stderr.write(`[ory-agent] fatal: ${err}\n`);
83
- await flushEvents();
84
- process.exit(0); // Fail open
17
+ const response_js_1 = require("./response.js");
18
+ void (0, argus_1.runHookProcess)({
19
+ harness: "goose",
20
+ handle: handlers_js_1.handleHookEvent,
21
+ respond: (output) => {
22
+ const { stdout, stderr, exitCode } = (0, response_js_1.renderHookResponse)(output);
23
+ return { ...(stdout ? { stdout } : {}), ...(stderr ? { stderr } : {}), exitCode };
24
+ },
85
25
  });
@@ -0,0 +1,20 @@
1
+ import type { GooseHookOutput } from "./types.js";
2
+ /** What the hook process writes and how it exits for one handler result. */
3
+ export interface GooseHookResponse {
4
+ stdout: string;
5
+ stderr: string;
6
+ exitCode: 0 | 2;
7
+ }
8
+ /**
9
+ * Translate a handler result into Goose's process-level hook protocol.
10
+ *
11
+ * A block is signalled three ways at once: `{"decision":"block","reason"}` on
12
+ * stdout, the same reason on stderr, and exit 2. Goose checks exit 2 first and
13
+ * takes the reason from stderr; otherwise it honors the stdout block whatever
14
+ * the exit status. Carrying the reason on both channels keeps it visible to
15
+ * the model on either path instead of Goose's generic "denied by plugin hook".
16
+ *
17
+ * Everything else exits 0. A banner is written as `{"banner"}`; an empty
18
+ * result writes nothing, which is the only clean allow on a blocking event.
19
+ */
20
+ export declare function renderHookResponse(output: GooseHookOutput): GooseHookResponse;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderHookResponse = renderHookResponse;
4
+ /**
5
+ * Translate a handler result into Goose's process-level hook protocol.
6
+ *
7
+ * A block is signalled three ways at once: `{"decision":"block","reason"}` on
8
+ * stdout, the same reason on stderr, and exit 2. Goose checks exit 2 first and
9
+ * takes the reason from stderr; otherwise it honors the stdout block whatever
10
+ * the exit status. Carrying the reason on both channels keeps it visible to
11
+ * the model on either path instead of Goose's generic "denied by plugin hook".
12
+ *
13
+ * Everything else exits 0. A banner is written as `{"banner"}`; an empty
14
+ * result writes nothing, which is the only clean allow on a blocking event.
15
+ */
16
+ function renderHookResponse(output) {
17
+ if (output.decision === "block") {
18
+ const reason = output.reason ?? "";
19
+ return {
20
+ stdout: JSON.stringify({ decision: "block", reason }),
21
+ stderr: reason ? `${reason}\n` : "",
22
+ exitCode: 2,
23
+ };
24
+ }
25
+ if (output.banner) {
26
+ return { stdout: JSON.stringify({ banner: output.banner }), stderr: "", exitCode: 0 };
27
+ }
28
+ return { stdout: "", stderr: "", exitCode: 0 };
29
+ }
package/dist/types.d.ts CHANGED
@@ -1,47 +1,58 @@
1
1
  /**
2
- * Goose hook event payload delivered on stdin.
2
+ * Goose hook event payload delivered on stdin (Goose's `HookContext`).
3
3
  *
4
4
  * Goose (Block's open-source agent CLI) invokes external shell hooks as
5
- * child processes, passing JSON on stdin and reading JSON from stdout. For
6
- * PreToolUse, a `{"action":"block"}` stdout payload blocks the action; any
7
- * other action allows it (fail-open). Exit code 2 is honored as a defensive
8
- * secondary block signal.
5
+ * child processes, passing JSON on stdin and reading the decision from the
6
+ * exit status and stdout. See {@link GooseHookOutput} for the response side.
9
7
  *
10
8
  * Events: SessionStart, SessionEnd, Stop, UserPromptSubmit, PreToolUse,
11
9
  * PostToolUse, PostToolUseFailure, BeforeReadFile, AfterFileEdit,
12
10
  * BeforeShellExecution, AfterShellExecution.
13
11
  *
14
- * Verified against goose v1.39.0. Hooks landed via PR #9304.
12
+ * Verified against goose v1.59.0 (`crates/goose/src/hooks/mod.rs` and the
13
+ * emit sites under `crates/goose/src/agents/state_machine/`).
15
14
  */
16
15
  export interface GooseHookInput {
17
16
  /** Lifecycle event name, e.g. "SessionStart" / "PreToolUse". */
18
17
  event: string;
19
18
  /** Stable identifier for the Goose session. */
20
19
  session_id: string;
21
- /** Optional matcher context supplied by the binary. Not consumed. */
22
- matcher_context?: Record<string, unknown>;
20
+ /**
21
+ * The string a rule's `matcher` regex is tested against: the tool name on
22
+ * tool events, the shell command on BeforeShellExecution /
23
+ * AfterShellExecution, the file path on BeforeReadFile / AfterFileEdit, and
24
+ * the prompt text on UserPromptSubmit.
25
+ */
26
+ matcher_context?: string | null;
27
+ /** Identifier shared by the pre and post events of one tool call. */
28
+ tool_call_id?: string;
23
29
  /** Working directory of the session. */
24
30
  working_dir?: string;
25
31
  tool_name?: string;
26
32
  tool_input?: Record<string, unknown>;
27
- tool_output?: Record<string, unknown>;
28
- /** Present on PostToolUseFailure. */
29
- error?: string;
30
- prompt?: string;
31
- file_path?: string;
32
- command?: string;
33
+ /** UserPromptSubmit: the submitted prompt text. */
34
+ message?: string;
35
+ /** Stop: the final assistant text for the turn, when there is any. */
36
+ last_assistant_message?: string;
33
37
  }
34
38
  /**
35
- * Goose hook output written to stdout (the `RawHookAction` shape).
39
+ * Goose hook output.
36
40
  *
37
- * Only PreToolUse honors a block action. We emit `{ action: "block",
38
- * message }` and pair it with exit code 2 as a defensive secondary block
39
- * signal in the hook entry point.
41
+ * - **PreToolUse deny**: `{ decision: "block", reason }` on stdout. The hook
42
+ * entry point also writes `reason` to stderr and exits 2. Goose reads exit 2
43
+ * first (reason from stderr) and otherwise honors the stdout block regardless
44
+ * of exit status, so either path carries the reason to the model.
45
+ * - **SessionStart banner**: `{ banner }` on stdout with exit 0. The
46
+ * interactive CLI shows it to the user before the first prompt; it is not
47
+ * visible to the model.
48
+ * - **Allow / observe**: `{}`, written as empty stdout with exit 0. Any other
49
+ * stdout on a blocking event (PreToolUse, Stop) reads as "no decision".
40
50
  *
41
- * Verified against goose v1.39.0: the JSON key is `action` with values
42
- * `allow` / `block` / `warn`, and the human-readable text field is `message`.
51
+ * Verified against goose v1.59.0 (`classify_output` and `extract_banner` in
52
+ * `crates/goose/src/hooks/mod.rs`).
43
53
  */
44
54
  export interface GooseHookOutput {
45
- action?: "allow" | "block" | "warn";
46
- message?: string;
55
+ decision?: "block";
56
+ reason?: string;
57
+ banner?: string;
47
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ory/goose",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Ory plugin for Goose (Block's open-source agent CLI): scaffolding skills, a local Ory instance, and authentication, authorization, and audit for every tool call",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://ory.com",
@@ -69,7 +69,7 @@
69
69
  ],
70
70
  "dependencies": {
71
71
  "reova": "^0.7.0",
72
- "@ory/argus": "1.9.1"
72
+ "@ory/argus": "1.10.0"
73
73
  },
74
74
  "devDependencies": {
75
75
  "typescript": "^7.0.2"