@plexor-dev/claude-code-plugin-staging 0.1.0-beta.23 → 0.1.0-beta.24

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.
@@ -92,6 +92,32 @@ function getGatewayLabel(apiUrl) {
92
92
  return apiUrl.includes('staging') ? 'staging' : 'production';
93
93
  }
94
94
 
95
+ function isRunningInsideClaudeSession(env = process.env) {
96
+ return Boolean(env.CLAUDECODE);
97
+ }
98
+
99
+ function createSkipVerifyResult() {
100
+ return { ok: true, reason: '', stdout: EXPECTED_VERIFY_RESPONSE, stderr: '', code: 0, pendingRestart: false };
101
+ }
102
+
103
+ function createPendingRestartVerifyResult() {
104
+ return {
105
+ ok: false,
106
+ reason: 'Restart Claude to finish Plexor activation in your current session.',
107
+ stdout: '',
108
+ stderr: '',
109
+ code: 0,
110
+ pendingRestart: true
111
+ };
112
+ }
113
+
114
+ function getVerifyLabel(verifyResult) {
115
+ if (verifyResult.pendingRestart) {
116
+ return 'Restart Claude';
117
+ }
118
+ return verifyResult.ok ? 'OK' : 'FAILED';
119
+ }
120
+
95
121
  function updateHealth(config, state) {
96
122
  config.health = {
97
123
  installed: true,
@@ -102,6 +128,7 @@ function updateHealth(config, state) {
102
128
  verify_prompt: VERIFY_PROMPT,
103
129
  verify_expected: EXPECTED_VERIFY_RESPONSE,
104
130
  verify_error: state.verifyResult.ok ? null : state.verifyResult.reason,
131
+ activation_pending_restart: Boolean(state.verifyResult.pendingRestart),
105
132
  gateway: state.gateway,
106
133
  previous_auth_preserved: state.previousAuthPreserved
107
134
  };
@@ -124,10 +151,14 @@ function printReceipt({ user, gateway, previousAuthPreserved, verifyResult }) {
124
151
  console.log('├─────────────────────────────────────────────┤');
125
152
  console.log(line(`Connected: OK (${user.email || 'Unknown'})`));
126
153
  console.log(line(`Routing Active: OK (${gateway})`));
127
- console.log(line(`Verified: ${verifyResult.ok ? 'OK' : 'FAILED'}`));
154
+ console.log(line(`Verified: ${getVerifyLabel(verifyResult)}`));
128
155
  console.log(line(`Previous Claude auth: ${previousAuthPreserved ? 'Saved' : 'None found'}`));
129
156
  console.log('├─────────────────────────────────────────────┤');
130
- if (verifyResult.ok) {
157
+ if (verifyResult.pendingRestart) {
158
+ console.log(line('Plexor routing is configured'));
159
+ console.log(line('Restart Claude to activate Plexor'));
160
+ console.log(line('Then run /plexor-status'));
161
+ } else if (verifyResult.ok) {
131
162
  console.log(line('Plexor routing is configured'));
132
163
  console.log(line('Restart Claude, then send a prompt'));
133
164
  console.log(line('Logout/uninstall restores prior auth'));
@@ -221,9 +252,9 @@ async function main() {
221
252
  currentSettings.env?.PLEXOR_PREVIOUS_CLAUDE_PRIMARY_API_KEY
222
253
  );
223
254
 
224
- const verifyResult = skipVerify
225
- ? { ok: true, reason: '', stdout: EXPECTED_VERIFY_RESPONSE, stderr: '', code: 0 }
226
- : runClaudeRouteVerification();
255
+ const verifyResult = isRunningInsideClaudeSession()
256
+ ? createPendingRestartVerifyResult()
257
+ : (skipVerify ? createSkipVerifyResult() : runClaudeRouteVerification());
227
258
 
228
259
  updateHealth(updatedConfig, {
229
260
  gateway: getGatewayLabel(apiUrl),
@@ -243,12 +274,22 @@ async function main() {
243
274
  verifyResult
244
275
  });
245
276
 
246
- if (!verifyResult.ok) {
277
+ if (!verifyResult.ok && !verifyResult.pendingRestart) {
247
278
  process.exit(1);
248
279
  }
249
280
  }
250
281
 
251
- main().catch((err) => {
252
- console.error(`Error: ${err.message}`);
253
- process.exit(1);
254
- });
282
+ if (require.main === module) {
283
+ main().catch((err) => {
284
+ console.error(`Error: ${err.message}`);
285
+ process.exit(1);
286
+ });
287
+ } else {
288
+ module.exports = {
289
+ createPendingRestartVerifyResult,
290
+ createSkipVerifyResult,
291
+ getVerifyLabel,
292
+ isRunningInsideClaudeSession,
293
+ updateHealth
294
+ };
295
+ }
@@ -172,6 +172,47 @@ function loadConfig() {
172
172
  }
173
173
  }
174
174
 
175
+ function saveConfig(config) {
176
+ try {
177
+ const configDir = path.dirname(CONFIG_PATH);
178
+ if (!fs.existsSync(configDir)) {
179
+ fs.mkdirSync(configDir, { recursive: true, mode: 0o700 });
180
+ }
181
+ const tempPath = path.join(configDir, `.config.${Date.now()}.tmp`);
182
+ fs.writeFileSync(tempPath, JSON.stringify(config, null, 2), { mode: 0o600 });
183
+ fs.renameSync(tempPath, CONFIG_PATH);
184
+ return true;
185
+ } catch {
186
+ return false;
187
+ }
188
+ }
189
+
190
+ function isActivationPendingRestart(verification = {}) {
191
+ return verification.activation_pending_restart === true;
192
+ }
193
+
194
+ function shouldPromotePendingRestart(verification = {}, routing = {}, userFetchWorked = false) {
195
+ return isActivationPendingRestart(verification) && routing.active && userFetchWorked;
196
+ }
197
+
198
+ function getVerificationSummary(verification = {}, options = {}) {
199
+ const { routingActive = false, userFetchWorked = false } = options;
200
+
201
+ if (shouldPromotePendingRestart(verification, { active: routingActive }, userFetchWorked)) {
202
+ return { verified: 'OK', nextAction: '/plexor-status', shouldPromote: true };
203
+ }
204
+
205
+ if (isActivationPendingRestart(verification)) {
206
+ return { verified: 'Restart Claude', nextAction: 'Restart Claude', shouldPromote: false };
207
+ }
208
+
209
+ return {
210
+ verified: verification.verified ? 'OK' : (verification.verify_error ? 'Failed' : 'Not yet'),
211
+ nextAction: null,
212
+ shouldPromote: false
213
+ };
214
+ }
215
+
175
216
  /**
176
217
  * Check for environment mismatch between config and routing
177
218
  */
@@ -385,12 +426,33 @@ ${line(`└── Cost saved: $${sessionCostSaved}`)}
385
426
  const envLabel = routing.isStaging ? '(staging)' : '(production)';
386
427
  const stateMismatch = checkStateMismatch(enabled, routing.active);
387
428
  const connectedState = userFetchWorked ? 'OK' : 'Unknown';
388
- const verifiedState = verification.verified
429
+ const verificationSummary = getVerificationSummary(verification, {
430
+ routingActive: routing.active,
431
+ userFetchWorked
432
+ });
433
+
434
+ if (verificationSummary.shouldPromote) {
435
+ config.health = {
436
+ ...verification,
437
+ verified: true,
438
+ verified_at: new Date().toISOString(),
439
+ verify_error: null,
440
+ activation_pending_restart: false
441
+ };
442
+ saveConfig(config);
443
+ verification.verified = true;
444
+ verification.verified_at = config.health.verified_at;
445
+ verification.verify_error = null;
446
+ verification.activation_pending_restart = false;
447
+ }
448
+
449
+ const verifiedState = verificationSummary.shouldPromote
389
450
  ? 'OK'
390
- : (verification.verify_error ? 'Failed' : 'Not yet');
391
- const nextAction = !routing.active || partialState.partial || stateMismatch || !verification.verified
392
- ? '/plexor-setup'
393
- : '/plexor-status';
451
+ : verificationSummary.verified;
452
+ const nextAction = verificationSummary.nextAction ||
453
+ (!routing.active || partialState.partial || stateMismatch || !verification.verified
454
+ ? '/plexor-setup'
455
+ : '/plexor-status');
394
456
 
395
457
  // Note: Environment mismatch warning removed - it caused false positives during
396
458
  // concurrent operations and transient states. The partial state and config/routing
@@ -521,7 +583,15 @@ function fetchJson(apiUrl, endpoint, apiKey) {
521
583
  });
522
584
  }
523
585
 
524
- main().catch(err => {
525
- console.error('Error:', err.message);
526
- process.exit(1);
527
- });
586
+ if (require.main === module) {
587
+ main().catch(err => {
588
+ console.error('Error:', err.message);
589
+ process.exit(1);
590
+ });
591
+ } else {
592
+ module.exports = {
593
+ getVerificationSummary,
594
+ isActivationPendingRestart,
595
+ shouldPromotePendingRestart
596
+ };
597
+ }
@@ -31,7 +31,7 @@ class PlexorClient {
31
31
  'Content-Type': 'application/json',
32
32
  'X-API-Key': this.apiKey,
33
33
  'X-Plexor-Key': this.apiKey,
34
- 'User-Agent': 'plexor-claude-code-plugin/0.1.0-beta.23'
34
+ 'User-Agent': 'plexor-claude-code-plugin/0.1.0-beta.24'
35
35
  },
36
36
  timeout: this.timeout
37
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexor-dev/claude-code-plugin-staging",
3
- "version": "0.1.0-beta.23",
3
+ "version": "0.1.0-beta.24",
4
4
  "description": "STAGING - LLM cost optimization plugin for Claude Code (internal testing)",
5
5
  "main": "lib/constants.js",
6
6
  "bin": {