@love-moon/cli2sdk 0.1.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 (70) hide show
  1. package/dist/bin/claude_test_cli.d.ts +2 -0
  2. package/dist/bin/claude_test_cli.js +83 -0
  3. package/dist/bin/claude_test_cli.js.map +1 -0
  4. package/dist/bin/copilot_test_cli.d.ts +2 -0
  5. package/dist/bin/copilot_test_cli.js +83 -0
  6. package/dist/bin/copilot_test_cli.js.map +1 -0
  7. package/dist/bin/cursor_test_cli.d.ts +2 -0
  8. package/dist/bin/cursor_test_cli.js +83 -0
  9. package/dist/bin/cursor_test_cli.js.map +1 -0
  10. package/dist/bin/tmates_test_cli.d.ts +2 -0
  11. package/dist/bin/tmates_test_cli.js +74 -0
  12. package/dist/bin/tmates_test_cli.js.map +1 -0
  13. package/dist/core/base.d.ts +31 -0
  14. package/dist/core/base.js +87 -0
  15. package/dist/core/base.js.map +1 -0
  16. package/dist/core/chat_session.d.ts +22 -0
  17. package/dist/core/chat_session.js +59 -0
  18. package/dist/core/chat_session.js.map +1 -0
  19. package/dist/core/router.d.ts +19 -0
  20. package/dist/core/router.js +119 -0
  21. package/dist/core/router.js.map +1 -0
  22. package/dist/core/stream.d.ts +9 -0
  23. package/dist/core/stream.js +56 -0
  24. package/dist/core/stream.js.map +1 -0
  25. package/dist/index.d.ts +14 -0
  26. package/dist/index.js +13 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/providers/claude.d.ts +6 -0
  29. package/dist/providers/claude.js +27 -0
  30. package/dist/providers/claude.js.map +1 -0
  31. package/dist/providers/codex.d.ts +6 -0
  32. package/dist/providers/codex.js +87 -0
  33. package/dist/providers/codex.js.map +1 -0
  34. package/dist/providers/copilot.d.ts +8 -0
  35. package/dist/providers/copilot.js +29 -0
  36. package/dist/providers/copilot.js.map +1 -0
  37. package/dist/providers/cursor.d.ts +8 -0
  38. package/dist/providers/cursor.js +53 -0
  39. package/dist/providers/cursor.js.map +1 -0
  40. package/dist/providers/gemini.d.ts +6 -0
  41. package/dist/providers/gemini.js +26 -0
  42. package/dist/providers/gemini.js.map +1 -0
  43. package/dist/providers/local_binary.d.ts +6 -0
  44. package/dist/providers/local_binary.js +27 -0
  45. package/dist/providers/local_binary.js.map +1 -0
  46. package/dist/providers/tmates.d.ts +10 -0
  47. package/dist/providers/tmates.js +36 -0
  48. package/dist/providers/tmates.js.map +1 -0
  49. package/dist/types/index.d.ts +56 -0
  50. package/dist/types/index.js +2 -0
  51. package/dist/types/index.js.map +1 -0
  52. package/dist/types/message.d.ts +8 -0
  53. package/dist/types/message.js +2 -0
  54. package/dist/types/message.js.map +1 -0
  55. package/dist/types/provider.d.ts +53 -0
  56. package/dist/types/provider.js +2 -0
  57. package/dist/types/provider.js.map +1 -0
  58. package/dist/types/result.d.ts +23 -0
  59. package/dist/types/result.js +2 -0
  60. package/dist/types/result.js.map +1 -0
  61. package/dist/utils/cache.d.ts +14 -0
  62. package/dist/utils/cache.js +47 -0
  63. package/dist/utils/cache.js.map +1 -0
  64. package/dist/utils/logger.d.ts +16 -0
  65. package/dist/utils/logger.js +39 -0
  66. package/dist/utils/logger.js.map +1 -0
  67. package/dist/utils/shell.d.ts +21 -0
  68. package/dist/utils/shell.js +92 -0
  69. package/dist/utils/shell.js.map +1 -0
  70. package/package.json +47 -0
