latentcode 0.1.0-alpha.10 → 0.1.0-alpha.11

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
@@ -98,7 +98,21 @@ npm install && npm run build
98
98
  node dist/latentcode.mjs
99
99
  ```
100
100
 
101
- The engine is resolved in this order: `LATENTCODE_OPENCODE_BIN`, then the pinned `@opencode/cli` dependency, then `opencode` on PATH.
101
+ The engine is resolved in this order: `LATENTCODE_OPENCODE_BIN`, then the pinned `@opencode/cli` dependency, then `opencode` on PATH. An engine outside the pinned major.minor line still starts, but the start card and `latentcode status` warn about it.
102
+
103
+ ### Engine upgrades
104
+
105
+ The engine is pinned to an exact `@opencode/cli` version and only changes in a LatentCode release. Before a bump, run the contract check against the new version:
106
+
107
+ ```bash
108
+ npm run build
109
+ npm run engine:check -- --version 2.5.0 # or --bin /path/to/opencode
110
+ npm run engine:check -- --model opencode/<id> # when the free models are out of quota
111
+ ```
112
+
113
+ It drives LatentCode's own engine client and reducer: catalog, integrations, config reload with a custom provider, commands, MCP, and one real shell turn with the ask-before-shell rules. Exit code 0 = all good, 1 = a check failed, 2 = everything ran except the shell turn (no free model answered).
114
+
115
+ The `OpenCode watch` workflow runs this every Monday against the newest `@opencode/cli`. When a version past the pin appears it opens an `opencode-watch` issue with the result and pings Telegram, once per version. The bump itself is a normal PR.
102
116
 
103
117
  ### Develop against the mock ad server
104
118
 
@@ -117,7 +131,7 @@ latentcode (this repo) opencode serve (child process, 127.0.0.1, rand
117
131
  ```
118
132
 
119
133
  - `src/engine/server.ts` starts a private `opencode serve` for each run. It is never the user's background service.
120
- - `src/engine/session.ts` is a pure reducer from engine events to UI state. Tests replay a recorded opencode 2.2.0 turn.
134
+ - `src/engine/session.ts` is a pure reducer from engine events to UI state. Tests replay a recorded opencode 2.2.0 turn; `npm run engine:check` runs a live one.
121
135
  - `src/engine/catalog.ts` turns the engine's flat provider and model lists into what the picker shows: providers with a plain connection label, models with size, price and effort levels.
122
136
  - `src/boot.ts` runs start-up as named steps (engine, providers, model, safety, Earn) that the start card displays.
123
137
  - `src/ui/` is the Ink TUI: `App.tsx` (transcript, prompt, palette, status line), `panels/` (model picker, providers and connect, wallet), and the pure helpers `editor.ts`, `markdown.ts`, `commands.ts`, `stdin.ts`.
@@ -33909,6 +33909,7 @@ var SseParser = class {
33909
33909
  };
33910
33910
 
33911
33911
  // src/engine/bin.ts
33912
+ import { spawnSync } from "node:child_process";
33912
33913
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
33913
33914
  import { createRequire } from "node:module";
33914
33915
  import { homedir } from "node:os";
@@ -33961,6 +33962,31 @@ function resolveEngineBin(env3 = process.env, from) {
33961
33962
  const home2 = join(homedir(), ".opencode", "bin", exe);
33962
33963
  return existsSync2(home2) ? { path: home2, source: "home" } : null;
33963
33964
  }
