@trycadence/cli 0.1.18-dev.0 → 0.1.19-dev.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.
Files changed (2) hide show
  1. package/dist/cadence +61 -1
  2. package/package.json +1 -1
package/dist/cadence CHANGED
@@ -1488,6 +1488,7 @@ function createCadenceClient(options = {}) {
1488
1488
  current: (input) => rpc.sessions.current.query(input),
1489
1489
  leases: {
1490
1490
  create: (input) => rpc.sessions.leases.create.mutate(input),
1491
+ renew: (input) => rpc.sessions.leases.renew.mutate(input),
1491
1492
  release: (input) => rpc.sessions.leases.release.mutate(input)
1492
1493
  }
1493
1494
  },
@@ -1520,7 +1521,7 @@ import { createInterface } from "readline/promises";
1520
1521
  // package.json
1521
1522
  var package_default = {
1522
1523
  name: "@trycadence/cli",
1523
- version: "0.1.18-dev.0",
1524
+ version: "0.1.19-dev.0",
1524
1525
  private: false,
1525
1526
  type: "module",
1526
1527
  bin: {
@@ -3308,6 +3309,8 @@ function readAgentSessionCadenceContext(record) {
3308
3309
  ...typeof contextRecord.ticketId === "string" ? { ticketId: contextRecord.ticketId } : {},
3309
3310
  ...typeof contextRecord.sessionId === "string" ? { sessionId: contextRecord.sessionId } : {},
3310
3311
  ...typeof contextRecord.changesetId === "string" ? { changesetId: contextRecord.changesetId } : {},
3312
+ ...typeof contextRecord.leaseId === "string" ? { leaseId: contextRecord.leaseId } : {},
3313
+ ...typeof contextRecord.leaseExpiresAt === "string" ? { leaseExpiresAt: contextRecord.leaseExpiresAt } : {},
3311
3314
  ...typeof contextRecord.capturedAt === "string" ? { capturedAt: contextRecord.capturedAt } : {}
3312
3315
  };
3313
3316
  return cadenceContext.ticketId || cadenceContext.sessionId || cadenceContext.changesetId ? { cadenceContext } : {};
@@ -3501,6 +3504,8 @@ function activeSessionFromCurrent(current) {
3501
3504
  ...sessionId ? { id: sessionId } : {},
3502
3505
  ticketId: leaseRecord.ticketId,
3503
3506
  ...typeof leaseRecord.changesetId === "string" ? { changesetId: leaseRecord.changesetId } : typeof sessionRecord.changesetId === "string" ? { changesetId: sessionRecord.changesetId } : {},
3507
+ ...typeof leaseRecord.id === "string" ? { leaseId: leaseRecord.id } : {},
3508
+ ...typeof leaseRecord.expiresAt === "string" ? { leaseExpiresAt: leaseRecord.expiresAt } : {},
3504
3509
  status: "active"
3505
3510
  };
3506
3511
  }
@@ -3525,6 +3530,8 @@ function cadenceContextFromCurrent(current) {
3525
3530
  const ticketId = typeof activeSession.ticketId === "string" ? activeSession.ticketId : undefined;
3526
3531
  const sessionId = typeof activeSession.id === "string" ? activeSession.id : undefined;
3527
3532
  const changesetId = typeof activeSession.changesetId === "string" ? activeSession.changesetId : undefined;
3533
+ const leaseId = typeof activeSession.leaseId === "string" ? activeSession.leaseId : undefined;
3534
+ const leaseExpiresAt2 = typeof activeSession.leaseExpiresAt === "string" ? activeSession.leaseExpiresAt : undefined;
3528
3535
  if (!ticketId && !sessionId && !changesetId) {
3529
3536
  return;
3530
3537
  }
@@ -3532,9 +3539,41 @@ function cadenceContextFromCurrent(current) {
3532
3539
  ...ticketId ? { ticketId } : {},
3533
3540
  ...sessionId ? { sessionId } : {},
3534
3541
  ...changesetId ? { changesetId } : {},
3542
+ ...leaseId ? { leaseId } : {},
3543
+ ...leaseExpiresAt2 ? { leaseExpiresAt: leaseExpiresAt2 } : {},
3535
3544
  capturedAt: new Date().toISOString()
3536
3545
  };
3537
3546
  }
3547
+ function leaseExpiresAtFromResponse(value) {
3548
+ return value && typeof value === "object" && "expiresAt" in value && typeof value.expiresAt === "string" ? value.expiresAt : undefined;
3549
+ }
3550
+ async function renewAgentSessionLease(client, projectId, context) {
3551
+ if (!context?.leaseId) {
3552
+ return context;
3553
+ }
3554
+ const expiresAt = leaseExpiresAt(defaultLeaseTtlSeconds);
3555
+ const renewed = await client.sessions.leases.renew({
3556
+ projectId,
3557
+ leaseId: context.leaseId,
3558
+ lease: {
3559
+ expiresAt,
3560
+ ...commandMetadata()
3561
+ }
3562
+ });
3563
+ return {
3564
+ ...context,
3565
+ leaseId: objectStringId(renewed) ?? context.leaseId,
3566
+ leaseExpiresAt: leaseExpiresAtFromResponse(renewed) ?? expiresAt,
3567
+ capturedAt: new Date().toISOString()
3568
+ };
3569
+ }
3570
+ async function renewAgentSessionLeaseBestEffort(client, projectId, context) {
3571
+ try {
3572
+ return await renewAgentSessionLease(client, projectId, context);
3573
+ } catch {
3574
+ return context;
3575
+ }
3576
+ }
3538
3577
  async function readCurrentCadenceContext(client, projectId) {
3539
3578
  const current = await client.sessions.current({
3540
3579
  projectId,
@@ -4864,6 +4903,9 @@ async function runAgentRunIngestStop(parsed, options, config, meta) {
4864
4903
  try {
4865
4904
  const client = await createClient(config, options);
4866
4905
  cadenceContext = await readCurrentCadenceContext(client, projectId) ?? cadenceContext;
4906
+ if (!duplicateTurn) {
4907
+ cadenceContext = await renewAgentSessionLeaseBestEffort(client, projectId, cadenceContext);
4908
+ }
4867
4909
  } catch {}
4868
4910
  }
4869
4911
  const observedSession = {
@@ -5325,6 +5367,8 @@ async function runAgentRunRoute(parsed, options, config, meta) {
5325
5367
  let targetTicketId = currentTicketId;
5326
5368
  let targetSessionId = currentSessionId;
5327
5369
  let targetChangesetId = currentChangesetId;
5370
+ let targetLeaseId = savedContext?.leaseId ?? currentContext?.leaseId;
5371
+ let targetLeaseExpiresAt = savedContext?.leaseExpiresAt ?? currentContext?.leaseExpiresAt;
5328
5372
  let intakeResult;
5329
5373
  let selectedTicket;
5330
5374
  let summary = routePlan.summary ?? routePlan.entries[0]?.summary ?? routePlan.route.reason ?? "Agent run route";
@@ -5354,6 +5398,8 @@ async function runAgentRunRoute(parsed, options, config, meta) {
5354
5398
  ...targetTicketId ? { ticketId: targetTicketId } : {},
5355
5399
  ...targetSessionId ? { sessionId: targetSessionId } : {},
5356
5400
  ...targetChangesetId ? { changesetId: targetChangesetId } : {},
5401
+ ...targetLeaseId ? { leaseId: targetLeaseId } : {},
5402
+ ...targetLeaseExpiresAt ? { leaseExpiresAt: targetLeaseExpiresAt } : {},
5357
5403
  ...eventFile ? { eventFile } : {},
5358
5404
  event,
5359
5405
  prompt,
@@ -5382,6 +5428,8 @@ async function runAgentRunRoute(parsed, options, config, meta) {
5382
5428
  ticketId: targetTicketId,
5383
5429
  ...targetSessionId ? { sessionId: targetSessionId } : {},
5384
5430
  ...targetChangesetId ? { changesetId: targetChangesetId } : {},
5431
+ ...targetLeaseId ? { leaseId: targetLeaseId } : {},
5432
+ ...targetLeaseExpiresAt ? { leaseExpiresAt: targetLeaseExpiresAt } : {},
5385
5433
  capturedAt: checkedAt
5386
5434
  }
5387
5435
  } : {},
@@ -5549,6 +5597,8 @@ async function runAgentRunRoute(parsed, options, config, meta) {
5549
5597
  ...commandMetadata()
5550
5598
  }
5551
5599
  });
5600
+ targetLeaseId = objectStringId(lease);
5601
+ targetLeaseExpiresAt = leaseExpiresAtFromResponse(lease);
5552
5602
  lifecycleOperations.push(checkpointLifecycleOperation("lease.claimed", true, { ticketId: targetTicketId, sessionId: targetSessionId, lease }));
5553
5603
  }
5554
5604
  if (targetSessionId) {
@@ -5638,6 +5688,8 @@ async function runAgentRunCheckpoint(parsed, options, config, meta) {
5638
5688
  const ticketId = parsed.options.ticket ?? savedContext?.ticketId ?? currentContext?.ticketId;
5639
5689
  const sessionId = parsed.options.session ?? savedContext?.sessionId ?? currentContext?.sessionId;
5640
5690
  const changesetId = parsed.options.changeset ?? savedContext?.changesetId ?? currentContext?.changesetId;
5691
+ const leaseId = savedContext?.leaseId ?? currentContext?.leaseId;
5692
+ const leaseExpiresAtValue = savedContext?.leaseExpiresAt ?? currentContext?.leaseExpiresAt;
5641
5693
  if (!ticketId) {
5642
5694
  await writeAgentLoopState(parsed, options, {
5643
5695
  ...state,
@@ -5934,6 +5986,8 @@ async function runAgentRunCheckpoint(parsed, options, config, meta) {
5934
5986
  ticketId,
5935
5987
  ...sessionId ? { sessionId } : {},
5936
5988
  ...changesetId ? { changesetId } : {},
5989
+ ...leaseId ? { leaseId } : {},
5990
+ ...leaseExpiresAtValue ? { leaseExpiresAt: leaseExpiresAtValue } : {},
5937
5991
  capturedAt: checkedAt
5938
5992
  },
5939
5993
  lastCheckpointAt: checkedAt,
@@ -5972,6 +6026,8 @@ async function runAgentRunCheckpoint(parsed, options, config, meta) {
5972
6026
  let targetTicketId = ticketId;
5973
6027
  let targetSessionId = sessionId;
5974
6028
  let targetChangesetId = changesetId;
6029
+ let targetLeaseId = leaseId;
6030
+ let targetLeaseExpiresAt = leaseExpiresAtValue;
5975
6031
  const cadenceWrites = [];
5976
6032
  const lifecycleOperations = [];
5977
6033
  let intakeResult;
@@ -6000,6 +6056,8 @@ async function runAgentRunCheckpoint(parsed, options, config, meta) {
6000
6056
  ticketId: targetTicketId,
6001
6057
  ...targetSessionId ? { sessionId: targetSessionId } : {},
6002
6058
  ...targetChangesetId ? { changesetId: targetChangesetId } : {},
6059
+ ...targetLeaseId ? { leaseId: targetLeaseId } : {},
6060
+ ...targetLeaseExpiresAt ? { leaseExpiresAt: targetLeaseExpiresAt } : {},
6003
6061
  ...eventFile ? { eventFile } : {},
6004
6062
  event,
6005
6063
  prompt,
@@ -6035,6 +6093,8 @@ async function runAgentRunCheckpoint(parsed, options, config, meta) {
6035
6093
  ticketId: targetTicketId,
6036
6094
  ...targetSessionId ? { sessionId: targetSessionId } : {},
6037
6095
  ...targetChangesetId ? { changesetId: targetChangesetId } : {},
6096
+ ...targetLeaseId ? { leaseId: targetLeaseId } : {},
6097
+ ...targetLeaseExpiresAt ? { leaseExpiresAt: targetLeaseExpiresAt } : {},
6038
6098
  capturedAt: checkedAt
6039
6099
  },
6040
6100
  lastCheckpointAt: checkedAt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycadence/cli",
3
- "version": "0.1.18-dev.0",
3
+ "version": "0.1.19-dev.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {