@commonlyai/cli 0.1.32 → 0.1.34
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/README.md +3 -1
- package/package.json +1 -1
- package/src/lib/daemon-supervisor.js +34 -6
package/README.md
CHANGED
|
@@ -24,4 +24,6 @@ Requires Node 20+. No build step.
|
|
|
24
24
|
node --experimental-vm-modules node_modules/.bin/jest --no-coverage
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Instance-selection tests use distinct persisted `savedAt` values and both insertion orders.
|
|
28
|
+
Keep active-instance precedence separate from the newest-match fallback; back-to-back
|
|
29
|
+
`saveInstance` calls can share a millisecond and hide a broken selection branch.
|
package/package.json
CHANGED
|
@@ -87,12 +87,33 @@ export const createDaemonSupervisor = ({
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
// The server-declared runtime config carries the owner's model choice; the
|
|
91
|
+
// adapter reads it from the token record's environment (claude: --model).
|
|
92
|
+
const environmentFor = (row) => (
|
|
93
|
+
row.runtime?.model ? { model: String(row.runtime.model) } : null
|
|
94
|
+
);
|
|
95
|
+
|
|
90
96
|
// Ensure ~/.commonly/tokens/<name>.json exists so `agent run` can boot.
|
|
91
97
|
// The mint refuses to clobber an existing token (409 token_exists); the
|
|
92
98
|
// binding to THIS machine is the owner's explicit takeover choice (D3), so
|
|
93
99
|
// that refusal is answered with rotate:true — loudly.
|
|
100
|
+
// Returns 'ready' | 'changed' (record updated — the seat must restart to
|
|
101
|
+
// load it) | false.
|
|
94
102
|
const ensureToken = async (row) => {
|
|
95
|
-
|
|
103
|
+
const existing = loadToken(row.agentName);
|
|
104
|
+
if (existing) {
|
|
105
|
+
// A model changed in the UI reaches the seat here: update the record,
|
|
106
|
+
// and let the caller restart the child (`agent run` reads its record
|
|
107
|
+
// once at boot). A row with NO declared model leaves the record alone —
|
|
108
|
+
// never strip an operator's hand-set environment.
|
|
109
|
+
const wanted = environmentFor(row);
|
|
110
|
+
if (wanted && existing.environment?.model !== wanted.model) {
|
|
111
|
+
saveToken(row.agentName, { ...existing, environment: { ...(existing.environment || {}), ...wanted } });
|
|
112
|
+
log(`[${row.agentName}] model changed to ${wanted.model} — restarting the seat to load it`);
|
|
113
|
+
return 'changed';
|
|
114
|
+
}
|
|
115
|
+
return 'ready';
|
|
116
|
+
}
|
|
96
117
|
const body = { agentName: row.agentName, instanceId: row.instanceId };
|
|
97
118
|
let minted;
|
|
98
119
|
try {
|
|
@@ -120,6 +141,7 @@ export const createDaemonSupervisor = ({
|
|
|
120
141
|
log(`[${row.agentName}] no usable CLI adapter on this machine — install claude or codex, or attach manually`);
|
|
121
142
|
return false;
|
|
122
143
|
}
|
|
144
|
+
const environment = environmentFor(row);
|
|
123
145
|
saveToken(row.agentName, {
|
|
124
146
|
agentName: row.agentName,
|
|
125
147
|
instanceId: row.instanceId,
|
|
@@ -127,9 +149,10 @@ export const createDaemonSupervisor = ({
|
|
|
127
149
|
instanceUrl: record.instanceUrl,
|
|
128
150
|
podId: row.podIds?.[0] || null,
|
|
129
151
|
adapter,
|
|
152
|
+
...(environment ? { environment } : {}),
|
|
130
153
|
});
|
|
131
|
-
log(`[${row.agentName}] provisioned runtime token (adapter: ${adapter})`);
|
|
132
|
-
return
|
|
154
|
+
log(`[${row.agentName}] provisioned runtime token (adapter: ${adapter}${environment ? `, model: ${environment.model}` : ''})`);
|
|
155
|
+
return 'ready';
|
|
133
156
|
};
|
|
134
157
|
|
|
135
158
|
const tick = async () => {
|
|
@@ -180,9 +203,14 @@ export const createDaemonSupervisor = ({
|
|
|
180
203
|
seats.set(key, seat);
|
|
181
204
|
}
|
|
182
205
|
seat.desired = true;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
206
|
+
// eslint-disable-next-line no-await-in-loop
|
|
207
|
+
const ready = await ensureToken(row);
|
|
208
|
+
if (ready === 'changed' && seat.child) {
|
|
209
|
+
// desired stays true, so the exit handler respawns with the updated
|
|
210
|
+
// record — the restart path IS the D6 path, no second spawner.
|
|
211
|
+
seat.child.kill('SIGTERM');
|
|
212
|
+
} else if (ready && !seat.child && !seat.backoffTimer) {
|
|
213
|
+
startChild(seat);
|
|
186
214
|
}
|
|
187
215
|
}
|
|
188
216
|
|