@chances-ai/cli 1.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.
- package/dist/boot/create-app.d.ts +9 -0
- package/dist/boot/create-app.d.ts.map +1 -0
- package/dist/boot/create-app.js +25 -0
- package/dist/boot/create-app.js.map +1 -0
- package/dist/boot/load-runtime.d.ts +32 -0
- package/dist/boot/load-runtime.d.ts.map +1 -0
- package/dist/boot/load-runtime.js +109 -0
- package/dist/boot/load-runtime.js.map +1 -0
- package/dist/commands/chat.d.ts +6 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +63 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config.d.ts +6 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +23 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/doctor.d.ts +6 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +30 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/prompt.d.ts +5 -0
- package/dist/commands/prompt.d.ts.map +1 -0
- package/dist/commands/prompt.js +66 -0
- package/dist/commands/prompt.js.map +1 -0
- package/dist/commands/registry.d.ts +37 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +18 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/session.d.ts +6 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +24 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/version.d.ts +7 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +47 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/entrypoints/cli-bun.d.ts +3 -0
- package/dist/entrypoints/cli-bun.d.ts.map +1 -0
- package/dist/entrypoints/cli-bun.js +9 -0
- package/dist/entrypoints/cli-bun.js.map +1 -0
- package/dist/entrypoints/cli-node.d.ts +3 -0
- package/dist/entrypoints/cli-node.d.ts.map +1 -0
- package/dist/entrypoints/cli-node.js +9 -0
- package/dist/entrypoints/cli-node.js.map +1 -0
- package/dist/entrypoints/cli.d.ts +14 -0
- package/dist/entrypoints/cli.d.ts.map +1 -0
- package/dist/entrypoints/cli.js +98 -0
- package/dist/entrypoints/cli.js.map +1 -0
- package/dist/modes/json.d.ts +6 -0
- package/dist/modes/json.d.ts.map +1 -0
- package/dist/modes/json.js +19 -0
- package/dist/modes/json.js.map +1 -0
- package/dist/modes/ndjson.d.ts +6 -0
- package/dist/modes/ndjson.d.ts.map +1 -0
- package/dist/modes/ndjson.js +14 -0
- package/dist/modes/ndjson.js.map +1 -0
- package/dist/modes/text.d.ts +6 -0
- package/dist/modes/text.d.ts.map +1 -0
- package/dist/modes/text.js +9 -0
- package/dist/modes/text.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AgentEngine } from "@chances-ai/core";
|
|
2
|
+
import { type PermissionResolver } from "@chances-ai/tools";
|
|
3
|
+
import type { SessionManager } from "@chances-ai/session";
|
|
4
|
+
import type { AppContext } from "./load-runtime.js";
|
|
5
|
+
/** Wires an AgentEngine for a given session and permission resolver. */
|
|
6
|
+
export declare function buildEngine(ctx: AppContext, session: SessionManager, resolver: PermissionResolver): AgentEngine;
|
|
7
|
+
/** Auto-resolver for non-interactive modes: approve only when --yes was passed. */
|
|
8
|
+
export declare function autoResolver(approve: boolean): PermissionResolver;
|
|
9
|
+
//# sourceMappingURL=create-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/boot/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,GAAG,WAAW,CAe/G;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,kBAAkB,CAEjE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AgentEngine } from "@chances-ai/core";
|
|
2
|
+
import { MemoryStore } from "@chances-ai/memory";
|
|
3
|
+
import { PermissionGate } from "@chances-ai/tools";
|
|
4
|
+
/** Wires an AgentEngine for a given session and permission resolver. */
|
|
5
|
+
export function buildEngine(ctx, session, resolver) {
|
|
6
|
+
const gate = new PermissionGate(ctx.config.permissions, resolver);
|
|
7
|
+
const memory = new MemoryStore(ctx.workspaceRoot);
|
|
8
|
+
return new AgentEngine({
|
|
9
|
+
bus: ctx.bus,
|
|
10
|
+
router: ctx.router,
|
|
11
|
+
tools: ctx.tools,
|
|
12
|
+
gate,
|
|
13
|
+
session,
|
|
14
|
+
memory,
|
|
15
|
+
plugins: ctx.plugins,
|
|
16
|
+
workspaceRoot: ctx.workspaceRoot,
|
|
17
|
+
preferredModel: ctx.config.model,
|
|
18
|
+
preferredProvider: ctx.config.provider,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Auto-resolver for non-interactive modes: approve only when --yes was passed. */
|
|
22
|
+
export function autoResolver(approve) {
|
|
23
|
+
return async () => approve;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=create-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../../src/boot/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAA2B,MAAM,mBAAmB,CAAC;AAI5E,wEAAwE;AACxE,MAAM,UAAU,WAAW,CAAC,GAAe,EAAE,OAAuB,EAAE,QAA4B;IAChG,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAClD,OAAO,IAAI,WAAW,CAAC;QACrB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,IAAI;QACJ,OAAO;QACP,MAAM;QACN,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK;QAChC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ;KACvC,CAAC,CAAC;AACL,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EventBus, FeatureFlags, Logger, type LogLevel } from "@chances-ai/runtime";
|
|
2
|
+
import { AuthStore, type ChancesConfig, type ExternalPluginEntry } from "@chances-ai/config";
|
|
3
|
+
import { ModelRegistry, ModelRouter } from "@chances-ai/ai";
|
|
4
|
+
import { ToolRegistry } from "@chances-ai/tools";
|
|
5
|
+
import { TelemetrySink } from "@chances-ai/telemetry";
|
|
6
|
+
import { PluginHost, type Plugin } from "@chances-ai/plugin-api";
|
|
7
|
+
export interface AppContext {
|
|
8
|
+
bus: EventBus;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
flags: FeatureFlags;
|
|
11
|
+
config: ChancesConfig;
|
|
12
|
+
auth: AuthStore;
|
|
13
|
+
registry: ModelRegistry;
|
|
14
|
+
router: ModelRouter;
|
|
15
|
+
tools: ToolRegistry;
|
|
16
|
+
telemetry: TelemetrySink;
|
|
17
|
+
plugins: PluginHost | undefined;
|
|
18
|
+
workspaceRoot: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RuntimeOverrides {
|
|
21
|
+
provider?: string;
|
|
22
|
+
model?: string;
|
|
23
|
+
logLevel?: LogLevel;
|
|
24
|
+
}
|
|
25
|
+
/** Builds the shared application context (the wiring all commands depend on). */
|
|
26
|
+
export declare function loadRuntime(overrides?: RuntimeOverrides): Promise<AppContext>;
|
|
27
|
+
/** Resolves the user's `path` to something dynamic `import()` accepts, then
|
|
28
|
+
* invokes the module's default-exported factory with the entry's `options`.
|
|
29
|
+
* Throws include the resolved specifier so misconfigured paths are easy to
|
|
30
|
+
* diagnose from logs. */
|
|
31
|
+
export declare function importExternalPlugin(entry: ExternalPluginEntry, workspaceRoot: string): Promise<Plugin>;
|
|
32
|
+
//# sourceMappingURL=load-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-runtime.d.ts","sourceRoot":"","sources":["../../src/boot/load-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EAET,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAiB,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGjE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,QAAQ,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,iFAAiF;AACjF,wBAAsB,WAAW,CAAC,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAsBvF;AA2CD;;;yBAGyB;AACzB,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAsBjB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { EventBus, FeatureFlags, Logger, } from "@chances-ai/runtime";
|
|
4
|
+
import { AuthStore, loadConfig, } from "@chances-ai/config";
|
|
5
|
+
import { ModelRegistry, ModelRouter, buildRegistry } from "@chances-ai/ai";
|
|
6
|
+
import { ToolRegistry, builtinTools } from "@chances-ai/tools";
|
|
7
|
+
import { TelemetrySink } from "@chances-ai/telemetry";
|
|
8
|
+
import { PluginHost } from "@chances-ai/plugin-api";
|
|
9
|
+
import { loggerPlugin } from "@chances-ai/plugin-logger";
|
|
10
|
+
/** Builds the shared application context (the wiring all commands depend on). */
|
|
11
|
+
export async function loadRuntime(overrides = {}) {
|
|
12
|
+
const config = loadConfig();
|
|
13
|
+
if (overrides.provider)
|
|
14
|
+
config.provider = overrides.provider;
|
|
15
|
+
if (overrides.model)
|
|
16
|
+
config.model = overrides.model;
|
|
17
|
+
const bus = new EventBus();
|
|
18
|
+
const flags = new FeatureFlags();
|
|
19
|
+
const logger = new Logger(bus, overrides.logLevel ?? "warn");
|
|
20
|
+
const auth = new AuthStore();
|
|
21
|
+
const registry = buildRegistry({ apiKeyFor: (p) => auth.apiKey(p) });
|
|
22
|
+
const router = new ModelRouter(registry);
|
|
23
|
+
const tools = new ToolRegistry();
|
|
24
|
+
for (const tool of builtinTools)
|
|
25
|
+
tools.register(tool);
|
|
26
|
+
const telemetry = new TelemetrySink(config.workspaceRoot);
|
|
27
|
+
telemetry.attach(bus);
|
|
28
|
+
const plugins = await loadPlugins(config, bus, logger, tools);
|
|
29
|
+
return { bus, logger, flags, config, auth, registry, router, tools, telemetry, plugins, workspaceRoot: config.workspaceRoot };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Builds and loads the plugin host. Returns `undefined` when no plugin is
|
|
33
|
+
* configured — that keeps the engine wiring free of a useless empty host and
|
|
34
|
+
* the cold path identical to "no plugin-api in scope".
|
|
35
|
+
*/
|
|
36
|
+
async function loadPlugins(config, bus, logger, tools) {
|
|
37
|
+
const enabled = await collectPlugins(config, logger);
|
|
38
|
+
if (enabled.length === 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
const host = new PluginHost(bus, logger, tools);
|
|
41
|
+
for (const plugin of enabled) {
|
|
42
|
+
try {
|
|
43
|
+
await host.load(plugin);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
logger.warn(`failed to load plugin ${plugin.name}: ${e.message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return host;
|
|
50
|
+
}
|
|
51
|
+
async function collectPlugins(config, logger) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const loggerCfg = config.plugins?.logger;
|
|
54
|
+
if (loggerCfg?.enabled) {
|
|
55
|
+
const path = loggerCfg.path ?? join(config.workspaceRoot, ".chances", "transcript.log");
|
|
56
|
+
out.push(loggerPlugin({ path }));
|
|
57
|
+
}
|
|
58
|
+
for (const entry of config.plugins?.external ?? []) {
|
|
59
|
+
try {
|
|
60
|
+
out.push(await importExternalPlugin(entry, config.workspaceRoot));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
logger.warn(`failed to import plugin '${entry.path}': ${e.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/** Resolves the user's `path` to something dynamic `import()` accepts, then
|
|
69
|
+
* invokes the module's default-exported factory with the entry's `options`.
|
|
70
|
+
* Throws include the resolved specifier so misconfigured paths are easy to
|
|
71
|
+
* diagnose from logs. */
|
|
72
|
+
export async function importExternalPlugin(entry, workspaceRoot) {
|
|
73
|
+
const specifier = resolveSpecifier(entry.path, workspaceRoot);
|
|
74
|
+
let mod;
|
|
75
|
+
try {
|
|
76
|
+
mod = (await import(specifier));
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error(`failed to import '${entry.path}' (resolved to ${specifier}): ${e.message}`);
|
|
80
|
+
}
|
|
81
|
+
if (typeof mod.default !== "function") {
|
|
82
|
+
throw new Error(`module '${entry.path}' (${specifier}) does not default-export a factory`);
|
|
83
|
+
}
|
|
84
|
+
const result = mod.default(entry.options);
|
|
85
|
+
if (!result ||
|
|
86
|
+
typeof result.name !== "string" ||
|
|
87
|
+
typeof result.onLoad !== "function") {
|
|
88
|
+
throw new Error(`module '${entry.path}' (${specifier}) factory did not return a Plugin (need {name, onLoad})`);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/** Resolves a config-supplied plugin path. Workspace-relative paths are
|
|
93
|
+
* resolved against `workspaceRoot` and forbidden from escaping it; absolute
|
|
94
|
+
* paths and bare specifiers are returned as the user wrote them (the user is
|
|
95
|
+
* opting in by typing them in config). */
|
|
96
|
+
function resolveSpecifier(path, workspaceRoot) {
|
|
97
|
+
if (path.startsWith("./") || path.startsWith("../")) {
|
|
98
|
+
const abs = resolve(workspaceRoot, path);
|
|
99
|
+
const rel = relative(workspaceRoot, abs);
|
|
100
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) {
|
|
101
|
+
throw new Error(`relative plugin path escapes workspace: ${path}`);
|
|
102
|
+
}
|
|
103
|
+
return pathToFileURL(abs).href;
|
|
104
|
+
}
|
|
105
|
+
if (isAbsolute(path))
|
|
106
|
+
return pathToFileURL(path).href;
|
|
107
|
+
return path;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=load-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-runtime.js","sourceRoot":"","sources":["../../src/boot/load-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,GAEP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,UAAU,GAGX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAe,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAsBzD,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,YAA8B,EAAE;IAChE,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,IAAI,SAAS,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G,GAAG,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QACzC,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IACD,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IACtD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AppContext } from "../boot/load-runtime.js";
|
|
2
|
+
import type { CliCommand } from "./registry.js";
|
|
3
|
+
/** Interactive Ink chat. The view-model is the permission resolver. */
|
|
4
|
+
export declare function runInteractive(ctx: AppContext): Promise<number>;
|
|
5
|
+
export declare const chatCommand: CliCommand;
|
|
6
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,uEAAuE;AACvE,wBAAsB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAwCrE;AAED,eAAO,MAAM,WAAW,EAAE,UAczB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CancellationTokenSource } from "@chances-ai/runtime";
|
|
2
|
+
import { SessionManager, SessionStore } from "@chances-ai/session";
|
|
3
|
+
import { parseSlashInput } from "@chances-ai/plugin-api";
|
|
4
|
+
import { ChatViewModel, renderChat } from "@chances-ai/tui";
|
|
5
|
+
import { buildEngine } from "../boot/create-app.js";
|
|
6
|
+
import { runPrompt } from "./prompt.js";
|
|
7
|
+
/** Interactive Ink chat. The view-model is the permission resolver. */
|
|
8
|
+
export async function runInteractive(ctx) {
|
|
9
|
+
const store = new SessionStore(ctx.workspaceRoot);
|
|
10
|
+
const session = SessionManager.create("interactive", store);
|
|
11
|
+
const vm = new ChatViewModel();
|
|
12
|
+
vm.attach(ctx.bus);
|
|
13
|
+
const engine = buildEngine(ctx, session, vm.requestPermission);
|
|
14
|
+
const handle = renderChat(vm, async (prompt) => {
|
|
15
|
+
const cts = new CancellationTokenSource();
|
|
16
|
+
try {
|
|
17
|
+
await engine.runTurn(prompt, cts.token);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
ctx.bus.emit({ type: "error", code: "UNKNOWN", message: err instanceof Error ? err.message : String(err) });
|
|
21
|
+
}
|
|
22
|
+
}, async (line) => {
|
|
23
|
+
const { name, args } = parseSlashInput(line);
|
|
24
|
+
if (!name) {
|
|
25
|
+
vm.pushError(`Unknown command: /`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!ctx.plugins) {
|
|
29
|
+
vm.pushError(`Unknown command: /${name}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const result = await ctx.plugins.dispatchSlash(name, args);
|
|
33
|
+
if (!result.ok) {
|
|
34
|
+
vm.pushError(`Unknown command: /${name}`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (result.output) {
|
|
38
|
+
if (result.isError)
|
|
39
|
+
vm.pushError(result.output);
|
|
40
|
+
else
|
|
41
|
+
vm.pushInfo(result.output);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
await handle.waitUntilExit();
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
export const chatCommand = {
|
|
48
|
+
name: "chat",
|
|
49
|
+
description: "Start an interactive chat, or with -p run a one-shot prompt.",
|
|
50
|
+
async run(ctx, args) {
|
|
51
|
+
if (!ctx)
|
|
52
|
+
throw new Error("chat requires a runtime context");
|
|
53
|
+
if (args.prompt !== undefined) {
|
|
54
|
+
return runPrompt(ctx, args.prompt, args.format, args.yes);
|
|
55
|
+
}
|
|
56
|
+
if (!process.stdout.isTTY) {
|
|
57
|
+
process.stderr.write("Interactive mode requires a TTY. Use -p \"<prompt>\" for non-interactive runs.\n");
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
return runInteractive(ctx);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAe;IAClD,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,IAAI,aAAa,EAAE,CAAC;IAC/B,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEnB,MAAM,MAA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,CAAC,OAAO;gBAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;gBAC3C,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,CACF,CAAC;IACF,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;IAC7B,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAe;IACrC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,8DAA8D;IAC3E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI;QACjB,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC7D,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAC;YACzG,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AppContext } from "../boot/load-runtime.js";
|
|
2
|
+
import type { CliCommand } from "./registry.js";
|
|
3
|
+
/** Prints the resolved configuration (no secrets are stored in config). */
|
|
4
|
+
export declare function showConfig(ctx: AppContext): number;
|
|
5
|
+
export declare const configCommand: CliCommand;
|
|
6
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAWlD;AAED,eAAO,MAAM,aAAa,EAAE,UAO3B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Prints the resolved configuration (no secrets are stored in config). */
|
|
2
|
+
export function showConfig(ctx) {
|
|
3
|
+
const view = {
|
|
4
|
+
provider: ctx.config.provider,
|
|
5
|
+
model: ctx.config.model ?? null,
|
|
6
|
+
workspaceRoot: ctx.config.workspaceRoot,
|
|
7
|
+
permissions: ctx.config.permissions,
|
|
8
|
+
providersReady: ctx.registry.providers(),
|
|
9
|
+
featureFlags: ctx.flags.all(),
|
|
10
|
+
};
|
|
11
|
+
process.stdout.write(JSON.stringify(view, null, 2) + "\n");
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
export const configCommand = {
|
|
15
|
+
name: "config",
|
|
16
|
+
description: "Print the resolved configuration as JSON.",
|
|
17
|
+
run(ctx) {
|
|
18
|
+
if (!ctx)
|
|
19
|
+
throw new Error("config requires a runtime context");
|
|
20
|
+
return showConfig(ctx);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAGA,2EAA2E;AAC3E,MAAM,UAAU,UAAU,CAAC,GAAe;IACxC,MAAM,IAAI,GAAG;QACX,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ;QAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,IAAI;QAC/B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,aAAa;QACvC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW;QACnC,cAAc,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE;QACxC,YAAY,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE;KAC9B,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3D,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAe;IACvC,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,2CAA2C;IACxD,GAAG,CAAC,GAAG;QACL,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC/D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AppContext } from "../boot/load-runtime.js";
|
|
2
|
+
import type { CliCommand } from "./registry.js";
|
|
3
|
+
/** Environment self-check: runtime, native load status, providers, workspace. */
|
|
4
|
+
export declare function runDoctor(ctx: AppContext): number;
|
|
5
|
+
export declare const doctorCommand: CliCommand;
|
|
6
|
+
//# sourceMappingURL=doctor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAiBjD;AAED,eAAO,MAAM,aAAa,EAAE,UAO3B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { native } from "@chances-ai/native";
|
|
2
|
+
/** Environment self-check: runtime, native load status, providers, workspace. */
|
|
3
|
+
export function runDoctor(ctx) {
|
|
4
|
+
const lines = [
|
|
5
|
+
"chances doctor",
|
|
6
|
+
"──────────────",
|
|
7
|
+
`bun runtime : ${process.versions.bun ?? "not running under bun"}`,
|
|
8
|
+
`node runtime : ${process.versions.node}`,
|
|
9
|
+
`native addon : ${native.isNativeLoaded() ? "loaded" : "JS fallback (expected in 1.x)"}`,
|
|
10
|
+
`workspace root : ${ctx.workspaceRoot}`,
|
|
11
|
+
`active provider : ${ctx.config.provider}`,
|
|
12
|
+
`active model : ${ctx.config.model ?? "(router default)"}`,
|
|
13
|
+
`providers ready : ${ctx.registry.providers().join(", ") || "none"}`,
|
|
14
|
+
`models available : ${ctx.registry.all().length}`,
|
|
15
|
+
`anthropic key : ${ctx.auth.hasCredentials("anthropic") ? "yes" : "no"}`,
|
|
16
|
+
`openai key : ${ctx.auth.hasCredentials("openai") ? "yes" : "no"}`,
|
|
17
|
+
];
|
|
18
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
export const doctorCommand = {
|
|
22
|
+
name: "doctor",
|
|
23
|
+
description: "Print runtime, provider, and workspace diagnostics.",
|
|
24
|
+
run(ctx) {
|
|
25
|
+
if (!ctx)
|
|
26
|
+
throw new Error("doctor requires a runtime context");
|
|
27
|
+
return runDoctor(ctx);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,GAAe;IACvC,MAAM,KAAK,GAAG;QACZ,gBAAgB;QAChB,gBAAgB;QAChB,sBAAuB,OAAO,CAAC,QAA+C,CAAC,GAAG,IAAI,uBAAuB,E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3
|
+
/** Single-shot, non-interactive execution for scripts/CI. */
|
|
4
|
+
export declare function runPrompt(ctx: AppContext, prompt: string, format: OutputFormat, autoApprove: boolean): Promise<number>;
|
|
5
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEtD,6DAA6D;AAC7D,wBAAsB,SAAS,CAC7B,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CancellationTokenSource, ErrorCode, exitCodeFor } from "@chances-ai/runtime";
|
|
2
|
+
import { SessionManager } from "@chances-ai/session";
|
|
3
|
+
import { parseSlashInput } from "@chances-ai/plugin-api";
|
|
4
|
+
import { autoResolver, buildEngine } from "../boot/create-app.js";
|
|
5
|
+
import { attachJson } from "../modes/json.js";
|
|
6
|
+
import { attachNdjson } from "../modes/ndjson.js";
|
|
7
|
+
import { attachText } from "../modes/text.js";
|
|
8
|
+
/** Single-shot, non-interactive execution for scripts/CI. */
|
|
9
|
+
export async function runPrompt(ctx, prompt, format, autoApprove) {
|
|
10
|
+
if (prompt.startsWith("/")) {
|
|
11
|
+
return runSlashPrompt(ctx, prompt, format);
|
|
12
|
+
}
|
|
13
|
+
let lastError = null;
|
|
14
|
+
ctx.bus.on("error", (e) => (lastError = e.code));
|
|
15
|
+
const renderer = format === "json" ? attachJson(ctx.bus) : format === "ndjson" ? attachNdjson(ctx.bus) : attachText(ctx.bus);
|
|
16
|
+
const session = SessionManager.create("prompt");
|
|
17
|
+
const engine = buildEngine(ctx, session, autoResolver(autoApprove));
|
|
18
|
+
const cts = new CancellationTokenSource();
|
|
19
|
+
try {
|
|
20
|
+
await engine.runTurn(prompt, cts.token);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
ctx.bus.emit({ type: "error", code: "UNKNOWN", message: err instanceof Error ? err.message : String(err) });
|
|
24
|
+
}
|
|
25
|
+
renderer.finalize();
|
|
26
|
+
return lastError ? exitCodeFor(lastError) : 0;
|
|
27
|
+
}
|
|
28
|
+
async function runSlashPrompt(ctx, line, format) {
|
|
29
|
+
const { name, args } = parseSlashInput(line);
|
|
30
|
+
if (!name) {
|
|
31
|
+
return emitSlashError(`Unknown command: /`, format);
|
|
32
|
+
}
|
|
33
|
+
if (!ctx.plugins) {
|
|
34
|
+
return emitSlashError(`Unknown command: /${name}`, format);
|
|
35
|
+
}
|
|
36
|
+
const result = await ctx.plugins.dispatchSlash(name, args);
|
|
37
|
+
if (!result.ok) {
|
|
38
|
+
return emitSlashError(`Unknown command: /${name}`, format);
|
|
39
|
+
}
|
|
40
|
+
const output = result.output ?? "";
|
|
41
|
+
emitSlashOutput(output, result.isError ?? false, format);
|
|
42
|
+
return result.isError ? exitCodeFor(ErrorCode.Unknown) : 0;
|
|
43
|
+
}
|
|
44
|
+
function emitSlashOutput(text, isError, format) {
|
|
45
|
+
if (format === "json") {
|
|
46
|
+
process.stdout.write(JSON.stringify({
|
|
47
|
+
text,
|
|
48
|
+
toolCalls: [],
|
|
49
|
+
usage: { inputTokens: 0, outputTokens: 0, costUsd: 0 },
|
|
50
|
+
error: isError ? { code: ErrorCode.Unknown, message: text } : null,
|
|
51
|
+
}) + "\n");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (format === "ndjson") {
|
|
55
|
+
if (isError)
|
|
56
|
+
process.stdout.write(JSON.stringify({ type: "error", code: ErrorCode.Unknown, message: text }) + "\n");
|
|
57
|
+
process.stdout.write(JSON.stringify({ type: "result", text }) + "\n");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
process.stdout.write(text + "\n");
|
|
61
|
+
}
|
|
62
|
+
function emitSlashError(message, format) {
|
|
63
|
+
emitSlashOutput(message, true, format);
|
|
64
|
+
return exitCodeFor(ErrorCode.Usage);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAmC,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAe,EACf,MAAc,EACd,MAAoB,EACpB,WAAoB;IAEpB,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,SAAS,GAAyB,IAAI,CAAC;IAC3C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,MAAM,QAAQ,GACZ,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GA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,GAAG,IAAI,CAAC,CAAC;QACpH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACtE,OAAO;IACT,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,cAAc,CAAC,OAAe,EAAE,MAAoB;IAC3D,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AppContext } from "../boot/load-runtime.js";
|
|
2
|
+
import type { OutputFormat } from "./prompt.js";
|
|
3
|
+
/**
|
|
4
|
+
* Arguments common to every CLI sub-command. `positional` is the list of
|
|
5
|
+
* tokens after the command name; flags (`--json`, `-p`, etc.) are normalized
|
|
6
|
+
* onto the named fields by `parseArgs`.
|
|
7
|
+
*/
|
|
8
|
+
export interface CliArgs {
|
|
9
|
+
positional: string[];
|
|
10
|
+
prompt?: string;
|
|
11
|
+
format: OutputFormat;
|
|
12
|
+
yes: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface CliCommand {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
/** When true (default), the dispatcher loads the runtime context before
|
|
18
|
+
* calling `run`. Pre-runtime commands (`version`, `help`) opt out so they
|
|
19
|
+
* stay fast and never read config. */
|
|
20
|
+
needsRuntime?: boolean;
|
|
21
|
+
/** `ctx` is the loaded AppContext for runtime commands, or `null` when
|
|
22
|
+
* `needsRuntime: false`. `registry` is the same registry that dispatched
|
|
23
|
+
* the call — `help` uses it to enumerate commands. */
|
|
24
|
+
run(ctx: AppContext | null, args: CliArgs, registry: CommandRegistry): Promise<number> | number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Indexed lookup of available CLI sub-commands. 1.x exposes a small built-in
|
|
28
|
+
* set; later versions can hand a reference to this registry to plugins so they
|
|
29
|
+
* can `register()` their own commands without forking apps/cli.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CommandRegistry {
|
|
32
|
+
private readonly commands;
|
|
33
|
+
register(cmd: CliCommand): void;
|
|
34
|
+
get(name: string): CliCommand | undefined;
|
|
35
|
+
list(): CliCommand[];
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/commands/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,GAAG,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB;;0CAEsC;IACtC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;0DAEsD;IACtD,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACjG;AAED;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;IAE1D,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAI/B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIzC,IAAI,IAAI,UAAU,EAAE;CAGrB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indexed lookup of available CLI sub-commands. 1.x exposes a small built-in
|
|
3
|
+
* set; later versions can hand a reference to this registry to plugins so they
|
|
4
|
+
* can `register()` their own commands without forking apps/cli.
|
|
5
|
+
*/
|
|
6
|
+
export class CommandRegistry {
|
|
7
|
+
commands = new Map();
|
|
8
|
+
register(cmd) {
|
|
9
|
+
this.commands.set(cmd.name, cmd);
|
|
10
|
+
}
|
|
11
|
+
get(name) {
|
|
12
|
+
return this.commands.get(name);
|
|
13
|
+
}
|
|
14
|
+
list() {
|
|
15
|
+
return [...this.commands.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/commands/registry.ts"],"names":[],"mappings":"AA4BA;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACT,QAAQ,GAAG,IAAI,GAAG,EAAsB,CAAC;IAE1D,QAAQ,CAAC,GAAe;QACtB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AppContext } from "../boot/load-runtime.js";
|
|
2
|
+
import type { CliCommand } from "./registry.js";
|
|
3
|
+
/** Lists persisted sessions for the current workspace. */
|
|
4
|
+
export declare function listSessions(ctx: AppContext): number;
|
|
5
|
+
export declare const sessionCommand: CliCommand;
|
|
6
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/commands/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,0DAA0D;AAC1D,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAWpD;AAED,eAAO,MAAM,cAAc,EAAE,UAO5B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SessionStore } from "@chances-ai/session";
|
|
2
|
+
/** Lists persisted sessions for the current workspace. */
|
|
3
|
+
export function listSessions(ctx) {
|
|
4
|
+
const store = new SessionStore(ctx.workspaceRoot);
|
|
5
|
+
const sessions = store.list();
|
|
6
|
+
if (sessions.length === 0) {
|
|
7
|
+
process.stdout.write("No sessions yet.\n");
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
for (const s of sessions) {
|
|
11
|
+
process.stdout.write(`${s.id} ${s.updatedAt} ${s.turns.length} turns ${s.title}\n`);
|
|
12
|
+
}
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
export const sessionCommand = {
|
|
16
|
+
name: "session",
|
|
17
|
+
description: "List persisted sessions in the current workspace.",
|
|
18
|
+
run(ctx) {
|
|
19
|
+
if (!ctx)
|
|
20
|
+
throw new Error("session requires a runtime context");
|
|
21
|
+
return listSessions(ctx);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/commands/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,0DAA0D;AAC1D,MAAM,UAAU,YAAY,CAAC,GAAe;IAC1C,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC3C,OAAO,CAAC,CAAC;IACX,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,mDAAmD;IAChE,GAAG,CAAC,GAAG;QACL,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAChE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CliCommand, CommandRegistry } from "./registry.js";
|
|
2
|
+
export declare const VERSION: string;
|
|
3
|
+
export declare function printVersion(): number;
|
|
4
|
+
export declare function printHelp(registry?: CommandRegistry): number;
|
|
5
|
+
export declare const versionCommand: CliCommand;
|
|
6
|
+
export declare const helpCommand: CliCommand;
|
|
7
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/commands/version.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAMjE,eAAO,MAAM,OAAO,QAAc,CAAC;AAEnC,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED,wBAAgB,SAAS,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,MAAM,CA8B5D;AAED,eAAO,MAAM,cAAc,EAAE,UAO5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,UAOzB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
2
|
+
// Single source of truth: the version sits in apps/cli/package.json and
|
|
3
|
+
// `release.ts` bumps it there. Reading it here means `chances --version` can
|
|
4
|
+
// never drift behind the published version. `bun --compile` embeds the JSON
|
|
5
|
+
// into the binary, and tsc resolveJsonModule handles the dev path.
|
|
6
|
+
export const VERSION = pkg.version;
|
|
7
|
+
export function printVersion() {
|
|
8
|
+
process.stdout.write(`chances ${VERSION}\n`);
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
export function printHelp(registry) {
|
|
12
|
+
const lines = [
|
|
13
|
+
"chances — a Bun-first, multi-provider terminal coding agent",
|
|
14
|
+
"",
|
|
15
|
+
"Usage:",
|
|
16
|
+
" chances start interactive chat",
|
|
17
|
+
' chances -p "<prompt>" run a single prompt (non-interactive)',
|
|
18
|
+
];
|
|
19
|
+
if (registry) {
|
|
20
|
+
const padTo = Math.max(...registry.list().map((c) => c.name.length));
|
|
21
|
+
for (const cmd of registry.list()) {
|
|
22
|
+
if (cmd.name === "chat")
|
|
23
|
+
continue; // chat is the default; documented above
|
|
24
|
+
lines.push(` chances ${cmd.name.padEnd(padTo)} ${cmd.description}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
lines.push("", "Options:", " -p, --prompt <text> non-interactive prompt", " --json emit a single final JSON object", " --ndjson emit one event frame per line", " --yes auto-approve permission prompts", " --provider <id> override provider (mock|anthropic|openai)", " --model <id> override model", " -h, --help show this help", " --version print the CLI version", "");
|
|
28
|
+
process.stdout.write(lines.join("\n"));
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
export const versionCommand = {
|
|
32
|
+
name: "version",
|
|
33
|
+
description: "Print the CLI version.",
|
|
34
|
+
needsRuntime: false,
|
|
35
|
+
run() {
|
|
36
|
+
return printVersion();
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const helpCommand = {
|
|
40
|
+
name: "help",
|
|
41
|
+
description: "Show this help.",
|
|
42
|
+
needsRuntime: false,
|
|
43
|
+
run(_ctx, _args, registry) {
|
|
44
|
+
return printHelp(registry);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/commands/version.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAG3D,wEAAwE;AACxE,6EAA6E;AAC7E,4EAA4E;AAC5E,mEAAmE;AACnE,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;AAEnC,MAAM,UAAU,YAAY;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,OAAO,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,QAA0B;IAClD,MAAM,KAAK,GAAa;QACtB,6DAA6D;QAC7D,EAAE;QACF,QAAQ;QACR,wDAAwD;QACxD,wEAAwE;KACzE,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,EA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1,9 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { main } from "./cli.js";
|
|
3
|
+
main()
|
|
4
|
+
.then((code) => process.exit(code))
|
|
5
|
+
.catch((err) => {
|
|
6
|
+
process.stderr.write(`fatal: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=cli-bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-bun.js","sourceRoot":"","sources":["../../src/entrypoints/cli-bun.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,IAAI,EAAE;KACH,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAClC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-node.d.ts","sourceRoot":"","sources":["../../src/entrypoints/cli-node.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from "./cli.js";
|
|
3
|
+
main()
|
|
4
|
+
.then((code) => process.exit(code))
|
|
5
|
+
.catch((err) => {
|
|
6
|
+
process.stderr.write(`fatal: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=cli-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-node.js","sourceRoot":"","sources":["../../src/entrypoints/cli-node.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,IAAI,EAAE;KACH,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAClC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AppContext } from "../boot/load-runtime.js";
|
|
2
|
+
import { printHelp, printVersion } from "../commands/version.js";
|
|
3
|
+
import { CommandRegistry } from "../commands/registry.js";
|
|
4
|
+
/** Builds the registry of built-in sub-commands. */
|
|
5
|
+
export declare function buildCommandRegistry(): CommandRegistry;
|
|
6
|
+
export type LoadRuntimeFn = (overrides: {
|
|
7
|
+
provider?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
}) => Promise<AppContext>;
|
|
10
|
+
/** `loadRuntimeFn` is an injection seam for tests — see cli.test.tsx. */
|
|
11
|
+
export declare function main(argv?: string[], loadRuntimeFn?: LoadRuntimeFn): Promise<number>;
|
|
12
|
+
/** Exported so tests can pre-build a registry without invoking main(). */
|
|
13
|
+
export { printHelp, printVersion };
|
|
14
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/entrypoints/cli.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAMvE,OAAO,EAAe,SAAS,EAAE,YAAY,EAAkB,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AA2D1D,oDAAoD;AACpD,wBAAgB,oBAAoB,IAAI,eAAe,CAStD;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtG,yEAAyE;AACzE,wBAAsB,IAAI,CACxB,IAAI,GAAE,MAAM,EAA0B,EACtC,aAAa,GAAE,aAA2B,GACzC,OAAO,CAAC,MAAM,CAAC,CAgCjB;AAED,0EAA0E;AAC1E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { loadRuntime } from "../boot/load-runtime.js";
|
|
2
|
+
import { chatCommand } from "../commands/chat.js";
|
|
3
|
+
import { doctorCommand } from "../commands/doctor.js";
|
|
4
|
+
import { sessionCommand } from "../commands/session.js";
|
|
5
|
+
import { configCommand } from "../commands/config.js";
|
|
6
|
+
import { helpCommand, printHelp, printVersion, versionCommand } from "../commands/version.js";
|
|
7
|
+
import { CommandRegistry } from "../commands/registry.js";
|
|
8
|
+
function parseArgs(argv) {
|
|
9
|
+
const out = { command: "chat", rest: [], format: "text", yes: false, help: false, version: false };
|
|
10
|
+
const positional = [];
|
|
11
|
+
for (let i = 0; i < argv.length; i++) {
|
|
12
|
+
const arg = argv[i];
|
|
13
|
+
switch (arg) {
|
|
14
|
+
case "-p":
|
|
15
|
+
case "--prompt":
|
|
16
|
+
out.prompt = argv[++i] ?? "";
|
|
17
|
+
break;
|
|
18
|
+
case "--json":
|
|
19
|
+
out.format = "json";
|
|
20
|
+
break;
|
|
21
|
+
case "--ndjson":
|
|
22
|
+
out.format = "ndjson";
|
|
23
|
+
break;
|
|
24
|
+
case "--yes":
|
|
25
|
+
out.yes = true;
|
|
26
|
+
break;
|
|
27
|
+
case "--provider":
|
|
28
|
+
out.provider = argv[++i];
|
|
29
|
+
break;
|
|
30
|
+
case "--model":
|
|
31
|
+
out.model = argv[++i];
|
|
32
|
+
break;
|
|
33
|
+
case "-h":
|
|
34
|
+
case "--help":
|
|
35
|
+
out.help = true;
|
|
36
|
+
break;
|
|
37
|
+
case "--version":
|
|
38
|
+
out.version = true;
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
positional.push(arg);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (positional.length > 0) {
|
|
45
|
+
out.command = positional[0];
|
|
46
|
+
out.rest = positional.slice(1);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** Builds the registry of built-in sub-commands. */
|
|
51
|
+
export function buildCommandRegistry() {
|
|
52
|
+
const registry = new CommandRegistry();
|
|
53
|
+
registry.register(chatCommand);
|
|
54
|
+
registry.register(doctorCommand);
|
|
55
|
+
registry.register(configCommand);
|
|
56
|
+
registry.register(sessionCommand);
|
|
57
|
+
registry.register(helpCommand);
|
|
58
|
+
registry.register(versionCommand);
|
|
59
|
+
return registry;
|
|
60
|
+
}
|
|
61
|
+
/** `loadRuntimeFn` is an injection seam for tests — see cli.test.tsx. */
|
|
62
|
+
export async function main(argv = process.argv.slice(2), loadRuntimeFn = loadRuntime) {
|
|
63
|
+
const args = parseArgs(argv);
|
|
64
|
+
const registry = buildCommandRegistry();
|
|
65
|
+
// Version/help short-circuit BEFORE looking at the positional command. This
|
|
66
|
+
// way `chances --version` works the same as `chances version`, and crucially
|
|
67
|
+
// never enters the chat command, whose TTY guard would error out under e.g.
|
|
68
|
+
// `npm i -g @chances-ai/cli && chances --version` in a CI shell.
|
|
69
|
+
if (args.version)
|
|
70
|
+
return printVersion();
|
|
71
|
+
if (args.help)
|
|
72
|
+
return printHelp(registry);
|
|
73
|
+
const cmd = registry.get(args.command) ?? registry.get("chat");
|
|
74
|
+
const cliArgs = { positional: args.rest, prompt: args.prompt, format: args.format, yes: args.yes };
|
|
75
|
+
if (cmd.needsRuntime === false) {
|
|
76
|
+
return cmd.run(null, cliArgs, registry);
|
|
77
|
+
}
|
|
78
|
+
const ctx = await loadRuntimeFn({ provider: args.provider, model: args.model });
|
|
79
|
+
try {
|
|
80
|
+
return await cmd.run(ctx, cliArgs, registry);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
// Plugins may hold file handles / sockets / etc. Give them a chance to clean
|
|
84
|
+
// up regardless of whether the command succeeded or threw. Dispose errors
|
|
85
|
+
// are logged but don't mask the command's own outcome.
|
|
86
|
+
if (ctx.plugins) {
|
|
87
|
+
try {
|
|
88
|
+
await ctx.plugins.dispose();
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
ctx.logger.warn(`plugin dispose failed: ${e.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Exported so tests can pre-build a registry without invoking main(). */
|
|
97
|
+
export { printHelp, printVersion };
|
|
98
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/entrypoints/cli.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;A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AA;CAAE,CAkBlE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** JSON mode: emit exactly one final object on stdout (logs go to stderr). */
|
|
2
|
+
export function attachJson(bus) {
|
|
3
|
+
let text = "";
|
|
4
|
+
const toolCalls = [];
|
|
5
|
+
const usage = { inputTokens: 0, outputTokens: 0, costUsd: 0 };
|
|
6
|
+
let error = null;
|
|
7
|
+
bus.on("assistant:message", (e) => (text = e.text));
|
|
8
|
+
bus.on("tool:call", (e) => toolCalls.push({ name: e.name, args: e.args }));
|
|
9
|
+
bus.on("usage", (e) => {
|
|
10
|
+
usage.inputTokens += e.inputTokens;
|
|
11
|
+
usage.outputTokens += e.outputTokens;
|
|
12
|
+
usage.costUsd += e.costUsd;
|
|
13
|
+
});
|
|
14
|
+
bus.on("error", (e) => (error = { code: e.code, message: e.message }));
|
|
15
|
+
return {
|
|
16
|
+
finalize: () => process.stdout.write(JSON.stringify({ text, toolCalls, usage, error }) + "\n"),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/modes/json.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,MAAM,UAAU,UAAU,CAAC,GAAa;IACtC,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,MAAM,SAAS,GAAwC,EAAE,CAAC;IAC1D,MAAM,KAAK,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IAC9D,IAAI,KAAK,GAA6C,IAAI,CAAC;IAE3D,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3E,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACpB,KAAK,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC;QACnC,KAAK,CAAC,YAAY,IAAI,CAAC,CAAC,YAAY,CAAC;QACrC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAEvE,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;KAC/F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ndjson.d.ts","sourceRoot":"","sources":["../../src/modes/ndjson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;CAAE,CAWpE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** NDJSON mode: one event frame per line for streaming automation. */
|
|
2
|
+
export function attachNdjson(bus) {
|
|
3
|
+
const write = (frame) => {
|
|
4
|
+
process.stdout.write(JSON.stringify(frame) + "\n");
|
|
5
|
+
};
|
|
6
|
+
bus.on("turn:start", (e) => write({ type: "start", turnId: e.turnId }));
|
|
7
|
+
bus.on("assistant:delta", (e) => write({ type: "token", text: e.text }));
|
|
8
|
+
bus.on("tool:call", (e) => write({ type: "tool_call", callId: e.callId, name: e.name, args: e.args }));
|
|
9
|
+
bus.on("tool:result", (e) => write({ type: "tool_result", name: e.name, ok: e.ok, output: e.output }));
|
|
10
|
+
bus.on("assistant:message", (e) => write({ type: "result", text: e.text }));
|
|
11
|
+
bus.on("error", (e) => write({ type: "error", code: e.code, message: e.message }));
|
|
12
|
+
return { finalize: () => { } };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ndjson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ndjson.js","sourceRoot":"","sources":["../../src/modes/ndjson.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,MAAM,UAAU,YAAY,CAAC,GAAa;IACxC,MAAM,KAAK,GAAG,CAAC,KAA8B,EAAQ,EAAE;QACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC;IACF,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACxE,GAAG,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACzE,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACvG,GAAG,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACvG,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5E,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACnF,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/modes/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;CAAE,CAQlE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Plain-text mode: stream assistant output to stdout, diagnostics to stderr. */
|
|
2
|
+
export function attachText(bus) {
|
|
3
|
+
bus.on("assistant:delta", (e) => process.stdout.write(e.text));
|
|
4
|
+
bus.on("tool:call", (e) => process.stderr.write(`\n[tool] ${e.name} ${JSON.stringify(e.args)}\n`));
|
|
5
|
+
bus.on("tool:result", (e) => process.stderr.write(`[tool:${e.ok ? "ok" : "fail"}] ${e.output.slice(0, 200)}\n`));
|
|
6
|
+
bus.on("error", (e) => process.stderr.write(`[error] ${e.code}: ${e.message}\n`));
|
|
7
|
+
return { finalize: () => process.stdout.write("\n") };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/modes/text.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,GAAa;IACtC,GAAG,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnG,GAAG,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CACnF,CAAC;IACF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;IAClF,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;AACxD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chances-ai/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"chances": "./dist/entrypoints/cli-node.js",
|
|
7
|
+
"chances-bun": "./dist/entrypoints/cli-bun.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["dist"],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@ai-sdk/anthropic": "^1.2.0",
|
|
12
|
+
"@ai-sdk/openai": "^1.3.0",
|
|
13
|
+
"@chances-ai/ai": "1.0.0",
|
|
14
|
+
"@chances-ai/config": "1.0.0",
|
|
15
|
+
"@chances-ai/core": "1.0.0",
|
|
16
|
+
"@chances-ai/memory": "1.0.0",
|
|
17
|
+
"@chances-ai/native": "1.0.0",
|
|
18
|
+
"@chances-ai/plugin-api": "1.0.0",
|
|
19
|
+
"@chances-ai/plugin-logger": "1.0.0",
|
|
20
|
+
"@chances-ai/runtime": "1.0.0",
|
|
21
|
+
"@chances-ai/session": "1.0.0",
|
|
22
|
+
"@chances-ai/telemetry": "1.0.0",
|
|
23
|
+
"@chances-ai/tools": "1.0.0",
|
|
24
|
+
"@chances-ai/tui": "1.0.0",
|
|
25
|
+
"ai": "^4.3.0",
|
|
26
|
+
"ink": "^5.0.1",
|
|
27
|
+
"react": "^18.3.1",
|
|
28
|
+
"react-devtools-core": "7.0.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"dev": "bun run src/entrypoints/cli-bun.ts",
|
|
32
|
+
"build": "tsc -b",
|
|
33
|
+
"build:compile": "bun ../../scripts/build-release-binaries.ts",
|
|
34
|
+
"check": "tsc -b",
|
|
35
|
+
"test": "bun test"
|
|
36
|
+
}
|
|
37
|
+
}
|