latentcode 0.1.0-alpha.6 → 0.1.0-alpha.7

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
@@ -3,7 +3,7 @@
3
3
  Terminal coding agent that pays you for its idle time.
4
4
 
5
5
  - **Bring your own model access.** API keys or a provider subscription where the provider allows third-party clients. Connect them inside the app with `/connect`.
6
- - **Earn mode.** While the agent works, one clearly labelled sponsored line sits in the working bar. You earn Latent Credit from it on your Latent wallet (the same wallet the other Latent surfaces use): $1 of model usage per credit with a bonus when you keep it — spend it with `/key`, or sell it for USDG.
6
+ - **Earn mode.** A clearly labelled sponsored slot sits in the status dock under the input, next to your model, provider, credit balance and session earnings. It appears while the agent works and stays after the reply; a view counts after 10 s with the terminal focused (idle time counts only while you are active). You earn Latent Credit from it on your Latent wallet (the same wallet the other Latent surfaces use): $1 of model usage per credit with a bonus when you keep it — spend it with `/key`, or sell it for USDG.
7
7
  - **The model is never for sale.** Ads never enter the model's context or output, and the agent never recommends sponsored tools. The only targeting signal that leaves your machine is a coarse category slug (for example `backend`), classified locally.
8
8
  - **Real attention.** An impression is billed once, and only after the ad has been on screen for 10 s while the terminal is focused (xterm focus events, DEC 1004) — the ad server's view floor, the same rule as every other Latent surface. A turn that ends earlier keeps the ad for the next turn instead of wasting it. Only impressions the server confirms count toward the session tally.
9
9
  - **Clickable.** In terminals with hyperlinks (iTerm2, Ghostty, Kitty, WezTerm, VS Code, Windows Terminal) the sponsored copy itself is a link; elsewhere the short URL is shown beside it. A coloured monogram badge (stable per brand) leads the line in every terminal. `ctrl+o` works everywhere. Every click goes through the ad server's tracked redirect. `LATENTCODE_LINKS=osc8|plain|hybrid` overrides the detection.
