@vecteur/cli 0.2.1 → 0.2.2

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.
@@ -10,7 +10,7 @@ import { createInterface } from "node:readline";
10
10
  import { loadConfig } from "../config.js";
11
11
  import { login } from "./auth.js";
12
12
  import { streamTurn, webBase, buildLocalContextQuery, openBrowser } from "../runner.js";
13
- import { handleSlashCommand, parseMentions, resolveWorkspaceProject } from "../session.js";
13
+ import { handleSlashCommand, parseMentions, renameProject, resolveWorkspaceProject, titleFromPrompt } from "../session.js";
14
14
  const DIM = "\x1b[2m", RESET = "\x1b[0m", CYAN = "\x1b[36m", BOLD = "\x1b[1m";
15
15
  export async function chat() {
16
16
  let cfg = loadConfig();
@@ -105,6 +105,9 @@ export async function chat() {
105
105
  console.log("\n" + (res.answer ?? "(no answer)") + "\n");
106
106
  if (res.sawVisual)
107
107
  console.log(`${DIM}(visual artifacts — see ${webBase()}/projects/${project})${RESET}`);
108
+ // First prompt in a freshly-created project becomes its title (self-describing in the web app).
109
+ if (created && turns === 0)
110
+ void renameProject(project, titleFromPrompt(raw));
108
111
  lastTaskId = res.taskId;
109
112
  turns++;
110
113
  }
package/dist/session.js CHANGED
@@ -7,14 +7,33 @@ export async function resolveWorkspaceProject() {
7
7
  const bound = getWorkspaceProject(cwd);
8
8
  if (bound)
9
9
  return { id: bound, created: false };
10
- const name = basename(cwd) || "workspace";
10
+ // Provisional, unique title until the first prompt renames it: "<dir> · <datetime>".
11
+ // The directory tells you where it came from; the timestamp keeps same-named dirs distinct.
12
+ const dir = basename(cwd) || "workspace";
13
+ const stamp = new Date().toISOString().slice(0, 16).replace("T", " ");
11
14
  const proj = await api("/api/v1/projects", {
12
15
  method: "POST",
13
- body: { name: `${name} (CLI)` },
16
+ body: { name: `${dir} · ${stamp}` },
14
17
  });
15
18
  setWorkspaceProject(cwd, proj.id);
16
19
  return { id: proj.id, created: true };
17
20
  }
21
+ /** A short, human project title from the user's first prompt (collapsed + capped to 60 chars). */
22
+ export function titleFromPrompt(raw) {
23
+ const t = raw.replace(/\s+/g, " ").trim();
24
+ return t.length > 60 ? `${t.slice(0, 57).trimEnd()}…` : t;
25
+ }
26
+ /** Rename a project (best-effort — a nicer title must never break or block a turn). */
27
+ export async function renameProject(projectId, name) {
28
+ if (!name)
29
+ return;
30
+ try {
31
+ await api(`/api/v1/projects/${projectId}`, { method: "PUT", body: { name } });
32
+ }
33
+ catch {
34
+ /* ignore — title is cosmetic */
35
+ }
36
+ }
18
37
  /** Split a line into the prompt text and any @path file mentions. */
19
38
  export function parseMentions(line) {
20
39
  const files = [];
@@ -27,6 +46,7 @@ export function parseMentions(line) {
27
46
  return { text: text.trim(), files };
28
47
  }
29
48
  export const SLASH_COMMANDS = [
49
+ { name: "usage", desc: "show remaining AI usage, forecast and granted pools" },
30
50
  { name: "files", desc: "list files in this workspace directory" },
31
51
  { name: "project", desc: "show the project bound to this directory" },
32
52
  { name: "open", desc: "open this workspace's run in the web app" },
@@ -35,6 +55,44 @@ export const SLASH_COMMANDS = [
35
55
  { name: "help", desc: "show this help" },
36
56
  { name: "exit", desc: "quit" },
37
57
  ];
58
+ /** 1,000 usage units ≈ 1 minute — same vocabulary as the web app and MCP. */
59
+ export function unitsAsTime(units) {
60
+ if (units < 0)
61
+ return "unlimited";
62
+ const minutes = Math.round(units / 1000);
63
+ if (minutes < 60)
64
+ return `${minutes} min`;
65
+ const hours = Math.floor(minutes / 60);
66
+ const rem = minutes % 60;
67
+ return rem === 0 ? `${hours}h` : `${hours}h ${String(rem).padStart(2, "0")}m`;
68
+ }
69
+ export function formatUsage(sub) {
70
+ const lines = [];
71
+ const t = sub.tokens;
72
+ lines.push(`plan: ${(sub.account_type ?? "free").toUpperCase()}`);
73
+ if (t) {
74
+ const dailyLeft = Math.max(0, t.daily_limit - t.daily_used);
75
+ const monthlyLeft = Math.max(0, t.monthly_limit - t.monthly_used);
76
+ lines.push(`today: ${unitsAsTime(t.daily_used)} used · ≈ ${unitsAsTime(dailyLeft)} left of ${unitsAsTime(t.daily_limit)}`);
77
+ lines.push(`this month: ${unitsAsTime(t.monthly_used)} used · ≈ ${unitsAsTime(monthlyLeft)} left of ${unitsAsTime(t.monthly_limit)}`);
78
+ }
79
+ if (sub.forecast) {
80
+ const f = sub.forecast;
81
+ const pct = f.projected_pct_of_limit != null ? `~${f.projected_pct_of_limit}% of your monthly allowance by month-end` : "";
82
+ const dep = f.depletion_date ? ` · runs out ~${f.depletion_date}` : "";
83
+ if (pct || dep)
84
+ lines.push(`forecast: ${pct}${dep}`);
85
+ }
86
+ for (const g of sub.grants ?? []) {
87
+ const shared = (g.shared_member_count ?? 0) > 1 ? ` · shared with ${g.shared_member_count}` : "";
88
+ const exp = g.expires_at ? ` · expires ${g.expires_at.slice(0, 10)}` : "";
89
+ lines.push(`granted: ${unitsAsTime(g.remaining_units ?? 0)} left (${g.label ?? "grant"})${shared}${exp}`);
90
+ }
91
+ if (typeof sub.credit_balance_eur === "number") {
92
+ lines.push(`credits: €${sub.credit_balance_eur.toFixed(2)}`);
93
+ }
94
+ return lines.map((l) => ` ${l}`).join("\n");
95
+ }
38
96
  export const HELP = `
39
97
  Commands:
40
98
  @path attach a local file as context (e.g. "explain @mission.md")
@@ -59,5 +117,14 @@ export async function handleSlashCommand(cmd, ctx) {
59
117
  const output = (files.files ?? []).map((f) => ` ${f.name ?? f}`).join("\n") || " (none)";
60
118
  return { output };
61
119
  }
120
+ if (name === "usage") {
121
+ try {
122
+ const sub = await api("/api/v1/billing/subscription");
123
+ return { output: formatUsage(sub) };
124
+ }
125
+ catch (e) {
126
+ return { output: `could not load usage (${e.message})` };
127
+ }
128
+ }
62
129
  return { output: `unknown command: /${name} (/help)` };
63
130
  }
package/dist/ui/App.js CHANGED
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
3
  import { Box, Static, Text, useApp, useInput } from "ink";
4
4
  import { buildLocalContextQuery, openBrowser, streamTurn, webBase } from "../runner.js";
5
- import { handleSlashCommand, parseMentions, SLASH_COMMANDS } from "../session.js";
5
+ import { handleSlashCommand, parseMentions, renameProject, SLASH_COMMANDS, titleFromPrompt } from "../session.js";
6
6
  import { markdownToAnsi } from "./markdown.js";
7
7
  import { Header } from "./Header.js";
8
8
  import { Logo } from "./logo.js";
@@ -110,6 +110,9 @@ export function App({ project, cwd, created }) {
110
110
  }
111
111
  else {
112
112
  pushItem({ user: raw, answer: result.answer ?? "(no answer)", sawVisual: result.sawVisual });
113
+ // First prompt in a freshly-created project becomes its title (self-describing in the web app).
114
+ if (created && turns === 0)
115
+ void renameProject(project, titleFromPrompt(raw));
113
116
  setLastTaskId(result.taskId);
114
117
  setTurns((prev) => prev + 1);
115
118
  setTokenTotal((prev) => prev + (result.tokens?.total ?? 0));
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * `version.test.ts` (the build/test fails if they drift). Used for `--version`, the
4
4
  * `User-Agent` header (lets the server gate old clients with 426), and the update check.
5
5
  */
6
- export const VERSION = "0.2.1";
6
+ export const VERSION = "0.2.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vecteur/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Vecteur CLI — a thin client for the Vecteur space-engineering platform (login, ask, projects, files). Hosted brain; no IP ships.",
5
5
  "type": "module",
6
6
  "license": "MIT",