@seekskyworld/open-browser 0.2.0 → 0.3.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/Docs/open-browser-api.d.ts +13 -9
- package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +6 -6
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/access-registry.mjs +8 -3
- package/action-execution.mjs +30 -5
- package/api-contract.mjs +6 -6
- package/browser-extension/manifest.json +1 -1
- package/browser-extension/newtab.js +1 -0
- package/browser-extension/phase-labels.js +1 -1
- package/browser-extension/popup.html +3 -1
- package/browser-extension/popup.js +33 -13
- package/browser-extension/tab-action.js +3 -2
- package/browser-extension/worker.js +3 -3
- package/capability-matrix.mjs +1 -1
- package/chromium-host.mjs +6 -10
- package/chromium-shell.mjs +2 -2
- package/cli.mjs +22 -22
- package/contract-validation.mjs +1 -1
- package/desktop/Info.plist +2 -2
- package/desktop/WorkspacePanel.m +3 -2
- package/desktop/build-macos.mjs +6 -3
- package/desktop/notarize-macos.mjs +54 -10
- package/desktop/sign.mjs +17 -2
- package/desktop/verify-macos-release.mjs +21 -13
- package/desktop/verify-version.mjs +22 -2
- package/engine-service.mjs +85 -26
- package/managed-input.mjs +22 -5
- package/mcp-http.mjs +9 -9
- package/mcp-server.mjs +23 -7
- package/mcp.mjs +1 -0
- package/package.json +6 -5
- package/page-activity.mjs +2 -1
- package/page-observation.mjs +4 -1
- package/receipt-store.mjs +17 -7
- package/runtime.mjs +2 -2
- package/sdk.mjs +24 -14
- package/service.mjs +36 -20
- package/skill-links.mjs +72 -18
- package/skills/open-browser/SKILL.md +8 -97
- package/skills/open-browser/references/macos.md +3 -0
- package/skills/open-browser/{SKILL.windows.md → references/operations.md} +7 -60
- package/skills/open-browser/references/recovery.md +36 -0
- package/skills/open-browser/references/windows.md +3 -0
- package/skills/open-browser/scripts/bootstrap.mjs +77 -89
- package/skills/open-browser/scripts/guide.mjs +17 -0
- package/studio/studio.js +2 -2
- package/tab-adoption.mjs +9 -3
- package/tab-recovery.mjs +100 -0
- package/visual-page.mjs +17 -7
- package/workspace-lifecycle.mjs +18 -2
- package/workspace-state.mjs +57 -16
- package/skills/open-browser/SKILL.macos.md +0 -112
package/chromium-host.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
4
4
|
import { managedInput } from './managed-input.mjs';
|
|
5
5
|
import { pageActivity } from './page-activity.mjs';
|
|
6
6
|
import { desktopCapabilities } from './capability-matrix.mjs';
|
|
7
|
+
import { extensionWorkspace } from './workspace-state.mjs';
|
|
7
8
|
|
|
8
9
|
export const extensionId = 'ehmdmliolflappfnmopemgojhbiilmpl';
|
|
9
10
|
const workerUrl = 'chrome-extension://' + extensionId + '/worker.js';
|
|
@@ -52,7 +53,7 @@ export async function chromiumHost(context) {
|
|
|
52
53
|
};
|
|
53
54
|
let initial = await worker();
|
|
54
55
|
const currentVersion = host => evaluateWorker(host, () => globalThis.openBrowserGroupVersion);
|
|
55
|
-
if (await currentVersion(initial) !==
|
|
56
|
+
if (await currentVersion(initial) !== 14) {
|
|
56
57
|
// A persistent Chromium profile can start the previous cached MV3 worker.
|
|
57
58
|
const replacement = context.waitForEvent('serviceworker', { predicate: isHost, timeout: 10000 });
|
|
58
59
|
try {
|
|
@@ -63,7 +64,7 @@ export async function chromiumHost(context) {
|
|
|
63
64
|
// Chromium can defer the replacement worker until its next profile launch.
|
|
64
65
|
throw Object.assign(new Error('工作区扩展已请求更新', { cause }), { code: 'extension_reload' });
|
|
65
66
|
}
|
|
66
|
-
if (await currentVersion(initial) !==
|
|
67
|
+
if (await currentVersion(initial) !== 14) throw new Error('请重新构建 open-browser 工作区扩展。');
|
|
67
68
|
}
|
|
68
69
|
let stopped = false;
|
|
69
70
|
let lastState;
|
|
@@ -112,12 +113,7 @@ export async function chromiumHost(context) {
|
|
|
112
113
|
while (!stopped) {
|
|
113
114
|
const startRevision = revision;
|
|
114
115
|
try {
|
|
115
|
-
const state =
|
|
116
|
-
workspaceId, agentName, name, mode, controlGeneration, pages: pages.map(({pageId}) => ({pageId})),
|
|
117
|
-
running: activity.running, currentPageId: activity.current?.pageId, stepKind: activity.current?.stepKind,
|
|
118
|
-
dispatchState: activity.current?.dispatchState, phase: activity.phase, needsCredential: activity.needsCredential,
|
|
119
|
-
needsHumanVerification: activity.needsHumanVerification,
|
|
120
|
-
}));
|
|
116
|
+
const state = await list();
|
|
121
117
|
const signature = JSON.stringify(state);
|
|
122
118
|
if (signature !== lastState) {
|
|
123
119
|
await evaluateWorker(await worker(), items => globalThis.openBrowserSync(items), state);
|
|
@@ -199,9 +195,9 @@ export async function chromiumHost(context) {
|
|
|
199
195
|
},
|
|
200
196
|
async show() { await evaluateWorker(await worker(), () => globalThis.openBrowserShow()); },
|
|
201
197
|
clickBar,
|
|
202
|
-
start(call, onBar) {
|
|
198
|
+
start(call, onBar, listForSync = async () => (await call('listWorkspaces')).map(ws => extensionWorkspace(ws))) {
|
|
203
199
|
void requests(call);
|
|
204
|
-
void sync(
|
|
200
|
+
void sync(listForSync);
|
|
205
201
|
if (onBar) void watchFrontTab(onBar);
|
|
206
202
|
},
|
|
207
203
|
stop() { stopped = true; changed(); },
|
package/chromium-shell.mjs
CHANGED
|
@@ -111,7 +111,7 @@ async function seedProfile(profileDir) {
|
|
|
111
111
|
finally { await rm(temporary, { force: true }); }
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
export async function launchChromiumShell({ profileDir = defaultProfile, headless = false, netLogPath } = {}) {
|
|
114
|
+
export async function launchChromiumShell({ profileDir = defaultProfile, headless = false, netLogPath, restoreSession = false } = {}) {
|
|
115
115
|
// A locally compiled Dev engine uses an ephemeral profile. It has a distinct
|
|
116
116
|
// executable identity and must never open an installed user's Keychain/profile.
|
|
117
117
|
const customEngine = isDevelopmentBuild && process.env.OPEN_BROWSER_DEV_CHROMIUM;
|
|
@@ -134,7 +134,7 @@ export async function launchChromiumShell({ profileDir = defaultProfile, headles
|
|
|
134
134
|
// the first visible tab is redirected to the open-browser cockpit.
|
|
135
135
|
ignoreDefaultArgs: ['--disable-extensions', '--disable-popup-blocking',
|
|
136
136
|
...(!customEngine ? ['--use-mock-keychain', '--password-store=basic'] : [])],
|
|
137
|
-
args: [...chromiumPrivacyArgs(), '--load-extension=' + extensionDir, '--window-size=1240,860',
|
|
137
|
+
args: [...chromiumPrivacyArgs(), ...(restoreSession ? ['--restore-last-session'] : []), '--load-extension=' + extensionDir, '--window-size=1240,860',
|
|
138
138
|
...(process.platform === 'linux' ? ['--class=open-browser', '--name=open-browser'] : []),
|
|
139
139
|
...(netLogPath ? ['--log-net-log=' + netLogPath, '--net-log-capture-mode=Default'] : [])],
|
|
140
140
|
});
|
package/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
import { socketPath, adminTokenPath } from './paths.mjs';
|
|
5
5
|
import { localRequest, agentMethods, OpenBrowserClient, OpenBrowserError } from './sdk.mjs';
|
|
@@ -14,6 +14,7 @@ const help = `open-browser <method> [< params.json]
|
|
|
14
14
|
printf '%s\\n' '{"workspaceId":"WORKSPACE_ID","pageId":"PAGE_ID"}' | open-browser observe
|
|
15
15
|
printf '%s\\n' '{"workspaceId":"WORKSPACE_ID","operationId":"finish-UNIQUE-ID","keepPageIds":[]}' | open-browser finishWorkspace
|
|
16
16
|
|
|
17
|
+
open-browser --json <method> # stdout 返回 {result} 或 {error},失败保留非零退出码
|
|
17
18
|
open-browser session # 每行读取 {"id":1,"method":"observe","params":{...}},直到 stdin 关闭
|
|
18
19
|
|
|
19
20
|
echo '{"name":"网页检查","agentName":"研究助手"}' | node cli.mjs createWorkspace
|
|
@@ -29,21 +30,6 @@ const help = `open-browser <method> [< params.json]
|
|
|
29
30
|
open-browser skill # 输出与当前包版本匹配的 Skill 指南
|
|
30
31
|
`;
|
|
31
32
|
|
|
32
|
-
async function printSkillGuide() {
|
|
33
|
-
const platform = process.platform === 'darwin' ? 'macos' : process.platform === 'win32' ? 'windows' : null;
|
|
34
|
-
const candidates = platform
|
|
35
|
-
? [`skills/open-browser/SKILL.${platform}.md`, 'skills/open-browser/SKILL.md']
|
|
36
|
-
: ['skills/open-browser/SKILL.md'];
|
|
37
|
-
for (const relative of candidates) {
|
|
38
|
-
try {
|
|
39
|
-
const guide = await readFile(new URL(relative, import.meta.url), 'utf8');
|
|
40
|
-
process.stdout.write(guide.endsWith('\n') ? guide : guide + '\n');
|
|
41
|
-
return;
|
|
42
|
-
} catch {}
|
|
43
|
-
}
|
|
44
|
-
throw new OpenBrowserError('SKILL_GUIDE_NOT_FOUND', `未找到 Skill 指南。已检查:${candidates.join('、')}`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
33
|
async function readParams() {
|
|
48
34
|
const chunks = [];
|
|
49
35
|
let bytes = 0;
|
|
@@ -88,8 +74,15 @@ async function sessionMain() {
|
|
|
88
74
|
api.close();
|
|
89
75
|
}
|
|
90
76
|
|
|
77
|
+
const jsonMode = process.argv[2] === '--json';
|
|
78
|
+
function writeResult(result) {
|
|
79
|
+
process.stdout.write(JSON.stringify(jsonMode ? {result:result ?? null} : result) + '\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
91
82
|
async function main() {
|
|
92
|
-
const [method, ...extra] = process.argv.slice(2);
|
|
83
|
+
const [method, ...extra] = process.argv.slice(jsonMode ? 3 : 2);
|
|
84
|
+
if (jsonMode && !agentMethods.includes(method) && !method?.startsWith('admin.'))
|
|
85
|
+
throw new OpenBrowserError('UNKNOWN_METHOD','--json 需要一个 API 方法名。');
|
|
93
86
|
if (method === 'session') {
|
|
94
87
|
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', 'session 不接受额外参数。');
|
|
95
88
|
await sessionMain();
|
|
@@ -102,7 +95,8 @@ async function main() {
|
|
|
102
95
|
}
|
|
103
96
|
if (method === 'skill') {
|
|
104
97
|
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', 'skill 不接受额外参数。');
|
|
105
|
-
await
|
|
98
|
+
const { readSkillGuide } = await import('./skills/open-browser/scripts/guide.mjs');
|
|
99
|
+
process.stdout.write(await readSkillGuide());
|
|
106
100
|
return;
|
|
107
101
|
}
|
|
108
102
|
if (!method || method === '--help' || method === '-h') {
|
|
@@ -119,21 +113,27 @@ async function main() {
|
|
|
119
113
|
const result = await admin(method.slice(6),args);
|
|
120
114
|
if (method === 'admin.pair') {
|
|
121
115
|
try { await writeFile(tokenFile,result.token + '\n',{flag:'wx',mode:0o600}); }
|
|
122
|
-
catch (error) {
|
|
116
|
+
catch (error) {
|
|
117
|
+
try { await admin('revokeClient', {principalId:result.principalId}); }
|
|
118
|
+
catch {
|
|
119
|
+
throw new OpenBrowserError('PAIR_CLEANUP_FAILED', `令牌文件写入失败,请用 admin.revokeClient 核对并撤销 ${result.principalId}。`);
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
123
|
delete result.token;
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
writeResult(result);
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
if (!agentMethods.includes(method)) throw new OpenBrowserError('UNKNOWN_METHOD', '未知的方法,请用 --help 查看命令。');
|
|
129
129
|
const api = new OpenBrowserClient({ fallbackName: 'CLI' });
|
|
130
130
|
const params = await readParams();
|
|
131
131
|
const result = method === 'capabilities' ? await api.capabilities() : await api.call(method, params);
|
|
132
|
-
|
|
132
|
+
writeResult(result);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
main().catch(error => {
|
|
136
|
-
process.stderr.write(JSON.stringify({ error: {
|
|
136
|
+
(jsonMode ? process.stdout : process.stderr).write(JSON.stringify({ error: {
|
|
137
137
|
code: error.code ?? 'CLI_ERROR', message: error.message,
|
|
138
138
|
...(error.nextAction ? { nextAction: error.nextAction } : {}),
|
|
139
139
|
} }) + '\n');
|
package/contract-validation.mjs
CHANGED
|
@@ -7,7 +7,7 @@ const schemas = new Map(tools.map(tool => [tool.name,tool.inputSchema]));
|
|
|
7
7
|
// Older callers spread a returned page or workspace handle into a subsequent request.
|
|
8
8
|
// Strip only the known read-only handle fields before checking that request.
|
|
9
9
|
const viewFields = new Set(['agentName','name','mode','pages','controlGeneration','activity','blockedOrigins','pageId','origin','title','profile','profileId','profileAlias',
|
|
10
|
-
'pageAvailability','nextAction','scope','accountAlias','ownership','syncState','syncRevision','lastSyncedAt','security','openedByOperationId','openerPageId','documentId','pendingDialogs']);
|
|
10
|
+
'pageAvailability','readyForAgent','nextAction','scope','accountAlias','ownership','syncState','syncRevision','lastSyncedAt','security','openedByOperationId','openerPageId','documentId','pendingDialogs']);
|
|
11
11
|
|
|
12
12
|
export function checkAgentRequest(method, params) {
|
|
13
13
|
const schema = schemas.get(method);
|
package/desktop/Info.plist
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<key>CFBundleExecutable</key><string>open-browser</string>
|
|
8
8
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
9
9
|
<key>CFBundleIconFile</key><string>open-browser.icns</string>
|
|
10
|
-
<key>CFBundleVersion</key><string>
|
|
11
|
-
<key>CFBundleShortVersionString</key><string>0.
|
|
10
|
+
<key>CFBundleVersion</key><string>2</string>
|
|
11
|
+
<key>CFBundleShortVersionString</key><string>0.3.0</string>
|
|
12
12
|
<key>NSHighResolutionCapable</key><true/>
|
|
13
13
|
</dict></plist>
|
package/desktop/WorkspacePanel.m
CHANGED
|
@@ -49,7 +49,7 @@ static NSString *Operation(NSDictionary *op) {
|
|
|
49
49
|
static NSInteger Group(NSDictionary *workspace) {
|
|
50
50
|
NSDictionary *activity = workspace[@"activity"];
|
|
51
51
|
if (![workspace[@"mode"] isEqual:@"agent"]) return 2;
|
|
52
|
-
if ([activity[@"needsCredential"] boolValue] || [@[@"failed", @"outcome_unknown", @"needs_credential"] containsObject:String(activity[@"phase"])]) return 0;
|
|
52
|
+
if ([activity[@"needsCredential"] boolValue] || [activity[@"needsVisualPermission"] boolValue] || [@[@"failed", @"outcome_unknown", @"needs_credential", @"needs_visual_permission"] containsObject:String(activity[@"phase"])]) return 0;
|
|
53
53
|
if (Map(activity[@"current"]) || [activity[@"queued"] integerValue] || [@[@"queued", @"running"] containsObject:String(activity[@"phase"])]) return 1;
|
|
54
54
|
return 3;
|
|
55
55
|
}
|
|
@@ -60,11 +60,12 @@ static NSString *Status(NSDictionary *workspace) {
|
|
|
60
60
|
NSDictionary *activity = workspace[@"activity"];
|
|
61
61
|
if ([activity[@"needsHumanVerification"] boolValue]) return @"需要人工验证";
|
|
62
62
|
if ([activity[@"needsCredential"] boolValue]) return @"等待补充凭据";
|
|
63
|
+
if ([activity[@"needsVisualPermission"] boolValue]) return @"需要授权截图";
|
|
63
64
|
NSString *current = Operation(Map(activity[@"current"]));
|
|
64
65
|
if (current.length) return current;
|
|
65
66
|
NSDictionary *phase = @{@"running":@"执行中", @"actionability":@"检查目标", @"dispatching":@"正在派发",
|
|
66
67
|
@"waiting":@"等待页面", @"verifying":@"核对结果", @"queued":@"排队中", @"completed":@"已完成", @"failed":@"执行失败",
|
|
67
|
-
@"outcome_unknown":@"结果待核对", @"cancelled":@"已取消", @"needs_credential":@"等待补充凭据", @"needs_human_verification":@"需要人工验证"};
|
|
68
|
+
@"outcome_unknown":@"结果待核对", @"cancelled":@"已取消", @"needs_credential":@"等待补充凭据", @"needs_human_verification":@"需要人工验证", @"needs_visual_permission":@"需要授权截图"};
|
|
68
69
|
return phase[String(activity[@"phase"])] ?: @"等待指令";
|
|
69
70
|
}
|
|
70
71
|
|
package/desktop/build-macos.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { isDevelopmentBuild } from '../build-profile.mjs';
|
|
|
11
11
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
12
12
|
const archOption = process.argv.findIndex(value => value === '--arch');
|
|
13
13
|
const requestedArch = archOption >= 0 ? process.argv[archOption + 1] : process.env.OPEN_BROWSER_TARGET_ARCH || process.arch;
|
|
14
|
+
const compilerArch = requestedArch === 'x64' ? 'x86_64' : requestedArch;
|
|
14
15
|
const sums = {
|
|
15
16
|
arm64: 'e7131995759b61a0170b646010d2ad35a5d37b4cb0d471f3e8317eac6f742f3d',
|
|
16
17
|
x64: 'c53383238206b9ae4db23c5d8a63645e2e753bec8ab51a49cc81939aa64e9422',
|
|
@@ -58,7 +59,7 @@ try {
|
|
|
58
59
|
execFileSync('plutil', ['-replace', 'CFBundleName', '-string', 'open-browser Dev', outerInfo]);
|
|
59
60
|
execFileSync('plutil', ['-replace', 'CFBundleDisplayName', '-string', 'open-browser Dev', outerInfo]);
|
|
60
61
|
}
|
|
61
|
-
execFileSync('xcrun', ['clang', '-arch',
|
|
62
|
+
execFileSync('xcrun', ['clang', '-arch', compilerArch, '-fobjc-arc', '-O2', '-framework', 'AppKit', '-framework', 'CoreGraphics',
|
|
62
63
|
path.join(root, 'desktop/Launcher.m'), path.join(root, 'desktop/OBControlBar.m'),
|
|
63
64
|
'-o', path.join(contents, 'MacOS/open-browser')], { stdio: 'inherit' });
|
|
64
65
|
await copyFile(path.join(root, 'desktop/icons/open-browser.icns'), path.join(resources, 'open-browser.icns'));
|
|
@@ -68,8 +69,10 @@ try {
|
|
|
68
69
|
await mkdir(engine, { recursive: true });
|
|
69
70
|
const sourceEngine = path.join(root, '.open-browser', 'engine');
|
|
70
71
|
const executable = path.relative(sourceEngine, await engineExecutable());
|
|
71
|
-
const
|
|
72
|
-
|
|
72
|
+
const platformDirectory = path.dirname(path.resolve(sourceEngine, executable, '../../..'));
|
|
73
|
+
const packagedDirectory = path.join(engine,path.relative(sourceEngine,platformDirectory));
|
|
74
|
+
await mkdir(path.dirname(packagedDirectory),{recursive:true});
|
|
75
|
+
copyTree(platformDirectory,packagedDirectory);
|
|
73
76
|
// Brand the packaged browser, which owns the visible window and Dock entry.
|
|
74
77
|
const originalBinary = path.join(engine, executable);
|
|
75
78
|
const originalBundle = path.resolve(path.dirname(originalBinary), '../..');
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { access, mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import { signingIdentity } from './sign.mjs';
|
|
5
6
|
import { fileURLToPath } from 'node:url';
|
|
6
7
|
|
|
7
8
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
8
9
|
const defaultApp = path.join(root, 'dist', 'open-browser.app');
|
|
9
10
|
|
|
10
11
|
function usage() {
|
|
11
|
-
console.log(`用法:node desktop/notarize-macos.mjs [app-path] [--zip zip-path]
|
|
12
|
+
console.log(`用法:node desktop/notarize-macos.mjs [app-path] [--zip zip-path] [--dmg dmg-path]
|
|
12
13
|
|
|
13
|
-
提交并公证 macOS 应用,固化票据后生成可上传的 GitHub ZIP。
|
|
14
|
+
提交并公证 macOS 应用,固化票据后生成可上传的 GitHub ZIP 和可选 DMG。
|
|
14
15
|
凭据优先使用 OPEN_BROWSER_NOTARY_PROFILE,其次使用 App Store Connect API Key,
|
|
15
16
|
最后使用 Apple ID 加应用专用密码。凭据只从环境变量或本机钥匙串读取。`);
|
|
16
17
|
}
|
|
@@ -18,6 +19,7 @@ function usage() {
|
|
|
18
19
|
function parseArgs(argv) {
|
|
19
20
|
let app = process.env.OPEN_BROWSER_APP_PATH || defaultApp;
|
|
20
21
|
let zip = process.env.OPEN_BROWSER_NOTARY_ZIP;
|
|
22
|
+
let dmg = process.env.OPEN_BROWSER_NOTARY_DMG;
|
|
21
23
|
for (let index = 0; index < argv.length; index += 1) {
|
|
22
24
|
const value = argv[index];
|
|
23
25
|
if (value === '--help' || value === '-h') return { help: true };
|
|
@@ -26,6 +28,11 @@ function parseArgs(argv) {
|
|
|
26
28
|
if (!zip) throw new Error('--zip 需要文件路径。');
|
|
27
29
|
continue;
|
|
28
30
|
}
|
|
31
|
+
if (value === '--dmg') {
|
|
32
|
+
dmg = argv[++index];
|
|
33
|
+
if (!dmg) throw new Error('--dmg 需要文件路径。');
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
29
36
|
if (value.startsWith('--')) throw new Error('未知参数:' + value);
|
|
30
37
|
if (app !== defaultApp && app !== process.env.OPEN_BROWSER_APP_PATH)
|
|
31
38
|
throw new Error('只能指定一个应用路径。');
|
|
@@ -33,7 +40,12 @@ function parseArgs(argv) {
|
|
|
33
40
|
}
|
|
34
41
|
const appArch = app.endsWith('-x64.app') ? 'x64' : app.endsWith('-arm64.app') ? 'arm64' : process.arch;
|
|
35
42
|
if (!zip) zip = path.join(path.dirname(app), `open-browser-macos-${appArch}.zip`);
|
|
36
|
-
return {
|
|
43
|
+
return {
|
|
44
|
+
app: path.resolve(app),
|
|
45
|
+
zip: path.resolve(zip),
|
|
46
|
+
dmg: dmg ? path.resolve(dmg) : undefined,
|
|
47
|
+
help: false,
|
|
48
|
+
};
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
function run(command, args, options = {}) {
|
|
@@ -123,12 +135,23 @@ async function main() {
|
|
|
123
135
|
|
|
124
136
|
run('/usr/bin/ditto', ['-c', '-k', '--keepParent', '--sequesterRsrc', parsed.app, parsed.zip]);
|
|
125
137
|
const credentials = notaryCredentials();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
function submitAndStaple(archive, target) {
|
|
139
|
+
const prefix = notarytool === '/usr/bin/xcrun' ? ['notarytool'] : [];
|
|
140
|
+
const args = [...prefix, 'submit', archive, '--wait', '--output-format', 'json', ...credentials];
|
|
141
|
+
if (process.env.OPEN_BROWSER_NOTARY_S3_ACCELERATION === '0') args.push('--no-s3-acceleration');
|
|
142
|
+
let result;
|
|
143
|
+
try {
|
|
144
|
+
result = JSON.parse(execFileSync(notarytool, args, { encoding: 'utf8', stdio:['ignore','pipe','pipe'] }));
|
|
145
|
+
} catch {
|
|
146
|
+
throw new Error('Apple 公证提交失败:' + path.basename(archive));
|
|
147
|
+
}
|
|
148
|
+
console.log(path.basename(archive), result.id, result.status);
|
|
149
|
+
if (result.status !== 'Accepted') throw new Error('Apple 未接受这次公证提交。');
|
|
150
|
+
const staplePrefix = stapler === '/usr/bin/xcrun' ? ['stapler'] : [];
|
|
151
|
+
run(stapler, [...staplePrefix, 'staple', target]);
|
|
152
|
+
run(stapler, [...staplePrefix, 'validate', target]);
|
|
153
|
+
}
|
|
154
|
+
submitAndStaple(parsed.zip, parsed.app);
|
|
132
155
|
run(spctl, ['--assess', '--type', 'execute', '--verbose=4', parsed.app]);
|
|
133
156
|
|
|
134
157
|
// The first archive is the notarization input. Recreate it after stapling so
|
|
@@ -136,6 +159,27 @@ async function main() {
|
|
|
136
159
|
run('/usr/bin/ditto', ['-c', '-k', '--keepParent', '--sequesterRsrc', parsed.app, parsed.zip]);
|
|
137
160
|
const digest = await sha256(parsed.zip);
|
|
138
161
|
await writeFile(parsed.zip + '.sha256', `${digest} ${path.basename(parsed.zip)}\n`);
|
|
162
|
+
if (parsed.dmg) {
|
|
163
|
+
const staging = await mkdtemp(path.join(root, 'dist', '.open-browser-notary-dmg-'));
|
|
164
|
+
const volume = path.join(staging, `open-browser ${path.basename(parsed.app, '.app')}`);
|
|
165
|
+
try {
|
|
166
|
+
await mkdir(volume, { recursive: true });
|
|
167
|
+
run('/usr/bin/ditto', [parsed.app, path.join(volume, path.basename(parsed.app))]);
|
|
168
|
+
run('/bin/ln', ['-s', '/Applications', path.join(volume, 'Applications')]);
|
|
169
|
+
run('/usr/bin/hdiutil', [
|
|
170
|
+
'create', '-volname', `open-browser ${path.basename(parsed.app, '.app')}`,
|
|
171
|
+
'-srcfolder', volume, '-ov', '-format', 'UDZO', parsed.dmg,
|
|
172
|
+
]);
|
|
173
|
+
run('/usr/bin/codesign', ['--sign', signingIdentity(), '--timestamp', parsed.dmg]);
|
|
174
|
+
submitAndStaple(parsed.dmg, parsed.dmg);
|
|
175
|
+
run(spctl, ['--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=4', parsed.dmg]);
|
|
176
|
+
const dmgDigest = await sha256(parsed.dmg);
|
|
177
|
+
await writeFile(parsed.dmg + '.sha256', `${dmgDigest} ${path.basename(parsed.dmg)}\n`);
|
|
178
|
+
console.log(`${parsed.dmg}\nSHA-256 ${dmgDigest}`);
|
|
179
|
+
} finally {
|
|
180
|
+
await rm(staging, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
139
183
|
console.log(`${parsed.zip}\nSHA-256 ${digest}`);
|
|
140
184
|
}
|
|
141
185
|
|
package/desktop/sign.mjs
CHANGED
|
@@ -45,6 +45,15 @@ function signCode(path, identity, preserveEntitlements = false) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function signDeep(bundle, identity, preserveEntitlements = false) {
|
|
49
|
+
const timestamp = process.env.OPEN_BROWSER_CODESIGN_TIMESTAMP === 'none'
|
|
50
|
+
? '--timestamp=none'
|
|
51
|
+
: '--timestamp';
|
|
52
|
+
const args = ['--deep', '--force', timestamp, '--options', 'runtime', '--entitlements', entitlements, '--sign', identity];
|
|
53
|
+
if (preserveEntitlements) args.push('--preserve-metadata=entitlements');
|
|
54
|
+
execFileSync('/usr/bin/codesign', [...args, bundle], { stdio: 'inherit' });
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
export function signingIdentity(requested = process.env.OPEN_BROWSER_SIGN_IDENTITY || process.env.APPLE_SIGNING_IDENTITY) {
|
|
49
58
|
const listing = execFileSync('/usr/bin/security', ['find-identity', '-v', '-p', 'codesigning'], { encoding: 'utf8' });
|
|
50
59
|
const identities = [...listing.matchAll(/^\s*\d+\) ([0-9A-F]{40}) "([^"]+)"\s*$/gm)];
|
|
@@ -58,8 +67,14 @@ export function signingIdentity(requested = process.env.OPEN_BROWSER_SIGN_IDENTI
|
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
export function signBundle(bundle, identity, nested = false) {
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
try {
|
|
71
|
+
for (const path of nestedCodePaths(bundle)) signCode(path, identity);
|
|
72
|
+
signCode(bundle, identity, nested);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// Some Chromium x64 helper layouts reject an individual parent signature
|
|
75
|
+
// until every nested code object is rewritten as one deep operation.
|
|
76
|
+
signDeep(bundle, identity, nested);
|
|
77
|
+
}
|
|
63
78
|
execFileSync('/usr/bin/codesign', ['--verify', '--strict', '--deep', bundle], { stdio: 'inherit' });
|
|
64
79
|
}
|
|
65
80
|
|
|
@@ -21,7 +21,7 @@ function run(command, args) {
|
|
|
21
21
|
|
|
22
22
|
async function main() {
|
|
23
23
|
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
24
|
-
console.log('用法:node desktop/verify-macos-release.mjs [app-path]');
|
|
24
|
+
console.log('用法:node desktop/verify-macos-release.mjs [app-path] [--zip zip-path] [--dmg dmg-path]');
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
if (process.platform !== 'darwin') throw new Error('macOS 发行验收只能在 macOS 执行。');
|
|
@@ -39,18 +39,26 @@ async function main() {
|
|
|
39
39
|
run(commandPath('spctl', '/usr/sbin/spctl'), ['--assess', '--type', 'execute', '--verbose=4', app]);
|
|
40
40
|
|
|
41
41
|
const appArch = app.endsWith('-x64.app') ? 'x64' : app.endsWith('-arm64.app') ? 'arm64' : process.env.OPEN_BROWSER_TARGET_ARCH || process.arch;
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
const zipArg = process.argv.indexOf('--zip');
|
|
43
|
+
const dmgArg = process.argv.indexOf('--dmg');
|
|
44
|
+
const zip = zipArg >= 0 ? process.argv[zipArg + 1] : process.env.OPEN_BROWSER_NOTARY_ZIP || path.join(path.dirname(app), `open-browser-macos-${appArch}.zip`);
|
|
45
|
+
const dmg = dmgArg >= 0 ? process.argv[dmgArg + 1] : process.env.OPEN_BROWSER_NOTARY_DMG || path.join(path.dirname(app), `open-browser-macos-${appArch}.dmg`);
|
|
46
|
+
run('/usr/bin/codesign', ['--verify', '--strict', dmg]);
|
|
47
|
+
run(stapler, stapler === '/usr/bin/xcrun' ? ['stapler', 'validate', dmg] : ['validate', dmg]);
|
|
48
|
+
run(commandPath('spctl', '/usr/sbin/spctl'), ['--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=4', dmg]);
|
|
49
|
+
for (const [kind, file] of [['ZIP', zip], ['DMG', dmg]]) {
|
|
50
|
+
try {
|
|
51
|
+
await access(file);
|
|
52
|
+
const checksumFile = file + '.sha256';
|
|
53
|
+
await access(checksumFile);
|
|
54
|
+
const expected = (await readFile(checksumFile, 'utf8')).trim().split(/\s+/)[0];
|
|
55
|
+
const actual = createHash('sha256').update(await readFile(file)).digest('hex');
|
|
56
|
+
if (expected !== actual) throw new Error(`${kind} SHA-256 不匹配:${file}`);
|
|
57
|
+
console.log(`${file}\nSHA-256 ${actual}`);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error?.code === 'ENOENT') throw new Error(`缺少已公证的 ${kind} 或校验和:${file}`);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
54
62
|
}
|
|
55
63
|
console.log(`macOS 发行验收通过:${app}`);
|
|
56
64
|
}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
5
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
6
|
+
import { createMcpServer } from '../mcp-server.mjs';
|
|
4
7
|
|
|
5
8
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
6
9
|
const packageInfo = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'));
|
|
10
|
+
// npm omits package-lock.json from distributed tarballs.
|
|
11
|
+
const lock = await readFile(path.join(root, 'package-lock.json'), 'utf8').then(JSON.parse)
|
|
12
|
+
.catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
7
13
|
const manifest = JSON.parse(await readFile(path.join(root, 'browser-extension/manifest.json'), 'utf8'));
|
|
8
14
|
const plist = await readFile(path.join(root, 'desktop/Info.plist'), 'utf8');
|
|
9
15
|
const expected = packageInfo.version;
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
const client = new Client({name:'release-check', version:expected});
|
|
17
|
+
const server = createMcpServer();
|
|
18
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
19
|
+
try {
|
|
20
|
+
await server.connect(serverTransport);
|
|
21
|
+
await client.connect(clientTransport);
|
|
22
|
+
const versions = {...(lock && {lock:lock.version, lockedPackage:lock.packages?.['']?.version}), extension:manifest.version,
|
|
23
|
+
macOS:plist.match(/<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/)?.[1],
|
|
24
|
+
mcp:client.getServerVersion()?.version};
|
|
25
|
+
for (const [source, version] of Object.entries(versions)) {
|
|
26
|
+
if (version !== expected) throw new Error(`Version mismatch: package=${expected}, ${source}=${version}`);
|
|
27
|
+
}
|
|
28
|
+
} finally {
|
|
29
|
+
await client.close();
|
|
30
|
+
await server.close();
|
|
31
|
+
}
|
|
12
32
|
console.log(`open-browser version ${expected} is consistent`);
|