@heywavie/cli 0.2.0 → 0.2.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
@@ -21,7 +21,8 @@ The token works once, for 30 minutes, and rides after `#`, so fetching the page
21
21
  ## What the service does
22
22
 
23
23
  `heywavie run` waits on `GET /device/asks` by the computer's key, as its own device, for `claude` asks only, and runs
24
- each turn with Claude Code here (`src/claude.mjs`), three at once: model only, Claude Code's own tools off (no shell, no
24
+ each turn with Claude Code here (`src/claude.mjs`), three at once, on Claude Opus 5.5 (named, so neither their Claude Code
25
+ default nor their settings picks it): model only, Claude Code's own tools off (no shell, no
25
26
  files, no web), none of the person's settings, hooks or plugins, an empty folder of its own, and only Wavie's tools,
26
27
  reached over MCP by the turn's own token. What Claude Code says goes back to the server as it says it. The key reaches
27
28
  its turns and `/plans/claude/host`, nothing else of their account; Claude's sign-in stays in Claude Code.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heywavie/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Claude on your computer, for Wavie: your agents think with your own Claude plan",
5
5
  "homepage": "https://heywavie.com",
6
6
  "license": "UNLICENSED",
package/src/claude.mjs CHANGED
@@ -49,10 +49,21 @@ export function claudeEnv(env = process.env, home = os.homedir(), bin = null, {
49
49
  return { ...base, USER: who, LOGNAME: env.LOGNAME || who, PATH: [...own, ...UNIX_PATH].join(':') };
50
50
  }
51
51
 
52
+ /**
53
+ * The Claude model a turn thinks with: named, so their own Claude Code default (Fable on a Max plan) or anything set in
54
+ * their settings, which never load here, doesn't pick it.
55
+ */
56
+ export const CLAUDE_MODEL = 'claude-opus-5-5';
57
+
58
+ /** Claude Code's refusal of a model the account can't use: its first message, marked or in its own words. */
59
+ const REFUSED = /issue with the selected model/i;
60
+ // Refused once here: later turns go straight to Claude Code's own default, until the service starts again.
61
+ let refusedHere = false;
62
+
52
63
  /** The one command a turn runs: model only, Wavie's tools at `tools` its only ones. */
53
- export function claudeArgs({ systemFile, tools, maxSteps }) {
64
+ export function claudeArgs({ systemFile, tools, maxSteps, model = CLAUDE_MODEL }) {
54
65
  const mcp = { mcpServers: { wavie: { type: 'http', url: tools } } };
55
- return ['-p', '--output-format', 'stream-json', '--verbose', '--include-partial-messages', '--input-format', 'stream-json',
66
+ return ['-p', ...(model ? ['--model', model] : []), '--output-format', 'stream-json', '--verbose', '--include-partial-messages', '--input-format', 'stream-json',
56
67
  '--system-prompt-file', systemFile, '--tools', '', '--strict-mcp-config', '--mcp-config', JSON.stringify(mcp),
57
68
  '--allowedTools', 'mcp__wavie', '--permission-prompts', 'none', '--no-session-persistence', '--disable-slash-commands',
58
69
  // No --safe-mode: it turns off MCP servers too, Wavie's with them. Their CLAUDE.md stays out without it.
@@ -191,32 +202,56 @@ export async function runTurn({ bin, turn, fetch = globalThis.fetch, env = proce
191
202
  const dir = await mkdtemp(path.join(os.tmpdir(), 'wavie-claude-'));
192
203
  const systemFile = path.join(dir, 'system.md');
193
204
  await writeFile(systemFile, turn.system, { mode: 0o600 });
194
- child = spawn(bin, claudeArgs({ systemFile, tools: turn.tools, maxSteps: turn.maxSteps }), { cwd: dir, env: claudeEnv(env, home, bin, { user: os.userInfo().username }),
195
- stdio: ['pipe', 'pipe', 'pipe'] });
196
- children.add(child);
197
205
  const ceiling = setTimeout(stop, maxMs);
198
- let buffer = '';
199
206
  let errText = '';
200
- child.stdout.on('data', (d) => {
201
- buffer += d;
202
- let nl;
203
- while ((nl = buffer.indexOf('\n')) >= 0) {
204
- const line = buffer.slice(0, nl).trim();
205
- buffer = buffer.slice(nl + 1);
206
- if (line) pending.push(line);
207
- }
208
- });
209
- child.stderr.on('data', (d) => { errText = (errText + d).slice(-4000); });
210
- child.stdin.on('error', () => {});
211
- child.stdin.end(message);
212
- const code = await new Promise((resolve) => {
213
- child.on('error', (err) => { errText = `${errText}\n${err?.message ?? err}`; resolve(-1); });
214
- child.on('close', (c) => resolve(c ?? -1));
215
- });
216
- children.delete(child);
207
+ // Once on CLAUDE_MODEL. A plan that can't use it (Claude Code answers its first message with model_not_found) runs
208
+ // again on Claude Code's own default: Claude Code's opening lines wait until the first message shows which, and the
209
+ // refusal never reaches the server as an answer.
210
+ const once = async (model) => {
211
+ child = spawn(bin, claudeArgs({ systemFile, tools: turn.tools, maxSteps: turn.maxSteps, model }), { cwd: dir, env: claudeEnv(env, home, bin, { user: os.userInfo().username }),
212
+ stdio: ['pipe', 'pipe', 'pipe'] });
213
+ children.add(child);
214
+ let buffer = '';
215
+ let held = model ? [] : null;
216
+ let refused = false;
217
+ const take = (line) => {
218
+ if (refused) return;
219
+ if (!held) { pending.push(line); return; }
220
+ let item = null;
221
+ try { item = JSON.parse(line); } catch { /* not JSON: shown as it is */ }
222
+ if (item?.type === 'system') { held.push(line); return; }
223
+ const words = item?.type === 'assistant' ? (item.message?.content ?? []).map((b) => b?.text ?? '').join(' ') : '';
224
+ if (item?.type === 'assistant' && (item.error === 'model_not_found' || REFUSED.test(words))) { refused = true; held = null; return; }
225
+ pending.push(...held, line);
226
+ held = null;
227
+ };
228
+ errText = '';
229
+ child.stdout.on('data', (d) => {
230
+ buffer += d;
231
+ let nl;
232
+ while ((nl = buffer.indexOf('\n')) >= 0) {
233
+ const line = buffer.slice(0, nl).trim();
234
+ buffer = buffer.slice(nl + 1);
235
+ if (line) take(line);
236
+ }
237
+ });
238
+ child.stderr.on('data', (d) => { errText = (errText + d).slice(-4000); });
239
+ child.stdin.on('error', () => {});
240
+ child.stdin.end(message);
241
+ const exit = await new Promise((resolve) => {
242
+ child.on('error', (err) => { errText = `${errText}\n${err?.message ?? err}`; resolve(-1); });
243
+ child.on('close', (c) => resolve(c ?? -1));
244
+ });
245
+ children.delete(child);
246
+ if (buffer.trim()) take(buffer.trim());
247
+ if (held) pending.push(...held);
248
+ return { exit, refused };
249
+ };
250
+ let { exit: code, refused } = await once(refusedHere ? null : CLAUDE_MODEL);
251
+ if (refused) refusedHere = true;
252
+ if (refused && !stopping) ({ exit: code } = await once(null));
217
253
  clearInterval(timer);
218
254
  clearTimeout(ceiling);
219
- if (buffer.trim()) pending.push(buffer.trim());
220
255
  for (let i = 0; i < 4 && (pending.length || batches.length || i === 0); i++) await flush(true);
221
256
  for (let i = 0; i < 3; i++) if (await send({ end: { code, error: errText } })) break;
222
257
  await rm(dir, { recursive: true, force: true }).catch(() => {});