nubos-pilot 0.1.0
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/agents/np-ai-researcher.md +140 -0
- package/agents/np-code-fixer.md +363 -0
- package/agents/np-code-reviewer.md +351 -0
- package/agents/np-domain-researcher.md +136 -0
- package/agents/np-eval-auditor.md +167 -0
- package/agents/np-eval-planner.md +153 -0
- package/agents/np-executor.md +72 -0
- package/agents/np-framework-selector.md +171 -0
- package/agents/np-nyquist-auditor.md +185 -0
- package/agents/np-plan-checker.md +165 -0
- package/agents/np-planner.md +199 -0
- package/agents/np-researcher.md +150 -0
- package/agents/np-security-auditor.md +206 -0
- package/agents/np-ui-auditor.md +369 -0
- package/agents/np-ui-checker.md +192 -0
- package/agents/np-ui-researcher.md +324 -0
- package/agents/np-verifier.md +79 -0
- package/bin/check-coverage.cjs +40 -0
- package/bin/check-workflows.cjs +171 -0
- package/bin/check-workflows.test.cjs +208 -0
- package/bin/install.js +500 -0
- package/bin/np-tools/_commands.cjs +70 -0
- package/bin/np-tools/add-tests.cjs +171 -0
- package/bin/np-tools/add-tests.test.cjs +122 -0
- package/bin/np-tools/add-todo.cjs +108 -0
- package/bin/np-tools/add-todo.test.cjs +112 -0
- package/bin/np-tools/agent-skills.cjs +14 -0
- package/bin/np-tools/agent-skills.test.cjs +42 -0
- package/bin/np-tools/ai-integration-phase.cjs +109 -0
- package/bin/np-tools/ai-integration-phase.test.cjs +123 -0
- package/bin/np-tools/askuser.cjs +53 -0
- package/bin/np-tools/askuser.test.cjs +49 -0
- package/bin/np-tools/autonomous.cjs +69 -0
- package/bin/np-tools/autonomous.test.cjs +74 -0
- package/bin/np-tools/checkpoint.cjs +101 -0
- package/bin/np-tools/checkpoint.test.cjs +119 -0
- package/bin/np-tools/code-review.cjs +133 -0
- package/bin/np-tools/code-review.test.cjs +96 -0
- package/bin/np-tools/commit-task.cjs +120 -0
- package/bin/np-tools/commit-task.test.cjs +160 -0
- package/bin/np-tools/commit.cjs +103 -0
- package/bin/np-tools/commit.test.cjs +93 -0
- package/bin/np-tools/config.cjs +101 -0
- package/bin/np-tools/config.test.cjs +71 -0
- package/bin/np-tools/discuss-phase-power.cjs +265 -0
- package/bin/np-tools/discuss-phase-power.test.cjs +242 -0
- package/bin/np-tools/discuss-phase.cjs +132 -0
- package/bin/np-tools/discuss-phase.test.cjs +148 -0
- package/bin/np-tools/dispatch.cjs +116 -0
- package/bin/np-tools/doctor.cjs +242 -0
- package/bin/np-tools/eval-review.cjs +116 -0
- package/bin/np-tools/eval-review.test.cjs +123 -0
- package/bin/np-tools/execute-phase.cjs +182 -0
- package/bin/np-tools/execute-phase.test.cjs +116 -0
- package/bin/np-tools/execute-plan.cjs +124 -0
- package/bin/np-tools/execute-plan.test.cjs +82 -0
- package/bin/np-tools/help.cjs +28 -0
- package/bin/np-tools/help.test.cjs +29 -0
- package/bin/np-tools/init-dispatch.test.cjs +91 -0
- package/bin/np-tools/metrics.cjs +97 -0
- package/bin/np-tools/metrics.test.cjs +188 -0
- package/bin/np-tools/new-milestone.cjs +288 -0
- package/bin/np-tools/new-milestone.test.cjs +166 -0
- package/bin/np-tools/new-project.cjs +284 -0
- package/bin/np-tools/new-project.test.cjs +165 -0
- package/bin/np-tools/next.cjs +7 -0
- package/bin/np-tools/next.test.cjs +30 -0
- package/bin/np-tools/park.cjs +48 -0
- package/bin/np-tools/park.test.cjs +50 -0
- package/bin/np-tools/pause-work.cjs +24 -0
- package/bin/np-tools/pause-work.test.cjs +74 -0
- package/bin/np-tools/phase.cjs +71 -0
- package/bin/np-tools/phase.test.cjs +81 -0
- package/bin/np-tools/plan-diff.cjs +57 -0
- package/bin/np-tools/plan-diff.test.cjs +134 -0
- package/bin/np-tools/plan-milestone-gaps.cjs +115 -0
- package/bin/np-tools/plan-milestone-gaps.test.cjs +122 -0
- package/bin/np-tools/plan-phase.cjs +350 -0
- package/bin/np-tools/plan-phase.test.cjs +263 -0
- package/bin/np-tools/progress.cjs +7 -0
- package/bin/np-tools/progress.test.cjs +44 -0
- package/bin/np-tools/queue.cjs +213 -0
- package/bin/np-tools/research-phase.cjs +144 -0
- package/bin/np-tools/research-phase.test.cjs +154 -0
- package/bin/np-tools/reset-slice.cjs +17 -0
- package/bin/np-tools/reset-slice.test.cjs +96 -0
- package/bin/np-tools/resolve-model.cjs +110 -0
- package/bin/np-tools/resolve-model.test.cjs +200 -0
- package/bin/np-tools/resume-work.cjs +76 -0
- package/bin/np-tools/resume-work.test.cjs +91 -0
- package/bin/np-tools/skip.cjs +48 -0
- package/bin/np-tools/skip.test.cjs +66 -0
- package/bin/np-tools/slug.cjs +34 -0
- package/bin/np-tools/slug.test.cjs +46 -0
- package/bin/np-tools/state.cjs +16 -0
- package/bin/np-tools/state.test.cjs +40 -0
- package/bin/np-tools/stats.cjs +151 -0
- package/bin/np-tools/stats.test.cjs +118 -0
- package/bin/np-tools/triage.cjs +128 -0
- package/bin/np-tools/ui-phase.cjs +108 -0
- package/bin/np-tools/ui-phase.test.cjs +121 -0
- package/bin/np-tools/ui-review.cjs +108 -0
- package/bin/np-tools/ui-review.test.cjs +120 -0
- package/bin/np-tools/undo-task.cjs +31 -0
- package/bin/np-tools/undo-task.test.cjs +117 -0
- package/bin/np-tools/undo.cjs +43 -0
- package/bin/np-tools/undo.test.cjs +120 -0
- package/bin/np-tools/unpark.cjs +48 -0
- package/bin/np-tools/unpark.test.cjs +50 -0
- package/bin/np-tools/verify-work.cjs +186 -0
- package/bin/np-tools/verify-work.test.cjs +97 -0
- package/docs/adr/0001-no-daemon-invariant.md +82 -0
- package/docs/adr/0002-zero-runtime-dependencies.md +90 -0
- package/docs/adr/0003-max-six-unit-types.md +85 -0
- package/docs/adr/0004-atomic-commit-per-unit.md +102 -0
- package/docs/adr/0005-three-orthogonal-file-trees.md +98 -0
- package/docs/adr/0006-yaml-dependency-amendment.md +60 -0
- package/docs/adr/README.md +27 -0
- package/docs/agent-frontmatter-schema.md +84 -0
- package/docs/phase-artifact-schemas.md +292 -0
- package/docs/phase-directory-layout.md +82 -0
- package/lib/__tests__/README.md +1 -0
- package/lib/agents.cjs +98 -0
- package/lib/agents.test.cjs +286 -0
- package/lib/askuser.cjs +36 -0
- package/lib/askuser.test.cjs +310 -0
- package/lib/checkpoint.cjs +135 -0
- package/lib/checkpoint.test.cjs +184 -0
- package/lib/core.cjs +165 -0
- package/lib/core.test.cjs +405 -0
- package/lib/fixtures/README.md +1 -0
- package/lib/fixtures/phase-tree/README.md +1 -0
- package/lib/fixtures/plans/cycle/PLAN.md +16 -0
- package/lib/fixtures/plans/cycle/tasks/T-01.md +20 -0
- package/lib/fixtures/plans/cycle/tasks/T-02.md +20 -0
- package/lib/fixtures/plans/cycle/tasks/T-03.md +20 -0
- package/lib/fixtures/plans/linear/PLAN.md +16 -0
- package/lib/fixtures/plans/linear/tasks/T-01.md +20 -0
- package/lib/fixtures/plans/linear/tasks/T-02.md +20 -0
- package/lib/fixtures/plans/linear/tasks/T-03.md +20 -0
- package/lib/fixtures/plans/parallel/PLAN.md +16 -0
- package/lib/fixtures/plans/parallel/tasks/T-01.md +20 -0
- package/lib/fixtures/plans/parallel/tasks/T-02.md +20 -0
- package/lib/fixtures/plans/parallel/tasks/T-03.md +20 -0
- package/lib/fixtures/plans/wave-conflict/PLAN.md +16 -0
- package/lib/fixtures/plans/wave-conflict/tasks/T-01.md +20 -0
- package/lib/fixtures/plans/wave-conflict/tasks/T-02.md +20 -0
- package/lib/fixtures/roadmap/ROADMAP-malformed.md +3 -0
- package/lib/fixtures/roadmap/ROADMAP-minimal.md +51 -0
- package/lib/fixtures/roadmap/roadmap-malformed.yaml +7 -0
- package/lib/fixtures/roadmap/roadmap-minimal.yaml +40 -0
- package/lib/fixtures/roadmap/roadmap-ten-phases.yaml +101 -0
- package/lib/fixtures/templates/phase-context.md +6 -0
- package/lib/fixtures/templates/plan-skeleton.md +6 -0
- package/lib/frontmatter.cjs +251 -0
- package/lib/frontmatter.test.cjs +177 -0
- package/lib/gaps.cjs +197 -0
- package/lib/gaps.test.cjs +200 -0
- package/lib/git.cjs +207 -0
- package/lib/git.test.cjs +305 -0
- package/lib/install/agents-md.cjs +77 -0
- package/lib/install/backup.cjs +70 -0
- package/lib/install/codex-toml.cjs +440 -0
- package/lib/install/managed-block.cjs +30 -0
- package/lib/install/manifest.cjs +148 -0
- package/lib/install/mcp-writer.cjs +127 -0
- package/lib/install/runtime-detect.cjs +44 -0
- package/lib/install/staging.cjs +149 -0
- package/lib/metrics-aggregate.cjs +229 -0
- package/lib/metrics-aggregate.test.cjs +192 -0
- package/lib/metrics.cjs +120 -0
- package/lib/metrics.test.cjs +182 -0
- package/lib/model-aliases.regression.test.cjs +16 -0
- package/lib/model-profiles.cjs +42 -0
- package/lib/model-profiles.test.cjs +61 -0
- package/lib/next.cjs +236 -0
- package/lib/next.test.cjs +194 -0
- package/lib/phase.cjs +95 -0
- package/lib/phase.test.cjs +189 -0
- package/lib/plan-checker-contract.test.cjs +72 -0
- package/lib/plan-diff.cjs +173 -0
- package/lib/plan-diff.test.cjs +217 -0
- package/lib/plan.cjs +85 -0
- package/lib/plan.test.cjs +263 -0
- package/lib/progress.cjs +95 -0
- package/lib/progress.test.cjs +116 -0
- package/lib/researcher-contract.test.cjs +61 -0
- package/lib/roadmap-render.cjs +206 -0
- package/lib/roadmap-render.test.cjs +121 -0
- package/lib/roadmap.cjs +416 -0
- package/lib/roadmap.test.cjs +371 -0
- package/lib/runtime/_contract.test.cjs +61 -0
- package/lib/runtime/_readline.cjs +119 -0
- package/lib/runtime/_readline.test.cjs +126 -0
- package/lib/runtime/claude.cjs +48 -0
- package/lib/runtime/claude.test.cjs +101 -0
- package/lib/runtime/codex.cjs +35 -0
- package/lib/runtime/codex.test.cjs +114 -0
- package/lib/runtime/gemini.cjs +35 -0
- package/lib/runtime/gemini.test.cjs +109 -0
- package/lib/runtime/index.cjs +49 -0
- package/lib/runtime/index.test.cjs +181 -0
- package/lib/runtime/opencode.cjs +35 -0
- package/lib/runtime/opencode.test.cjs +124 -0
- package/lib/state.cjs +205 -0
- package/lib/state.test.cjs +264 -0
- package/lib/surface-audit.test.cjs +46 -0
- package/lib/tasks.cjs +327 -0
- package/lib/tasks.test.cjs +389 -0
- package/lib/template.cjs +66 -0
- package/lib/template.test.cjs +159 -0
- package/lib/undo.cjs +179 -0
- package/lib/undo.test.cjs +261 -0
- package/lib/verify.cjs +116 -0
- package/lib/verify.test.cjs +187 -0
- package/np-tools.cjs +303 -0
- package/package.json +39 -0
- package/templates/AI-SPEC.md +90 -0
- package/templates/CONTEXT.md +32 -0
- package/templates/PLAN.md +69 -0
- package/templates/PROJECT.md +60 -0
- package/templates/REQUIREMENTS.md +38 -0
- package/templates/SECURITY.md +61 -0
- package/templates/UI-SPEC.md +64 -0
- package/templates/VALIDATION.md +76 -0
- package/templates/claude/payload/README.md +11 -0
- package/templates/opencode/opencode.json +6 -0
- package/templates/opencode/payload/AGENTS.md +9 -0
- package/workflows/add-backlog.md +212 -0
- package/workflows/add-tests.md +69 -0
- package/workflows/add-todo.md +222 -0
- package/workflows/ai-integration-phase.md +230 -0
- package/workflows/autonomous.md +94 -0
- package/workflows/cleanup.md +325 -0
- package/workflows/code-review-fix.md +435 -0
- package/workflows/code-review.md +447 -0
- package/workflows/discuss-phase-assumptions.md +269 -0
- package/workflows/discuss-phase-power.md +139 -0
- package/workflows/discuss-phase.md +386 -0
- package/workflows/dispatch.md +9 -0
- package/workflows/doctor.md +10 -0
- package/workflows/eval-review.md +243 -0
- package/workflows/execute-phase.md +142 -0
- package/workflows/execute-plan.md +82 -0
- package/workflows/help.md +8 -0
- package/workflows/new-milestone.md +166 -0
- package/workflows/new-project.md +213 -0
- package/workflows/next.md +8 -0
- package/workflows/note.md +244 -0
- package/workflows/park.md +29 -0
- package/workflows/pause-work.md +34 -0
- package/workflows/plan-milestone-gaps.md +233 -0
- package/workflows/plan-phase.md +351 -0
- package/workflows/progress.md +8 -0
- package/workflows/queue.md +9 -0
- package/workflows/research-phase.md +327 -0
- package/workflows/reset-slice.md +39 -0
- package/workflows/resume-work.md +79 -0
- package/workflows/review.md +489 -0
- package/workflows/secure-phase.md +209 -0
- package/workflows/session-report.md +243 -0
- package/workflows/skip.md +29 -0
- package/workflows/state.md +7 -0
- package/workflows/stats.md +170 -0
- package/workflows/thread.md +214 -0
- package/workflows/triage.md +9 -0
- package/workflows/ui-phase.md +246 -0
- package/workflows/ui-review.md +222 -0
- package/workflows/undo-task.md +42 -0
- package/workflows/undo.md +55 -0
- package/workflows/unpark.md +29 -0
- package/workflows/validate-phase.md +231 -0
- package/workflows/verify-work.md +83 -0
package/lib/next.cjs
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { readState } = require('./state.cjs');
|
|
4
|
+
const { parseRoadmap } = require('./roadmap.cjs');
|
|
5
|
+
const { findPhaseDir, paddedPhase } = require('./phase.cjs');
|
|
6
|
+
const { listPlans } = require('./plan.cjs');
|
|
7
|
+
const { loadTaskGraph } = require('./tasks.cjs');
|
|
8
|
+
const { NubosPilotError } = require('./core.cjs');
|
|
9
|
+
|
|
10
|
+
function _safeReadState(cwd) {
|
|
11
|
+
try {
|
|
12
|
+
return readState(cwd);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (err && err.code === 'ENOENT') return null;
|
|
15
|
+
|
|
16
|
+
if (err && typeof err === 'object' && err.code === 'schema-version-mismatch') throw err;
|
|
17
|
+
|
|
18
|
+
if (err && err.code && String(err.code).startsWith('ENOENT')) return null;
|
|
19
|
+
|
|
20
|
+
if (err && err.message && /ENOENT/.test(err.message)) return null;
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _safeParseRoadmap(cwd) {
|
|
26
|
+
try {
|
|
27
|
+
return parseRoadmap(cwd);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (err && err.code === 'roadmap-parse-error') return null;
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _firstPendingPhase(roadmap) {
|
|
35
|
+
if (!roadmap || !Array.isArray(roadmap.phases) || roadmap.phases.length === 0) return null;
|
|
36
|
+
for (const p of roadmap.phases) {
|
|
37
|
+
if (!p.complete) return Number(p.number);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _phaseDirFor(n, cwd) {
|
|
43
|
+
try {
|
|
44
|
+
return findPhaseDir(n, cwd);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (err && err.code === 'not-in-project') return null;
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _hasContext(phaseDir, n) {
|
|
53
|
+
if (!phaseDir) return false;
|
|
54
|
+
const padded = paddedPhase(n);
|
|
55
|
+
return fs.existsSync(path.join(phaseDir, padded + '-CONTEXT.md'));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _hasVerification(phaseDir, n) {
|
|
59
|
+
if (!phaseDir) return false;
|
|
60
|
+
const padded = paddedPhase(n);
|
|
61
|
+
return fs.existsSync(path.join(phaseDir, padded + '-VERIFICATION.md'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _phasePlanPaths(phaseDir) {
|
|
65
|
+
if (!phaseDir) return [];
|
|
66
|
+
return listPlans(phaseDir);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _firstPendingTaskPointer(phaseDir) {
|
|
70
|
+
const plans = _phasePlanPaths(phaseDir);
|
|
71
|
+
if (plans.length === 0) return null;
|
|
72
|
+
|
|
73
|
+
const planDir = path.dirname(plans[0]);
|
|
74
|
+
let tg;
|
|
75
|
+
try {
|
|
76
|
+
tg = loadTaskGraph(planDir);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
if (!tg.tasks || tg.tasks.length === 0) return null;
|
|
83
|
+
if (!tg.waves || tg.waves.length === 0) return null;
|
|
84
|
+
const firstWaveIds = tg.waves[0];
|
|
85
|
+
const pendingInWave = firstWaveIds
|
|
86
|
+
.map((id) => tg.tasks.find((t) => t.id === id))
|
|
87
|
+
.filter((t) => t && t.frontmatter && t.frontmatter.status !== 'done')
|
|
88
|
+
.sort((a, b) => a.frontmatter.id.localeCompare(b.frontmatter.id));
|
|
89
|
+
if (pendingInWave.length === 0) return null;
|
|
90
|
+
const pick = pendingInWave[0];
|
|
91
|
+
return {
|
|
92
|
+
id: pick.frontmatter.id,
|
|
93
|
+
owner: pick.frontmatter.owner,
|
|
94
|
+
tier: pick.frontmatter.tier,
|
|
95
|
+
wave: typeof pick.frontmatter.wave === 'number' ? pick.frontmatter.wave : 1,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function _allTasksDone(phaseDir) {
|
|
100
|
+
const plans = _phasePlanPaths(phaseDir);
|
|
101
|
+
if (plans.length === 0) return false;
|
|
102
|
+
for (const planPath of plans) {
|
|
103
|
+
const planDir = path.dirname(planPath);
|
|
104
|
+
let tg;
|
|
105
|
+
try { tg = loadTaskGraph(planDir); }
|
|
106
|
+
catch { return false; }
|
|
107
|
+
if (!tg.tasks || tg.tasks.length === 0) return false;
|
|
108
|
+
for (const t of tg.tasks) {
|
|
109
|
+
if (!t.frontmatter || t.frontmatter.status !== 'done') return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function resolveGate(phaseN, cwd) {
|
|
116
|
+
const phaseDir = _phaseDirFor(phaseN, cwd);
|
|
117
|
+
if (!_hasContext(phaseDir, phaseN)) return { rule: 1 };
|
|
118
|
+
const plans = _phasePlanPaths(phaseDir);
|
|
119
|
+
if (plans.length === 0) return { rule: 2 };
|
|
120
|
+
if (!_allTasksDone(phaseDir)) {
|
|
121
|
+
const task = _firstPendingTaskPointer(phaseDir);
|
|
122
|
+
return { rule: 3, task };
|
|
123
|
+
}
|
|
124
|
+
if (!_hasVerification(phaseDir, phaseN)) return { rule: 4 };
|
|
125
|
+
return { rule: 5 };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function _shapeForRule(gate, n) {
|
|
129
|
+
switch (gate.rule) {
|
|
130
|
+
case 1:
|
|
131
|
+
return {
|
|
132
|
+
next_step: { command: `/np:discuss-phase ${n}`, reason: `Phase ${n} has no CONTEXT.md` },
|
|
133
|
+
task: null,
|
|
134
|
+
phase: n,
|
|
135
|
+
plan: null,
|
|
136
|
+
};
|
|
137
|
+
case 2:
|
|
138
|
+
return {
|
|
139
|
+
next_step: { command: `/np:plan-phase ${n}`, reason: `Phase ${n} has CONTEXT.md but no PLAN.md yet` },
|
|
140
|
+
task: null,
|
|
141
|
+
phase: n,
|
|
142
|
+
plan: null,
|
|
143
|
+
};
|
|
144
|
+
case 3: {
|
|
145
|
+
const task = gate.task || null;
|
|
146
|
+
const planFromTask = task && task.id ? task.id.slice(0, 5) : null;
|
|
147
|
+
return {
|
|
148
|
+
next_step: { command: `/np:execute-phase ${n}`, reason: `Phase ${n} has pending tasks` },
|
|
149
|
+
task,
|
|
150
|
+
phase: n,
|
|
151
|
+
plan: planFromTask,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
case 4:
|
|
155
|
+
return {
|
|
156
|
+
next_step: { command: `/np:verify-work ${n}`, reason: `Phase ${n} tasks all done — awaiting verification` },
|
|
157
|
+
task: null,
|
|
158
|
+
phase: n,
|
|
159
|
+
plan: null,
|
|
160
|
+
};
|
|
161
|
+
default:
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function computeNextStep(cwd = process.cwd()) {
|
|
167
|
+
try {
|
|
168
|
+
const roadmap = _safeParseRoadmap(cwd);
|
|
169
|
+
|
|
170
|
+
if (!roadmap) {
|
|
171
|
+
return _shapeForRule({ rule: 1 }, 1);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
let phaseN;
|
|
176
|
+
const state = _safeReadState(cwd);
|
|
177
|
+
const cur = state && state.frontmatter ? state.frontmatter.current_phase : null;
|
|
178
|
+
if (cur != null && Number.isFinite(Number(cur))) {
|
|
179
|
+
phaseN = Number(cur);
|
|
180
|
+
} else {
|
|
181
|
+
const first = _firstPendingPhase(roadmap);
|
|
182
|
+
if (first == null) {
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
next_step: { command: '/np:complete-milestone', reason: 'All phases complete' },
|
|
186
|
+
task: null,
|
|
187
|
+
phase: null,
|
|
188
|
+
plan: null,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
phaseN = first;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const gate = resolveGate(phaseN, cwd);
|
|
195
|
+
if (gate.rule !== 5) {
|
|
196
|
+
return _shapeForRule(gate, phaseN);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const idx = roadmap.phases.findIndex((p) => Number(p.number) === phaseN);
|
|
200
|
+
let nextPending = null;
|
|
201
|
+
for (let i = idx + 1; i < roadmap.phases.length; i++) {
|
|
202
|
+
if (!roadmap.phases[i].complete) {
|
|
203
|
+
nextPending = Number(roadmap.phases[i].number);
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (nextPending == null) {
|
|
208
|
+
return {
|
|
209
|
+
next_step: { command: '/np:complete-milestone', reason: 'All phases complete' },
|
|
210
|
+
task: null,
|
|
211
|
+
phase: null,
|
|
212
|
+
plan: null,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const gate2 = resolveGate(nextPending, cwd);
|
|
217
|
+
if (gate2.rule === 5) {
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
next_step: { command: `/np:plan-phase ${nextPending}`, reason: 'Next phase ready for planning' },
|
|
222
|
+
task: null, phase: nextPending, plan: null,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return _shapeForRule(gate2, nextPending);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
if (err && err.code) throw err;
|
|
228
|
+
throw new NubosPilotError(
|
|
229
|
+
'next-internal-error',
|
|
230
|
+
`computeNextStep failed: ${err && err.message}`,
|
|
231
|
+
{ cause: err && err.message },
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
module.exports = { computeNextStep, resolveGate };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const { test, afterEach } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
|
|
7
|
+
const next = require('./next.cjs');
|
|
8
|
+
|
|
9
|
+
const sandboxes = [];
|
|
10
|
+
|
|
11
|
+
function makeSandbox() {
|
|
12
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'np-next-test-'));
|
|
13
|
+
fs.mkdirSync(path.join(root, '.nubos-pilot'));
|
|
14
|
+
sandboxes.push(root);
|
|
15
|
+
return root;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function writeState(root, fm) {
|
|
19
|
+
const lines = ['---'];
|
|
20
|
+
for (const k of Object.keys(fm)) {
|
|
21
|
+
const v = fm[k];
|
|
22
|
+
if (v !== null && typeof v === 'object' && !Array.isArray(v)) {
|
|
23
|
+
lines.push(`${k}:`);
|
|
24
|
+
for (const nk of Object.keys(v)) lines.push(` ${nk}: ${v[nk] == null ? 'null' : v[nk]}`);
|
|
25
|
+
} else {
|
|
26
|
+
lines.push(`${k}: ${v == null ? 'null' : v}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
lines.push('---', '', '');
|
|
30
|
+
fs.writeFileSync(path.join(root, '.nubos-pilot', 'STATE.md'), lines.join('\n'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function writeRoadmap(root, phases) {
|
|
34
|
+
const ms = {
|
|
35
|
+
schema_version: 1,
|
|
36
|
+
milestones: [{ id: 'v1.0', name: 'milestone', phases }],
|
|
37
|
+
};
|
|
38
|
+
const YAML = require('yaml');
|
|
39
|
+
fs.writeFileSync(path.join(root, '.nubos-pilot', 'roadmap.yaml'), YAML.stringify(ms, { indent: 2 }));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function mkPhase(root, n, slug, { context = false, plan = false, tasks = null, verification = false } = {}) {
|
|
43
|
+
const padded = String(n).padStart(2, '0');
|
|
44
|
+
const dir = path.join(root, '.nubos-pilot', 'phases', padded + '-' + slug);
|
|
45
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
46
|
+
if (context) fs.writeFileSync(path.join(dir, padded + '-CONTEXT.md'), '# ctx\n');
|
|
47
|
+
if (plan) fs.writeFileSync(path.join(dir, padded + '-01-PLAN.md'), '---\nphase: ' + n + '\nplan: "' + padded + '-01"\n---\nbody\n');
|
|
48
|
+
if (verification) fs.writeFileSync(path.join(dir, padded + '-VERIFICATION.md'), '# verify\n');
|
|
49
|
+
if (tasks) {
|
|
50
|
+
const tdir = path.join(dir, 'tasks');
|
|
51
|
+
fs.mkdirSync(tdir, { recursive: true });
|
|
52
|
+
for (const t of tasks) {
|
|
53
|
+
const body =
|
|
54
|
+
'---\n' +
|
|
55
|
+
`id: ${padded}-01-T${String(t.num).padStart(2, '0')}\n` +
|
|
56
|
+
`status: ${t.status || 'pending'}\n` +
|
|
57
|
+
'tier: sonnet\n' +
|
|
58
|
+
'owner: np-executor\n' +
|
|
59
|
+
`phase: ${n}\n` +
|
|
60
|
+
`plan: ${padded}-01\n` +
|
|
61
|
+
'type: execute\n' +
|
|
62
|
+
`wave: ${t.wave || 1}\n` +
|
|
63
|
+
`depends_on: ${t.depends_on ? JSON.stringify(t.depends_on) : '[]'}\n` +
|
|
64
|
+
'files_modified: []\n' +
|
|
65
|
+
'autonomous: true\n' +
|
|
66
|
+
'must_haves:\n truths: []\n artifacts: []\n key_links: []\n' +
|
|
67
|
+
'---\nbody\n';
|
|
68
|
+
fs.writeFileSync(path.join(tdir, `T-${String(t.num).padStart(2, '0')}.md`), body);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return dir;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
afterEach(() => {
|
|
75
|
+
while (sandboxes.length) {
|
|
76
|
+
const p = sandboxes.pop();
|
|
77
|
+
try { fs.rmSync(p, { recursive: true, force: true }); } catch {}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('N1 (rule 1): phase missing CONTEXT.md → discuss-phase', () => {
|
|
82
|
+
const root = makeSandbox();
|
|
83
|
+
writeRoadmap(root, [{ number: 1, name: 'Foundation', slug: 'foundation', status: 'pending' }]);
|
|
84
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
85
|
+
|
|
86
|
+
const out = next.computeNextStep(root);
|
|
87
|
+
assert.equal(out.next_step.command, '/np:discuss-phase 1');
|
|
88
|
+
assert.equal(out.task, null);
|
|
89
|
+
assert.equal(out.phase, 1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('N2 (rule 2): CONTEXT.md exists but no PLAN.md → plan-phase', () => {
|
|
93
|
+
const root = makeSandbox();
|
|
94
|
+
writeRoadmap(root, [{ number: 1, name: 'Foundation', slug: 'foundation', status: 'pending' }]);
|
|
95
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
96
|
+
mkPhase(root, 1, 'foundation', { context: true });
|
|
97
|
+
const out = next.computeNextStep(root);
|
|
98
|
+
assert.equal(out.next_step.command, '/np:plan-phase 1');
|
|
99
|
+
assert.equal(out.task, null);
|
|
100
|
+
assert.equal(out.phase, 1);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('N3 (rule 3): PLAN.md exists + pending tasks → execute-phase + task pointer', () => {
|
|
104
|
+
const root = makeSandbox();
|
|
105
|
+
writeRoadmap(root, [{ number: 1, name: 'Foundation', slug: 'foundation', status: 'pending' }]);
|
|
106
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
107
|
+
mkPhase(root, 1, 'foundation', {
|
|
108
|
+
context: true,
|
|
109
|
+
plan: true,
|
|
110
|
+
tasks: [
|
|
111
|
+
{ num: 1, status: 'pending', wave: 1 },
|
|
112
|
+
{ num: 2, status: 'pending', wave: 1, depends_on: ['T-01'] },
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
const out = next.computeNextStep(root);
|
|
116
|
+
assert.equal(out.next_step.command, '/np:execute-phase 1');
|
|
117
|
+
assert.ok(out.task);
|
|
118
|
+
assert.equal(out.task.id, '01-01-T01', 'task.id comes from frontmatter.id');
|
|
119
|
+
assert.equal(out.task.owner, 'np-executor');
|
|
120
|
+
assert.equal(out.task.tier, 'sonnet');
|
|
121
|
+
assert.equal(out.task.wave, 1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('N4 (rule 4): all tasks done but no VERIFICATION.md → verify-work', () => {
|
|
125
|
+
const root = makeSandbox();
|
|
126
|
+
writeRoadmap(root, [{ number: 1, name: 'Foundation', slug: 'foundation', status: 'pending' }]);
|
|
127
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
128
|
+
mkPhase(root, 1, 'foundation', {
|
|
129
|
+
context: true,
|
|
130
|
+
plan: true,
|
|
131
|
+
tasks: [{ num: 1, status: 'done', wave: 1 }],
|
|
132
|
+
});
|
|
133
|
+
const out = next.computeNextStep(root);
|
|
134
|
+
assert.equal(out.next_step.command, '/np:verify-work 1');
|
|
135
|
+
assert.equal(out.task, null);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('N5 (rule 5): phase done+verified → next phase rules recursed', () => {
|
|
139
|
+
const root = makeSandbox();
|
|
140
|
+
writeRoadmap(root, [
|
|
141
|
+
{ number: 1, name: 'Foundation', slug: 'foundation', status: 'done' },
|
|
142
|
+
{ number: 2, name: 'Second', slug: 'second', status: 'pending' },
|
|
143
|
+
]);
|
|
144
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
145
|
+
mkPhase(root, 1, 'foundation', {
|
|
146
|
+
context: true, plan: true, verification: true,
|
|
147
|
+
tasks: [{ num: 1, status: 'done', wave: 1 }],
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const out = next.computeNextStep(root);
|
|
151
|
+
assert.equal(out.next_step.command, '/np:discuss-phase 2');
|
|
152
|
+
assert.equal(out.phase, 2);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('N6 (rule 6): all phases done → complete-milestone', () => {
|
|
156
|
+
const root = makeSandbox();
|
|
157
|
+
writeRoadmap(root, [
|
|
158
|
+
{ number: 1, name: 'Foundation', slug: 'foundation', status: 'done' },
|
|
159
|
+
]);
|
|
160
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
161
|
+
mkPhase(root, 1, 'foundation', {
|
|
162
|
+
context: true, plan: true, verification: true,
|
|
163
|
+
tasks: [{ num: 1, status: 'done', wave: 1 }],
|
|
164
|
+
});
|
|
165
|
+
const out = next.computeNextStep(root);
|
|
166
|
+
assert.equal(out.next_step.command, '/np:complete-milestone');
|
|
167
|
+
assert.equal(out.task, null);
|
|
168
|
+
assert.equal(out.phase, null);
|
|
169
|
+
assert.equal(out.plan, null);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('N7: fresh project (no STATE.md, no roadmap.yaml) → rule 1 for phase 1 (Pattern S-7)', () => {
|
|
173
|
+
const root = makeSandbox();
|
|
174
|
+
|
|
175
|
+
const out = next.computeNextStep(root);
|
|
176
|
+
assert.equal(out.next_step.command, '/np:discuss-phase 1');
|
|
177
|
+
assert.equal(out.phase, 1);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('N8: rule 3 deterministic task pointer = lexicographically-first pending in waves[0]', () => {
|
|
181
|
+
const root = makeSandbox();
|
|
182
|
+
writeRoadmap(root, [{ number: 1, name: 'Foundation', slug: 'foundation', status: 'pending' }]);
|
|
183
|
+
writeState(root, { schema_version: 2, current_phase: 1, current_plan: null, current_task: null });
|
|
184
|
+
mkPhase(root, 1, 'foundation', {
|
|
185
|
+
context: true, plan: true,
|
|
186
|
+
tasks: [
|
|
187
|
+
{ num: 2, status: 'pending', wave: 1 },
|
|
188
|
+
{ num: 1, status: 'pending', wave: 1 },
|
|
189
|
+
{ num: 3, status: 'pending', wave: 1, depends_on: ['T-01'] },
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
const out = next.computeNextStep(root);
|
|
193
|
+
assert.equal(out.task.id, '01-01-T01');
|
|
194
|
+
});
|
package/lib/phase.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { projectStateDir, withFileLock, NubosPilotError } = require('./core.cjs');
|
|
4
|
+
|
|
5
|
+
function paddedPhase(n) {
|
|
6
|
+
const s = String(n);
|
|
7
|
+
const m = s.match(/^(\d+)(\.\d+)?$/);
|
|
8
|
+
if (!m) {
|
|
9
|
+
throw new NubosPilotError(
|
|
10
|
+
'phase-not-found',
|
|
11
|
+
'Invalid phase number: ' + s,
|
|
12
|
+
{ got: n }
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return m[1].padStart(2, '0') + (m[2] || '');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function phaseSlug(name) {
|
|
19
|
+
return String(name)
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
22
|
+
.replace(/^-+|-+$/g, '');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _listPhaseEntries(phasesRoot) {
|
|
26
|
+
try {
|
|
27
|
+
return fs.readdirSync(phasesRoot, { withFileTypes: true });
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (err && err.code === 'ENOENT') return null;
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function findPhaseDir(n, cwd = process.cwd()) {
|
|
35
|
+
const padded = paddedPhase(n);
|
|
36
|
+
const phasesRoot = path.join(projectStateDir(cwd), 'phases');
|
|
37
|
+
const entries = _listPhaseEntries(phasesRoot);
|
|
38
|
+
if (entries === null) return null;
|
|
39
|
+
|
|
40
|
+
const matches = entries
|
|
41
|
+
.filter((e) => e.isDirectory())
|
|
42
|
+
.filter((e) => e.name === padded || e.name.startsWith(padded + '-'))
|
|
43
|
+
.map((e) => e.name)
|
|
44
|
+
.sort((a, b) => b.length - a.length);
|
|
45
|
+
|
|
46
|
+
if (matches.length === 0) return null;
|
|
47
|
+
return path.join(phasesRoot, matches[0]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _extractSlugTail(name, padded) {
|
|
51
|
+
if (name === padded) return '';
|
|
52
|
+
if (name.startsWith(padded + '-')) return name.slice(padded.length + 1);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createPhaseDir(n, slug, cwd = process.cwd()) {
|
|
57
|
+
const padded = paddedPhase(n);
|
|
58
|
+
const cleanSlug = phaseSlug(slug);
|
|
59
|
+
if (cleanSlug === '') {
|
|
60
|
+
throw new NubosPilotError(
|
|
61
|
+
'phase-not-found',
|
|
62
|
+
'Invalid slug: ' + slug,
|
|
63
|
+
{ slug }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const phasesRoot = path.join(projectStateDir(cwd), 'phases');
|
|
68
|
+
fs.mkdirSync(phasesRoot, { recursive: true });
|
|
69
|
+
|
|
70
|
+
return withFileLock(path.join(phasesRoot, '.phase-create'), () => {
|
|
71
|
+
const entries = _listPhaseEntries(phasesRoot) || [];
|
|
72
|
+
for (const e of entries) {
|
|
73
|
+
if (!e.isDirectory()) continue;
|
|
74
|
+
const tail = _extractSlugTail(e.name, padded);
|
|
75
|
+
if (tail === null) continue;
|
|
76
|
+
const existingPath = path.join(phasesRoot, e.name);
|
|
77
|
+
if (tail === cleanSlug) return existingPath;
|
|
78
|
+
throw new NubosPilotError(
|
|
79
|
+
'phase-slug-mismatch',
|
|
80
|
+
`Phase ${padded} already exists with different slug`,
|
|
81
|
+
{
|
|
82
|
+
padded,
|
|
83
|
+
expected_slug: cleanSlug,
|
|
84
|
+
existing_slug: tail,
|
|
85
|
+
existing_path: existingPath,
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const target = path.join(phasesRoot, padded + '-' + cleanSlug);
|
|
90
|
+
fs.mkdirSync(target, { recursive: true });
|
|
91
|
+
return target;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = { findPhaseDir, createPhaseDir, phaseSlug, paddedPhase };
|