@jeffreyjyz/opencode-command-code 0.3.18 → 0.4.0

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.
@@ -1,6 +1,5 @@
1
1
  import type { LanguageModelV3 } from "@ai-sdk/provider";
2
2
  import { type WireLane } from "./wire";
3
- export declare const DEFAULT_BASE_URL = "https://api.commandcode.ai";
4
3
  export interface CommandCodeProviderOptions {
5
4
  /** Bearer key; the v2 host passes the resolved connection credential here. */
6
5
  apiKey?: string;
@@ -1,12 +1,6 @@
1
- import { spawn } from "node:child_process";
1
+ import { type OcPlan } from "../constants/sidebar";
2
2
  import { type ModelMeta, type Usage } from "./rows";
3
3
  import { type ZenUsage } from "./zen";
4
- /** `detached` is load-bearing, not tidiness: it starts the child in its own
5
- * session, so it has no controlling terminal. cmduse's snapshot() paints a
6
- * "fetching usage…" spinner straight to /dev/tty — piping stdout/stderr does
7
- * not stop it — which would corrupt the opencode TUI this process inherits its
8
- * tty from. Detaching makes that open fail; stdout/stderr stay piped. */
9
- export declare const SPAWN_OPTIONS: Parameters<typeof spawn>[2];
10
4
  /** Parse `cmduse -1 --json` into the usage snapshot. */
11
5
  export declare function parseUsageJson(text: string): Usage;
12
6
  /**
@@ -23,8 +17,17 @@ export declare function requireSnapshot(usage: Usage): Usage;
23
17
  * kind of session. Rows that carry only one side are kept.
24
18
  */
25
19
  export declare function parseMpcJson(text: string): Map<string, ModelMeta>;
26
- /** mpc's catalog, cached on disk: it scrapes live docs over the network. */
27
- export declare function loadMeta(): Promise<Map<string, ModelMeta>>;
20
+ /**
21
+ * mpc's args for the per-model catalog. `--shape off` is the recursion break
22
+ * (mpc's default `--shape auto` spawns reqshape, which spawns mpc back), never
23
+ * dropped; `--oc-plan` selects which Go plan's per-model allowance is baked in.
24
+ */
25
+ export declare function metaArgs(plan: OcPlan): string[];
26
+ /** ocuse's args: `--plan` selects the Go plan's per-model limits. */
27
+ export declare function zenArgs(plan: OcPlan): string[];
28
+ /** mpc's catalog, cached on disk: it scrapes live docs over the network. The
29
+ * cache is per plan, since mpc bakes that plan's per-model allowance into it. */
30
+ export declare function loadMeta(plan?: OcPlan): Promise<Map<string, ModelMeta>>;
28
31
  /** One usage snapshot from cmduse. Throws when cmduse is missing, fails, or
29
32
  * returns the errored defaults its JSON carries when the account API is
30
33
  * unreachable (see `requireSnapshot`). */
@@ -34,4 +37,4 @@ export declare function loadUsage(): Promise<Usage>;
34
37
  * (those providers have no usage API). Throws when ocuse is missing or fails,
35
38
  * and the caller then omits the panel.
36
39
  */
37
- export declare function loadZen(): Promise<ZenUsage>;
40
+ export declare function loadZen(plan?: OcPlan): Promise<ZenUsage>;
@@ -1,10 +1,12 @@
1
+ import { type OcPlan } from "../constants/sidebar";
1
2
  export interface Prefs {
2
3
  colors: boolean;
4
+ /** OpenCode Go plan the sidebar renders per-model limits for. */
5
+ ocPlan: OcPlan;
3
6
  }
4
- export declare const DEFAULTS: Prefs;
5
7
  /** Preferences live beside opencode's own config, XDG layout honoured. */
6
8
  export declare function prefsPath(env?: NodeJS.ProcessEnv): string;
7
- /** Only a literal `true` enables colour, so a typo cannot turn the panel on. */
9
+ /** Only a literal `true` enables colour; an unknown plan falls back to `go`. */
8
10
  export declare function parsePrefs(raw: unknown): Prefs;
9
- /** Env override, then the file, then the default. Cached for `CACHE_MS`. */
11
+ /** Env override, then the file, then the default. Cached for `PREFS_CACHE_MS`. */
10
12
  export declare function loadPrefs(env?: NodeJS.ProcessEnv, now?: number): Prefs;
@@ -21,11 +21,11 @@ export type SidebarRow = [
21
21
  export declare function pctTone(pct: number): Tone;
22
22
  /**
23
23
  * The sidebar is 42 columns wide with 2+2 padding, and our panel keeps one more
24
- * column clear on the right, so a rendered row must stay within this. Rows that
25
- * cannot fit are split across an indented continuation (`""` label) rather than
26
- * wrapping in the host's renderer, which is what made the panel look broken.
24
+ * column clear on the right, so a rendered row must stay within ROW_WIDTH.
25
+ * Rows that cannot fit are split across an indented continuation (`""` label)
26
+ * rather than wrapping in the host's renderer, which is what made the panel
27
+ * look broken.
27
28
  */
28
- export declare const ROW_WIDTH = 37;
29
29
  /** A horizontal rule between blocks. */
30
30
  export declare function separator(): SidebarRow;
31
31
  /** Truncate to `width`, ellipsis included. */
@@ -43,6 +43,8 @@ export interface ModelMeta {
43
43
  /** Cheapest plan that serves the model, from the generated catalog. */
44
44
  minPlan?: string | null;
45
45
  allowance?: number;
46
+ /** Unbounded on the CommandCode side: `allowance` is 0 by convention. */
47
+ free?: boolean;
46
48
  rates?: {
47
49
  input: number;
48
50
  output: number;
@@ -67,6 +69,8 @@ export interface ModelMeta {
67
69
  provider?: string;
68
70
  plan?: string;
69
71
  allowance?: number;
72
+ /** Unbounded on the OpenCode Go side: its allowance is 0 by convention. */
73
+ free?: boolean;
70
74
  rates?: {
71
75
  input: number;
72
76
  output: number;
@@ -112,6 +116,13 @@ export interface Usage {
112
116
  }
113
117
  /** Money at credit scale: cents, but "$60" not "$60.00". */
114
118
  export declare function money(value: number): string;
119
+ /**
120
+ * A monthly allowance as it appears on the panel. A free/unbounded model has no
121
+ * budget to divide — mpc reports `free: true` and allowance 0 — so it reads `∞`
122
+ * rather than the misleading `$0/mo` (0 is not a budget). Both sides call this,
123
+ * so a free CommandCode model and a free OpenCode Go one render alike.
124
+ */
125
+ export declare function allowanceLabel(limit: number, free?: boolean): string;
115
126
  /** Rate scale needs more precision than credit scale ($0.0036). */
116
127
  export declare function rate(value: number): string;
117
128
  export declare function count(value: number): string;
@@ -15,15 +15,20 @@ export declare function rememberSnapshot(snapshot: Usage): void;
15
15
  export declare function seededRows(): SidebarRow[];
16
16
  /**
17
17
  * Keep the last figure for a model. Keyed canonically because the session's id
18
- * and the stored `modelID` differ by vendor prefix and punctuation.
18
+ * and the stored `modelID` differ by vendor prefix and punctuation, and by the
19
+ * session too: the figure is the model's spend *in a conversation*, which the
20
+ * panel divides by that session's own total, so reusing it in another session
21
+ * counted one conversation's spend against another's and read as "over 100% of
22
+ * session".
19
23
  */
20
- export declare function rememberModelUsage(id: string, usage: ModelUsage): void;
24
+ export declare function rememberModelUsage(id: string, usage: ModelUsage, session?: string): void;
21
25
  /**
22
- * The remembered figure for `id`, or undefined when that model is unseen. An
23
- * undefined id is the frame during a session switch: keeping the previous row up
24
- * beats blanking it, the same call `wasOurs` makes for the account block.
26
+ * The remembered figure for `id` in `session`, or undefined when that model is
27
+ * unseen or the figure belongs to a different conversation. An undefined id is
28
+ * the frame during a session switch: keeping the previous row up beats blanking
29
+ * it, the same call `wasOurs` makes for the account block.
25
30
  */
26
- export declare function seededModelUsage(id: string | undefined): ModelUsage | undefined;
31
+ export declare function seededModelUsage(id: string | undefined, session?: string): ModelUsage | undefined;
27
32
  /** Keep a catalog for the next panel that needs it. An empty map is never
28
33
  * remembered: it cannot be distinguished from "mpc returned nothing" and would
29
34
  * wipe a good catalog. */
@@ -1,7 +1,3 @@
1
- /** 5-hour window length in seconds. Mirrors cmduse_core::FIVE_HOUR_SECS. */
2
- export declare const FIVE_HOUR_SECS: number;
3
- /** Weekly window length in seconds. Mirrors cmduse_core::WEEKLY_SECS. */
4
- export declare const WEEKLY_SECS: number;
5
1
  /**
6
2
  * Percentage of a rolling window that has elapsed, or undefined when the
7
3
  * window has not started (or has no reset time). `nowSecs` is whole seconds —
@@ -1,10 +1,4 @@
1
1
  import { type ModelMeta, type ModelUsage, type SidebarRow } from "./rows";
2
- /** Go's documented per-model window shares of the monthly allowance. */
3
- export declare const GO_WINDOW_SHARE: {
4
- readonly fiveHour: 0.2;
5
- readonly weekly: 0.5;
6
- readonly month: 1;
7
- };
8
2
  export interface ZenTotals {
9
3
  requests: number;
10
4
  cost: number;
package/dist/tui.d.ts CHANGED
@@ -33,8 +33,8 @@ interface V1Api {
33
33
  export declare const tui: (api: V1Api) => Promise<void>;
34
34
  export declare const commandCodeTui: TuiPluginNs.Definition;
35
35
  declare const _default: {
36
- tui: (api: V1Api) => Promise<void>;
37
36
  id: string;
38
37
  setup: (context: TuiPluginNs.Context) => Promise<TuiPluginNs.Cleanup | void> | TuiPluginNs.Cleanup | void;
38
+ tui: typeof tui;
39
39
  };
40
40
  export default _default;