@@ -7941,7 +7941,7 @@ var require_react_reconciler_development = __commonJS({
7941
7941
  var HostPortal = 4;
7942
7942
  var HostComponent = 5;
7943
7943
  var HostText = 6;
7944
- var Fragment5 = 7;
7944
+ var Fragment6 = 7;
7945
7945
  var Mode = 8;
7946
7946
  var ContextConsumer = 9;
7947
7947
  var ContextProvider = 10;
@@ -8081,7 +8081,7 @@ var require_react_reconciler_development = __commonJS({
8081
8081
  return "DehydratedFragment";
8082
8082
  case ForwardRef:
8083
8083
  return getWrappedName$1(type, type.render, "ForwardRef");
8084
- case Fragment5:
8084
+ case Fragment6:
8085
8085
  return "Fragment";
8086
8086
  case HostComponent:
8087
8087
  return type;
@@ -11215,7 +11215,7 @@ var require_react_reconciler_development = __commonJS({
11215
11215
  }
11216
11216
  }
11217
11217
  function updateFragment2(returnFiber, current2, fragment, lanes, key) {
11218
- if (current2 === null || current2.tag !== Fragment5) {
11218
+ if (current2 === null || current2.tag !== Fragment6) {
11219
11219
  var created = createFiberFromFragment(fragment, returnFiber.mode, lanes, key);
11220
11220
  created.return = returnFiber;
11221
11221
  return created;
@@ -11618,7 +11618,7 @@ var require_react_reconciler_development = __commonJS({
11618
11618
  if (child.key === key) {
11619
11619
  var elementType = element.type;
11620
11620
  if (elementType === REACT_FRAGMENT_TYPE) {
11621
- if (child.tag === Fragment5) {
11621
+ if (child.tag === Fragment6) {
11622
11622
  deleteRemainingChildren(returnFiber, child.sibling);
11623
11623
  var existing = useFiber(child, element.props.children);
11624
11624
  existing.return = returnFiber;
@@ -17109,7 +17109,7 @@ var require_react_reconciler_development = __commonJS({
17109
17109
  var _resolvedProps2 = workInProgress2.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
17110
17110
  return updateForwardRef(current2, workInProgress2, type, _resolvedProps2, renderLanes2);
17111
17111
  }
17112
- case Fragment5:
17112
+ case Fragment6:
17113
17113
  return updateFragment(current2, workInProgress2, renderLanes2);
17114
17114
  case Mode:
17115
17115
  return updateMode(current2, workInProgress2, renderLanes2);
@@ -17546,7 +17546,7 @@ var require_react_reconciler_development = __commonJS({
17546
17546
  case SimpleMemoComponent:
17547
17547
  case FunctionComponent:
17548
17548
  case ForwardRef:
17549
- case Fragment5:
17549
+ case Fragment6:
17550
17550
  case Mode:
17551
17551
  case Profiler:
17552
17552
  case ContextConsumer:
@@ -22314,7 +22314,7 @@ var require_react_reconciler_development = __commonJS({
22314
22314
  return fiber;
22315
22315
  }
22316
22316
  function createFiberFromFragment(elements, mode, lanes, key) {
22317
- var fiber = createFiber(Fragment5, elements, key, mode);
22317
+ var fiber = createFiber(Fragment6, elements, key, mode);
22318
22318
  fiber.lanes = lanes;
22319
22319
  return fiber;
22320
22320
  }
@@ -34846,6 +34846,7 @@ function classifyPrompt(prompt, cwd2 = process.cwd()) {
34846
34846
  var MIN_VISIBLE_MS = 1e4;
34847
34847
  var ROTATE_MS = 1e4;
34848
34848
  var HOLD_MS = 27e4;
34849
+ var ACTIVE_MS = 6e4;
34849
34850
  function safeUrl(raw) {
34850
34851
  return raw && isSafeUrl(raw) ? new URL(raw).toString() : "";
34851
34852
  }
@@ -34875,10 +34876,14 @@ var AdController = class {
34875
34876
  billed = false;
34876
34877
  lastTick = 0;
34877
34878
  fetching = false;
34879
+ /** Generation of the request in flight; a stale one never blocks a new turn. */
34880
+ fetchingGen = -1;
34878
34881
  generation = 0;
34879
34882
  context = "general";
34880
34883
  impressions = 0;
34881
34884
  sessionEarned = 0;
34885
+ adIndex = 0;
34886
+ lastActivity = 0;
34882
34887
  listeners = /* @__PURE__ */ new Set();
34883
34888
  /** Cached for useSyncExternalStore — must be referentially stable between emits. */
34884
34889
  snap = null;
@@ -34890,6 +34895,7 @@ var AdController = class {
34890
34895
  minVisibleMs: opts.minVisibleMs ?? MIN_VISIBLE_MS,
34891
34896
  rotateMs: opts.rotateMs ?? ROTATE_MS,
34892
34897
  holdMs: opts.holdMs ?? HOLD_MS,
34898
+ activeMs: opts.activeMs ?? ACTIVE_MS,
34893
34899
  classify: opts.classify ?? ((p, cwd2) => classifyPrompt(p, cwd2))
34894
34900
  };
34895
34901
  opts.focus.onChange(() => this.emit());
@@ -34920,7 +34926,9 @@ var AdController = class {
34920
34926
  if (this.snap) return this.snap;
34921
34927
  return this.snap = {
34922
34928
  status: this.status,
34923
- current: this.working ? this.current : null,
34929
+ current: this.current,
34930
+ adIndex: this.adIndex,
34931
+ idle: !this.working,
34924
34932
  visibleMs: this.visibleMs,
34925
34933
  billed: this.billed,
34926
34934
  focusTracked: this.o.focus.known,
@@ -34929,24 +34937,30 @@ var AdController = class {
34929
34937
  context: this.context
34930
34938
  };
34931
34939
  }
34940
+ /** The user typed or pasted: idle dwell may count for the next ACTIVE_MS. */
34941
+ noteActivity() {
34942
+ this.lastActivity = this.o.now();
34943
+ }
34932
34944
  /** Called on execution start/end. `prompt` is classified locally, never sent. */
34933
34945
  setWorking(working, prompt = "") {
34934
34946
  if (working === this.working) return;
34935
34947
  this.working = working;
34936
34948
  this.lastTick = this.o.now();
34949
+ this.lastActivity = this.lastTick;
34937
34950
  if (working) {
34938
34951
  this.context = this.o.classify(prompt, this.o.cwd);
34939
- if (!this.holding()) {
34940
- this.clear();
34941
- void this.fetchNext();
34942
- }
34943
- } else if (this.billed || !this.current) {
34952
+ if (this.current && !this.billed && !this.holding()) this.clear();
34953
+ if (!this.holding()) void this.fetchNext();
34954
+ } else if (!this.current) {
34944
34955
  this.clear();
34945
34956
  } else {
34946
34957
  this.generation += 1;
34947
34958
  }
34948
34959
  this.emit();
34949
34960
  }
34961
+ attentive(now) {
34962
+ return this.o.focus.focused && (this.working || now - this.lastActivity < this.o.activeMs);
34963
+ }
34950
34964
  /** An un-billed ad that may still be shown and billed. */
34951
34965
  holding() {
34952
34966
  return !!this.current && !this.billed && this.o.now() - this.current.fetchedAt < this.o.holdMs;
@@ -34956,13 +34970,22 @@ var AdController = class {
34956
34970
  const now = this.o.now();
34957
34971
  const dt = Math.max(0, now - this.lastTick);
34958
34972
  this.lastTick = now;
34959
- if (!this.working || !this.current) return;
34973
+ if (!this.current) return;
34960
34974
  if (!this.billed && !this.holding()) {
34961
34975
  this.clear();
34962
- void this.fetchNext();
34976
+ if (this.working) void this.fetchNext();
34977
+ this.emit();
34963
34978
  return;
34964
34979
  }
34965
- if (this.o.focus.focused) this.visibleMs += dt;
34980
+ if (!this.working && this.billed && now - this.current.fetchedAt >= this.o.holdMs) {
34981
+ this.clear();
34982
+ this.emit();
34983
+ return;
34984
+ }
34985
+ if (!this.billed && this.attentive(now)) {
34986
+ this.visibleMs += dt;
34987
+ this.emit();
34988
+ }
34966
34989
  if (!this.billed && this.visibleMs >= this.o.minVisibleMs) {
34967
34990
  this.billed = true;
34968
34991
  const shown = this.current;
@@ -34982,14 +35005,13 @@ var AdController = class {
34982
35005
  });
34983
35006
  this.emit();
34984
35007
  }
34985
- if (this.billed && now - this.shownAt >= this.o.rotateMs && !this.fetching) {
35008
+ if (this.working && this.billed && now - this.shownAt >= this.o.rotateMs && !this.fetching) {
34986
35009
  void this.fetchNext();
34987
35010
  }
34988
35011
  }
34989
35012
  /** User asked to open the ad (keyboard): the tracked link, or null. The server counts the click on redirect. */
34990
35013
  click() {
34991
- const ad = this.working ? this.current : null;
34992
- return ad?.link || null;
35014
+ return this.current?.link || null;
34993
35015
  }
34994
35016
  clear() {
34995
35017
  this.generation += 1;
@@ -34998,9 +35020,10 @@ var AdController = class {
34998
35020
  this.billed = false;
34999
35021
  }
35000
35022
  async fetchNext() {
35001
- if (this.status !== "ok" || this.fetching) return;
35002
- this.fetching = true;
35003
35023
  const gen = this.generation;
35024
+ if (this.status !== "ok" || this.fetching && this.fetchingGen === gen) return;
35025
+ this.fetching = true;
35026
+ this.fetchingGen = gen;
35004
35027
  try {
35005
35028
  const ad = await this.o.api.request({ wallet: this.o.wallet, context: this.context, sessionId: this.o.sessionId });
35006
35029
  if (gen !== this.generation || !this.working || this.status !== "ok") return;
@@ -35010,13 +35033,14 @@ var AdController = class {
35010
35033
  return;
35011
35034
  }
35012
35035
  this.current = display;
35036
+ this.adIndex += 1;
35013
35037
  this.shownAt = this.o.now();
35014
35038
  this.lastTick = this.shownAt;
35015
35039
  this.visibleMs = 0;
35016
35040
  this.billed = false;
35017
35041
  this.emit();
35018
35042
  } finally {
35019
- this.fetching = false;
35043
+ if (this.fetchingGen === gen) this.fetching = false;
35020
35044
  }
35021
35045
  }
35022
35046
  emit() {
@@ -35810,48 +35834,144 @@ function reduce(state, ev, now = Date.now()) {
35810
35834
  }
35811
35835
  }
35812
35836
 
35813
- // src/ui/SponsoredLine.tsx
35837
+ // src/ui/StatusPanel.tsx
35814
35838
  var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
35815
- var MAX_BARE_URL = 60;
35816
- var SHAPE = linkShape();
35817
- function SponsoredLine({ ad, billed, shape = SHAPE }) {
35818
- const linked = !!ad.link && shape !== "plain";
35819
- const showUrl = !!ad.shownUrl && shape !== "osc8" && ad.shownUrl.length <= MAX_BARE_URL;
35820
- const badge = adBadge(ad.title || ad.body);
35821
- const copy = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
35822
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, underline: linked, children: ad.title || ad.body }),
35823
- ad.title && ad.body ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.muted, children: [
35824
- " \u2014 ",
35825
- ad.body
35826
- ] }) : null
35839
+ var fmtTok = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n);
35840
+ var fmtUsd2 = (n) => `$${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 2)}`;
35841
+ function Rule({ width }) {
35842
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.border, children: "\u2500".repeat(Math.max(0, width)) });
35843
+ }
35844
+ function Progress({ ms, of, billed }) {
35845
+ if (billed) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.ok, children: [
35846
+ G.ok,
35847
+ " view counted"
35827
35848
  ] });
35828
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
35829
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
35830
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
35831
- G.earn,
35832
- " Sponsored"
35833
- ] }),
35834
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35835
- " ",
35836
- G.thin,
35837
- " "
35849
+ const n = 10;
35850
+ const filled = Math.min(n, Math.floor(ms / of * n));
35851
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
35852
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.earn, children: "\u25B0".repeat(filled) }),
35853
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.border, children: "\u25B1".repeat(n - filled) }),
35854
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35855
+ " ",
35856
+ Math.floor(ms / 1e3),
35857
+ "s / ",
35858
+ Math.round(of / 1e3),
35859
+ "s"
35860
+ ] })
35861
+ ] });
35862
+ }
35863
+ function StatusPanel(p) {
35864
+ const inner = p.width - 4;
35865
+ const frame = p.working ? C.accent : C.border;
35866
+ const name = p.model || "no model";
35867
+ const prov = p.provider ? ` \xB7 ${p.provider}` : "";
35868
+ const variant = p.variant ? ` ${p.variant}` : "";
35869
+ const usage2 = [p.tokens ? `${fmtTok(p.tokens)} tok` : "", p.cost ? fmtUsd2(p.cost) : ""].filter(Boolean).join(" \xB7 ");
35870
+ const rightLen = usage2 ? usage2.length + 2 : 0;
35871
+ const leftBudget = p.width - 9 - rightLen;
35872
+ const leftText = clip(`${name}${variant}${prov}`, Math.max(8, leftBudget));
35873
+ const fill = Math.max(1, p.width - 8 - leftText.length - rightLen);
35874
+ const top = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
35875
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: frame, children: "\u256D\u2500 " }),
35876
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: p.latent ? C.earn : p.working ? C.accent : C.ok, children: G.dot }),
35877
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
35878
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, color: C.text, children: leftText.slice(0, name.length) }),
35879
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.accent2, children: leftText.slice(name.length, name.length + variant.length) }),
35880
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.muted, children: leftText.slice(name.length + variant.length) }),
35881
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: frame, children: [
35882
+ " ",
35883
+ "\u2500".repeat(fill)
35884
+ ] }),
35885
+ usage2 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35886
+ " ",
35887
+ usage2,
35888
+ " "
35889
+ ] }) : null,
35890
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: frame, children: "\u2500\u256E" })
35891
+ ] });
35892
+ const earnings = p.earn === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
35893
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
35894
+ G.earn,
35895
+ " "
35896
+ ] }),
35897
+ p.balance != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
35898
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, bold: true, children: [
35899
+ p.balance.toFixed(3),
35900
+ " cr"
35838
35901
  ] }),
