@pmate/cli 0.44.2 → 0.44.4
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.
|
@@ -4,13 +4,14 @@ const { homedir } = require('node:os')
|
|
|
4
4
|
const path = require('node:path')
|
|
5
5
|
const methods = ['capabilities','workspaces.list','agents.list','agents.create','agents.update','plugins.list','plugins.configure','runtime.checkEnvironment','runtime.install','runtime.status','scripts.run']
|
|
6
6
|
function createAgentRuntime({ platform = process.platform, home = homedir(), execute, fetcher = fetch } = {}) {
|
|
7
|
+
let identityEpoch=0
|
|
7
8
|
let identity, installation, progress = { phase: 'idle' }
|
|
8
9
|
const root = path.join(home, '.pmate', 'merry-runtime')
|
|
9
10
|
const run = execute || ((file, args, cwd) => new Promise((resolve, reject) => {
|
|
10
11
|
execFile(file, args, { cwd, timeout: 600000, maxBuffer: 1024 * 1024, env: { ...process.env, PATH: [path.join(home,'.bun/bin'),'/opt/homebrew/bin','/usr/local/bin',process.env.PATH].filter(Boolean).join(':'), GIT_TERMINAL_PROMPT: '0' } }, (error, stdout) => error ? reject(new Error(`${path.basename(file)} 执行失败,请检查本地安装和仓库访问权限`)) : resolve(stdout.trim()))
|
|
11
12
|
}))
|
|
12
13
|
const installed = async () => {
|
|
13
|
-
if(existsSync(path.join(root,'packages/pmate-agent-tools/src/cli.ts')))return true
|
|
14
|
+
if(existsSync(path.join(root,'packages/pmate-agent-tools/src/cli.ts'))){try{await run('bun',['packages/pmate-agent-tools/src/cli.ts','plugin','--help'],root);return true}catch{return false}}
|
|
14
15
|
try{await run('pmate-agent-tools',['plugin','--help']);return true}catch{return false}
|
|
15
16
|
}
|
|
16
17
|
const check = async () => {
|
|
@@ -34,8 +35,8 @@ function createAgentRuntime({ platform = process.platform, home = homedir(), exe
|
|
|
34
35
|
const missing=environment.checks.filter(c=>!c.ready).map(c=>c.name)
|
|
35
36
|
if(missing.length)throw new Error(`请先安装 ${missing.join('、')},然后重新检测`)
|
|
36
37
|
if(environment.installed&&!existsSync(root)){progress={phase:'ready',message:'已检测到现有 Runtime'};return progress}
|
|
37
|
-
if(existsSync(root)&&!
|
|
38
|
-
if(!
|
|
38
|
+
if(existsSync(root)&&!existsSync(path.join(root,'packages/pmate-agent-tools/src/cli.ts')))throw new Error('安装目录已存在但不完整,请检查后重试;不会覆盖现有文件')
|
|
39
|
+
if(!existsSync(root)){mkdirSync(path.dirname(root),{recursive:true,mode:0o700});progress={phase:'downloading',message:'正在获取 Runtime 源码'};await run('git',['clone','https://github.com/parrot-mate/pmate-agents.git',root])}
|
|
39
40
|
progress={phase:'installing',message:'正在安装依赖'}
|
|
40
41
|
await run('pnpm',['install','--frozen-lockfile','--ignore-scripts'],root)
|
|
41
42
|
progress={phase:'verifying',message:'正在验证 Runtime'}
|
|
@@ -65,7 +66,15 @@ function createAgentRuntime({ platform = process.platform, home = homedir(), exe
|
|
|
65
66
|
if(method==='agents.create'&&expectedRevision!==undefined)throw new Error('创建不能指定 revision')
|
|
66
67
|
return api(base+(method==='plugins.configure'?'/runtime-plugins/':'/vega-agents/')+encodeURIComponent(id),'PUT',{...config,...(expectedRevision===undefined?{}:{expectedRevision})})
|
|
67
68
|
}
|
|
68
|
-
return { invoke,
|
|
69
|
+
return { invoke,
|
|
70
|
+
async configureIdentity(value, configure) {
|
|
71
|
+
const epoch=++identityEpoch;identity=undefined
|
|
72
|
+
const result=await configure(value)
|
|
73
|
+
if(epoch===identityEpoch)identity={appId:value.appId,token:value.token}
|
|
74
|
+
return result
|
|
75
|
+
},
|
|
76
|
+
setIdentity(value) { identityEpoch++;identity=value ? {appId:value.appId,token:value.token} : undefined }
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
function installAgentRuntime({ ipcMain, trusted, runtime }) {
|
|
71
80
|
ipcMain.handle('pmate:electron:invoke',(event,method,input)=>{if(!trusted(event))throw new Error('Untrusted Electron sender');return runtime.invoke(method,input)})
|
|
@@ -95,9 +95,7 @@ else {
|
|
|
95
95
|
})
|
|
96
96
|
ipcMain.handle('pmate:reach:configure', async (event, identity) => {
|
|
97
97
|
if (!desktopNotifications.trusted(event)) throw new Error('Untrusted reach sender')
|
|
98
|
-
|
|
99
|
-
agentRuntime.setIdentity(identity)
|
|
100
|
-
return result
|
|
98
|
+
return agentRuntime.configureIdentity(identity, value => desktopReach.configure(value))
|
|
101
99
|
})
|
|
102
100
|
ipcMain.handle('pmate:reach:stop', event => {
|
|
103
101
|
if (!desktopNotifications.trusted(event)) throw new Error('Untrusted reach sender')
|