@nyxa/nyx-agent 0.3.3 → 0.3.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/commands/init.js +42 -0
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -6,6 +6,8 @@ import pc from "picocolors";
|
|
|
6
6
|
import { ensureDir, pathExists, readText, writeText } from "../runtime/files.js";
|
|
7
7
|
import { getNyxDir, relativeToProject } from "../runtime/paths.js";
|
|
8
8
|
const DEFAULT_OPENAI_MODEL = "gpt-5.5";
|
|
9
|
+
const GITIGNORE_MARKER = "# NyxAgent runtime artifacts";
|
|
10
|
+
const GITIGNORE_ENTRIES = [".nyxagent/runs/", ".nyxagent/state.json"];
|
|
9
11
|
export async function initCommand(options, projectRoot = process.cwd()) {
|
|
10
12
|
const root = path.resolve(projectRoot);
|
|
11
13
|
const nyxDir = getNyxDir(root);
|
|
@@ -21,6 +23,7 @@ export async function initCommand(options, projectRoot = process.cwd()) {
|
|
|
21
23
|
await ensureDir(nyxDir);
|
|
22
24
|
const templatesDir = getTemplatesDir();
|
|
23
25
|
await copyTemplateTree(templatesDir, nyxDir, Boolean(options.missing));
|
|
26
|
+
await ensureGitignoreEntries(root);
|
|
24
27
|
if (resolved) {
|
|
25
28
|
await writeText(configPath, buildConfigToml(resolved));
|
|
26
29
|
}
|
|
@@ -146,6 +149,45 @@ async function ensureWorkItemsDirectory(root, taskPath) {
|
|
|
146
149
|
throw new Error(`Work item path is not a directory: ${taskPath}`);
|
|
147
150
|
}
|
|
148
151
|
}
|
|
152
|
+
async function ensureGitignoreEntries(root) {
|
|
153
|
+
const gitignorePath = path.join(root, ".gitignore");
|
|
154
|
+
const current = (await pathExists(gitignorePath))
|
|
155
|
+
? await readText(gitignorePath)
|
|
156
|
+
: "";
|
|
157
|
+
const lines = current.split(/\r?\n/);
|
|
158
|
+
const existingEntries = new Set(lines.map((line) => line.trim()));
|
|
159
|
+
const missingEntries = GITIGNORE_ENTRIES.filter((entry) => !existingEntries.has(entry));
|
|
160
|
+
if (missingEntries.length === 0) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const markerIndex = lines.findIndex((line) => line.trim() === GITIGNORE_MARKER);
|
|
164
|
+
let updated;
|
|
165
|
+
if (markerIndex >= 0) {
|
|
166
|
+
const nextLines = [...lines];
|
|
167
|
+
nextLines.splice(markerIndex + 1, 0, ...missingEntries);
|
|
168
|
+
updated = normalizeGitignoreContent(nextLines.join("\n"));
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
const prefix = getGitignoreAppendPrefix(current);
|
|
172
|
+
updated = `${current}${prefix}${GITIGNORE_MARKER}\n${missingEntries.join("\n")}\n`;
|
|
173
|
+
}
|
|
174
|
+
await writeText(gitignorePath, updated);
|
|
175
|
+
}
|
|
176
|
+
function getGitignoreAppendPrefix(current) {
|
|
177
|
+
if (current.length === 0) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
if (current.endsWith("\n\n")) {
|
|
181
|
+
return "";
|
|
182
|
+
}
|
|
183
|
+
if (current.endsWith("\n")) {
|
|
184
|
+
return "\n";
|
|
185
|
+
}
|
|
186
|
+
return "\n\n";
|
|
187
|
+
}
|
|
188
|
+
function normalizeGitignoreContent(value) {
|
|
189
|
+
return `${value.replace(/\n*$/, "")}\n`;
|
|
190
|
+
}
|
|
149
191
|
function buildConfigToml(options) {
|
|
150
192
|
const harness = buildHarnessToml(options.harness);
|
|
151
193
|
const workItems = buildWorkItemsToml(options);
|