MCPcopy Create free account
hub / github.com/Tencent/teamai-cli / parseLockContent

Function parseLockContent

src/update.ts:140–154  ·  view source on GitHub ↗

* Parse a lock file's contents. Understands both the current JSON payload and * the legacy plain-integer PID format written by older teamai versions, so an * on-disk lock from a previous install is still evaluated for staleness rather * than treated as un-owned garbage.

(content: string)

Source from the content-addressed store, hash-verified

138 * than treated as un-owned garbage.
139 */
140function parseLockContent(content: string): { pid: number; owner?: string } | null {
141 const trimmed = content.trim();
142 if (!trimmed) return null;
143 try {
144 const parsed = JSON.parse(trimmed) as Partial<LockPayload>;
145 if (typeof parsed.pid === 'number' && !isNaN(parsed.pid)) {
146 return { pid: parsed.pid, owner: typeof parsed.owner === 'string' ? parsed.owner : undefined };
147 }
148 return null;
149 } catch {
150 // Legacy format: the file held only the bare PID as a string.
151 const pid = parseInt(trimmed, 10);
152 return isNaN(pid) ? null : { pid };
153 }
154}
155
156/**
157 * Inspect the lock at `resolved` and report whether it is stale — its owning

Callers 3

isLockStaleFunction · 0.85
removeIfOwnerFunction · 0.85
releaseLockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected