@chances-ai/cli 17.0.0 → 18.0.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.
Files changed (73) hide show
  1. package/dist/boot/dispose.d.ts.map +1 -1
  2. package/dist/boot/dispose.js +11 -0
  3. package/dist/boot/dispose.js.map +1 -1
  4. package/dist/boot/load-runtime.d.ts +8 -0
  5. package/dist/boot/load-runtime.d.ts.map +1 -1
  6. package/dist/boot/load-runtime.js +2 -37
  7. package/dist/boot/load-runtime.js.map +1 -1
  8. package/dist/boot/open-browser.d.ts +10 -0
  9. package/dist/boot/open-browser.d.ts.map +1 -0
  10. package/dist/boot/open-browser.js +39 -0
  11. package/dist/boot/open-browser.js.map +1 -0
  12. package/dist/boot/web-assets.d.ts +11 -0
  13. package/dist/boot/web-assets.d.ts.map +1 -0
  14. package/dist/boot/web-assets.js +23 -0
  15. package/dist/boot/web-assets.js.map +1 -0
  16. package/dist/commands/chat.d.ts +2 -2
  17. package/dist/commands/chat.d.ts.map +1 -1
  18. package/dist/commands/chat.js +10 -4
  19. package/dist/commands/chat.js.map +1 -1
  20. package/dist/commands/config.d.ts +4 -1
  21. package/dist/commands/config.d.ts.map +1 -1
  22. package/dist/commands/config.js +8 -3
  23. package/dist/commands/config.js.map +1 -1
  24. package/dist/commands/doctor.d.ts +4 -1
  25. package/dist/commands/doctor.d.ts.map +1 -1
  26. package/dist/commands/doctor.js +8 -3
  27. package/dist/commands/doctor.js.map +1 -1
  28. package/dist/commands/help-text.d.ts +43 -0
  29. package/dist/commands/help-text.d.ts.map +1 -0
  30. package/dist/commands/help-text.js +87 -0
  31. package/dist/commands/help-text.js.map +1 -0
  32. package/dist/commands/prompt.d.ts +4 -1
  33. package/dist/commands/prompt.d.ts.map +1 -1
  34. package/dist/commands/prompt.js +6 -3
  35. package/dist/commands/prompt.js.map +1 -1
  36. package/dist/commands/serve.js +1 -1
  37. package/dist/commands/serve.js.map +1 -1
  38. package/dist/commands/stats.d.ts +4 -0
  39. package/dist/commands/stats.d.ts.map +1 -1
  40. package/dist/commands/stats.js +18 -0
  41. package/dist/commands/stats.js.map +1 -1
  42. package/dist/commands/version.d.ts.map +1 -1
  43. package/dist/commands/version.js +7 -17
  44. package/dist/commands/version.js.map +1 -1
  45. package/dist/slash/config.d.ts +10 -0
  46. package/dist/slash/config.d.ts.map +1 -0
  47. package/dist/slash/config.js +22 -0
  48. package/dist/slash/config.js.map +1 -0
  49. package/dist/slash/doctor.d.ts +9 -0
  50. package/dist/slash/doctor.d.ts.map +1 -0
  51. package/dist/slash/doctor.js +21 -0
  52. package/dist/slash/doctor.js.map +1 -0
  53. package/dist/slash/help.d.ts +9 -8
  54. package/dist/slash/help.d.ts.map +1 -1
  55. package/dist/slash/help.js +36 -18
  56. package/dist/slash/help.js.map +1 -1
  57. package/dist/slash/index.d.ts +6 -0
  58. package/dist/slash/index.d.ts.map +1 -1
  59. package/dist/slash/index.js +11 -1
  60. package/dist/slash/index.js.map +1 -1
  61. package/dist/slash/stats.d.ts +10 -0
  62. package/dist/slash/stats.d.ts.map +1 -0
  63. package/dist/slash/stats.js +23 -0
  64. package/dist/slash/stats.js.map +1 -0
  65. package/dist/slash/web.d.ts +25 -0
  66. package/dist/slash/web.d.ts.map +1 -0
  67. package/dist/slash/web.js +79 -0
  68. package/dist/slash/web.js.map +1 -0
  69. package/dist/web/assets/index-C060taGU.css +1 -0
  70. package/dist/web/assets/index-DGs1rWta.js +110 -0
  71. package/dist/web/assets/index-DGs1rWta.js.map +1 -0
  72. package/dist/web/index.html +13 -0
  73. package/package.json +21 -21
