@messenger-agent/client 0.33.0-alpha.9 → 0.33.1-alpha.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/dist/config-file.d.ts +1 -0
- package/dist/config-file.js +1 -1
- package/dist/index.js +4 -4
- package/dist/install.js +3 -3
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +3 -3
- package/dist/supervisor.d.ts +2 -1
- package/dist/supervisor.js +1 -1
- package/package.json +5 -5
package/dist/config-file.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function ensureClientDirectories(dataDir: string, configPath: str
|
|
|
17
17
|
export declare function readConfigYaml(configPath: string): Promise<YamlObject>;
|
|
18
18
|
export declare function mergeClientConfig(existing: YamlObject, options: ClientConfigOptions): YamlObject;
|
|
19
19
|
export declare function readClientPath(configPath: string): Promise<string | undefined>;
|
|
20
|
+
export declare function readAgentServer(configPath: string): Promise<string | undefined>;
|
|
20
21
|
export declare function writeClientPath(configPath: string, path: string): Promise<void>;
|
|
21
22
|
export declare function readUpgradeChannel(configPath: string): Promise<ReleaseChannel>;
|
|
22
23
|
export declare function writeUpgradeChannel(configPath: string, channel: ReleaseChannel): Promise<void>;
|
package/dist/config-file.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{constants as
|
|
1
|
+
import{constants as p}from"node:fs";import{access as g,chmod as f,mkdir as a,readFile as v,rename as y,stat as x,writeFile as h}from"node:fs/promises";import{dirname as l,join as s}from"node:path";import{normalizeAgentServer as m}from"@messenger-agent/shared/agent-config";import{parse as C,stringify as _}from"yaml";import{normalizeReleaseChannel as k}from"./runtime.js";function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function o(e,r){const t=e[r];if(u(t))return t;const n={};return e[r]=n,n}async function U(e,r){await a(l(r),{recursive:!0,mode:448}),await f(l(r),448),await a(e,{recursive:!0,mode:448}),await a(s(e,"logs"),{recursive:!0,mode:448}),await a(s(e,"uploads"),{recursive:!0,mode:448}),await a(s(e,"runtime"),{recursive:!0,mode:448})}async function A(e){try{return await g(e,p.F_OK),!0}catch{return!1}}async function i(e){if(!await A(e))return{};const r=C(await v(e,"utf8"));if(r==null)return{};if(!u(r))throw new Error(`Config file must contain a YAML object: ${e}`);return r}function $(e,r){const t={...e};if(t.log_level??="info",r.preserveWorkspaces||(t.workspaces=[{id:r.workspaceId,name:r.workspaceName??`${r.tunnelId} Default`,path:r.workspacePath}]),t.data_dir=r.dataDir,r.path){const w=o(t,"client");w.path=r.path}r.server&&(t.server=m(r.server));const n=o(t,"file_uploads");n.temp_dir=s(r.dataDir,"uploads");const c=o(t,"tunnel");return c.enabled=!0,r.serverUrl&&(c.server_url=r.serverUrl),c.tunnel_id=r.tunnelId,c.token=r.token,t}async function Y(e){const t=(await i(e)).client;if(!(!u(t)||typeof t.path!="string"||!t.path.trim()))return t.path}async function z(e){const r=await i(e);return typeof r.server=="string"&&r.server.trim()?m(r.server):void 0}async function R(e,r){const t=await i(e),n=o(t,"client");n.path=r,await d(e,t)}async function S(e){const t=(await i(e)).auto_upgrade,n=u(t)?t.channel:void 0;return k(n)??"latest"}async function K(e,r){const t=await i(e),n=o(t,"auto_upgrade");n.channel=r,await d(e,t)}async function d(e,r){await a(l(e),{recursive:!0,mode:448});const t=`${e}.${process.pid}.${Date.now()}.tmp`;await h(t,_(r),{mode:384}),await f(t,384),await y(t,e),await f(e,384)}async function L(e){await U(e.dataDir,e.configPath);const r=await i(e.configPath),t=$(r,e);return await d(e.configPath,t),t}async function M(e){if(((await x(e)).mode&511&63)!==0)throw new Error(`Config file permissions are too broad: ${e}`)}export{M as assertPrivateConfig,U as ensureClientDirectories,$ as mergeClientConfig,z as readAgentServer,Y as readClientPath,i as readConfigYaml,S as readUpgradeChannel,L as updateClientConfig,R as writeClientPath,d as writeConfigYaml,K as writeUpgradeChannel};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{parseCliArgs as S,UsageError as
|
|
3
|
-
`)}function
|
|
4
|
-
`):"No maintenance task has been scheduled"}function
|
|
2
|
+
import{parseCliArgs as S,UsageError as A,usage as u}from"./args.js";import{activateMigratedService as N,completeMigrationHandoff as T,installClient as W}from"./install.js";import{currentPackageVersion as f,installRuntime as b,normalizeUpgradeVersion as G,rollbackRuntime as O}from"./runtime.js";import{serviceCommandsForConfig as p,serviceName as h,uninstallLegacyService as _,uninstallService as E,verifyServiceHealth as H}from"./service.js";import{runSupervisor as M}from"./supervisor.js";import{runCommand as D}from"./exec.js";import{defaultConfigPath as i,preferredClientPaths as l}from"./paths.js";import{readAgentServer as F,readClientPath as I,writeClientPath as w,writeUpgradeChannel as $}from"./config-file.js";import{requestAgentRestart as R,requestClientActivity as U,requestMaintenanceCancel as k,requestMaintenanceStatus as q,requestScheduleMaintenance as L}from"./control.js";import{cliName as j,productName as x}from"./identity.js";import{migrateLegacyClient as z}from"./migration.js";import{assertPlatformNativeDependencies as B}from"./native-dependencies.js";async function J(){const e=S(process.argv.slice(2));if(e.command==="version"){console.log(`${j} ${await f()}`);return}if(e.command==="self-check"){await f(),B(),console.log(`${x} runtime is healthy`);return}if(e.command==="complete-migration"){await T(e.handoffPath);return}if(e.command==="run-service"){await M(e.configPath??process.env.AGENT_CONFIG_PATH??i);return}if(e.command==="install"){const t=await W(e);console.log(`Installed ${h}`),console.log(`Config: ${t.configPath}`),console.log(`Data: ${t.dataDir}`),console.log(`Runtime: ${t.runtime.currentLink}`),console.log(`Command: ${t.runtime.cliWrapperPath}`),console.log(`Service file: ${t.service.servicePath}`),console.log(`Upgrade: ${t.runtime.cliWrapperPath} upgrade`),console.log(`Restart: ${t.runtime.cliWrapperPath} restart`),console.log(`Status: ${t.runtime.cliWrapperPath} status`),console.log(`Logs: ${t.service.commands.logs}`);for(const n of t.service.warnings)console.warn(`Warning: ${n}`);return}if(e.command==="upgrade"){const{version:t,channel:n}=G(e.version,e.channel),a=process.env.PATH,o=e.configPath===i?l().configPath:e.configPath;if(a&&await w(o,a),n&&(await $(o,n),console.log(`Auto-upgrade channel: ${n}`)),e.delaySeconds!==void 0){await m(o,{type:"upgrade",version:t,path:a},e.delaySeconds,e.allowWaiting);return}const c=await z(),r=o===c.legacyPaths.configPath?c.paths.configPath:o;a&&r!==o&&await w(r,a),n&&r!==o&&await $(r,n);const s=await b({version:t,configPath:r,server:await F(r),runtimeDir:c.paths.runtimeDir,binDir:c.paths.binDir,path:a??await I(r)});if(!await N(c,s,r,a)){const d=p(r);try{await g(d.restart),await H()}catch(y){throw await O(s),await g(d.restart).catch(()=>{}),y}}console.log(`Upgraded runtime to ${s.version}`),console.log(`Runtime: ${s.currentLink}`),console.log(`Command: ${s.cliWrapperPath}`),console.log(`Status: ${s.cliWrapperPath} status`);return}if(e.command==="sessions"){const t=await U(v(e.configPath));console.log(e.json?JSON.stringify(t):V(t));return}if(e.command==="maintenance"){const t=v(e.configPath),n=e.action==="cancel"?await k(t):await q(t);console.log(e.json?JSON.stringify(n??null):K(n));return}if(e.command==="restart"&&e.agent){if(e.delaySeconds!==void 0){await m(process.env.AGENT_CONFIG_PATH??i,{type:"restart",agent:e.agent},e.delaySeconds,e.allowWaiting);return}await R(process.env.AGENT_CONFIG_PATH??i,e.agent),console.log(`Restarted ${e.agent} agent`);return}if(e.command==="status"||e.command==="start"||e.command==="restart"||e.command==="stop"){if((e.command==="restart"||e.command==="stop")&&e.delaySeconds!==void 0){await m(process.env.AGENT_CONFIG_PATH??i,{type:e.command},e.delaySeconds,e.allowWaiting);return}const t=l().configPath,n=p(t),a=e.command==="status"?n.status:e.command==="start"?n.start:e.command==="restart"?n.restart:n.stop;await g(a);return}if(e.command==="uninstall"){if(e.delaySeconds!==void 0){await m(process.env.AGENT_CONFIG_PATH??i,{type:"uninstall"},e.delaySeconds,e.allowWaiting);return}l().configPath===i?await E():await _(),console.log(`Uninstalled ${h}`);return}}function v(e){return e===i?l().configPath:e}async function m(e,t,n,a){const o=await L(e,{operation:t,delaySeconds:n,allowWaiting:a});console.log(`Scheduled maintenance task ${o.id}`),console.log(`Operation: ${P(o.operation)}`),console.log(`Not before: ${o.notBefore}`)}function V(e){const t=[`Active sessions: ${e.active}`,`Waiting sessions: ${e.waiting}`];for(const n of["codex","claude"]){const a=e.agents[n];t.push(a.available?`${C(n)}: active=${a.active}, waiting=${a.waiting}`:`${C(n)}: unavailable (${a.error})`)}return t.join(`
|
|
3
|
+
`)}function K(e){return e?[`Task: ${e.id}`,`Operation: ${P(e.operation)}`,`Status: ${e.status}`,`Not before: ${e.notBefore}`,...e.message?[`Message: ${e.message}`]:[]].join(`
|
|
4
|
+
`):"No maintenance task has been scheduled"}function P(e){return e.type==="upgrade"?`upgrade to ${e.version}`:e.type==="restart"?e.agent?`restart ${e.agent}`:"restart client":e.type}function C(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}async function g(e){const t=await D("/bin/sh",["-lc",e],{allowFailure:!0});if(t.stdout&&process.stdout.write(t.stdout),t.stderr&&process.stderr.write(t.stderr),t.status!==0)throw new Error(t.stderr||t.stdout||`Command failed: ${e}`)}J().catch(e=>{if(e instanceof A){const n=e.message===u()?e.message:`${e.message}
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${u()}`;console.error(n),process.exit(2)}const t=e instanceof Error?e.message:String(e);console.error(t),process.exit(1)});
|
package/dist/install.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{randomUUID as _}from"node:crypto";import{mkdir as C,readFile as L,realpath as H,rename as j,stat as R,writeFile as W}from"node:fs/promises";import{join as P}from"node:path";import{setTimeout as U}from"node:timers/promises";import{normalizeAgentServer as z}from"@messenger-agent/shared/agent-config";import{readConfigYaml as S,updateClientConfig as F,writeUpgradeChannel as G}from"./config-file.js";import{installRuntime as V,rollbackRuntime as g}from"./runtime.js";import{installService as A,startLegacyService as D,stopLegacyService as E,uninstallLegacyService as b,uninstallService as M}from"./service.js";import{UsageError as
|
|
2
|
-
`)??[]){const c=
|
|
3
|
-
`,{mode:384}),await j(e,t)}function K(t=process.platform){if(t!=="linux"&&t!=="darwin")throw new Error("Only Linux and macOS are supported")}function Q(t=process.versions.node){const
|
|
1
|
+
import{randomUUID as _}from"node:crypto";import{mkdir as C,readFile as L,realpath as H,rename as j,stat as R,writeFile as W}from"node:fs/promises";import{join as P}from"node:path";import{setTimeout as U}from"node:timers/promises";import{normalizeAgentServer as z}from"@messenger-agent/shared/agent-config";import{readConfigYaml as S,updateClientConfig as F,writeUpgradeChannel as G}from"./config-file.js";import{installRuntime as V,rollbackRuntime as g}from"./runtime.js";import{installService as A,startLegacyService as D,stopLegacyService as E,uninstallLegacyService as b,uninstallService as M}from"./service.js";import{UsageError as w}from"./args.js";import{defaultWorkspacePath as I,legacyCodingAgentPaths as q,messengerAgentPaths as B}from"./paths.js";import{runCommand as y}from"./exec.js";import{completeLegacyMigration as N,migrateLegacyClient as J,rollbackLegacyMigration as Z}from"./migration.js";const x="vip.elevo.messenger.agent.migration";async function gt(t,r,e,s){if(!t.migrated)return!1;if(process.platform==="darwin")return X(t,r,e,s);try{return await T(t,r,e,s),!0}catch(n){throw await g(r).catch(()=>{}),await O(t),n}}async function T(t,r,e,s){const n=await S(e),o=p(n,"data_dir")??t.paths.dataDir,i=Array.isArray(n.workspaces)?n.workspaces.find(c=>!!c&&typeof c=="object"&&!Array.isArray(c)&&typeof c.path=="string"):void 0,a=p(i,"path");if(!a)throw new Error("Migrated config does not contain a workspace path");await E(),await A({configPath:e,dataDir:o,workspacePath:a,serviceCommandPath:r.wrapperPath,path:s}),await b(),await N(t)}async function X(t,r,e,s,n={}){return Y(t,r,e,s,{...n,platform:"darwin"})}async function Y(t,r,e,s,n={}){const o=n.run??y,i=n.wait??U,a=n.attempts??1200,c=n.platform??process.platform;if(c!=="darwin"&&c!=="linux")throw new Error("Only Linux and macOS are supported");const f=P(t.paths.rootDir,"migration-handoff.json"),u=c==="darwin"?`${x}.${process.pid}`:`messenger-agent-migration-${process.pid}`;c==="darwin"&&await $(o,[],void 0,!0),await l(f,{schemaVersion:1,status:"scheduled",helperLabel:u,migration:t,runtime:r,configPath:e,...s?{path:s}:{},updatedAt:new Date().toISOString()});try{c==="darwin"?await o("launchctl",["submit","-l",u,"--",r.cliWrapperPath,"complete-migration","--handoff",f]):await o("systemd-run",["--user","--quiet","--collect","--unit",u,"--",r.cliWrapperPath,"complete-migration","--handoff",f])}catch(d){throw await l(f,{...await m(f),status:"failed",message:d instanceof Error?d.message:String(d),updatedAt:new Date().toISOString()}),d}for(let d=0;d<a;d+=1){const h=await m(f);if(h.status==="completed")return c==="darwin"&&await o("launchctl",["remove",u],{allowFailure:!0}),!0;if(h.status==="failed")throw new Error(h.message??"Service migration failed");await i(100)}throw new Error(`Timed out waiting for service migration; inspect ${f}`)}async function yt(t,r){try{const e=await m(P(t,"migration-handoff.json"));return e.status!=="completed"&&e.runtime.version!==r}catch(e){if(e.code==="ENOENT")return!0;throw e}}async function vt(t,r={}){const e=await m(t),s=r.run??y;if(e.status==="completed"||e.status==="failed"){await v(e,s,r.activeHelperLabel);return}await l(t,{...e,status:"running",updatedAt:new Date().toISOString()});try{await(r.activate??T)(e.migration,e.runtime,e.configPath,e.path),await l(t,{...e,status:"completed",updatedAt:new Date().toISOString()}),await v(e,s,r.activeHelperLabel)}catch(n){const o=[];await(r.rollback??g)(e.runtime).catch(a=>{o.push(`runtime rollback failed: ${String(a)}`)}),await(r.uninstall??M)().catch(a=>{o.push(`new service cleanup failed: ${String(a)}`)}),await(r.startLegacy??D)().catch(a=>{o.push(`legacy service restart failed: ${String(a)}`)});const i=[n instanceof Error?n.message:String(n),...o].join("; ");throw await l(t,{...e,status:"failed",message:i,updatedAt:new Date().toISOString()}),await v(e,s,r.activeHelperLabel),n}}async function v(t,r=y,e=process.env.XPC_SERVICE_NAME){await $(r,[t.helperLabel],e)}async function $(t,r=[],e,s=!1){const n=new Set(r.filter(k));if(e&&k(e)&&n.add(e),n.size===0&&!s)return;if(s||n.size>0){const i=await t("launchctl",["list"],{allowFailure:!0,logCommand:!1}).catch(()=>{});for(const a of i?.stdout.split(`
|
|
2
|
+
`)??[]){const c=a.trim().split(/\s+/).at(-1);c&&k(c)&&n.add(c)}}const o=[...n].filter(i=>i!==e);e&&n.has(e)&&o.push(e);for(const i of o)await t("launchctl",["remove",i],{allowFailure:!0}).catch(()=>{})}function k(t){return t.startsWith(`${x}.`)}async function m(t){const r=JSON.parse(await L(t,"utf8"));if(r.schemaVersion!==1||!r.migration||!r.runtime||typeof r.configPath!="string"||typeof r.helperLabel!="string"||r.status!=="scheduled"&&r.status!=="running"&&r.status!=="completed"&&r.status!=="failed")throw new Error(`Invalid Messenger Agent migration handoff: ${t}`);return r}async function l(t,r){const e=`${t}.${process.pid}.tmp`;await W(e,`${JSON.stringify(r,null,2)}
|
|
3
|
+
`,{mode:384}),await j(e,t)}function K(t=process.platform){if(t!=="linux"&&t!=="darwin")throw new Error("Only Linux and macOS are supported")}function Q(t=process.versions.node){const r=/^(\d+)\.(\d+)\.(\d+)(?:[.-]|$)/.exec(t),e=Number(r?.[1]),s=Number(r?.[2]);if(!(e>22||e===22&&s>=19))throw new Error("Node.js 22.19.0 or newer is required")}function tt(t){if(t.server)try{z(t.server)}catch{throw new Error("--server must be a valid HTTP or HTTPS server address")}if(t.tunnelId&&!/^[A-Za-z0-9._:-]+$/.test(t.tunnelId))throw new Error("--tunnel-id may only contain letters, numbers, '.', '_', ':', and '-'");if(t.workspaceId&&!/^[A-Za-z0-9._:-]+$/.test(t.workspaceId))throw new Error("--workspace-id may only contain letters, numbers, '.', '_', ':', and '-'");if(t.workspaceName&&(t.workspaceName.trim().length===0||t.workspaceName.trim().length>128))throw new Error("--workspace-name must be between 1 and 128 characters")}async function et(t,r=!1){r&&await C(t,{recursive:!0});const e=await H(t);if(!(await R(e)).isDirectory())throw new Error("--workspace must point to an existing directory");return e}async function kt(t){K(),Q();const r=B(),e=q(),n=t.configPath===r.configPath||t.configPath===e.configPath?await J():void 0;let o;try{const i=n?{...t,configPath:t.configPath===n.legacyPaths.configPath?n.paths.configPath:t.configPath,dataDir:t.dataDir===n.legacyPaths.dataDir?n.paths.dataDir:t.dataDir}:t,a=await rt(i);tt(a);const c=await et(a.workspace,a.createWorkspace);await F({configPath:a.configPath,dataDir:a.dataDir,workspacePath:c,workspaceId:a.workspaceId,workspaceName:a.workspaceName,tunnelId:a.tunnelId,token:a.token,server:a.server,serverUrl:a.serverUrl,preserveWorkspaces:a.preserveWorkspaces,path:process.env.PATH}),t.channel&&await G(a.configPath,t.channel),o=await V({version:"current",configPath:a.configPath,server:a.server,runtimeDir:n?.paths.runtimeDir,binDir:n?.paths.binDir,path:process.env.PATH,hostArtifactDirectory:process.env.MESSENGER_AGENT_BOOTSTRAP_HOST_DIR,clientDirectory:process.env.MESSENGER_AGENT_BOOTSTRAP_CLIENT_DIR}),n?.migrated&&await E();const f=await A({configPath:a.configPath,dataDir:a.dataDir,workspacePath:c,serviceCommandPath:o.wrapperPath,path:process.env.PATH});return n?.migrated&&(await b(),await N(n)),{configPath:a.configPath,dataDir:a.dataDir,workspacePath:c,runtime:o,service:f}}catch(i){throw o&&await g(o).catch(()=>{}),n?.migrated&&await O(n),i}}async function O(t){await M().catch(()=>{}),await Z(t),await D().catch(()=>{})}async function rt(t){const r=await S(t.configPath),e=nt(r,"tunnel"),s=t.server??p(r,"server"),n=t.tunnelId??p(e,"tunnel_id"),o=t.token??p(e,"token"),i=at(r,t.workspaceId,n),a=t.workspace??i?.path??I,c=t.workspaceId??i?.id??_(),f=t.workspaceName??i?.name??(n?`${n} Default`:void 0),u=a===I;if(!n)throw new w("Missing required option: --tunnel-id");if(!o)throw new w("Missing required option: --token");if(!c)throw new w("Missing required option: --workspace-id");if(!f)throw new w("Missing required option: --workspace-name");return{...t,server:s,tunnelId:n,token:o,workspace:a,workspaceId:c,workspaceName:f,preserveWorkspaces:!t.workspace&&!!i,createWorkspace:u}}function at(t,r,e){const s=t.workspaces;if(!Array.isArray(s))return;const n=s.filter(a=>!!a&&typeof a=="object"&&!Array.isArray(a)&&typeof a.path=="string");if(r){const a=n.find(c=>c.id===r);return!a||typeof a.path!="string"?void 0:{id:r,name:typeof a.name=="string"&&a.name?a.name:`${e??r} Default`,path:a.path}}const o=r??(e?`${e}--default`:void 0),i=(o?n.find(a=>a.id===o):void 0)??n.find(a=>a.id==="default")??n[0];if(!(!i||typeof i.path!="string"))return{id:typeof i.id=="string"&&i.id?i.id:o??"default",name:typeof i.name=="string"&&i.name?i.name:`${e??o??"default"} Default`,path:i.path}}function nt(t,r){const e=t[r];if(!(!e||typeof e!="object"||Array.isArray(e)))return e}function p(t,r){const e=t?.[r];return typeof e=="string"&&e?e:void 0}export{gt as activateMigratedService,Q as assertNodeVersion,K as assertSupportedPlatform,vt as completeMigrationHandoff,kt as installClient,rt as resolveInstallArgs,et as resolveWorkspacePath,X as scheduleDarwinMigrationHandoff,Y as scheduleMigrationHandoff,yt as shouldAttemptAutomaticMigration,tt as validateInstallArgs};
|
package/dist/runtime.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type RuntimeInstallOptions = {
|
|
|
10
10
|
platform?: NodeJS.Platform;
|
|
11
11
|
arch?: NodeJS.Architecture;
|
|
12
12
|
registryUrl?: string;
|
|
13
|
+
server?: string;
|
|
14
|
+
nodeHostMirrorUrl?: string;
|
|
13
15
|
hostArtifactDirectory?: string;
|
|
14
16
|
clientDirectory?: string;
|
|
15
17
|
};
|
|
@@ -57,6 +59,8 @@ export declare function defaultAgentHomes(): [string, string];
|
|
|
57
59
|
export declare function installRuntime(options: RuntimeInstallOptions): Promise<RuntimeInstallResult>;
|
|
58
60
|
export declare function rollbackRuntime(result: RuntimeInstallResult): Promise<void>;
|
|
59
61
|
export declare function nodeHostPackageName(platform: "linux" | "darwin", arch: "x64" | "arm64"): string;
|
|
62
|
+
export declare function nodeHostMirrorTarballUrl(platform: "linux" | "darwin", arch: "x64" | "arm64", version: string, mirrorUrl?: string): string;
|
|
63
|
+
export declare function resolveNodeHostMirrorUrl(server?: string, configuredMirrorUrl?: string | undefined): string;
|
|
60
64
|
export declare function resolveChannelPackageVersion(channel: ReleaseChannel, registryUrl?: string): Promise<string>;
|
|
61
65
|
export declare function syncBundledSkills(skillsSourceDir: string, agentHomes: string[]): Promise<void>;
|
|
62
66
|
export {};
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{createHash as
|
|
2
|
-
`),x=["#!/bin/sh","set -eu",`export AGENT_CONFIG_PATH=${
|
|
3
|
-
`);await N(M,g,{mode:448}),await N(
|
|
1
|
+
import{createHash as se}from"node:crypto";import{createReadStream as ce,createWriteStream as le}from"node:fs";import{access as ue,cp as j,lstat as Z,mkdir as E,readFile as S,readlink as fe,rename as k,rm as y,symlink as de,writeFile as N}from"node:fs/promises";import{homedir as q}from"node:os";import{basename as me,delimiter as we,dirname as A,isAbsolute as G,join as i,relative as pe,resolve as v}from"node:path";import{Readable as he}from"node:stream";import{pipeline as ge}from"node:stream/promises";import{fileURLToPath as Q}from"node:url";import{normalizeOptional as ye,resolveAgentBridgeUrls as $e}from"@messenger-agent/shared/agent-config";import{runCommand as P}from"./exec.js";import{cliName as ve,legacyCliName as Ee,runtimePackageScope as ke}from"./identity.js";import{defaultBinDir as Ne,defaultRuntimeDir as Pe,legacyCodingAgentPaths as xe,messengerAgentPaths as be}from"./paths.js";const O="https://registry.npmjs.org",I="@messenger-agent/client",ar=["latest","beta","alpha"];function ir(e){if(!(e==null||e==="")){if(e==="stable")return"latest";if(e==="latest"||e==="beta"||e==="alpha")return e;throw new Error(`Unknown release channel: ${String(e)} (expected latest, beta, or alpha)`)}}function W(e){return e==="stable"?"latest":e==="latest"||e==="beta"||e==="alpha"?e:void 0}function or(e,r){const t=W(e),n=r??t;return{version:t?n??t:e,channel:n}}function sr(e){return/^\d+\.\d+\.\d+-/.test(e)}function cr(e,r){const[t]=e.split("+",1),[n]=r.split("+",1),a=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(t??""),s=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(n??"");if(!a||!s)throw new Error(`Automatic upgrades require semantic versions, received: ${e} and ${r}`);for(let l=1;l<=3;l+=1){const c=Number(a[l])-Number(s[l]);if(c!==0)return Math.sign(c)}return De(a[4],s[4])}function De(e,r){if(!e&&!r)return 0;if(!e)return 1;if(!r)return-1;const t=e.split("."),n=r.split(".");for(let a=0;a<Math.max(t.length,n.length);a+=1){const s=t[a],l=n[a];if(s===void 0)return-1;if(l===void 0)return 1;const c=/^\d+$/.test(s),o=/^\d+$/.test(l);if(c&&o){const w=Number(s)-Number(l);if(w!==0)return Math.sign(w);continue}if(c)return-1;if(o)return 1;if(s!==l)return s<l?-1:1}return 0}async function Re(){const e=i(A(Q(import.meta.url)),"..","package.json");return JSON.parse(await S(e,"utf8")).version??"latest"}function lr(e=import.meta.url){const r=A(Q(e));return me(r)==="src"?i(r,"..","assets","skills"):i(r,"assets","skills")}function Se(){return[process.env.CODEX_HOME??i(q(),".codex"),process.env.CLAUDE_CONFIG_DIR??i(q(),".claude")]}async function m(e){await y(e,{recursive:!0,force:!0})}async function V(e,r){const t=`${r}.tmp-${process.pid}`;await m(t),await de(e,t,"dir"),await k(t,r)}async function z(e){try{return(await Z(e)).isSymbolicLink()}catch{return!1}}async function ur(e){const r=Ae(e.configPath),t=e.runtimeDir??r?.runtimeDir??Pe,n=e.binDir??r?.binDir??Ne,a=Ie(e.platform??process.platform),s=We(e.arch??process.arch),l=W(e.version),c=e.version==="current"?await Re():l?await Me(l,e.registryUrl):e.version,o=await Ue({runtimeDir:t,platform:a,arch:s,registryUrl:e.registryUrl,mirrorUrl:ee(e.server,e.nodeHostMirrorUrl),artifactDirectory:e.hostArtifactDirectory}),w=c.replaceAll("/","_").replaceAll(":","_"),p=i(t,"releases"),u=i(p,w),h=i(t,"current"),D=i(u,"node_modules","@messenger-agent","client","dist","index.js"),d=i(u,"node_modules","@messenger-agent","client","package.json"),_=e.skillsSourceDir??i(u,"node_modules","@messenger-agent","client","dist","assets","skills"),M=i(n,"messenger-agent-service"),U=i(n,"coding-agent-client-service"),T=i(n,ve),L=i(n,Ee),ae=[M,U,T,L];if(await E(p,{recursive:!0,mode:448}),await E(n,{recursive:!0,mode:448}),!(await F(d,c)&&(await X(o.nodeExecutable,D)).status===0)){const f=`${u}.tmp-${process.pid}`,R=i(f,"node_modules","@messenger-agent","client","dist","index.js");await m(f),await E(f,{recursive:!0,mode:448});try{if(e.clientDirectory&&await F(i(e.clientDirectory,"node_modules","@messenger-agent","client","package.json"),c))await j(e.clientDirectory,f,{recursive:!0});else{const x=i(f,".npmrc");await N(x,""),await P(o.nodeExecutable,[o.npmCli,"install","--prefix",f,"--omit=dev","--include=optional","--ignore-scripts","--no-audit","--no-fund","--registry",e.registryUrl??process.env.MESSENGER_AGENT_NPM_REGISTRY??O,"--userconfig",x,`${I}@${c}`],{env:{PATH:Le(o.nodeExecutable,e.path)},cwd:f})}if(!await F(i(f,"node_modules","@messenger-agent","client","package.json"),c))throw new Error(`Installed Messenger Agent Client does not match ${c}`);const g=await X(o.nodeExecutable,R);if(g.status!==0)throw new Error(`Messenger Agent Client self-check failed: ${g.stderr||g.stdout}`);await m(u),await k(f,u)}catch(g){throw await m(f),g}}const[ie,oe]=Se();await Ve(_,[e.codexHome??ie,e.claudeHome??oe]);const J=await ne(h),B=await ne(o.currentLink),Y=await Promise.all(ae.map(async f=>({path:f,content:await He(f)})));await z(h)||await m(h),await z(o.currentLink)||await m(o.currentLink);try{await V(o.releaseDir,o.currentLink),await V(u,h);const f=b(o.currentLink,o.manifest.node),R=i(h,"node_modules","@messenger-agent","client","dist","index.js"),g=["#!/bin/sh","set -eu",...e.path?[`export PATH=${$(e.path)}`]:[],`export AGENT_CONFIG_PATH=${$(e.configPath)}`,`exec ${$(f)} ${$(R)} run-service --config ${$(e.configPath)}`,""].join(`
|
|
2
|
+
`),x=["#!/bin/sh","set -eu",`export AGENT_CONFIG_PATH=${$(e.configPath)}`,`exec ${$(f)} ${$(R)} "$@"`,""].join(`
|
|
3
|
+
`);await N(M,g,{mode:448}),await N(U,g,{mode:448}),await N(T,x,{mode:448}),await N(L,x,{mode:448})}catch(f){throw await H(J,h),await H(B,o.currentLink),await K(Y),f}return{releaseDir:u,currentLink:h,wrapperPath:M,legacyServiceWrapperPath:U,cliWrapperPath:T,legacyCliWrapperPath:L,version:c,previousReleaseDir:J,hostCurrentLink:o.currentLink,previousHostReleaseDir:B,previousWrappers:Y}}async function X(e,r){return P(e,[r,"self-check"],{allowFailure:!0})}function Ae(e){const r=be();if(v(e)===v(r.configPath))return r;const t=xe();return v(e)===v(t.configPath)?t:void 0}async function fr(e){await H(e.previousReleaseDir,e.currentLink),await H(e.previousHostReleaseDir,e.hostCurrentLink),await K(e.previousWrappers)}async function H(e,r){e?await V(e,r):await m(r)}async function He(e){try{return await S(e,"utf8")}catch(r){if(r.code==="ENOENT")return;throw r}}async function K(e){await Promise.all(e.map(({path:r,content:t})=>t===void 0?m(r):N(r,t,{mode:448})))}function Ce(e,r){return`${ke}/node-host-${e}-${r}`}function _e(e,r,t,n=ee()){return`${n.replace(/\/$/,"")}/${e}/${r}/${encodeURIComponent(t)}.tgz`}function ee(e,r=process.env.MESSENGER_AGENT_NODE_HOST_MIRROR_URL){return(ye(r)??`${$e(e).server}/messenger/agent/node-host`).replace(/\/$/,"")}async function Me(e,r){return(await re(I,e,r)).version}async function Ue(e){const r=Ce(e.platform,e.arch),t=e.artifactDirectory?void 0:await je(r,"latest",e.registryUrl),a=(e.artifactDirectory?await te(i(e.artifactDirectory,"manifest.json"),{platform:e.platform,arch:e.arch}):void 0)?.version??t?.version;if(!a)throw new Error(`Unable to resolve ${r}`);const s=i(e.runtimeDir,"host"),l=i(s,"releases"),c=`${a}-${e.platform}-${e.arch}`.replaceAll("/","_").replaceAll(":","_"),o=i(l,c),w=i(s,"current"),p=i(o,"manifest.json");if(await E(l,{recursive:!0,mode:448}),!await C(p)){const d=`${o}.tmp-${process.pid}`;await m(d),await E(d,{recursive:!0,mode:448});try{e.artifactDirectory?await j(e.artifactDirectory,d,{recursive:!0}):t&&await Te(t,d,_e(e.platform,e.arch,t.version,e.mirrorUrl)),await m(o),await k(d,o)}catch(_){throw await m(d),_}}const u=await te(p,{version:a,platform:e.platform,arch:e.arch});await Oe(o,u);const h=b(o,u.node),D=b(o,u.npm);if(!await C(h)||!await C(D))throw new Error(`Node Host ${r}@${a} is incomplete`);if(u.platform==="darwin"){const d=i(o,"Messenger Agent.app");await P("codesign",["--verify","--deep","--strict",d]),await P("spctl",["--assess","--type","execute",d])}return{releaseDir:o,currentLink:w,nodeExecutable:h,npmCli:D,manifest:u}}async function Te(e,r,t){const n=`${r}.tgz`;try{const a=[];let s=!1;for(const l of new Set([t,e.tarball]))try{await y(n,{force:!0});const c=await fetch(l);if(!c.ok||!c.body)throw new Error(`HTTP ${c.status}`);await ge(he.fromWeb(c.body),le(n,{mode:384})),await Ge(n,e.integrity),s=!0;break}catch(c){a.push(`${l}: ${c instanceof Error?c.message:String(c)}`)}if(!s)throw new Error(`Unable to download ${e.packageName}@${e.version}: ${a.join("; ")}`);await P("tar",["-xzf",n,"-C",r,"--strip-components=2","package/host"])}finally{await y(n,{force:!0})}}async function F(e,r){try{const t=JSON.parse(await S(e,"utf8"));return t.name===I&&t.version===r}catch{return!1}}function Le(e,r=process.env.PATH){const t=A(e);return r?`${t}${we}${r}`:t}async function je(e,r,t=process.env.MESSENGER_AGENT_NPM_REGISTRY??O){const{metadata:n,version:a}=await re(e,r,t),s=n.versions?.[a]?.dist;if(!s?.tarball||!s.integrity)throw new Error(`Registry returned incomplete artifact metadata for ${e}@${a}`);return{packageName:e,version:a,tarball:s.tarball,integrity:s.integrity}}async function re(e,r,t=process.env.MESSENGER_AGENT_NPM_REGISTRY??O){const n=`${t.replace(/\/$/,"")}/${encodeURIComponent(e)}`,a=await fetch(n,{headers:{accept:"application/json"}});if(!a.ok)throw new Error(`Unable to resolve ${e}: HTTP ${a.status}`);const s=await a.json(),l=W(r)?s["dist-tags"]?.[r]:r;if(!l)throw new Error(`Registry has no ${r} release for ${e}`);return{metadata:s,version:l}}async function Ge(e,r){const t=r.indexOf("-");if(t<=0)throw new Error("Node Host has an invalid integrity value");const n=r.slice(0,t),a=r.slice(t+1),s=se(n);for await(const l of ce(e))s.update(l);if(s.digest("base64")!==a)throw new Error("Node Host integrity verification failed")}async function te(e,r){const t=JSON.parse(await S(e,"utf8"));if(t.schemaVersion!==1||t.product!=="messenger-agent-node-host"||r.version!==void 0&&t.version!==r.version||typeof t.version!="string"||typeof t.nodeVersion!="string"||t.platform!==r.platform||t.arch!==r.arch||typeof t.node!="string"||typeof t.npm!="string"||t.payload!==void 0&&typeof t.payload!="string")throw new Error(`Node Host manifest does not match ${r.platform}-${r.arch}${r.version?`@${r.version}`:""}`);return t}async function Oe(e,r){if(!r.payload)return;const t=b(e,r.node);if(await C(t))return;if(r.platform!=="darwin")throw new Error("Only macOS Node Hosts may contain a zip payload");const n=b(e,r.payload);await P("ditto",["-x","-k",n,e])}function b(e,r){if(!r||G(r))throw new Error(`Node Host contains an unsafe path: ${r}`);const t=v(e),n=v(e,r),a=pe(t,n);if(a.startsWith("..")||G(a))throw new Error(`Node Host contains an unsafe path: ${r}`);return n}function Ie(e){if(e==="linux"||e==="darwin")return e;throw new Error(`No Messenger Agent runtime is available for platform: ${e}`)}function We(e){if(e==="x64"||e==="arm64")return e;throw new Error(`No Messenger Agent runtime is available for architecture: ${e}`)}async function ne(e){if(!await z(e))return;const r=await fe(e);return G(r)?r:v(A(e),r)}async function C(e){try{return await ue(e),!0}catch{return!1}}async function Ve(e,r){const t="manage-messenger-agent",n="manage-coding-agent-client",a=i(e,t),s=await ze(a);for(const l of new Set(r)){const c=i(l,"skills"),o=i(c,t),w=i(c,`.${t}.tmp-${process.pid}`),p=i(c,`.${t}.old-${process.pid}`);if(await y(w,{recursive:!0,force:!0}),await y(p,{recursive:!0,force:!0}),await y(i(c,n),{recursive:!0,force:!0}),!s){await y(o,{recursive:!0,force:!0});continue}await E(c,{recursive:!0,mode:448}),await j(a,w,{recursive:!0}),await k(o,p).catch(u=>{if(u.code!=="ENOENT")throw u});try{await k(w,o),await y(p,{recursive:!0,force:!0})}catch(u){throw await k(p,o).catch(()=>{}),u}}}async function ze(e){try{return(await Z(e)).isDirectory()}catch(r){if(r.code==="ENOENT")return!1;throw r}}function $(e){return`'${e.replaceAll("'","'\\''")}'`}export{cr as compareSemverVersions,lr as currentBundledSkillsDir,Re as currentPackageVersion,Se as defaultAgentHomes,ur as installRuntime,sr as isPrereleaseVersion,_e as nodeHostMirrorTarballUrl,Ce as nodeHostPackageName,ir as normalizeReleaseChannel,or as normalizeUpgradeVersion,W as parseReleaseChannel,ar as releaseChannels,Me as resolveChannelPackageVersion,ee as resolveNodeHostMirrorUrl,fr as rollbackRuntime,Ve as syncBundledSkills};
|
package/dist/supervisor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { readClientPath } from "./config-file.js";
|
|
2
|
+
import { readAgentServer, readClientPath } from "./config-file.js";
|
|
3
3
|
import { currentPackageVersion, installRuntime, rollbackRuntime } from "./runtime.js";
|
|
4
4
|
import { migrateLegacyClient } from "./migration.js";
|
|
5
5
|
import { scheduleMigrationHandoff, shouldAttemptAutomaticMigration } from "./install.js";
|
|
@@ -55,4 +55,5 @@ export declare function migrateLegacyServiceAtStartup(configPath: string, depend
|
|
|
55
55
|
handoff?: typeof scheduleMigrationHandoff;
|
|
56
56
|
rollback?: typeof rollbackRuntime;
|
|
57
57
|
readPath?: typeof readClientPath;
|
|
58
|
+
readServer?: typeof readAgentServer;
|
|
58
59
|
}): Promise<boolean>;
|
package/dist/supervisor.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as b}from"node:child_process";import{randomUUID as M}from"node:crypto";import{createRequire as k}from"node:module";import{dirname as h,join as f,resolve as w}from"node:path";import{parse as C}from"yaml";import{readFile as E,unlink as y}from"node:fs/promises";import{readAgentServer as v,readClientPath as A,readUpgradeChannel as I,writeClientPath as $}from"./config-file.js";import{readControlSocketPath as L,startControlServer as N}from"./control.js";import{MaintenanceScheduler as F}from"./maintenance.js";import{currentBundledSkillsDir as O,currentPackageVersion as R,defaultAgentHomes as D,installRuntime as P,rollbackRuntime as S,syncBundledSkills as G}from"./runtime.js";import{launchdLabel as _,serviceCommandsForConfig as j,serviceName as B}from"./service.js";import{legacyLaunchdLabel as q,legacyServiceName as U}from"./identity.js";import{legacyCodingAgentPaths as T}from"./paths.js";import{runCommand as u}from"./exec.js";import{AutoUpgradeScheduler as H}from"./auto-upgrade.js";import{migrateLegacyClient as K}from"./migration.js";import{scheduleMigrationHandoff as Y,shouldAttemptAutomaticMigration as V}from"./install.js";import{isAgentActivityResponse as W}from"@messenger-agent/shared/agent-activity";const g=k(import.meta.url);function X(){return[{name:"codex",entry:g.resolve("@messenger-agent/codex-agent")},{name:"claude",entry:g.resolve("@messenger-agent/claude-agent")},{name:"workspace",entry:g.resolve("@messenger-agent/messenger-agent")}]}function z(i,t){let e=i;for(const r of t){if(!e||typeof e!="object"||Array.isArray(e))return;e=e[r]}return e}async function J(i){const t=C(await E(i,"utf8")),e=z(t,["workspaces"]);if(Array.isArray(e)){const r=e.find(s=>!!s&&typeof s=="object"&&!Array.isArray(s)&&typeof s.path=="string");if(typeof r?.path=="string"&&r.path.trim())return r.path}return h(i)}class Q{options;stopping=!1;running;restartBaseMs;restartMaxMs;constructor(t){this.options=t,this.running=(t.agents??X()).map(e=>({definition:e,restartAttempts:0})),this.restartBaseMs=t.restartBaseMs??1e3,this.restartMaxMs=t.restartMaxMs??3e4}start(){for(const t of this.running)this.startAgent(t)}async stop(){this.stopping=!0;for(const t of this.running)t.restartTimer&&clearTimeout(t.restartTimer),t.process?.kill("SIGTERM");await Promise.all(this.running.map(t=>t.process).filter(t=>!!t&&t.exitCode===null&&!t.killed).map(t=>new Promise(e=>{const r=setTimeout(()=>{t.kill("SIGKILL"),e()},8e3);t.once("exit",()=>{clearTimeout(r),e()})})))}restartAgent(t){const e=this.running.find(({definition:r})=>r.name===t);return e?(e.restartPromise||(e.restartPromise=this.restartAgentProcess(e).finally(()=>{e.restartPromise=void 0})),e.restartPromise):Promise.reject(new Error(`Agent is not managed by this client: ${t}`))}async activityStatus(t=1e3){const[e,r]=await Promise.all([this.agentActivityStatus("codex",t),this.agentActivityStatus("claude",t)]),s=[e,r].filter(a=>a.available);return{active:s.reduce((a,n)=>a+n.active,0),waiting:s.reduce((a,n)=>a+n.waiting,0),agents:{codex:e,claude:r}}}agentActivityStatus(t,e){const r=this.running.find(({definition:s})=>s.name===t)?.process;return!r||!r.connected||!r.send?Promise.resolve({available:!1,error:`${t} agent is not connected`}):new Promise(s=>{const a=M(),n={type:"client.activity.request",requestId:a};let o=!1;const l=c=>{o||(o=!0,clearTimeout(x),r.off("message",m),s(c))},m=c=>{!W(c)||c.requestId!==a||c.agent!==t||l({available:!0,...c.snapshot})},x=setTimeout(()=>l({available:!1,error:`${t} agent did not respond`}),e);r.on("message",m),r.send(n,c=>{c&&l({available:!1,error:c.message})})})}async restartAgentProcess(t){t.restartTimer&&(clearTimeout(t.restartTimer),t.restartTimer=void 0);const e=t.process;if(e&&e.exitCode===null&&!e.killed&&(e.kill("SIGTERM"),await rt(e)),this.stopping)throw new Error("Client service is stopping");t.restartAttempts=0,this.startAgent(t)}startAgent(t){const e={...process.env,AGENT_CONFIG_PATH:this.options.configPath};t.definition.name==="workspace"&&(delete e.OPENAI_API_KEY,delete e.CODEX_API_KEY,delete e.ANTHROPIC_API_KEY);const r=(this.options.spawnProcess??b)(process.execPath,[t.definition.entry],{cwd:this.options.workspacePath,env:e,stdio:["inherit","inherit","inherit","ipc"]});t.process=r,t.definition.name==="workspace"&&r.on("message",s=>{s&&typeof s=="object"&&"type"in s&&s.type==="client.workspaces.changed"&&Promise.all([this.restartAgent("codex"),this.restartAgent("claude")]).catch(a=>{console.error("[client] failed to reload agents after workspace configuration changed",a)})}),console.log(`[client] started ${t.definition.name}-agent pid=${r.pid}`),r.once("exit",(s,a)=>{if(t.process=void 0,this.stopping||t.restartPromise)return;const n=Math.min(this.restartBaseMs*2**t.restartAttempts,this.restartMaxMs);t.restartAttempts+=1,console.error(`[client] ${t.definition.name}-agent exited with code=${s??"null"} signal=${a??"null"}; restarting in ${n}ms`),t.restartTimer=setTimeout(()=>{t.restartTimer=void 0,this.startAgent(t)},n)})}}async function Pt(i){if(await Z(i))return;await G(O(),D());const t=await J(i),e=new Q({configPath:i,workspacePath:t}),r=await L(i),s=new F({statePath:f(h(r),"maintenance.json"),getActivity:()=>e.activityStatus(),execute:(l,m)=>tt(l,i,e,m)});await s.start();const a=new H({statePath:f(h(r),"auto-upgrade.json"),maintenance:s,getChannel:()=>I(i)});await a.start();const n=await N(r,{restartAgent:l=>e.restartAgent(l),getActivity:()=>e.activityStatus(),maintenance:s});e.start();const o=async()=>{a.stop(),s.stop(),await n.close(),await e.stop(),process.exit(0)};process.once("SIGINT",()=>{o()}),process.once("SIGTERM",()=>{o()})}async function Z(i,t={}){const e=T();if(w(i)!==w(e.configPath))return!1;const r=await(t.currentVersion??R)();if(!await(t.shouldAttempt??V)(e.rootDir,r))return!1;let s;try{const a=await(t.migrate??K)();if(!a.migrated)return!1;const n=await(t.readPath??A)(a.paths.configPath),o=await(t.readServer??v)(a.paths.configPath);return s=await(t.install??P)({version:r,configPath:a.paths.configPath,runtimeDir:a.paths.runtimeDir,binDir:a.paths.binDir,path:n,server:o}),await(t.handoff??Y)(a,s,a.paths.configPath,n),!0}catch(a){return s&&await(t.rollback??S)(s).catch(()=>{}),console.error(`[client] automatic legacy migration failed: ${a instanceof Error?a.message:String(a)}`),!1}}async function tt(i,t,e,r){if(i.type==="upgrade"){i.path&&await $(t,i.path);const s=await P({version:i.version,configPath:t,server:await v(t),path:i.path??await A(t)});await r("restarting");try{await d(p(t).restart)}catch(a){throw await S(s),await d(p(t).restart).catch(()=>{}),a}return}if(i.type==="restart"&&i.agent){await e.restartAgent(i.agent);return}if(i.type==="restart"){await r("restarting"),await d(p(t).restart);return}if(i.type==="stop"){await r("stopping"),await d(p(t).stop);return}await r("stopping"),await et(t)}function p(i){return j(i)}async function d(i){const t=await u("/bin/sh",["-lc",i],{allowFailure:!0});if(t.status!==0)throw new Error(t.stderr||t.stdout||`Service command failed: ${i}`)}async function et(i){const t=process.env.HOME??"",e=i===T().configPath,r=e?U:B,s=e?q:_;if(process.platform==="linux"){await u("systemctl",["--user","disable",`${r}.service`],{allowFailure:!0}),await y(f(t,".config","systemd","user",`${r}.service`)).catch(a=>{if(a.code!=="ENOENT")throw a}),await u("systemctl",["--user","daemon-reload"],{allowFailure:!0}),await u("systemctl",["--user","stop",`${r}.service`],{allowFailure:!0});return}if(process.platform==="darwin"){const a=process.getuid?.();if(a===void 0)throw new Error("Unable to determine current uid for launchctl");const n=f(t,"Library","LaunchAgents",`${s}.plist`);await y(n).catch(o=>{if(o.code!=="ENOENT")throw o}),await u("launchctl",["bootout",`gui/${a}/${s}`],{allowFailure:!0});return}throw new Error("Only Linux and macOS are supported")}function rt(i){return new Promise(t=>{const e=setTimeout(()=>{i.kill("SIGKILL")},8e3);i.once("exit",()=>{clearTimeout(e),t()})})}export{Q as AgentSupervisor,Z as migrateLegacyServiceAtStartup,J as readWorkspacePathFromConfig,X as resolveAgentEntries,Pt as runSupervisor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@messenger-agent/client",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"cac": "^7.0.0",
|
|
23
23
|
"yaml": "^2.9.0",
|
|
24
|
-
"@messenger-agent/
|
|
25
|
-
"@messenger-agent/
|
|
26
|
-
"@messenger-agent/
|
|
27
|
-
"@messenger-agent/
|
|
24
|
+
"@messenger-agent/messenger-agent": "0.33.1-alpha.0",
|
|
25
|
+
"@messenger-agent/claude-agent": "0.33.1-alpha.0",
|
|
26
|
+
"@messenger-agent/shared": "0.33.1-alpha.0",
|
|
27
|
+
"@messenger-agent/codex-agent": "0.33.1-alpha.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "rm -rf dist && tsc -p tsconfig.json && node ../../scripts/copy-client-assets.mjs && chmod +x dist/index.js",
|