dsh-sideby-note 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +331 -0
- package/LICENSE +21 -0
- package/README.en.md +302 -0
- package/README.md +301 -2
- package/client/client.js +4425 -0
- package/cordis.patch.yml +6 -0
- package/docs/assets/features/actions-dark.png +0 -0
- package/docs/assets/features/actions.png +0 -0
- package/docs/assets/features/clear-dark.png +0 -0
- package/docs/assets/features/clear.png +0 -0
- package/docs/assets/features/empty-dark.png +0 -0
- package/docs/assets/features/empty.png +0 -0
- package/docs/assets/features/panel-dark.png +0 -0
- package/docs/assets/features/panel.png +0 -0
- package/docs/assets/features/settings-dark.png +0 -0
- package/docs/assets/features/settings.png +0 -0
- package/docs/assets/preview-badge-dark.png +0 -0
- package/docs/assets/preview-badge.png +0 -0
- package/docs/assets/preview-right-dark.png +0 -0
- package/docs/assets/preview-right.png +0 -0
- package/docs/assets/storefront-icon.svg +22 -0
- package/docs/panel-ui-rules.md +77 -0
- package/host/apply-update.js +204 -0
- package/host/exec.js +68 -0
- package/host/profile.js +99 -0
- package/host/route.js +360 -0
- package/host/versions.js +92 -0
- package/icon.svg +12 -0
- package/index.js +28 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +94 -4
- package/scripts/install.mjs +281 -0
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bundle patch layer: load this package's host entry (a no-op Cordis plugin),
|
|
2
|
+
# while the `dsh.client` declaration in package.json loads the browser bundle
|
|
3
|
+
# (./client/client.js) and registers the session entry plus its panel.
|
|
4
|
+
- insert:
|
|
5
|
+
- id: dsh-sideby-note
|
|
6
|
+
name: 'dsh-sideby-note'
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="540" height="540" viewBox="0 0 180 180">
|
|
2
|
+
<!--
|
|
3
|
+
商店图标母版:插件市场只收位图,所以这里按 540px 渲染(3× 于 180)后缩到
|
|
4
|
+
180×180,输出到仓库根目录的 icon.png。卡片里按 16px 圆形裁切显示,
|
|
5
|
+
改动图形后务必在 16px 下再看一眼。
|
|
6
|
+
图形按宿主插件图标的 36 画布绘制,这里放大 4.4 倍并居中在白底瓦片上;
|
|
7
|
+
比宿主插件列表里的比例略大,是为了 16px 圆形裁切后仍认得出来。
|
|
8
|
+
-->
|
|
9
|
+
<defs>
|
|
10
|
+
<linearGradient id="sideby-note-card" x1="16" y1="12" x2="28" y2="30" gradientUnits="userSpaceOnUse">
|
|
11
|
+
<stop stop-color="#7AC2FF"/>
|
|
12
|
+
<stop offset="1" stop-color="#4A65E8"/>
|
|
13
|
+
</linearGradient>
|
|
14
|
+
</defs>
|
|
15
|
+
<rect x="0.75" y="0.75" width="178.5" height="178.5" rx="40" fill="#FFFFFF" stroke="#E0E0E0" stroke-width="1.5"/>
|
|
16
|
+
<g transform="translate(10.8 8.6) scale(4.4)">
|
|
17
|
+
<path d="M9.5 7H17.5C19.71 7 21.5 8.79 21.5 11V16C21.5 18.21 19.71 20 17.5 20H13.6L9.35 23.85C8.83 24.32 8 23.95 8 23.25V19.72C6.53 19.16 5.5 17.7 5.5 16V11C5.5 8.79 7.29 7 9.5 7Z" fill="#7CB7FF" fill-opacity="0.55"/>
|
|
18
|
+
<path d="M18 12H27C28.93 12 30.5 13.57 30.5 15.5V24.5L25 30H18C16.07 30 14.5 28.43 14.5 26.5V15.5C14.5 13.57 16.07 12 18 12Z" fill="url(#sideby-note-card)"/>
|
|
19
|
+
<path d="M30.5 24.5H26.6C25.72 24.5 25 25.22 25 26.1V30L30.5 24.5Z" fill="#BCD5FD"/>
|
|
20
|
+
<path d="M18.25 17.25H26.75M18.25 21.5H22.75" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round"/>
|
|
21
|
+
</g>
|
|
22
|
+
</svg>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# 边记部(Sideby Note)面板 UI 规则
|
|
2
|
+
|
|
3
|
+
面向后续改动的约束清单。历史复查的过程、逐项对照与截图已移除,只保留规则与待决项;当前界面截图见 [`docs/assets/`](./assets/)。
|
|
4
|
+
|
|
5
|
+
基准:DSH 宿主的 UI / UX 设计规范(令牌、字号、描边、浮层、滚动条与无障碍条款)。
|
|
6
|
+
|
|
7
|
+
## 1. 令牌与尺度
|
|
8
|
+
|
|
9
|
+
| 规则 | 落地 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| 只用 DSH 语义别名,不自建色板 | `--dsw-alias-*`(墨色 / 悬停 / 描边 / 状态 / 设置卡);测试禁止 `#hex`、`rgb()` 与平行灰阶 |
|
|
12
|
+
| 字号只取三档 | 标题 14/500、行与按钮 13/400、说明与计数 12/400;行高统一 20,计数行 16 |
|
|
13
|
+
| 字重上限 500 | 层级靠字号与墨色,不用 600 |
|
|
14
|
+
| 圆角按角色 | 浮窗 `--dsw-radius-panel`(28)、分组与字段 16、紧凑控件 8、胶囊 999 并配 `corner-shape:round` |
|
|
15
|
+
| 中性描边 0.5px | 虚线 1px、spinner 环 1.5px 为例外 |
|
|
16
|
+
| 浮层无边框 | `border:0` + `--dsw-elevation-panel`;0.5px 发丝线画在阴影第一层,不同时叠中性描边 |
|
|
17
|
+
| 滚动条用共享皮肤 | 不写组件私有 `::-webkit-scrollbar` 或 `scrollbar-width/color`;面板内只重绑 `--dsh-scrollbar-*` |
|
|
18
|
+
| hover 只在支持的设备启用 | 全部收进 `@media (hover:hover)`;触摸端行操作常显 |
|
|
19
|
+
| 动效只动 opacity / transform | 100 / 200ms,`--ds-ease-in-out` |
|
|
20
|
+
| 图标画布 36×36 | `icon.svg` 自包含,路径居中缩放 |
|
|
21
|
+
| 文案只来自字典 | `src/client/i18n/` 为唯一来源,中英逐键一致;中文提示不带句号 |
|
|
22
|
+
|
|
23
|
+
## 2. 面板基线尺寸
|
|
24
|
+
|
|
25
|
+
| 项 | 值 |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| 入口按钮 | 28×28,R8,未完成数为胶囊角标 |
|
|
28
|
+
| 面板头 | 标题 14/500 与计数 12/400 同行;设置 / 关闭收进右侧动作组 |
|
|
29
|
+
| 分区标题 | 12/500,`label-secondary` |
|
|
30
|
+
| 行内图标按钮 | 24×24,R8;复制 / 转发 / 退回三枚都是图标按钮,「退回」用产品 `IconRefresh` 水平镜像成逆时针 ↺ |
|
|
31
|
+
| 勾选圈 | 视觉 14×14,命中区 24×24 |
|
|
32
|
+
| 录入区 | 0.5px 描边、R16、padding 12;添加按钮 H28、R8 |
|
|
33
|
+
| 行分隔线 | 0.5px |
|
|
34
|
+
| 列表滚动条 | 9px 轨道、2px 内缩、距面板边缘 16px |
|
|
35
|
+
| 窄视口 | ≤480px 时四边 12px,宽度按视口夹取 |
|
|
36
|
+
|
|
37
|
+
对比度(主题令牌的既有值,作为回归参考):
|
|
38
|
+
|
|
39
|
+
| 文本 | 明 | 暗 |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| 正文 / 标题 `label-primary` | 17.7:1 | 13.6:1 |
|
|
42
|
+
| 说明 / 时间 / 计数 `label-secondary` | 5.4:1 | 9.4:1 |
|
|
43
|
+
| 勾选圈描边 `label-tertiary`(非文本) | 3.5:1 | 6.7:1 |
|
|
44
|
+
|
|
45
|
+
`label-tertiary` 不承担文字:明色下只有 3.5:1,文字统一走 `secondary`。
|
|
46
|
+
|
|
47
|
+
## 3. 交互规则
|
|
48
|
+
|
|
49
|
+
- **入口**:会话顶部 28×28 按钮,未完成数作胶囊徽标;打开时 `data-active`,再次点击、点外部或 Esc 关闭,关闭后焦点回到入口。
|
|
50
|
+
- **新会话入口**:空白新会话没有 conversation utilities 行,入口落在 header corner(右侧栏按钮左侧),只提供工作区清单且不显示「会话」选项;首轮对话后入口回到 utilities,会话清单才可切换。
|
|
51
|
+
- **范围提示**:悬停或键盘聚焦「工作区 / 会话」时,说明工作区清单由所有会话共享、会话清单仅当前会话可见;空白新会话只有工作区,提示当前只能记到工作区。
|
|
52
|
+
- **反馈**:复制、转发、退回、清除完成与写失败都走 `shell.overlay` 的全局 Toast,面板关闭后仍可见;失败时不改动任何数据、草稿或转发标记。
|
|
53
|
+
- **单一编辑区**:只有顶部录入框能编辑便笺正文;行内不再就地编辑。点行尾「退回」把正文移回录入框并移除该行,提交后重新加入;录入框已有内容时退回会被拒绝并提示,避免覆盖未提交草稿。
|
|
54
|
+
- **六个状态**:默认 / 悬停 / 按下 / 键盘聚焦(主题 2px 环)/ 禁用 / 加载(按钮内 12px 环、`aria-busy`)。
|
|
55
|
+
- **浮层安全**:`position:fixed` + portal 到 body;宽高按视口夹取,只在下方确实放不下时才翻到锚点上方;顶边不低于 `--dsh-frame-overlay-top`;外侧 pointerdown 与 Esc 都能关闭。
|
|
56
|
+
- **设置**:点齿轮后在面板内的独立滚动区展开,与列表共用同一套 9px 轨道、2px 内缩;面板不够高时列表先让出高度,设置卡再在自己轨道里滚动,卡片内容不被面板下沿裁切;面板够高时不出现滚动条。
|
|
57
|
+
- **响应式**:390×844 下四边 12px,标题与操作不截断;触摸设备操作按钮常显。
|
|
58
|
+
- **数据**:写失败保持原状;按会话隔离;不读取旧键,也不做自动迁移。
|
|
59
|
+
|
|
60
|
+
## 4. 测试守护
|
|
61
|
+
|
|
62
|
+
`npm test` 运行 51 条契约断言与 1 个 jsdom 集成测试。契约测试守住:
|
|
63
|
+
|
|
64
|
+
- 颜色 / 字号 / 间距 / 圆角 / 描边 / 浮层材质;
|
|
65
|
+
- 滚动条共享皮肤、hover 门控;
|
|
66
|
+
- 字典完整、中英一致、中文提示不带句号;
|
|
67
|
+
- Toast 座位、写失败保留数据、Tooltip 覆盖行内操作、移动端不主动聚焦;
|
|
68
|
+
- 已下线的整页实现不得回流。
|
|
69
|
+
|
|
70
|
+
jsdom 集成测试真实驱动构建产物:打开面板、添加、设置与快捷键、完成、清除二次确认、退回录入框、键盘缩放、清空到空态、分区记忆。
|
|
71
|
+
|
|
72
|
+
## 5. 例外与待决
|
|
73
|
+
|
|
74
|
+
1. **入口按钮使用原生 `title`**:它由插件注入宿主 header 的 DOM(React portal 会被宿主重渲染回收),无法包共享 `Tooltip`;若宿主提供 header utilities 插槽,可统一。
|
|
75
|
+
2. **右侧浮窗不是侧栏 slot**:当前是锚定入口的浮窗;若产品希望常驻右侧栏,应改注册到 `rightbar`,属产品决策。
|
|
76
|
+
3. **链接与错误文本的明色对比度**:`--dsw-alias-link` 3.97:1、`--dsw-alias-state-error-primary` 4.22:1,低于 4.5:1;均为主题令牌,建议在主题层统一提升,插件内不覆盖。
|
|
77
|
+
4. **图标仍需设计师确认**:`icon.svg` 为 36 画布、自包含 SVG。
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-app update, run inside the host.
|
|
3
|
+
*
|
|
4
|
+
* DSH's plugin manager replaces an installed package only after removing it,
|
|
5
|
+
* and a running Desktop refuses to remove a bundle that a live fiber still
|
|
6
|
+
* uses (`bundle-in-use`) — which is exactly the state this plugin is in while
|
|
7
|
+
* its panel is open. So the update never removes anything: it asks DSH to
|
|
8
|
+
* install over the package, and only when that is refused does it fall back to
|
|
9
|
+
* DSH's own `dsh plugin add` and then to the profile's package manager.
|
|
10
|
+
*
|
|
11
|
+
* The three steps are ordered by "how much of DSH's own verification runs", not
|
|
12
|
+
* by convenience: `installBundle` checks DSH peers and restores the profile on
|
|
13
|
+
* failure, `dsh plugin add` does the same under the profile's write lock, and
|
|
14
|
+
* the bare package manager is the last resort that still leaves a consistent
|
|
15
|
+
* profile because it only rewrites the dependency and the lock.
|
|
16
|
+
*
|
|
17
|
+
* Nothing here talks to the browser; the route layer does. Everything the
|
|
18
|
+
* update needs is injected so the ordering and the verification can be tested
|
|
19
|
+
* without a host.
|
|
20
|
+
*/
|
|
21
|
+
import { PACKAGE, installedVersion } from './profile.js'
|
|
22
|
+
import { isExactVersion, isPrerelease } from './versions.js'
|
|
23
|
+
|
|
24
|
+
/** An update failure with a stable code the panel can translate. */
|
|
25
|
+
export class UpdateError extends Error {
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} code
|
|
28
|
+
* @param {string} message
|
|
29
|
+
* @param {{ retryable?: boolean, diagnostic?: string }} [extra]
|
|
30
|
+
*/
|
|
31
|
+
constructor(code, message, extra = {}) {
|
|
32
|
+
super(message)
|
|
33
|
+
this.name = 'UpdateError'
|
|
34
|
+
this.code = code
|
|
35
|
+
this.retryable = extra.retryable === true
|
|
36
|
+
this.diagnostic = extra.diagnostic
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** How long one install step may take before the host stops waiting. */
|
|
41
|
+
export const UPDATE_TIMEOUT_MS = 10 * 60_000
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The command a person can run when no automatic path is available.
|
|
45
|
+
*
|
|
46
|
+
* Prereleases are not covered by the installer's default `^1.0.0` range, and
|
|
47
|
+
* they reach npmjs before the configured mirror; pin the package and registry
|
|
48
|
+
* for the npx fetch so the command cannot quietly install the stable line.
|
|
49
|
+
* @param {string} profileDir
|
|
50
|
+
* @param {string} target
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
export function manualCommand(profileDir, target) {
|
|
54
|
+
const prerelease = isPrerelease(target)
|
|
55
|
+
const registry = prerelease ? ' --registry=https://registry.npmjs.org/' : ''
|
|
56
|
+
const packageSpec = prerelease ? `${PACKAGE}@${target}` : PACKAGE
|
|
57
|
+
return `npx -y${registry} ${packageSpec} install --version ${target} --profile-dir "${profileDir}"`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* First line of a failed step worth showing: DSH's own diagnostic, else the
|
|
62
|
+
* error line the package manager printed, else its last line.
|
|
63
|
+
* @param {string} output
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
function failureLine(output) {
|
|
67
|
+
const lines = String(output ?? '')
|
|
68
|
+
.split(/\r?\n/u)
|
|
69
|
+
.map(line => line.trim())
|
|
70
|
+
.filter(line => line !== '')
|
|
71
|
+
return (
|
|
72
|
+
lines.findLast(line => /ERR_PNPM_[A-Z_]+/u.test(line)) ??
|
|
73
|
+
lines.findLast(line => /^(?:\[?error\]?|\bERROR\b)|\brejected\b/iu.test(line)) ??
|
|
74
|
+
lines.at(-1) ??
|
|
75
|
+
'no output'
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Install `target` over the installed copy and prove it landed.
|
|
81
|
+
*
|
|
82
|
+
* @param {{
|
|
83
|
+
* target: string,
|
|
84
|
+
* profileDir: string,
|
|
85
|
+
* installer?: { installBundle: (spec: string, options?: { enabled?: boolean }) => Promise<any> },
|
|
86
|
+
* pluginCommand?: (args: readonly string[]) => Promise<{ exitCode: number | null, output?: string, timedOut?: boolean, logPath?: string, kind?: string, incompatible?: readonly unknown[] }>,
|
|
87
|
+
* packageManager?: { command: string, args?: readonly string[], env?: Record<string, string> },
|
|
88
|
+
* runner?: (command: string, args: readonly string[], options: { cwd: string, env?: Record<string, string>, timeoutMs?: number }) => Promise<{ exitCode: number | null, stdout?: string, stderr?: string }>,
|
|
89
|
+
* readVersion?: (dir: string) => string | undefined,
|
|
90
|
+
* timeoutMs?: number,
|
|
91
|
+
* }} input
|
|
92
|
+
* @returns {Promise<{ route: 'dsh' | 'dsh-plugin' | 'package-manager' | 'none', previousVersion?: string, installedVersion: string, updated: boolean, restartRequired: boolean, output?: string }>}
|
|
93
|
+
*/
|
|
94
|
+
export async function applyUpdate(input) {
|
|
95
|
+
const { target, profileDir } = input
|
|
96
|
+
if (!isExactVersion(target)) throw new UpdateError('UPDATE_REJECTED', `not a version: ${String(target)}`)
|
|
97
|
+
const readVersion = input.readVersion ?? installedVersion
|
|
98
|
+
const timeoutMs = input.timeoutMs ?? UPDATE_TIMEOUT_MS
|
|
99
|
+
const spec = `${PACKAGE}@${target}`
|
|
100
|
+
|
|
101
|
+
const previousVersion = readVersion(profileDir)
|
|
102
|
+
// Already there: say so instead of reinstalling over a working copy.
|
|
103
|
+
if (previousVersion === target) {
|
|
104
|
+
return { route: 'none', previousVersion, installedVersion: target, updated: false, restartRequired: false }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const verify = (route, output) => {
|
|
108
|
+
const installed = readVersion(profileDir)
|
|
109
|
+
if (installed !== target) {
|
|
110
|
+
throw new UpdateError(
|
|
111
|
+
'RESOLVED_VERSION_MISMATCH',
|
|
112
|
+
`${spec} was not installed: found ${installed ?? 'no package'} after ${route}`,
|
|
113
|
+
{ retryable: true, diagnostic: output },
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
route,
|
|
118
|
+
...(previousVersion === undefined ? {} : { previousVersion }),
|
|
119
|
+
installedVersion: installed,
|
|
120
|
+
updated: true,
|
|
121
|
+
// DSH keeps the loaded build until it restarts, so the caller must say so.
|
|
122
|
+
restartRequired: true,
|
|
123
|
+
...(output === undefined || output === '' ? {} : { output: String(output).slice(-4_000) }),
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 1. DSH's own installer: checks compatibility and restores the profile on failure.
|
|
128
|
+
if (input.installer?.installBundle !== undefined) {
|
|
129
|
+
let change
|
|
130
|
+
try {
|
|
131
|
+
// `enabled: false` leaves the profile's bundle selection alone: this
|
|
132
|
+
// upgrades the package, it does not add or drop a row.
|
|
133
|
+
change = await input.installer.installBundle(spec, { enabled: false })
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new UpdateError('UPDATE_FAILED', `DSH could not install ${spec}: ${messageOf(error)}`)
|
|
136
|
+
}
|
|
137
|
+
const refusal = change?.error?.code
|
|
138
|
+
if (change?.application === 'failed' && refusal !== 'already-installed') {
|
|
139
|
+
throw new UpdateError(
|
|
140
|
+
typeof refusal === 'string' && refusal !== '' ? refusal : 'UPDATE_FAILED',
|
|
141
|
+
`DSH refused ${spec}${typeof change?.error?.diagnostic === 'string' ? `: ${change.error.diagnostic}` : ''}`,
|
|
142
|
+
{ retryable: refusal === 'bundle-in-use' || refusal === 'OPERATION_BUSY' },
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
if (change?.application !== 'failed') return verify('dsh', change?.packageResult?.output)
|
|
146
|
+
// `already-installed` means this DSH replaces a package only after removing
|
|
147
|
+
// it; removing is what a running host refuses, so ask the plugin command.
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 2. DSH's own `dsh plugin add`: replaces in place under the profile's lock.
|
|
151
|
+
if (input.pluginCommand !== undefined) {
|
|
152
|
+
let result
|
|
153
|
+
try {
|
|
154
|
+
result = await input.pluginCommand(['add', spec, '--save-exact'])
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new UpdateError('UPDATE_FAILED', `DSH could not install ${spec}: ${messageOf(error)}`)
|
|
157
|
+
}
|
|
158
|
+
const refused = Array.isArray(result?.incompatible) && result.incompatible.length > 0
|
|
159
|
+
if (refused || result?.exitCode !== 0 || result?.timedOut === true) {
|
|
160
|
+
throw new UpdateError(
|
|
161
|
+
refused ? 'incompatible-version' : 'UPDATE_FAILED',
|
|
162
|
+
`DSH could not install ${spec}: ${failureLine(result?.output ?? '')}`,
|
|
163
|
+
{ retryable: result?.timedOut === true, diagnostic: result?.output },
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
return verify('dsh-plugin', result?.output)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 3. The profile's own package manager, which the launcher supplies.
|
|
170
|
+
if (input.packageManager !== undefined && input.runner !== undefined) {
|
|
171
|
+
const task = input.runner(
|
|
172
|
+
input.packageManager.command,
|
|
173
|
+
[...(input.packageManager.args ?? []), 'add', spec, '--save-exact'],
|
|
174
|
+
{ cwd: profileDir, ...(input.packageManager.env === undefined ? {} : { env: input.packageManager.env }), timeoutMs },
|
|
175
|
+
)
|
|
176
|
+
let result
|
|
177
|
+
try {
|
|
178
|
+
result = await task
|
|
179
|
+
} catch (error) {
|
|
180
|
+
throw new UpdateError('UPDATE_FAILED', `the profile's package manager failed: ${messageOf(error)}`)
|
|
181
|
+
}
|
|
182
|
+
if (result?.exitCode !== 0) {
|
|
183
|
+
const output = [result?.stdout ?? '', result?.stderr ?? ''].join('\n').trim()
|
|
184
|
+
throw new UpdateError('UPDATE_FAILED', `${input.packageManager.command} could not install ${spec}: ${failureLine(output)}`, {
|
|
185
|
+
diagnostic: output,
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
return verify('package-manager', [result?.stdout ?? '', result?.stderr ?? ''].join('\n').trim())
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
throw new UpdateError(
|
|
192
|
+
'AUTO_UPDATE_UNAVAILABLE',
|
|
193
|
+
'this host offers no installer for the running profile',
|
|
194
|
+
{ retryable: false, diagnostic: manualCommand(profileDir, target) },
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @param {unknown} error
|
|
200
|
+
* @returns {string}
|
|
201
|
+
*/
|
|
202
|
+
function messageOf(error) {
|
|
203
|
+
return error instanceof Error ? error.message : String(error)
|
|
204
|
+
}
|
package/host/exec.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn one process and collect bounded output.
|
|
3
|
+
*
|
|
4
|
+
* The update runs a package manager, which can be slow and noisy; output is
|
|
5
|
+
* capped so a pathological log cannot grow the host's memory, and a deadline
|
|
6
|
+
* ends the wait rather than holding the request forever.
|
|
7
|
+
*/
|
|
8
|
+
import { spawn } from 'node:child_process'
|
|
9
|
+
|
|
10
|
+
/** Output kept per stream; enough for the error line, not for a full log. */
|
|
11
|
+
const MAX_OUTPUT_BYTES = 16 * 1024
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} command
|
|
15
|
+
* @param {readonly string[]} args
|
|
16
|
+
* @param {{ cwd: string, env?: Record<string, string>, timeoutMs?: number }} options
|
|
17
|
+
* @returns {Promise<{ exitCode: number | null, stdout: string, stderr: string, timedOut: boolean }>}
|
|
18
|
+
*/
|
|
19
|
+
export function runProcess(command, args, options) {
|
|
20
|
+
const timeoutMs = options.timeoutMs ?? 10 * 60_000
|
|
21
|
+
return new Promise(resolve => {
|
|
22
|
+
/** @type {string[]} */
|
|
23
|
+
const stdout = []
|
|
24
|
+
/** @type {string[]} */
|
|
25
|
+
const stderr = []
|
|
26
|
+
let stdoutBytes = 0
|
|
27
|
+
let stderrBytes = 0
|
|
28
|
+
let timedOut = false
|
|
29
|
+
let child
|
|
30
|
+
try {
|
|
31
|
+
child = spawn(command, args, {
|
|
32
|
+
cwd: options.cwd,
|
|
33
|
+
env: { ...process.env, ...(options.env ?? {}) },
|
|
34
|
+
// A Windows `.cmd` shim is not an executable Node can start directly.
|
|
35
|
+
shell: process.platform === 'win32' && /\.(?:cmd|bat)$/iu.test(command),
|
|
36
|
+
windowsHide: true,
|
|
37
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
38
|
+
})
|
|
39
|
+
} catch (error) {
|
|
40
|
+
resolve({ exitCode: null, stdout: '', stderr: error instanceof Error ? error.message : String(error), timedOut: false })
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
const timer = setTimeout(() => {
|
|
44
|
+
timedOut = true
|
|
45
|
+
child.kill()
|
|
46
|
+
}, timeoutMs)
|
|
47
|
+
child.stdout?.on('data', chunk => {
|
|
48
|
+
if (stdoutBytes >= MAX_OUTPUT_BYTES) return
|
|
49
|
+
const text = String(chunk)
|
|
50
|
+
stdoutBytes += text.length
|
|
51
|
+
stdout.push(text.slice(0, MAX_OUTPUT_BYTES))
|
|
52
|
+
})
|
|
53
|
+
child.stderr?.on('data', chunk => {
|
|
54
|
+
if (stderrBytes >= MAX_OUTPUT_BYTES) return
|
|
55
|
+
const text = String(chunk)
|
|
56
|
+
stderrBytes += text.length
|
|
57
|
+
stderr.push(text.slice(0, MAX_OUTPUT_BYTES))
|
|
58
|
+
})
|
|
59
|
+
child.on('error', error => {
|
|
60
|
+
clearTimeout(timer)
|
|
61
|
+
resolve({ exitCode: null, stdout: stdout.join(''), stderr: `${stderr.join('')}${error.message}`, timedOut })
|
|
62
|
+
})
|
|
63
|
+
child.on('close', code => {
|
|
64
|
+
clearTimeout(timer)
|
|
65
|
+
resolve({ exitCode: code, stdout: stdout.join(''), stderr: stderr.join(''), timedOut })
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
}
|
package/host/profile.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where this plugin is installed, and which version is actually there.
|
|
3
|
+
*
|
|
4
|
+
* The update path never trusts the running module: DSH keeps the loaded build
|
|
5
|
+
* in memory after the files on disk change, so "installed" always means the
|
|
6
|
+
* manifest under the profile's `node_modules`. Everything here is a read.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
9
|
+
import { homedir } from 'node:os'
|
|
10
|
+
import { isAbsolute, join, resolve } from 'node:path'
|
|
11
|
+
|
|
12
|
+
/** The package this host half updates and reports on. */
|
|
13
|
+
export const PACKAGE = 'dsh-sideby-note'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Parse a JSON file, or answer undefined when it is missing or malformed.
|
|
17
|
+
* @param {string} path
|
|
18
|
+
* @returns {any}
|
|
19
|
+
*/
|
|
20
|
+
export function readJson(path) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(readFileSync(path, 'utf8'))
|
|
23
|
+
} catch {
|
|
24
|
+
return undefined
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The DSH home directory, as DSH itself resolves it.
|
|
30
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
export function dshHome(env = process.env) {
|
|
34
|
+
const configured = typeof env.DSH_HOME === 'string' ? env.DSH_HOME.trim() : ''
|
|
35
|
+
return configured === '' ? join(homedir(), '.dsh') : configured
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The profile directory this host runs in.
|
|
40
|
+
*
|
|
41
|
+
* The launcher records the profile it opened (`profileContext`); the fallback
|
|
42
|
+
* follows DSH's own layout so a host without that service still behaves.
|
|
43
|
+
* @param {{ dir?: unknown } | undefined} profileContext
|
|
44
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
export function profileDirOf(profileContext, env = process.env) {
|
|
48
|
+
const recorded = profileContext !== null && typeof profileContext === 'object' ? profileContext.dir : undefined
|
|
49
|
+
if (typeof recorded === 'string' && recorded.trim() !== '') return resolve(recorded)
|
|
50
|
+
const explicit = typeof env.DSH_PROFILE_DIR === 'string' ? env.DSH_PROFILE_DIR.trim() : ''
|
|
51
|
+
if (explicit !== '') return resolve(explicit)
|
|
52
|
+
const name = typeof env.DSH_PROFILE === 'string' && env.DSH_PROFILE.trim() !== '' ? env.DSH_PROFILE.trim() : 'desktop'
|
|
53
|
+
return join(dshHome(env), 'profiles', name)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether a directory looks like a DSH profile.
|
|
58
|
+
* @param {string} dir
|
|
59
|
+
* @returns {boolean}
|
|
60
|
+
*/
|
|
61
|
+
export function isProfileDir(dir) {
|
|
62
|
+
const manifest = readJson(join(dir, 'package.json'))
|
|
63
|
+
return manifest !== null && typeof manifest === 'object' && typeof manifest.dsh?.profile === 'object'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The version on disk for this package, read from the profile's public link
|
|
68
|
+
* rather than from whatever versioned directory pnpm left behind.
|
|
69
|
+
* @param {string} profileDir
|
|
70
|
+
* @returns {string | undefined}
|
|
71
|
+
*/
|
|
72
|
+
export function installedVersion(profileDir) {
|
|
73
|
+
const manifest = readJson(join(profileDir, 'node_modules', PACKAGE, 'package.json'))
|
|
74
|
+
return typeof manifest?.version === 'string' ? manifest.version : undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The dependency spec the profile records, which DSH restores when an install
|
|
79
|
+
* fails — so it is the recorded intent, not necessarily what is on disk.
|
|
80
|
+
* @param {string} profileDir
|
|
81
|
+
* @returns {string | undefined}
|
|
82
|
+
*/
|
|
83
|
+
export function dependencySpec(profileDir) {
|
|
84
|
+
const manifest = readJson(join(profileDir, 'package.json'))
|
|
85
|
+
const spec = manifest?.dependencies?.[PACKAGE] ?? manifest?.devDependencies?.[PACKAGE]
|
|
86
|
+
return typeof spec === 'string' ? spec : undefined
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* How this profile installed the package: from the registry, from a checkout,
|
|
91
|
+
* or by something this host cannot drive.
|
|
92
|
+
* @param {string | undefined} spec
|
|
93
|
+
* @returns {'npm' | 'link' | 'manual'}
|
|
94
|
+
*/
|
|
95
|
+
export function installMode(spec) {
|
|
96
|
+
if (spec === undefined) return 'manual'
|
|
97
|
+
if (/^(?:link|file|workspace):/.test(spec) || /^\.{1,2}(?:[/\\]|$)/.test(spec)) return 'link'
|
|
98
|
+
return isAbsolute(spec) ? 'link' : 'npm'
|
|
99
|
+
}
|