latentcode 0.1.0-alpha.10 → 0.1.0-alpha.12

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);
@@ -34844,8 +34892,9 @@ function saveConfig(data) {
34844
34892
  }
34845
34893
  return next;
34846
34894
  }
34895
+ var serverOverride = "";
34847
34896
  function resolveServer(cfg = loadConfig()) {
34848
- return (process.env.LATENTCODE_ADS_SERVER || cfg.server || process.env.ADS_SERVER || DEFAULT_SERVER).replace(/\/+$/, "");
34897
+ return (process.env.LATENTCODE_ADS_SERVER || serverOverride || cfg.server || process.env.ADS_SERVER || DEFAULT_SERVER).replace(/\/+$/, "");
34849
34898
  }
34850
34899
  function resolveWallet(cfg = loadConfig()) {
34851
34900
  const w = cfg.wallet || process.env.ADS_WALLET || "";
@@ -35311,6 +35360,7 @@ var AdController = class {
35311
35360
  rotateMs: opts.rotateMs ?? ROTATE_MS,
35312
35361
  holdMs: opts.holdMs ?? HOLD_MS,
35313
35362
  activeMs: opts.activeMs ?? ACTIVE_MS,
35363
+ visible: opts.visible ?? (() => true),
35314
35364
  classify: opts.classify ?? ((p, cwd2) => classifyPrompt(p, cwd2))
35315
35365
  };
35316
35366
  opts.focus.onChange(() => this.emit());
@@ -35375,7 +35425,7 @@ var AdController = class {
35375
35425
  this.emit();
35376
35426
  }
35377
35427
  attentive(now) {
35378
- return this.o.focus.focused && (this.working || now - this.lastActivity < this.o.activeMs);
35428
+ return this.o.visible() && this.o.focus.focused && (this.working || now - this.lastActivity < this.o.activeMs);
35379
35429
  }
35380
35430
  /** An un-billed ad that may still be shown and billed. */
35381
35431
  holding() {
@@ -35731,19 +35781,26 @@ function credits(balanceUsd, bonus) {
35731
35781
 
35732
35782
  // src/ui/theme.ts
35733
35783
  var C = {
35734
- accent: "#A78BFA",
35735
- accent2: "#5EEAD4",
35736
- text: "#E5E7EB",
35737
- muted: "#9CA3AF",
35738
- faint: "#6B7280",
35739
- border: "#4B5563",
35740
- ok: "#4ADE80",
35741
- warn: "#FBBF24",
35742
- err: "#F87171",
35743
- earn: "#FCD34D",
35744
- add: "#4ADE80",
35745
- del: "#F87171",
35746
- code: "#93C5FD"
35784
+ /** Structure: frames, spinner, headings, LATENT in the wordmark (dashboard --accent). */
35785
+ accent: "#63A9FF",
35786
+ /** Ember accent: CODE in the wordmark, CTAs, the selected row (--ember-500). */
35787
+ accent2: "#FF8A3D",
35788
+ text: "#E2EDFF",
35789
+ muted: "#A3B5D3",
35790
+ faint: "#6E82A6",
35791
+ border: "#2C4673",
35792
+ /** --live */
35793
+ ok: "#4EE59A",
35794
+ /** --warn */
35795
+ warn: "#FFC56B",
35796
+ /** --danger */
35797
+ err: "#FF7A85",
35798
+ /** Money coming in and progress are ember (--ember-300). */
35799
+ earn: "#FFB270",
35800
+ add: "#4EE59A",
35801
+ del: "#FF7A85",
35802
+ /** --glow */
35803
+ code: "#8CC4FF"
35747
35804
  };
35748
35805
  var G = {
35749
35806
  prompt: "\u276F",
@@ -35944,12 +36001,18 @@ async function boot(args, focus, report) {
35944
36001
  throw e;
35945
36002
  }
35946
36003
  };
36004
+ let engineVersion = "";
35947
36005
  const engine = await step("engine", async () => {
35948
- const bin = resolveEngineBin();
36006
+ const bin = resolveEngine();
35949
36007
  if (!bin) throw new EngineError(ENGINE_NOT_FOUND);
35950
36008
  const value = await Engine.start({ cwd: args.cwd, bin: bin.path });
35951
36009
  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` };
36010
+ engineVersion = bin.version ?? "";
36011
+ return {
36012
+ value,
36013
+ status: bin.warning ? "warn" : "ok",
36014
+ detail: bin.warning ? `${bin.warning} \xB7 ${where}` : `opencode${bin.version ? " " + bin.version : ""} \xB7 ${where} \xB7 private, this session only`
36015
+ };
35953
36016
  });
35954
36017
  const models = new ModelStore();
35955
36018
  let latentStart;
@@ -36023,14 +36086,13 @@ async function boot(args, focus, report) {
36023
36086
  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
36087
  return { value: { wallet, server, api, controller }, status: enabled && wallet ? "ok" : "warn", detail };
36025
36088
  });
36026
- const engineVersion = resolveEngineBin()?.version ?? "";
36027
36089
  const sync = new StateSync({
36028
36090
  server: earn.server,
36029
36091
  key: () => loadConfig().sync_key,
36030
36092
  enabled: () => loadConfig().sync !== false,
36031
36093
  lastHash: fileHashStore(),
36032
36094
  collect: async () => buildSyncState({
36033
- appVersion: true ? "0.1.0-alpha.10" : "",
36095
+ appVersion: true ? "0.1.0-alpha.12" : "",
36034
36096
  engineVersion,
36035
36097
  model: await engine.defaultModel().then((m) => m ? `${m.providerID}/${m.id}` : session.key),
36036
36098
  catalog: await engine.catalog(),
@@ -36292,18 +36354,11 @@ function reduce(state, ev, now = Date.now()) {
36292
36354
  }
36293
36355
  }
36294
36356
 
36295
- // src/ui/StatusPanel.tsx
36296
- var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
36297
- var fmtTok = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n);
36298
- var fmtUsd2 = (n) => `$${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 2)}`;
36299
- var fmtCredits = (n) => `${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 3)} cr`;
36300
- function Rule({ width }) {
36301
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.border, children: "\u2500".repeat(Math.max(0, width)) });
36302
- }
36357
+ // src/ads/verdict.ts
36303
36358
  function verdictLabel(v) {
36304
36359
  switch (v) {
36305
36360
  case "tracked":
36306
- return { text: `${G.ok} view counted`, tone: "ok" };
36361
+ return { text: "\u2713 view counted", tone: "ok" };
36307
36362
  case "unearned":
36308
36363
  return { text: "view not paid on this device", tone: "warn" };
36309
36364
  case "skipped":
@@ -36314,6 +36369,15 @@ function verdictLabel(v) {
36314
36369
  return { text: "counting view\u2026", tone: "faint" };
36315
36370
  }
36316
36371
  }
36372
+
36373
+ // src/ui/StatusPanel.tsx
36374
+ var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
36375
+ var fmtTok = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n);
36376
+ var fmtUsd2 = (n) => `$${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 2)}`;
36377
+ var fmtCredits = (n) => `${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 3)} cr`;
36378
+ function Rule({ width }) {
36379
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.border, children: "\u2500".repeat(Math.max(0, width)) });
36380
+ }
36317
36381
  function Progress({ ms, of, billed, verdict }) {
36318
36382
  if (billed) {
36319
36383
  const l = verdictLabel(verdict);
@@ -39602,7 +39666,7 @@ function row(mark, label2, value, width = 10) {
39602
39666
  }
39603
39667
 
39604
39668
  // src/mcpCli.ts
39605
- import { spawnSync } from "node:child_process";
39669
+ import { spawnSync as spawnSync2 } from "node:child_process";
39606
39670
  var HELP = `${a.bold("latentcode mcp")} \u2014 MCP servers (shared with OpenCode)
39607
39671
 
39608
39672
  latentcode mcp list status of every server
@@ -39667,7 +39731,7 @@ async function mcpCommand(argv, cwd2 = process.cwd()) {
39667
39731
  case "add": {
39668
39732
  const project = rest.includes("--project");
39669
39733
  const spec = parseMcpAdd(rest.filter((x) => x !== "--project"));
39670
- const r = spawnSync(engineBin(), mcpAddArgv(spec, project ? "project" : "global"), { stdio: "inherit", cwd: cwd2 });
39734
+ const r = spawnSync2(engineBin(), mcpAddArgv(spec, project ? "project" : "global"), { stdio: "inherit", cwd: cwd2 });
39671
39735
  return r.status ?? 1;
39672
39736
  }
39673
39737
  case "remove":
@@ -39686,7 +39750,7 @@ async function mcpCommand(argv, cwd2 = process.cwd()) {
39686
39750
  }
39687
39751
  case "auth":
39688
39752
  case "logout": {
39689
- const r = spawnSync(engineBin(), ["mcp", sub, ...rest, "--standalone"], { stdio: "inherit", cwd: cwd2 });
39753
+ const r = spawnSync2(engineBin(), ["mcp", sub, ...rest, "--standalone"], { stdio: "inherit", cwd: cwd2 });
39690
39754
  return r.status ?? 1;
39691
39755
  }
39692
39756
  case "help":
@@ -39703,7 +39767,7 @@ ${HELP}`);
39703
39767
 
39704
39768
  // src/index.tsx
39705
39769
  var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
39706
- var VERSION = "0.1.0-alpha.10";
39770
+ var VERSION = "0.1.0-alpha.12";
39707
39771
  var usage = () => `${logo()}
39708
39772
  ${a.dim(`v${VERSION} \xB7 terminal coding agent. Bring your own model access; earn while it works.`)}
39709
39773
 
@@ -39787,14 +39851,14 @@ ${usage()}`);
39787
39851
  function auth(argv) {
39788
39852
  const engine = resolveEngineBin();
39789
39853
  if (!engine) throw new EngineError(ENGINE_NOT_FOUND);
39790
- const r = spawnSync2(engine.path, ["auth", ...argv.length ? argv : ["login"], "--standalone"], { stdio: "inherit" });
39854
+ const r = spawnSync3(engine.path, ["auth", ...argv.length ? argv : ["login"], "--standalone"], { stdio: "inherit" });
39791
39855
  process.exit(r.status ?? 1);
39792
39856
  }
39793
39857
  async function status() {
39794
39858
  const cfg = loadConfig();
39795
39859
  const wallet = resolveWallet(cfg);
39796
39860
  const server = resolveServer(cfg);
39797
- const engine = resolveEngineBin();
39861
+ const engine = resolveEngine();
39798
39862
  const earnOn = adsEnabled(cfg);
39799
39863
  const ok = a.ok("\u2713");
39800
39864
  const off = a.warn("\u25CB");
@@ -39805,10 +39869,11 @@ async function status() {
39805
39869
  row(wallet ? ok : off, "Wallet", wallet ? `${wallet}${cfg.auth ? a.dim(` (${cfg.auth})`) : ""}` : a.warn("not connected \u2014 run `latentcode login`")),
39806
39870
  row(earnOn && wallet ? ok : off, "Earn mode", earnOn ? "on" : "off"),
39807
39871
  row(
39808
- engine ? ok : a.err("\u2717"),
39872
+ engine ? engine.warning ? off : ok : a.err("\u2717"),
39809
39873
  "Engine",
39810
39874
  engine ? `opencode${engine.version ? " " + engine.version : ""} (${engine.source}) ${a.dim(engine.path)}` : a.err("not found")
39811
39875
  ),
39876
+ ...engine?.warning ? [row(a.dim(" "), "", a.warn(engine.warning))] : [],
39812
39877
  row(a.dim("\xB7"), "Ad server", a.dim(server))
39813
39878
  ];
39814
39879
  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.12",
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",