moi-computer 0.1.3 → 0.1.4

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": "moi-computer",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",
@@ -298,6 +298,18 @@ function appletRuntimePlugin(
298
298
  loader: 'js'
299
299
  }))
300
300
 
301
+ // `devalue` is moi's OWN dependency, injected into every applet bundle via
302
+ // the mei:rpc virtual module above. A virtual module has no on-disk
303
+ // location, so Bun resolves the bare `devalue` specifier against the
304
+ // process cwd's node_modules — which breaks when the server runs from a
305
+ // neutral cwd (a prebuilt/global install; see serverCwd in cli.ts). A
306
+ // resolveDir on the onLoad is ignored for bare specifiers in Bun 1.3, so
307
+ // pin it to an absolute path inside moi's OWN package (this file's dir
308
+ // walks up to moi's node_modules), making the applet build cwd-independent.
309
+ build.onResolve({ filter: /^devalue$/ }, () => ({
310
+ path: Bun.resolveSync('devalue', import.meta.dir)
311
+ }))
312
+
301
313
  // The `moi` runtime module (fileUrl). A bare specifier, so match it exactly.
302
314
  build.onResolve({ filter: /^moi$/ }, () => ({ path: 'moi', namespace: 'moi-runtime' }))
303
315
  build.onLoad({ filter: /.*/, namespace: 'moi-runtime' }, () => ({
package/server/cli.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  import './cli-colors' // must precede citty: sets NO_COLOR before its color flag is computed
3
3
  import { defineCommand, runMain, showUsage } from 'citty'
4
- import { existsSync } from 'node:fs'
4
+ import { existsSync, readFileSync } from 'node:fs'
5
5
  import { tmpdir } from 'node:os'
6
6
  import { join, resolve } from 'path'
7
7
  import pc from 'picocolors'
@@ -22,6 +22,7 @@ import { columns } from './cli-ui'
22
22
  import { CONTROL_PORT, PORT } from './constants'
23
23
  import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw'
24
24
  import { liftToWorkspaceRoot, registerWorkspace } from './registry'
25
+ import { serverCwd } from './server-cwd'
25
26
  import {
26
27
  type SkillStatus,
27
28
  isBehind,
@@ -85,20 +86,19 @@ async function openBrowser(url: string) {
85
86
  } catch {}
86
87
  }
87
88
 
88
- // Spawn the server as a child with cwd=projectRoot so bunfig.toml is found at Bun startup.
89
- // bunfig.toml is read before any JS runs, so process.chdir() is too late.
90
- // MOI_SERVER=1 tells the child it is the actual server process. No `--hot`:
91
- // frontend HMR comes from Bun.serve's dev bundler, and server reloads are a
92
- // full process restart driven by the dev supervisor (see runDevSupervisor).
89
+ // Spawn the server as a child. MOI_SERVER=1 tells the child it is the actual
90
+ // server process. No `--hot`: frontend HMR comes from Bun.serve's dev bundler,
91
+ // and server reloads are a full process restart driven by the dev supervisor
92
+ // (see runDevSupervisor).
93
93
  function spawnServer(
94
- projectRoot: string,
94
+ cwd: string,
95
95
  env: Record<string, string | undefined> = process.env
96
96
  ): ReturnType<typeof Bun.spawn> {
97
97
  return Bun.spawn(['bun', import.meta.filename, 'start'], {
98
98
  stdin: 'inherit',
99
99
  stdout: 'inherit',
100
100
  stderr: 'inherit',
101
- cwd: projectRoot,
101
+ cwd,
102
102
  env: { ...env, MOI_SERVER: '1' }
103
103
  })
104
104
  }
@@ -269,7 +269,7 @@ const init = defineCommand({
269
269
 
270
270
  if (!running && args.web) {
271
271
  console.log(pc.dim(' Starting server…'))
272
- const proc = spawnServer(projectRoot)
272
+ const proc = spawnServer(serverCwd(projectRoot, false))
273
273
  running = await waitForServer()
274
274
  if (!running) {
275
275
  console.error(pc.red(' Server failed to start\n'))
@@ -350,12 +350,14 @@ const start = defineCommand({
350
350
  await runDevSupervisor(projectRoot, env)
351
351
  return
352
352
  }
353
- const proc = spawnServer(projectRoot, env)
353
+ const proc = spawnServer(serverCwd(projectRoot, dev), env)
354
354
  await proc.exited
355
355
  process.exit(proc.exitCode ?? 0)
356
356
  }
357
357
 
358
- // This IS the server process (MOI_SERVER=1, cwd=projectRoot, bunfig.toml loaded).
358
+ // This IS the server process (MOI_SERVER=1). cwd is the package root when the
359
+ // dev bundler runs (bunfig loaded at Bun startup) or a neutral dir for a
360
+ // prebuilt install — see serverCwd().
359
361
  await import('./web')
360
362
  console.log(`\n${pc.green('✓')} Server started on http://localhost:${PORT}`)
361
363
  console.log(pc.dim(' Press Ctrl+C to stop\n'))
@@ -1511,9 +1513,48 @@ const skill = defineCommand({
1511
1513
  }
1512
1514
  })
1513
1515
 
1516
+ // `<package version> (<8-char commit>)`, e.g. `0.1.3 (27e17e80)`. The commit is
1517
+ // read from git at call time, so it appears for a source/`bun link` checkout and
1518
+ // is simply omitted for a published package (which ships no .git).
1519
+ function moiVersion(): string {
1520
+ const root = join(import.meta.dir, '..')
1521
+ let version = '0.0.0'
1522
+ try {
1523
+ version = (JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { version: string })
1524
+ .version
1525
+ } catch {}
1526
+ let commit = ''
1527
+ try {
1528
+ const out = Bun.spawnSync(['git', 'rev-parse', '--short=8', 'HEAD'], { cwd: root })
1529
+ if (out.success) commit = out.stdout.toString().trim()
1530
+ } catch {}
1531
+ return commit ? `${version} (${commit})` : version
1532
+ }
1533
+
1534
+ const version = defineCommand({
1535
+ meta: { name: 'version', description: 'Print the moi version' },
1536
+ run() {
1537
+ console.log(moiVersion())
1538
+ }
1539
+ })
1540
+
1514
1541
  const main = defineCommand({
1515
- meta: { name: 'moi', description: 'moi — local AI workspace' },
1516
- subCommands: { init, start, bundle, refresh, theme, config, status, openclaw, scratch, skill }
1542
+ // A function so the git lookup runs only for `moi --version` / `--help`, not on
1543
+ // every command. citty resolves a function meta (used for --version + usage).
1544
+ meta: () => ({ name: 'moi', description: 'moi — local AI workspace', version: moiVersion() }),
1545
+ subCommands: {
1546
+ init,
1547
+ start,
1548
+ bundle,
1549
+ refresh,
1550
+ theme,
1551
+ config,
1552
+ status,
1553
+ openclaw,
1554
+ scratch,
1555
+ skill,
1556
+ version
1557
+ }
1517
1558
  })
1518
1559
 
1519
1560
  // Route `moi config --help` to the same terse cheat sheet as `moi config help`;
@@ -0,0 +1,23 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { homedir, tmpdir } from 'node:os'
3
+ import { join } from 'path'
4
+
5
+ // Where the moi server child process should run.
6
+ //
7
+ // It only needs to sit in the package root when the DEV BUNDLER will run at
8
+ // boot: Bun reads bunfig.toml and its cwd-relative `[serve.static]` plugins
9
+ // (`./client/externalize-react.ts`) before any JS runs, so the cwd must be the
10
+ // package root then — and process.chdir() is too late.
11
+ //
12
+ // A PREBUILT install (dist/index.html present, no --dev) serves static files
13
+ // and never reads the bunfig, so it runs from a neutral, stable dir instead.
14
+ // Otherwise the server sits inside the very directory `bun i -g` replaces on
15
+ // upgrade, dangling its own cwd inode and breaking every later widget build
16
+ // with "CurrentWorkingDirectoryUnlinked Error creating transpiler". The child
17
+ // finds its own code via import.meta.filename (absolute), so a neutral cwd
18
+ // costs nothing.
19
+ export function serverCwd(projectRoot: string, dev: boolean): string {
20
+ const usesDevBundler = dev || !existsSync(join(projectRoot, 'dist', 'index.html'))
21
+ if (usesDevBundler) return projectRoot
22
+ return homedir() || tmpdir() || projectRoot
23
+ }