Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(desktop): pin bundled npm deps through the Desktop lockfile (#19462)

Innei6b85e332f13f
diff --git a/.agents/acceptance/PROCESS.md b/.agents/acceptance/PROCESS.md
index 8738da13ba5..5fc25017eb3 100644
--- a/.agents/acceptance/PROCESS.md
+++ b/.agents/acceptance/PROCESS.md
@@ -93,7 +93,11 @@ requires abstracting the feedback first.
### Step 1 β€” Prepare the plan
Skip to Step 2 if this is a re-run after a fix, the plan is already agreed, or
-the user gave exact commands.
+the user gave exact commands. Skip straight to Step 5 when the delivery was
+already verified on the real product earlier in this session: the run's own
+observations, logs, command output, and captures are the evidence, and the
+round is written from them and ingested without re-execution or a checker stage
+(SKILL.md β†’ Decide whether to execute).
Draft the surface, cases, expected evidence, assumptions, and deliverable β€” but
do not send it for review yet: Step 2 must establish real environment state
diff --git a/.agents/skills/pr/SKILL.md b/.agents/skills/pr/SKILL.md
index 0a931ee3610..12c71a0f428 100644
--- a/.agents/skills/pr/SKILL.md
+++ b/.agents/skills/pr/SKILL.md
@@ -49,7 +49,7 @@ If current branch is `canary`/`main` but there are NO uncommitted changes and no
### 5. Acceptance gate
-A feature or fix needs a published acceptance round before the PR is opened (AGENTS.md β†’ Acceptance). If step 1 found none for this branch, run the `acceptance` skill first and come back with its `https://app.lobehub.com/acceptance/<id>` link. Pure refactors or tooling changes with no user-visible outcome may skip it β€” state that in the PR body instead of leaving the line out.
+A feature or fix needs a published acceptance round before the PR is opened (AGENTS.md β†’ Acceptance). If step 1 found none for this branch, run the `acceptance` skill first and come back with its `https://app.lobehub.com/acceptance/<id>` link. When the delivery was already verified on the real product earlier in the session, that skill's ingest path publishes the existing observations and artifacts directly β€” no re-run, no re-plan. Pure refactors or tooling changes with no user-visible outcome may skip it β€” state that in the PR body instead of leaving the line out.
### 6. Create PR with `gh pr create --base canary`
diff --git a/apps/desktop/pnpm-lock.yaml b/apps/desktop/pnpm-lock.yaml
index 022868cf506..da5a1dc745e 100644
--- a/apps/desktop/pnpm-lock.yaml
+++ b/apps/desktop/pnpm-lock.yaml
@@ -707,6 +707,9 @@ importers:
numeral:
specifier: ^2.0.6
version: 2.0.6
+ partial-json:
+ specifier: ^0.1.7
+ version: 0.1.7
pure-rand:
specifier: ^7.0.1
version: 7.0.1
@@ -7335,6 +7338,9 @@ packages:
resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==}
engines: {node: '>= 0.8'}
+ resolution: {integrity: sha512-Njv/59hHaokb/hRUjce3Hdv12wd60MtM9Z5Olmn+nehe0QDAsRtRbJPvJ0Z91TusF0SuZRIvnM+S4l6EIP8leA==}
+
resolution: {integrity: sha512-0YNdUceMdaQwoKce1gatDScmMo5pu/tfABfnzEqeG0gtTmd7mh/WcwgUjtAeOU7N8nFFlbQBnFK2gXW5fGvmMA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@@ -16254,6 +16260,8 @@ snapshots:
+
diff --git a/apps/desktop/scripts/__tests__/devOrchestrator.test.mjs b/apps/desktop/scripts/__tests__/devOrchestrator.test.mjs
index 754834836b5..8e3d5b0194a 100644
--- a/apps/desktop/scripts/__tests__/devOrchestrator.test.mjs
+++ b/apps/desktop/scripts/__tests__/devOrchestrator.test.mjs
@@ -168,6 +168,27 @@ describe('createDevOrchestrator', () => {
expect(electron.kill).toHaveBeenCalledTimes(1);
});
+ it('names every changed bundle in the restart log, once', async () => {
+ const h = createHarness();
+ h.orchestrator.start();
+ await h.becomeReady();
+
+ h.watchers[0]('change', 'index.js');
+ h.watchers[1]('change', 'index.js');
+ await vi.advanceTimersByTimeAsync(500);
+
+ const message = h.options.log.mock.calls.at(-1)[0];
+ expect(message).toContain('[desktop-dev] main/preload bundle changed');
+ expect(message).toContain('dist/main/index.js: change');
+ expect(message).toContain('dist/preload/index.js: change');
+
+ h.electronSpawns()[0].child.emit('exit', null);
+ h.watchers[0]('change', 'index.js');
+ await vi.advanceTimersByTimeAsync(500);
+
+ expect(h.options.log.mock.calls.at(-1)[0]).not.toContain('dist/preload/index.js');
+ });
+
it('stops the watchers when electron is quit by hand', async () => {
const h = createHarness();
h.orchestrator.start();
diff --git a/apps/desktop/scripts/__tests__/mainHash.test.mjs b/apps/desktop/scripts/__tests__/mainHash.test.mjs
index 82b309f81d8..c8bb7349074 100644
--- a/apps/desktop/scripts/__tests__/mainHash.test.mjs
+++ b/apps/desktop/scripts/__tests__/mainHash.test.mjs
@@ -392,11 +392,11 @@ describe('workspace Vite graph', () => {
expect((await hash()).mainHash).not.toBe(call.mainHash);
});
- it('rejects bundled npm code resolved outside the frozen Desktop installation', async () => {
+ it('requires bundled npm code to be pinned by the Desktop lockfile', async () => {
await mkdir(path.join(root, 'apps/desktop/node_modules'), { recursive: true });
await put(
'node_modules/floating/package.json',
- '{"name":"floating","type":"module","main":"index.js"}',
+ '{"name":"floating","version":"1.0.0","type":"module","main":"index.js"}',
);
await put('node_modules/floating/index.js', 'export const value = 1;');
await put(
@@ -412,7 +412,11 @@ describe('workspace Vite graph', () => {
},
ssr: { noExternal: true },
});
- await expect(hash({ graph: [graph] })).rejects.toThrow("outside Desktop's locked installation");
+ await expect(hash({ graph: [graph] })).rejects.toThrow(
+ 'not pinned by apps/desktop/pnpm-lock.yaml: [email protected]',
+ );
+ await put('apps/desktop/pnpm-lock.yaml', 'lockfileVersion: 9\npackages:\n [email protected]:\n');
+ expect((await hash({ graph: [graph] })).mainHash).toMatch(/^[0-9a-f]{64}$/);
});
it('tracks star forwarding, cycles and CommonJS without dropping runtime dependencies', async () => {
diff --git a/apps/desktop/scripts/devOrchestrator.mjs b/apps/desktop/scripts/devOrchestrator.mjs
index 4cf8e615649..bf60cafa4af 100644
--- a/apps/desktop/scripts/devOrchestrator.mjs
+++ b/apps/desktop/scripts/devOrchestrator.mjs
@@ -87,11 +87,20 @@ export function createDevOrchestrator({
});
}
- function scheduleRestart() {
+ const pendingChanges = new Map();
+
+ function scheduleRestart(dir, eventType, filename) {
+ const file = path.join(dir, filename ?? '');
+ const detail = existsSync(file)
+ ? `${statSync(file).size}B @${new Date(statSync(file).mtimeMs).toISOString()}`
+ : 'missing';
+ pendingChanges.set(path.relative(desktopRoot, file), `${eventType} ${detail}`);
clearTimeout(debounce);
debounce = setTimeout(() => {
+ const changes = [...pendingChanges].map(([f, d]) => ` ${f}: ${d}`).join('\n');
+ pendingChanges.clear();
if (shuttingDown || !electron) return;
- log('[desktop-dev] main/preload bundle changed, restarting electron');
+ log(`[desktop-dev] main/preload bundle changed, restarting electron\n${changes}`);
restarting = true;
electron.kill();
}, restartDebounceMs);
@@ -99,7 +108,7 @@ export function createDevOrchestrator({
function watchBundles() {
for (const dir of [path.dirname(MAIN_BUNDLE), path.dirname(PRELOAD_BUNDLE)]) {
- watch(dir, scheduleRestart);
+ watch(dir, (eventType, filename) => scheduleRestart(dir, eventType, filename));
}
}
diff --git a/apps/desktop/scripts/mainHash.mjs b/apps/desktop/scripts/mainHash.mjs
index 0f7a731bccf..8197f96f186 100644
--- a/apps/desktop/scripts/mainHash.mjs
+++ b/apps/desktop/scripts/mainHash.mjs
@@ -53,6 +53,17 @@ const stableJson = (value) =>
: item,
);
+export function lockedPackages(lockfile) {
+ const locked = new Set();
+ let inPackages = false;
+ for (const line of lockfile.split('\n')) {
+ if (/^\S/.test(line)) inPackages = line.startsWith('packages:');
+ const key = inPackages && line.match(/^ {2}'?(\S+?)'?:\s*$/)?.[1];
+ if (key) locked.add(key);
+ }
+ return locked;
+}
+
export function createInputManifest(inputs) {
const sorted = [...inputs].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
if (new Set(sorted.map((input) => input.path)).size !== sorted.length) {
@@ -166,14 +177,42 @@ export async function collectSourceInputs({
};
const sourceFile = (id) => id.replace(/^\0/, '').split('?')[0];
- let installedRoot;
+ // The lockfile is the only dependency input to the hash, so every bundled npm module
+ // must resolve to a version it pins, wherever pnpm happened to link it from.
+ let locked;
+ const packageIdentity = async (file) => {
+ for (let dir = path.dirname(file); ; dir = path.dirname(dir)) {
+ try {
+ const { name, version } = JSON.parse(
+ await readFile(path.join(dir, 'package.json'), 'utf8'),
+ );
+ if (name && version) return `${name}@${version}`;
+ } catch (error) {
+ if (error.code !== 'ENOENT') throw error;
+ }
+ if (dir === path.dirname(dir)) return undefined;
+ }
+ };
for (const target of graph) {
for (const id of target.nodes.keys()) {
const file = sourceFile(id);
if (!path.isAbsolute(file) || !slash(file).includes('/node_modules/')) continue;
- installedRoot ??= await realpath(path.join(repoRoot, 'apps/desktop/node_modules'));
- if (!inside(installedRoot, await realpath(file))) {
- throw new Error(`Main hash dependency is outside Desktop's locked installation: ${file}`);
+ locked ??= lockedPackages(
+ await readFile(path.join(repoRoot, 'apps/desktop/pnpm-lock.yaml'), 'utf8'),
+ );
+ const dependency = await packageIdentity(await realpath(file));
+ const name = dependency?.slice(0, dependency.lastIndexOf('@'));
+ // Tarball, git, file: and link: specifiers pin by resolution instead of version.
+ const pinned =
+ dependency &&
+ (locked.has(dependency) ||
+ [...locked].some(
+ (key) => key.startsWith(`${name}@`) && /^[a-z+]+:/.test(key.slice(name.length + 1)),
+ ));
+ if (!pinned) {
+ throw new Error(
+ `Main hash dependency is not pinned by apps/desktop/pnpm-lock.yaml: ${dependency ?? 'unknown'} (${file})`,
+ );
}
}
}
diff --git a/packages/builtin-skills/src/acceptance/SKILL.md b/packages/builtin-skills/src/acceptance/SKILL.md
index f3b074533c5..2062ad897bc 100644
--- a/packages/builtin-skills/src/acceptance/SKILL.md
+++ b/packages/builtin-skills/src/acceptance/SKILL.md
@@ -32,13 +32,14 @@ must not by itself start another verification run. First inspect the requested
scope and the task's existing reports, evidence, and published acceptance links
(from the conversation, PR, or local `.acceptances/` directory).
-| Delivery state | Action |
-| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| Documentation/instruction-only change, or pure refactor/tooling change with no product behavior change | Skip product acceptance and briefly state why. Keep any applicable quality checks. |
-| Gitlink-only sync | Do not launch a fresh acceptance. Link the upstream change and its existing acceptance when available; disclose missing upstream evidence without claiming it passed. Cloud changes accompanying the sync are assessed separately. |
-| Completed acceptance already published and still covers the delivery | Reuse its URL and coverage. Do not create a round or rerun cases just for the PR. |
-| Completed acceptance report and evidence exist locally and still cover the delivery | Inspect coverage and artifacts, then upload that report using [report.md](references/report.md). Preserve the original execution provenance; no product rerun, new plan, or repeated completed checker review is needed merely for upload. |
-| Product behavior lacks valid evidence, or relevant behavior changed after verification | Execute only the missing or affected outcomes, retain unaffected evidence with its original provenance, and publish according to the round rules below. |
+| Delivery state | Action |
+| ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Documentation/instruction-only change, or pure refactor/tooling change with no product behavior change | Skip product acceptance and briefly state why. Keep any applicable quality checks. |
+| Gitlink-only sync | Do not launch a fresh acceptance. Link the upstream change and its existing acceptance when available; disclose missing upstream evidence without claiming it passed. Cloud changes accompanying the sync are assessed separately. |
+| Completed acceptance already published and still covers the delivery | Reuse its URL and coverage. Do not create a round or rerun cases just for the PR. |
+| Completed acceptance report and evidence exist locally and still cover the delivery | Inspect coverage and artifacts, then upload that report using [report.md](references/report.md). Preserve the original execution provenance; no product rerun, new plan, or repeated completed checker review is needed merely for upload. |
+| The delivery was already exercised on the real product earlier in this session (observations and raw artifacts exist, no report yet) | Do not rerun, re-plan, or open a checker stage. Write `plan[]` and `cases[]` from the observations already made, attach the original artifacts (logs, command output, captures) with their original provenance, disclose any required medium that was never captured instead of recapturing it, and ingest. |
+| Product behavior lacks valid evidence, or relevant behavior changed after verification | Execute only the missing or affected outcomes, retain unaffected evidence with its original provenance, and publish according to the round rules below. |
Evidence is reusable when its criteria cover the requested behavior, its artifacts
are available and support the observations, and subsequent code, dependency,
diff --git a/packages/context-engine/package.json b/packages/context-engine/package.json
index c94f0bfb981..5829897951d 100644
--- a/packages/context-engine/package.json
+++ b/packages/context-engine/package.json
@@ -29,6 +29,7 @@
"debug": "^4.4.3",
"es-toolkit": "^1.49.0",
"immer": "^10.2.0",
+ "partial-json": "^0.1.7",
"tokenx": "^1.3.0",
"ts-md5": "^2.0.1",
"unist-builder": "^4.0.0",
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 9dbf06ae4ec..7c65488c561 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -31,6 +31,7 @@
"model-bank": "workspace:*",
"nanoid": "^5.1.16",
"numeral": "^2.0.6",
+ "partial-json": "^0.1.7",
"pure-rand": "^7.0.1",
"remark": "^15.0.1",
"remark-gfm": "^4.0.1",