Skip to content

Add worktree-specific favicon branding - #540

Merged
cryppadotta merged 1 commit into
masterfrom
nm/worktree-favicon
Mar 10, 2026
Merged

cryppadotta merged 1 commit into
masterfrom
nm/worktree-favicon

Conversation

@cryppadotta

Copy link
Copy Markdown
Contributor

Summary

  • set in
  • swap favicon assets at serve time when running inside a worktree instance
  • add a pink worktree favicon asset set and coverage for the new branding logic

Testing

  • pnpm -r typecheck
  • pnpm test:run
  • pnpm build

@greptile-apps

greptile-apps Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces worktree-specific favicon branding: a new PAPERCLIP_IN_WORKTREE env flag is emitted by the CLI's worktree setup, and the server's new ui-branding module uses it to swap the favicon <link> tags in index.html at serve time (replacing them with a distinct pink asset set), so developers can immediately tell which browser tab is a worktree instance.

Key points:

  • Logic concern: applyUiBranding unconditionally replaces the favicon block, even in non-worktree (production) mode, substituting the original HTML with the hardcoded DEFAULT_FAVICON_LINKS constant. This means any future change to the favicon links inside ui/index.html must be mirrored in that constant or it will be silently overwritten in production. An early return when branding is disabled would eliminate this risk entirely.
  • The marker-based HTML rewrite approach is clean and doesn't require a full HTML parser.
  • The new isWorktreeUiBrandingEnabled helper uses a robust truthy-string check ("1", "true", "yes", "on"), which is a nice touch.
  • Test coverage is good overall; only the absent-variable case for isWorktreeUiBrandingEnabled is missing.

Confidence Score: 3/5

  • Safe to merge with one logic fix — the unconditional favicon-block replacement in non-worktree mode needs to be addressed before this ships to production.
  • The overall approach is sound and the worktree-mode path works correctly. The main concern is that applyUiBranding replaces the favicon block even in non-worktree (production) mode, substituting the original HTML with a hardcoded constant that must be kept manually in sync with ui/index.html. A future favicon update in the HTML that isn't mirrored in DEFAULT_FAVICON_LINKS would silently serve stale icons in production. This is a real, reproducible maintenance hazard that warrants fixing before merge.
  • server/src/ui-branding.ts — the unconditional favicon-block replacement logic needs an early-return guard for non-worktree mode.

Important Files Changed

Filename Overview
server/src/ui-branding.ts New module that swaps favicon <link> tags at serve time when PAPERCLIP_IN_WORKTREE=true. Contains a logic issue: in non-worktree mode the favicon block is still replaced with a hardcoded DEFAULT_FAVICON_LINKS constant instead of being left untouched, creating a silent sync hazard between this constant and ui/index.html.
server/src/app.ts Integrates applyUiBranding into both static-file and Vite-dev serving paths. Changes are minimal and correctly placed; the HTML is branded once per startup in static mode and per-request in dev mode.
server/src/tests/ui-branding.test.ts Good coverage for the three exported functions, but missing an explicit assertion for the absent/undefined PAPERCLIP_IN_WORKTREE env var case.
cli/src/commands/worktree-lib.ts Adds PAPERCLIP_IN_WORKTREE: "true" to the env entries emitted for worktree instances. Simple, correct change.
cli/src/tests/worktree.test.ts Adds assertion that buildWorktreeEnvEntries sets PAPERCLIP_IN_WORKTREE=true. Clean and adequate.
ui/index.html Wraps the existing favicon <link> tags with <!-- PAPERCLIP_FAVICON_START --> / <!-- PAPERCLIP_FAVICON_END --> markers. Change is minimal and correct.
doc/DEVELOPING.md Adds one sentence documenting that PAPERCLIP_IN_WORKTREE=true is set in the repo-local env for worktree instances. Accurate and concise.
ui/public/worktree-favicon.svg New pink SVG favicon for worktree instances, with a dark-mode media query variant. Looks correct.

Last reviewed commit: c799fca

