@lunora/cli 1.0.0-alpha.3 → 1.0.0-alpha.30
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/__assets__/package-og.svg +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +243 -114
- package/dist/index.d.ts +243 -114
- package/dist/index.mjs +7 -7
- package/dist/packem_chunks/handler.mjs +89 -7
- package/dist/packem_chunks/handler10.mjs +8 -14
- package/dist/packem_chunks/handler11.mjs +19 -189
- package/dist/packem_chunks/handler12.mjs +176 -115
- package/dist/packem_chunks/handler13.mjs +118 -52
- package/dist/packem_chunks/handler14.mjs +50 -43
- package/dist/packem_chunks/handler15.mjs +46 -67
- package/dist/packem_chunks/handler16.mjs +73 -37
- package/dist/packem_chunks/handler17.mjs +38 -100
- package/dist/packem_chunks/handler18.mjs +87 -154
- package/dist/packem_chunks/handler19.mjs +148 -67
- package/dist/packem_chunks/handler2.mjs +2 -2
- package/dist/packem_chunks/handler20.mjs +71 -76
- package/dist/packem_chunks/handler21.mjs +71 -288
- package/dist/packem_chunks/handler3.mjs +1 -1
- package/dist/packem_chunks/handler4.mjs +1 -1
- package/dist/packem_chunks/handler5.mjs +2 -2
- package/dist/packem_chunks/handler6.mjs +2 -2
- package/dist/packem_chunks/handler7.mjs +1 -1
- package/dist/packem_chunks/handler8.mjs +1 -1
- package/dist/packem_chunks/handler9.mjs +311 -12
- package/dist/packem_chunks/planDevCommand.mjs +46 -49
- package/dist/packem_chunks/runCodegenCommand.mjs +2 -2
- package/dist/packem_chunks/runDeployCommand.mjs +105 -15
- package/dist/packem_chunks/runInitCommand.mjs +1980 -77
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +5 -5
- package/dist/packem_chunks/runResetCommand.mjs +4 -4
- package/dist/packem_chunks/runRpcCommand.mjs +1 -1
- package/dist/packem_shared/{COMMANDS-CHw4zOZ9.mjs → COMMANDS-B0ftFD_3.mjs} +47 -21
- package/dist/packem_shared/{command-BDXcJCCJ.mjs → command-D3lB_4Az.mjs} +6 -1
- package/dist/packem_shared/{commands-DIQ3nf0C.mjs → commands-B-gR09Z_.mjs} +124 -22
- package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-B40gPzQo.mjs} +9 -4
- package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +61 -0
- package/dist/packem_shared/{diffSnapshots-RR2ZE8Ya.mjs → diffSnapshots-BeDvvNiF.mjs} +1 -1
- package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
- package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-wUvAN6AL.mjs} +1 -1
- package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
- package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +4 -0
- package/dist/packem_shared/{schemaIrToSnapshot-aBTo7TM5.mjs → schemaIrToSnapshot-DdsljJT-.mjs} +1 -1
- package/dist/packem_shared/storage-BIsph-Vk.mjs +84 -0
- package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +47 -0
- package/package.json +12 -11
- package/skills/lunora-setup-storage/SKILL.md +7 -3
- package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
- package/dist/packem_shared/runAddCommand-3I3JFZUG.mjs +0 -4
- /package/dist/packem_shared/{defaultSpawner-DxI3mebw.mjs → createRecordingSpawner-DxI3mebw.mjs} +0 -0
|
@@ -1,105 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { AGENT_RULES_DIR, detectAgentRules, LUNORA_SKILL_NAMES } from '@lunora/config';
|
|
4
|
-
import { join, relative, dirname } from '@visulima/path';
|
|
5
|
-
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
1
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
2
|
+
import { r as runAddCommand, b as runRegistryViewCommand, a as runBuildIndexCommand } from '../packem_shared/commands-B-gR09Z_.mjs';
|
|
6
3
|
|
|
7
|
-
const resolveBundledSkillsDirectory = (startDirectory = dirname(fileURLToPath(import.meta.url))) => {
|
|
8
|
-
let directory = startDirectory;
|
|
9
|
-
for (let index = 0; index < 6; index += 1) {
|
|
10
|
-
const packageJson = join(directory, "package.json");
|
|
11
|
-
if (existsSync(packageJson)) {
|
|
12
|
-
try {
|
|
13
|
-
const parsed = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
14
|
-
if (parsed.name === "@lunora/cli") {
|
|
15
|
-
const skills = join(directory, "skills");
|
|
16
|
-
return existsSync(skills) ? skills : void 0;
|
|
17
|
-
}
|
|
18
|
-
} catch {
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const parent = dirname(directory);
|
|
22
|
-
if (parent === directory) {
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
directory = parent;
|
|
26
|
-
}
|
|
27
|
-
return void 0;
|
|
28
|
-
};
|
|
29
|
-
const listBundledSkills = (skillsDirectory) => readdirSync(skillsDirectory).filter((name) => {
|
|
30
|
-
const directory = join(skillsDirectory, name);
|
|
31
|
-
return statSync(directory).isDirectory() && existsSync(join(directory, "SKILL.md"));
|
|
32
|
-
});
|
|
33
|
-
const copySkill = (source, destination, overwrite) => {
|
|
34
|
-
mkdirSync(destination, { recursive: true });
|
|
35
|
-
let wrote = false;
|
|
36
|
-
for (const entry of readdirSync(source)) {
|
|
37
|
-
const from = join(source, entry);
|
|
38
|
-
const to = join(destination, entry);
|
|
39
|
-
if (statSync(from).isDirectory()) {
|
|
40
|
-
wrote = copySkill(from, to, overwrite) || wrote;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (existsSync(to) && !overwrite) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
writeFileSync(to, readFileSync(from));
|
|
47
|
-
wrote = true;
|
|
48
|
-
}
|
|
49
|
-
return wrote;
|
|
50
|
-
};
|
|
51
|
-
const runRulesInstall = (options) => {
|
|
52
|
-
const cwd = options.cwd ?? process.cwd();
|
|
53
|
-
const overwrite = options.overwrite === true;
|
|
54
|
-
const skillsDirectory = resolveBundledSkillsDirectory();
|
|
55
|
-
if (skillsDirectory === void 0) {
|
|
56
|
-
options.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?).");
|
|
57
|
-
return { code: 1, installed: [], skipped: [] };
|
|
58
|
-
}
|
|
59
|
-
const installed = [];
|
|
60
|
-
const skipped = [];
|
|
61
|
-
for (const name of listBundledSkills(skillsDirectory)) {
|
|
62
|
-
const destination = join(cwd, AGENT_RULES_DIR, name);
|
|
63
|
-
const wrote = copySkill(join(skillsDirectory, name), destination, overwrite);
|
|
64
|
-
if (wrote) {
|
|
65
|
-
installed.push(name);
|
|
66
|
-
} else {
|
|
67
|
-
skipped.push(name);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const target = relative(cwd, join(cwd, AGENT_RULES_DIR)) || AGENT_RULES_DIR;
|
|
71
|
-
if (installed.length > 0) {
|
|
72
|
-
options.logger.success(`Installed ${String(installed.length)} Lunora skill(s) into ${target}/: ${installed.join(", ")}.`);
|
|
73
|
-
}
|
|
74
|
-
if (skipped.length > 0) {
|
|
75
|
-
options.logger.info(`Skipped ${String(skipped.length)} existing skill(s) (re-run with --overwrite to replace): ${skipped.join(", ")}.`);
|
|
76
|
-
}
|
|
77
|
-
options.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill.");
|
|
78
|
-
return { code: 0, installed, skipped };
|
|
79
|
-
};
|
|
80
|
-
const runRulesCheck = (options) => {
|
|
81
|
-
const cwd = options.cwd ?? process.cwd();
|
|
82
|
-
const status = detectAgentRules(cwd);
|
|
83
|
-
if (status.installed) {
|
|
84
|
-
options.logger.success(`Lunora agent rules are installed (${String(status.present.length)}/${String(LUNORA_SKILL_NAMES.length)} skills).`);
|
|
85
|
-
if (status.missing.length > 0) {
|
|
86
|
-
options.logger.info(`Missing: ${status.missing.join(", ")}. Run \`lunora rules install\` to add them.`);
|
|
87
|
-
}
|
|
88
|
-
return { code: 0, installed: status.present, skipped: [] };
|
|
89
|
-
}
|
|
90
|
-
options.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora.");
|
|
91
|
-
return { code: options.strict === true ? 1 : 0, installed: status.present, skipped: [] };
|
|
92
|
-
};
|
|
93
4
|
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
94
|
-
const subcommand = argument[0]
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
5
|
+
const subcommand = argument[0];
|
|
6
|
+
const names = argument.slice(1);
|
|
7
|
+
if (subcommand === "add") {
|
|
8
|
+
return runAddCommand({
|
|
9
|
+
allowUnsafeSource: options.allowUnsafeSource === true,
|
|
10
|
+
cwd,
|
|
11
|
+
diff: options.diff === true,
|
|
12
|
+
dryRun: options.dryRun === true,
|
|
13
|
+
from: options.from,
|
|
14
|
+
json: options.json === true,
|
|
15
|
+
logger,
|
|
16
|
+
names,
|
|
17
|
+
overwrite: options.overwrite === true,
|
|
18
|
+
ref: options.ref,
|
|
19
|
+
source: options.source,
|
|
20
|
+
yes: options.yes === true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (subcommand === "list") {
|
|
24
|
+
return runAddCommand({ cwd, from: options.from, json: options.json === true, list: true, logger, names: [], ref: options.ref, source: options.source });
|
|
25
|
+
}
|
|
26
|
+
if (subcommand === "view") {
|
|
27
|
+
return runRegistryViewCommand({
|
|
28
|
+
allowUnsafeSource: options.allowUnsafeSource === true,
|
|
29
|
+
from: options.from,
|
|
30
|
+
logger,
|
|
31
|
+
names,
|
|
32
|
+
ref: options.ref,
|
|
33
|
+
source: options.source
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (subcommand === "build") {
|
|
37
|
+
return runBuildIndexCommand({ check: options.check === true, from: options.from, logger, out: options.out });
|
|
38
|
+
}
|
|
39
|
+
logger.error("registry: unknown subcommand. Usage: lunora registry <add|list|view|build> [names…]");
|
|
102
40
|
return { code: 1 };
|
|
103
41
|
});
|
|
104
42
|
|
|
105
|
-
export { execute
|
|
43
|
+
export { execute };
|
|
@@ -1,172 +1,105 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { seedPlan } from '@lunora/seed';
|
|
7
|
-
import { join } from '@visulima/path';
|
|
8
|
-
import { Project } from 'ts-morph';
|
|
9
|
-
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
10
|
-
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
11
|
-
import { runImportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
12
|
-
import { runResetCommand } from './runResetCommand.mjs';
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { AGENT_RULES_DIR, detectAgentRules, LUNORA_SKILL_NAMES } from '@lunora/config';
|
|
4
|
+
import { join, relative, dirname } from '@visulima/path';
|
|
5
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
13
6
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
const seedFailure = (code) => {
|
|
35
|
-
return { code, conflicts: 0, generated: 0, inserted: 0, ndjson: "" };
|
|
36
|
-
};
|
|
37
|
-
const guardSeedTargets = (options, schemaPath) => {
|
|
38
|
-
if (!existsSync(schemaPath)) {
|
|
39
|
-
options.logger.error(`schema not found: ${schemaPath} — run \`vis generate lunora-table --name=<name>\` to create one`);
|
|
40
|
-
return seedFailure(1);
|
|
41
|
-
}
|
|
42
|
-
if (options.reset === true && (options.prod === true || !isLocalUrl(options.url))) {
|
|
43
|
-
options.logger.error("--reset only clears local .wrangler/state and cannot be combined with --prod or a remote --url");
|
|
44
|
-
return seedFailure(1);
|
|
7
|
+
const resolveBundledSkillsDirectory = (startDirectory = dirname(fileURLToPath(import.meta.url))) => {
|
|
8
|
+
let directory = startDirectory;
|
|
9
|
+
for (let index = 0; index < 6; index += 1) {
|
|
10
|
+
const packageJson = join(directory, "package.json");
|
|
11
|
+
if (existsSync(packageJson)) {
|
|
12
|
+
try {
|
|
13
|
+
const parsed = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
14
|
+
if (parsed.name === "@lunora/cli") {
|
|
15
|
+
const skills = join(directory, "skills");
|
|
16
|
+
return existsSync(skills) ? skills : void 0;
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const parent = dirname(directory);
|
|
22
|
+
if (parent === directory) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
directory = parent;
|
|
45
26
|
}
|
|
46
27
|
return void 0;
|
|
47
28
|
};
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
const conflicts = result.body?.conflicts ?? 0;
|
|
63
|
-
if (conflicts > 0) {
|
|
64
|
-
options.logger.warn(
|
|
65
|
-
`${String(conflicts)} row(s) skipped — their _id already exists. Seeding is deterministic; re-run with --reset to wipe local state first, or a different --seed for fresh ids.`
|
|
66
|
-
);
|
|
29
|
+
const listBundledSkills = (skillsDirectory) => readdirSync(skillsDirectory).filter((name) => {
|
|
30
|
+
const directory = join(skillsDirectory, name);
|
|
31
|
+
return statSync(directory).isDirectory() && existsSync(join(directory, "SKILL.md"));
|
|
32
|
+
});
|
|
33
|
+
const copySkill = (source, destination, overwrite) => {
|
|
34
|
+
mkdirSync(destination, { recursive: true });
|
|
35
|
+
let wrote = false;
|
|
36
|
+
for (const entry of readdirSync(source)) {
|
|
37
|
+
const from = join(source, entry);
|
|
38
|
+
const to = join(destination, entry);
|
|
39
|
+
if (statSync(from).isDirectory()) {
|
|
40
|
+
wrote = copySkill(from, to, overwrite) || wrote;
|
|
41
|
+
continue;
|
|
67
42
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
const validateSeedTable = (options, ir) => {
|
|
75
|
-
if (options.table === void 0 || ir.tables.some((table) => table.name === options.table)) {
|
|
76
|
-
return void 0;
|
|
43
|
+
if (existsSync(to) && !overwrite) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
writeFileSync(to, readFileSync(from));
|
|
47
|
+
wrote = true;
|
|
77
48
|
}
|
|
78
|
-
|
|
79
|
-
options.logger.error(`unknown table "${options.table}" — schema defines: ${available || "(no tables)"}`);
|
|
80
|
-
return seedFailure(1);
|
|
49
|
+
return wrote;
|
|
81
50
|
};
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
51
|
+
const runRulesInstall = (options) => {
|
|
52
|
+
const cwd = options.cwd ?? process.cwd();
|
|
53
|
+
const overwrite = options.overwrite === true;
|
|
54
|
+
const skillsDirectory = resolveBundledSkillsDirectory();
|
|
55
|
+
if (skillsDirectory === void 0) {
|
|
56
|
+
options.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?).");
|
|
57
|
+
return { code: 1, installed: [], skipped: [] };
|
|
58
|
+
}
|
|
59
|
+
const installed = [];
|
|
60
|
+
const skipped = [];
|
|
61
|
+
for (const name of listBundledSkills(skillsDirectory)) {
|
|
62
|
+
const destination = join(cwd, AGENT_RULES_DIR, name);
|
|
63
|
+
const wrote = copySkill(join(skillsDirectory, name), destination, overwrite);
|
|
64
|
+
if (wrote) {
|
|
65
|
+
installed.push(name);
|
|
66
|
+
} else {
|
|
67
|
+
skipped.push(name);
|
|
68
|
+
}
|
|
86
69
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
const target = relative(cwd, join(cwd, AGENT_RULES_DIR)) || AGENT_RULES_DIR;
|
|
71
|
+
if (installed.length > 0) {
|
|
72
|
+
options.logger.success(`Installed ${String(installed.length)} Lunora skill(s) into ${target}/: ${installed.join(", ")}.`);
|
|
90
73
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
`This will insert ${String(generated)} generated row(s) into ${options.url ?? "the production worker"}. Continue? [y/N] `
|
|
94
|
-
);
|
|
95
|
-
if (!confirmed) {
|
|
96
|
-
options.logger.info("seed: aborted");
|
|
97
|
-
return seedFailure(1);
|
|
74
|
+
if (skipped.length > 0) {
|
|
75
|
+
options.logger.info(`Skipped ${String(skipped.length)} existing skill(s) (re-run with --overwrite to replace): ${skipped.join(", ")}.`);
|
|
98
76
|
}
|
|
99
|
-
|
|
77
|
+
options.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill.");
|
|
78
|
+
return { code: 0, installed, skipped };
|
|
100
79
|
};
|
|
101
|
-
const
|
|
80
|
+
const runRulesCheck = (options) => {
|
|
102
81
|
const cwd = options.cwd ?? process.cwd();
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const project = new Project({ skipAddingFilesFromTsConfig: true });
|
|
109
|
-
const ir = discoverSchema(project, schemaPath);
|
|
110
|
-
const unknownTable = validateSeedTable(options, ir);
|
|
111
|
-
if (unknownTable !== void 0) {
|
|
112
|
-
return unknownTable;
|
|
113
|
-
}
|
|
114
|
-
const schema = schemaFromIr(ir);
|
|
115
|
-
const plan = seedPlan(schema, {
|
|
116
|
-
defaultCount: options.count ?? 10,
|
|
117
|
-
only: options.table === void 0 ? void 0 : [options.table],
|
|
118
|
-
seed: options.seed ?? 0
|
|
119
|
-
});
|
|
120
|
-
const lines = [];
|
|
121
|
-
for (const { rows, table } of plan) {
|
|
122
|
-
for (const row of rows) {
|
|
123
|
-
lines.push(JSON.stringify({ doc: row, table }, ndjsonReplacer));
|
|
82
|
+
const status = detectAgentRules(cwd);
|
|
83
|
+
if (status.installed) {
|
|
84
|
+
options.logger.success(`Lunora agent rules are installed (${String(status.present.length)}/${String(LUNORA_SKILL_NAMES.length)} skills).`);
|
|
85
|
+
if (status.missing.length > 0) {
|
|
86
|
+
options.logger.info(`Missing: ${status.missing.join(", ")}. Run \`lunora rules install\` to add them.`);
|
|
124
87
|
}
|
|
88
|
+
return { code: 0, installed: status.present, skipped: [] };
|
|
125
89
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
options.logger.info(`generated ${String(generated)} row(s) across ${String(plan.length)} table(s) — dry run, nothing inserted`);
|
|
134
|
-
return { code: 0, conflicts: 0, generated, inserted: 0, ndjson };
|
|
135
|
-
}
|
|
136
|
-
if (options.reset === true) {
|
|
137
|
-
const reset = await runResetCommand({ cwd, logger: options.logger, yes: true });
|
|
138
|
-
if (reset.code !== 0) {
|
|
139
|
-
return { code: reset.code, conflicts: 0, generated, inserted: 0, ndjson };
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (generated === 0) {
|
|
143
|
-
options.logger.warn("no rows generated — nothing to insert");
|
|
144
|
-
return { code: 0, conflicts: 0, generated: 0, inserted: 0, ndjson };
|
|
90
|
+
options.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora.");
|
|
91
|
+
return { code: options.strict === true ? 1 : 0, installed: status.present, skipped: [] };
|
|
92
|
+
};
|
|
93
|
+
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
94
|
+
const subcommand = argument[0] ?? "check";
|
|
95
|
+
if (subcommand === "install") {
|
|
96
|
+
return runRulesInstall({ cwd, logger, overwrite: options.overwrite === true });
|
|
145
97
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return aborted;
|
|
98
|
+
if (subcommand === "check") {
|
|
99
|
+
return runRulesCheck({ cwd, logger, strict: options.strict === true });
|
|
149
100
|
}
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
const execute = defineHandler(async ({ cwd, logger, options }) => {
|
|
153
|
-
const result = await runSeedCommand({
|
|
154
|
-
batchSize: options.batchSize,
|
|
155
|
-
count: options.count,
|
|
156
|
-
cwd,
|
|
157
|
-
dryRun: options.dryRun === true,
|
|
158
|
-
logger,
|
|
159
|
-
prod: options.prod === true,
|
|
160
|
-
reset: options.reset === true,
|
|
161
|
-
seed: options.seed,
|
|
162
|
-
table: options.table,
|
|
163
|
-
token: options.token,
|
|
164
|
-
// Resolve the link here (only under --prod) so seed's own remote/confirm
|
|
165
|
-
// logic and the downstream import both see the same effective target.
|
|
166
|
-
url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url }),
|
|
167
|
-
yes: options.yes === true
|
|
168
|
-
});
|
|
169
|
-
return { code: result.code };
|
|
101
|
+
logger.error("rules: unknown subcommand. Usage: lunora rules <install|check>");
|
|
102
|
+
return { code: 1 };
|
|
170
103
|
});
|
|
171
104
|
|
|
172
|
-
export { execute,
|
|
105
|
+
export { execute, resolveBundledSkillsDirectory, runRulesCheck, runRulesInstall };
|
|
@@ -1,89 +1,170 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { discoverSchema, schemaFromIr } from '@lunora/codegen';
|
|
5
|
+
import { seedPlan } from '@lunora/seed';
|
|
6
|
+
import { join } from '@visulima/path';
|
|
7
|
+
import { Project } from 'ts-morph';
|
|
8
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
9
|
+
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
10
|
+
import { b as tuiConfirm } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
|
|
11
|
+
import { runImportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
12
|
+
import { runResetCommand } from './runResetCommand.mjs';
|
|
10
13
|
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
14
|
+
const isLocalUrl = (url) => {
|
|
15
|
+
if (url === void 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const { hostname } = new URL(url);
|
|
20
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
14
23
|
}
|
|
15
|
-
const result = await spawner({ args: ["exec", "tsc", "--noEmit", "-p", "tsconfig.json"], command: "pnpm", cwd });
|
|
16
|
-
return result.code === 0 ? {} : { error: `type errors: tsc --noEmit exited ${String(result.code)}` };
|
|
17
24
|
};
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const ndjsonReplacer = (_key, value) => {
|
|
26
|
+
if (typeof value === "bigint") {
|
|
27
|
+
return Number(value);
|
|
28
|
+
}
|
|
29
|
+
if (value instanceof ArrayBuffer) {
|
|
30
|
+
return [...new Uint8Array(value)];
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
const seedFailure = (code) => {
|
|
35
|
+
return { code, conflicts: 0, generated: 0, inserted: 0, ndjson: "" };
|
|
36
|
+
};
|
|
37
|
+
const guardSeedTargets = (options, schemaPath) => {
|
|
38
|
+
if (!existsSync(schemaPath)) {
|
|
39
|
+
options.logger.error(`schema not found: ${schemaPath} — run \`vis generate lunora-table --name=<name>\` to create one`);
|
|
40
|
+
return seedFailure(1);
|
|
41
|
+
}
|
|
42
|
+
if (options.reset === true && (options.prod === true || !isLocalUrl(options.url))) {
|
|
43
|
+
options.logger.error("--reset only clears local .wrangler/state and cannot be combined with --prod or a remote --url");
|
|
44
|
+
return seedFailure(1);
|
|
28
45
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
return void 0;
|
|
47
|
+
};
|
|
48
|
+
const insertSeedRows = async (ndjson, generated, cwd, options) => {
|
|
49
|
+
const scratchDirectory = await mkdtemp(join(tmpdir(), "lunora-seed-"));
|
|
50
|
+
const temporaryFile = join(scratchDirectory, "rows.ndjson");
|
|
51
|
+
await writeFile(temporaryFile, ndjson, "utf8");
|
|
52
|
+
try {
|
|
53
|
+
const result = await runImportCommand({
|
|
54
|
+
batchSize: options.batchSize,
|
|
55
|
+
fetchImpl: options.fetchImpl,
|
|
56
|
+
file: temporaryFile,
|
|
57
|
+
logger: options.logger,
|
|
58
|
+
prod: options.prod,
|
|
59
|
+
token: options.token,
|
|
60
|
+
url: options.url
|
|
61
|
+
});
|
|
62
|
+
const conflicts = result.body?.conflicts ?? 0;
|
|
63
|
+
if (conflicts > 0) {
|
|
64
|
+
options.logger.warn(
|
|
65
|
+
`${String(conflicts)} row(s) skipped — their _id already exists. Seeding is deterministic; re-run with --reset to wipe local state first, or a different --seed for fresh ids.`
|
|
66
|
+
);
|
|
33
67
|
}
|
|
34
|
-
return { code:
|
|
68
|
+
return { code: result.code, conflicts, generated, inserted: result.inserted, ndjson };
|
|
69
|
+
} finally {
|
|
70
|
+
await rm(scratchDirectory, { force: true, recursive: true }).catch(() => {
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const validateSeedTable = (options, ir) => {
|
|
75
|
+
if (options.table === void 0 || ir.tables.some((table) => table.name === options.table)) {
|
|
76
|
+
return void 0;
|
|
35
77
|
}
|
|
36
|
-
|
|
37
|
-
|
|
78
|
+
const available = ir.tables.map((table) => table.name).join(", ");
|
|
79
|
+
options.logger.error(`unknown table "${options.table}" — schema defines: ${available || "(no tables)"}`);
|
|
80
|
+
return seedFailure(1);
|
|
38
81
|
};
|
|
39
|
-
const
|
|
82
|
+
const confirmRemoteSeedTarget = async (options, generated) => {
|
|
83
|
+
const targetsRemote = options.prod === true || !isLocalUrl(options.url);
|
|
84
|
+
if (!targetsRemote || options.yes === true) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
if (!process.stdin.isTTY && options.confirm === void 0) {
|
|
88
|
+
options.logger.error("seed: refusing to insert into a non-local target without confirmation — re-run with --yes");
|
|
89
|
+
return seedFailure(1);
|
|
90
|
+
}
|
|
91
|
+
const confirmer = options.confirm ?? tuiConfirm;
|
|
92
|
+
const confirmed = await confirmer(`This will insert ${String(generated)} generated row(s) into ${options.url ?? "the production worker"}. Continue?`);
|
|
93
|
+
if (!confirmed) {
|
|
94
|
+
options.logger.info("seed: aborted");
|
|
95
|
+
return seedFailure(1);
|
|
96
|
+
}
|
|
97
|
+
return void 0;
|
|
98
|
+
};
|
|
99
|
+
const runSeedCommand = async (options) => {
|
|
40
100
|
const cwd = options.cwd ?? process.cwd();
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
101
|
+
const schemaPath = join(cwd, "lunora", "schema.ts");
|
|
102
|
+
const guard = guardSeedTargets(options, schemaPath);
|
|
103
|
+
if (guard !== void 0) {
|
|
104
|
+
return guard;
|
|
105
|
+
}
|
|
106
|
+
const project = new Project({ skipAddingFilesFromTsConfig: true });
|
|
107
|
+
const ir = discoverSchema(project, schemaPath);
|
|
108
|
+
const unknownTable = validateSeedTable(options, ir);
|
|
109
|
+
if (unknownTable !== void 0) {
|
|
110
|
+
return unknownTable;
|
|
111
|
+
}
|
|
112
|
+
const schema = schemaFromIr(ir);
|
|
113
|
+
const plan = seedPlan(schema, {
|
|
114
|
+
defaultCount: options.count ?? 10,
|
|
115
|
+
only: options.table === void 0 ? void 0 : [options.table],
|
|
116
|
+
seed: options.seed ?? 0
|
|
117
|
+
});
|
|
118
|
+
const lines = [];
|
|
119
|
+
for (const { rows, table } of plan) {
|
|
120
|
+
for (const row of rows) {
|
|
121
|
+
lines.push(JSON.stringify({ doc: row, table }, ndjsonReplacer));
|
|
55
122
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (options.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
errors.push(typecheck.error);
|
|
123
|
+
}
|
|
124
|
+
const ndjson = lines.length > 0 ? `${lines.join("\n")}
|
|
125
|
+
` : "";
|
|
126
|
+
const generated = lines.length;
|
|
127
|
+
if (options.dryRun === true) {
|
|
128
|
+
if (ndjson.length > 0) {
|
|
129
|
+
process.stdout.write(ndjson);
|
|
64
130
|
}
|
|
65
|
-
|
|
66
|
-
|
|
131
|
+
options.logger.info(`generated ${String(generated)} row(s) across ${String(plan.length)} table(s) — dry run, nothing inserted`);
|
|
132
|
+
return { code: 0, conflicts: 0, generated, inserted: 0, ndjson };
|
|
133
|
+
}
|
|
134
|
+
if (options.reset === true) {
|
|
135
|
+
const reset = await runResetCommand({ cwd, logger: options.logger, yes: true });
|
|
136
|
+
if (reset.code !== 0) {
|
|
137
|
+
return { code: reset.code, conflicts: 0, generated, inserted: 0, ndjson };
|
|
67
138
|
}
|
|
68
139
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
140
|
+
if (generated === 0) {
|
|
141
|
+
options.logger.warn("no rows generated — nothing to insert");
|
|
142
|
+
return { code: 0, conflicts: 0, generated: 0, inserted: 0, ndjson };
|
|
143
|
+
}
|
|
144
|
+
const aborted = await confirmRemoteSeedTarget(options, generated);
|
|
145
|
+
if (aborted !== void 0) {
|
|
146
|
+
return aborted;
|
|
72
147
|
}
|
|
73
|
-
return
|
|
148
|
+
return insertSeedRows(ndjson, generated, cwd, options);
|
|
74
149
|
};
|
|
75
150
|
const execute = defineHandler(async ({ cwd, logger, options }) => {
|
|
76
|
-
const result = await
|
|
77
|
-
|
|
78
|
-
|
|
151
|
+
const result = await runSeedCommand({
|
|
152
|
+
batchSize: options.batchSize,
|
|
153
|
+
count: options.count,
|
|
79
154
|
cwd,
|
|
80
|
-
|
|
155
|
+
dryRun: options.dryRun === true,
|
|
81
156
|
logger,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
157
|
+
prod: options.prod === true,
|
|
158
|
+
reset: options.reset === true,
|
|
159
|
+
seed: options.seed,
|
|
160
|
+
table: options.table,
|
|
161
|
+
token: options.token,
|
|
162
|
+
// Resolve the link here (only under --prod) so seed's own remote/confirm
|
|
163
|
+
// logic and the downstream import both see the same effective target.
|
|
164
|
+
url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url }),
|
|
165
|
+
yes: options.yes === true
|
|
85
166
|
});
|
|
86
167
|
return { code: result.code };
|
|
87
168
|
});
|
|
88
169
|
|
|
89
|
-
export { execute,
|
|
170
|
+
export { execute, runSeedCommand };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mkdtempSync, rmSync, existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join, relative } from 'node:path';
|
|
4
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
5
|
-
import { defaultSpawner } from '../packem_shared/
|
|
4
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
5
|
+
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
6
6
|
|
|
7
7
|
const walk = (root) => {
|
|
8
8
|
const entries = [];
|