33965
+ var PINNED_ENGINE = true ? "2.4.2" : "";
33966
+ function probeEngineVersion(path, timeoutMs = 5e3) {
33967
+ try {
33968
+ const r = spawnSync(path, ["--version"], { encoding: "utf8", timeout: timeoutMs, stdio: ["ignore", "pipe", "pipe"] });
33969
+ return parseEngineVersion(`${r.stdout ?? ""} ${r.stderr ?? ""}`);
33970
+ } catch {
33971
+ return void 0;
33972
+ }
33973
+ }
33974
+ function parseEngineVersion(text) {
33975
+ return text.match(/(?:^|[^\w.])v?(\d+\.\d+\.\d+(?:-[\w.-]+)?)/)?.[1];
33976
+ }
33977
+ function engineVersionWarning(found, pinned = PINNED_ENGINE) {
33978
+ if (!pinned) return null;
33979
+ if (!found) return `opencode version unknown; LatentCode is tested with ${pinned}`;
33980
+ const line = (v) => v.split(".").slice(0, 2).join(".");
33981
+ if (line(found) === line(pinned)) return null;
33982
+ return `opencode ${found} is not the tested ${pinned}; some things may not work`;
33983
+ }
33984
+ function resolveEngine(env3 = process.env, from) {
33985
+ const bin = resolveEngineBin(env3, from);
33986
+ if (!bin) return null;
33987
+ const version = bin.version ?? probeEngineVersion(bin.path);
33988
+ return { ...bin, version, warning: engineVersionWarning(version) };
33989
+ }
33964
33990
 
33965
33991
  // src/engine/catalog.ts
33966
33992
  var LATENT_ID = "latent";
@@ -34584,14 +34610,36 @@ ${seen.slice(-800)}`));
34584
34610
  async integrations() {
34585
34611
  return (await this.call("GET", "/api/integration")).data;
34586
34612
  }
34587
- /** Connected providers and their models, shaped for the UI. */
34588
- async catalog() {
34589
- const [providers, integrations, models] = await Promise.all([
34590
- this.call("GET", "/api/provider"),
34591
- this.integrations().catch(() => []),
34592
- this.call("GET", "/api/model")
34593
- ]);
34594
- return buildCatalog(providers.data, integrations, models.data);
34613
+ /**
34614
+ * Connected providers and their models, shaped for the UI.
34615
+ *
34616
+ * From opencode 2.4 `/api/provider`, `/api/model` and the integrations'
34617
+ * connections fill in over the first second or two after `serve` starts
34618
+ * listening, each at its own pace. Read too early, the start card says
34619
+ * "none connected" and providers show up nameless or with the wrong
34620
+ * connection. So poll until they agree (every model's provider is listed)
34621
+ * and two reads in a row look the same. An engine with nothing
34622
+ * connected stays empty for the whole wait, which is fine.
34623
+ */
34624
+ async catalog(waitMs = 4e3) {
34625
+ const until = Date.now() + waitMs;
34626
+ let last = "";
34627
+ for (; ; ) {
34628
+ const [providers, integrations, models] = await Promise.all([
34629
+ this.call("GET", "/api/provider"),
34630
+ this.integrations().catch(() => []),
34631
+ this.call("GET", "/api/model")
34632
+ ]);
34633
+ const p = providers.data ?? [];
34634
+ const m = models.data ?? [];
34635
+ const ids = new Set(p.map((x) => x.id));
34636
+ const linked = integrations.reduce((n, i) => n + (i.connections?.length ?? 0), 0);
34637
+ const size = `${p.length}/${m.length}/${integrations.length}/${linked}`;
34638
+ const settled = p.length > 0 && m.length > 0 && m.every((x) => ids.has(x.providerID)) && size === last;
34639
+ if (settled || Date.now() >= until) return buildCatalog(p, integrations, m);
34640
+ last = size;
34641
+ await new Promise((r) => setTimeout(r, 200));
34642
+ }
34595
34643
  }
34596
34644
  /** Store an API key for a provider. The key goes to the local engine only. */
34597
34645
  /** The engine's global config directory, as it reports it (`GET /api/config`). */
@@ -34798,7 +34846,7 @@ ${seen.slice(-800)}`));
34798
34846
  };
34799
34847
 
34800
34848
  // src/index.tsx
34801
- import { spawnSync as spawnSync2 } from "node:child_process";
34849
+ import { spawnSync as spawnSync3 } from "node:child_process";
34802
34850
 
34803
34851
  // src/ui/Root.tsx