Comment thread server/src/ui-branding.ts
Comment on lines +32 to +41
export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string {
const start = html.indexOf(FAVICON_BLOCK_START);
const end = html.indexOf(FAVICON_BLOCK_END);
if (start === -1 || end === -1 || end < start) return html;

const before = html.slice(0, start + FAVICON_BLOCK_START.length);
const after = html.slice(end);
const links = renderFaviconLinks(isWorktreeUiBrandingEnabled(env));
return `${before}\n${links}\n ${after}`;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_FAVICON_LINKS silently overwrites production favicon HTML

In non-worktree mode, applyUiBranding still replaces the entire favicon block with the hardcoded DEFAULT_FAVICON_LINKS constant instead of leaving the original HTML untouched. This creates a fragile coupling: DEFAULT_FAVICON_LINKS must always remain byte-for-byte in sync with what's between the markers in ui/index.html. If anyone adds, removes, or changes a favicon <link> in ui/index.html without also updating this constant, production will silently serve the stale hardcoded set.

The simplest fix is to bail out early when branding is not needed, preserving the original HTML exactly as built:

Suggested change
export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string {
const start = html.indexOf(FAVICON_BLOCK_START);
const end = html.indexOf(FAVICON_BLOCK_END);
if (start === -1 || end === -1 || end < start) return html;
const before = html.slice(0, start + FAVICON_BLOCK_START.length);
const after = html.slice(end);
const links = renderFaviconLinks(isWorktreeUiBrandingEnabled(env));
return `${before}\n${links}\n ${after}`;
}
export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string {
if (!isWorktreeUiBrandingEnabled(env)) return html;
const start = html.indexOf(FAVICON_BLOCK_START);
const end = html.indexOf(FAVICON_BLOCK_END);
if (start === -1 || end === -1 || end < start) return html;
const before = html.slice(0, start + FAVICON_BLOCK_START.length);
const after = html.slice(end);
const links = renderFaviconLinks(true);
return `${before}\n${links}\n ${after}`;
}

With this change DEFAULT_FAVICON_LINKS (and renderFaviconLinks(false)) become dead code that can be removed, eliminating the sync hazard entirely.

Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/ui-branding.ts
Line: 32-41

Comment:
**`DEFAULT_FAVICON_LINKS` silently overwrites production favicon HTML**

In non-worktree mode, `applyUiBranding` still replaces the entire favicon block with the hardcoded `DEFAULT_FAVICON_LINKS` constant instead of leaving the original HTML untouched. This creates a fragile coupling: `DEFAULT_FAVICON_LINKS` must always remain byte-for-byte in sync with what's between the markers in `ui/index.html`. If anyone adds, removes, or changes a favicon `<link>` in `ui/index.html` without also updating this constant, production will silently serve the stale hardcoded set.

The simplest fix is to bail out early when branding is not needed, preserving the original HTML exactly as built:

```suggestion
export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string {
  if (!isWorktreeUiBrandingEnabled(env)) return html;

  const start = html.indexOf(FAVICON_BLOCK_START);
  const end = html.indexOf(FAVICON_BLOCK_END);
  if (start === -1 || end === -1 || end < start) return html;

  const before = html.slice(0, start + FAVICON_BLOCK_START.length);
  const after = html.slice(end);
  const links = renderFaviconLinks(true);
  return `${before}\n${links}\n    ${after}`;
}
```

With this change `DEFAULT_FAVICON_LINKS` (and `renderFaviconLinks(false)`) become dead code that can be removed, eliminating the sync hazard entirely.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +15 to +19
it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => {
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test case: PAPERCLIP_IN_WORKTREE absent or undefined

The test covers "true", "1", and "false" but doesn't cover the common case where the env var is not set at all (i.e., {}). isTruthyEnvValue handles this with its if (!value) return false guard, but it's worth explicitly asserting to prevent regressions:

Suggested change
it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => {
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false);
});
it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => {
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false);
expect(isWorktreeUiBrandingEnabled({})).toBe(false);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: undefined })).toBe(false);
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/__tests__/ui-branding.test.ts
Line: 15-19

Comment:
**Missing test case: `PAPERCLIP_IN_WORKTREE` absent or `undefined`**

The test covers `"true"`, `"1"`, and `"false"` but doesn't cover the common case where the env var is not set at all (i.e., `{}`). `isTruthyEnvValue` handles this with its `if (!value) return false` guard, but it's worth explicitly asserting to prevent regressions:

```suggestion
  it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => {
    expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true);
    expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true);
    expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false);
    expect(isWorktreeUiBrandingEnabled({})).toBe(false);
    expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: undefined })).toBe(false);
  });
```

How can I resolve this? If you propose a fix, please make it concise.

@cryppadotta
cryppadotta merged commit 7820730 into master Mar 10, 2026
3 checks passed
@cryppadotta
cryppadotta deleted the nm/worktree-favicon branch March 12, 2026 16:23
tr00x pushed a commit to tr00x/paperclip that referenced this pull request Mar 26, 2026
hhhhansel pushed a commit to hhhhansel/paperclip that referenced this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant