nexus/server/src
Nexus Dev 91530b07a4 fix(nexus): expand tilde and mkdir workspace cwd on agent save
Zero-terminal bug fix. When a user set an agent's working directory
to "~/nexus-test-01" through the UI, the path was stored verbatim in
agents.adapter_config.cwd and the downstream local adapters (claude_
local, codex_local, gemini_local, cursor, opencode_local, hermes_
local, etc.) failed to resolve the tilde — shells expand ~, child
processes don't. The user was then expected to ssh in and create the
directory by hand, which contradicts Nexus's zero-terminal charter.

Add two helpers in server/src/routes/agents.ts:

  expandUserPath(candidate)
    Trim, expand leading "~" or "~/" to os.homedir(), then
    path.resolve() to absolute form. Null-safe on non-string input.

  normalizeAdapterConfigPaths(adapterConfig)  [async]
    If adapterConfig.cwd is a non-empty string, expand it, assert
    absolute, mkdir -p (recursive), and stat to confirm it's a
    directory. Any failure becomes an unprocessable (422) error with
    the reason surfaced to the UI. Logs an info line when a path is
    actually changed, so the audit trail records that Nexus expanded
    a user-supplied tilde.

Wire into the three existing call sites:

  POST /api/companies/:companyId/agent-hires
  POST /api/companies/:companyId/agents
  PATCH /api/agents/:id

...all of which previously called applyCreateDefaultsByAdapterType
then secretsSvc.normalizeAdapterConfigForPersistence. Added
normalizeAdapterConfigPaths between the secrets step and
assertAdapterConfigConstraints on create + hire, and between secrets
normalization and syncInstructionsBundleConfigFromFilePath on patch.
Each call site now stores a fully resolved absolute path and is
guaranteed the directory exists on disk.

DB state for the two agents that hit this bug today (Project Manager
and Engineer on the Nexus company) was already patched out-of-band
to /home/mikkel/nexus-test-01 by a direct SQL update and mkdir. This
commit prevents recurrence for any future agent-create or agent-patch.

Not addressed here (scope creep):
  - instructionsFilePath / instructionsRootPath also accept
    user-provided paths but are managed by a separate subsystem;
    they may need their own tilde-expansion pass if the UI ever
    exposes them directly.
  - No restriction on where the cwd can be. Nexus runs as the host
    user and trusts the caller. A future policy could limit cwd to
    $HOME or a configured workspace root, but that's a separate
    decision.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 17:56:15 +00:00
..
__tests__ feat: Phase 45 — Content as Skills (9 SKILL.md files, Creative group, gap fixes) 2026-04-05 09:57:20 +00:00
adapters Merge branch 'master' into add-gpt-5-4-xhigh-effort 2026-03-31 06:19:26 -05:00
auth fix: disable secure cookies for HTTP deployments 2026-03-08 22:00:51 -05:00
data feat(30-01): hardware detection, nexus-settings, extended model catalog 2026-04-04 03:55:49 +00:00
middleware fix: align telemetry client payload and dimensions with backend schema 2026-04-02 10:47:29 -05:00
onboarding-assets [nexus] fix: restore upstream delegation and fact-extraction content lost during rebase 2026-04-04 03:55:42 +00:00
realtime update typing to node v24 from v20 2026-03-05 14:36:00 -03:00
routes fix(nexus): expand tilde and mkdir workspace cwd on agent save 2026-04-10 17:56:15 +00:00
secrets refactor: rename packages to @paperclipai and CLI binary to paperclipai 2026-03-03 08:45:26 -06:00
services feat: Phase 45 — Content as Skills (9 SKILL.md files, Creative group, gap fixes) 2026-04-05 09:57:20 +00:00
skills/content feat: Phase 45 — Content as Skills (9 SKILL.md files, Creative group, gap fixes) 2026-04-05 09:57:20 +00:00
storage refactor: rename packages to @paperclipai and CLI binary to paperclipai 2026-03-03 08:45:26 -06:00
types feat: Phase 44 — Video & Presentations (Remotion MP4, SSE progress) 2026-04-05 09:57:11 +00:00
utils feat: Phase 42 — Wallpapers, Social, Format Conversion & Voice (12 platforms, convert pipeline, offline badge) 2026-04-05 09:56:53 +00:00
agent-auth-jwt.ts Implement local agent JWT authentication for adapters 2026-02-18 16:46:45 -06:00
app.ts fix(nexus): auto-bootstrap invite and vite onnxruntime middleware 2026-04-10 16:50:28 +00:00
attachment-types.ts feat: Phase 40 — Job Infrastructure (content jobs, SSE events, namespaced storage) 2026-04-05 09:55:08 +00:00
board-claim.ts refactor: rename packages to @paperclipai and CLI binary to paperclipai 2026-03-03 08:45:26 -06:00
bootstrap-invite.ts fix(nexus): auto-bootstrap invite and vite onnxruntime middleware 2026-04-10 16:50:28 +00:00
config-file.ts refactor: rename packages to @paperclipai and CLI binary to paperclipai 2026-03-03 08:45:26 -06:00
config.ts feat: implement app-side telemetry sender 2026-04-02 10:47:29 -05:00
dev-server-status.ts Add guarded dev restart handling 2026-03-20 08:50:00 -05:00
dev-watch-ignore.ts Harden dev-watch excludes for nested UI outputs 2026-03-26 12:35:19 -05:00
errors.ts Add server routes for companies, approvals, costs, and dashboard 2026-02-17 09:07:27 -06:00
home-paths.ts feat(09-01): install @libsql/client, schema, DB init, path helpers 2026-04-04 03:55:42 +00:00
index.ts fix(nexus): auto-bootstrap invite and vite onnxruntime middleware 2026-04-10 16:50:28 +00:00
log-redaction.ts Add username log censor setting 2026-03-20 08:50:00 -05:00
paths.ts feat(cli): add client commands and home-based local runtime defaults 2026-02-20 07:10:58 -06:00
redaction.ts Implement secrets service with local encryption, redaction, and runtime resolution 2026-02-19 15:43:52 -06:00
startup-banner.ts feat(02-01): replace PAPERCLIP ASCII art with NEXUS in banners 2026-04-04 03:55:41 +00:00
telemetry.ts fix: add periodic flush and graceful shutdown for server-side telemetry 2026-04-02 10:47:29 -05:00
ui-branding.ts Add worktree UI branding 2026-03-13 11:12:43 -05:00
version.ts add app version label 2026-03-17 09:40:07 +05:30
worktree-config.ts Avoid sibling worktree port collisions 2026-03-26 11:12:39 -05:00