@neural-node-labs/xcoder-sdlc 0.0.0-stage → 1.4.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Neural Node Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ <!-- xcoder:version 6 | xcoder:task task-0d242c | xcoder:updated 2026-11-19T14:15:55.863Z | xcoder:subtask code-st-8d2337 -->
2
+ # @neural-node-labs/xcoder-sdlc — the `xcoder` SDLC agent and `ba-v1`
3
+
4
+ This package ships two binaries: `xcoder`, the full SDLC pipeline (design → build → test → secure review), and `ba-v1`, a one-shot business-analyst that turns raw business input into a structured requirements document.
5
+
6
+ ## Install
7
+
8
+ ```
9
+ npm install -g @neural-node-labs/xcoder-sdlc
10
+ ```
11
+
12
+ Node >= 20 is required.
13
+
14
+ ## Quick start
15
+
16
+ ```
17
+ xcoder index
18
+ xcoder status incomplete
19
+ xcoder resume
20
+ ba-v1 requirements.md --output docs/REQUIREMENTS.md
21
+ ```
22
+
23
+ ## CLI reference
24
+
25
+ ### `xcoder` (root)
26
+
27
+ | Flag | Meaning |
28
+ |---|---|
29
+ | `--config <settings>` | Save LLM/env settings to `~/.xcoder/config.json`; `--config show` prints them. |
30
+ | `-w, --workspace <dir>` | Workspace root (default: current working directory). |
31
+ | `--debug-protocol-error` | Enable protocol-error diagnostic logging (also `PROTOCOL_ERROR_LOG`). |
32
+ | `--debug-tools [path]` | Enable tool-error logging to `tools.log` (also `DEBUG_TOOLS`). |
33
+ | `--max-healing <n>` | Cap on self-healing attempts. |
34
+ | `--budget <usd>` | Spend budget for the run. |
35
+ | `--json` | Machine-readable output. |
36
+ | `--no-architect` | Skip the architect stage. |
37
+ | `--reindex` | Force a workspace re-index before running. |
38
+
39
+ ### Task and workspace commands
40
+
41
+ | Command | Meaning | Notable flags |
42
+ |---|---|---|
43
+ | `xcoder index` | Build or rebuild the workspace index. | — |
44
+ | `xcoder status [filterOrId]` | List task runs or show one run's DAG. | — |
45
+ | `xcoder resume [taskId]` | Continue an escalated/halted task in place. | `-c, --concurrency <n>`, `--model <name>`, `--spinner <style>`, `--lesson-learned`, `--no-lesson-learned`, `--resume [taskId]`, `--task <taskId>` |
46
+ | `xcoder incomplete` | List resumable escalated/halted tasks. | — |
47
+ | `xcoder bench` | Run the benchmark harness. | `--fixtures <dir>`, `--out <file>`, `--compare <file>`, `-c, --concurrency <n>`, `--model <name>`, `--keep-workspaces`, `--spinner <style>` |
48
+ | `xcoder browse [url]` | Drive a browser. | `-s, --step <spec>`, `--headed`, `--timeout <ms>`, `--url <url>`, `--credential-ref <envVarName>` |
49
+ | `xcoder observe` | Stream live Thought/Action/Observation events. | — |
50
+ | `xcoder release` | Build a release installer. | `--platform <platform>`, `--arch <arch>`, `--output <dir>`, `--increment <level>` |
51
+
52
+ ### `xcoder backlog`
53
+
54
+ `xcoder backlog add <title>` (`--description`, `--priority`) · `xcoder backlog list` (`--status`) · `xcoder backlog start <id>` · `xcoder backlog continue <id>` · `xcoder backlog done <id>` · `xcoder backlog status <id>` · `xcoder backlog pick` (`--model`). `start` and `continue` accept `-c, --concurrency <n>`, `--model <name>`, `--lesson-learned`, `--no-lesson-learned`.
55
+
56
+ ### `xcoder sprint`
57
+
58
+ `xcoder sprint start` (`--max-items <n>`, `-c, --concurrency <n>`, `--model <name>`, `--dry-run`, `--force`, `--lesson-learned`, `--no-lesson-learned`) · `xcoder sprint status` · `xcoder sprint retro` · `xcoder sprint abort`.
59
+
60
+ ### Advanced flags
61
+
62
+ `-task, --task <text>`, `--wbc <path>`, `--code <path>`, `--design <text-or-path>`, `--defect <text>` feed the task and defect entry points. Secrets are never passed inline: `--credential-ref` names an environment variable.
63
+
64
+ ### `ba-v1 <input>`
65
+
66
+ The installed program name is `ba-v1` (there is no `ba` alias). `<input>` is a `.md`/`.txt` file, a directory of them, or a bare requirement string.
67
+
68
+ | Flag | Meaning |
69
+ |---|---|
70
+ | `--model <name>` | Override the LLM model (default `$XCODER_MODEL` or `claude-sonnet-5`). |
71
+ | `--output <file>` | Output path; when omitted the document is printed to stdout. |
72
+ | `--workspace <dir>` | Workspace root (default: current working directory). |
73
+ | `--spinner <style>` | Spinner style (default `clack`). |
74
+
75
+ ### Delegated commands
76
+
77
+ `test`, `swarm`, `task` and `license` are registered into `xcoder` by `@neural-node-labs/xcoder-dna`; see the [@neural-node-labs/xcoder-dna README](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/xcoder-dna) for their flags.
78
+
79
+ `jarvis` is registered here as a delegation: `xcoder jarvis [args...]` runs the real jarvis binary and forwards every argument unchanged, so `xcoder jarvis --chat` starts jarvis's multi-turn session and `xcoder jarvis --help` prints jarvis's own usage. Every flag belongs to jarvis, so none is re-specified here. See [DELEGATION.md](https://github.com/Neural-Node-Labs/xcoder-origin/blob/main/docs/DELEGATION.md).
80
+
81
+ ## Exit codes
82
+
83
+ ### `xcoder`
84
+
85
+ | Code | Meaning |
86
+ |---|---|
87
+ | `0` | The task run completed. |
88
+ | `1` | Local failure: item/task not found, invalid flag value, or an unexpected error. |
89
+ | `2` | The task run status is `escalated`, or a benchmark reported an `error`/`escalated` result. |
90
+ | `3` | The task run status is `halted`. |
91
+ | `4` | The command requires an active license (`LICENSE_REQUIRED_EXIT_CODE`). |
92
+
93
+ ### `ba-v1`
94
+
95
+ | Code | Meaning |
96
+ |---|---|
97
+ | `0` | The requirements document was generated (and, when `--output` was given, written). |
98
+ | `1` | Generation failed, or an unexpected error. |
99
+
100
+ ## Environment variables
101
+
102
+ | Variable | Effect |
103
+ |---|---|
104
+ | `PROTOCOL_ERROR_LOG` | Enable protocol-error diagnostic logging (same as `--debug-protocol-error`). |
105
+ | `DEBUG_TOOLS` | Enable tool-error logging; the value is the log path. |
106
+ | `XCODER_LESSON_LEARNED` | Enable lesson-learned (same as `--lesson-learned`). |
107
+ | `XCODER_MODEL` | Default model for `ba-v1` when `--model` is omitted. |
108
+ | `NO_COLOR` | When present, colour output is disabled. |
109
+
110
+ ## Dependency direction
111
+
112
+ `@neural-node-labs/xcoder-sdlc` depends on @neural-node-labs/xcoder-dna only, and registers `test`, `swarm`, `task` and `license` from it. It never imports another agent package (`xcoder-qa-agent`, `xcoder-litebro`).
113
+
114
+ ## Documentation contract
115
+
116
+ This README ships to npm (`files` includes it), so it is gated like code by `packages/sdlc-agent/src/doc-readme.test.ts`. Because the package ships two bins, the test parses both `src/sdlc-cli.ts` and `src/ba-cli.ts` at run time and fails when either CLI declares a flag the README omits, when the README documents a flag neither declares, or when a locally declared `xcoder` subcommand goes undocumented. It also pins the manifest bins (`xcoder`, `ba-v1`) and the required section order. Run it in isolation with:
117
+
118
+ ```
119
+ npx vitest run packages/sdlc-agent/src/doc-readme.test.ts
120
+ ```
121
+
122
+ ## Related packages
123
+
124
+ - [@neural-node-labs/xcoder-dna](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/xcoder-dna) — shared runtime and the commands this CLI delegates.
125
+ - [xcoder-qa-agent](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/qa-agent) — the `bugfinder` QA agent.
126
+ - [xcoder-litebro](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/litebro) — the tool-less planner/broker.
127
+ - [USAGE.md](https://github.com/Neural-Node-Labs/xcoder-origin/blob/main/docs/USAGE.md) — full workspace CLI reference.
128
+ - [SDLC_ORCHESTRATOR_REFERENCE.md](https://github.com/Neural-Node-Labs/xcoder-origin/blob/main/docs/SDLC_ORCHESTRATOR_REFERENCE.md) — process, flow and recovery limits.
129
+ - [other-clis.md](https://github.com/Neural-Node-Labs/xcoder-origin/blob/main/docs/other-clis.md) — per-binary synopsis for `ba` and friends.
130
+
131
+ ## License
132
+
133
+ see [LICENSE](./LICENSE) for details.
2
134
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "dotenv/config";
package/dist/ba-cli.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ // xcoder:version 4 | xcoder:task task-46e4c0 | xcoder:updated 2026-10-25T16:36:55.041Z | xcoder:subtask code-st-1329b0
3
+ import "dotenv/config";
4
+ import { Command } from "commander";
5
+ import path from "node:path";
6
+ import { runBaGeneration } from "./ba-runner.js";
7
+ import { maybePrintBanner } from "xcoder-dna";
8
+ import { log } from "xcoder-dna";
9
+ import { setSpinnerStyle } from "xcoder-dna";
10
+ import { XCODER_VERSION } from "xcoder-dna";
11
+ const program = new Command();
12
+ program
13
+ .name("ba")
14
+ .description("Xcoder SDLC Business Analyst — generate structured technical requirements from raw business input.")
15
+ .version(XCODER_VERSION)
16
+ .argument("<input>", "A .md/.txt file, a directory of .md/.txt files, or a bare requirement string")
17
+ .option("--model <name>", "override the LLM model (default: $XCODER_MODEL or claude-sonnet-5)")
18
+ .option("--output <file>", "output path for the generated requirements document; if omitted, prints to stdout")
19
+ .option("--workspace <dir>", "workspace root (default: current working directory)", process.cwd())
20
+ .option("--spinner <style>", "spinner style for the thinking indicator (default: \"clack\")", "clack")
21
+ .action(async (input, opts) => {
22
+ const workspaceRoot = path.resolve(opts.workspace);
23
+ setSpinnerStyle(opts.spinner);
24
+ const result = await runBaGeneration({
25
+ workspaceRoot,
26
+ baInputPath: input,
27
+ outputPath: opts.output,
28
+ model: opts.model,
29
+ spinnerStyle: opts.spinner,
30
+ });
31
+ if (result.ok && result.backlogId) {
32
+ log.ok(`Backlog item ${result.backlogId} created${result.backlogPath ? ` → ${result.backlogPath}` : ""}`);
33
+ }
34
+ if (!result.ok) {
35
+ process.exitCode = 1;
36
+ }
37
+ });
38
+ maybePrintBanner(process.argv);
39
+ program.parseAsync(process.argv).catch((e) => {
40
+ log.fail(e.stack ?? String(e));
41
+ process.exitCode = 1;
42
+ });
@@ -0,0 +1,29 @@
1
+ export interface BaRunnerOptions {
2
+ workspaceRoot: string;
3
+ baInputPath: string;
4
+ outputPath?: string;
5
+ model?: string;
6
+ spinnerStyle?: string;
7
+ }
8
+ export interface BaRunnerResult {
9
+ ok: boolean;
10
+ outputPath?: string;
11
+ backlogPath?: string;
12
+ backlogId?: string;
13
+ outputContent?: string;
14
+ error?: string;
15
+ }
16
+ /**
17
+ * Runs a standalone one-step Business Analyst Sub Agent to generate
18
+ * technical requirements from a raw business requirements input.
19
+ *
20
+ * Handles file, directory, and title-only inputs via resolveBaInput().
21
+ * Creates a backlog item (BL-###) before running the BA SubAgent so every
22
+ * invocation leaves a traceable record. On success, persists the generated
23
+ * document to .xcoder/backlog/<BL-id>.md and updates the item's description.
24
+ * On LLM failure, writes a placeholder document and exits non-zero.
25
+ *
26
+ * Invoked directly from the --ba CLI flag. Bypasses the Master Orchestrator
27
+ * DAG entirely — this is a single-step transform, not a pipeline.
28
+ */
29
+ export declare function runBaGeneration(opts: BaRunnerOptions): Promise<BaRunnerResult>;
@@ -0,0 +1,294 @@
1
+ // xcoder:version 2 | xcoder:task task-c49600 | xcoder:updated 2026-08-13T13:51:54.106Z | xcoder:subtask code-st-6d79ef
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { shortId } from "xcoder-dna";
5
+ import { log } from "xcoder-dna";
6
+ import { getOutputPaths } from "xcoder-dna";
7
+ import { SubAgent } from "xcoder-dna";
8
+ import { createLlmClient } from "xcoder-dna";
9
+ import { BA_REQUIREMENTS_DIRECTIVE } from "xcoder-dna";
10
+ import { addBacklogItem, updateBacklogItem } from "xcoder-dna";
11
+ import { createXcoderPaths } from "xcoder-dna";
12
+ /**
13
+ * Resolve the baInputPath into one of three modes — file, directory, or title.
14
+ * - file: path exists, is a file, read its content.
15
+ * - directory: path exists, concatenate all .md/.txt entries (flat, non-recursive).
16
+ * - title: path is neither a file nor a directory — treat as a raw feature title.
17
+ *
18
+ * Throws on: empty directory, unreadable file, empty file.
19
+ */
20
+ function resolveBaInput(workspaceRoot, baInputPath) {
21
+ const resolved = path.resolve(workspaceRoot, baInputPath);
22
+ let stat;
23
+ try {
24
+ stat = fs.statSync(resolved);
25
+ }
26
+ catch {
27
+ // Not a file or directory — treat as a bare title.
28
+ return { mode: "title", content: baInputPath };
29
+ }
30
+ if (stat.isDirectory()) {
31
+ const entries = fs.readdirSync(resolved);
32
+ const markdownAndText = entries
33
+ .filter((e) => e.endsWith(".md") || e.endsWith(".txt"))
34
+ .sort(); // deterministic order
35
+ if (markdownAndText.length === 0) {
36
+ throw new Error(`directory contains no .md or .txt files: ${resolved}`);
37
+ }
38
+ const parts = markdownAndText.map((filename) => {
39
+ const filePath = path.join(resolved, filename);
40
+ const content = fs.readFileSync(filePath, "utf-8");
41
+ return `### File: ${filename}\n\n${content}\n`;
42
+ });
43
+ return {
44
+ mode: "directory",
45
+ content: parts.join("\n---\n\n"),
46
+ resolvedPath: resolved,
47
+ fileCount: parts.length,
48
+ };
49
+ }
50
+ // Treat as a file.
51
+ const content = fs.readFileSync(resolved, "utf-8");
52
+ if (!content.trim()) {
53
+ throw new Error(`input file is empty: ${resolved}`);
54
+ }
55
+ return { mode: "file", content, resolvedPath: resolved };
56
+ }
57
+ /**
58
+ * Produce a placeholder Markdown document when the LLM fails, preserving
59
+ * the raw input so no information is lost.
60
+ */
61
+ function buildPlaceholder(rawInput, errorMessage) {
62
+ return [
63
+ "# Technical Requirements (BA Generation Failed)",
64
+ "",
65
+ "## Goal",
66
+ "(LLM generation failed — raw input preserved below)",
67
+ "",
68
+ "## Non-Goals",
69
+ "(not determined)",
70
+ "",
71
+ "## Constraints",
72
+ "(not determined)",
73
+ "",
74
+ "## Acceptance Criteria",
75
+ "(not determined)",
76
+ "",
77
+ "## Raw Input",
78
+ rawInput,
79
+ "",
80
+ "## Error",
81
+ errorMessage,
82
+ "",
83
+ ].join("\n");
84
+ }
85
+ /**
86
+ * Write a file to the project-owned backlog directory atomically (tmp + rename).
87
+ * The temporary staging file is placed under .tmp/atomic/ to keep the target
88
+ * directory clean and make cleanup easier (see FR-5). Cross-filesystem EXDEV
89
+ * is handled via copy+unlink fallback.
90
+ */
91
+ function atomicWrite(workspaceRoot, filename, content) {
92
+ const outputs = getOutputPaths({ cwd: workspaceRoot });
93
+ outputs.ensureGitignore();
94
+ const xcoderPaths = createXcoderPaths(workspaceRoot);
95
+ const backlogDir = xcoderPaths.backlogDir();
96
+ fs.mkdirSync(backlogDir, { recursive: true });
97
+ const finalPath = path.join(backlogDir, filename);
98
+ const atomicDir = outputs.atomicDir();
99
+ fs.mkdirSync(atomicDir, { recursive: true });
100
+ const tmpPath = path.join(atomicDir, filename);
101
+ fs.writeFileSync(tmpPath, content, "utf-8");
102
+ try {
103
+ fs.renameSync(tmpPath, finalPath);
104
+ }
105
+ catch {
106
+ // EXDEV fallback for cross-filesystem moves (e.g. different mount points)
107
+ try {
108
+ fs.copyFileSync(tmpPath, finalPath);
109
+ fs.unlinkSync(tmpPath);
110
+ }
111
+ catch {
112
+ // Best-effort: if even copy+unlink fails, the content is still in the
113
+ // atomic staging dir — it won't be lost.
114
+ throw new Error(`atomicWrite: rename failed and copy fallback also failed for ${finalPath}`);
115
+ }
116
+ }
117
+ }
118
+ /**
119
+ * Runs a standalone one-step Business Analyst Sub Agent to generate
120
+ * technical requirements from a raw business requirements input.
121
+ *
122
+ * Handles file, directory, and title-only inputs via resolveBaInput().
123
+ * Creates a backlog item (BL-###) before running the BA SubAgent so every
124
+ * invocation leaves a traceable record. On success, persists the generated
125
+ * document to .xcoder/backlog/<BL-id>.md and updates the item's description.
126
+ * On LLM failure, writes a placeholder document and exits non-zero.
127
+ *
128
+ * Invoked directly from the --ba CLI flag. Bypasses the Master Orchestrator
129
+ * DAG entirely — this is a single-step transform, not a pipeline.
130
+ */
131
+ export async function runBaGeneration(opts) {
132
+ const { workspaceRoot, baInputPath, outputPath, model } = opts;
133
+ // 1. Resolve input — may throw.
134
+ let resolution;
135
+ try {
136
+ resolution = resolveBaInput(workspaceRoot, baInputPath);
137
+ }
138
+ catch (e) {
139
+ const msg = e.message;
140
+ log.fail(msg);
141
+ process.exitCode = 1;
142
+ return { ok: false, error: msg };
143
+ }
144
+ // 2. Derive a title for the backlog item.
145
+ const title = resolution.mode === "title"
146
+ ? baInputPath
147
+ : path.basename("resolvedPath" in resolution ? resolution.resolvedPath : baInputPath);
148
+ // 3. Create backlog item BEFORE running the LLM (guarantees audit trail).
149
+ let backlogItem;
150
+ try {
151
+ backlogItem = await addBacklogItem(workspaceRoot, title);
152
+ }
153
+ catch (e) {
154
+ const msg = `failed to create backlog item: ${e.message}`;
155
+ log.fail(msg);
156
+ process.exitCode = 1;
157
+ return { ok: false, error: msg };
158
+ }
159
+ const backlogId = backlogItem.id;
160
+ const backlogPath = `.xcoder/backlog/${backlogId}.md`;
161
+ // 4. Create LlmClient.
162
+ let llm;
163
+ try {
164
+ llm = createLlmClient("orchestrator", { model });
165
+ }
166
+ catch (e) {
167
+ const msg = e.message;
168
+ log.fail(msg);
169
+ process.exitCode = 1;
170
+ // Write placeholder — LLM client creation failed.
171
+ const placeholder = buildPlaceholder(resolution.content, msg);
172
+ await writeBacklogDocAndUpdate(workspaceRoot, backlogId, placeholder, msg, "LLM init failure");
173
+ return { ok: false, error: msg, backlogId, backlogPath, outputContent: placeholder };
174
+ }
175
+ // 5. Build a one-node SubtaskNode for the business analyst.
176
+ const nodeId = `ba-${shortId("st")}`;
177
+ const inputLabel = resolution.mode === "file" || resolution.mode === "directory"
178
+ ? resolution.resolvedPath
179
+ : `feature title: "${baInputPath}"`;
180
+ const subtaskNode = {
181
+ id: nodeId,
182
+ stage: "requirements",
183
+ role: "business-analyst",
184
+ engine: "react-v1",
185
+ dependsOn: [],
186
+ goal: `Read the raw business requirement from upstream context (key: "rawBusinessRequirement") — this is the contents from ${inputLabel} — and produce a structured technical requirements document in Markdown.`,
187
+ upstreamContext: {
188
+ rawBusinessRequirement: resolution.content,
189
+ },
190
+ deliverableSpec: "A structured technical requirements Markdown document with sections: Goal, Non-Goals, Constraints, Acceptance Criteria.",
191
+ acceptanceCriteria: [
192
+ { id: "AC1", type: "rubric", description: "Goal is stated as a concrete, checkable outcome." },
193
+ { id: "AC2", type: "rubric", description: "Non-goals and constraints are explicit." },
194
+ { id: "AC3", type: "rubric", description: "Acceptance criteria are numbered and checkable." },
195
+ ],
196
+ status: "ready",
197
+ healing: { attempts: 0, maxAttempts: 1, log: [] },
198
+ };
199
+ // 6. Create SubAgent directly (NOT via SdlcOrchestrator).
200
+ const taskId = shortId("task");
201
+ const agent = new SubAgent({
202
+ taskId,
203
+ workspaceRoot,
204
+ llm,
205
+ directiveOverride: BA_REQUIREMENTS_DIRECTIVE,
206
+ });
207
+ // 7. Run the agent and await result.
208
+ let result;
209
+ try {
210
+ result = await agent.run(subtaskNode);
211
+ }
212
+ catch (e) {
213
+ const msg = `BA agent run threw unexpectedly: ${e.message}`;
214
+ log.fail(msg);
215
+ process.exitCode = 1;
216
+ const placeholder = buildPlaceholder(resolution.content, msg);
217
+ await writeBacklogDocAndUpdate(workspaceRoot, backlogId, placeholder, msg, "LLM crash");
218
+ return { ok: false, error: msg, backlogId, backlogPath, outputContent: placeholder };
219
+ }
220
+ // 8. Check for SubAgent crash.
221
+ if (result.crashed) {
222
+ const msg = `BA agent crashed: ${result.summary || "unknown error"}`;
223
+ log.fail(msg);
224
+ process.exitCode = 1;
225
+ const placeholder = buildPlaceholder(resolution.content, msg);
226
+ await writeBacklogDocAndUpdate(workspaceRoot, backlogId, placeholder, msg, "LLM crash");
227
+ return { ok: false, error: msg, backlogId, backlogPath, outputContent: placeholder };
228
+ }
229
+ // 9. Extract deliverable, format as Markdown.
230
+ const content = typeof result.deliverable === "string"
231
+ ? result.deliverable
232
+ : result.deliverable != null
233
+ ? JSON.stringify(result.deliverable, null, 2)
234
+ : result.summary ?? "(no output produced)";
235
+ // 10. Write backlog document atomically.
236
+ try {
237
+ atomicWrite(workspaceRoot, `${backlogId}.md`, content);
238
+ }
239
+ catch (e) {
240
+ const msg = `failed to write backlog document: ${e.message}`;
241
+ log.fail(msg);
242
+ process.exitCode = 1;
243
+ return { ok: false, error: msg, backlogId, backlogPath };
244
+ }
245
+ // 11. Update backlog item description with the document path.
246
+ try {
247
+ await updateBacklogItem(workspaceRoot, backlogId, {
248
+ description: `Requirements document: ${backlogPath}`,
249
+ });
250
+ }
251
+ catch (e) {
252
+ log.fail(`could not update backlog item description: ${e.message}`);
253
+ // Non-fatal — the document is already saved.
254
+ }
255
+ // 12. Write user-specified output if provided.
256
+ if (outputPath) {
257
+ const resolvedOutput = path.resolve(workspaceRoot, outputPath);
258
+ try {
259
+ fs.mkdirSync(path.dirname(resolvedOutput), { recursive: true });
260
+ fs.writeFileSync(resolvedOutput, content, "utf-8");
261
+ log.ok(`requirements written to ${resolvedOutput}`);
262
+ return { ok: true, outputPath: resolvedOutput, backlogId, backlogPath, outputContent: content };
263
+ }
264
+ catch (e) {
265
+ const msg = `failed to write output file: ${e.message}`;
266
+ log.fail(msg);
267
+ process.exitCode = 1;
268
+ return { ok: true, backlogId, backlogPath, outputContent: content, error: msg };
269
+ }
270
+ }
271
+ // No output path — print to stdout.
272
+ log.raw(content);
273
+ return { ok: true, backlogId, backlogPath, outputContent: content };
274
+ }
275
+ /**
276
+ * Shared helper for LLM failure paths: write the placeholder to the backlog
277
+ * doc and update the backlog item description to reflect the error.
278
+ */
279
+ async function writeBacklogDocAndUpdate(workspaceRoot, backlogId, placeholder, errorMessage, errorKind) {
280
+ try {
281
+ atomicWrite(workspaceRoot, `${backlogId}.md`, placeholder);
282
+ }
283
+ catch {
284
+ log.fail(`could not write placeholder backlog document for ${backlogId}`);
285
+ }
286
+ try {
287
+ await updateBacklogItem(workspaceRoot, backlogId, {
288
+ description: `.xcoder/backlog/${backlogId}.md\n\n[ERROR: ${errorKind} — raw input preserved]`,
289
+ });
290
+ }
291
+ catch {
292
+ log.fail(`could not update backlog item description for ${backlogId}`);
293
+ }
294
+ }
@@ -0,0 +1,8 @@
1
+ import type { Command } from "commander";
2
+ /**
3
+ * Register `xcoder jarvis [args...]`.
4
+ *
5
+ * `xcoder jarvis --chat` starts jarvis's multi-turn session, and any other
6
+ * jarvis flag reaches it unchanged — run `xcoder jarvis --help` for the list.
7
+ */
8
+ export declare function registerJarvisCommand(parent: Command): void;
@@ -0,0 +1,16 @@
1
+ // xcoder:version 1 | xcoder:task task-691585 | xcoder:updated 2026-11-05T05:45:32.793Z | xcoder:subtask code-st-b5251b
2
+ // `xcoder jarvis ...` — reach the real jarvis CLI without leaving xcoder.
3
+ //
4
+ // Registered the same way as `test`, `swarm`, `task` and `license`: one exported
5
+ // `register...Command(parent)` so `sdlc-cli.ts` stays a thin composition root.
6
+ // The command interprets nothing; every argument belongs to jarvis.
7
+ import { JARVIS_SPEC, registerDelegatedCommand } from "xcoder-dna";
8
+ /**
9
+ * Register `xcoder jarvis [args...]`.
10
+ *
11
+ * `xcoder jarvis --chat` starts jarvis's multi-turn session, and any other
12
+ * jarvis flag reaches it unchanged — run `xcoder jarvis --help` for the list.
13
+ */
14
+ export function registerJarvisCommand(parent) {
15
+ registerDelegatedCommand(parent, JARVIS_SPEC);
16
+ }
@@ -0,0 +1 @@
1
+ export { AGENT_NAME, runSdlcAgent } from "./program.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // Public barrel - the only import path other packages may use.
2
+ export { AGENT_NAME, runSdlcAgent } from "./program.js";
@@ -0,0 +1,3 @@
1
+ export declare const AGENT_NAME: "sdlc-agent";
2
+ /** Program entry. Returns an exit code; never calls process.exit itself. */
3
+ export declare function runSdlcAgent(argv: string[]): Promise<number>;
@@ -0,0 +1,18 @@
1
+ // Public program surface of this agent package.
2
+ export const AGENT_NAME = "sdlc-agent";
3
+ /** Program entry. Returns an exit code; never calls process.exit itself. */
4
+ export async function runSdlcAgent(argv) {
5
+ const saved = process.argv;
6
+ process.argv = [saved[0] ?? "node", "xcoder", ...argv];
7
+ try {
8
+ await import("./sdlc-cli.js");
9
+ return typeof process.exitCode === "number" ? process.exitCode : 0;
10
+ }
11
+ catch (err) {
12
+ process.stderr.write(`\nError: ${err instanceof Error ? err.message : String(err)}\n`);
13
+ return 1;
14
+ }
15
+ finally {
16
+ process.argv = saved;
17
+ }
18
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};