@commonlyai/cli 0.1.133 → 0.1.134

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.133",
3
+ "version": "0.1.134",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -45,6 +45,9 @@
45
45
  "setupFiles": [
46
46
  "<rootDir>/jest.setup.cjs"
47
47
  ],
48
+ "setupFilesAfterEnv": [
49
+ "<rootDir>/jest.teardown.cjs"
50
+ ],
48
51
  "transform": {},
49
52
  "testMatch": [
50
53
  "**/__tests__/**/*.[jt]s?(x)",
@@ -208,6 +208,37 @@ export const createDaemonSupervisor = ({
208
208
 
209
209
  const existing = loadToken(row.agentName);
210
210
  if (existing) {
211
+ // Local records are still keyed by agent name. Never rotate or launch
212
+ // another instance through a same-name record: that would overwrite a
213
+ // different seat's bearer until instance-scoped local records land.
214
+ if ((existing.instanceId || 'default') !== (row.instanceId || 'default')) {
215
+ log(`[${row.agentName}] local token belongs to instance '${existing.instanceId || 'default'}'; refusing '${row.instanceId || 'default'}'`);
216
+ return false;
217
+ }
218
+ // A human owner can request a fresh key from Settings after revocation.
219
+ // The daemon owns its local token file, so the browser only stamps the
220
+ // directive; this host rotates the key and restarts its child once.
221
+ const requestedAt = row.reconnectRequestedAt && new Date(row.reconnectRequestedAt).getTime();
222
+ const appliedAt = existing.reconnectRequestAppliedAt
223
+ && new Date(existing.reconnectRequestAppliedAt).getTime();
224
+ if (Number.isFinite(requestedAt) && requestedAt > (appliedAt || 0)) {
225
+ try {
226
+ const minted = await client.post('/api/agent-binding/runtime-token', {
227
+ agentName: row.agentName, instanceId: row.instanceId, rotate: true,
228
+ });
229
+ if (!minted?.token) throw new Error('mint returned no token');
230
+ saveToken(row.agentName, {
231
+ ...existing,
232
+ runtimeToken: minted.token,
233
+ reconnectRequestAppliedAt: row.reconnectRequestedAt,
234
+ });
235
+ log(`[${row.agentName}] owner-requested key rotation applied; restarting the seat`);
236
+ return 'changed';
237
+ } catch (error) {
238
+ log(`[${row.agentName}] owner-requested key rotation failed: ${error.message}`);
239
+ return false;
240
+ }
241
+ }
211
242
  // A model changed in the UI reaches the seat here: update the record,
212
243
  // and let the caller restart the child (`agent run` reads its record
213
244
  // once at boot). A row with NO declared model leaves the record alone —