spets 0.1.86 → 0.1.87

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.
@@ -0,0 +1,164 @@
1
+ import {
2
+ clearConfigCache,
3
+ getConfigPath,
4
+ loadConfig
5
+ } from "./chunk-VQV22N3Y.js";
6
+
7
+ // src/ui/sections/config.ts
8
+ import { writeFileSync } from "fs";
9
+ import { spawnSync } from "child_process";
10
+ import { select, input, confirm } from "@inquirer/prompts";
11
+ import { stringify as yamlStringify } from "yaml";
12
+ function getEditableFields() {
13
+ return [
14
+ { field: "steps", type: "array", description: "Workflow steps (ordered list)" },
15
+ { field: "output.path", type: "string", description: "Output directory path" },
16
+ { field: "knowledge.enabled", type: "boolean", description: "Enable knowledge saving" },
17
+ { field: "knowledge.inject", type: "boolean", description: "Inject knowledge into prompts" },
18
+ { field: "github.owner", type: "string", description: "GitHub repository owner" },
19
+ { field: "github.repo", type: "string", description: "GitHub repository name" }
20
+ ];
21
+ }
22
+ function renderConfigJSON(cwd = process.cwd()) {
23
+ const config = loadConfig(cwd);
24
+ const response = {
25
+ section: "config",
26
+ data: config,
27
+ editableFields: getEditableFields(),
28
+ actions: ["set", "edit"]
29
+ };
30
+ return JSON.stringify(response, null, 2);
31
+ }
32
+ function setConfigField(field, value, cwd = process.cwd()) {
33
+ try {
34
+ const configPath = getConfigPath(cwd);
35
+ const config = loadConfig(cwd);
36
+ let parsedValue;
37
+ try {
38
+ parsedValue = JSON.parse(value);
39
+ } catch {
40
+ parsedValue = value;
41
+ }
42
+ const parts = field.split(".");
43
+ let current = config;
44
+ for (let i = 0; i < parts.length - 1; i++) {
45
+ const part = parts[i];
46
+ if (!(part in current) || typeof current[part] !== "object") {
47
+ current[part] = {};
48
+ }
49
+ current = current[part];
50
+ }
51
+ current[parts[parts.length - 1]] = parsedValue;
52
+ const yamlContent = yamlStringify(config);
53
+ writeFileSync(configPath, yamlContent);
54
+ clearConfigCache();
55
+ return { success: true, message: `Set ${field} = ${JSON.stringify(parsedValue)}` };
56
+ } catch (error) {
57
+ return { success: false, message: `Failed to set ${field}: ${error.message}` };
58
+ }
59
+ }
60
+ function openConfigInEditor(cwd = process.cwd()) {
61
+ const configPath = getConfigPath(cwd);
62
+ const editor = process.env.EDITOR || process.env.VISUAL || "vi";
63
+ const result = spawnSync(editor, [configPath], {
64
+ stdio: "inherit",
65
+ shell: true
66
+ });
67
+ if (result.status === 0) {
68
+ clearConfigCache();
69
+ return { success: true, message: "Config edited successfully" };
70
+ } else {
71
+ return { success: false, message: `Editor exited with code ${result.status}` };
72
+ }
73
+ }
74
+ async function runConfigInteractive(cwd = process.cwd()) {
75
+ while (true) {
76
+ const config = loadConfig(cwd);
77
+ const action = await select({
78
+ message: "Config Management",
79
+ choices: [
80
+ { value: "view", name: "\u{1F4CB} View current config" },
81
+ { value: "steps", name: "\u{1F4DD} Edit steps" },
82
+ { value: "output", name: "\u{1F4C1} Edit output path" },
83
+ { value: "knowledge", name: "\u{1F9E0} Edit knowledge settings" },
84
+ { value: "github", name: "\u{1F419} Edit GitHub settings" },
85
+ { value: "edit", name: "\u270F\uFE0F Open in editor" },
86
+ { value: "back", name: "\u2190 Back to main menu" }
87
+ ]
88
+ });
89
+ if (action === "back") {
90
+ break;
91
+ }
92
+ if (action === "view") {
93
+ console.log("\nCurrent Config:");
94
+ console.log(JSON.stringify(config, null, 2));
95
+ console.log();
96
+ continue;
97
+ }
98
+ if (action === "edit") {
99
+ const result = openConfigInEditor(cwd);
100
+ console.log(result.message);
101
+ continue;
102
+ }
103
+ if (action === "steps") {
104
+ const currentSteps = config.steps.join(", ");
105
+ const newSteps = await input({
106
+ message: "Enter steps (comma-separated):",
107
+ default: currentSteps
108
+ });
109
+ const stepsArray = newSteps.split(",").map((s) => s.trim()).filter(Boolean);
110
+ const result = setConfigField("steps", JSON.stringify(stepsArray), cwd);
111
+ console.log(result.message);
112
+ continue;
113
+ }
114
+ if (action === "output") {
115
+ const currentPath = config.output?.path || ".spets/outputs";
116
+ const newPath = await input({
117
+ message: "Output directory path:",
118
+ default: currentPath
119
+ });
120
+ const result = setConfigField("output.path", JSON.stringify(newPath), cwd);
121
+ console.log(result.message);
122
+ continue;
123
+ }
124
+ if (action === "knowledge") {
125
+ const enabled = await confirm({
126
+ message: "Enable knowledge saving?",
127
+ default: config.knowledge?.enabled ?? true
128
+ });
129
+ setConfigField("knowledge.enabled", JSON.stringify(enabled), cwd);
130
+ const inject = await confirm({
131
+ message: "Inject knowledge into prompts?",
132
+ default: config.knowledge?.inject ?? true
133
+ });
134
+ const result = setConfigField("knowledge.inject", JSON.stringify(inject), cwd);
135
+ console.log(result.message);
136
+ continue;
137
+ }
138
+ if (action === "github") {
139
+ const owner = await input({
140
+ message: "GitHub owner:",
141
+ default: config.github?.owner || ""
142
+ });
143
+ if (owner) {
144
+ setConfigField("github.owner", JSON.stringify(owner), cwd);
145
+ }
146
+ const repo = await input({
147
+ message: "GitHub repo:",
148
+ default: config.github?.repo || ""
149
+ });
150
+ if (repo) {
151
+ const result = setConfigField("github.repo", JSON.stringify(repo), cwd);
152
+ console.log(result.message);
153
+ }
154
+ continue;
155
+ }
156
+ }
157
+ }
158
+
159
+ export {
160
+ renderConfigJSON,
161
+ setConfigField,
162
+ openConfigInEditor,
163
+ runConfigInteractive
164
+ };