@@ -0,0 +1,56 @@
1
+ export interface ToolCall {
2
+ function: string;
3
+ parameters: {
4
+ [key: string]: any;
5
+ };
6
+ }
7
+ export interface ToolCallResponse {
8
+ success: boolean;
9
+ content: any;
10
+ [key: string]: any;
11
+ }
12
+ export interface AIModel {
13
+ name: string;
14
+ description: string;
15
+ capabilities: string[];
16
+ toolCallFormat: 'json' | 'yaml';
17
+ }
18
+ export interface GenerationConfig {
19
+ models: AIModel[];
20
+ outputDirectory: string;
21
+ language: 'typescript' | 'javascript';
22
+ includeExamples?: boolean;
23
+ }
24
+ export interface ChatMessage {
25
+ role: 'user' | 'assistant' | 'system';
26
+ content: string;
27
+ toolCalls?: ToolCall[];
28
+ toolCallResponses?: ToolCallResponse[];
29
+ }
30
+ export interface BaseAdapterOptions {
31
+ executablePath?: string;
32
+ workingDirectory?: string;
33
+ timeout?: number;
34
+ }
35
+ export interface CLIAdapter {
36
+ generateCode(prompt: string, options?: {
37
+ model?: string;
38
+ temperature?: number;
39
+ maxTokens?: number;
40
+ }): Promise<{
41
+ success: boolean;
42
+ code?: string;
43
+ error?: string;
44
+ rawOutput?: string;
45
+ }>;
46
+ chat(messages: ChatMessage[], options?: {
47
+ model?: string;
48
+ temperature?: number;
49
+ }): Promise<{
50
+ success: boolean;
51
+ response?: string;
52
+ toolCalls?: ToolCall[];
53
+ error?: string;
54
+ }>;
55
+ listModels(): Promise<AIModel[]>;
56
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export type MessageRole = "user" | "assistant" | "system" | "tool";
2
+ export interface Message {
3
+ role: MessageRole;
4
+ content: string;
5
+ timestamp?: number;
6
+ meta?: Record<string, unknown>;
7
+ }
8
+ export type MessageHistory = Message[];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ import { MessageHistory } from "./message.js";
2
+ import { ResultChunk, RunResult } from "./result.js";
3
+ import { CacheOptions } from "../utils/cache.js";
4
+ import { LoggerOptions } from "../utils/logger.js";
5
+ export type ProviderName = "claude" | "gemini" | "cursor" | "local" | "tmates" | "copilot" | "codex" | "auto";
6
+ export interface ShellOptions {
7
+ cwd?: string;
8
+ env?: NodeJS.ProcessEnv;
9
+ timeoutMs?: number;
10
+ stdin?: string | Buffer;
11
+ signal?: AbortSignal;
12
+ }
13
+ export interface ProviderBinaryConfig extends ShellOptions {
14
+ command?: string;
15
+ args?: string[];
16
+ streamArgs?: string[];
17
+ inputFormat?: "text" | "json";
18
+ supportsStreaming?: boolean;
19
+ name?: string;
20
+ }
21
+ export interface CodexConfig extends ProviderBinaryConfig {
22
+ model?: string;
23
+ sandboxMode?: string;
24
+ workingDirectory?: string;
25
+ skipGitRepoCheck?: boolean;
26
+ modelReasoningEffort?: string;
27
+ networkAccessEnabled?: boolean;
28
+ webSearchEnabled?: boolean;
29
+ approvalPolicy?: string;
30
+ }
31
+ export interface Cli2SdkConfig {
32
+ provider?: ProviderName;
33
+ claude?: ProviderBinaryConfig;
34
+ gemini?: ProviderBinaryConfig;
35
+ cursor?: ProviderBinaryConfig;
36
+ local?: ProviderBinaryConfig;
37
+ tmates?: ProviderBinaryConfig;
38
+ copilot?: ProviderBinaryConfig;
39
+ codex?: CodexConfig;
40
+ cache?: CacheOptions;
41
+ logger?: Partial<LoggerOptions>;
42
+ shell?: ShellOptions;
43
+ }
44
+ export interface RunOptions extends ShellOptions {
45
+ provider?: ProviderName;
46
+ history?: MessageHistory;
47
+ metadata?: Record<string, unknown>;
48
+ quiet?: boolean;
49
+ }
50
+ export interface ProviderRunner {
51
+ run(prompt: string, options?: RunOptions): Promise<RunResult>;
52
+ stream(prompt: string, options?: RunOptions): AsyncGenerator<ResultChunk>;
53
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { MessageHistory } from "./message.js";
2
+ export interface Usage {
3
+ promptTokens?: number;
4
+ completionTokens?: number;
5
+ totalTokens?: number;
6
+ }
7
+ export interface ResultChunk {
8
+ id?: string;
9
+ text?: string;
10
+ delta?: string;
11
+ done?: boolean;
12
+ usage?: Usage;
13
+ metadata?: Record<string, unknown>;
14
+ provider?: string;
15
+ }
16
+ export interface RunResult {
17
+ text: string;
18
+ chunks: ResultChunk[];
19
+ history?: MessageHistory;
20
+ usage?: Usage;
21
+ provider: string;
22
+ metadata?: Record<string, unknown>;
23
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/types/result.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export interface CacheOptions {
2
+ max?: number;
3
+ ttlMs?: number;
4
+ }
5
+ export declare class LruCache<K, V> {
6
+ private readonly options;
7
+ private map;
8
+ constructor(options?: CacheOptions);
9
+ get(key: K): V | undefined;
10
+ set(key: K, value: V): void;
11
+ delete(key: K): void;
12
+ clear(): void;
13
+ private trim;
14
+ }
@@ -0,0 +1,47 @@
1
+ export class LruCache {
2
+ options;
3
+ map = new Map();
4
+ constructor(options = {}) {
5
+ this.options = options;
6
+ }
7
+ get(key) {
8
+ const entry = this.map.get(key);
9
+ if (!entry)
10
+ return undefined;
11
+ if (entry.expiresAt && entry.expiresAt < Date.now()) {
12
+ this.map.delete(key);
13
+ return undefined;
14
+ }
15
+ this.map.delete(key);
16
+ this.map.set(key, entry);
17
+ return entry.value;
18
+ }
19
+ set(key, value) {
20
+ const next = {
21
+ value,
22
+ expiresAt: this.options.ttlMs ? Date.now() + this.options.ttlMs : undefined
23
+ };
24
+ if (this.map.has(key)) {
25
+ this.map.delete(key);
26
+ }
27
+ this.map.set(key, next);
28
+ this.trim();
29
+ }
30
+ delete(key) {
31
+ this.map.delete(key);
32
+ }
33
+ clear() {
34
+ this.map.clear();
35
+ }
36
+ trim() {
37
+ const max = this.options.max ?? 128;
38
+ while (this.map.size > max) {
39
+ const oldestKey = this.map.keys().next().value;
40
+ if (oldestKey === undefined) {
41
+ break;
42
+ }
43
+ this.map.delete(oldestKey);
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=cache.js.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AE,CAAC;IACd,CAAC;IAED,MAAM,CAAC,GAAM;QACX,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IAEO,IAAI;QACV,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YAC/C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,MAAM;YACR,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ export type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
2
+ export interface Logger {
3
+ readonly level: LogLevel;
4
+ readonly tag: string;
5
+ debug: (...args: unknown[]) => void;
6
+ info: (...args: unknown[]) => void;
7
+ warn: (...args: unknown[]) => void;
8
+ error: (...args: unknown[]) => void;
9
+ }
10
+ export interface LoggerOptions {
11
+ level?: LogLevel;
12
+ tag?: string;
13
+ writer?: Pick<Console, "debug" | "info" | "warn" | "error">;
14
+ }
15
+ export declare const createLogger: (options?: LoggerOptions) => Logger;
16
+ export declare const silentLogger: Logger;
@@ -0,0 +1,39 @@
1
+ const levelOrder = {
2
+ silent: 0,
3
+ error: 1,
4
+ warn: 2,
5
+ info: 3,
6
+ debug: 4
7
+ };
8
+ const noop = () => undefined;
9
+ export const createLogger = (options = {}) => {
10
+ const envLevel = process.env.CLI2SDK_LOG_LEVEL || undefined;
11
+ const level = options.level || envLevel || "info";
12
+ const tag = options.tag ?? "cli2sdk";
13
+ const writer = options.writer ?? console;
14
+ const threshold = levelOrder[level] ?? levelOrder.info;
15
+ const emit = (lvl, args) => {
16
+ if ((levelOrder[lvl] ?? 0) > threshold || level === "silent") {
17
+ return;
18
+ }
19
+ const prefix = `[${tag}]`;
20
+ writer[lvl](prefix, ...args);
21
+ };
22
+ return {
23
+ level,
24
+ tag,
25
+ debug: (...args) => emit("debug", args),
26
+ info: (...args) => emit("info", args),
27
+ warn: (...args) => emit("warn", args),
28
+ error: (...args) => emit("error", args)
29
+ };
30
+ };
31
+ export const silentLogger = {
32
+ level: "silent",
33
+ tag: "cli2sdk",
34
+ debug: noop,
35
+ info: noop,
36
+ warn: noop,
37
+ error: noop
38
+ };
39
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,GAA6B;IAC3C,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;AAE7B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAAyB,EAAE,EAAU,EAAE;IAClE,MAAM,QAAQ,GAAI,OAAO,CAAC,GAAG,CAAC,iBAA8B,IAAI,SAAS,CAAC;IAC1E,MAAM,KAAK,GAAa,OAAO,CAAC,KAAK,IAAI,QAAQ,IAAI,MAAM,CAAC;IAC5D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC;IAEvD,MAAM,IAAI,GAAG,CAAC,GAAgC,EAAE,IAAe,EAAE,EAAE;QACjE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC7D,OAAO;QACT,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;QAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,OAAO;QACL,KAAK;QACL,GAAG;QACH,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC;QACvC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;QACrC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;QACrC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC;KACxC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAW;IAClC,KAAK,EAAE,QAAQ;IACf,GAAG,EAAE,SAAS;IACd,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Logger } from "./logger.js";
2
+ export interface CommandRequest {
3
+ command: string;
4
+ args?: string[];
5
+ cwd?: string;
6
+ env?: NodeJS.ProcessEnv;
7
+ timeoutMs?: number;
8
+ stdin?: string | Buffer;
9
+ signal?: AbortSignal;
10
+ }
11
+ export interface CommandResult {
12
+ stdout: string;
13
+ stderr: string;
14
+ exitCode: number;
15
+ }
16
+ export declare class CommandError extends Error {
17
+ readonly result: CommandResult;
18
+ constructor(message: string, result: CommandResult);
19
+ }
20
+ export declare const runCommand: (request: CommandRequest, logger?: Logger) => Promise<CommandResult>;
21
+ export declare const streamCommand: (request: CommandRequest, logger?: Logger) => AsyncGenerator<string>;
@@ -0,0 +1,92 @@
1
+ import { spawn } from "child_process";
2
+ import { once } from "events";
3
+ import { createLogger } from "./logger.js";
4
+ export class CommandError extends Error {
5
+ result;
6
+ constructor(message, result) {
7
+ super(message);
8
+ this.result = result;
9
+ this.name = "CommandError";
10
+ }
11
+ }
12
+ const withDefaultEnv = (env) => ({
13
+ ...process.env,
14
+ ...env
15
+ });
16
+ export const runCommand = async (request, logger = createLogger()) => {
17
+ const child = spawn(request.command, request.args ?? [], {
18
+ cwd: request.cwd,
19
+ env: withDefaultEnv(request.env),
20
+ stdio: "pipe"
21
+ });
22
+ const chunks = [];
23
+ const errors = [];
24
+ if (request.stdin) {
25
+ child.stdin.write(request.stdin);
26
+ }
27
+ child.stdin.end();
28
+ child.stdout.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
29
+ child.stderr.on("data", (chunk) => errors.push(Buffer.from(chunk)));
30
+ const cleanup = setupAbort(child, request, logger);
31
+ const [exitCode] = (await once(child, "exit"));
32
+ cleanup();
33
+ const stdout = Buffer.concat(chunks).toString("utf8");
34
+ const stderr = Buffer.concat(errors).toString("utf8");
35
+ const result = { stdout, stderr, exitCode };
36
+ if (exitCode !== 0) {
37
+ logger.error(`CLI command failed (${request.command})`, stderr.trim() || stdout.trim());
38
+ throw new CommandError(`Command ${request.command} exited with code ${exitCode}`, result);
39
+ }
40
+ return result;
41
+ };
42
+ export const streamCommand = async function* (request, logger = createLogger()) {
43
+ const child = spawn(request.command, request.args ?? [], {
44
+ cwd: request.cwd,
45
+ env: withDefaultEnv(request.env),
46
+ stdio: ["pipe", "pipe", "pipe"]
47
+ });
48
+ if (request.stdin) {
49
+ child.stdin.write(request.stdin);
50
+ }
51
+ child.stdin.end();
52
+ const cleanup = setupAbort(child, request, logger);
53
+ const stderr = [];
54
+ child.stderr.on("data", (chunk) => {
55
+ stderr.push(Buffer.from(chunk));
56
+ });
57
+ try {
58
+ for await (const chunk of child.stdout) {
59
+ yield chunk.toString("utf8");
60
+ }
61
+ }
62
+ finally {
63
+ const [exitCode] = (await once(child, "exit"));
64
+ cleanup();
65
+ if (exitCode !== 0) {
66
+ throw new CommandError(`Command ${request.command} exited with code ${exitCode}`, {
67
+ stdout: "",
68
+ stderr: Buffer.concat(stderr).toString("utf8"),
69
+ exitCode
70
+ });
71
+ }
72
+ }
73
+ };
74
+ const setupAbort = (child, request, logger) => {
75
+ let timeout;
76
+ const abort = (reason) => {
77
+ logger.warn(`Aborting CLI command: ${reason}`);
78
+ child.kill("SIGTERM");
79
+ };
80
+ if (request.timeoutMs) {
81
+ timeout = setTimeout(() => abort("timeout"), request.timeoutMs);
82
+ }
83
+ const abortListener = () => abort("signal");
84
+ request.signal?.addEventListener("abort", abortListener);
85
+ return () => {
86
+ if (timeout) {
87
+ clearTimeout(timeout);
88
+ }
89
+ request.signal?.removeEventListener("abort", abortListener);
90
+ };
91
+ };
92
+ //# sourceMappingURL=shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAU,YAAY,EAAE,MAAM,aAAa,CAAC;AAkBnD,MAAM,OAAO,YAAa,SAAQ,KAAK;IAGnB;IAFlB,YACE,OAAe,EACC,MAAqB;QAErC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,WAAM,GAAN,MAAM,CAAe;QAGrC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,cAAc,GAAG,CAAC,GAAuB,EAAqB,EAAE,CAAC,CAAC;IACtE,GAAG,OAAO,CAAC,GAAG;IACd,GAAG,GAAG;CACP,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,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AO,GAAG,EAAE;QACV,IAAI,OAAO,EAAE,CAAC;YACZ,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@love-moon/cli2sdk",
3
+ "version": "0.1.0",
4
+ "description": "Unified SDK that wraps CLI-based AI code tools into a single TypeScript API.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "bin": {
15
+ "cli2sdk-claude": "dist/bin/claude_test_cli.js",
16
+ "cli2sdk-cursor": "dist/bin/cursor_test_cli.js",
17
+ "cli2sdk-tmates": "dist/bin/tmates_test_cli.js",
18
+ "cli2sdk-copilot": "dist/bin/copilot_test_cli.js"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json",
22
+ "typecheck": "tsc --noEmit -p tsconfig.json",
23
+ "clean": "rimraf dist",
24
+ "test": "npm run build && node --test test/**/*.spec.js",
25
+ "prepare": "npm run build",
26
+ "prepublishOnly": "npm run build"
27
+ },
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
31
+ "dependencies": {
32
+ "commander": "^14.0.2",
33
+ "tslib": "^2.6.2",
34
+ "@types/node": "^20.19.25",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "devDependencies": {
38
+ "rimraf": "^5.0.10"
39
+ },
40
+ "directories": {
41
+ "doc": "docs",
42
+ "test": "test"
43
+ },
44
+ "keywords": [],
45
+ "author": "",
46
+ "license": "ISC"
47
+ }