#5039·hindsight

pi adapter resolves the repo from `process.cwd()`, so the extension silently disables itself under pi-web-ui

Author: thanlifeCreated Oct 1, 2026Updated Oct 1, 2026

Description

The pi integration resolves the project directory from process.cwd() when the extension factory runs, instead of the session's working directory. In pi's web UI (pi-web-ui) a single long-lived node process serves every session, so process.cwd() is the server's launch directory rather than the workspace the user opened. With optInOnly: true that directory is not opted in, the runtime is disabled, and nothing is registered — no tools, no hooks, no log line.

Steps To Reproduce

  1. Configure the integration against a reachable Hindsight server (apiUrl + apiToken) with optInOnly: true and optInPaths: ["<REPO-ROOT>"], where <REPO-ROOT> is a git repo.
  2. Start the web UI from a directory that is not the repo: pi-web-ui --port <PORT> --cwd <WORKSPACE-ROOT>.
  3. In the web UI, open a session whose workspace is <REPO-ROOT> and send any prompt.
  4. Inspect %USERPROFILE%\.hindsight\coding-agents-logs\: plugin.log shows the config being parsed (e.g. pages[...] warnings), but there is **no** session_start / inject_* / retain_* line, and diag.jsonl receives no events for the bank.
  5. Same repo, same config, but launched as a CLI from inside the repo (cd <REPO-ROOT> && pi): everything works normally.

Current Behavior

  • The extension loads and parses config, then registers no tools and no hooks — the agent never receives the hindsight_* tools.
  • There is no error, no warning, and no diag event; the only trace is the absence of activity.

Confirmed by importing the published factory directly (dist/pi.js default export is the extension factory) and invoking it with different process.cwd() values:

process.cwd() at factory time registered
the opted-in repo 8 hindsight_* tools + before_agent_start + agent_end
any other directory (nothing — inert)

Expected Behavior

  • The project directory should come from the session — pi already exposes it as ExtensionContext.cwd — so a web-UI session in an opted-in repo behaves exactly like the CLI.
  • At minimum, a disabled runtime should be visible: one WARN / diag line stating that the directory was not opted in, so "no memory" is diagnosable instead of silent.

Impact

  • Affects any pi-web-ui user: memory never activates, and nothing indicates why. The failure reads as "Hindsight does not work" rather than "this host resolves a different directory".
  • Silent by construction (no tools, no log, no diag event), so it costs a full debugging session to attribute — in my case it required reading the bundled adapter and probing the factory.
  • pi CLI users (cd repo && pi) are unaffected, which makes the bug look environment-specific.

Initial Diagnosis

Needs verification against the source — I only have the published bundle dist/pi.js (repository.directory is hindsight-integrations/coding-agents, so presumably src/pi.ts):

javascript
function createPiExtension(harness) {
  return (pi) => {
    const repoPath = process.cwd();          // <-- process cwd, not the session cwd
    const core = createRuntime(harness, repoPath);
    if (!core) return;                       // <-- disabled => nothing registered at all
    ...
  };
}

function applyBankConfig(cfg, resolvedId, directory) {
  if (directory !== void 0 && !isOptedIn(cfg, directory))
    return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };   // <-- silent disable
}

pi's public API does expose the session directory: ExtensionContext.cwd in @earendil-works/pi-coding-agent (dist/core/extensions/types.d.ts). The factory itself receives only ExtensionAPI (type ExtensionFactory = (pi: ExtensionAPI) => void | Promise<void>), so the bank/opt-in decision likely has to move from factory time to the first event that carries ctx.

Suggested Fix

  • Recommendation: resolve the directory per session from ctx.cwd instead of process.cwd().
    • Reason: in a single-process, multi-session host the process cwd is not the workspace; every hook this adapter already registers receives ctx.
    • Options: (a) defer runtime creation to session_start and register tools from there; (b) keep factory-time registration but re-resolve the bank on before_agent_start when ctx.cwd differs from the captured directory; (c) at minimum log the captured directory and the opt-in decision so the inert state is observable.
  • Emitting a diag event such as runtime_disabled (with the reason) would help every harness.

Acceptance Criteria

  • With pi-web-ui (single process, --cwd ≠ workspace), a session opened in an opted-in repo registers the hindsight_* tools and injects/retains exactly like the CLI does.
  • When a directory is not opted in, at least one WARN / diag line states that the runtime is disabled and why.
  • Existing CLI behavior (cd <REPO-ROOT> && pi) is unchanged.
  • Two sessions in different repos inside the same web-ui process resolve to two different banks.

Environment

  • @vectorize-io/hindsight-coding-agents 0.8.0
  • pi @earendil-works/pi-coding-agent 0.99.2 (CLI + pi-web-ui), Node 24.21.0, Windows
  • Hindsight server 0.10.2, self-hosted; integration config: optInOnly: true, optInPaths: ["<REPO-ROOT>"], autoUpdate: false