35839
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { backgroundColor: badge.color, color: "#111827", bold: true, children: ` ${badge.letter} ` }),
35840
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
35841
- linked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Transform, { transform: (out) => osc8(out, ad.link), children: copy }) : copy,
35842
- showUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.accent2, children: [
35843
- " \xB7 ",
35844
- ad.shownUrl
35845
- ] }) : null,
35846
- ad.link ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35847
- " \xB7 ctrl+o ",
35848
- ad.ctaText
35849
- ] }) : null
35902
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, children: " \xB7 " })
35903
+ ] }) : null,
35904
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
35905
+ "+",
35906
+ p.sessionCredits.toFixed(3)
35850
35907
  ] }),
35851
- billed && ad.earn > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
35852
- " +$",
35853
- ad.earn.toFixed(4)
35854
- ] }) : null
35908
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35909
+ inner >= 84 ? " this session" : "",
35910
+ " \xB7 ",
35911
+ p.views,
35912
+ " view",
35913
+ p.views === 1 ? "" : "s"
35914
+ ] })
35915
+ ] }) : p.earn === "disabled" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35916
+ G.earn,
35917
+ " Earn off \xB7 /ads on"
35918
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.warn, children: [
35919
+ G.earn,
35920
+ " /login to start earning"
35921
+ ] });
35922
+ const ad = p.earn === "ok" ? p.ad : null;
35923
+ let body;
35924
+ if (ad) {
35925
+ const badge = adBadge(ad.title || ad.body);
35926
+ const cta = ad.link ? `${ad.ctaText || "Open"} ${G.arrow}` : "";
35927
+ const ctaLen = cta ? cta.length + 8 : 0;
35928
+ const brand = ad.title || ad.body;
35929
+ const rest = ad.title && ad.body ? ` \u2014 ${ad.body}` : "";
35930
+ const copyText = clip(brand + rest, Math.max(10, inner - 4 - ctaLen));
35931
+ const copy = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
35932
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, underline: !!ad.link && p.osc8Links, children: copyText.slice(0, brand.length) }),
35933
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.muted, children: copyText.slice(brand.length) })
35934
+ ] });
35935
+ body = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
35936
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
35937
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, bold: true, children: "SPONSORED" }),
35938
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
35939
+ "AD \xB7 ",
35940
+ String(p.adIndex ?? 1).padStart(2, "0")
35941
+ ] })
35942
+ ] }),
35943
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
35944
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
35945
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { backgroundColor: badge.color, color: "#111827", bold: true, children: ` ${badge.letter} ` }),
35946
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
35947
+ p.osc8Links && ad.link ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Transform, { transform: (o) => osc8(o, ad.link), children: copy }) : copy
35948
+ ] }),
35949
+ cta ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
35950
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.accent2, bold: true, children: cta }),
35951
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, children: " ctrl+o" })
35952
+ ] }) : null
35953
+ ] }),
35954
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Rule, { width: inner }),
35955
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
35956
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
35957
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Progress, { ms: p.visibleMs ?? 0, of: p.minVisibleMs ?? 1e4, billed: !!p.billed }),
35958
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, children: " \xB7 Powered by Latent Ads" })
35959
+ ] }),
35960
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexShrink: 0, marginLeft: 2, children: earnings })
35961
+ ] })
35962
+ ] });
35963
+ } else {
35964
+ body = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
35965
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, wrap: "truncate-end", children: [
35966
+ p.wallet ? p.wallet : "",
35967
+ p.earn === "ok" ? `${p.wallet ? " \xB7 " : ""}ads show while the agent works` : ""
35968
+ ] }),
35969
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexShrink: 0, marginLeft: 2, children: earnings })
35970
+ ] });
35971
+ }
35972
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { flexDirection: "column", width: p.width, children: [
35973
+ top,
35974
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexDirection: "column", borderStyle: "round", borderTop: false, borderColor: frame, paddingX: 1, width: p.width, children: body })
35855
35975
  ] });
