@astrosheep/square 0.3.42 → 0.3.43

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.
@@ -64,7 +64,10 @@ export async function recordWakeAttempt(attempt, env = process.env) {
64
64
  throw new Error(`${value.outcome} wake attempts require a transport signature.`);
65
65
  }
66
66
  const safe = redact(value, env.PASEO_PASSWORD);
67
- await ledger(env).appendWakeAttempt({ location: safe.attention.squarePath, participant: safe.attention.recipient, session: safe.session ?? safe.signature ?? `route:${safe.routeKind}`, activity: formatActivityId(safe.attention.actIndex), kind: 'wake', outcome: safe.outcome, routeKind: safe.routeKind, signature: safe.signature, attemptN: safe.attemptN, message: safe.message, diagnostic: safe.diagnostic, at: safe.at });
67
+ const session = safe.session ?? safe.signature ?? `route:${safe.routeKind}`;
68
+ const claim = await ledger(env).claimEvidence({ location: safe.attention.squarePath, participant: safe.attention.recipient, session, activity: formatActivityId(safe.attention.actIndex), kind: 'wake', leaseMs: 5000 });
69
+ if (claim.status === 'acquired')
70
+ await ledger(env).appendWakeAttempt({ location: safe.attention.squarePath, participant: safe.attention.recipient, session, activity: formatActivityId(safe.attention.actIndex), kind: 'wake', outcome: safe.outcome, routeKind: safe.routeKind, signature: safe.signature, attemptN: safe.attemptN, message: safe.message, diagnostic: safe.diagnostic, at: safe.at, claimToken: claim.claimToken });
68
71
  return value;
69
72
  }
70
73
  export async function recordRecoveredUnknown(attention, lease, env = process.env, at = Date.now()) {
@@ -94,7 +97,10 @@ export async function recordRecoveredUnknown(attention, lease, env = process.env
94
97
  attemptN: lease.attemptN,
95
98
  message: 'The notification worker ended after dispatch began; transport acceptance is unknown.',
96
99
  };
97
- await ledger(env).appendWakeAttempt({ location: attention.squarePath, participant: attention.recipient, session: lease.session ?? value.signature, activity: formatActivityId(attention.actIndex), kind: 'wake', outcome: 'unknown', routeKind, signature: value.signature, attemptN: value.attemptN, message: value.message, at });
100
+ const session = lease.session ?? value.signature;
101
+ const claim = await ledger(env).claimEvidence({ location: attention.squarePath, participant: attention.recipient, session, activity: formatActivityId(attention.actIndex), kind: 'wake', leaseMs: 5000 });
102
+ if (claim.status === 'acquired')
103
+ await ledger(env).appendWakeAttempt({ location: attention.squarePath, participant: attention.recipient, session, activity: formatActivityId(attention.actIndex), kind: 'wake', outcome: 'unknown', routeKind, signature: value.signature, attemptN: value.attemptN, message: value.message, at, claimToken: claim.claimToken });
98
104
  return value;
99
105
  }
100
106
  }
@@ -34,6 +34,7 @@ export default function squarePiExtension(pi) {
34
34
  let sessionId;
35
35
  let sessionCwd;
36
36
  let joiningContext;
37
+ let previousSessionId;
37
38
  let watcher;
38
39
  let watcherAbort;
39
40
  let generation = 0;
@@ -196,6 +197,8 @@ export default function squarePiExtension(pi) {
196
197
  retryWait = undefined;
197
198
  sessionId = ctx.sessionManager.getSessionId();
198
199
  sessionCwd = ctx.cwd || process.cwd();
200
+ previousSessionId = process.env.SQUARE_PI_SESSION_ID;
201
+ process.env.SQUARE_PI_SESSION_ID = sessionId;
199
202
  joiningContext = undefined;
200
203
  void automaticSessionStart('pi', sessionId, sessionCwd).catch(() => undefined);
201
204
  watcherAbort = new AbortController();
@@ -230,6 +233,10 @@ export default function squarePiExtension(pi) {
230
233
  for (const waiter of settledWaiters) waiter.resolve();
231
234
  settledWaiters = [];
232
235
  if (sessionId && sessionCwd) void automaticSessionEnd('pi', sessionId, sessionCwd).catch(() => undefined);
236
+ if (process.env.SQUARE_PI_SESSION_ID === sessionId) {
237
+ if (previousSessionId === undefined) delete process.env.SQUARE_PI_SESSION_ID;
238
+ else process.env.SQUARE_PI_SESSION_ID = previousSessionId;
239
+ }
233
240
  sessionId = undefined;
234
241
  sessionCwd = undefined;
235
242
  joiningContext = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrosheep/square",
3
- "version": "0.3.42",
3
+ "version": "0.3.43",
4
4
  "description": "A shared public square where agents join, catch activity, express, and step out when done.",
5
5
  "type": "module",
6
6
  "bin": {