codex-to-poke 0.1.0 → 0.1.1

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 CHANGED
@@ -6,10 +6,11 @@ Pokedex is an independent open-source project. It is not affiliated with, endors
6
6
 
7
7
  ```bash
8
8
  codex login
9
- npx poke@latest login
10
9
  npx codex-to-poke
11
10
  ```
12
11
 
12
+ Pokedex starts the Poke login flow automatically if the tunnel needs it.
13
+
13
14
  Keep the terminal open while using Poke. When the prompt opens, type `help` to see commands.
14
15
 
15
16
  Common modes:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-to-poke",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Unofficial local Poke to Codex bridge.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -149,14 +149,58 @@ async function startStack() {
149
149
  await waitForAgent();
150
150
  statuses.agent = 'ok';
151
151
 
152
- statuses.poke = 'starting';
153
- spawnManaged('poke', npxBin(), ['poke@latest', 'tunnel', mcpHttpUrlWithToken(), '-n', 'pokedex']);
154
- await waitForPoke();
152
+ await startPokeTunnel();
155
153
  statuses.poke = 'ok';
156
154
  console.log("✅ Everything's fine. pokedex is ready.");
157
155
  console.log('Type "help" for commands. Keep this terminal open while you use Poke.\n');
158
156
  }
159
157
 
158
+ async function startPokeTunnel() {
159
+ statuses.poke = 'starting';
160
+ spawnPokeTunnel();
161
+ try {
162
+ await waitForPoke();
163
+ } catch (error) {
164
+ if (!pokeNeedsLogin()) throw error;
165
+ await runPokeLogin();
166
+ spawnPokeTunnel();
167
+ await waitForPoke();
168
+ }
169
+ }
170
+
171
+ function spawnPokeTunnel() {
172
+ spawnManaged('poke', npxBin(), ['poke@latest', 'tunnel', mcpHttpUrlWithToken(), '-n', 'pokedex']);
173
+ }
174
+
175
+ async function runPokeLogin() {
176
+ console.log('Poke is not logged in. Starting `npx poke@latest login`...\n');
177
+ const code = await runInteractive(npxBin(), ['poke@latest', 'login']);
178
+ if (code !== 0)
179
+ throw new Error('Poke login did not complete. Run `npx poke@latest login` and retry.');
180
+ console.log('\nPoke login finished. Starting the tunnel again...\n');
181
+ }
182
+
183
+ function runInteractive(command, commandArgs) {
184
+ return new Promise((resolveRun, rejectRun) => {
185
+ const child = spawn(command, commandArgs, {
186
+ cwd: invocationCwd,
187
+ stdio: 'inherit',
188
+ env: process.env,
189
+ });
190
+ child.on('error', rejectRun);
191
+ child.on('exit', (code, signal) => {
192
+ if (signal) rejectRun(new Error(`Poke login stopped by ${signal}.`));
193
+ else resolveRun(code ?? 0);
194
+ });
195
+ });
196
+ }
197
+
198
+ function pokeNeedsLogin() {
199
+ return (serviceLogs.get('poke') ?? []).some((line) =>
200
+ /not logged in|npx poke@latest login|poke login/i.test(line)
201
+ );
202
+ }
203
+
160
204
  async function waitForRelay() {
161
205
  await waitFor(
162
206
  async () => {
@@ -439,7 +483,7 @@ function printInteractiveHelp() {
439
483
 
440
484
  setup
441
485
  codex login
442
- npx poke@latest login`);
486
+ Poke login opens automatically if needed`);
443
487
  }
444
488
 
445
489
  function spawnManaged(name, bin, binArgs) {
@@ -802,7 +846,7 @@ usage
802
846
 
803
847
  setup
804
848
  codex login
805
- npx poke@latest login
849
+ Poke login opens automatically if needed
806
850
 
807
851
  config
808
852
  ~/.pokedex/config.json