@agimon-ai/foundation-process-registry 0.2.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/LICENSE +52 -0
- package/dist/ProcessRegistryService.cjs +2 -0
- package/dist/ProcessRegistryService.cjs.map +1 -0
- package/dist/ProcessRegistryService.mjs +2 -0
- package/dist/ProcessRegistryService.mjs.map +1 -0
- package/dist/cli.cjs +4 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +11 -0
- package/dist/cli.d.mts +11 -0
- package/dist/cli.mjs +4 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +164 -0
- package/dist/index.d.mts +164 -0
- package/dist/index.mjs +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
|
|
5
|
+
Licensor: AgiFlow
|
|
6
|
+
Licensed Work: @agimon-ai/public-packages
|
|
7
|
+
The Licensed Work is (c) 2026 AgiFlow.
|
|
8
|
+
Additional Use Grant: None
|
|
9
|
+
Change Date: 2030-03-06
|
|
10
|
+
Change License: Apache License, Version 2.0
|
|
11
|
+
|
|
12
|
+
Terms
|
|
13
|
+
|
|
14
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
15
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
16
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
17
|
+
production use.
|
|
18
|
+
|
|
19
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
20
|
+
available distribution of a specific version of the Licensed Work under this
|
|
21
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
22
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
23
|
+
above terminate.
|
|
24
|
+
|
|
25
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
26
|
+
currently in effect as described in this License, you must purchase a
|
|
27
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
28
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
29
|
+
|
|
30
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
31
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
32
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
33
|
+
for each version of the Licensed Work released by Licensor.
|
|
34
|
+
|
|
35
|
+
You must conspicuously display this License on each original or modified copy
|
|
36
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
37
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
38
|
+
License apply to your use of that work.
|
|
39
|
+
|
|
40
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
41
|
+
terminate your rights under this License for the current and all other
|
|
42
|
+
versions of the Licensed Work.
|
|
43
|
+
|
|
44
|
+
This License does not grant you any right in any trademark or logo of
|
|
45
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
46
|
+
Licensor as expressly required by this License).
|
|
47
|
+
|
|
48
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
49
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
52
|
+
TITLE.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:path`);c=s(c);let l=require(`node:crypto`),u=require(`node:fs/promises`);u=s(u);let d=require(`zod`),f=require(`node:os`);f=s(f);let p=require(`@agimon-ai/foundation-port-registry`);const m=1,h=d.z.enum([`service`,`tool`]),g=d.z.record(d.z.string(),d.z.unknown()),_=d.z.object({repositoryPath:d.z.string().trim().min(1,`repositoryPath is required`),serviceName:d.z.string().trim().min(1,`serviceName is required`),serviceType:h,environment:d.z.string().trim().min(1).optional(),pid:d.z.number().int().min(1),port:d.z.number().int().min(1).max(65535).optional(),host:d.z.string().trim().min(1).optional(),command:d.z.string().trim().min(1).optional(),args:d.z.array(d.z.string()).optional(),metadata:g.optional(),createdAt:d.z.string().trim().min(1),updatedAt:d.z.string().trim().min(1)}),v=d.z.object({version:d.z.literal(1),updatedAt:d.z.string().trim().min(1),entries:d.z.array(_)}),y=d.z.object({repositoryPath:d.z.string().trim().min(1),serviceName:d.z.string().trim().min(1),serviceType:h.default(`service`),environment:d.z.string().trim().min(1).optional(),pid:d.z.number().int().min(1),port:d.z.number().int().min(1).max(65535).optional(),host:d.z.string().trim().min(1).optional(),command:d.z.string().trim().min(1).optional(),args:d.z.array(d.z.string()).optional(),metadata:g.optional(),force:d.z.boolean().optional()}),b=d.z.object({repositoryPath:d.z.string().trim().min(1),serviceName:d.z.string().trim().min(1),serviceType:h.optional(),pid:d.z.number().int().min(1).optional(),environment:d.z.string().trim().min(1).optional(),force:d.z.boolean().optional(),kill:d.z.boolean().optional().default(!0),releasePort:d.z.boolean().optional().default(!0)}),x=d.z.object({repositoryPath:d.z.string().trim().min(1).optional(),serviceType:h.optional(),serviceName:d.z.string().trim().min(1).optional(),environment:d.z.string().trim().min(1).optional()}),S=d.z.object({success:d.z.boolean(),pid:d.z.number().int().min(1).optional(),record:_.optional(),error:d.z.string().optional()});var C=class extends Error{code;constructor(e,t,n){super(e,n),this.name=`ProcessRegistryError`,this.code=t}};const w=c.default.join(f.default.homedir(),`.process-registry`,`processes.json`),T=`${w}.lock`,E=75,D=80,O=e=>c.default.resolve(e),k=e=>`${e}.${(0,l.randomBytes)(6).toString(`hex`)}.tmp`;var A=class e{registryPath;lockPath;constructor(t=w,n,r=new p.PortRegistryService(process.env.PORT_REGISTRY_PATH)){this.portRegistry=r,this.registryPath=e.resolveRegistryPath(t),this.lockPath=n??`${this.registryPath}.lock`}static resolveRegistryPath(e){if(!e)return w;let t=c.default.isAbsolute(e)?e:c.default.join(process.cwd(),e);return c.default.extname(t)===`.json`?t:c.default.join(t,`processes.json`)}async registerProcess(e){let t=y.parse(e);return this.withLock(async()=>{let e=await this.loadState(),n=O(t.repositoryPath),r=t.serviceType??`service`,i=t.environment??process.env.NODE_ENV??`development`,a=await this.pruneState(e),o=this.findEntry(a,{repositoryPath:n,serviceName:t.serviceName,serviceType:r,environment:i});if(o){if(o.pid===t.pid)return o.updatedAt=new Date().toISOString(),o.port=t.port??o.port,o.host=t.host??o.host,o.command=t.command??o.command,o.args=t.args??o.args,o.metadata=t.metadata??o.metadata,await this.saveState(a),this.createSuccessResponse(t.pid,o);let e=this.isProcessRunning(o.pid);if(e&&!t.force)return this.createFailureResponse(`Process already registered for ${t.serviceName} in requested scope`);e&&await this.terminateProcess(o.pid),await this.releaseAssociatedPort(o),this.removeMatchingEntries(a,{repositoryPath:n,serviceName:t.serviceName,serviceType:r,environment:i})}let s=new Date().toISOString(),c={repositoryPath:n,serviceName:t.serviceName,serviceType:r,environment:i,pid:t.pid,port:t.port,host:t.host,command:t.command,args:t.args,metadata:t.metadata,createdAt:s,updatedAt:s};return a.entries.push(c),await this.saveState(a),this.createSuccessResponse(t.pid,c)})}async releaseProcess(e){let t=b.parse(e);return this.withLock(async()=>{let e=await this.loadState(),n=await this.pruneMissingRepositories(e),r=O(t.repositoryPath),i=t.serviceType??`service`,a=t.environment??process.env.NODE_ENV??`development`,o=n.entries.filter(e=>!(e.repositoryPath!==r||e.serviceName!==t.serviceName||e.serviceType!==i||t.environment&&e.environment!==a||typeof t.pid==`number`&&e.pid!==t.pid));if(o.length===0)return this.createFailureResponse(`No matching process entry for ${t.serviceName}`);let s=[],c=new Set;for(let e of o){let n=this.entryKey(e);try{(t.kill??!0)&&this.isProcessRunning(e.pid)&&await this.terminateProcess(e.pid),(t.releasePort??!0)&&await this.releaseAssociatedPort(e),c.add(n)}catch(t){s.push(`${e.serviceName} (pid ${e.pid}): ${t instanceof Error?t.message:String(t)}`)}}return c.size>0&&(n.entries=n.entries.filter(e=>!c.has(this.entryKey(e))),await this.saveState(n)),s.length>0?this.createFailureResponse(s.join(`; `)):this.createSuccessResponse()})}async listProcesses(e={}){let t=x.parse(e);return this.withLock(async()=>{let e=await this.loadState();return[...(await this.pruneState(e)).entries].filter(e=>!(t.repositoryPath&&e.repositoryPath!==O(t.repositoryPath)||t.serviceType&&e.serviceType!==t.serviceType||t.serviceName&&e.serviceName!==t.serviceName||t.environment&&e.environment!==t.environment))})}async withLock(e){let t=`${process.pid}-${(0,l.randomBytes)(6).toString(`hex`)}`;await this.acquireLock(t);try{return await e()}finally{await this.releaseLock(t)}}async loadState(){await u.default.mkdir(c.default.dirname(this.registryPath),{recursive:!0});try{let e=await u.default.readFile(this.registryPath,`utf-8`),t=JSON.parse(e);return v.parse(t)}catch(e){let t=e;if(t.code===`ENOENT`)return{version:1,updatedAt:new Date().toISOString(),entries:[]};if(t instanceof SyntaxError){let e=`${this.registryPath}.corrupt.${Date.now()}`;await u.default.rename(this.registryPath,e).catch(()=>void 0)}throw new C(`Failed to read registry file: ${e instanceof Error?e.message:String(e)}`,`REGISTRY_READ_FAILED`,{cause:e})}}async saveState(e){await u.default.mkdir(c.default.dirname(this.registryPath),{recursive:!0});let t={...e,updatedAt:new Date().toISOString(),entries:[...e.entries]},n=k(this.registryPath);await u.default.writeFile(n,JSON.stringify(t,null,2),`utf-8`),await u.default.rename(n,this.registryPath)}async pruneState(e){let t=await this.pruneMissingRepositories(e);return this.pruneDeadProcesses(t)}async pruneMissingRepositories(e){let t=(await Promise.all(e.entries.map(async e=>({entry:e,exists:await this.pathExists(e.repositoryPath)})))).filter(e=>e.exists).map(e=>e.entry);return t.length!==e.entries.length&&(e.entries=t,await this.saveState(e)),e}async pruneDeadProcesses(e){let t=[],n=!1;for(let r of e.entries){if(this.isProcessRunning(r.pid)){t.push(r);continue}n=!0,await this.releaseAssociatedPort(r)}return n&&(e.entries=t,await this.saveState(e)),e}async acquireLock(e){await u.default.mkdir(c.default.dirname(this.lockPath),{recursive:!0});for(let t=0;t<80;t+=1)try{let t={pid:process.pid,token:e,createdAt:new Date().toISOString()};await u.default.writeFile(this.lockPath,JSON.stringify(t),{flag:`wx`});return}catch(e){if(e.code!==`EEXIST`)throw new C(`Failed to acquire registry lock: ${e instanceof Error?e.message:String(e)}`,`REGISTRY_LOCK_FAILED`,{cause:e});if(await this.isStaleLock()){await u.default.unlink(this.lockPath).catch(()=>void 0),--t;continue}await this.delay(75)}throw new C(`Unable to acquire registry lock (timeout)`,`REGISTRY_LOCK_FAILED`)}async releaseLock(e){try{let t=await u.default.readFile(this.lockPath,`utf-8`);JSON.parse(t).token===e&&await u.default.unlink(this.lockPath)}catch{}}async isStaleLock(){try{let e=await u.default.readFile(this.lockPath,`utf-8`),t=JSON.parse(e);return t.pid&&this.isProcessRunning(t.pid)?(Date.now()-new Date(t.createdAt).getTime(),!1):!0}catch{return!0}}isProcessRunning(e){try{return process.kill(e,0),!0}catch{return!1}}async terminateProcess(e){try{process.kill(e,0)}catch{return}try{process.kill(e,`SIGTERM`)}catch(t){if(t.code===`ESRCH`)return;throw Error(`Failed to send SIGTERM to process ${e}: ${t instanceof Error?t.message:String(t)}`,{cause:t})}if(await this.delay(500),this.isProcessRunning(e)){try{process.kill(e,`SIGKILL`)}catch(t){if(t.code===`ESRCH`)return;throw Error(`Failed to send SIGKILL to process ${e}: ${t instanceof Error?t.message:String(t)}`,{cause:t})}if(await this.delay(250),this.isProcessRunning(e))throw Error(`Process ${e} did not exit after SIGKILL`)}}async releaseAssociatedPort(e){if(!(!this.portRegistry||!e.port))try{let t=await this.portRegistry.releasePort({repositoryPath:e.repositoryPath,serviceName:e.serviceName,serviceType:e.serviceType,environment:e.environment,pid:e.pid,force:!0});if(!t.success&&t.error&&!t.error.includes(`No matching registry entry`))throw Error(t.error)}catch{}}entryKey(e){return[e.repositoryPath,e.serviceName,e.serviceType,e.environment??``,String(e.pid)].join(`|`)}findEntry(e,t){return e.entries.find(e=>e.repositoryPath===t.repositoryPath&&e.serviceName===t.serviceName&&e.serviceType===t.serviceType&&(t.environment?e.environment===t.environment:!0))}removeMatchingEntries(e,t){e.entries=e.entries.filter(e=>!(e.repositoryPath===t.repositoryPath&&e.serviceName===t.serviceName&&e.serviceType===t.serviceType&&(!t.environment||e.environment===t.environment)))}createSuccessResponse(e,t){return S.parse({success:!0,...typeof e==`number`?{pid:e}:{},...t?{record:t}:{}})}createFailureResponse(e){return S.parse({success:!1,error:e})}async pathExists(e){try{return await u.default.access(e),!0}catch{return!1}}delay(e){return new Promise(t=>setTimeout(t,e))}};Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return 75}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return 80}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return 1}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return s}});
|
|
2
|
+
//# sourceMappingURL=ProcessRegistryService.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessRegistryService.cjs","names":["z","path","os","portRegistry: PortRegistryCleanup","PortRegistryService","path","record: ProcessRegistryRecord","errors: string[]","fs","payload: ProcessRegistryState","aliveEntries: ProcessRegistryRecord[]","lockState: LockState"],"sources":["../src/types/index.ts","../src/utils/index.ts","../src/services/ProcessRegistryService.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const REGISTRY_VERSION = 1 as const;\n\nexport const ServiceCategorySchema = z.enum(['service', 'tool']);\n\nexport const ProcessMetadataSchema = z.record(z.string(), z.unknown());\n\nexport const ProcessRegistryRecordSchema = z.object({\n repositoryPath: z.string().trim().min(1, 'repositoryPath is required'),\n serviceName: z.string().trim().min(1, 'serviceName is required'),\n serviceType: ServiceCategorySchema,\n environment: z.string().trim().min(1).optional(),\n pid: z.number().int().min(1),\n port: z.number().int().min(1).max(65535).optional(),\n host: z.string().trim().min(1).optional(),\n command: z.string().trim().min(1).optional(),\n args: z.array(z.string()).optional(),\n metadata: ProcessMetadataSchema.optional(),\n createdAt: z.string().trim().min(1),\n updatedAt: z.string().trim().min(1),\n});\n\nexport const ProcessRegistryStateSchema = z.object({\n version: z.literal(REGISTRY_VERSION),\n updatedAt: z.string().trim().min(1),\n entries: z.array(ProcessRegistryRecordSchema),\n});\n\nexport const RegisterProcessRequestSchema = z.object({\n repositoryPath: z.string().trim().min(1),\n serviceName: z.string().trim().min(1),\n serviceType: ServiceCategorySchema.default('service'),\n environment: z.string().trim().min(1).optional(),\n pid: z.number().int().min(1),\n port: z.number().int().min(1).max(65535).optional(),\n host: z.string().trim().min(1).optional(),\n command: z.string().trim().min(1).optional(),\n args: z.array(z.string()).optional(),\n metadata: ProcessMetadataSchema.optional(),\n force: z.boolean().optional(),\n});\n\nexport const ReleaseProcessRequestSchema = z.object({\n repositoryPath: z.string().trim().min(1),\n serviceName: z.string().trim().min(1),\n serviceType: ServiceCategorySchema.optional(),\n pid: z.number().int().min(1).optional(),\n environment: z.string().trim().min(1).optional(),\n force: z.boolean().optional(),\n kill: z.boolean().optional().default(true),\n releasePort: z.boolean().optional().default(true),\n});\n\nexport const ListProcessFiltersSchema = z.object({\n repositoryPath: z.string().trim().min(1).optional(),\n serviceType: ServiceCategorySchema.optional(),\n serviceName: z.string().trim().min(1).optional(),\n environment: z.string().trim().min(1).optional(),\n});\n\nexport const ProcessRegistryResponseSchema = z.object({\n success: z.boolean(),\n pid: z.number().int().min(1).optional(),\n record: ProcessRegistryRecordSchema.optional(),\n error: z.string().optional(),\n});\n\nexport type ServiceCategory = z.infer<typeof ServiceCategorySchema>;\nexport type ProcessMetadata = z.infer<typeof ProcessMetadataSchema>;\nexport type ProcessRegistryRecord = z.infer<typeof ProcessRegistryRecordSchema>;\nexport type ProcessRegistryState = z.infer<typeof ProcessRegistryStateSchema>;\nexport type RegisterProcessRequest = z.infer<typeof RegisterProcessRequestSchema>;\nexport type ReleaseProcessRequest = z.infer<typeof ReleaseProcessRequestSchema>;\nexport type ListProcessFilters = z.infer<typeof ListProcessFiltersSchema>;\nexport type ProcessRegistryResponse = z.infer<typeof ProcessRegistryResponseSchema>;\n\nexport type ProcessRegistryErrorCode =\n | 'INVALID_REQUEST'\n | 'REGISTRY_READ_FAILED'\n | 'REGISTRY_WRITE_FAILED'\n | 'REGISTRY_LOCK_FAILED'\n | 'NO_PROCESS_FOUND';\n\nexport class ProcessRegistryError extends Error {\n readonly code: ProcessRegistryErrorCode;\n\n constructor(message: string, code: ProcessRegistryErrorCode, options?: ErrorOptions) {\n super(message, options);\n this.name = 'ProcessRegistryError';\n this.code = code;\n }\n}\n","import { randomBytes } from 'node:crypto';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const DEFAULT_REGISTRY_PATH = path.join(os.homedir(), '.process-registry', 'processes.json');\nexport const DEFAULT_REGISTRY_LOCK_PATH = `${DEFAULT_REGISTRY_PATH}.lock`;\nexport const LOCK_RETRY_DELAY_MS = 75;\nexport const LOCK_MAX_RETRIES = 80;\n\nexport const normalizeRepositoryPath = (value: string): string => path.resolve(value);\n\nexport const makeTempPath = (filePath: string): string => {\n const random = randomBytes(6).toString('hex');\n return `${filePath}.${random}.tmp`;\n};\n","import { randomBytes } from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport {\n type ListProcessFilters,\n ListProcessFiltersSchema,\n type ProcessRegistryRecord,\n ProcessRegistryError,\n type ProcessRegistryResponse,\n ProcessRegistryResponseSchema,\n type ProcessRegistryState,\n ProcessRegistryStateSchema,\n REGISTRY_VERSION,\n type RegisterProcessRequest,\n RegisterProcessRequestSchema,\n type ReleaseProcessRequest,\n ReleaseProcessRequestSchema,\n} from '../types';\nimport {\n DEFAULT_REGISTRY_PATH,\n LOCK_MAX_RETRIES,\n LOCK_RETRY_DELAY_MS,\n makeTempPath,\n normalizeRepositoryPath,\n} from '../utils';\nimport { PortRegistryService } from '@agimon-ai/foundation-port-registry';\n\ninterface LockState {\n pid: number;\n token: string;\n createdAt: string;\n}\n\ninterface NormalizedFilters {\n repositoryPath: string;\n serviceName: string;\n serviceType: 'service' | 'tool';\n environment?: string;\n}\n\ntype PortRegistryCleanup = Pick<PortRegistryService, 'releasePort'>;\n\nexport class ProcessRegistryService {\n private readonly registryPath: string;\n private readonly lockPath: string;\n\n constructor(\n registryPath: string = DEFAULT_REGISTRY_PATH,\n lockPath?: string,\n private readonly portRegistry: PortRegistryCleanup = new PortRegistryService(process.env.PORT_REGISTRY_PATH),\n ) {\n this.registryPath = ProcessRegistryService.resolveRegistryPath(registryPath);\n this.lockPath = lockPath ?? `${this.registryPath}.lock`;\n }\n\n static resolveRegistryPath(inputPath?: string): string {\n if (!inputPath) {\n return DEFAULT_REGISTRY_PATH;\n }\n\n const resolvedPath = path.isAbsolute(inputPath) ? inputPath : path.join(process.cwd(), inputPath);\n if (path.extname(resolvedPath) === '.json') {\n return resolvedPath;\n }\n\n return path.join(resolvedPath, 'processes.json');\n }\n\n async registerProcess(rawRequest: RegisterProcessRequest): Promise<ProcessRegistryResponse> {\n const request = RegisterProcessRequestSchema.parse(rawRequest);\n\n return this.withLock(async () => {\n const state = await this.loadState();\n const normalizedRepo = normalizeRepositoryPath(request.repositoryPath);\n const serviceType = request.serviceType ?? 'service';\n const environment = request.environment ?? process.env.NODE_ENV ?? 'development';\n const registry = await this.pruneState(state);\n const existing = this.findEntry(registry, {\n repositoryPath: normalizedRepo,\n serviceName: request.serviceName,\n serviceType,\n environment,\n });\n\n if (existing) {\n if (existing.pid === request.pid) {\n existing.updatedAt = new Date().toISOString();\n existing.port = request.port ?? existing.port;\n existing.host = request.host ?? existing.host;\n existing.command = request.command ?? existing.command;\n existing.args = request.args ?? existing.args;\n existing.metadata = request.metadata ?? existing.metadata;\n await this.saveState(registry);\n return this.createSuccessResponse(request.pid, existing);\n }\n\n const isAlive = this.isProcessRunning(existing.pid);\n if (isAlive && !request.force) {\n return this.createFailureResponse(\n `Process already registered for ${request.serviceName} in requested scope`,\n );\n }\n\n if (isAlive) {\n await this.terminateProcess(existing.pid);\n }\n\n await this.releaseAssociatedPort(existing);\n this.removeMatchingEntries(registry, {\n repositoryPath: normalizedRepo,\n serviceName: request.serviceName,\n serviceType,\n environment,\n });\n }\n\n const now = new Date().toISOString();\n const record: ProcessRegistryRecord = {\n repositoryPath: normalizedRepo,\n serviceName: request.serviceName,\n serviceType,\n environment,\n pid: request.pid,\n port: request.port,\n host: request.host,\n command: request.command,\n args: request.args,\n metadata: request.metadata,\n createdAt: now,\n updatedAt: now,\n };\n\n registry.entries.push(record);\n await this.saveState(registry);\n return this.createSuccessResponse(request.pid, record);\n });\n }\n\n async releaseProcess(rawRequest: ReleaseProcessRequest): Promise<ProcessRegistryResponse> {\n const request = ReleaseProcessRequestSchema.parse(rawRequest);\n\n return this.withLock(async () => {\n const state = await this.loadState();\n const registry = await this.pruneMissingRepositories(state);\n const normalizedRepo = normalizeRepositoryPath(request.repositoryPath);\n const serviceType = request.serviceType ?? 'service';\n const environment = request.environment ?? process.env.NODE_ENV ?? 'development';\n const matches = registry.entries.filter((entry) => {\n if (entry.repositoryPath !== normalizedRepo) return false;\n if (entry.serviceName !== request.serviceName) return false;\n if (entry.serviceType !== serviceType) return false;\n if (request.environment && entry.environment !== environment) return false;\n if (typeof request.pid === 'number' && entry.pid !== request.pid) return false;\n return true;\n });\n\n if (matches.length === 0) {\n return this.createFailureResponse(`No matching process entry for ${request.serviceName}`);\n }\n\n const errors: string[] = [];\n const removable = new Set<string>();\n\n for (const entry of matches) {\n const entryKey = this.entryKey(entry);\n\n try {\n if (request.kill ?? true) {\n if (this.isProcessRunning(entry.pid)) {\n await this.terminateProcess(entry.pid);\n }\n }\n\n if (request.releasePort ?? true) {\n await this.releaseAssociatedPort(entry);\n }\n\n removable.add(entryKey);\n } catch (error) {\n errors.push(\n `${entry.serviceName} (pid ${entry.pid}): ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n if (removable.size > 0) {\n registry.entries = registry.entries.filter((entry) => !removable.has(this.entryKey(entry)));\n await this.saveState(registry);\n }\n\n if (errors.length > 0) {\n return this.createFailureResponse(errors.join('; '));\n }\n\n return this.createSuccessResponse();\n });\n }\n\n async listProcesses(filters: ListProcessFilters = {}): Promise<ProcessRegistryRecord[]> {\n const request = ListProcessFiltersSchema.parse(filters);\n\n return this.withLock(async () => {\n const state = await this.loadState();\n const registry = await this.pruneState(state);\n\n return [...registry.entries].filter((entry) => {\n if (request.repositoryPath && entry.repositoryPath !== normalizeRepositoryPath(request.repositoryPath)) {\n return false;\n }\n if (request.serviceType && entry.serviceType !== request.serviceType) return false;\n if (request.serviceName && entry.serviceName !== request.serviceName) return false;\n if (request.environment && entry.environment !== request.environment) return false;\n return true;\n });\n });\n }\n\n private async withLock<T>(callback: () => Promise<T>): Promise<T> {\n const lockToken = `${process.pid}-${randomBytes(6).toString('hex')}`;\n await this.acquireLock(lockToken);\n\n try {\n return await callback();\n } finally {\n await this.releaseLock(lockToken);\n }\n }\n\n private async loadState(): Promise<ProcessRegistryState> {\n await fs.mkdir(path.dirname(this.registryPath), { recursive: true });\n\n try {\n const content = await fs.readFile(this.registryPath, 'utf-8');\n const parsed = JSON.parse(content);\n return ProcessRegistryStateSchema.parse(parsed);\n } catch (error) {\n const sysError = error as NodeJS.ErrnoException;\n if (sysError.code === 'ENOENT') {\n return {\n version: REGISTRY_VERSION,\n updatedAt: new Date().toISOString(),\n entries: [],\n };\n }\n\n if (sysError instanceof SyntaxError) {\n const backupPath = `${this.registryPath}.corrupt.${Date.now()}`;\n await fs.rename(this.registryPath, backupPath).catch(() => undefined);\n }\n\n throw new ProcessRegistryError(\n `Failed to read registry file: ${error instanceof Error ? error.message : String(error)}`,\n 'REGISTRY_READ_FAILED',\n { cause: error },\n );\n }\n }\n\n private async saveState(state: ProcessRegistryState): Promise<void> {\n await fs.mkdir(path.dirname(this.registryPath), { recursive: true });\n\n const payload: ProcessRegistryState = {\n ...state,\n updatedAt: new Date().toISOString(),\n entries: [...state.entries],\n };\n\n const tempPath = makeTempPath(this.registryPath);\n await fs.writeFile(tempPath, JSON.stringify(payload, null, 2), 'utf-8');\n await fs.rename(tempPath, this.registryPath);\n }\n\n private async pruneState(state: ProcessRegistryState): Promise<ProcessRegistryState> {\n const repositoryPruned = await this.pruneMissingRepositories(state);\n return this.pruneDeadProcesses(repositoryPruned);\n }\n\n private async pruneMissingRepositories(state: ProcessRegistryState): Promise<ProcessRegistryState> {\n const entries = await Promise.all(\n state.entries.map(async (entry) => ({\n entry,\n exists: await this.pathExists(entry.repositoryPath),\n })),\n );\n\n const pruned = entries.filter((value) => value.exists).map((value) => value.entry);\n if (pruned.length !== state.entries.length) {\n state.entries = pruned;\n await this.saveState(state);\n }\n\n return state;\n }\n\n private async pruneDeadProcesses(state: ProcessRegistryState): Promise<ProcessRegistryState> {\n const aliveEntries: ProcessRegistryRecord[] = [];\n let changed = false;\n\n for (const entry of state.entries) {\n if (this.isProcessRunning(entry.pid)) {\n aliveEntries.push(entry);\n continue;\n }\n\n changed = true;\n await this.releaseAssociatedPort(entry);\n }\n\n if (changed) {\n state.entries = aliveEntries;\n await this.saveState(state);\n }\n\n return state;\n }\n\n private async acquireLock(token: string): Promise<void> {\n await fs.mkdir(path.dirname(this.lockPath), { recursive: true });\n\n for (let attempt = 0; attempt < LOCK_MAX_RETRIES; attempt += 1) {\n try {\n const lockState: LockState = {\n pid: process.pid,\n token,\n createdAt: new Date().toISOString(),\n };\n await fs.writeFile(this.lockPath, JSON.stringify(lockState), { flag: 'wx' });\n return;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw new ProcessRegistryError(\n `Failed to acquire registry lock: ${error instanceof Error ? error.message : String(error)}`,\n 'REGISTRY_LOCK_FAILED',\n { cause: error },\n );\n }\n\n const stale = await this.isStaleLock();\n if (stale) {\n await fs.unlink(this.lockPath).catch(() => undefined);\n attempt -= 1;\n continue;\n }\n\n await this.delay(LOCK_RETRY_DELAY_MS);\n }\n }\n\n throw new ProcessRegistryError('Unable to acquire registry lock (timeout)', 'REGISTRY_LOCK_FAILED');\n }\n\n private async releaseLock(token: string): Promise<void> {\n try {\n const existing = await fs.readFile(this.lockPath, 'utf-8');\n const parsed = JSON.parse(existing) as { token: string };\n if (parsed.token === token) {\n await fs.unlink(this.lockPath);\n }\n } catch {\n // ignore\n }\n }\n\n private async isStaleLock(): Promise<boolean> {\n try {\n const content = await fs.readFile(this.lockPath, 'utf-8');\n const parsed = JSON.parse(content) as LockState;\n\n if (parsed.pid) {\n const pidAlive = this.isProcessRunning(parsed.pid);\n if (pidAlive) {\n const age = Date.now() - new Date(parsed.createdAt).getTime();\n if (Number.isFinite(age) && age < 5000) {\n return false;\n }\n\n return false;\n }\n }\n\n return true;\n } catch {\n return true;\n }\n }\n\n private isProcessRunning(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n }\n\n private async terminateProcess(pid: number): Promise<void> {\n try {\n process.kill(pid, 0);\n } catch {\n return;\n }\n\n try {\n process.kill(pid, 'SIGTERM');\n } catch (error) {\n const sysError = error as NodeJS.ErrnoException;\n if (sysError.code === 'ESRCH') {\n return;\n }\n\n throw new Error(\n `Failed to send SIGTERM to process ${pid}: ${error instanceof Error ? error.message : String(error)}`,\n {\n cause: error,\n },\n );\n }\n\n await this.delay(500);\n\n if (!this.isProcessRunning(pid)) {\n return;\n }\n\n try {\n process.kill(pid, 'SIGKILL');\n } catch (error) {\n const sysError = error as NodeJS.ErrnoException;\n if (sysError.code === 'ESRCH') {\n return;\n }\n\n throw new Error(\n `Failed to send SIGKILL to process ${pid}: ${error instanceof Error ? error.message : String(error)}`,\n {\n cause: error,\n },\n );\n }\n\n await this.delay(250);\n\n if (this.isProcessRunning(pid)) {\n throw new Error(`Process ${pid} did not exit after SIGKILL`);\n }\n }\n\n private async releaseAssociatedPort(entry: ProcessRegistryRecord): Promise<void> {\n if (!this.portRegistry || !entry.port) {\n return;\n }\n\n try {\n const result = await this.portRegistry.releasePort({\n repositoryPath: entry.repositoryPath,\n serviceName: entry.serviceName,\n serviceType: entry.serviceType,\n environment: entry.environment,\n pid: entry.pid,\n force: true,\n });\n\n if (!result.success && result.error && !result.error.includes('No matching registry entry')) {\n throw new Error(result.error);\n }\n } catch {\n // Best-effort cleanup: port release failures should not block process cleanup.\n }\n }\n\n private entryKey(entry: ProcessRegistryRecord): string {\n return [\n entry.repositoryPath,\n entry.serviceName,\n entry.serviceType,\n entry.environment ?? '',\n String(entry.pid),\n ].join('|');\n }\n\n private findEntry(state: ProcessRegistryState, filters: NormalizedFilters): ProcessRegistryRecord | undefined {\n return state.entries.find(\n (entry) =>\n entry.repositoryPath === filters.repositoryPath &&\n entry.serviceName === filters.serviceName &&\n entry.serviceType === filters.serviceType &&\n (filters.environment ? entry.environment === filters.environment : true),\n );\n }\n\n private removeMatchingEntries(state: ProcessRegistryState, filters: NormalizedFilters): void {\n state.entries = state.entries.filter(\n (entry) =>\n !(\n entry.repositoryPath === filters.repositoryPath &&\n entry.serviceName === filters.serviceName &&\n entry.serviceType === filters.serviceType &&\n (!filters.environment || entry.environment === filters.environment)\n ),\n );\n }\n\n private createSuccessResponse(pid?: number, record?: ProcessRegistryRecord): ProcessRegistryResponse {\n return ProcessRegistryResponseSchema.parse({\n success: true,\n ...(typeof pid === 'number' ? { pid } : {}),\n ...(record ? { record } : {}),\n });\n }\n\n private createFailureResponse(error: string): ProcessRegistryResponse {\n return ProcessRegistryResponseSchema.parse({\n success: false,\n error,\n });\n }\n\n private async pathExists(candidate: string): Promise<boolean> {\n try {\n await fs.access(candidate);\n return true;\n } catch {\n return false;\n }\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"],"mappings":"wqBAEA,MAAa,EAAmB,EAEnB,EAAwBA,EAAAA,EAAE,KAAK,CAAC,UAAW,OAAO,CAAC,CAEnD,EAAwBA,EAAAA,EAAE,OAAOA,EAAAA,EAAE,QAAQ,CAAEA,EAAAA,EAAE,SAAS,CAAC,CAEzD,EAA8BA,EAAAA,EAAE,OAAO,CAClD,eAAgBA,EAAAA,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAG,6BAA6B,CACtE,YAAaA,EAAAA,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAG,0BAA0B,CAChE,YAAa,EACb,YAAaA,EAAAA,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAChD,IAAKA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,IAA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sBAA8B,EAAc,EAAyD,CACnG,OAAO,EAA8B,MAAM,CACzC,QAAS,GACT,GAAI,OAAO,GAAQ,SAAW,CAAE,MAAK,CAAG,EAAE,CAC1C,GAAI,EAAS,CAAE,SAAQ,CAAG,EAAE,CAC7B,CAAC,CAGJ,sBAA8B,EAAwC,CACpE,OAAO,EAA8B,MAAM,CACzC,QAAS,GACT,QACD,CAAC,CAGJ,MAAc,WAAW,EAAqC,CAC5D,GAAI,CAEF,OADA,MAAMA,EAAAA,QAAG,OAAO,EAAU,CACnB,QACD,CACN,MAAO,IAIX,MAAc,EAA2B,CACvC,OAAO,IAAI,QAAS,GAAY,WAAW,EAAS,EAAG,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:path";import{randomBytes as t}from"node:crypto";import n from"node:fs/promises";import{z as r}from"zod";import i from"node:os";import{PortRegistryService as a}from"@agimon-ai/foundation-port-registry";const o=1,s=r.enum([`service`,`tool`]),c=r.record(r.string(),r.unknown()),l=r.object({repositoryPath:r.string().trim().min(1,`repositoryPath is required`),serviceName:r.string().trim().min(1,`serviceName is required`),serviceType:s,environment:r.string().trim().min(1).optional(),pid:r.number().int().min(1),port:r.number().int().min(1).max(65535).optional(),host:r.string().trim().min(1).optional(),command:r.string().trim().min(1).optional(),args:r.array(r.string()).optional(),metadata:c.optional(),createdAt:r.string().trim().min(1),updatedAt:r.string().trim().min(1)}),u=r.object({version:r.literal(1),updatedAt:r.string().trim().min(1),entries:r.array(l)}),d=r.object({repositoryPath:r.string().trim().min(1),serviceName:r.string().trim().min(1),serviceType:s.default(`service`),environment:r.string().trim().min(1).optional(),pid:r.number().int().min(1),port:r.number().int().min(1).max(65535).optional(),host:r.string().trim().min(1).optional(),command:r.string().trim().min(1).optional(),args:r.array(r.string()).optional(),metadata:c.optional(),force:r.boolean().optional()}),f=r.object({repositoryPath:r.string().trim().min(1),serviceName:r.string().trim().min(1),serviceType:s.optional(),pid:r.number().int().min(1).optional(),environment:r.string().trim().min(1).optional(),force:r.boolean().optional(),kill:r.boolean().optional().default(!0),releasePort:r.boolean().optional().default(!0)}),p=r.object({repositoryPath:r.string().trim().min(1).optional(),serviceType:s.optional(),serviceName:r.string().trim().min(1).optional(),environment:r.string().trim().min(1).optional()}),m=r.object({success:r.boolean(),pid:r.number().int().min(1).optional(),record:l.optional(),error:r.string().optional()});var h=class extends Error{code;constructor(e,t,n){super(e,n),this.name=`ProcessRegistryError`,this.code=t}};const g=e.join(i.homedir(),`.process-registry`,`processes.json`),_=`${g}.lock`,v=75,y=80,b=t=>e.resolve(t),x=e=>`${e}.${t(6).toString(`hex`)}.tmp`;var S=class r{registryPath;lockPath;constructor(e=g,t,n=new a(process.env.PORT_REGISTRY_PATH)){this.portRegistry=n,this.registryPath=r.resolveRegistryPath(e),this.lockPath=t??`${this.registryPath}.lock`}static resolveRegistryPath(t){if(!t)return g;let n=e.isAbsolute(t)?t:e.join(process.cwd(),t);return e.extname(n)===`.json`?n:e.join(n,`processes.json`)}async registerProcess(e){let t=d.parse(e);return this.withLock(async()=>{let e=await this.loadState(),n=b(t.repositoryPath),r=t.serviceType??`service`,i=t.environment??process.env.NODE_ENV??`development`,a=await this.pruneState(e),o=this.findEntry(a,{repositoryPath:n,serviceName:t.serviceName,serviceType:r,environment:i});if(o){if(o.pid===t.pid)return o.updatedAt=new Date().toISOString(),o.port=t.port??o.port,o.host=t.host??o.host,o.command=t.command??o.command,o.args=t.args??o.args,o.metadata=t.metadata??o.metadata,await this.saveState(a),this.createSuccessResponse(t.pid,o);let e=this.isProcessRunning(o.pid);if(e&&!t.force)return this.createFailureResponse(`Process already registered for ${t.serviceName} in requested scope`);e&&await this.terminateProcess(o.pid),await this.releaseAssociatedPort(o),this.removeMatchingEntries(a,{repositoryPath:n,serviceName:t.serviceName,serviceType:r,environment:i})}let s=new Date().toISOString(),c={repositoryPath:n,serviceName:t.serviceName,serviceType:r,environment:i,pid:t.pid,port:t.port,host:t.host,command:t.command,args:t.args,metadata:t.metadata,createdAt:s,updatedAt:s};return a.entries.push(c),await this.saveState(a),this.createSuccessResponse(t.pid,c)})}async releaseProcess(e){let t=f.parse(e);return this.withLock(async()=>{let e=await this.loadState(),n=await this.pruneMissingRepositories(e),r=b(t.repositoryPath),i=t.serviceType??`service`,a=t.environment??process.env.NODE_ENV??`development`,o=n.entries.filter(e=>!(e.repositoryPath!==r||e.serviceName!==t.serviceName||e.serviceType!==i||t.environment&&e.environment!==a||typeof t.pid==`number`&&e.pid!==t.pid));if(o.length===0)return this.createFailureResponse(`No matching process entry for ${t.serviceName}`);let s=[],c=new Set;for(let e of o){let n=this.entryKey(e);try{(t.kill??!0)&&this.isProcessRunning(e.pid)&&await this.terminateProcess(e.pid),(t.releasePort??!0)&&await this.releaseAssociatedPort(e),c.add(n)}catch(t){s.push(`${e.serviceName} (pid ${e.pid}): ${t instanceof Error?t.message:String(t)}`)}}return c.size>0&&(n.entries=n.entries.filter(e=>!c.has(this.entryKey(e))),await this.saveState(n)),s.length>0?this.createFailureResponse(s.join(`; `)):this.createSuccessResponse()})}async listProcesses(e={}){let t=p.parse(e);return this.withLock(async()=>{let e=await this.loadState();return[...(await this.pruneState(e)).entries].filter(e=>!(t.repositoryPath&&e.repositoryPath!==b(t.repositoryPath)||t.serviceType&&e.serviceType!==t.serviceType||t.serviceName&&e.serviceName!==t.serviceName||t.environment&&e.environment!==t.environment))})}async withLock(e){let n=`${process.pid}-${t(6).toString(`hex`)}`;await this.acquireLock(n);try{return await e()}finally{await this.releaseLock(n)}}async loadState(){await n.mkdir(e.dirname(this.registryPath),{recursive:!0});try{let e=await n.readFile(this.registryPath,`utf-8`),t=JSON.parse(e);return u.parse(t)}catch(e){let t=e;if(t.code===`ENOENT`)return{version:1,updatedAt:new Date().toISOString(),entries:[]};if(t instanceof SyntaxError){let e=`${this.registryPath}.corrupt.${Date.now()}`;await n.rename(this.registryPath,e).catch(()=>void 0)}throw new h(`Failed to read registry file: ${e instanceof Error?e.message:String(e)}`,`REGISTRY_READ_FAILED`,{cause:e})}}async saveState(t){await n.mkdir(e.dirname(this.registryPath),{recursive:!0});let r={...t,updatedAt:new Date().toISOString(),entries:[...t.entries]},i=x(this.registryPath);await n.writeFile(i,JSON.stringify(r,null,2),`utf-8`),await n.rename(i,this.registryPath)}async pruneState(e){let t=await this.pruneMissingRepositories(e);return this.pruneDeadProcesses(t)}async pruneMissingRepositories(e){let t=(await Promise.all(e.entries.map(async e=>({entry:e,exists:await this.pathExists(e.repositoryPath)})))).filter(e=>e.exists).map(e=>e.entry);return t.length!==e.entries.length&&(e.entries=t,await this.saveState(e)),e}async pruneDeadProcesses(e){let t=[],n=!1;for(let r of e.entries){if(this.isProcessRunning(r.pid)){t.push(r);continue}n=!0,await this.releaseAssociatedPort(r)}return n&&(e.entries=t,await this.saveState(e)),e}async acquireLock(t){await n.mkdir(e.dirname(this.lockPath),{recursive:!0});for(let e=0;e<80;e+=1)try{let e={pid:process.pid,token:t,createdAt:new Date().toISOString()};await n.writeFile(this.lockPath,JSON.stringify(e),{flag:`wx`});return}catch(t){if(t.code!==`EEXIST`)throw new h(`Failed to acquire registry lock: ${t instanceof Error?t.message:String(t)}`,`REGISTRY_LOCK_FAILED`,{cause:t});if(await this.isStaleLock()){await n.unlink(this.lockPath).catch(()=>void 0),--e;continue}await this.delay(75)}throw new h(`Unable to acquire registry lock (timeout)`,`REGISTRY_LOCK_FAILED`)}async releaseLock(e){try{let t=await n.readFile(this.lockPath,`utf-8`);JSON.parse(t).token===e&&await n.unlink(this.lockPath)}catch{}}async isStaleLock(){try{let e=await n.readFile(this.lockPath,`utf-8`),t=JSON.parse(e);return t.pid&&this.isProcessRunning(t.pid)?(Date.now()-new Date(t.createdAt).getTime(),!1):!0}catch{return!0}}isProcessRunning(e){try{return process.kill(e,0),!0}catch{return!1}}async terminateProcess(e){try{process.kill(e,0)}catch{return}try{process.kill(e,`SIGTERM`)}catch(t){if(t.code===`ESRCH`)return;throw Error(`Failed to send SIGTERM to process ${e}: ${t instanceof Error?t.message:String(t)}`,{cause:t})}if(await this.delay(500),this.isProcessRunning(e)){try{process.kill(e,`SIGKILL`)}catch(t){if(t.code===`ESRCH`)return;throw Error(`Failed to send SIGKILL to process ${e}: ${t instanceof Error?t.message:String(t)}`,{cause:t})}if(await this.delay(250),this.isProcessRunning(e))throw Error(`Process ${e} did not exit after SIGKILL`)}}async releaseAssociatedPort(e){if(!(!this.portRegistry||!e.port))try{let t=await this.portRegistry.releasePort({repositoryPath:e.repositoryPath,serviceName:e.serviceName,serviceType:e.serviceType,environment:e.environment,pid:e.pid,force:!0});if(!t.success&&t.error&&!t.error.includes(`No matching registry entry`))throw Error(t.error)}catch{}}entryKey(e){return[e.repositoryPath,e.serviceName,e.serviceType,e.environment??``,String(e.pid)].join(`|`)}findEntry(e,t){return e.entries.find(e=>e.repositoryPath===t.repositoryPath&&e.serviceName===t.serviceName&&e.serviceType===t.serviceType&&(t.environment?e.environment===t.environment:!0))}removeMatchingEntries(e,t){e.entries=e.entries.filter(e=>!(e.repositoryPath===t.repositoryPath&&e.serviceName===t.serviceName&&e.serviceType===t.serviceType&&(!t.environment||e.environment===t.environment)))}createSuccessResponse(e,t){return m.parse({success:!0,...typeof e==`number`?{pid:e}:{},...t?{record:t}:{}})}createFailureResponse(e){return m.parse({success:!1,error:e})}async pathExists(e){try{return await n.access(e),!0}catch{return!1}}delay(e){return new Promise(t=>setTimeout(t,e))}};export{s as _,v as a,p as c,l as d,m as f,f as g,d as h,y as i,c as l,o as m,_ as n,x as o,u as p,g as r,b as s,S as t,h as u};
|
|
2
|
+
//# sourceMappingURL=ProcessRegistryService.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessRegistryService.mjs","names":["portRegistry: PortRegistryCleanup","record: ProcessRegistryRecord","errors: string[]","payload: ProcessRegistryState","aliveEntries: ProcessRegistryRecord[]","lockState: LockState"],"sources":["../src/types/index.ts","../src/utils/index.ts","../src/services/ProcessRegistryService.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const REGISTRY_VERSION = 1 as const;\n\nexport const ServiceCategorySchema = z.enum(['service', 'tool']);\n\nexport const ProcessMetadataSchema = z.record(z.string(), z.unknown());\n\nexport const ProcessRegistryRecordSchema = z.object({\n repositoryPath: z.string().trim().min(1, 'repositoryPath is required'),\n serviceName: z.string().trim().min(1, 'serviceName is required'),\n serviceType: ServiceCategorySchema,\n environment: z.string().trim().min(1).optional(),\n pid: z.number().int().min(1),\n port: z.number().int().min(1).max(65535).optional(),\n host: z.string().trim().min(1).optional(),\n command: z.string().trim().min(1).optional(),\n args: z.array(z.string()).optional(),\n metadata: ProcessMetadataSchema.optional(),\n createdAt: z.string().trim().min(1),\n updatedAt: z.string().trim().min(1),\n});\n\nexport const ProcessRegistryStateSchema = z.object({\n version: z.literal(REGISTRY_VERSION),\n updatedAt: z.string().trim().min(1),\n entries: z.array(ProcessRegistryRecordSchema),\n});\n\nexport const RegisterProcessRequestSchema = z.object({\n repositoryPath: z.string().trim().min(1),\n serviceName: z.string().trim().min(1),\n serviceType: ServiceCategorySchema.default('service'),\n environment: z.string().trim().min(1).optional(),\n pid: z.number().int().min(1),\n port: z.number().int().min(1).max(65535).optional(),\n host: z.string().trim().min(1).optional(),\n command: z.string().trim().min(1).optional(),\n args: z.array(z.string()).optional(),\n metadata: ProcessMetadataSchema.optional(),\n force: z.boolean().optional(),\n});\n\nexport const ReleaseProcessRequestSchema = z.object({\n repositoryPath: z.string().trim().min(1),\n serviceName: z.string().trim().min(1),\n serviceType: ServiceCategorySchema.optional(),\n pid: z.number().int().min(1).optional(),\n environment: z.string().trim().min(1).optional(),\n force: z.boolean().optional(),\n kill: z.boolean().optional().default(true),\n releasePort: z.boolean().optional().default(true),\n});\n\nexport const ListProcessFiltersSchema = z.object({\n repositoryPath: z.string().trim().min(1).optional(),\n serviceType: ServiceCategorySchema.optional(),\n serviceName: z.string().trim().min(1).optional(),\n environment: z.string().trim().min(1).optional(),\n});\n\nexport const ProcessRegistryResponseSchema = z.object({\n success: z.boolean(),\n pid: z.number().int().min(1).optional(),\n record: ProcessRegistryRecordSchema.optional(),\n error: z.string().optional(),\n});\n\nexport type ServiceCategory = z.infer<typeof ServiceCategorySchema>;\nexport type ProcessMetadata = z.infer<typeof ProcessMetadataSchema>;\nexport type ProcessRegistryRecord = z.infer<typeof ProcessRegistryRecordSchema>;\nexport type ProcessRegistryState = z.infer<typeof ProcessRegistryStateSchema>;\nexport type RegisterProcessRequest = z.infer<typeof RegisterProcessRequestSchema>;\nexport type ReleaseProcessRequest = z.infer<typeof ReleaseProcessRequestSchema>;\nexport type ListProcessFilters = z.infer<typeof ListProcessFiltersSchema>;\nexport type ProcessRegistryResponse = z.infer<typeof ProcessRegistryResponseSchema>;\n\nexport type ProcessRegistryErrorCode =\n | 'INVALID_REQUEST'\n | 'REGISTRY_READ_FAILED'\n | 'REGISTRY_WRITE_FAILED'\n | 'REGISTRY_LOCK_FAILED'\n | 'NO_PROCESS_FOUND';\n\nexport class ProcessRegistryError extends Error {\n readonly code: ProcessRegistryErrorCode;\n\n constructor(message: string, code: ProcessRegistryErrorCode, options?: ErrorOptions) {\n super(message, options);\n this.name = 'ProcessRegistryError';\n this.code = code;\n }\n}\n","import { randomBytes } from 'node:crypto';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const DEFAULT_REGISTRY_PATH = path.join(os.homedir(), '.process-registry', 'processes.json');\nexport const DEFAULT_REGISTRY_LOCK_PATH = `${DEFAULT_REGISTRY_PATH}.lock`;\nexport const LOCK_RETRY_DELAY_MS = 75;\nexport const LOCK_MAX_RETRIES = 80;\n\nexport const normalizeRepositoryPath = (value: string): string => path.resolve(value);\n\nexport const makeTempPath = (filePath: string): string => {\n const random = randomBytes(6).toString('hex');\n return `${filePath}.${random}.tmp`;\n};\n","import { randomBytes } from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport {\n type ListProcessFilters,\n ListProcessFiltersSchema,\n type ProcessRegistryRecord,\n ProcessRegistryError,\n type ProcessRegistryResponse,\n ProcessRegistryResponseSchema,\n type ProcessRegistryState,\n ProcessRegistryStateSchema,\n REGISTRY_VERSION,\n type RegisterProcessRequest,\n RegisterProcessRequestSchema,\n type ReleaseProcessRequest,\n ReleaseProcessRequestSchema,\n} from '../types';\nimport {\n DEFAULT_REGISTRY_PATH,\n LOCK_MAX_RETRIES,\n LOCK_RETRY_DELAY_MS,\n makeTempPath,\n normalizeRepositoryPath,\n} from '../utils';\nimport { PortRegistryService } from '@agimon-ai/foundation-port-registry';\n\ninterface LockState {\n pid: number;\n token: string;\n createdAt: string;\n}\n\ninterface NormalizedFilters {\n repositoryPath: string;\n serviceName: string;\n serviceType: 'service' | 'tool';\n environment?: string;\n}\n\ntype PortRegistryCleanup = Pick<PortRegistryService, 'releasePort'>;\n\nexport class ProcessRegistryService {\n private readonly registryPath: string;\n private readonly lockPath: string;\n\n constructor(\n registryPath: string = DEFAULT_REGISTRY_PATH,\n lockPath?: string,\n private readonly portRegistry: PortRegistryCleanup = new PortRegistryService(process.env.PORT_REGISTRY_PATH),\n ) {\n this.registryPath = ProcessRegistryService.resolveRegistryPath(registryPath);\n this.lockPath = lockPath ?? `${this.registryPath}.lock`;\n }\n\n static resolveRegistryPath(inputPath?: string): string {\n if (!inputPath) {\n return DEFAULT_REGISTRY_PATH;\n }\n\n const resolvedPath = path.isAbsolute(inputPath) ? inputPath : path.join(process.cwd(), inputPath);\n if (path.extname(resolvedPath) === '.json') {\n return resolvedPath;\n }\n\n return path.join(resolvedPath, 'processes.json');\n }\n\n async registerProcess(rawRequest: RegisterProcessRequest): Promise<ProcessRegistryResponse> {\n const request = RegisterProcessRequestSchema.parse(rawRequest);\n\n return this.withLock(async () => {\n const state = await this.loadState();\n const normalizedRepo = normalizeRepositoryPath(request.repositoryPath);\n const serviceType = request.serviceType ?? 'service';\n const environment = request.environment ?? process.env.NODE_ENV ?? 'development';\n const registry = await this.pruneState(state);\n const existing = this.findEntry(registry, {\n repositoryPath: normalizedRepo,\n serviceName: request.serviceName,\n serviceType,\n environment,\n });\n\n if (existing) {\n if (existing.pid === request.pid) {\n existing.updatedAt = new Date().toISOString();\n existing.port = request.port ?? existing.port;\n existing.host = request.host ?? existing.host;\n existing.command = request.command ?? existing.command;\n existing.args = request.args ?? existing.args;\n existing.metadata = request.metadata ?? existing.metadata;\n await this.saveState(registry);\n return this.createSuccessResponse(request.pid, existing);\n }\n\n const isAlive = this.isProcessRunning(existing.pid);\n if (isAlive && !request.force) {\n return this.createFailureResponse(\n `Process already registered for ${request.serviceName} in requested scope`,\n );\n }\n\n if (isAlive) {\n await this.terminateProcess(existing.pid);\n }\n\n await this.releaseAssociatedPort(existing);\n this.removeMatchingEntries(registry, {\n repositoryPath: normalizedRepo,\n serviceName: request.serviceName,\n serviceType,\n environment,\n });\n }\n\n const now = new Date().toISOString();\n const record: ProcessRegistryRecord = {\n repositoryPath: normalizedRepo,\n serviceName: request.serviceName,\n serviceType,\n environment,\n pid: request.pid,\n port: request.port,\n host: request.host,\n command: request.command,\n args: request.args,\n metadata: request.metadata,\n createdAt: now,\n updatedAt: now,\n };\n\n registry.entries.push(record);\n await this.saveState(registry);\n return this.createSuccessResponse(request.pid, record);\n });\n }\n\n async releaseProcess(rawRequest: ReleaseProcessRequest): Promise<ProcessRegistryResponse> {\n const request = ReleaseProcessRequestSchema.parse(rawRequest);\n\n return this.withLock(async () => {\n const state = await this.loadState();\n const registry = await this.pruneMissingRepositories(state);\n const normalizedRepo = normalizeRepositoryPath(request.repositoryPath);\n const serviceType = request.serviceType ?? 'service';\n const environment = request.environment ?? process.env.NODE_ENV ?? 'development';\n const matches = registry.entries.filter((entry) => {\n if (entry.repositoryPath !== normalizedRepo) return false;\n if (entry.serviceName !== request.serviceName) return false;\n if (entry.serviceType !== serviceType) return false;\n if (request.environment && entry.environment !== environment) return false;\n if (typeof request.pid === 'number' && entry.pid !== request.pid) return false;\n return true;\n });\n\n if (matches.length === 0) {\n return this.createFailureResponse(`No matching process entry for ${request.serviceName}`);\n }\n\n const errors: string[] = [];\n const removable = new Set<string>();\n\n for (const entry of matches) {\n const entryKey = this.entryKey(entry);\n\n try {\n if (request.kill ?? true) {\n if (this.isProcessRunning(entry.pid)) {\n await this.terminateProcess(entry.pid);\n }\n }\n\n if (request.releasePort ?? true) {\n await this.releaseAssociatedPort(entry);\n }\n\n removable.add(entryKey);\n } catch (error) {\n errors.push(\n `${entry.serviceName} (pid ${entry.pid}): ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n if (removable.size > 0) {\n registry.entries = registry.entries.filter((entry) => !removable.has(this.entryKey(entry)));\n await this.saveState(registry);\n }\n\n if (errors.length > 0) {\n return this.createFailureResponse(errors.join('; '));\n }\n\n return this.createSuccessResponse();\n });\n }\n\n async listProcesses(filters: ListProcessFilters = {}): Promise<ProcessRegistryRecord[]> {\n const request = ListProcessFiltersSchema.parse(filters);\n\n return this.withLock(async () => {\n const state = await this.loadState();\n const registry = await this.pruneState(state);\n\n return [...registry.entries].filter((entry) => {\n if (request.repositoryPath && entry.repositoryPath !== normalizeRepositoryPath(request.repositoryPath)) {\n return false;\n }\n if (request.serviceType && entry.serviceType !== request.serviceType) return false;\n if (request.serviceName && entry.serviceName !== request.serviceName) return false;\n if (request.environment && entry.environment !== request.environment) return false;\n return true;\n });\n });\n }\n\n private async withLock<T>(callback: () => Promise<T>): Promise<T> {\n const lockToken = `${process.pid}-${randomBytes(6).toString('hex')}`;\n await this.acquireLock(lockToken);\n\n try {\n return await callback();\n } finally {\n await this.releaseLock(lockToken);\n }\n }\n\n private async loadState(): Promise<ProcessRegistryState> {\n await fs.mkdir(path.dirname(this.registryPath), { recursive: true });\n\n try {\n const content = await fs.readFile(this.registryPath, 'utf-8');\n const parsed = JSON.parse(content);\n return ProcessRegistryStateSchema.parse(parsed);\n } catch (error) {\n const sysError = error as NodeJS.ErrnoException;\n if (sysError.code === 'ENOENT') {\n return {\n version: REGISTRY_VERSION,\n updatedAt: new Date().toISOString(),\n entries: [],\n };\n }\n\n if (sysError instanceof SyntaxError) {\n const backupPath = `${this.registryPath}.corrupt.${Date.now()}`;\n await fs.rename(this.registryPath, backupPath).catch(() => undefined);\n }\n\n throw new ProcessRegistryError(\n `Failed to read registry file: ${error instanceof Error ? error.message : String(error)}`,\n 'REGISTRY_READ_FAILED',\n { cause: error },\n );\n }\n }\n\n private async saveState(state: ProcessRegistryState): Promise<void> {\n await fs.mkdir(path.dirname(this.registryPath), { recursive: true });\n\n const payload: ProcessRegistryState = {\n ...state,\n updatedAt: new Date().toISOString(),\n entries: [...state.entries],\n };\n\n const tempPath = makeTempPath(this.registryPath);\n await fs.writeFile(tempPath, JSON.stringify(payload, null, 2), 'utf-8');\n await fs.rename(tempPath, this.registryPath);\n }\n\n private async pruneState(state: ProcessRegistryState): Promise<ProcessRegistryState> {\n const repositoryPruned = await this.pruneMissingRepositories(state);\n return this.pruneDeadProcesses(repositoryPruned);\n }\n\n private async pruneMissingRepositories(state: ProcessRegistryState): Promise<ProcessRegistryState> {\n const entries = await Promise.all(\n state.entries.map(async (entry) => ({\n entry,\n exists: await this.pathExists(entry.repositoryPath),\n })),\n );\n\n const pruned = entries.filter((value) => value.exists).map((value) => value.entry);\n if (pruned.length !== state.entries.length) {\n state.entries = pruned;\n await this.saveState(state);\n }\n\n return state;\n }\n\n private async pruneDeadProcesses(state: ProcessRegistryState): Promise<ProcessRegistryState> {\n const aliveEntries: ProcessRegistryRecord[] = [];\n let changed = false;\n\n for (const entry of state.entries) {\n if (this.isProcessRunning(entry.pid)) {\n aliveEntries.push(entry);\n continue;\n }\n\n changed = true;\n await this.releaseAssociatedPort(entry);\n }\n\n if (changed) {\n state.entries = aliveEntries;\n await this.saveState(state);\n }\n\n return state;\n }\n\n private async acquireLock(token: string): Promise<void> {\n await fs.mkdir(path.dirname(this.lockPath), { recursive: true });\n\n for (let attempt = 0; attempt < LOCK_MAX_RETRIES; attempt += 1) {\n try {\n const lockState: LockState = {\n pid: process.pid,\n token,\n createdAt: new Date().toISOString(),\n };\n await fs.writeFile(this.lockPath, JSON.stringify(lockState), { flag: 'wx' });\n return;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw new ProcessRegistryError(\n `Failed to acquire registry lock: ${error instanceof Error ? error.message : String(error)}`,\n 'REGISTRY_LOCK_FAILED',\n { cause: error },\n );\n }\n\n const stale = await this.isStaleLock();\n if (stale) {\n await fs.unlink(this.lockPath).catch(() => undefined);\n attempt -= 1;\n continue;\n }\n\n await this.delay(LOCK_RETRY_DELAY_MS);\n }\n }\n\n throw new ProcessRegistryError('Unable to acquire registry lock (timeout)', 'REGISTRY_LOCK_FAILED');\n }\n\n private async releaseLock(token: string): Promise<void> {\n try {\n const existing = await fs.readFile(this.lockPath, 'utf-8');\n const parsed = JSON.parse(existing) as { token: string };\n if (parsed.token === token) {\n await fs.unlink(this.lockPath);\n }\n } catch {\n // ignore\n }\n }\n\n private async isStaleLock(): Promise<boolean> {\n try {\n const content = await fs.readFile(this.lockPath, 'utf-8');\n const parsed = JSON.parse(content) as LockState;\n\n if (parsed.pid) {\n const pidAlive = this.isProcessRunning(parsed.pid);\n if (pidAlive) {\n const age = Date.now() - new Date(parsed.createdAt).getTime();\n if (Number.isFinite(age) && age < 5000) {\n return false;\n }\n\n return false;\n }\n }\n\n return true;\n } catch {\n return true;\n }\n }\n\n private isProcessRunning(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n }\n\n private async terminateProcess(pid: number): Promise<void> {\n try {\n process.kill(pid, 0);\n } catch {\n return;\n }\n\n try {\n process.kill(pid, 'SIGTERM');\n } catch (error) {\n const sysError = error as NodeJS.ErrnoException;\n if (sysError.code === 'ESRCH') {\n return;\n }\n\n throw new Error(\n `Failed to send SIGTERM to process ${pid}: ${error instanceof Error ? error.message : String(error)}`,\n {\n cause: error,\n },\n );\n }\n\n await this.delay(500);\n\n if (!this.isProcessRunning(pid)) {\n return;\n }\n\n try {\n process.kill(pid, 'SIGKILL');\n } catch (error) {\n const sysError = error as NodeJS.ErrnoException;\n if (sysError.code === 'ESRCH') {\n return;\n }\n\n throw new Error(\n `Failed to send SIGKILL to process ${pid}: ${error instanceof Error ? error.message : String(error)}`,\n {\n cause: error,\n },\n );\n }\n\n await this.delay(250);\n\n if (this.isProcessRunning(pid)) {\n throw new Error(`Process ${pid} did not exit after SIGKILL`);\n }\n }\n\n private async releaseAssociatedPort(entry: ProcessRegistryRecord): Promise<void> {\n if (!this.portRegistry || !entry.port) {\n return;\n }\n\n try {\n const result = await this.portRegistry.releasePort({\n repositoryPath: entry.repositoryPath,\n serviceName: entry.serviceName,\n serviceType: entry.serviceType,\n environment: entry.environment,\n pid: entry.pid,\n force: true,\n });\n\n if (!result.success && result.error && !result.error.includes('No matching registry entry')) {\n throw new Error(result.error);\n }\n } catch {\n // Best-effort cleanup: port release failures should not block process cleanup.\n }\n }\n\n private entryKey(entry: ProcessRegistryRecord): string {\n return [\n entry.repositoryPath,\n entry.serviceName,\n entry.serviceType,\n entry.environment ?? '',\n String(entry.pid),\n ].join('|');\n }\n\n private findEntry(state: ProcessRegistryState, filters: NormalizedFilters): ProcessRegistryRecord | undefined {\n return state.entries.find(\n (entry) =>\n entry.repositoryPath === filters.repositoryPath &&\n entry.serviceName === filters.serviceName &&\n entry.serviceType === filters.serviceType &&\n (filters.environment ? entry.environment === filters.environment : true),\n );\n }\n\n private removeMatchingEntries(state: ProcessRegistryState, filters: NormalizedFilters): void {\n state.entries = state.entries.filter(\n (entry) =>\n !(\n entry.repositoryPath === filters.repositoryPath &&\n entry.serviceName === filters.serviceName &&\n entry.serviceType === filters.serviceType &&\n (!filters.environment || entry.environment === filters.environment)\n ),\n );\n }\n\n private createSuccessResponse(pid?: number, record?: ProcessRegistryRecord): ProcessRegistryResponse {\n return ProcessRegistryResponseSchema.parse({\n success: true,\n ...(typeof pid === 'number' ? { pid } : {}),\n ...(record ? { record } : {}),\n });\n }\n\n private createFailureResponse(error: string): ProcessRegistryResponse {\n return ProcessRegistryResponseSchema.parse({\n success: false,\n error,\n });\n }\n\n private async pathExists(candidate: string): Promise<boolean> {\n try {\n await fs.access(candidate);\n return true;\n } catch {\n return false;\n }\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"],"mappings":"4NAEA,MAAa,EAAmB,EAEnB,EAAwB,EAAE,KAAK,CAAC,UAAW,OAAO,CAAC,CAEnD,EAAwB,EAAE,OAAO,EAAE,QAAQ,CAAE,EAAE,SAAS,CAAC,CAEzD,EAA8B,EAAE,OAAO,CAClD,eAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAG,6BAA6B,CACtE,YAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAG,0BAA0B,CAChE,YAAa,EACb,YAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAChD,IAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAC5B,KAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC,UAAU,CACnD,KAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CACzC,QAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAC5C,KAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU,CACpC,SAAU,EAAsB,UAAU,CAC1C,UAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CACnC,UAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CACpC,CAAC,CAEW,EAA6B,EAAE,OAAO,CACjD,QAAS,EAAE,QAAQ,EAAiB,CACpC,UAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CACnC,QAAS,EAAE,MAAM,EAA4B,CAC9C,CAAC,CAEW,EAA+B,EAAE,OAAO,CACnD,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,cAAgB,EAAQ,cAC7B,CAAC,EAAQ,aAAe,EAAM,cAAgB,EAAQ,cAE5D,CAGH,sBAA8B,EAAc,EAAyD,CACnG,OAAO,EAA8B,MAAM,CACzC,QAAS,GACT,GAAI,OAAO,GAAQ,SAAW,CAAE,MAAK,CAAG,EAAE,CAC1C,GAAI,EAAS,CAAE,SAAQ,CAAG,EAAE,CAC7B,CAAC,CAGJ,sBAA8B,EAAwC,CACpE,OAAO,EAA8B,MAAM,CACzC,QAAS,GACT,QACD,CAAC,CAGJ,MAAc,WAAW,EAAqC,CAC5D,GAAI,CAEF,OADA,MAAM,EAAG,OAAO,EAAU,CACnB,QACD,CACN,MAAO,IAIX,MAAc,EAA2B,CACvC,OAAO,IAAI,QAAS,GAAY,WAAW,EAAS,EAAG,CAAC"}
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const e=require(`./ProcessRegistryService.cjs`);let t=require(`node:path`);function n(e,t,n){if(e.includes(`=`)){let t=e.indexOf(`=`),r=t>=0?e.slice(t+1):``;if(r.length===0)throw Error(`Missing value for ${n}`);return[r,0]}if(!t||t.startsWith(`--`))throw Error(`Missing value for ${n}`);return[t,1]}function r(e){let t={};for(let r=0;r<e.length;r+=1){let i=e[r];if(i===`--repository-path`){let[a,o]=n(i,e[r+1],`--repository-path`);t.repositoryPath=a,r+=o;continue}if(i.startsWith(`--repository-path=`)){let[e]=n(i,void 0,`--repository-path`);t.repositoryPath=e;continue}if(i===`--service-name`){let[a,o]=n(i,e[r+1],`--service-name`);t.serviceName=a,r+=o;continue}if(i.startsWith(`--service-name=`)){let[e]=n(i,void 0,`--service-name`);t.serviceName=e;continue}throw i===`--help`||i===`-h`?Error(`help`):i.startsWith(`--`)?Error(`Unknown option: ${i}`):Error(`Unknown argument: ${i}`)}return t}function i(){let e=(0,t.basename)(process.argv[1]||`process-registry`);return[`Usage: ${e} release-process [options]`,``,`Options:`,` --repository-path <path> Worktree root to clean up (default: process.cwd())`,` --service-name <name> Service name to clean up (default: all services in worktree)`,``,`Examples:`,` ${e} release-process --repository-path /path/to/worktree --service-name mcp-proxy-http`,` ${e} release-process --service-name mcp-proxy-http`,` ${e} release-process --repository-path /path/to/worktree`].join(`
|
|
3
|
+
`)}function a(e){let t=new Map;for(let n of e){let e=[n.repositoryPath,n.serviceName,n.serviceType,n.environment??``,String(n.pid??``)].join(`|`);t.has(e)||t.set(e,n)}return[...t.values()]}async function o(t){let n=e.s(t.repositoryPath??process.cwd()),r=t.serviceName?.trim(),i=new e.t(process.env.PROCESS_REGISTRY_PATH),o=await i.listProcesses({repositoryPath:n,...r?{serviceName:r}:{}});if(o.length===0){let e=r?`service ${r} `:``;console.error(`No matching process registrations found for ${e}in worktree ${n}`),process.exit(1)}let s=a(o),c=[];for(let e of s){let t=await i.releaseProcess({repositoryPath:n,serviceName:e.serviceName,serviceType:e.serviceType,environment:e.environment,...e.pid?{pid:e.pid}:{},kill:!0,releasePort:!0});t.success||c.push(`Service ${e.serviceName}: ${t.error??`Unknown error`}`)}if(c.length>0){console.error(`Failed to release ${c.length} entr${c.length===1?`y`:`ies`}:`);for(let e of c)console.error(`- ${e}`);process.exit(1)}r?console.log(`Released ${s.length} process registration(s) for service ${r} in ${n}`):console.log(`Released ${s.length} process registration(s) for worktree ${n}`)}async function s(){let[e=``,...t]=process.argv.slice(2);if(e===`-h`||e===`--help`||e===`help`){console.log(i());return}e!==`release-process`&&(console.error(`Unknown command: ${e||`(none)`}`),console.error(i()),process.exit(1));try{await o(r(t))}catch(e){if(e instanceof Error&&e.message===`help`){console.log(i());return}console.error(e instanceof Error?e.message:`Failed to execute command`),process.exit(1)}}process.argv[1]&&/[\\/](cli\.(ts|mjs|cjs))$/.test(process.argv[1])&&s(),exports.parseReleaseProcessArgs=r,exports.runReleaseProcess=o;
|
|
4
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["parsed: ReleaseProcessCommandOptions","normalizeRepositoryPath","ProcessRegistryService","releaseErrors: string[]"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { basename } from 'node:path';\nimport { ProcessRegistryService } from './services';\nimport { normalizeRepositoryPath } from './utils';\nimport { type ProcessRegistryRecord } from './types';\n\ntype ReleaseProcessCommandOptions = {\n repositoryPath?: string;\n serviceName?: string;\n};\n\nfunction parseValueFromArg(arg: string, nextValue: string | undefined, optionName: string): [string, number] {\n if (arg.includes('=')) {\n const equalsIndex = arg.indexOf('=');\n const value = equalsIndex >= 0 ? arg.slice(equalsIndex + 1) : '';\n if (value.length === 0) {\n throw new Error(`Missing value for ${optionName}`);\n }\n\n return [value, 0];\n }\n\n if (!nextValue || nextValue.startsWith('--')) {\n throw new Error(`Missing value for ${optionName}`);\n }\n\n return [nextValue, 1];\n}\n\nfunction parseReleaseProcessArgs(argv: string[]): ReleaseProcessCommandOptions {\n const parsed: ReleaseProcessCommandOptions = {};\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n if (arg === '--repository-path') {\n const [value, consumed] = parseValueFromArg(arg, argv[index + 1], '--repository-path');\n parsed.repositoryPath = value;\n index += consumed;\n continue;\n }\n\n if (arg.startsWith('--repository-path=')) {\n const [value] = parseValueFromArg(arg, undefined, '--repository-path');\n parsed.repositoryPath = value;\n continue;\n }\n\n if (arg === '--service-name') {\n const [value, consumed] = parseValueFromArg(arg, argv[index + 1], '--service-name');\n parsed.serviceName = value;\n index += consumed;\n continue;\n }\n\n if (arg.startsWith('--service-name=')) {\n const [value] = parseValueFromArg(arg, undefined, '--service-name');\n parsed.serviceName = value;\n continue;\n }\n\n if (arg === '--help' || arg === '-h') {\n throw new Error('help');\n }\n\n if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n }\n\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return parsed;\n}\n\nfunction formatUsage() {\n const command = basename(process.argv[1] || 'process-registry');\n\n return [\n `Usage: ${command} release-process [options]`,\n '',\n 'Options:',\n ' --repository-path <path> Worktree root to clean up (default: process.cwd())',\n ' --service-name <name> Service name to clean up (default: all services in worktree)',\n '',\n 'Examples:',\n ` ${command} release-process --repository-path /path/to/worktree --service-name mcp-proxy-http`,\n ` ${command} release-process --service-name mcp-proxy-http`,\n ` ${command} release-process --repository-path /path/to/worktree`,\n ].join('\\n');\n}\n\nfunction dedupeRecords(records: ProcessRegistryRecord[]): ProcessRegistryRecord[] {\n const byKey = new Map<string, ProcessRegistryRecord>();\n\n for (const record of records) {\n const key = [\n record.repositoryPath,\n record.serviceName,\n record.serviceType,\n record.environment ?? '',\n String(record.pid ?? ''),\n ].join('|');\n if (!byKey.has(key)) {\n byKey.set(key, record);\n }\n }\n\n return [...byKey.values()];\n}\n\nasync function runReleaseProcess(options: ReleaseProcessCommandOptions): Promise<void> {\n const repositoryPath = normalizeRepositoryPath(options.repositoryPath ?? process.cwd());\n const serviceName = options.serviceName?.trim();\n const service = new ProcessRegistryService(process.env.PROCESS_REGISTRY_PATH);\n\n const matches = await service.listProcesses({\n repositoryPath,\n ...(serviceName ? { serviceName } : {}),\n });\n\n if (matches.length === 0) {\n const target = serviceName ? `service ${serviceName} ` : '';\n console.error(`No matching process registrations found for ${target}in worktree ${repositoryPath}`);\n process.exit(1);\n }\n\n const releases = dedupeRecords(matches);\n const releaseErrors: string[] = [];\n\n for (const entry of releases) {\n const response = await service.releaseProcess({\n repositoryPath,\n serviceName: entry.serviceName,\n serviceType: entry.serviceType,\n environment: entry.environment,\n ...(entry.pid ? { pid: entry.pid } : {}),\n kill: true,\n releasePort: true,\n });\n\n if (!response.success) {\n releaseErrors.push(`Service ${entry.serviceName}: ${response.error ?? 'Unknown error'}`);\n }\n }\n\n if (releaseErrors.length > 0) {\n console.error(`Failed to release ${releaseErrors.length} entr${releaseErrors.length === 1 ? 'y' : 'ies'}:`);\n for (const failure of releaseErrors) {\n console.error(`- ${failure}`);\n }\n process.exit(1);\n }\n\n if (serviceName) {\n console.log(`Released ${releases.length} process registration(s) for service ${serviceName} in ${repositoryPath}`);\n } else {\n console.log(`Released ${releases.length} process registration(s) for worktree ${repositoryPath}`);\n }\n}\n\nasync function main() {\n const [command = '', ...rawArgs] = process.argv.slice(2);\n\n if (command === '-h' || command === '--help' || command === 'help') {\n console.log(formatUsage());\n return;\n }\n\n if (command !== 'release-process') {\n console.error(`Unknown command: ${command || '(none)'}`);\n console.error(formatUsage());\n process.exit(1);\n }\n\n try {\n const options = parseReleaseProcessArgs(rawArgs);\n await runReleaseProcess(options);\n } catch (error) {\n if (error instanceof Error && error.message === 'help') {\n console.log(formatUsage());\n return;\n }\n\n console.error(error instanceof Error ? error.message : 'Failed to execute command');\n process.exit(1);\n }\n}\n\nif (process.argv[1] && /[\\\\/](cli\\.(ts|mjs|cjs))$/.test(process.argv[1])) {\n void main();\n}\n\nexport { parseReleaseProcessArgs, runReleaseProcess };\n"],"mappings":";2EAYA,SAAS,EAAkB,EAAa,EAA+B,EAAsC,CAC3G,GAAI,EAAI,SAAS,IAAI,CAAE,CACrB,IAAM,EAAc,EAAI,QAAQ,IAAI,CAC9B,EAAQ,GAAe,EAAI,EAAI,MAAM,EAAc,EAAE,CAAG,GAC9D,GAAI,EAAM,SAAW,EACnB,MAAU,MAAM,qBAAqB,IAAa,CAGpD,MAAO,CAAC,EAAO,EAAE,CAGnB,GAAI,CAAC,GAAa,EAAU,WAAW,KAAK,CAC1C,MAAU,MAAM,qBAAqB,IAAa,CAGpD,MAAO,CAAC,EAAW,EAAE,CAGvB,SAAS,EAAwB,EAA8C,CAC7E,IAAMA,EAAuC,EAAE,CAE/C,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAK,OAAQ,GAAS,EAAG,CACnD,IAAM,EAAM,EAAK,GACjB,GAAI,IAAQ,oBAAqB,CAC/B,GAAM,CAAC,EAAO,GAAY,EAAkB,EAAK,EAAK,EAAQ,GAAI,oBA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AAE,EAGjB,GAAI,CAEF,MAAM,EADU,EAAwB,EAAQ,CAChB,OACzB,EAAO,CACd,GAAI,aAAiB,OAAS,EAAM,UAAY,OAAQ,CACtD,QAAQ,IAAI,GAAa,CAAC,CAC1B,OAGF,QAAQ,MAAM,aAAiB,MAAQ,EAAM,QAAU,4BAA4B,CACnF,QAAQ,KAAK,EAAE,EAIf,QAAQ,KAAK,IAAM,4BAA4B,KAAK,QAAQ,KAAK,GAAG,EACjE,GAAM"}
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/cli.d.ts
|
|
3
|
+
type ReleaseProcessCommandOptions = {
|
|
4
|
+
repositoryPath?: string;
|
|
5
|
+
serviceName?: string;
|
|
6
|
+
};
|
|
7
|
+
declare function parseReleaseProcessArgs(argv: string[]): ReleaseProcessCommandOptions;
|
|
8
|
+
declare function runReleaseProcess(options: ReleaseProcessCommandOptions): Promise<void>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { parseReleaseProcessArgs, runReleaseProcess };
|
|
11
|
+
//# sourceMappingURL=cli.d.cts.map
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/cli.d.ts
|
|
3
|
+
type ReleaseProcessCommandOptions = {
|
|
4
|
+
repositoryPath?: string;
|
|
5
|
+
serviceName?: string;
|
|
6
|
+
};
|
|
7
|
+
declare function parseReleaseProcessArgs(argv: string[]): ReleaseProcessCommandOptions;
|
|
8
|
+
declare function runReleaseProcess(options: ReleaseProcessCommandOptions): Promise<void>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { parseReleaseProcessArgs, runReleaseProcess };
|
|
11
|
+
//# sourceMappingURL=cli.d.mts.map
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{s as e,t}from"./ProcessRegistryService.mjs";import{basename as n}from"node:path";function r(e,t,n){if(e.includes(`=`)){let t=e.indexOf(`=`),r=t>=0?e.slice(t+1):``;if(r.length===0)throw Error(`Missing value for ${n}`);return[r,0]}if(!t||t.startsWith(`--`))throw Error(`Missing value for ${n}`);return[t,1]}function i(e){let t={};for(let n=0;n<e.length;n+=1){let i=e[n];if(i===`--repository-path`){let[a,o]=r(i,e[n+1],`--repository-path`);t.repositoryPath=a,n+=o;continue}if(i.startsWith(`--repository-path=`)){let[e]=r(i,void 0,`--repository-path`);t.repositoryPath=e;continue}if(i===`--service-name`){let[a,o]=r(i,e[n+1],`--service-name`);t.serviceName=a,n+=o;continue}if(i.startsWith(`--service-name=`)){let[e]=r(i,void 0,`--service-name`);t.serviceName=e;continue}throw i===`--help`||i===`-h`?Error(`help`):i.startsWith(`--`)?Error(`Unknown option: ${i}`):Error(`Unknown argument: ${i}`)}return t}function a(){let e=n(process.argv[1]||`process-registry`);return[`Usage: ${e} release-process [options]`,``,`Options:`,` --repository-path <path> Worktree root to clean up (default: process.cwd())`,` --service-name <name> Service name to clean up (default: all services in worktree)`,``,`Examples:`,` ${e} release-process --repository-path /path/to/worktree --service-name mcp-proxy-http`,` ${e} release-process --service-name mcp-proxy-http`,` ${e} release-process --repository-path /path/to/worktree`].join(`
|
|
3
|
+
`)}function o(e){let t=new Map;for(let n of e){let e=[n.repositoryPath,n.serviceName,n.serviceType,n.environment??``,String(n.pid??``)].join(`|`);t.has(e)||t.set(e,n)}return[...t.values()]}async function s(n){let r=e(n.repositoryPath??process.cwd()),i=n.serviceName?.trim(),a=new t(process.env.PROCESS_REGISTRY_PATH),s=await a.listProcesses({repositoryPath:r,...i?{serviceName:i}:{}});if(s.length===0){let e=i?`service ${i} `:``;console.error(`No matching process registrations found for ${e}in worktree ${r}`),process.exit(1)}let c=o(s),l=[];for(let e of c){let t=await a.releaseProcess({repositoryPath:r,serviceName:e.serviceName,serviceType:e.serviceType,environment:e.environment,...e.pid?{pid:e.pid}:{},kill:!0,releasePort:!0});t.success||l.push(`Service ${e.serviceName}: ${t.error??`Unknown error`}`)}if(l.length>0){console.error(`Failed to release ${l.length} entr${l.length===1?`y`:`ies`}:`);for(let e of l)console.error(`- ${e}`);process.exit(1)}i?console.log(`Released ${c.length} process registration(s) for service ${i} in ${r}`):console.log(`Released ${c.length} process registration(s) for worktree ${r}`)}async function c(){let[e=``,...t]=process.argv.slice(2);if(e===`-h`||e===`--help`||e===`help`){console.log(a());return}e!==`release-process`&&(console.error(`Unknown command: ${e||`(none)`}`),console.error(a()),process.exit(1));try{await s(i(t))}catch(e){if(e instanceof Error&&e.message===`help`){console.log(a());return}console.error(e instanceof Error?e.message:`Failed to execute command`),process.exit(1)}}process.argv[1]&&/[\\/](cli\.(ts|mjs|cjs))$/.test(process.argv[1])&&c();export{i as parseReleaseProcessArgs,s as runReleaseProcess};
|
|
4
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["parsed: ReleaseProcessCommandOptions","releaseErrors: string[]"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { basename } from 'node:path';\nimport { ProcessRegistryService } from './services';\nimport { normalizeRepositoryPath } from './utils';\nimport { type ProcessRegistryRecord } from './types';\n\ntype ReleaseProcessCommandOptions = {\n repositoryPath?: string;\n serviceName?: string;\n};\n\nfunction parseValueFromArg(arg: string, nextValue: string | undefined, optionName: string): [string, number] {\n if (arg.includes('=')) {\n const equalsIndex = arg.indexOf('=');\n const value = equalsIndex >= 0 ? arg.slice(equalsIndex + 1) : '';\n if (value.length === 0) {\n throw new Error(`Missing value for ${optionName}`);\n }\n\n return [value, 0];\n }\n\n if (!nextValue || nextValue.startsWith('--')) {\n throw new Error(`Missing value for ${optionName}`);\n }\n\n return [nextValue, 1];\n}\n\nfunction parseReleaseProcessArgs(argv: string[]): ReleaseProcessCommandOptions {\n const parsed: ReleaseProcessCommandOptions = {};\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n if (arg === '--repository-path') {\n const [value, consumed] = parseValueFromArg(arg, argv[index + 1], '--repository-path');\n parsed.repositoryPath = value;\n index += consumed;\n continue;\n }\n\n if (arg.startsWith('--repository-path=')) {\n const [value] = parseValueFromArg(arg, undefined, '--repository-path');\n parsed.repositoryPath = value;\n continue;\n }\n\n if (arg === '--service-name') {\n const [value, consumed] = parseValueFromArg(arg, argv[index + 1], '--service-name');\n parsed.serviceName = value;\n index += consumed;\n continue;\n }\n\n if (arg.startsWith('--service-name=')) {\n const [value] = parseValueFromArg(arg, undefined, '--service-name');\n parsed.serviceName = value;\n continue;\n }\n\n if (arg === '--help' || arg === '-h') {\n throw new Error('help');\n }\n\n if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n }\n\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return parsed;\n}\n\nfunction formatUsage() {\n const command = basename(process.argv[1] || 'process-registry');\n\n return [\n `Usage: ${command} release-process [options]`,\n '',\n 'Options:',\n ' --repository-path <path> Worktree root to clean up (default: process.cwd())',\n ' --service-name <name> Service name to clean up (default: all services in worktree)',\n '',\n 'Examples:',\n ` ${command} release-process --repository-path /path/to/worktree --service-name mcp-proxy-http`,\n ` ${command} release-process --service-name mcp-proxy-http`,\n ` ${command} release-process --repository-path /path/to/worktree`,\n ].join('\\n');\n}\n\nfunction dedupeRecords(records: ProcessRegistryRecord[]): ProcessRegistryRecord[] {\n const byKey = new Map<string, ProcessRegistryRecord>();\n\n for (const record of records) {\n const key = [\n record.repositoryPath,\n record.serviceName,\n record.serviceType,\n record.environment ?? '',\n String(record.pid ?? ''),\n ].join('|');\n if (!byKey.has(key)) {\n byKey.set(key, record);\n }\n }\n\n return [...byKey.values()];\n}\n\nasync function runReleaseProcess(options: ReleaseProcessCommandOptions): Promise<void> {\n const repositoryPath = normalizeRepositoryPath(options.repositoryPath ?? process.cwd());\n const serviceName = options.serviceName?.trim();\n const service = new ProcessRegistryService(process.env.PROCESS_REGISTRY_PATH);\n\n const matches = await service.listProcesses({\n repositoryPath,\n ...(serviceName ? { serviceName } : {}),\n });\n\n if (matches.length === 0) {\n const target = serviceName ? `service ${serviceName} ` : '';\n console.error(`No matching process registrations found for ${target}in worktree ${repositoryPath}`);\n process.exit(1);\n }\n\n const releases = dedupeRecords(matches);\n const releaseErrors: string[] = [];\n\n for (const entry of releases) {\n const response = await service.releaseProcess({\n repositoryPath,\n serviceName: entry.serviceName,\n serviceType: entry.serviceType,\n environment: entry.environment,\n ...(entry.pid ? { pid: entry.pid } : {}),\n kill: true,\n releasePort: true,\n });\n\n if (!response.success) {\n releaseErrors.push(`Service ${entry.serviceName}: ${response.error ?? 'Unknown error'}`);\n }\n }\n\n if (releaseErrors.length > 0) {\n console.error(`Failed to release ${releaseErrors.length} entr${releaseErrors.length === 1 ? 'y' : 'ies'}:`);\n for (const failure of releaseErrors) {\n console.error(`- ${failure}`);\n }\n process.exit(1);\n }\n\n if (serviceName) {\n console.log(`Released ${releases.length} process registration(s) for service ${serviceName} in ${repositoryPath}`);\n } else {\n console.log(`Released ${releases.length} process registration(s) for worktree ${repositoryPath}`);\n }\n}\n\nasync function main() {\n const [command = '', ...rawArgs] = process.argv.slice(2);\n\n if (command === '-h' || command === '--help' || command === 'help') {\n console.log(formatUsage());\n return;\n }\n\n if (command !== 'release-process') {\n console.error(`Unknown command: ${command || '(none)'}`);\n console.error(formatUsage());\n process.exit(1);\n }\n\n try {\n const options = parseReleaseProcessArgs(rawArgs);\n await runReleaseProcess(options);\n } catch (error) {\n if (error instanceof Error && error.message === 'help') {\n console.log(formatUsage());\n return;\n }\n\n console.error(error instanceof Error ? error.message : 'Failed to execute command');\n process.exit(1);\n }\n}\n\nif (process.argv[1] && /[\\\\/](cli\\.(ts|mjs|cjs))$/.test(process.argv[1])) {\n void main();\n}\n\nexport { parseReleaseProcessArgs, runReleaseProcess };\n"],"mappings":";wFAYA,SAAS,EA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,QAAQ,MAAM,qBAAqB,EAAc,OAAO,OAAO,EAAc,SAAW,EAAI,IAAM,MAAM,GAAG,CAC3G,IAAK,IAAM,KAAW,EACpB,QAAQ,MAAM,KAAK,IAAU,CAE/B,QAAQ,KAAK,EAAE,CAGb,EACF,QAAQ,IAAI,YAAY,EAAS,OAAO,uCAAuC,EAAY,MAAM,IAAiB,CAElH,QAAQ,IAAI,YAAY,EAAS,OAAO,wCAAwC,IAAiB,CAIrG,eAAe,GAAO,CACpB,GAAM,CAAC,EAAU,GAAI,GAAG,GAAW,QAAQ,KAAK,MAAM,EAAE,CAExD,GAAI,IAAY,MAAQ,IAAY,UAAY,IAAY,OAAQ,CAClE,QAAQ,IAAI,GAAa,CAAC,CAC1B,OAGE,IAAY,oBACd,QAAQ,MAAM,oBAAoB,GAAW,WAAW,CACxD,QAAQ,MAAM,GAAa,CAAC,CAC5B,QAAQ,KAAK,EAAE,EAGjB,GAAI,CAEF,MAAM,EADU,EAAwB,EAAQ,CAChB,OACzB,EAAO,CACd,GAAI,aAAiB,OAAS,EAAM,UAAY,OAAQ,CACtD,QAAQ,IAAI,GAAa,CAAC,CAC1B,OAGF,QAAQ,MAAM,aAAiB,MAAQ,EAAM,QAAU,4BAA4B,CACnF,QAAQ,KAAK,EAAE,EAIf,QAAQ,KAAK,IAAM,4BAA4B,KAAK,QAAQ,KAAK,GAAG,EACjE,GAAM"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./ProcessRegistryService.cjs`);exports.DEFAULT_REGISTRY_LOCK_PATH=e.n,exports.DEFAULT_REGISTRY_PATH=e.r,exports.LOCK_MAX_RETRIES=e.i,exports.LOCK_RETRY_DELAY_MS=e.a,exports.ListProcessFiltersSchema=e.c,exports.ProcessMetadataSchema=e.l,exports.ProcessRegistryError=e.u,exports.ProcessRegistryRecordSchema=e.d,exports.ProcessRegistryResponseSchema=e.f,exports.ProcessRegistryService=e.t,exports.ProcessRegistryStateSchema=e.p,exports.REGISTRY_VERSION=e.m,exports.RegisterProcessRequestSchema=e.h,exports.ReleaseProcessRequestSchema=e.g,exports.ServiceCategorySchema=e._,exports.makeTempPath=e.o,exports.normalizeRepositoryPath=e.s;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PortRegistryService } from "@agimon-ai/foundation-port-registry";
|
|
3
|
+
|
|
4
|
+
//#region src/types/index.d.ts
|
|
5
|
+
declare const REGISTRY_VERSION: 1;
|
|
6
|
+
declare const ServiceCategorySchema: z.ZodEnum<{
|
|
7
|
+
service: "service";
|
|
8
|
+
tool: "tool";
|
|
9
|
+
}>;
|
|
10
|
+
declare const ProcessMetadataSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
11
|
+
declare const ProcessRegistryRecordSchema: z.ZodObject<{
|
|
12
|
+
repositoryPath: z.ZodString;
|
|
13
|
+
serviceName: z.ZodString;
|
|
14
|
+
serviceType: z.ZodEnum<{
|
|
15
|
+
service: "service";
|
|
16
|
+
tool: "tool";
|
|
17
|
+
}>;
|
|
18
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
19
|
+
pid: z.ZodNumber;
|
|
20
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
host: z.ZodOptional<z.ZodString>;
|
|
22
|
+
command: z.ZodOptional<z.ZodString>;
|
|
23
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
25
|
+
createdAt: z.ZodString;
|
|
26
|
+
updatedAt: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
declare const ProcessRegistryStateSchema: z.ZodObject<{
|
|
29
|
+
version: z.ZodLiteral<1>;
|
|
30
|
+
updatedAt: z.ZodString;
|
|
31
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
32
|
+
repositoryPath: z.ZodString;
|
|
33
|
+
serviceName: z.ZodString;
|
|
34
|
+
serviceType: z.ZodEnum<{
|
|
35
|
+
service: "service";
|
|
36
|
+
tool: "tool";
|
|
37
|
+
}>;
|
|
38
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
39
|
+
pid: z.ZodNumber;
|
|
40
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
host: z.ZodOptional<z.ZodString>;
|
|
42
|
+
command: z.ZodOptional<z.ZodString>;
|
|
43
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
44
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
|
+
createdAt: z.ZodString;
|
|
46
|
+
updatedAt: z.ZodString;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
declare const RegisterProcessRequestSchema: z.ZodObject<{
|
|
50
|
+
repositoryPath: z.ZodString;
|
|
51
|
+
serviceName: z.ZodString;
|
|
52
|
+
serviceType: z.ZodDefault<z.ZodEnum<{
|
|
53
|
+
service: "service";
|
|
54
|
+
tool: "tool";
|
|
55
|
+
}>>;
|
|
56
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
57
|
+
pid: z.ZodNumber;
|
|
58
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
host: z.ZodOptional<z.ZodString>;
|
|
60
|
+
command: z.ZodOptional<z.ZodString>;
|
|
61
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
63
|
+
force: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
declare const ReleaseProcessRequestSchema: z.ZodObject<{
|
|
66
|
+
repositoryPath: z.ZodString;
|
|
67
|
+
serviceName: z.ZodString;
|
|
68
|
+
serviceType: z.ZodOptional<z.ZodEnum<{
|
|
69
|
+
service: "service";
|
|
70
|
+
tool: "tool";
|
|
71
|
+
}>>;
|
|
72
|
+
pid: z.ZodOptional<z.ZodNumber>;
|
|
73
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
74
|
+
force: z.ZodOptional<z.ZodBoolean>;
|
|
75
|
+
kill: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
76
|
+
releasePort: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
declare const ListProcessFiltersSchema: z.ZodObject<{
|
|
79
|
+
repositoryPath: z.ZodOptional<z.ZodString>;
|
|
80
|
+
serviceType: z.ZodOptional<z.ZodEnum<{
|
|
81
|
+
service: "service";
|
|
82
|
+
tool: "tool";
|
|
83
|
+
}>>;
|
|
84
|
+
serviceName: z.ZodOptional<z.ZodString>;
|
|
85
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
declare const ProcessRegistryResponseSchema: z.ZodObject<{
|
|
88
|
+
success: z.ZodBoolean;
|
|
89
|
+
pid: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
record: z.ZodOptional<z.ZodObject<{
|
|
91
|
+
repositoryPath: z.ZodString;
|
|
92
|
+
serviceName: z.ZodString;
|
|
93
|
+
serviceType: z.ZodEnum<{
|
|
94
|
+
service: "service";
|
|
95
|
+
tool: "tool";
|
|
96
|
+
}>;
|
|
97
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
98
|
+
pid: z.ZodNumber;
|
|
99
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
host: z.ZodOptional<z.ZodString>;
|
|
101
|
+
command: z.ZodOptional<z.ZodString>;
|
|
102
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
103
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
104
|
+
createdAt: z.ZodString;
|
|
105
|
+
updatedAt: z.ZodString;
|
|
106
|
+
}, z.core.$strip>>;
|
|
107
|
+
error: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
type ServiceCategory = z.infer<typeof ServiceCategorySchema>;
|
|
110
|
+
type ProcessMetadata = z.infer<typeof ProcessMetadataSchema>;
|
|
111
|
+
type ProcessRegistryRecord = z.infer<typeof ProcessRegistryRecordSchema>;
|
|
112
|
+
type ProcessRegistryState = z.infer<typeof ProcessRegistryStateSchema>;
|
|
113
|
+
type RegisterProcessRequest = z.infer<typeof RegisterProcessRequestSchema>;
|
|
114
|
+
type ReleaseProcessRequest = z.infer<typeof ReleaseProcessRequestSchema>;
|
|
115
|
+
type ListProcessFilters = z.infer<typeof ListProcessFiltersSchema>;
|
|
116
|
+
type ProcessRegistryResponse = z.infer<typeof ProcessRegistryResponseSchema>;
|
|
117
|
+
type ProcessRegistryErrorCode = 'INVALID_REQUEST' | 'REGISTRY_READ_FAILED' | 'REGISTRY_WRITE_FAILED' | 'REGISTRY_LOCK_FAILED' | 'NO_PROCESS_FOUND';
|
|
118
|
+
declare class ProcessRegistryError extends Error {
|
|
119
|
+
readonly code: ProcessRegistryErrorCode;
|
|
120
|
+
constructor(message: string, code: ProcessRegistryErrorCode, options?: ErrorOptions);
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/services/ProcessRegistryService.d.ts
|
|
124
|
+
type PortRegistryCleanup = Pick<PortRegistryService, 'releasePort'>;
|
|
125
|
+
declare class ProcessRegistryService {
|
|
126
|
+
private readonly portRegistry;
|
|
127
|
+
private readonly registryPath;
|
|
128
|
+
private readonly lockPath;
|
|
129
|
+
constructor(registryPath?: string, lockPath?: string, portRegistry?: PortRegistryCleanup);
|
|
130
|
+
static resolveRegistryPath(inputPath?: string): string;
|
|
131
|
+
registerProcess(rawRequest: RegisterProcessRequest): Promise<ProcessRegistryResponse>;
|
|
132
|
+
releaseProcess(rawRequest: ReleaseProcessRequest): Promise<ProcessRegistryResponse>;
|
|
133
|
+
listProcesses(filters?: ListProcessFilters): Promise<ProcessRegistryRecord[]>;
|
|
134
|
+
private withLock;
|
|
135
|
+
private loadState;
|
|
136
|
+
private saveState;
|
|
137
|
+
private pruneState;
|
|
138
|
+
private pruneMissingRepositories;
|
|
139
|
+
private pruneDeadProcesses;
|
|
140
|
+
private acquireLock;
|
|
141
|
+
private releaseLock;
|
|
142
|
+
private isStaleLock;
|
|
143
|
+
private isProcessRunning;
|
|
144
|
+
private terminateProcess;
|
|
145
|
+
private releaseAssociatedPort;
|
|
146
|
+
private entryKey;
|
|
147
|
+
private findEntry;
|
|
148
|
+
private removeMatchingEntries;
|
|
149
|
+
private createSuccessResponse;
|
|
150
|
+
private createFailureResponse;
|
|
151
|
+
private pathExists;
|
|
152
|
+
private delay;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/utils/index.d.ts
|
|
156
|
+
declare const DEFAULT_REGISTRY_PATH: string;
|
|
157
|
+
declare const DEFAULT_REGISTRY_LOCK_PATH: string;
|
|
158
|
+
declare const LOCK_RETRY_DELAY_MS = 75;
|
|
159
|
+
declare const LOCK_MAX_RETRIES = 80;
|
|
160
|
+
declare const normalizeRepositoryPath: (value: string) => string;
|
|
161
|
+
declare const makeTempPath: (filePath: string) => string;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { DEFAULT_REGISTRY_LOCK_PATH, DEFAULT_REGISTRY_PATH, LOCK_MAX_RETRIES, LOCK_RETRY_DELAY_MS, ListProcessFilters, ListProcessFiltersSchema, ProcessMetadata, ProcessMetadataSchema, ProcessRegistryError, ProcessRegistryErrorCode, ProcessRegistryRecord, ProcessRegistryRecordSchema, ProcessRegistryResponse, ProcessRegistryResponseSchema, ProcessRegistryService, ProcessRegistryState, ProcessRegistryStateSchema, REGISTRY_VERSION, RegisterProcessRequest, RegisterProcessRequestSchema, ReleaseProcessRequest, ReleaseProcessRequestSchema, ServiceCategory, ServiceCategorySchema, makeTempPath, normalizeRepositoryPath };
|
|
164
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PortRegistryService } from "@agimon-ai/foundation-port-registry";
|
|
3
|
+
|
|
4
|
+
//#region src/types/index.d.ts
|
|
5
|
+
declare const REGISTRY_VERSION: 1;
|
|
6
|
+
declare const ServiceCategorySchema: z.ZodEnum<{
|
|
7
|
+
service: "service";
|
|
8
|
+
tool: "tool";
|
|
9
|
+
}>;
|
|
10
|
+
declare const ProcessMetadataSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
11
|
+
declare const ProcessRegistryRecordSchema: z.ZodObject<{
|
|
12
|
+
repositoryPath: z.ZodString;
|
|
13
|
+
serviceName: z.ZodString;
|
|
14
|
+
serviceType: z.ZodEnum<{
|
|
15
|
+
service: "service";
|
|
16
|
+
tool: "tool";
|
|
17
|
+
}>;
|
|
18
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
19
|
+
pid: z.ZodNumber;
|
|
20
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
host: z.ZodOptional<z.ZodString>;
|
|
22
|
+
command: z.ZodOptional<z.ZodString>;
|
|
23
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
25
|
+
createdAt: z.ZodString;
|
|
26
|
+
updatedAt: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
declare const ProcessRegistryStateSchema: z.ZodObject<{
|
|
29
|
+
version: z.ZodLiteral<1>;
|
|
30
|
+
updatedAt: z.ZodString;
|
|
31
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
32
|
+
repositoryPath: z.ZodString;
|
|
33
|
+
serviceName: z.ZodString;
|
|
34
|
+
serviceType: z.ZodEnum<{
|
|
35
|
+
service: "service";
|
|
36
|
+
tool: "tool";
|
|
37
|
+
}>;
|
|
38
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
39
|
+
pid: z.ZodNumber;
|
|
40
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
host: z.ZodOptional<z.ZodString>;
|
|
42
|
+
command: z.ZodOptional<z.ZodString>;
|
|
43
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
44
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
|
+
createdAt: z.ZodString;
|
|
46
|
+
updatedAt: z.ZodString;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
declare const RegisterProcessRequestSchema: z.ZodObject<{
|
|
50
|
+
repositoryPath: z.ZodString;
|
|
51
|
+
serviceName: z.ZodString;
|
|
52
|
+
serviceType: z.ZodDefault<z.ZodEnum<{
|
|
53
|
+
service: "service";
|
|
54
|
+
tool: "tool";
|
|
55
|
+
}>>;
|
|
56
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
57
|
+
pid: z.ZodNumber;
|
|
58
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
host: z.ZodOptional<z.ZodString>;
|
|
60
|
+
command: z.ZodOptional<z.ZodString>;
|
|
61
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
63
|
+
force: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
declare const ReleaseProcessRequestSchema: z.ZodObject<{
|
|
66
|
+
repositoryPath: z.ZodString;
|
|
67
|
+
serviceName: z.ZodString;
|
|
68
|
+
serviceType: z.ZodOptional<z.ZodEnum<{
|
|
69
|
+
service: "service";
|
|
70
|
+
tool: "tool";
|
|
71
|
+
}>>;
|
|
72
|
+
pid: z.ZodOptional<z.ZodNumber>;
|
|
73
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
74
|
+
force: z.ZodOptional<z.ZodBoolean>;
|
|
75
|
+
kill: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
76
|
+
releasePort: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
declare const ListProcessFiltersSchema: z.ZodObject<{
|
|
79
|
+
repositoryPath: z.ZodOptional<z.ZodString>;
|
|
80
|
+
serviceType: z.ZodOptional<z.ZodEnum<{
|
|
81
|
+
service: "service";
|
|
82
|
+
tool: "tool";
|
|
83
|
+
}>>;
|
|
84
|
+
serviceName: z.ZodOptional<z.ZodString>;
|
|
85
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
declare const ProcessRegistryResponseSchema: z.ZodObject<{
|
|
88
|
+
success: z.ZodBoolean;
|
|
89
|
+
pid: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
record: z.ZodOptional<z.ZodObject<{
|
|
91
|
+
repositoryPath: z.ZodString;
|
|
92
|
+
serviceName: z.ZodString;
|
|
93
|
+
serviceType: z.ZodEnum<{
|
|
94
|
+
service: "service";
|
|
95
|
+
tool: "tool";
|
|
96
|
+
}>;
|
|
97
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
98
|
+
pid: z.ZodNumber;
|
|
99
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
host: z.ZodOptional<z.ZodString>;
|
|
101
|
+
command: z.ZodOptional<z.ZodString>;
|
|
102
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
103
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
104
|
+
createdAt: z.ZodString;
|
|
105
|
+
updatedAt: z.ZodString;
|
|
106
|
+
}, z.core.$strip>>;
|
|
107
|
+
error: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
type ServiceCategory = z.infer<typeof ServiceCategorySchema>;
|
|
110
|
+
type ProcessMetadata = z.infer<typeof ProcessMetadataSchema>;
|
|
111
|
+
type ProcessRegistryRecord = z.infer<typeof ProcessRegistryRecordSchema>;
|
|
112
|
+
type ProcessRegistryState = z.infer<typeof ProcessRegistryStateSchema>;
|
|
113
|
+
type RegisterProcessRequest = z.infer<typeof RegisterProcessRequestSchema>;
|
|
114
|
+
type ReleaseProcessRequest = z.infer<typeof ReleaseProcessRequestSchema>;
|
|
115
|
+
type ListProcessFilters = z.infer<typeof ListProcessFiltersSchema>;
|
|
116
|
+
type ProcessRegistryResponse = z.infer<typeof ProcessRegistryResponseSchema>;
|
|
117
|
+
type ProcessRegistryErrorCode = 'INVALID_REQUEST' | 'REGISTRY_READ_FAILED' | 'REGISTRY_WRITE_FAILED' | 'REGISTRY_LOCK_FAILED' | 'NO_PROCESS_FOUND';
|
|
118
|
+
declare class ProcessRegistryError extends Error {
|
|
119
|
+
readonly code: ProcessRegistryErrorCode;
|
|
120
|
+
constructor(message: string, code: ProcessRegistryErrorCode, options?: ErrorOptions);
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/services/ProcessRegistryService.d.ts
|
|
124
|
+
type PortRegistryCleanup = Pick<PortRegistryService, 'releasePort'>;
|
|
125
|
+
declare class ProcessRegistryService {
|
|
126
|
+
private readonly portRegistry;
|
|
127
|
+
private readonly registryPath;
|
|
128
|
+
private readonly lockPath;
|
|
129
|
+
constructor(registryPath?: string, lockPath?: string, portRegistry?: PortRegistryCleanup);
|
|
130
|
+
static resolveRegistryPath(inputPath?: string): string;
|
|
131
|
+
registerProcess(rawRequest: RegisterProcessRequest): Promise<ProcessRegistryResponse>;
|
|
132
|
+
releaseProcess(rawRequest: ReleaseProcessRequest): Promise<ProcessRegistryResponse>;
|
|
133
|
+
listProcesses(filters?: ListProcessFilters): Promise<ProcessRegistryRecord[]>;
|
|
134
|
+
private withLock;
|
|
135
|
+
private loadState;
|
|
136
|
+
private saveState;
|
|
137
|
+
private pruneState;
|
|
138
|
+
private pruneMissingRepositories;
|
|
139
|
+
private pruneDeadProcesses;
|
|
140
|
+
private acquireLock;
|
|
141
|
+
private releaseLock;
|
|
142
|
+
private isStaleLock;
|
|
143
|
+
private isProcessRunning;
|
|
144
|
+
private terminateProcess;
|
|
145
|
+
private releaseAssociatedPort;
|
|
146
|
+
private entryKey;
|
|
147
|
+
private findEntry;
|
|
148
|
+
private removeMatchingEntries;
|
|
149
|
+
private createSuccessResponse;
|
|
150
|
+
private createFailureResponse;
|
|
151
|
+
private pathExists;
|
|
152
|
+
private delay;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/utils/index.d.ts
|
|
156
|
+
declare const DEFAULT_REGISTRY_PATH: string;
|
|
157
|
+
declare const DEFAULT_REGISTRY_LOCK_PATH: string;
|
|
158
|
+
declare const LOCK_RETRY_DELAY_MS = 75;
|
|
159
|
+
declare const LOCK_MAX_RETRIES = 80;
|
|
160
|
+
declare const normalizeRepositoryPath: (value: string) => string;
|
|
161
|
+
declare const makeTempPath: (filePath: string) => string;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { DEFAULT_REGISTRY_LOCK_PATH, DEFAULT_REGISTRY_PATH, LOCK_MAX_RETRIES, LOCK_RETRY_DELAY_MS, ListProcessFilters, ListProcessFiltersSchema, ProcessMetadata, ProcessMetadataSchema, ProcessRegistryError, ProcessRegistryErrorCode, ProcessRegistryRecord, ProcessRegistryRecordSchema, ProcessRegistryResponse, ProcessRegistryResponseSchema, ProcessRegistryService, ProcessRegistryState, ProcessRegistryStateSchema, REGISTRY_VERSION, RegisterProcessRequest, RegisterProcessRequestSchema, ReleaseProcessRequest, ReleaseProcessRequestSchema, ServiceCategory, ServiceCategorySchema, makeTempPath, normalizeRepositoryPath };
|
|
164
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./ProcessRegistryService.mjs";export{u as DEFAULT_REGISTRY_LOCK_PATH,p as DEFAULT_REGISTRY_PATH,s as LOCK_MAX_RETRIES,t as LOCK_RETRY_DELAY_MS,n as ListProcessFiltersSchema,c as ProcessMetadataSchema,g as ProcessRegistryError,r as ProcessRegistryRecordSchema,i as ProcessRegistryResponseSchema,h as ProcessRegistryService,f as ProcessRegistryStateSchema,l as REGISTRY_VERSION,o as RegisterProcessRequestSchema,a as ReleaseProcessRequestSchema,e as ServiceCategorySchema,d as makeTempPath,m as normalizeRepositoryPath};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agimon-ai/foundation-process-registry",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Long-running process registry and cleanup coordination across worktrees",
|
|
5
|
+
"bin": {
|
|
6
|
+
"process-registry": "./dist/cli.cjs"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"zod": "4.3.6",
|
|
17
|
+
"@agimon-ai/foundation-port-registry": "0.2.4"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.0.0",
|
|
21
|
+
"tsdown": "0.16.1",
|
|
22
|
+
"typescript": "5.9.3",
|
|
23
|
+
"vitest": "4.0.18"
|
|
24
|
+
},
|
|
25
|
+
"author": "Vuong Ngo",
|
|
26
|
+
"license": "BUSL-1.1",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./*": "./*"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"test": "vitest run --coverage.enabled=false",
|
|
43
|
+
"lint": "eslint src",
|
|
44
|
+
"fixcode": "pnpm exec biome check --write",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|