ryeos-code 0.1.0__py3-none-any.whl
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.
- ryeos_code/.ai/directives/rye/code/diagnostics.md +48 -0
- ryeos_code/.ai/directives/rye/code/lsp.md +50 -0
- ryeos_code/.ai/directives/rye/code/npm.md +50 -0
- ryeos_code/.ai/directives/rye/code/typescript.md +50 -0
- ryeos_code/.ai/knowledge/rye/code/code-tools.md +349 -0
- ryeos_code/.ai/tools/rye/code/diagnostics/diagnostics.ts +347 -0
- ryeos_code/.ai/tools/rye/code/diagnostics/package-lock.json +555 -0
- ryeos_code/.ai/tools/rye/code/diagnostics/package.json +8 -0
- ryeos_code/.ai/tools/rye/code/git/git.py +246 -0
- ryeos_code/.ai/tools/rye/code/lsp/lsp.ts +438 -0
- ryeos_code/.ai/tools/rye/code/lsp/package-lock.json +593 -0
- ryeos_code/.ai/tools/rye/code/lsp/package.json +12 -0
- ryeos_code/.ai/tools/rye/code/npm/npm.ts +212 -0
- ryeos_code/.ai/tools/rye/code/npm/package-lock.json +555 -0
- ryeos_code/.ai/tools/rye/code/npm/package.json +8 -0
- ryeos_code/.ai/tools/rye/code/typescript/package-lock.json +555 -0
- ryeos_code/.ai/tools/rye/code/typescript/package.json +8 -0
- ryeos_code/.ai/tools/rye/code/typescript/typescript.ts +215 -0
- ryeos_code/__init__.py +1 -0
- ryeos_code/bundle.py +13 -0
- ryeos_code-0.1.0.dist-info/METADATA +13 -0
- ryeos_code-0.1.0.dist-info/RECORD +24 -0
- ryeos_code-0.1.0.dist-info/WHEEL +4 -0
- ryeos_code-0.1.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// rye:signed:2026-02-25T00:02:14Z:3bee8b7d861a79339f8fd009ef561e11abb40d1c87b08db49028242be4970d0f:P8p8U0WI5pmVYhqe7CRmFLbSJzKzwGe7OZ4HzWJ-frXdPrijfW7MkCjAHnBMGkg7QWkB0N8nPtFNgEJ3c2HDCA==:9fbfabe975fa5a7f
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { resolve, isAbsolute } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
|
|
7
|
+
export const __version__ = "1.0.0";
|
|
8
|
+
export const __tool_type__ = "javascript";
|
|
9
|
+
export const __executor_id__ = "rye/core/runtimes/node/node";
|
|
10
|
+
export const __category__ = "rye/code/npm";
|
|
11
|
+
export const __tool_description__ =
|
|
12
|
+
"NPM operations tool - install, run scripts, exec commands";
|
|
13
|
+
|
|
14
|
+
export const CONFIG_SCHEMA = {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
action: {
|
|
18
|
+
type: "string",
|
|
19
|
+
enum: ["install", "run", "build", "test", "init", "exec"],
|
|
20
|
+
description: "NPM action to perform",
|
|
21
|
+
},
|
|
22
|
+
args: {
|
|
23
|
+
type: "array",
|
|
24
|
+
items: { type: "string" },
|
|
25
|
+
default: [],
|
|
26
|
+
description:
|
|
27
|
+
"Arguments for the action (package names for install, script name for run, command for exec, etc.)",
|
|
28
|
+
},
|
|
29
|
+
flags: {
|
|
30
|
+
type: "object",
|
|
31
|
+
default: {},
|
|
32
|
+
description:
|
|
33
|
+
"Flags to pass (e.g. { save_dev: true, force: true, global: true })",
|
|
34
|
+
},
|
|
35
|
+
working_dir: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Working directory (relative to project root or absolute)",
|
|
38
|
+
},
|
|
39
|
+
timeout: {
|
|
40
|
+
type: "integer",
|
|
41
|
+
default: 120,
|
|
42
|
+
description: "Timeout in seconds",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ["action"],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const MAX_OUTPUT_BYTES = 51200;
|
|
49
|
+
const DEFAULT_TIMEOUT = 120;
|
|
50
|
+
|
|
51
|
+
interface Params {
|
|
52
|
+
action: string;
|
|
53
|
+
args?: string[];
|
|
54
|
+
flags?: Record<string, boolean | string>;
|
|
55
|
+
working_dir?: string;
|
|
56
|
+
timeout?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface Result {
|
|
60
|
+
success: boolean;
|
|
61
|
+
output?: string;
|
|
62
|
+
stdout?: string;
|
|
63
|
+
stderr?: string;
|
|
64
|
+
exit_code?: number;
|
|
65
|
+
error?: string;
|
|
66
|
+
truncated?: boolean;
|
|
67
|
+
command?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function truncateOutput(output: string, maxBytes: number): [string, boolean] {
|
|
71
|
+
const encoded = Buffer.from(output, "utf-8");
|
|
72
|
+
if (encoded.length <= maxBytes) return [output, false];
|
|
73
|
+
|
|
74
|
+
const truncated = encoded.subarray(0, maxBytes).toString("utf-8");
|
|
75
|
+
return [
|
|
76
|
+
truncated + `\n... [output truncated, ${encoded.length} bytes total]`,
|
|
77
|
+
true,
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function buildFlags(flags: Record<string, boolean | string>): string[] {
|
|
82
|
+
const result: string[] = [];
|
|
83
|
+
for (const [key, value] of Object.entries(flags)) {
|
|
84
|
+
const flag = key.length === 1 ? `-${key}` : `--${key.replace(/_/g, "-")}`;
|
|
85
|
+
if (value === true) {
|
|
86
|
+
result.push(flag);
|
|
87
|
+
} else if (typeof value === "string") {
|
|
88
|
+
result.push(flag, value);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function buildCommand(params: Params): string[] {
|
|
95
|
+
const args = params.args ?? [];
|
|
96
|
+
const flags = params.flags ? buildFlags(params.flags) : [];
|
|
97
|
+
|
|
98
|
+
switch (params.action) {
|
|
99
|
+
case "install":
|
|
100
|
+
return ["npm", "install", ...args, ...flags];
|
|
101
|
+
case "run":
|
|
102
|
+
if (args.length === 0) return ["npm", "run", ...flags];
|
|
103
|
+
return ["npm", "run", args[0], ...flags, ...args.slice(1)];
|
|
104
|
+
case "build":
|
|
105
|
+
return ["npm", "run", "build", ...flags];
|
|
106
|
+
case "test":
|
|
107
|
+
return ["npm", "test", ...flags];
|
|
108
|
+
case "init":
|
|
109
|
+
return ["npm", "init", "-y", ...flags];
|
|
110
|
+
case "exec":
|
|
111
|
+
if (args.length === 0)
|
|
112
|
+
throw new Error("exec action requires at least one arg (the command)");
|
|
113
|
+
return ["npx", ...args, ...flags];
|
|
114
|
+
default:
|
|
115
|
+
throw new Error(`Unknown action: ${params.action}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function execute(params: Params, projectPath: string): Result {
|
|
120
|
+
const project = resolve(projectPath);
|
|
121
|
+
|
|
122
|
+
if (!params.action) {
|
|
123
|
+
return { success: false, error: "Missing required parameter: action" };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const timeout = (params.timeout ?? DEFAULT_TIMEOUT) * 1000;
|
|
127
|
+
|
|
128
|
+
let cwd = project;
|
|
129
|
+
if (params.working_dir) {
|
|
130
|
+
cwd = isAbsolute(params.working_dir)
|
|
131
|
+
? resolve(params.working_dir)
|
|
132
|
+
: resolve(project, params.working_dir);
|
|
133
|
+
|
|
134
|
+
if (!existsSync(cwd)) {
|
|
135
|
+
return { success: false, error: `Working directory not found: ${cwd}` };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let cmd: string[];
|
|
140
|
+
try {
|
|
141
|
+
cmd = buildCommand(params);
|
|
142
|
+
} catch (e: any) {
|
|
143
|
+
return { success: false, error: e.message };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const cmdStr = cmd.join(" ");
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const output = execSync(cmdStr, {
|
|
150
|
+
cwd,
|
|
151
|
+
timeout,
|
|
152
|
+
encoding: "utf-8",
|
|
153
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
154
|
+
env: { ...process.env },
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const [stdout, truncated] = truncateOutput(output ?? "", MAX_OUTPUT_BYTES);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
success: true,
|
|
161
|
+
output: stdout,
|
|
162
|
+
stdout,
|
|
163
|
+
stderr: "",
|
|
164
|
+
exit_code: 0,
|
|
165
|
+
truncated,
|
|
166
|
+
command: cmdStr,
|
|
167
|
+
};
|
|
168
|
+
} catch (e: any) {
|
|
169
|
+
if (e.killed) {
|
|
170
|
+
return {
|
|
171
|
+
success: false,
|
|
172
|
+
error: `Command timed out after ${params.timeout ?? DEFAULT_TIMEOUT} seconds`,
|
|
173
|
+
command: cmdStr,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const stdout = e.stdout ?? "";
|
|
178
|
+
const stderr = e.stderr ?? "";
|
|
179
|
+
const [outTrunc, outWasTrunc] = truncateOutput(stdout, MAX_OUTPUT_BYTES);
|
|
180
|
+
const [errTrunc, errWasTrunc] = truncateOutput(stderr, MAX_OUTPUT_BYTES);
|
|
181
|
+
|
|
182
|
+
const outputParts: string[] = [];
|
|
183
|
+
if (outTrunc) outputParts.push(outTrunc);
|
|
184
|
+
if (errTrunc) outputParts.push(`[stderr]\n${errTrunc}`);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
success: false,
|
|
188
|
+
output: outputParts.join("\n"),
|
|
189
|
+
stdout: outTrunc,
|
|
190
|
+
stderr: errTrunc,
|
|
191
|
+
exit_code: e.status ?? 1,
|
|
192
|
+
truncated: outWasTrunc || errWasTrunc,
|
|
193
|
+
command: cmdStr,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// CLI entry point
|
|
199
|
+
const { values } = parseArgs({
|
|
200
|
+
options: {
|
|
201
|
+
params: { type: "string" },
|
|
202
|
+
"project-path": { type: "string" },
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (values.params && values["project-path"]) {
|
|
207
|
+
const result = execute(
|
|
208
|
+
JSON.parse(values.params) as Params,
|
|
209
|
+
values["project-path"],
|
|
210
|
+
);
|
|
211
|
+
console.log(JSON.stringify(result));
|
|
212
|
+
}
|