Skip to content

Commit f41b391

Browse files
committed
refactor: parse ACPX lease command identity
1 parent 8455593 commit f41b391

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎extensions/acpx/src/process-lease.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
openAcpxProcessLeaseStateStore,
1313
OPENCLAW_ACPX_LEASE_ID_ARG,
1414
OPENCLAW_GATEWAY_INSTANCE_ID_ARG,
15+
readAcpxProcessLeaseIdentity,
1516
withAcpxLeaseEnvironment,
1617
type AcpxProcessLease,
1718
} from "./process-lease.js";
@@ -113,3 +114,29 @@ describe("withAcpxLeaseEnvironment", () => {
113114
);
114115
});
115116
});
117+
118+
describe("readAcpxProcessLeaseIdentity", () => {
119+
it("reads quoted portable lease wrapper args", () => {
120+
expect(
121+
readAcpxProcessLeaseIdentity(
122+
[
123+
"node /tmp/openclaw/acpx/codex-acp-wrapper.mjs",
124+
OPENCLAW_ACPX_LEASE_ID_ARG,
125+
"'lease test'",
126+
OPENCLAW_GATEWAY_INSTANCE_ID_ARG,
127+
'"gateway test"',
128+
].join(" "),
129+
),
130+
).toEqual({
131+
leaseId: "lease test",
132+
gatewayInstanceId: "gateway test",
133+
});
134+
});
135+
136+
it("rejects incomplete lease identity", () => {
137+
expect(
138+
readAcpxProcessLeaseIdentity(`node wrapper.mjs ${OPENCLAW_ACPX_LEASE_ID_ARG} lease-test`),
139+
).toBeUndefined();
140+
expect(readAcpxProcessLeaseIdentity(undefined)).toBeUndefined();
141+
});
142+
});

‎extensions/acpx/src/process-lease.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,34 @@ import type {
77
OpenKeyedStoreOptions,
88
PluginStateKeyedStore,
99
} from "openclaw/plugin-sdk/plugin-state-runtime";
10+
import { splitCommandParts } from "./command-line.js";
1011
import { ACPX_PROCESS_LEASE_MAX_ENTRIES, ACPX_PROCESS_LEASE_NAMESPACE } from "./state.js";
1112

1213
/** CLI argument carrying the ACPX process lease id. */
1314
export const OPENCLAW_ACPX_LEASE_ID_ARG = "--openclaw-acpx-lease-id";
1415
/** CLI argument carrying the owning gateway instance id. */
1516
export const OPENCLAW_GATEWAY_INSTANCE_ID_ARG = "--openclaw-gateway-instance-id";
1617

18+
export type AcpxProcessLeaseIdentity = {
19+
leaseId: string;
20+
gatewayInstanceId: string;
21+
};
22+
23+
/** Read OpenClaw lease identity from a generated wrapper command. */
24+
export function readAcpxProcessLeaseIdentity(
25+
command: string | undefined,
26+
): AcpxProcessLeaseIdentity | undefined {
27+
const parts = splitCommandParts(command?.trim() ?? "");
28+
const leaseIndex = parts.lastIndexOf(OPENCLAW_ACPX_LEASE_ID_ARG);
29+
const gatewayIndex = parts.lastIndexOf(OPENCLAW_GATEWAY_INSTANCE_ID_ARG);
30+
const leaseId = leaseIndex >= 0 ? parts[leaseIndex + 1]?.trim() : "";
31+
const gatewayInstanceId = gatewayIndex >= 0 ? parts[gatewayIndex + 1]?.trim() : "";
32+
if (!leaseId || !gatewayInstanceId) {
33+
return undefined;
34+
}
35+
return { leaseId, gatewayInstanceId };
36+
}
37+
1738
/** Lifecycle state for a tracked ACPX wrapper process. */
1839
type AcpxProcessLeaseState = "open" | "closing" | "closed" | "lost";
1940

0 commit comments

Comments
 (0)