35856
35976
  }
35857
35977
 
@@ -37861,6 +37981,7 @@ function HelpPanel({ width, commands, onClose }) {
37861
37981
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.faint, wrap: "wrap", children: `Privacy: ads never enter the model's context or its answers. The only thing sent to the ad server is a coarse category (for example "backend"), worked out on this machine.` }) })
37862
37982
  ] });
37863
37983
  }
37984
+ var LINKS_OSC8 = linkShape() === "osc8";
37864
37985
  function App2(props) {
37865
37986
  const { engine, controller, api, cwd: cwd2, version } = props;
37866
37987
  const { exit } = use_app_default();
@@ -37938,14 +38059,27 @@ function App2(props) {
37938
38059
  (0, import_react26.useEffect)(() => {
37939
38060
  controller.setWorking(state.working, lastPrompt.current);
37940
38061
  }, [state.working, controller]);
38062
+ const lingering = !state.working && !!ad.current;
37941
38063
  (0, import_react26.useEffect)(() => {
37942
- if (!state.working) return;
37943
- const t = setInterval(() => {
37944
- controller.tick();
37945
- tick((f) => f + 1);
37946
- }, 250);
38064
+ if (!state.working && !lingering) return;
38065
+ const t = setInterval(
38066
+ () => {
38067
+ controller.tick();
38068
+ if (state.working) tick((f) => f + 1);
38069
+ },
38070
+ state.working ? 250 : 1e3
38071
+ );
37947
38072
  return () => clearInterval(t);
37948
- }, [state.working, controller]);
38073
+ }, [state.working, lingering, controller]);
38074
+ const [balance, setBalance] = (0, import_react26.useState)(null);
38075
+ (0, import_react26.useEffect)(() => {
38076
+ if (!wallet || state.working) return;
38077
+ let live2 = true;
38078
+ void api.creditSummary(wallet).then((c) => live2 && setBalance(c ? c.credits : null));
38079
+ return () => {
38080
+ live2 = false;
38081
+ };
38082
+ }, [api, wallet, state.working, ad.impressions]);
37949
38083
  (0, import_react26.useEffect)(() => setPermAt(0), [state.permissions[0]?.id]);