@@ -0,0 +1,23 @@
1
+ import { definePlugin } from "@chances-ai/plugin-api";
2
+ import { statsReport } from "../commands/stats.js";
3
+ /**
4
+ * (v19) `/stats [--since <date>] [--by-model]` — the in-chat form of
5
+ * `chances stats`: token usage + estimated cost from this workspace's
6
+ * `.chances/usage.jsonl`. Read-only; shares {@link statsReport} with the CLI
7
+ * command (bad flags come back as an inline usage message, never a throw).
8
+ */
9
+ export function makeStatsPlugin(deps) {
10
+ const command = {
11
+ name: "stats",
12
+ description: "Show token usage and estimated cost.",
13
+ argumentHint: "[--since <date>] [--by-model]",
14
+ run: (args) => statsReport(deps.ctx.workspaceRoot, args),
15
+ };
16
+ return definePlugin({
17
+ name: "builtin/stats",
18
+ onLoad(ctx) {
19
+ ctx.registerSlashCommand(command);
20
+ },
21
+ });
22
+ }
23
+ //# sourceMappingURL=stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/slash/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkC,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAsB;IACpD,MAAM,OAAO,GAAiB;QAC5B,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,sCAAsC;QACnD,YAAY,EAAE,+BAA+B;QAC7C,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC;KACzD,CAAC;IACF,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,eAAe;QACrB,MAAM,CAAC,GAAG;YACR,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { startRelay } from "@chances-ai/serve";
2
+ import { type Plugin } from "@chances-ai/plugin-api";
3
+ import type { BuiltinSlashDeps } from "./index.js";
4
+ /**
5
+ * The external effects `/web` performs — injectable so the command is unit-
6
+ * testable without starting a real socket or spawning a real browser. Defaults
7
+ * to the production implementations.
8
+ */
9
+ export interface WebIo {
10
+ startRelay: typeof startRelay;
11
+ openBrowser: (url: URL) => Promise<void>;
12
+ resolveWebAssetsDir: () => string | undefined;
13
+ }
14
+ /**
15
+ * (v20) `/web [stop]` — one-click web UI. Starts an in-process loopback relay
16
+ * serving the embedded SPA + the engine control channel (the SAME
17
+ * `EngineHost`/`RpcServer` seam `chances serve` uses, so each browser connection
18
+ * gets its own session over the shared runtime), then opens the browser.
19
+ *
20
+ * The relay outlives the command (stored on `ctx.relay`, stopped by
21
+ * `disposeRuntime` on exit or by `/web stop`); a second `/web` is idempotent —
22
+ * it re-opens the running URL. Loopback-only; LAN/auth is a later milestone.
23
+ */
24
+ export declare function makeWebPlugin(deps: BuiltinSlashDeps, io?: WebIo): Plugin;
25
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/slash/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAgB,KAAK,MAAM,EAAqB,MAAM,wBAAwB,CAAC;AAKtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,mBAAmB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CAC/C;AAID;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,GAAE,KAAc,GAAG,MAAM,CAoEhF"}
@@ -0,0 +1,79 @@
1
+ import { startRelay } from "@chances-ai/serve";
2
+ import { definePlugin } from "@chances-ai/plugin-api";
3
+ import { makeEngineHost } from "../commands/rpc.js";
4
+ import { openBrowser } from "../boot/open-browser.js";
5
+ import { resolveWebAssetsDir } from "../boot/web-assets.js";
6
+ import cliPkg from "../../package.json" with { type: "json" };
7
+ const realIo = { startRelay, openBrowser, resolveWebAssetsDir };
8
+ /**
9
+ * (v20) `/web [stop]` — one-click web UI. Starts an in-process loopback relay
10
+ * serving the embedded SPA + the engine control channel (the SAME
11
+ * `EngineHost`/`RpcServer` seam `chances serve` uses, so each browser connection
12
+ * gets its own session over the shared runtime), then opens the browser.
13
+ *
14
+ * The relay outlives the command (stored on `ctx.relay`, stopped by
15
+ * `disposeRuntime` on exit or by `/web stop`); a second `/web` is idempotent —
16
+ * it re-opens the running URL. Loopback-only; LAN/auth is a later milestone.
17
+ */
18
+ export function makeWebPlugin(deps, io = realIo) {
19
+ const command = {
20
+ name: "web",
21
+ description: "Open the web UI in your browser.",
22
+ argumentHint: "[stop]",
23
+ run: async (args, slashCtx) => {
24
+ const { ctx } = deps;
25
+ if (args[0] === "stop") {
26
+ if (!ctx.relay)
27
+ return "web UI is not running";
28
+ ctx.relay.stop();
29
+ ctx.relay = undefined;
30
+ return "web UI stopped";
31
+ }
32
+ // (codex v20 SHOULD-FIX) `/web` needs the interactive chat loop to stay
33
+ // alive — a one-shot `chances -p "/web"` (or an rpc dispatch) returns
34
+ // immediately, and `disposeRuntime` would stop the relay before the
35
+ // browser even connects. `openModal` is only wired in the TUI, so its
36
+ // absence means a non-interactive dispatch.
37
+ if (!slashCtx.openModal) {
38
+ return ("/web needs interactive chat — run `chances`, then type /web (a one-shot `-p` exits " +
39
+ "immediately and would kill the server). For headless serving use `chances serve --web <dir>`.");
40
+ }
41
+ // Already running → just re-open the browser at the live URL.
42
+ if (ctx.relay) {
43
+ const url = ctx.relay.url;
44
+ await io.openBrowser(new URL(url)).catch(() => { });
45
+ return `web UI already running on ${url} — reopened in your browser. /web stop to stop.`;
46
+ }
47
+ const staticDir = io.resolveWebAssetsDir();
48
+ if (!staticDir) {
49
+ return ("web UI assets aren't bundled in this build. In the repo, build them with " +
50
+ "`bun --filter @chances-ai/web build`, then run /web again — or use `chances serve --web <dir>`.");
51
+ }
52
+ const relay = await io.startRelay({
53
+ version: cliPkg.version,
54
+ staticDir,
55
+ control: {
56
+ host: makeEngineHost(ctx),
57
+ agent: { name: cliPkg.name, version: cliPkg.version },
58
+ // The browser closes the permission round-trip itself; don't auto-approve.
59
+ autoApprove: false,
60
+ },
61
+ });
62
+ ctx.relay = relay;
63
+ try {
64
+ await io.openBrowser(new URL(relay.url));
65
+ }
66
+ catch (e) {
67
+ return `web UI on ${relay.url} — open it in your browser (auto-open failed: ${e.message}). /web stop to stop.`;
68
+ }
69
+ return `web UI on ${relay.url} — opened in your browser. /web stop to stop.`;
70
+ },
71
+ };
72
+ return definePlugin({
73
+ name: "builtin/web",
74
+ onLoad(ctx) {
75
+ ctx.registerSlashCommand(command);
76
+ },
77
+ });
78
+ }
79
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/slash/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAkC,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,MAAM,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAc9D,MAAM,MAAM,GAAU,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AAEvE;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,IAAsB,EAAE,KAAY,MAAM;IACtE,MAAM,OAAO,GAAiB;QAC5B,IAAI,EAAE,KAAK;QACX,WAAW,EAAE,kCAAkC;QAC/C,YAAY,EAAE,QAAQ;QACtB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC5B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;YAErB,IAAI,IAAI,C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KAAK,GAAG,KAAK,CAAC;YAElB,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,aAAa,KAAK,CAAC,GAAG,iDAAkD,CAAW,CAAC,OAAO,uBAAuB,CAAC;YAC5H,CAAC;YACD,OAAO,aAAa,KAAK,CAAC,GAAG,+CAA+C,CAAC;QAC/E,CAAC;KACF,CAAC;IACF,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,aAAa;QACnB,MAAM,CAAC,GAAG;YACR,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ :root{color-scheme:dark light}*{box-sizing:border-box}html,body,#root{margin:0;padding:0;height:100%}body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif}