johankit 0.0.3 → 0.0.4
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/cli/commands/paste.js +15 -10
- package/dist/cli/commands/prompt.js +39 -7
- package/dist/cli/commands/sync.js +10 -6
- package/dist/cli/commands/three.js +106 -0
- package/dist/index.js +52 -34
- package/dist/services/JohankitService.js +59 -0
- package/dist/utils/createAsciiTree.js +46 -0
- package/johankit.yaml +2 -0
- package/package.json +2 -1
- package/src/cli/commands/paste.ts +15 -16
- package/src/cli/commands/prompt.ts +45 -7
- package/src/cli/commands/sync.ts +8 -6
- package/src/cli/commands/three.ts +117 -0
- package/src/core/scan.ts +1 -1
- package/src/index.ts +54 -37
- package/src/services/JohankitService.ts +70 -0
- package/src/types.ts +45 -0
- package/src/utils/createAsciiTree.ts +53 -0
- package/cli/commands/paste.js +0 -42
- package/cli/commands/paste.ts +0 -42
- package/cli/commands/prompt.js +0 -59
- package/cli/commands/prompt.ts +0 -57
- package/cli/commands/sync.js +0 -83
- package/cli/commands/sync.ts +0 -87
- package/commands/paste.js +0 -42
- package/commands/paste.ts +0 -45
- package/core/config.js +0 -44
- package/core/config.ts +0 -42
- package/core/schema.js +0 -30
- package/core/schema.ts +0 -29
- package/core/vm.js +0 -20
- package/core/vm.ts +0 -18
- package/dist/core/clean.js +0 -13
package/cli/commands/sync.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sync = void 0;
|
|
4
|
-
// src/cli/commands/sync.ts
|
|
5
|
-
const scan_1 = require("../../core/scan");
|
|
6
|
-
const diff_1 = require("../../core/diff");
|
|
7
|
-
const clipboard_1 = require("../../core/clipboard");
|
|
8
|
-
const validation_1 = require("../../core/validation");
|
|
9
|
-
const vm_1 = require("../../core/vm");
|
|
10
|
-
async function sync(dir) {
|
|
11
|
-
try {
|
|
12
|
-
const snapshotBefore = (0, scan_1.scanDir)(dir);
|
|
13
|
-
const template = `
|
|
14
|
-
You are an AI software engineer.
|
|
15
|
-
|
|
16
|
-
You will receive a JSON array representing a snapshot of a codebase.
|
|
17
|
-
Each item has the following structure:
|
|
18
|
-
|
|
19
|
-
\`\`\`json
|
|
20
|
-
{
|
|
21
|
-
"path": "relative/path/to/file.ext",
|
|
22
|
-
"content": "full file content"
|
|
23
|
-
}
|
|
24
|
-
\`\`\`
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
SNAPSHOT
|
|
29
|
-
${JSON.stringify(snapshotBefore, null, 2)}
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
YOUR TASK
|
|
34
|
-
Propose changes according to the user request.
|
|
35
|
-
|
|
36
|
-
Return ONLY a JSON array of patches.
|
|
37
|
-
|
|
38
|
-
PATCH FORMAT (STRICT)
|
|
39
|
-
{
|
|
40
|
-
\"path\": \"relative/path/to/file.ext\",
|
|
41
|
-
\"content\": \"FULL updated file content (omit for delete)\"
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
IMPORTANT RULES
|
|
45
|
-
- Do NOT return explanations
|
|
46
|
-
- Do NOT return markdown
|
|
47
|
-
- Return ONLY valid JSON
|
|
48
|
-
|
|
49
|
-
USER REQUEST
|
|
50
|
-
<Replace this with the user request>
|
|
51
|
-
`;
|
|
52
|
-
await (0, clipboard_1.copyToClipboard)(template.trim());
|
|
53
|
-
process.stdout.write("✔ Prompt with snapshot copied to clipboard\n");
|
|
54
|
-
const input = await readStdin();
|
|
55
|
-
let patches;
|
|
56
|
-
try {
|
|
57
|
-
patches = (0, vm_1.runInVm)(`module.exports = function() { return ${input}; }`)();
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
throw new Error("Invalid JSON input or execution in VM failed");
|
|
61
|
-
}
|
|
62
|
-
const validated = (0, validation_1.validatePatches)(patches);
|
|
63
|
-
(0, diff_1.applyDiff)(dir, validated);
|
|
64
|
-
const snapshotAfter = (0, scan_1.scanDir)(dir);
|
|
65
|
-
await (0, clipboard_1.copyToClipboard)(JSON.stringify(snapshotAfter, null, 2));
|
|
66
|
-
process.stdout.write("✔ Sync applied and new snapshot copied to clipboard\n");
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
process.stderr.write("✖ Sync failed\n");
|
|
70
|
-
if (error instanceof Error) {
|
|
71
|
-
process.stderr.write(`${error.message}\n`);
|
|
72
|
-
}
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.sync = sync;
|
|
77
|
-
function readStdin() {
|
|
78
|
-
return new Promise(resolve => {
|
|
79
|
-
let data = "";
|
|
80
|
-
process.stdin.on("data", c => (data += c));
|
|
81
|
-
process.stdin.on("end", () => resolve(data));
|
|
82
|
-
});
|
|
83
|
-
}
|
package/cli/commands/sync.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// src/cli/commands/sync.ts
|
|
2
|
-
import { scanDir } from "../../core/scan";
|
|
3
|
-
import { applyDiff } from "../../core/diff";
|
|
4
|
-
import { copyToClipboard } from "../../core/clipboard";
|
|
5
|
-
import { validatePatches } from "../../core/validation";
|
|
6
|
-
import { writeFiles } from "../../core/write";
|
|
7
|
-
import { runInVm } from "../../core/vm";
|
|
8
|
-
|
|
9
|
-
export async function sync(dir: string) {
|
|
10
|
-
try {
|
|
11
|
-
const snapshotBefore = scanDir(dir);
|
|
12
|
-
|
|
13
|
-
const template = `
|
|
14
|
-
You are an AI software engineer.
|
|
15
|
-
|
|
16
|
-
You will receive a JSON array representing a snapshot of a codebase.
|
|
17
|
-
Each item has the following structure:
|
|
18
|
-
|
|
19
|
-
\`\`\`json
|
|
20
|
-
{
|
|
21
|
-
"path": "relative/path/to/file.ext",
|
|
22
|
-
"content": "full file content"
|
|
23
|
-
}
|
|
24
|
-
\`\`\`
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
SNAPSHOT
|
|
29
|
-
${JSON.stringify(snapshotBefore, null, 2)}
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
YOUR TASK
|
|
34
|
-
Propose changes according to the user request.
|
|
35
|
-
|
|
36
|
-
Return ONLY a JSON array of patches.
|
|
37
|
-
|
|
38
|
-
PATCH FORMAT (STRICT)
|
|
39
|
-
{
|
|
40
|
-
\"path\": \"relative/path/to/file.ext\",
|
|
41
|
-
\"content\": \"FULL updated file content (omit for delete)\"
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
IMPORTANT RULES
|
|
45
|
-
- Do NOT return explanations
|
|
46
|
-
- Do NOT return markdown
|
|
47
|
-
- Return ONLY valid JSON
|
|
48
|
-
|
|
49
|
-
USER REQUEST
|
|
50
|
-
<Replace this with the user request>
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
await copyToClipboard(template.trim());
|
|
54
|
-
process.stdout.write("✔ Prompt with snapshot copied to clipboard\n");
|
|
55
|
-
|
|
56
|
-
const input = await readStdin();
|
|
57
|
-
|
|
58
|
-
let patches;
|
|
59
|
-
try {
|
|
60
|
-
patches = runInVm(`module.exports = function() { return ${input}; }`)();
|
|
61
|
-
} catch {
|
|
62
|
-
throw new Error("Invalid JSON input or execution in VM failed");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const validated = validatePatches(patches);
|
|
66
|
-
applyDiff(dir, validated);
|
|
67
|
-
|
|
68
|
-
const snapshotAfter = scanDir(dir);
|
|
69
|
-
await copyToClipboard(JSON.stringify(snapshotAfter, null, 2));
|
|
70
|
-
|
|
71
|
-
process.stdout.write("✔ Sync applied and new snapshot copied to clipboard\n");
|
|
72
|
-
} catch (error) {
|
|
73
|
-
process.stderr.write("✖ Sync failed\n");
|
|
74
|
-
if (error instanceof Error) {
|
|
75
|
-
process.stderr.write(`${error.message}\n`);
|
|
76
|
-
}
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function readStdin(): Promise<string> {
|
|
82
|
-
return new Promise(resolve => {
|
|
83
|
-
let data = "";
|
|
84
|
-
process.stdin.on("data", c => (data += c));
|
|
85
|
-
process.stdin.on("end", () => resolve(data));
|
|
86
|
-
});
|
|
87
|
-
}
|
package/commands/paste.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.paste = void 0;
|
|
4
|
-
// src/cli/commands/paste.ts
|
|
5
|
-
const write_1 = require("../../core/write");
|
|
6
|
-
const clipboard_1 = require("../../core/clipboard");
|
|
7
|
-
async function paste(dir) {
|
|
8
|
-
try {
|
|
9
|
-
const content = await (0, clipboard_1.readClipboard)();
|
|
10
|
-
if (!content) {
|
|
11
|
-
throw new Error("Clipboard empty or inaccessible");
|
|
12
|
-
}
|
|
13
|
-
let files;
|
|
14
|
-
try {
|
|
15
|
-
let cleanContent = content.replace(/^\uFEFF/, "").trim();
|
|
16
|
-
// Remove code block markers ``` ou ````` caso existam
|
|
17
|
-
cleanContent = cleanContent.replace(/```+\s*json?/g, "").replace(/```+/g, "");
|
|
18
|
-
files = JSON.parse(cleanContent);
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
throw new Error("Clipboard content is not valid JSON");
|
|
22
|
-
}
|
|
23
|
-
if (!Array.isArray(files)) {
|
|
24
|
-
throw new Error("Clipboard content is not a JSON array");
|
|
25
|
-
}
|
|
26
|
-
// Validação simples do snapshot
|
|
27
|
-
const isValidSnapshot = files.every(f => typeof f.path === 'string' && typeof f.content === 'string');
|
|
28
|
-
if (!isValidSnapshot) {
|
|
29
|
-
throw new Error("JSON does not match FileSnapshot structure {path, content}");
|
|
30
|
-
}
|
|
31
|
-
(0, write_1.writeFiles)(dir, files, true);
|
|
32
|
-
process.stdout.write("✔ Pasted from clipboard\n");
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
process.stderr.write("✖ Paste failed\n");
|
|
36
|
-
if (error instanceof Error) {
|
|
37
|
-
process.stderr.write(`${error.message}\n`);
|
|
38
|
-
}
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.paste = paste;
|
package/commands/paste.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/cli/commands/paste.ts
|
|
2
|
-
import { writeFiles } from "../../core/write";
|
|
3
|
-
import { readClipboard } from "../../core/clipboard";
|
|
4
|
-
|
|
5
|
-
export async function paste(dir: string) {
|
|
6
|
-
try {
|
|
7
|
-
const content = await readClipboard();
|
|
8
|
-
|
|
9
|
-
if (!content) {
|
|
10
|
-
throw new Error("Clipboard empty or inaccessible");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let files;
|
|
14
|
-
try {
|
|
15
|
-
let cleanContent = content.replace(/^\uFEFF/, "").trim();
|
|
16
|
-
// Remove code block markers ``` ou ````` caso existam
|
|
17
|
-
cleanContent = cleanContent.replace(/```+\s*json?/g, "").replace(/```+/g, "");
|
|
18
|
-
files = JSON.parse(cleanContent);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
throw new Error("Clipboard content is not valid JSON");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!Array.isArray(files)) {
|
|
24
|
-
throw new Error("Clipboard content is not a JSON array");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Validação simples do snapshot
|
|
28
|
-
const isValidSnapshot = files.every(f =>
|
|
29
|
-
typeof f.path === 'string' && typeof f.content === 'string'
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
if (!isValidSnapshot) {
|
|
33
|
-
throw new Error("JSON does not match FileSnapshot structure {path, content}");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
writeFiles(dir, files, true);
|
|
37
|
-
process.stdout.write("✔ Pasted from clipboard\n");
|
|
38
|
-
} catch (error) {
|
|
39
|
-
process.stderr.write("✖ Paste failed\n");
|
|
40
|
-
if (error instanceof Error) {
|
|
41
|
-
process.stderr.write(`${error.message}\n`);
|
|
42
|
-
}
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
}
|
package/core/config.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadConfig = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const js_yaml_1 = require("js-yaml");
|
|
10
|
-
const CONFIG_FILENAME = "johankit.yaml";
|
|
11
|
-
const DEFAULT_IGNORE = [
|
|
12
|
-
".git",
|
|
13
|
-
"node_modules",
|
|
14
|
-
"dist",
|
|
15
|
-
"build",
|
|
16
|
-
"coverage",
|
|
17
|
-
"tmp",
|
|
18
|
-
"temp",
|
|
19
|
-
];
|
|
20
|
-
function loadConfig(basePath) {
|
|
21
|
-
const configPath = path_1.default.join(basePath, CONFIG_FILENAME);
|
|
22
|
-
try {
|
|
23
|
-
const content = (0, fs_1.readFileSync)(configPath, "utf8");
|
|
24
|
-
const loadedConfig = (0, js_yaml_1.load)(content);
|
|
25
|
-
return {
|
|
26
|
-
ignore: [
|
|
27
|
-
...DEFAULT_IGNORE,
|
|
28
|
-
...(loadedConfig.ignore || []),
|
|
29
|
-
],
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
if (error instanceof Error && error.code === "ENOENT") {
|
|
34
|
-
return {
|
|
35
|
-
ignore: DEFAULT_IGNORE,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
console.warn(`[johankit] Aviso: Falha ao carregar ${CONFIG_FILENAME}. Usando defaults.`, error);
|
|
39
|
-
return {
|
|
40
|
-
ignore: DEFAULT_IGNORE,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.loadConfig = loadConfig;
|
package/core/config.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { readFileSync } from "fs";
|
|
3
|
-
import { load } from "js-yaml";
|
|
4
|
-
import { Config } from "../types";
|
|
5
|
-
|
|
6
|
-
const CONFIG_FILENAME = "johankit.yaml";
|
|
7
|
-
const DEFAULT_IGNORE = [
|
|
8
|
-
".git",
|
|
9
|
-
"node_modules",
|
|
10
|
-
"dist",
|
|
11
|
-
"build",
|
|
12
|
-
"coverage",
|
|
13
|
-
"tmp",
|
|
14
|
-
"temp",
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
export function loadConfig(basePath: string): Config {
|
|
18
|
-
const configPath = path.join(basePath, CONFIG_FILENAME);
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const content = readFileSync(configPath, "utf8");
|
|
22
|
-
const loadedConfig = load(content) as Partial<Config>;
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
ignore: [
|
|
26
|
-
...DEFAULT_IGNORE,
|
|
27
|
-
...(loadedConfig.ignore || []),
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (error instanceof Error && (error as any).code === "ENOENT") {
|
|
32
|
-
return {
|
|
33
|
-
ignore: DEFAULT_IGNORE,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
console.warn(`[johankit] Aviso: Falha ao carregar ${CONFIG_FILENAME}. Usando defaults.`, error);
|
|
38
|
-
return {
|
|
39
|
-
ignore: DEFAULT_IGNORE,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
package/core/schema.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validatePatches = void 0;
|
|
4
|
-
function isValidPatch(patch) {
|
|
5
|
-
if (typeof patch !== "object" || patch === null)
|
|
6
|
-
return false;
|
|
7
|
-
if (typeof patch.path !== "string" || patch.path.length === 0)
|
|
8
|
-
return false;
|
|
9
|
-
const validTypes = ["modify", "create", "delete"];
|
|
10
|
-
if (!validTypes.includes(patch.type))
|
|
11
|
-
return false;
|
|
12
|
-
if (patch.type === "delete") {
|
|
13
|
-
return patch.content === undefined;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return typeof patch.content === "string";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function validatePatches(patches) {
|
|
20
|
-
if (!Array.isArray(patches)) {
|
|
21
|
-
throw new Error("O patch deve ser um array JSON válido");
|
|
22
|
-
}
|
|
23
|
-
for (const [index, patch] of patches.entries()) {
|
|
24
|
-
if (!isValidPatch(patch)) {
|
|
25
|
-
throw new Error(`Patch inválido no índice ${index}: ${JSON.stringify(patch, null, 2)}.\nEsperado: { type: 'modify'|'create'|'delete', path: string, content?: string }`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return patches;
|
|
29
|
-
}
|
|
30
|
-
exports.validatePatches = validatePatches;
|
package/core/schema.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { DiffPatch } from "./diff";
|
|
2
|
-
|
|
3
|
-
function isValidPatch(patch: any): boolean {
|
|
4
|
-
if (typeof patch !== "object" || patch === null) return false;
|
|
5
|
-
if (typeof patch.path !== "string" || patch.path.length === 0) return false;
|
|
6
|
-
|
|
7
|
-
const validTypes = ["modify", "create", "delete"];
|
|
8
|
-
if (!validTypes.includes(patch.type)) return false;
|
|
9
|
-
|
|
10
|
-
if (patch.type === "delete") {
|
|
11
|
-
return patch.content === undefined;
|
|
12
|
-
} else {
|
|
13
|
-
return typeof patch.content === "string";
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function validatePatches(patches: any): DiffPatch[] {
|
|
18
|
-
if (!Array.isArray(patches)) {
|
|
19
|
-
throw new Error("O patch deve ser um array JSON válido");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
for (const [index, patch] of patches.entries()) {
|
|
23
|
-
if (!isValidPatch(patch)) {
|
|
24
|
-
throw new Error(`Patch inválido no índice ${index}: ${JSON.stringify(patch, null, 2)}.\nEsperado: { type: 'modify'|'create'|'delete', path: string, content?: string }`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return patches as DiffPatch[];
|
|
29
|
-
}
|
package/core/vm.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runInVm = void 0;
|
|
4
|
-
// src/core/vm.ts
|
|
5
|
-
const vm2_1 = require("vm2");
|
|
6
|
-
function runInVm(code, sandbox = {}) {
|
|
7
|
-
const vm = new vm2_1.NodeVM({
|
|
8
|
-
console: 'inherit',
|
|
9
|
-
sandbox,
|
|
10
|
-
require: {
|
|
11
|
-
external: true,
|
|
12
|
-
builtin: ['*'],
|
|
13
|
-
},
|
|
14
|
-
wrapper: 'commonjs',
|
|
15
|
-
timeout: 1000
|
|
16
|
-
});
|
|
17
|
-
const script = new vm2_1.VMScript(code);
|
|
18
|
-
return vm.run(script);
|
|
19
|
-
}
|
|
20
|
-
exports.runInVm = runInVm;
|
package/core/vm.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// src/core/vm.ts
|
|
2
|
-
import { NodeVM, VMScript } from 'vm2';
|
|
3
|
-
|
|
4
|
-
export function runInVm(code: string, sandbox: Record<string, any> = {}) {
|
|
5
|
-
const vm = new NodeVM({
|
|
6
|
-
console: 'inherit',
|
|
7
|
-
sandbox,
|
|
8
|
-
require: {
|
|
9
|
-
external: true,
|
|
10
|
-
builtin: ['*'],
|
|
11
|
-
},
|
|
12
|
-
wrapper: 'commonjs',
|
|
13
|
-
timeout: 1000
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const script = new VMScript(code);
|
|
17
|
-
return vm.run(script);
|
|
18
|
-
}
|
package/dist/core/clean.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanCodeBlock = void 0;
|
|
4
|
-
function cleanCodeBlock(content) {
|
|
5
|
-
const langMatch = content.match(/^```(\w+)?/);
|
|
6
|
-
const lang = langMatch ? langMatch[1] : null;
|
|
7
|
-
let cleaned = content.replace(/^\uFEFF/, '');
|
|
8
|
-
cleaned = cleaned.replace(/^```(\w+)?\s*/, '').replace(/```$/, '');
|
|
9
|
-
cleaned = cleaned.replace(/[\u0000-\u0008\u000B-\u000C\u000E-\u001F\u007F-\u009F]/g, '');
|
|
10
|
-
cleaned = cleaned.trim();
|
|
11
|
-
return { lang, cleaned };
|
|
12
|
-
}
|
|
13
|
-
exports.cleanCodeBlock = cleanCodeBlock;
|