@neural-node-labs/xcoder-litebro 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,87 @@
1
- # Temporary Holding Version
1
+ <!-- xcoder:version 6 | xcoder:task task-0d242c | xcoder:updated 2026-11-19T14:15:52.245Z | xcoder:subtask code-st-8d2337 -->
2
+ # @neural-node-labs/xcoder-litebro — the tool-less planner/broker agent
3
+
4
+ Litebro plans one goal with a Master Orchestrator that holds **no tools at all**, then delegates the plan's subtasks to worker agents on Xcoder's shared worker engine. The planner can only reason; only the workers can act.
5
+
6
+ ## Install
7
+
8
+ ```
9
+ npm install -g @neural-node-labs/xcoder-litebro
10
+ ```
11
+
12
+ Node >= 20 is required.
13
+
14
+ ## Quick start
15
+
16
+ ```
17
+ litebro "add a /health endpoint and a test for it"
18
+ ```
19
+
20
+ The goal is the single positional argument. There is no `run` subcommand and no task or subtask flag — the planner derives the subtasks itself.
21
+
22
+ `litebro` **is** the litebro CLI: the binary this package ships is the program, so `xcoder litebro` reaches exactly the same command and adds nothing to it. That is a command name, not an import — this package still depends on @neural-node-labs/xcoder-dna only.
23
+
24
+ ## CLI reference
25
+
26
+ ### `litebro [goal]`
27
+
28
+ `goal` is untrusted input and is treated as data, never as instructions.
29
+
30
+ | Flag | Meaning |
31
+ |---|---|
32
+ | `--secure` | Enforce the secure-architect bylaws: inject them into gated prompts and block success on an unreviewed or violating finding. Off by default. |
33
+ | `--concurrency <n>` | Max in-flight sub agents (default 3). |
34
+ | `--max-attempts <n>` | Total attempts per subtask (default 2). |
35
+ | `--max-plan-steps <n>` | Planner iterations before giving up (default 3). |
36
+ | `--max-subtasks <n>` | Plan size cap (default 8, hard cap 16). |
37
+ | `--workspace <dir>` | Workspace root (default: current working directory). |
38
+ | `--model <name>` | Overrides the configured LLM model. |
39
+ | `--task-id <id>` | Explicit run id. |
40
+ | `--json` | Machine output: the report only, no prose on stdout. Implies quiet. |
41
+ | `--quiet` | Suppress progress notes. |
42
+ | `--spinner <style>` | Thinking indicator style (default `line`). |
43
+ | `--no-color` | Disable colour output; sets `NO_COLOR=1`. |
44
+
45
+ ### Security posture
46
+
47
+ - **Tool-less guarantee.** The planner is constructed with `NO_TOOLS`. It cannot read files, run commands or fetch URLs; its only output is a plan that is schema-validated before dispatch.
48
+ - **`--secure` is opt-in and off by default.** When off, no bylaw verdict is computed, so `bylaw` is `null` and cannot influence the run status.
49
+ - **`secure.mode` is always reported.** Every run — human or `--json` — states whether secure mode was `enforce` or `off`.
50
+ ## Exit codes
51
+
52
+ | Code | Meaning |
53
+ |---|---|
54
+ | `0` | Run status `completed`: every planned subtask finished (and, under `--secure`, the bylaw review approved). |
55
+ | `1` | Run status `partial` or `failed`, or an unexpected error. A report is still printed. |
56
+ | `2` | Usage error — missing goal, a non-positive integer flag, or a rejected argument parse. No report is printed. |
57
+
58
+ ## Environment variables
59
+
60
+ | Variable | Effect |
61
+ |---|---|
62
+ | `NO_COLOR` | Set to `1` by `--no-color`. When present, colour and live chrome are disabled. |
63
+
64
+ ## Dependency direction
65
+
66
+ `@neural-node-labs/xcoder-litebro` depends on `@neural-node-labs/xcoder-dna` only. It never imports another agent package (`xcoder-qa-agent`, `@neural-node-labs/xcoder-sdlc`), so the plan/broker layer stays independently installable.
67
+
68
+ ## Documentation contract
69
+
70
+ This README ships to npm (`files` includes it), so it is gated like code by `packages/litebro/src/doc-readme.test.ts`. That test parses `src/cli.ts` at run time and fails when a declared flag is undocumented, when the README invents a flag the CLI does not declare, or when the H1 stops naming litebro. Run it in isolation with:
71
+
72
+ ```
73
+ npx vitest run packages/litebro/src/doc-readme.test.ts
74
+ ```
75
+
76
+ ## Related packages
77
+
78
+ - [@neural-node-labs/xcoder-dna](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/xcoder-dna) — shared runtime, tools, swarm and orchestration primitives.
79
+ - [@neural-node-labs/xcoder-sdlc](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/sdlc-agent) — the `xcoder` SDLC agent and the `ba-v1` business analyst.
80
+ - [xcoder-qa-agent](https://github.com/Neural-Node-Labs/xcoder-origin/tree/main/packages/qa-agent) — the `bugfinder` QA agent.
81
+ - [USAGE.md](https://github.com/Neural-Node-Labs/xcoder-origin/blob/main/docs/USAGE.md) — full workspace CLI reference.
82
+ - [SECURE_MODE.md](https://github.com/Neural-Node-Labs/xcoder-origin/blob/main/docs/SECURE_MODE.md) — the threat model behind `--secure`.
83
+
84
+ ## License
85
+
86
+ see [LICENSE](./LICENSE) for details.
2
87
 
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.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "xcoder-dna";
package/dist/cli.js ADDED
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env node
2
+ // xcoder:version 5 | xcoder:task task-50b086 | xcoder:updated 2026-11-05T12:48:28.290Z | xcoder:subtask code-st-712cf2
3
+ // `litebro` bin — plan one goal with a tool-less planner, then delegate the
4
+ // plan's subtasks to the existing worker engine.
5
+ //
6
+ // Deliberately minimal: parse, build clients, plan,
7
+ // dispatch, print. No `run` subcommand, no `--task`, no `--subtask` — the goal
8
+ // is the single positional argument (AC1, AC2).
9
+ // Filtered .env loading lives in loadConfig (never `dotenv/config`).
10
+ import "xcoder-dna";
11
+ import { Command } from "commander";
12
+ import path from "node:path";
13
+ import { createLlmClient } from "xcoder-dna";
14
+ import { log } from "xcoder-dna";
15
+ import { createTaskLogger } from "xcoder-dna";
16
+ import { agentCliIntro, agentCliOutro } from "./util/terminal.js";
17
+ import { setSpinnerStyle, AVAILABLE_SPINNER_STYLES } from "xcoder-dna";
18
+ import { enableProtocolErrorLogging } from "xcoder-dna";
19
+ import { enableToolErrorLogging } from "xcoder-dna";
20
+ import { XCODER_VERSION } from "xcoder-dna";
21
+ import { NO_TOOLS } from "./no-tools.js";
22
+ import { MasterOrchestrator } from "./master-orchestrator.js";
23
+ import { createSecureGate } from "./secure-gate.js";
24
+ import { dispatchPlan } from "./dispatcher.js";
25
+ import { deriveStatus, emptyTotals, exitCodeFor, formatHumanReport, summariseBylawVerdicts, } from "./report.js";
26
+ /** Usage errors exit 2 and never print a report. */
27
+ class UsageError extends Error {
28
+ }
29
+ /** Positive integer flag, or a UsageError — never NaN flowing into a loop bound. */
30
+ function positiveInt(raw, flag) {
31
+ const n = Number.parseInt(raw, 10);
32
+ if (!Number.isFinite(n) || n < 1) {
33
+ throw new UsageError(`option '${flag}' must be a positive integer, got '${raw}'`);
34
+ }
35
+ return n;
36
+ }
37
+ /** Ctrl-C aborts *new* waves; in-flight agents finish (existing engine semantics). */
38
+ function makeSignal() {
39
+ if (typeof AbortSignal === "undefined")
40
+ return undefined;
41
+ const controller = new AbortController();
42
+ process.once("SIGINT", () => controller.abort());
43
+ return controller.signal;
44
+ }
45
+ const program = new Command();
46
+ program
47
+ .name("litebro")
48
+ .description("Litebro — plan one goal with a tool-less Master Orchestrator, then delegate the " +
49
+ "plan's subtasks to worker agents on Xcoder's shared worker engine.")
50
+ .version(XCODER_VERSION)
51
+ .argument("[goal]", "One sentence describing what to build (untrusted input)")
52
+ .option("--secure", "Enforce secure-architect bylaws: inject them into gated prompts and block success " +
53
+ "on an unreviewed/violating finding. Off by default.", false)
54
+ .option("--concurrency <n>", "Max in-flight sub agents (default 3)", (v) => positiveInt(v, "--concurrency"))
55
+ .option("--max-attempts <n>", "Total attempts per subtask (default 2)", (v) => positiveInt(v, "--max-attempts"))
56
+ .option("--max-plan-steps <n>", "Planner iterations before giving up (default 3)", (v) => positiveInt(v, "--max-plan-steps"))
57
+ .option("--max-subtasks <n>", "Plan size cap (default 8, hard cap 16)", (v) => positiveInt(v, "--max-subtasks"))
58
+ .option("--workspace <dir>", "Workspace root (default cwd)", process.cwd())
59
+ .option("--model <name>", "Overrides the configured LLM model")
60
+ .option("--task-id <id>", "Explicit run id")
61
+ .option("--json", "Machine output: the report only, no prose on stdout", false)
62
+ .option("--quiet", "Suppress progress notes", false)
63
+ .option("--spinner <style>", `Thinking indicator (${AVAILABLE_SPINNER_STYLES.join(", ")})`, "line")
64
+ .option("--no-color", "Disable colour output")
65
+ .action(async (goalArg, opts) => {
66
+ if (!opts.color)
67
+ process.env.NO_COLOR = "1";
68
+ setSpinnerStyle(opts.spinner);
69
+ let showCliChrome = false;
70
+ let chromeStatus = "failed";
71
+ try {
72
+ // Validated here (not with a required argument) so a missing goal is a
73
+ // usage error with exit 2, matching every other usage error.
74
+ const goal = typeof goalArg === "string" ? goalArg.trim() : "";
75
+ if (!goal) {
76
+ throw new UsageError('a goal is required, e.g. `litebro "add a health endpoint"`');
77
+ }
78
+ const workspaceRoot = path.resolve(opts.workspace);
79
+ const secureMode = opts.secure ? "enforce" : "off";
80
+ const secure = createSecureGate(secureMode);
81
+ const taskId = opts.taskId?.trim() || process.env.XCODER_TASK_ID || `litebro-${Date.now()}`;
82
+ // The planner logs its own work too (design G-5). This bin previously wrote
83
+ // no shared task log at all, so a failed planning phase left no trace under
84
+ // .xcoder/logs. Bound on the SAME taskId the phases below receive, so the
85
+ // log joins the run rather than starting a parallel one.
86
+ const taskLog = createTaskLogger({
87
+ root: workspaceRoot,
88
+ taskId,
89
+ subtaskId: "planner",
90
+ onError: (message) => log.dim(`litebro: task log unavailable (${message})`),
91
+ });
92
+ await taskLog.sys(`planning in ${workspaceRoot}`);
93
+ const signal = makeSignal();
94
+ showCliChrome = !opts.json && !opts.quiet;
95
+ if (showCliChrome)
96
+ agentCliIntro("litebro", taskId);
97
+ const llmOverrides = {
98
+ workspaceRoot,
99
+ ...(opts.model ? { model: opts.model } : {}),
100
+ };
101
+ const plannerLlm = createLlmClient("orchestrator", llmOverrides);
102
+ const workerLlm = createLlmClient("sub_agent", llmOverrides);
103
+ enableProtocolErrorLogging();
104
+ enableToolErrorLogging();
105
+ const verbose = !opts.quiet && !opts.json;
106
+ // Keep the live view to phase transitions; the full planner trace remains in the report.
107
+ const emit = undefined;
108
+ const planner = new MasterOrchestrator({
109
+ llm: plannerLlm,
110
+ tools: NO_TOOLS,
111
+ secure,
112
+ maxPlanSteps: opts.maxPlanSteps,
113
+ maxSubtasks: opts.maxSubtasks,
114
+ emit,
115
+ });
116
+ if (verbose)
117
+ log.orchestrator(`Plan · ${goal}`);
118
+ const outcome = await planner.plan({ goal, signal });
119
+ let report;
120
+ if (outcome.ok) {
121
+ const plan = outcome.plan;
122
+ if (verbose)
123
+ log.orchestrator(`Plan ready · ${plan.subtasks.length} tasks · starting workers`);
124
+ const dispatched = await dispatchPlan(plan, {
125
+ workspaceRoot,
126
+ llm: workerLlm,
127
+ concurrency: opts.concurrency ?? 3,
128
+ maxAttempts: opts.maxAttempts ?? 2,
129
+ secure,
130
+ taskId,
131
+ signal,
132
+ quiet: (opts.quiet ?? false) || (opts.json ?? false),
133
+ });
134
+ const bylaw = secureMode === "enforce" ? summariseBylawVerdicts(dispatched.subtasks) : null;
135
+ report = {
136
+ taskId,
137
+ goal,
138
+ status: deriveStatus({ plan, subtasks: dispatched.subtasks, bylaw }),
139
+ secure: { mode: secureMode },
140
+ plan,
141
+ planning: {
142
+ steps: outcome.steps,
143
+ duplicateDetections: outcome.duplicateDetections,
144
+ failure: null,
145
+ errors: [],
146
+ trace: outcome.trace,
147
+ },
148
+ subtasks: dispatched.subtasks,
149
+ totals: dispatched.totals,
150
+ bylaw,
151
+ };
152
+ }
153
+ else {
154
+ // Fail closed: zero subtasks dispatched (AC4).
155
+ report = {
156
+ taskId,
157
+ goal,
158
+ status: deriveStatus({ plan: null, subtasks: [], bylaw: null }),
159
+ secure: { mode: secureMode },
160
+ plan: null,
161
+ planning: {
162
+ steps: outcome.steps,
163
+ duplicateDetections: outcome.duplicateDetections,
164
+ failure: outcome.reason,
165
+ errors: outcome.errors,
166
+ trace: outcome.trace,
167
+ },
168
+ subtasks: [],
169
+ totals: emptyTotals(),
170
+ bylaw: null,
171
+ };
172
+ }
173
+ if (opts.json) {
174
+ process.stdout.write(JSON.stringify(report, null, 2) + "\n");
175
+ }
176
+ else {
177
+ process.stdout.write(formatHumanReport(report));
178
+ }
179
+ process.exitCode = exitCodeFor(report.status);
180
+ chromeStatus = report.status;
181
+ if (showCliChrome)
182
+ agentCliOutro("litebro", chromeStatus);
183
+ }
184
+ catch (e) {
185
+ if (showCliChrome)
186
+ agentCliOutro("litebro", chromeStatus);
187
+ if (e instanceof UsageError) {
188
+ process.stderr.write(`litebro: ${e.message}\n`);
189
+ process.exitCode = 2;
190
+ return;
191
+ }
192
+ process.stderr.write(`litebro: ${e?.message ?? String(e)}\n`);
193
+ process.exitCode = 1;
194
+ }
195
+ });
196
+ program.parseAsync(process.argv).catch((e) => {
197
+ process.stderr.write(`litebro: ${e?.message ?? String(e)}\n`);
198
+ process.exitCode = 2;
199
+ });
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Plan → work.
3
+ *
4
+ * Deliberately thin. `WorkerOrchestrator` already provides concurrency,
5
+ * per-subtask retries, attempt history, an AbortSignal, and — critically —
6
+ * crash isolation (`crashed: true` instead of a rejected promise). This file
7
+ * adds exactly the two things a plan has that a worker request does not:
8
+ *
9
+ * 1. `dependsOn`, resolved into sequential topological waves. It is NOT a
10
+ * `WorkerSubtask` field and is not pushed down; independence there is a
11
+ * deliberate contract we do not want to widen.
12
+ * 2. A `skipped` status, for a subtask whose dependency did not succeed.
13
+ * It is never dispatched, so it must never be reported as `failed` —
14
+ * that would blame work that never ran.
15
+ *
16
+ * It never rethrows a subtask error (AC7): a run that loses one subtask still
17
+ * produces a full report.
18
+ */
19
+ import { type LlmClient } from "xcoder-dna";
20
+ import { type Role } from "xcoder-dna";
21
+ import { type WorkerRunRequest, type WorkerRunReport, type WorkerSubtaskReport } from "xcoder-dna";
22
+ import type { Plan } from "./plan-schema.js";
23
+ import type { BylawVerdict, SecureGate } from "./secure-gate.js";
24
+ export type LitecoderSubtaskStatus = "done" | "failed" | "skipped";
25
+ export interface LitecoderSubtaskReport extends Omit<WorkerSubtaskReport, "status"> {
26
+ readonly role: Role;
27
+ readonly status: LitecoderSubtaskStatus;
28
+ /** Always null when `--secure` is off (AC11). */
29
+ readonly bylawVerdict: BylawVerdict | null;
30
+ readonly dependsOn: readonly string[];
31
+ }
32
+ export interface DispatchOptions {
33
+ readonly workspaceRoot: string;
34
+ readonly llm: LlmClient;
35
+ readonly concurrency: number;
36
+ readonly maxAttempts: number;
37
+ readonly secure: SecureGate;
38
+ readonly taskId?: string;
39
+ readonly signal?: AbortSignal;
40
+ readonly quiet?: boolean;
41
+ /** Trusted shared context attached independently to each worker's task. */
42
+ readonly workerContext?: Readonly<Record<string, unknown>>;
43
+ /** Optional enforced allowlist passed to every dispatched worker. */
44
+ readonly allowedTools?: readonly string[];
45
+ }
46
+ export interface DispatchOutcome {
47
+ readonly subtasks: readonly LitecoderSubtaskReport[];
48
+ readonly totals: {
49
+ readonly subtasks: number;
50
+ readonly done: number;
51
+ readonly failed: number;
52
+ readonly skipped: number;
53
+ readonly totalAttempts: number;
54
+ readonly inputTokens: number;
55
+ readonly outputTokens: number;
56
+ readonly durationMs: number;
57
+ };
58
+ }
59
+ /** The only thing the dispatcher needs from the engine — an injection seam for tests. */
60
+ export interface DispatchEngine {
61
+ run(request: WorkerRunRequest): Promise<WorkerRunReport>;
62
+ }
63
+ export declare function dispatchPlan(plan: Plan, opts: DispatchOptions, engine?: DispatchEngine): Promise<DispatchOutcome>;
@@ -0,0 +1,147 @@
1
+ import { WorkerOrchestrator } from "xcoder-dna";
2
+ function emptySubtaskReport(id, role, dependsOn, reason) {
3
+ return {
4
+ id,
5
+ role,
6
+ status: "skipped",
7
+ attempts: 0,
8
+ summary: "",
9
+ error: reason,
10
+ filesTouched: [],
11
+ tokenUsage: { inputTokens: 0, outputTokens: 0 },
12
+ iterations: 0,
13
+ crashed: false,
14
+ history: [],
15
+ bylawVerdict: null,
16
+ dependsOn,
17
+ };
18
+ }
19
+ /**
20
+ * Groups the plan into waves: everything whose dependencies have already been
21
+ * placed goes into the next wave. A validated plan is acyclic and has no
22
+ * dangling ids (see `PlanSchema`), so this always terminates; the guard is
23
+ * belt-and-braces so a hand-built `Plan` in a test cannot hang the run.
24
+ */
25
+ function planWaves(plan) {
26
+ const placed = new Set();
27
+ const remaining = [...plan.subtasks];
28
+ const waves = [];
29
+ while (remaining.length > 0) {
30
+ const wave = remaining.filter((s) => s.dependsOn.every((d) => placed.has(d)));
31
+ if (wave.length === 0) {
32
+ // Unreachable for a validated plan. Place the rest so the run ends.
33
+ waves.push(remaining);
34
+ break;
35
+ }
36
+ waves.push(wave);
37
+ for (const s of wave) {
38
+ placed.add(s.id);
39
+ const idx = remaining.indexOf(s);
40
+ if (idx >= 0)
41
+ remaining.splice(idx, 1);
42
+ }
43
+ }
44
+ return waves;
45
+ }
46
+ export async function dispatchPlan(plan, opts, engine) {
47
+ const startedAt = Date.now();
48
+ const runner = engine ??
49
+ new WorkerOrchestrator({
50
+ workspaceRoot: opts.workspaceRoot,
51
+ llm: opts.llm,
52
+ quiet: opts.quiet ?? false,
53
+ });
54
+ const byId = new Map();
55
+ const waves = planWaves(plan);
56
+ for (const wave of waves) {
57
+ if (opts.signal?.aborted) {
58
+ for (const sub of wave) {
59
+ byId.set(sub.id, emptySubtaskReport(sub.id, sub.role, sub.dependsOn, "aborted before dispatch"));
60
+ }
61
+ continue;
62
+ }
63
+ const runnable = [];
64
+ for (const sub of wave) {
65
+ const blockedBy = sub.dependsOn.filter((d) => byId.get(d)?.status !== "done");
66
+ if (blockedBy.length > 0) {
67
+ byId.set(sub.id, emptySubtaskReport(sub.id, sub.role, sub.dependsOn, `skipped: dependency did not complete (${blockedBy.join(", ")})`));
68
+ continue;
69
+ }
70
+ // The bylaw block rides on the existing, already-typed `upstreamContext`
71
+ // vehicle, so `SubAgent` renders it without any change to the agent.
72
+ const bylawBlock = opts.secure.promptBlock(sub.role, sub.goal);
73
+ const upstreamContext = { ...(opts.workerContext ?? {}) };
74
+ if (bylawBlock)
75
+ upstreamContext.bylawContext = bylawBlock;
76
+ runnable.push({
77
+ id: sub.id,
78
+ goal: sub.goal,
79
+ role: sub.role,
80
+ deliverableSpec: sub.deliverableSpec,
81
+ ...(opts.allowedTools ? { allowedTools: [...opts.allowedTools] } : {}),
82
+ ...(Object.keys(upstreamContext).length > 0 ? { upstreamContext } : {}),
83
+ });
84
+ }
85
+ if (runnable.length === 0)
86
+ continue;
87
+ let report;
88
+ try {
89
+ report = await runner.run({
90
+ taskDescription: plan.rationale,
91
+ subtasks: runnable,
92
+ concurrency: opts.concurrency,
93
+ maxAttempts: opts.maxAttempts,
94
+ taskId: opts.taskId,
95
+ signal: opts.signal,
96
+ });
97
+ }
98
+ catch (e) {
99
+ // `WorkerOrchestrator.run` is contractually non-throwing; if it did
100
+ // throw, attribute the failure to this wave rather than lose the run.
101
+ const message = e?.message ?? String(e);
102
+ for (const sub of runnable) {
103
+ byId.set(sub.id, {
104
+ ...emptySubtaskReport(sub.id, sub.role ?? "programmer", [], message),
105
+ status: "failed",
106
+ attempts: 1,
107
+ history: [{ attempt: 1, ok: false, error: message }],
108
+ });
109
+ }
110
+ continue;
111
+ }
112
+ for (const sub of runnable) {
113
+ const planned = plan.subtasks.find((p) => p.id === sub.id);
114
+ const worker = report.subtasks.find((r) => r.id === sub.id);
115
+ if (!worker) {
116
+ byId.set(sub.id, emptySubtaskReport(sub.id, planned.role, planned.dependsOn, "no result returned"));
117
+ continue;
118
+ }
119
+ // Judged on what the sub agent returned to us. `reviewDeliverable`
120
+ // drops anything it cannot parse, so an unparseable summary surfaces as
121
+ // `unreviewed`, which blocks — the safe direction.
122
+ const verdict = opts.secure.judge(planned.role, planned.goal, worker.summary);
123
+ byId.set(sub.id, {
124
+ ...worker,
125
+ role: planned.role,
126
+ status: worker.status,
127
+ bylawVerdict: verdict,
128
+ dependsOn: planned.dependsOn,
129
+ });
130
+ }
131
+ }
132
+ // Report in plan order — stable, and every planned subtask appears once.
133
+ const subtasks = plan.subtasks.map((p) => byId.get(p.id) ?? emptySubtaskReport(p.id, p.role, p.dependsOn, "not dispatched"));
134
+ return {
135
+ subtasks,
136
+ totals: {
137
+ subtasks: subtasks.length,
138
+ done: subtasks.filter((s) => s.status === "done").length,
139
+ failed: subtasks.filter((s) => s.status === "failed").length,
140
+ skipped: subtasks.filter((s) => s.status === "skipped").length,
141
+ totalAttempts: subtasks.reduce((n, s) => n + s.attempts, 0),
142
+ inputTokens: subtasks.reduce((n, s) => n + s.tokenUsage.inputTokens, 0),
143
+ outputTokens: subtasks.reduce((n, s) => n + s.tokenUsage.outputTokens, 0),
144
+ durationMs: Date.now() - startedAt,
145
+ },
146
+ };
147
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Public surface of the Litebro planner CLI.
3
+ *
4
+ * Kept small on purpose: `no-tools` is exported so a test (or a reviewer) can
5
+ * assert the planner's tool surface is structurally empty without reaching
6
+ * into module internals.
7
+ */
8
+ export { NO_TOOLS, OrchestratorHasNoToolsError, isNoToolsRegistry } from "./no-tools.js";
9
+ export type { ToolRegistry } from "./no-tools.js";
10
+ export { PlanSchema, PlannedSubtaskSchema, RoleSchema, PLAN_ROLES, MAX_SUBTASKS_HARD_CAP, parsePlan, } from "./plan-schema.js";
11
+ export type { Plan, PlannedSubtask } from "./plan-schema.js";
12
+ export { MasterOrchestrator } from "./master-orchestrator.js";
13
+ export type { MasterOrchestratorOptions, PlanInput, PlanOutcome, PlannerFailure, PlannerTraceEntry, } from "./master-orchestrator.js";
14
+ export { createSecureGate, BYLAW_GATED_ROLES, SECURE_OFF_ADVISORY } from "./secure-gate.js";
15
+ export type { BylawVerdict, SecureGate, SecureMode } from "./secure-gate.js";
16
+ export { dispatchPlan } from "./dispatcher.js";
17
+ export type { DispatchEngine, DispatchOptions, DispatchOutcome, LitecoderSubtaskReport, LitecoderSubtaskStatus, } from "./dispatcher.js";
18
+ export { deriveStatus, describeSubtask, emptyTotals, exitCodeFor, formatHumanReport, summariseBylawVerdicts, } from "./report.js";
19
+ export type { BylawSummary, LitecoderRunReport, LitecoderRunStatus } from "./report.js";
20
+ export { AGENT_NAME, runLitebro } from "./program.js";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ // xcoder:version 1 | xcoder:task task-1f0256 | xcoder:updated 2026-10-17T14:36:48.169Z | xcoder:subtask code-st-9de79a
2
+ /**
3
+ * Public surface of the Litebro planner CLI.
4
+ *
5
+ * Kept small on purpose: `no-tools` is exported so a test (or a reviewer) can
6
+ * assert the planner's tool surface is structurally empty without reaching
7
+ * into module internals.
8
+ */
9
+ export { NO_TOOLS, OrchestratorHasNoToolsError, isNoToolsRegistry } from "./no-tools.js";
10
+ export { PlanSchema, PlannedSubtaskSchema, RoleSchema, PLAN_ROLES, MAX_SUBTASKS_HARD_CAP, parsePlan, } from "./plan-schema.js";
11
+ export { MasterOrchestrator } from "./master-orchestrator.js";
12
+ export { createSecureGate, BYLAW_GATED_ROLES, SECURE_OFF_ADVISORY } from "./secure-gate.js";
13
+ export { dispatchPlan } from "./dispatcher.js";
14
+ export { deriveStatus, describeSubtask, emptyTotals, exitCodeFor, formatHumanReport, summariseBylawVerdicts, } from "./report.js";
15
+ export { AGENT_NAME, runLitebro } from "./program.js";
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The planner.
3
+ *
4
+ * Turns one goal into a schema-valid `Plan`. It is the only component in
5
+ * Litebro that talks to a model, and it does so with NO tools: the
6
+ * constructor refuses any registry other than `NO_TOOLS`, so "the planner
7
+ * cannot act" is a structural fact rather than an instruction the model is
8
+ * asked to respect (PRM-04 / PRM-09).
9
+ *
10
+ * Termination does not depend on model behaviour. Three independent bounds:
11
+ * - `maxPlanSteps` (default 3) hard-caps the loop;
12
+ * - `DuplicateActionDetector` stops a repeated identical submission;
13
+ * - `PlanSchema` rejects anything malformed, so there is no partial plan.
14
+ *
15
+ * Fail closed: an `ok: false` outcome dispatches zero subtasks.
16
+ */
17
+ import { type LlmClient } from "xcoder-dna";
18
+ import { type ToolRegistry } from "./no-tools.js";
19
+ import { type Plan } from "./plan-schema.js";
20
+ import type { SecureGate } from "./secure-gate.js";
21
+ export interface PlannerTraceEntry {
22
+ readonly step: number;
23
+ readonly thought: string;
24
+ readonly action: "submit_plan";
25
+ readonly observation: string;
26
+ readonly ok: boolean;
27
+ }
28
+ export type PlannerFailure = "schema-invalid" | "step-cap" | "stuck" | "llm-error" | "aborted";
29
+ export interface PlanInput {
30
+ /** UNTRUSTED DATA (PRM-01). Never concatenated into the instruction section. */
31
+ readonly goal: string;
32
+ readonly signal?: AbortSignal;
33
+ }
34
+ export type PlanOutcome = {
35
+ readonly ok: true;
36
+ readonly plan: Plan;
37
+ readonly steps: number;
38
+ readonly duplicateDetections: number;
39
+ readonly trace: readonly PlannerTraceEntry[];
40
+ } | {
41
+ readonly ok: false;
42
+ readonly reason: PlannerFailure;
43
+ readonly errors: readonly string[];
44
+ readonly steps: number;
45
+ readonly duplicateDetections: number;
46
+ readonly trace: readonly PlannerTraceEntry[];
47
+ };
48
+ export interface MasterOrchestratorOptions {
49
+ readonly llm: LlmClient;
50
+ /** MUST be `NO_TOOLS`; anything else throws in the constructor. */
51
+ readonly tools: ToolRegistry;
52
+ /** Carried for reporting/framing only — never used to authorize anything. */
53
+ readonly secure?: SecureGate;
54
+ /** Default 3 (AI-09). */
55
+ readonly maxPlanSteps?: number;
56
+ /** Default 8, never above `MAX_SUBTASKS_HARD_CAP` (AI-09). */
57
+ readonly maxSubtasks?: number;
58
+ /** Default 5 (reuse the detector's default). */
59
+ readonly duplicateAbortAfter?: number;
60
+ /** Trusted product-specific planning constraints appended to the planner rules. */
61
+ readonly planningContext?: string;
62
+ readonly emit?: (entry: PlannerTraceEntry) => void;
63
+ }
64
+ export declare class MasterOrchestrator {
65
+ private readonly llm;
66
+ private readonly maxPlanSteps;
67
+ private readonly maxSubtasks;
68
+ private readonly duplicateAbortAfter;
69
+ private readonly planningContext?;
70
+ private readonly emit?;
71
+ /** Structurally zero: there is no tool surface to widen. */
72
+ readonly toolCount: 0;
73
+ constructor(opts: MasterOrchestratorOptions);
74
+ /** Never throws. Every failure is a typed outcome. */
75
+ plan(input: PlanInput): Promise<PlanOutcome>;
76
+ private record;
77
+ }