37950
38084
  (0, import_react26.useEffect)(() => {
37951
38085
  if (!quitArmed) return;
@@ -38156,9 +38290,13 @@ Spend it here: /login connects the Latent provider (or /key lk_\u2026 with a key
38156
38290
  const matches = overlay || perm || paletteHidden ? [] : matchCommands(editor.text, allCommands);
38157
38291
  const paletteOpen = matches.length > 0 && !(matches.length === 1 && "/" + matches[0].name === editor.text && !matches[0].args);
38158
38292
  const paletteSel = Math.min(paletteAt, Math.max(0, matches.length - 1));
38159
- usePaste((text) => setEditor(insert(editorRef.current, text.replace(/\n+$/, ""))), overlay === null && !perm);
38293
+ usePaste((text) => {
38294
+ controller.noteActivity();
38295
+ setEditor(insert(editorRef.current, text.replace(/\n+$/, "")));
38296
+ }, overlay === null && !perm);
38160
38297
  use_input_default(
38161
38298
  (ch, key) => {
38299
+ controller.noteActivity();
38162
38300
  if (perm) {
38163
38301
  const decisions = ["once", "always", "reject"];
38164
38302
  const reply = (d) => void engine.replyPermission(sessionID, perm.id, d).catch(fail);
@@ -38218,28 +38356,25 @@ Spend it here: /login connects the Latent provider (or /key lk_\u2026 with a key
38218
38356
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Static, { items: [header, ...done.map((it) => ({ id: it.id, it }))], children: (entry) => "it" in entry ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ItemView, { item: entry.it, live: false, cwd: cwd2, width, maxLines }, entry.id) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BootCard, { steps: props.bootSteps, version, cwd: cwd2, width, ready: true }, entry.id) }),
38219
38357
  live.map((it) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ItemView, { item: it, live: true, cwd: cwd2, width, maxLines }, it.id)),
38220
38358
  perm ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PermissionPrompt, { perm, selected: permAt, cwd: cwd2, width }) : null,
38221
- state.working ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { marginTop: 1, flexDirection: "column", width, children: [
38222
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
38223
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Spinner, {}),
38224
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { children: [
38225
- " ",
38226
- activityLabel(state),
38227
- "\u2026"
38228
- ] }),
38229
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
38230
- " ",
38231
- elapsed,
38232
- "s \xB7 ",
38233
- G.up,
38234
- fmtTokens(state.tokens.input),
38235
- " ",
38236
- G.down,
38237
- fmtTokens(state.tokens.output),
38238
- " \xB7 esc to interrupt"
38239
- ] })
38359
+ state.working ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { marginTop: 1, flexDirection: "column", width, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
38360
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Spinner, {}),
38361
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { children: [
38362
+ " ",
38363
+ activityLabel(state),
38364
+ "\u2026"
38240
38365
  ] }),
