pierre-guard
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePierre Integration Guard
Pierre集成防护
Plannotator's code review UI wraps — an open-source diff renderer that uses Shadow DOM. The integration is concentrated in a single file but relies on undocumented internals (shadow DOM selectors, CSS variable names, grid layout assumptions). This skill helps verify changes don't break that contract.
@pierre/diffsPlannotator的代码审查UI封装了——一个使用Shadow DOM的开源差异渲染器。该集成集中在单个文件中,但依赖于未公开的内部实现(Shadow DOM选择器、CSS变量名、网格布局假设)。此技能有助于验证修改不会破坏该集成约定。
@pierre/diffsSource of Truth
权威来源
- Upstream repo: https://github.com/pierrecomputer/pierre/tree/main/packages/diffs
- Local types: (
node_modules/@pierre/diffs/dist/files).d.ts - Integration point:
packages/review-editor/components/DiffViewer.tsx - Current version: check for the pinned version
packages/review-editor/package.json
Always verify against the upstream repo or local files — don't rely on memory of the API shape.
.d.ts- 上游仓库:https://github.com/pierrecomputer/pierre/tree/main/packages/diffs
- 本地类型定义:(
node_modules/@pierre/diffs/dist/文件).d.ts - 集成入口:
packages/review-editor/components/DiffViewer.tsx - 当前版本:查看中的固定版本
packages/review-editor/package.json
请始终以上游仓库或本地文件为准——不要依赖对API形态的记忆。
.d.tsWhat We Import
我们导入的内容
typescript
import { FileDiff } from '@pierre/diffs/react';
import { getSingularPatch, processFile } from '@pierre/diffs';These are the only three imports. is the only file that touches Pierre.
DiffViewer.tsxtypescript
import { FileDiff } from '@pierre/diffs/react';
import { getSingularPatch, processFile } from '@pierre/diffs';这是仅有的三个导入项。是唯一接触Pierre的文件。
DiffViewer.tsxAPI Surface to Guard
需要防护的API范围
1. Component Props (FileDiff
)
FileDiff1. 组件属性(FileDiff
)
FileDiffRead the current prop types from or the upstream source. The props we use:
node_modules/@pierre/diffs/dist/react/index.d.ts| Prop | Type | Notes |
|---|---|---|
| | From |
| | See options table below |
| | |
| | |
| | Custom inline annotation renderer |
| | The |
从或上游源码读取当前属性类型。我们使用的属性:
node_modules/@pierre/diffs/dist/react/index.d.ts| 属性 | 类型 | 说明 |
|---|---|---|
| | 来自 |
| | 见下方选项表格 |
| | |
| | |
| | 自定义内联注释渲染器 |
| | 悬停时的“+”按钮(上游已废弃——需留意是否被移除) |
2. Options Object
2. 选项对象
| Option | Value We Pass | Risk |
|---|---|---|
| | Low — standard enum |
| CSS string | High — targets internal selectors |
| | Low — standard enum |
| | Low |
| | Low |
| | Low |
| | Medium — deprecated prop |
| callback | Medium — signature could change |
| 选项 | 我们传入的值 | 风险等级 |
|---|---|---|
| | 低——标准枚举 |
| CSS字符串 | 高——针对内部选择器 |
| | 低——标准枚举 |
| | 低 |
| | 低 |
| | 低 |
| | 中——已废弃属性 |
| 回调函数 | 中——签名可能变更 |
3. Shadow DOM Selectors (via unsafeCSS
)
unsafeCSS3. Shadow DOM选择器(通过unsafeCSS
)
unsafeCSSThese are the selectors we inject CSS rules against. They target attributes inside Pierre's shadow DOM. If Pierre renames or removes any of these, our styling breaks silently.
data-*Currently used:
- — shadow root
:host - — root diff container
[data-diff] - — file wrapper
[data-file] - — header bar
[data-diffs-header] - — error display
[data-error-wrapper] - — virtual scroll buffer
[data-virtualizer-buffer] - — file metadata row
[data-file-info] - — line number gutter
[data-column-number] - — title (we hide it)
[data-diffs-header] [data-title] - — split layout mode
[data-diff-type='split'] - /
[data-overflow='scroll']— overflow mode[data-overflow='wrap']
这些是我们注入CSS规则所针对的选择器,它们指向Pierre Shadow DOM内的属性。如果Pierre重命名或移除其中任何一个,我们的样式会静默失效。
data-*当前使用的选择器:
- —— Shadow根节点
:host - —— 根差异容器
[data-diff] - —— 文件包装器
[data-file] - —— 标题栏
[data-diffs-header] - —— 错误显示区域
[data-error-wrapper] - —— 虚拟滚动缓冲区
[data-virtualizer-buffer] - —— 文件元数据行
[data-file-info] - —— 行号 gutter
[data-column-number] - —— 标题(我们会隐藏它)
[data-diffs-header] [data-title] - —— 拆分布局模式
[data-diff-type='split'] - /
[data-overflow='scroll']—— 溢出模式[data-overflow='wrap']
4. CSS Variables We Override
4. 我们覆盖的CSS变量
We override these variables to theme Pierre:
--diffs-*- ,
--diffs-bg— base colors--diffs-fg - ,
--diffs-dark-bg— theme-specific backgrounds--diffs-light-bg - ,
--diffs-dark— theme-specific foregrounds--diffs-light
我们覆盖这些变量来为Pierre设置主题:
--diffs-*- ,
--diffs-bg—— 基础颜色--diffs-fg - ,
--diffs-dark-bg—— 主题特定背景色--diffs-light-bg - ,
--diffs-dark—— 主题特定前景色--diffs-light
5. CSS Variables We Inject (Custom)
5. 我们注入的自定义CSS变量
We set these on a wrapper div outside the shadow DOM, relying on CSS custom property inheritance:
- ,
--split-left— control the split pane grid ratio--split-right
The grid override references these: . The fallback ensures the layout is safe if the variables aren't set.
unsafeCSSgrid-template-columns: var(--split-left, 1fr) var(--split-right, 1fr)1fr我们在Shadow DOM外的包装div上设置这些变量,依赖CSS自定义属性的继承性:
- ,
--split-left—— 控制拆分面板的网格比例--split-right
unsafeCSSgrid-template-columns: var(--split-left, 1fr) var(--split-right, 1fr)1fr6. Grid Layout Assumption
6. 网格布局假设
Pierre's split view uses CSS Grid with . We override this for the resizable split pane. If Pierre changes its layout engine (e.g., to flexbox or a different grid structure), the override will stop working.
grid-template-columns: 1fr 1frHow to verify: In the upstream source, search for in the diff component styles.
grid-template-columnsPierre的拆分视图使用CSS Grid,设置为。我们会覆盖此设置以实现可调整大小的拆分面板。如果Pierre更改其布局引擎(例如改为flexbox或不同的网格结构),该覆盖将失效。
grid-template-columns: 1fr 1fr验证方式: 在上游源码中,搜索差异组件样式中的。
grid-template-columnsVerification Checklist
验证检查清单
When reviewing changes that touch the Pierre integration, check:
在审查涉及Pierre集成的修改时,请检查:
Props & Types
属性与类型
- Read the current files to confirm prop names and types haven't changed
.d.ts - Check if is still supported (it's deprecated — may be removed)
renderHoverUtility - Verify still uses
DiffLineAnnotation(notside: 'deletions' | 'additions')'old' | 'new' - Confirm shape:
SelectedLineRange{ start, end, side? }
- 读取当前文件,确认属性名称和类型未变更
.d.ts - 检查是否仍受支持(已废弃——可能被移除)
renderHoverUtility - 验证仍使用
DiffLineAnnotation(而非side: 'deletions' | 'additions')'old' | 'new' - 确认的结构:
SelectedLineRange{ start, end, side? }
Shadow DOM Selectors
Shadow DOM选择器
- Grep the upstream source for each attribute we target in
data-*unsafeCSS - If upgrading the package version, diff the old and new CSS/HTML output for renamed attributes
- Test both and
splitviews — selectors are layout-dependentunified
- 在源码中搜索我们在中针对的每个
unsafeCSS属性data-* - 如果升级包版本,对比新旧版本的CSS/HTML输出,检查是否有重命名的属性
- 测试拆分和统一两种视图——选择器依赖布局
CSS Variables
CSS变量
- Grep upstream for ,
--diffs-bg, and other variables we override--diffs-fg - Verify the variable names haven't been renamed or removed
- Check that is still needed (Pierre may change specificity)
!important
- 在源码中搜索、
--diffs-bg以及我们覆盖的其他变量--diffs-fg - 验证变量名称未被重命名或移除
- 检查是否仍需要(Pierre可能更改了优先级)
!important
Theme Compliance
主题合规性
- New UI elements must use theme tokens (,
bg-border, etc.), not hardcoded colors likebg-primarybg-blue-500 - The existing component in
ResizeHandlesets the visual convention — match itpackages/ui/components/ResizeHandle.tsx
- 新UI元素必须使用主题令牌(、
bg-border等),而非硬编码颜色如bg-primarybg-blue-500 - 现有组件位于
ResizeHandle,定义了视觉规范——需与之匹配packages/ui/components/ResizeHandle.tsx
Build & Runtime
构建与运行时
- Run and verify the diff renders in both split and unified modes
bun run dev:review - Check the browser console for Pierre warnings (e.g., )
parseLineType: Invalid firstChar - Test with add-only and delete-only files (Pierre doesn't render split grid for these)
- If changing UI code, remember build order:
bun run --cwd apps/review build && bun run build:hook
- 运行,验证差异在拆分和统一模式下均能正常渲染
bun run dev:review - 检查浏览器控制台是否有Pierre警告(例如)
parseLineType: Invalid firstChar - 测试仅添加和仅删除的文件(Pierre不会为这些文件渲染拆分网格)
- 如果修改UI代码,请记住构建顺序:
bun run --cwd apps/review build && bun run build:hook
When Upgrading @pierre/diffs
升级@pierre/diffs时的步骤
- Check the upstream changelog / commit history at https://github.com/pierrecomputer/pierre
- Diff the files between old and new versions:
.d.tsbash# Before upgrading, snapshot current types cp -r node_modules/@pierre/diffs/dist /tmp/pierre-old # After upgrading diff -r /tmp/pierre-old node_modules/@pierre/diffs/dist - Search for renamed/removed data attributes in the new version
- Run through the full verification checklist above
- Test the resizable split pane — it depends on grid layout internals
- 查看上游变更日志/提交历史:https://github.com/pierrecomputer/pierre
- 对比新旧版本的文件:
.d.tsbash# 升级前,快照当前类型定义 cp -r node_modules/@pierre/diffs/dist /tmp/pierre-old # 升级后 diff -r /tmp/pierre-old node_modules/@pierre/diffs/dist - 在新版本中搜索是否有重命名/移除的data属性
- 完成上述完整的验证检查清单
- 测试可调整大小的拆分面板——它依赖网格布局的内部实现