34804
34852
  var import_react28 = __toESM(require_react(), 1);
@@ -35944,12 +35992,18 @@ async function boot(args, focus, report) {
35944
35992
  throw e;
35945
35993
  }
35946
35994
  };
35995
+ let engineVersion = "";
35947
35996
  const engine = await step("engine", async () => {
35948
- const bin = resolveEngineBin();
35997
+ const bin = resolveEngine();
35949
35998
  if (!bin) throw new EngineError(ENGINE_NOT_FOUND);
35950
35999
  const value = await Engine.start({ cwd: args.cwd, bin: bin.path });
35951
36000
  const where = { env: "from LATENTCODE_OPENCODE_BIN", bundled: "bundled", path: "from PATH", home: "from ~/.opencode" }[bin.source];
35952
- return { value, detail: `opencode${bin.version ? " " + bin.version : ""} \xB7 ${where} \xB7 private, this session only` };
36001
+ engineVersion = bin.version ?? "";
36002
+ return {
36003
+ value,
36004
+ status: bin.warning ? "warn" : "ok",
36005
+ detail: bin.warning ? `${bin.warning} \xB7 ${where}` : `opencode${bin.version ? " " + bin.version : ""} \xB7 ${where} \xB7 private, this session only`
36006
+ };
35953
36007
  });
35954
36008
  const models = new ModelStore();
35955
36009
  let latentStart;
@@ -36023,14 +36077,13 @@ async function boot(args, focus, report) {
36023
36077
  const detail = !enabled ? "off \u2014 /ads on to earn while the agent works" : wallet ? `on \xB7 pays into ${shortWallet(wallet)}` : "no wallet yet \u2014 /login to start earning";
36024
36078
  return { value: { wallet, server, api, controller }, status: enabled && wallet ? "ok" : "warn", detail };
36025
36079
  });