38241
- ad.current ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SponsoredLine, { ad: ad.current, billed: ad.billed }) : null
38242
- ] }) : null,
38366
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
38367
+ " ",
38368
+ elapsed,
38369
+ "s \xB7 ",
38370
+ G.up,
38371
+ fmtTokens(state.tokens.input),
38372
+ " ",
38373
+ G.down,
38374
+ fmtTokens(state.tokens.output),
38375
+ " \xB7 esc to interrupt"
38376
+ ] })
38377
+ ] }) }) : null,
38243
38378
  overlay?.t === "model" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
38244
38379
  ModelPicker,
38245
38380
  {
@@ -38317,44 +38452,29 @@ Spend it here: /login connects the Latent provider (or /key lk_\u2026 with a key
38317
38452
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["tab", "complete"], ["enter", "run"], ["esc", "dismiss"]] })
38318
38453
  ] }) : null
38319
38454
  ] }) : null,
38320
- paletteOpen || leaving ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { width, justifyContent: "space-between", paddingX: 1, children: [
38321
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { wrap: "truncate-end", children: quitArmed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.warn, children: "Press ctrl+c again to quit" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
38322
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: current ? C.text : C.warn, children: current?.name ?? (state.model || "no model") }),
38323
- state.variant ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.accent2, children: [
38324
- " ",
38325
- state.variant
38326
- ] }) : null,
38327
- provider ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
38328
- " \xB7 ",
38329
- provider.name
38330
- ] }) : null,
38331
- state.tokens.input + state.tokens.output ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
38332
- " ",
38333
- "\xB7 ",
38334
- fmtTokens(state.tokens.input + state.tokens.output),
38335
- " tok",
38336
- state.cost ? ` \xB7 ${fmtUsd(state.cost)}` : ""
38337
- ] }) : null
38338
- ] }) }),
38339
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { wrap: "truncate-end", children: ad.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.earn, children: [
38340
- G.earn,
38341
- " ",
38342
- credits(ad.sessionEarned, bonus).toFixed(3),
38343
- " cr earned",
38344
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
38345
- " \xB7 ",
38346
- ad.impressions,
38347
- " view",
38348
- ad.impressions === 1 ? "" : "s"
38349
- ] })
38350
- ] }) : ad.status === "disabled" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
38351
- G.earn,
38352
- " Earn off \xB7 /ads on"
38353
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.warn, children: [
38354
- G.earn,
38355
- " /login to start earning"
38356
- ] }) })
38357
- ] })
38455
+ paletteOpen || leaving ? null : quitArmed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { paddingX: 1, width, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.warn, children: "Press ctrl+c again to quit" }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
38456
+ StatusPanel,
38457
+ {
38458
+ width,
38459
+ model: current?.name ?? state.model,
38460
+ variant: state.variant,
38461
+ provider: provider?.name,
38462
+ latent: (current?.providerID ?? parseKey(state.model)?.providerID) === "latent",
38463
+ working: state.working,
38464
+ tokens: state.tokens.input + state.tokens.output,
38465
+ cost: state.cost,
38466
+ earn: ad.status,
38467
+ ad: ad.current,
38468
+ adIndex: ad.adIndex,
38469
+ visibleMs: ad.visibleMs,
38470
+ billed: ad.billed,
38471
+ balance,
38472
+ sessionCredits: credits(ad.sessionEarned, bonus),
38473
+ views: ad.impressions,
38474
+ wallet: shortWallet(wallet),
38475
+ osc8Links: LINKS_OSC8
38476
+ }
38477
+ )
38358
38478
  ] });
38359
38479
  }
38360
38480
 
@@ -38610,7 +38730,7 @@ function row(mark, label2, value, width = 10) {
38610
38730
 
38611
38731
  // src/index.tsx
38612
38732
  var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
38613
- var VERSION = "0.1.0-alpha.6";
38733
+ var VERSION = "0.1.0-alpha.7";
38614
38734
  var usage = () => `${logo()}
38615
38735
  ${a.dim(`v${VERSION} \xB7 terminal coding agent. Bring your own model access; earn while it works.`)}
38616
38736
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latentcode",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.7",
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": {