Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions desktop/e2e/remote-workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ test("remote pane CLI reaches its own Workspace over SSH and leaves the local Wo
for (const runtime of ["claude-code", "codex"] as const) {
const localContext = await hookFromPane(local, run.env.HIDE_STATE_DIR!, null, runtime, `local-${runtime}-hook`);
expect(localContext.status).toBe(0);
expect(localContext.context).toContain("Hide Workspace control is available for this connected pane");
expect(localContext.context).toContain("Hide Workspace control is available for this session's checkout");
expect(localContext.context).toContain("file open <path>");
expect(localContext.context).toContain("browser open <url-or-path>");
const remoteBeforeConnection = await hookFromPane(remote, path.join(run.root, "remote-cli-state"), bridge, runtime, `disconnected-${runtime}-hook`);
Expand All @@ -140,6 +140,19 @@ test("remote pane CLI reaches its own Workspace over SSH and leaves the local Wo
});
expect(plain.status).toBe(0);
expect(plain.stdout).not.toContain("Hide Workspace control is available");
// Outside any pane but inside a registered checkout (a Codex shared daemon,
// a plain terminal): the daemon binds the caller by its cwd and the hook
// names that checkout.
const noPaneEnv: NodeJS.ProcessEnv = { ...local.env, HIDE_STATE_DIR: run.env.HIDE_STATE_DIR! };
delete noPaneEnv.HERDR_PANE_ID;
const plainInCheckout = spawnSync(HOOK_CLI, ["hook", "--runtime", "codex", "--event", "SessionStart", "--memory-injection", "--source", "hide-subagents@5"], {
cwd: path.join(local.root, "fixture"),
env: noPaneEnv,
input: "{}", encoding: "utf8", timeout: 10_000,
});
expect(plainInCheckout.status).toBe(0);
expect(plainInCheckout.stdout).toContain("Hide Workspace control is available for this session's checkout");
expect(plainInCheckout.stdout).toContain(fs.realpathSync(path.join(local.root, "fixture")));
const state = JSON.parse(fs.readFileSync(path.join(run.env.HIDE_STATE_DIR!, "hided.json"), "utf8")) as { port: number; token: string };
await page.evaluate(async ({ port, token, socket }) => {
await new Promise<void>((resolve, reject) => {
Expand All @@ -166,7 +179,7 @@ test("remote pane CLI reaches its own Workspace over SSH and leaves the local Wo
for (const runtime of ["claude-code", "codex"] as const) {
const session = await hookFromPane(remote, path.join(run.root, "remote-cli-state"), bridge, runtime, `remote-${runtime}-hook`);
expect(session.status).toBe(0);
expect(session.context).toContain("Hide Workspace control is available for this connected pane");
expect(session.context).toContain("Hide Workspace control is available for this session's checkout");
expect(session.context).toContain("browser open <url-or-path>");
const reference = session.context.match(/HIDE_CAP_REF='([^']+)'/)?.[1];
expect(reference).toBeTruthy();
Expand Down
8 changes: 5 additions & 3 deletions docs/agent-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ Nothing parses the rest of the command, and the helper does not pass the marker
## What the hook returns and reports back

On `SessionStart`, the helper writes one runtime JSON envelope whose `hookSpecificOutput.additionalContext` combines the existing one-line worktree-purpose instruction with the bounded Project Memory capsule when Memory is enabled.
The same envelope adds Workspace commands only after `hide workspace bootstrap` and `hide workspace info` confirm a live, renderer-connected pane and report its actual capabilities.
The same envelope adds Workspace commands only after `hide workspace bootstrap` and `hide workspace info` confirm a renderer-connected Workspace for the caller and report its actual capabilities.
The probe does not need a pane id: the daemon binds a caller inside a Herdr pane to that pane, and any other local caller, such as a tool shell or hook inside Codex's shared app-server daemon or a plain terminal, to the registered checkout holding its cwd (`docs/ARCHITECTURE.md`, the Workspace CLI).
The guidance names that checkout path, so a session can read which Workspace its commands reach.
The helper uses the `hide` CLI beside its own bundled executable, or the CLI on `PATH` for an independently installed helper on an SSH device.
The app bundle carries that CLI beside the helper; the hook does not start Hide or install a remote hook.
An ordinary Claude Code or Codex session started in a connected Herdr pane receives the same conditional guidance as a Hide-managed session when Hide's hook is installed in that runtime's configuration on that machine.
A disconnected pane, unavailable renderer, or unsupported Browser surface receives no Workspace capability claim.
The guidance scopes every command to the calling pane's Workspace and lists only capabilities returned by the daemon; `hide workspace info` remains the live check and `hide --help` gives the full syntax.
A disconnected pane, a cwd outside every registered checkout, an unavailable renderer, or an unsupported Browser surface receives no Workspace capability claim.
The guidance scopes every command to the caller's checkout Workspace and lists only capabilities returned by the daemon; `hide workspace info` remains the live check and `hide --help` gives the full syntax.
The hook creates an owner-only, finite-lived credential reference and includes its path as a shell environment prefix for the listed commands.
The path is a credential reference and should be handled as private session context, even though it contains no bearer bytes itself.
The credential's bearer bytes and file contents never enter hook stdout, arguments, or the agent context, and each command rechecks the caller's checkout membership and renderer availability.
Expand Down
4 changes: 3 additions & 1 deletion hide-agent-hooks/src/bin/hide-agent-hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ fn run_hook(arguments: &[String]) {
} else {
runtime.and_then(|runtime| hook_stdout(runtime, event))
};
// The probe is not gated on a pane id: hided binds a caller outside any
// pane (a Codex shared daemon, a plain terminal) to the registered
// checkout holding its cwd, and refuses everything else itself.
if event == HookEvent::SessionStart
&& std::env::var("HERDR_PANE_ID").is_ok_and(|pane| !pane.is_empty())
&& let Some(context) = workspace_context::live_context()
{
output = output.map(|value| {
Expand Down
58 changes: 55 additions & 3 deletions hide-agent-hooks/src/workspace_context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! A SessionStart capability probe through the same pane-scoped CLI the agent
//! will use. The hook never reads bearer bytes or trusts a pane ID on its own.
//! A SessionStart capability probe through the same scoped CLI the agent will
//! use. The hook never reads bearer bytes or trusts a pane ID on its own, and
//! it needs no pane id at all: the daemon binds a caller in a pane to that
//! pane and any other local caller to the registered checkout holding its cwd,
//! so the guidance names the checkout the daemon answered with.

use std::ffi::OsString;
use std::io::Read;
Expand Down Expand Up @@ -88,6 +91,7 @@ fn format_context(program: &OsString, reference: &Path, answer: &Value) -> Optio
let identity = result.get("context")?;
identity.get("device_id")?.as_str()?;
identity.get("workspace_id")?.as_str()?;
let checkout_path = identity.get("checkout_path")?.as_str()?;
let capabilities = result.get("capabilities")?.as_array()?;
let has = |name: &str| capabilities.iter().any(|item| item.as_str() == Some(name));
if !has("workspace.info") {
Expand Down Expand Up @@ -127,7 +131,7 @@ fn format_context(program: &OsString, reference: &Path, answer: &Value) -> Optio
shell_quote(&program.to_string_lossy()),
);
Some(format!(
"Hide Workspace control is available for this connected pane. Commands affect only this pane's Workspace; there is no Workspace override. Prefix each command with `{command_prefix}`. Available commands: {}. Run `{} workspace info` to refresh capabilities and `{} --help` for syntax. Omit `--reveal` to leave the current screen and keyboard focus unchanged. A failed command returns a reason and next action; recheck before retrying a timed-out action.",
"Hide Workspace control is available for this session's checkout `{checkout_path}`. Commands affect only that checkout's Workspace; there is no Workspace override. Prefix each command with `{command_prefix}`. Available commands: {}. Run `{} workspace info` to refresh capabilities and `{} --help` for syntax. Omit `--reveal` to leave the current screen and keyboard focus unchanged. A failed command returns a reason and next action; recheck before retrying a timed-out action.",
commands.join(", "),
command_prefix,
shell_quote(&program.to_string_lossy()),
Expand All @@ -137,3 +141,51 @@ fn format_context(program: &OsString, reference: &Path, answer: &Value) -> Optio
fn shell_quote(value: &str) -> String {
format!("'{}'", value.replace('\'', "'\\''"))
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;

#[test]
fn guidance_names_the_checkout_the_daemon_bound_the_caller_to() {
let answer = json!({
"ok": true,
"result": {
"context": {
"device_id": "local",
"workspace_id": "workspace:1",
"checkout_id": "workspace:1:checkout:2",
"checkout_path": "/srv/project"
},
"capabilities": ["workspace.info", "browser.open", "view.close"]
}
});
let context = format_context(
&OsString::from("/opt/hide/hide"),
Path::new("/srv/state/pane-capabilities/ref.json"),
&answer,
)
.unwrap();
assert!(context.starts_with(
"Hide Workspace control is available for this session's checkout `/srv/project`."
));
assert!(
context
.contains("HIDE_CAP_REF='/srv/state/pane-capabilities/ref.json' '/opt/hide/hide'")
);
assert!(
context
.contains("browser open <url-or-path> [--reveal] [--wait], view close <view-id>")
);
assert!(!context.contains("file open"));
}

#[test]
fn an_answer_without_a_checkout_or_workspace_info_yields_no_guidance() {
let no_checkout = json!({"ok": true, "result": {"context": {"device_id": "local", "workspace_id": "w"}, "capabilities": ["workspace.info"]}});
assert!(format_context(&OsString::from("hide"), Path::new("/r"), &no_checkout).is_none());
let no_info = json!({"ok": true, "result": {"context": {"device_id": "local", "workspace_id": "w", "checkout_path": "/srv/p"}, "capabilities": ["view.list"]}});
assert!(format_context(&OsString::from("hide"), Path::new("/r"), &no_info).is_none());
}
}
Loading