36026
- const engineVersion = resolveEngineBin()?.version ?? "";
36027
36080
  const sync = new StateSync({
36028
36081
  server: earn.server,
36029
36082
  key: () => loadConfig().sync_key,
36030
36083
  enabled: () => loadConfig().sync !== false,
36031
36084
  lastHash: fileHashStore(),
36032
36085
  collect: async () => buildSyncState({
36033
- appVersion: true ? "0.1.0-alpha.10" : "",
36086
+ appVersion: true ? "0.1.0-alpha.11" : "",
36034
36087
  engineVersion,
36035
36088
  model: await engine.defaultModel().then((m) => m ? `${m.providerID}/${m.id}` : session.key),
36036
36089
  catalog: await engine.catalog(),
@@ -39602,7 +39655,7 @@ function row(mark, label2, value, width = 10) {
39602
39655
  }
39603
39656
 
39604
39657
  // src/mcpCli.ts
39605
- import { spawnSync } from "node:child_process";
39658
+ import { spawnSync as spawnSync2 } from "node:child_process";
39606
39659
  var HELP = `${a.bold("latentcode mcp")} \u2014 MCP servers (shared with OpenCode)
39607
39660
 
39608
39661
  latentcode mcp list status of every server
@@ -39667,7 +39720,7 @@ async function mcpCommand(argv, cwd2 = process.cwd()) {
39667
39720
  case "add": {
39668
39721
  const project = rest.includes("--project");
39669
39722
  const spec = parseMcpAdd(rest.filter((x) => x !== "--project"));
39670
- const r = spawnSync(engineBin(), mcpAddArgv(spec, project ? "project" : "global"), { stdio: "inherit", cwd: cwd2 });
39723
+ const r = spawnSync2(engineBin(), mcpAddArgv(spec, project ? "project" : "global"), { stdio: "inherit", cwd: cwd2 });
39671
39724
  return r.status ?? 1;
39672
39725
  }
39673
39726
  case "remove":
@@ -39686,7 +39739,7 @@ async function mcpCommand(argv, cwd2 = process.cwd()) {
39686
39739
  }
39687
39740
  case "auth":
39688
39741
  case "logout": {
39689
- const r = spawnSync(engineBin(), ["mcp", sub, ...rest, "--standalone"], { stdio: "inherit", cwd: cwd2 });
39742
+ const r = spawnSync2(engineBin(), ["mcp", sub, ...rest, "--standalone"], { stdio: "inherit", cwd: cwd2 });
39690
39743
  return r.status ?? 1;
39691
39744
  }
39692
39745
  case "help":
@@ -39703,7 +39756,7 @@ ${HELP}`);
39703
39756
 
39704
39757
  // src/index.tsx
39705
39758
  var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
39706
- var VERSION = "0.1.0-alpha.10";
39759
+ var VERSION = "0.1.0-alpha.11";
39707
39760
  var usage = () => `${logo()}
39708
39761
  ${a.dim(`v${VERSION} \xB7 terminal coding agent. Bring your own model access; earn while it works.`)}
39709
39762
 
@@ -39787,14 +39840,14 @@ ${usage()}`);
39787
39840
  function auth(argv) {
39788
39841
  const engine = resolveEngineBin();
39789
39842
  if (!engine) throw new EngineError(ENGINE_NOT_FOUND);
39790
- const r = spawnSync2(engine.path, ["auth", ...argv.length ? argv : ["login"], "--standalone"], { stdio: "inherit" });
39843
+ const r = spawnSync3(engine.path, ["auth", ...argv.length ? argv : ["login"], "--standalone"], { stdio: "inherit" });
39791
39844
  process.exit(r.status ?? 1);
39792
39845
  }
39793
39846
  async function status() {
39794
39847
  const cfg = loadConfig();
39795
39848
  const wallet = resolveWallet(cfg);
39796
39849
  const server = resolveServer(cfg);
39797
- const engine = resolveEngineBin();
39850
+ const engine = resolveEngine();
39798
39851
  const earnOn = adsEnabled(cfg);
39799
39852
  const ok = a.ok("\u2713");
39800
39853
  const off = a.warn("\u25CB");
@@ -39805,10 +39858,11 @@ async function status() {
39805
39858
  row(wallet ? ok : off, "Wallet", wallet ? `${wallet}${cfg.auth ? a.dim(` (${cfg.auth})`) : ""}` : a.warn("not connected \u2014 run `latentcode login`")),
39806
39859
  row(earnOn && wallet ? ok : off, "Earn mode", earnOn ? "on" : "off"),
39807
39860
  row(
39808
- engine ? ok : a.err("\u2717"),
39861
+ engine ? engine.warning ? off : ok : a.err("\u2717"),
39809
39862
  "Engine",
39810
39863
  engine ? `opencode${engine.version ? " " + engine.version : ""} (${engine.source}) ${a.dim(engine.path)}` : a.err("not found")
39811
39864
  ),
39865
+ ...engine?.warning ? [row(a.dim(" "), "", a.warn(engine.warning))] : [],
39812
39866
  row(a.dim("\xB7"), "Ad server", a.dim(server))
39813
39867
  ];
39814
39868
  if (wallet) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latentcode",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.11",
4
4
  "description": "Terminal coding agent that pays you for idle time. Bring your own subscription; the model is never for sale.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,8 @@
18
18
  "typecheck": "tsc --noEmit",
19
19
  "test": "node --test tests/*.test.mjs",
20
20
  "dev": "npm run build && node dist/latentcode.mjs",
21
- "prepublishOnly": "npm run typecheck && npm run build && npm test"
21
+ "prepublishOnly": "npm run typecheck && npm run build && npm test",
22
+ "engine:check": "node scripts/engine-check.mjs"
22
23
  },
23
24
  "license": "MIT",
24
25
  "devDependencies": {
@@ -33,7 +34,7 @@
33
34
  "typescript": "^7.0.2"
34
35
  },
35
36
  "dependencies": {
36
- "@opencode/cli": "2.2.5"
37
+ "@opencode/cli": "2.4.2"
37
38
  },
38
39
  "repository": {
39
40
  "type": "git",