@orion-qa/orion 3.1.0 → 3.3.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/.claude/agents/automation-strategist.md +1 -0
- package/.claude/agents/change-agent.md +1 -0
- package/.claude/agents/codebase-analyst.md +2 -1
- package/.claude/agents/environment-discovery.md +1 -0
- package/.claude/agents/evidence-validator.md +1 -0
- package/.claude/agents/executor.md +1 -0
- package/.claude/agents/failure-analyst.md +2 -1
- package/.claude/agents/implementer.md +2 -1
- package/.claude/agents/requirement-analyst.md +1 -0
- package/.claude/agents/reviewer.md +1 -0
- package/.claude/agents/test-reporter.md +1 -0
- package/.claude/settings.json +17 -0
- package/.claude/skills/architecture-analysis/SKILL.md +1 -1
- package/.claude/skills/automation-implementation/SKILL.md +7 -5
- package/.claude/skills/automation-review/references/assertion-guard.md +1 -1
- package/.claude/skills/code-review/SKILL.md +2 -0
- package/.claude/skills/documentation/SKILL.md +1 -1
- package/.claude/skills/execution/SKILL.md +5 -4
- package/.claude/skills/orion/SKILL.md +12 -7
- package/.claude/skills/orion/references/assess-fix.md +5 -4
- package/.claude/skills/orion/references/batch.md +64 -0
- package/.claude/skills/orion/references/blockers.md +1 -1
- package/.claude/skills/orion/references/conversation.md +56 -25
- package/.claude/skills/orion/references/delivery-formats.md +23 -35
- package/.claude/skills/orion/references/doctor.md +1 -1
- package/.claude/skills/orion/references/greeting.md +23 -0
- package/.claude/skills/orion/references/hosts.md +3 -2
- package/.claude/skills/orion/references/modes.md +4 -2
- package/.claude/skills/orion/references/plain-language.md +57 -0
- package/.claude/skills/orion/references/project-context-files.md +2 -1
- package/.claude/skills/orion/references/recovery-loop.md +8 -0
- package/.claude/skills/orion/references/setup-card.md +18 -3
- package/.claude/skills/orion/references/status-lines.md +10 -4
- package/.claude/skills/orion/scripts/batch_detect.mjs +98 -0
- package/.claude/skills/orion/scripts/batch_state.mjs +179 -0
- package/.claude/skills/orion/scripts/browser_setup.mjs +12 -7
- package/.claude/skills/orion/scripts/cases_export.py +724 -0
- package/.claude/skills/orion/scripts/codemap.mjs +116 -0
- package/.claude/skills/orion/scripts/done_check.mjs +200 -0
- package/.claude/skills/orion/scripts/fix_plan.mjs +21 -0
- package/.claude/skills/orion/scripts/hooks/lean_guard.mjs +162 -0
- package/.claude/skills/orion/scripts/lib/table.mjs +116 -0
- package/.claude/skills/orion/scripts/quiet.mjs +160 -0
- package/.claude/skills/orion/scripts/report_check.mjs +6 -3
- package/.claude/skills/orion/scripts/report_make.mjs +186 -0
- package/.claude/skills/orion/scripts/results_parse.mjs +16 -3
- package/.claude/skills/orion/scripts/rules.mjs +92 -0
- package/.claude/skills/orion/scripts/run_state.mjs +67 -0
- package/.claude/skills/orion/scripts/suite_check.mjs +41 -2
- package/.claude/skills/orion/templates/project-context/assessment.md +2 -2
- package/.claude/skills/orion/templates/project-context/retry-policy.md +6 -0
- package/.claude/skills/orion/templates/project-context/test-design.md +6 -0
- package/.claude/skills/playwright/templates/dotnet/PageObjects/BasePage.cs +4 -0
- package/.claude/skills/playwright/templates/javascript/fixtures/index.js +4 -2
- package/.claude/skills/playwright/templates/javascript/fixtures/session.js +9 -6
- package/.claude/skills/playwright/templates/javascript/jsconfig.json +3 -2
- package/.claude/skills/playwright/templates/javascript/pageObjects/basePage.js +4 -0
- package/.claude/skills/playwright/templates/javascript/playwright.config.js +3 -0
- package/.claude/skills/playwright/templates/javascript/reporters/summaryReporter.js +15 -1
- package/.claude/skills/playwright/templates/javascript/src/config/env.js +29 -1
- package/.claude/skills/playwright/templates/project/fixtures/index.ts +4 -2
- package/.claude/skills/playwright/templates/project/fixtures/session.ts +7 -5
- package/.claude/skills/playwright/templates/project/pageObjects/basePage.ts +4 -0
- package/.claude/skills/playwright/templates/project/playwright.config.ts +3 -0
- package/.claude/skills/playwright/templates/project/reporters/summaryReporter.ts +15 -0
- package/.claude/skills/playwright/templates/project/src/config/env.ts +29 -1
- package/.claude/skills/playwright/templates/python/page_objects/base_page.py +3 -0
- package/.claude/skills/playwright/templates/python/src/config/env.py +34 -2
- package/.claude/skills/selenium/templates/csharp-nunit/PageObjects/BasePage.cs +4 -0
- package/.claude/skills/selenium/templates/java-testng/src/test/java/automation/pageObjects/BasePage.java +3 -0
- package/.claude/skills/selenium/templates/python-pytest/page_objects/base_page.py +3 -0
- package/.claude/skills/self-healing/SKILL.md +1 -1
- package/.claude/skills/test-reporting/references/tool-mapping.md +13 -9
- package/.claude/skills/ui-observation/SKILL.md +1 -0
- package/.claude-plugin/plugin.json +15 -2
- package/.codex/agents/automation-strategist.toml +1 -0
- package/.codex/agents/change-agent.toml +1 -0
- package/.codex/agents/codebase-analyst.toml +1 -0
- package/.codex/agents/environment-discovery.toml +1 -0
- package/.codex/agents/evidence-validator.toml +1 -0
- package/.codex/agents/executor.toml +1 -0
- package/.codex/agents/failure-analyst.toml +1 -0
- package/.codex/agents/implementer.toml +2 -1
- package/.codex/agents/requirement-analyst.toml +1 -0
- package/.codex/agents/reviewer.toml +1 -0
- package/.codex/agents/test-reporter.toml +1 -0
- package/.codex/hooks.json +15 -0
- package/.cursor/commands/orion.md +1 -1
- package/.cursor/hooks.json +10 -0
- package/.devin/hooks.v1.json +13 -0
- package/.gemini/agents/automation-strategist.md +1 -0
- package/.gemini/agents/change-agent.md +1 -0
- package/.gemini/agents/codebase-analyst.md +1 -0
- package/.gemini/agents/environment-discovery.md +1 -0
- package/.gemini/agents/evidence-validator.md +1 -0
- package/.gemini/agents/executor.md +1 -0
- package/.gemini/agents/failure-analyst.md +1 -0
- package/.gemini/agents/implementer.md +2 -1
- package/.gemini/agents/requirement-analyst.md +1 -0
- package/.gemini/agents/reviewer.md +1 -0
- package/.gemini/agents/test-reporter.md +1 -0
- package/.gemini/commands/orion.toml +2 -2
- package/.github/hooks/orion-lean.json +13 -0
- package/.github/prompts/orion.prompt.md +2 -2
- package/.windsurf/workflows/orion.md +2 -2
- package/AGENTS.md +7 -7
- package/README.md +55 -160
- package/assets/run-flow.svg +1 -1
- package/bin/orion.mjs +7 -7
- package/hosts/gemini-extension/gemini-extension.json +1 -1
- package/hosts/gemini-extension/hooks/hooks.json +16 -0
- package/hosts/gemini-extension/policies/platform.toml +5 -0
- package/package.json +5 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Is this request one story or a batch? The rules the orchestrator applies on every host (references/batch.md), as a
|
|
4
|
+
* script where a shell exists; `check_batch_detect.py` keeps the two the same. Reads only the user's own message (and
|
|
5
|
+
* a file it names): keys inside a story fetched from a tracker never count.
|
|
6
|
+
*
|
|
7
|
+
* Usage (from the workspace root):
|
|
8
|
+
* node .claude/skills/orion/scripts/batch_detect.mjs --text "<the user's message>" [--file <stories.csv|.xlsx>] [--json]
|
|
9
|
+
* (--text - reads the message from stdin)
|
|
10
|
+
* Decision:
|
|
11
|
+
* single one story, or none named (a pasted story, one key, one big story with many cases: split into ≤ 8-case tasks)
|
|
12
|
+
* ask 2 or 3 stories: one question, batch suggested ("Run these 3 stories as a batch? yes / one at a time")
|
|
13
|
+
* batch 4+ stories, an epic, a JQL query, a file with 2+ story rows, or "all/every … stories" with a source
|
|
14
|
+
* A key counts only when the message asks for it: keys named as context ("blocked by SHOP-3", "like SHOP-9",
|
|
15
|
+
* "depends on", "related to", "see", "after", "duplicate of", "parent") don't.
|
|
16
|
+
* Output: one line per field (or JSON): decision, stories, source, workflow (build | design), split (stories with > 8
|
|
17
|
+
* cases), reason. Exit code: 0 decided · 2 wrong arguments or an unreadable file.
|
|
18
|
+
*/
|
|
19
|
+
import fs from 'node:fs';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { readRows } from './lib/table.mjs';
|
|
22
|
+
|
|
23
|
+
const KEY = /\b([A-Z][A-Z0-9]{1,9}-\d{1,6})\b/g;
|
|
24
|
+
const CONTEXT = /\b(blocked by|blocks|depends on|dependent on|related to|relates to|see|like|similar to|same as|after|before|duplicate of|duplicates|parent|child of|caused by|follow[- ]up (?:of|to)|from|as in|cloned from|split from)\s+(?:story\s+|ticket\s+|issue\s+)?$/i;
|
|
25
|
+
const EPIC = /\bepic\s+([A-Z][A-Z0-9]{1,9}-\d{1,6})\b|\b([A-Z][A-Z0-9]{1,9}-\d{1,6})\s+epic\b|\bstories (?:in|under|of) (?:the )?epic\b/i;
|
|
26
|
+
const JQL = /\b(jql\b|project\s*=\s*\w+|sprint\s+in\s+|fixVersion\s*=|issuetype\s*=|labels?\s*=)/i;
|
|
27
|
+
const ALL = /\b(?:(?:all|these|those|the following|the \d+|\d+)\s+(?:\w+\s+){0,2}(?:stories|tickets|issues)|(?:every|each)\s+(?:\w+\s+){0,2}(?:story|ticket|issue))\b/i;
|
|
28
|
+
const DESIGN = /\b(test cases only|only (?:the )?test cases|just (?:the )?test cases|design only|only design|no code|cases,? not (?:the )?code)\b/i;
|
|
29
|
+
const CASE_ROW = /^\s*(?:[-*•]|\d+[.)]|TC[-_ ]?\d+|TS[-_ ]?\d+)\s+\S/;
|
|
30
|
+
|
|
31
|
+
/** Story keys the message asks for, in order, without the ones named only as context. */
|
|
32
|
+
export function storyKeys(text) {
|
|
33
|
+
const keys = [];
|
|
34
|
+
// A key that starts a line of a pasted case list ("TC-12 check the total") is a case id, not a story.
|
|
35
|
+
const body = text.split('\n').map((l) => (CASE_ROW.test(l) ? l.replace(/^\s*(?:[-*•]\s*|\d+[.)]\s*)?[A-Z][A-Z0-9]{1,9}-\d{1,6}\b/, ' ') : l)).join('\n');
|
|
36
|
+
for (const m of body.matchAll(KEY)) {
|
|
37
|
+
const before = body.slice(Math.max(0, m.index - 40), m.index);
|
|
38
|
+
if (CONTEXT.test(before)) continue;
|
|
39
|
+
if (!keys.includes(m[1])) keys.push(m[1]);
|
|
40
|
+
}
|
|
41
|
+
return keys;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Rows of a stories file grouped by story: [{ key, cases }] (the key column: story, key, issue, id). */
|
|
45
|
+
export function storiesInFile(file) {
|
|
46
|
+
const rows = readRows(file);
|
|
47
|
+
if (!rows.length) return [];
|
|
48
|
+
const head = rows[0].map((h) => String(h).trim().toLowerCase());
|
|
49
|
+
let col = head.findIndex((h) => /^(story|story key|key|issue|issue key|jira|requirement)$/.test(h));
|
|
50
|
+
const body = col >= 0 ? rows.slice(1) : rows;
|
|
51
|
+
if (col < 0) col = 0;
|
|
52
|
+
const byKey = new Map();
|
|
53
|
+
for (const r of body) {
|
|
54
|
+
const k = String(r[col] ?? '').trim().match(/^[A-Z][A-Z0-9]{1,9}-\d{1,6}$/)?.[0];
|
|
55
|
+
if (!k) continue;
|
|
56
|
+
byKey.set(k, (byKey.get(k) || 0) + 1);
|
|
57
|
+
}
|
|
58
|
+
return [...byKey].map(([key, cases]) => ({ key, cases }));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The decision for one request. */
|
|
62
|
+
export function detect(text, file = null) {
|
|
63
|
+
const workflow = DESIGN.test(text) ? 'design' : 'build';
|
|
64
|
+
const pastedCases = text.split('\n').filter((l) => CASE_ROW.test(l)).length;
|
|
65
|
+
if (file) {
|
|
66
|
+
const stories = storiesInFile(file);
|
|
67
|
+
const split = stories.filter((s) => s.cases > 8).map((s) => s.key);
|
|
68
|
+
if (stories.length >= 2) return { decision: stories.length <= 3 ? 'ask' : 'batch', stories: stories.map((s) => s.key), source: `file ${path.basename(file)}`, workflow, split, reason: `${stories.length} stories in the file` };
|
|
69
|
+
return { decision: 'single', stories: stories.map((s) => s.key), source: `file ${path.basename(file)}`, workflow, split, reason: stories.length ? `one story in the file (${stories[0].cases} cases)` : 'no story keys in the file: one story' };
|
|
70
|
+
}
|
|
71
|
+
const epic = text.match(EPIC);
|
|
72
|
+
if (epic) return { decision: 'batch', stories: [], source: `epic ${epic[1] || epic[2] || '(named)'}`, workflow, split: [], reason: 'an epic: its stories are listed from the tracker' };
|
|
73
|
+
if (JQL.test(text)) return { decision: 'batch', stories: [], source: 'jql', workflow, split: [], reason: 'a tracker query: its stories are listed from the tracker' };
|
|
74
|
+
const keys = storyKeys(text);
|
|
75
|
+
if (keys.length >= 4) return { decision: 'batch', stories: keys, source: 'message', workflow, split: [], reason: `${keys.length} stories named` };
|
|
76
|
+
if (keys.length >= 2) return { decision: 'ask', stories: keys, source: 'message', workflow, split: [], reason: `${keys.length} stories named` };
|
|
77
|
+
if (keys.length < 2 && ALL.test(text) && /\b(sprint|board|backlog|release|version|label|component)\b/i.test(text)) {
|
|
78
|
+
return { decision: 'batch', stories: [], source: 'tracker list', workflow, split: [], reason: '"all/every … stories" of a sprint, board or release' };
|
|
79
|
+
}
|
|
80
|
+
const split = pastedCases > 8 ? [keys[0] || 'the story'] : [];
|
|
81
|
+
return { decision: 'single', stories: keys, source: 'message', workflow, split, reason: pastedCases > 8 ? `one story with ${pastedCases} cases: split into tasks of ≤ 8` : 'one story' };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function main() {
|
|
85
|
+
const a = process.argv.slice(2);
|
|
86
|
+
const opt = (n) => { const i = a.indexOf(n); return i >= 0 ? a[i + 1] : undefined; };
|
|
87
|
+
let text = opt('--text');
|
|
88
|
+
const file = opt('--file');
|
|
89
|
+
if (text === undefined) { console.log('usage: batch_detect.mjs --text "<message>" [--file <stories.csv|.xlsx>] [--json]'); process.exit(2); }
|
|
90
|
+
if (text === '-') text = fs.readFileSync(0, 'utf8');
|
|
91
|
+
if (file && !fs.existsSync(file)) { console.log(`can't read ${file}`); process.exit(2); }
|
|
92
|
+
let r;
|
|
93
|
+
try { r = detect(text, file); } catch (e) { console.log(`can't read ${file}: ${e.message}`); process.exit(2); }
|
|
94
|
+
if (a.includes('--json')) { console.log(JSON.stringify(r)); return; }
|
|
95
|
+
for (const [k, v] of Object.entries(r)) console.log(`${k}: ${Array.isArray(v) ? v.join(', ') || 'none' : v}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (process.argv[1] && path.resolve(process.argv[1]).endsWith('batch_detect.mjs')) main();
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The state of a batch of stories (references/batch.md), in one authoritative file, so a batch stopped by the usage
|
|
4
|
+
* limit, a budget cap or a new chat resumes where it was: `project-context/batches/B-<YYYYMMDD>-<HHMM>-<slug>/batch.json`,
|
|
5
|
+
* with a readable `batch.md` next to it rewritten on every change. The orchestrator keeps only `summary` in its context
|
|
6
|
+
* between waves, never the agents' RESULT bodies.
|
|
7
|
+
*
|
|
8
|
+
* Usage (from the workspace root):
|
|
9
|
+
* node .claude/skills/orion/scripts/batch_state.mjs init <slug> (--stories K1,K2,… | --from <stories.csv|.xlsx>)
|
|
10
|
+
* [--budget <USD>] [--parallel <K>] [--workflow build|design] → prints the batch.json path
|
|
11
|
+
* node .claude/skills/orion/scripts/batch_state.mjs <batch.json> <action> …
|
|
12
|
+
* Actions:
|
|
13
|
+
* set <story> <field>=<value> … story fields: state, screens (comma list), cases, run, usd, note
|
|
14
|
+
* set batch <field>=<value> … batch fields: spent_usd, budget_usd, parallel, foundation, wave
|
|
15
|
+
* screen <name> explored a shared screen was explored once (its map is in project-context/ui-maps/screens/)
|
|
16
|
+
* next the next wave and the stories (or screens) to start now, at most `parallel`
|
|
17
|
+
* summary one status line for the user
|
|
18
|
+
* resume-plan what is done, what is open, the next step
|
|
19
|
+
* Story states, in order: pending → analysed → designed → approved → built → verified → accepted; or blocked, skipped.
|
|
20
|
+
* Waves: plan (pending), screens (unexplored shared screens), strategy (analysed), approval (designed: the user's
|
|
21
|
+
* checkpoint, pages of ≤ 10), foundation (once, after all approvals), build (approved, `parallel` at a time), verify
|
|
22
|
+
* (built), integration (verified → accepted, one by one). A design-only batch ends at approval.
|
|
23
|
+
* Budget: when spent_usd reaches budget_usd, `next` says `stop: budget` (the batch stops at a wave boundary).
|
|
24
|
+
* Exit code: 0 done · 1 not found (story, file) · 2 wrong arguments.
|
|
25
|
+
*/
|
|
26
|
+
import fs from 'node:fs';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
import { insideWorkspace } from './lib/inside.mjs';
|
|
29
|
+
import { readRows } from './lib/table.mjs';
|
|
30
|
+
|
|
31
|
+
const STATES = ['pending', 'analysed', 'designed', 'approved', 'built', 'verified', 'accepted', 'blocked', 'skipped'];
|
|
32
|
+
const WAVES = ['plan', 'screens', 'strategy', 'approval', 'foundation', 'build', 'verify', 'integration'];
|
|
33
|
+
const STORY_FIELDS = ['state', 'screens', 'cases', 'run', 'usd', 'note'];
|
|
34
|
+
const BATCH_FIELDS = ['spent_usd', 'budget_usd', 'parallel', 'foundation', 'wave'];
|
|
35
|
+
const KEY = /^[A-Z][A-Z0-9]{1,9}-\d{1,6}$/;
|
|
36
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
37
|
+
|
|
38
|
+
function fail(msg, code = 2) { console.log(msg); process.exit(code); }
|
|
39
|
+
|
|
40
|
+
function load(file) {
|
|
41
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return fail(`can't read ${file}`, 1); }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The readable view of a batch. */
|
|
45
|
+
export function render(b) {
|
|
46
|
+
const lines = [`# Batch ${b.id}`, '', `- workflow: ${b.workflow} · parallel: ${b.parallel} · budget: ${b.budget_usd === null ? 'none' : `USD ${b.budget_usd}`} · spent: USD ${b.spent_usd}`,
|
|
47
|
+
`- foundation: ${b.foundation || 'not built'} · status: ${summary(b)}`, '', '| Story | State | Screens | Cases | Run | USD | Note |', '|---|---|---|---|---|---|---|'];
|
|
48
|
+
for (const s of b.stories) lines.push(`| ${s.key} | ${s.state} | ${s.screens.join(', ') || '—'} | ${s.cases ?? '—'} | ${s.run || '—'} | ${s.usd ?? '—'} | ${s.note || ''} |`);
|
|
49
|
+
const screens = Object.entries(b.screens);
|
|
50
|
+
if (screens.length) {
|
|
51
|
+
lines.push('', '| Shared screen | Explored | Used by |', '|---|---|---|');
|
|
52
|
+
for (const [name, sc] of screens) lines.push(`| ${name} | ${sc.explored ? 'yes' : 'no'} | ${b.stories.filter((s) => s.screens.includes(name)).map((s) => s.key).join(', ')} |`);
|
|
53
|
+
}
|
|
54
|
+
return `${lines.join('\n')}\n`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function save(file, b) {
|
|
58
|
+
fs.writeFileSync(file, `${JSON.stringify(b, null, 2)}\n`);
|
|
59
|
+
fs.writeFileSync(path.join(path.dirname(file), 'batch.md'), render(b));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const live = (b) => b.stories.filter((s) => !['blocked', 'skipped'].includes(s.state));
|
|
63
|
+
const at = (b, state) => live(b).filter((s) => s.state === state);
|
|
64
|
+
const done = (b) => b.stories.filter((s) => s.state === (b.workflow === 'design' ? 'approved' : 'accepted')).length;
|
|
65
|
+
|
|
66
|
+
/** The next wave and what to start in it. */
|
|
67
|
+
export function next(b) {
|
|
68
|
+
if (b.budget_usd !== null && b.spent_usd >= b.budget_usd) return { wave: 'stop', start: [], why: `budget: USD ${b.spent_usd} spent of ${b.budget_usd}` };
|
|
69
|
+
const k = b.parallel;
|
|
70
|
+
if (at(b, 'pending').length) return { wave: 'plan', start: at(b, 'pending').slice(0, Math.max(k, 6)).map((s) => s.key), why: 'requirement analysis, up to 6 at a time' };
|
|
71
|
+
const unexplored = Object.entries(b.screens).filter(([, s]) => !s.explored).map(([n]) => n);
|
|
72
|
+
if (unexplored.length) return { wave: 'screens', start: unexplored.slice(0, 1), why: 'each shared screen explored once, one at a time (one browser)' };
|
|
73
|
+
if (at(b, 'analysed').length) return { wave: 'strategy', start: at(b, 'analysed').slice(0, Math.max(k, 6)).map((s) => s.key), why: 'test design per story, from the shared screens' };
|
|
74
|
+
if (at(b, 'designed').length) return { wave: 'approval', start: at(b, 'designed').slice(0, 10).map((s) => s.key), why: 'the user approves the test-case tables, up to 10 stories per page' };
|
|
75
|
+
if (b.workflow === 'design') return { wave: 'done', start: [], why: `${done(b)} of ${b.stories.length} stories designed and approved` };
|
|
76
|
+
if (at(b, 'approved').length && !b.foundation) return { wave: 'foundation', start: ['foundation'], why: 'shared page objects, fixtures and helpers built once, before any story' };
|
|
77
|
+
if (at(b, 'approved').length) return { wave: 'build', start: at(b, 'approved').slice(0, k).map((s) => s.key), why: `stories built ${k} at a time, each in its own work copy from the foundation` };
|
|
78
|
+
if (at(b, 'built').length) return { wave: 'verify', start: at(b, 'built').slice(0, Math.min(k, 2)).map((s) => s.key), why: 'review and 3 runs per story, at most 2 runs at a time on a shared environment' };
|
|
79
|
+
if (at(b, 'verified').length) return { wave: 'integration', start: at(b, 'verified').slice(0, 1).map((s) => s.key), why: 'merged one at a time, graph check and one regression run, then accepted' };
|
|
80
|
+
return { wave: 'done', start: [], why: `${done(b)} of ${b.stories.length} stories accepted` };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** One status line. */
|
|
84
|
+
export function summary(b) {
|
|
85
|
+
const n = next(b);
|
|
86
|
+
const idx = WAVES.indexOf(n.wave);
|
|
87
|
+
const wave = idx >= 0 ? `Wave ${idx + 1}/${b.workflow === 'design' ? 4 : WAVES.length} ${n.wave}: ${n.start.join(', ')}` : n.wave === 'stop' ? `Stopped: ${n.why}` : 'Done';
|
|
88
|
+
const blocked = b.stories.filter((s) => s.state === 'blocked').map((s) => s.key);
|
|
89
|
+
return `${wave} · ${done(b)} of ${b.stories.length} done${blocked.length ? ` · blocked: ${blocked.join(', ')}` : ''} · USD ${b.spent_usd}${b.budget_usd !== null ? ` of ${b.budget_usd}` : ''}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function init(a) {
|
|
93
|
+
const slug = a[0];
|
|
94
|
+
if (!slug || !/^[a-z0-9][a-z0-9-]{0,40}$/.test(slug)) fail('init needs a slug: lowercase letters, digits and dashes');
|
|
95
|
+
const opt = (n) => { const i = a.indexOf(n); return i >= 0 ? a[i + 1] : undefined; };
|
|
96
|
+
let keys = [];
|
|
97
|
+
if (opt('--stories')) keys = opt('--stories').split(',').map((s) => s.trim()).filter(Boolean);
|
|
98
|
+
else if (opt('--from')) {
|
|
99
|
+
const rows = readRows(opt('--from'));
|
|
100
|
+
const head = (rows[0] || []).map((h) => String(h).trim().toLowerCase());
|
|
101
|
+
const col = Math.max(0, head.findIndex((h) => /^(story|story key|key|issue|issue key|jira|requirement)$/.test(h)));
|
|
102
|
+
for (const r of rows) { const k = String(r[col] ?? '').trim(); if (KEY.test(k) && !keys.includes(k)) keys.push(k); }
|
|
103
|
+
} else fail('init needs --stories K1,K2,… or --from <stories.csv|.xlsx>');
|
|
104
|
+
const bad = keys.filter((k) => !KEY.test(k));
|
|
105
|
+
if (bad.length || !keys.length) fail(bad.length ? `not story keys: ${bad.join(', ')}` : 'no stories');
|
|
106
|
+
const budget = opt('--budget') !== undefined ? Number(opt('--budget')) : null;
|
|
107
|
+
const parallel = opt('--parallel') !== undefined ? Number(opt('--parallel')) : 4;
|
|
108
|
+
const workflow = opt('--workflow') || 'build';
|
|
109
|
+
if ((budget !== null && !(budget > 0)) || !(parallel >= 1 && parallel <= 6) || !['build', 'design'].includes(workflow)) fail('--budget > 0, --parallel 1 to 6, --workflow build or design');
|
|
110
|
+
const d = new Date();
|
|
111
|
+
const id = `B-${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}-${slug}`;
|
|
112
|
+
const dir = path.join('project-context', 'batches', id);
|
|
113
|
+
insideWorkspace(dir, 'the batch folder');
|
|
114
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
115
|
+
const b = { id, workflow, parallel, budget_usd: budget, spent_usd: 0, foundation: null, screens: {},
|
|
116
|
+
stories: keys.map((key) => ({ key, state: 'pending', screens: [], cases: null, run: null, usd: null, note: '' })) };
|
|
117
|
+
const file = path.join(dir, 'batch.json');
|
|
118
|
+
save(file, b);
|
|
119
|
+
console.log(file);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function setFields(b, target, pairs) {
|
|
123
|
+
const s = target === 'batch' ? null : b.stories.find((x) => x.key === target);
|
|
124
|
+
if (target !== 'batch' && !s) fail(`no story ${target} in ${b.id}`, 1);
|
|
125
|
+
for (const p of pairs) {
|
|
126
|
+
const i = p.indexOf('=');
|
|
127
|
+
if (i < 1) fail(`expected field=value, got ${p}`);
|
|
128
|
+
const [f, v] = [p.slice(0, i), p.slice(i + 1)];
|
|
129
|
+
if (/password|secret|token|bearer|eyJ[A-Za-z0-9_-]{10,}/i.test(v)) fail(`refused: the value of ${f} looks like a secret`);
|
|
130
|
+
if (s) {
|
|
131
|
+
if (!STORY_FIELDS.includes(f)) fail(`story fields: ${STORY_FIELDS.join(', ')}`);
|
|
132
|
+
if (f === 'state' && !STATES.includes(v)) fail(`states: ${STATES.join(', ')}`);
|
|
133
|
+
if (f === 'screens') {
|
|
134
|
+
s.screens = v.split(',').map((x) => x.trim()).filter(Boolean);
|
|
135
|
+
for (const n of s.screens) if (!b.screens[n]) b.screens[n] = { explored: false };
|
|
136
|
+
} else if (f === 'cases' || f === 'usd') {
|
|
137
|
+
if (!(Number(v) >= 0)) fail(`${f} is a number`);
|
|
138
|
+
if (f === 'usd') b.spent_usd = Math.round((b.spent_usd - (s.usd || 0) + Number(v)) * 100) / 100;
|
|
139
|
+
s[f] = Number(v);
|
|
140
|
+
} else s[f] = v;
|
|
141
|
+
} else {
|
|
142
|
+
if (!BATCH_FIELDS.includes(f)) fail(`batch fields: ${BATCH_FIELDS.join(', ')}`);
|
|
143
|
+
if (['spent_usd', 'budget_usd', 'parallel'].includes(f)) {
|
|
144
|
+
if (!(Number(v) >= 0) || (f === 'parallel' && !(Number(v) >= 1 && Number(v) <= 6))) fail(`${f}: a number${f === 'parallel' ? ' from 1 to 6' : ''}`);
|
|
145
|
+
b[f] = Number(v);
|
|
146
|
+
} else b[f] = v;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function main() {
|
|
152
|
+
const a = process.argv.slice(2);
|
|
153
|
+
if (a[0] === 'init') return init(a.slice(1));
|
|
154
|
+
const [file, action, ...rest] = a;
|
|
155
|
+
if (!file || !action) fail('usage: batch_state.mjs init <slug> … | <batch.json> set|screen|next|summary|resume-plan …');
|
|
156
|
+
insideWorkspace(file, 'the batch file');
|
|
157
|
+
const b = load(file);
|
|
158
|
+
if (action === 'set') {
|
|
159
|
+
if (rest.length < 2) fail('set <story|batch> <field>=<value> …');
|
|
160
|
+
setFields(b, rest[0], rest.slice(1));
|
|
161
|
+
save(file, b);
|
|
162
|
+
console.log(summary(b));
|
|
163
|
+
} else if (action === 'screen') {
|
|
164
|
+
if (rest[1] !== 'explored' || !b.screens[rest[0]]) fail(b.screens[rest[0]] ? 'screen <name> explored' : `no shared screen ${rest[0]} (screens come from a story's screens= field)`, b.screens[rest[0]] ? 2 : 1);
|
|
165
|
+
b.screens[rest[0]].explored = true;
|
|
166
|
+
save(file, b);
|
|
167
|
+
console.log(summary(b));
|
|
168
|
+
} else if (action === 'next') {
|
|
169
|
+
const n = next(b);
|
|
170
|
+
console.log(`wave: ${n.wave}\nstart: ${n.start.join(', ') || 'none'}\nwhy: ${n.why}`);
|
|
171
|
+
} else if (action === 'summary') console.log(summary(b));
|
|
172
|
+
else if (action === 'resume-plan') {
|
|
173
|
+
for (const st of STATES) { const ks = b.stories.filter((s) => s.state === st).map((s) => s.key); if (ks.length) console.log(`${st}: ${ks.join(', ')}`); }
|
|
174
|
+
const n = next(b);
|
|
175
|
+
console.log(`next: ${n.wave} · ${n.start.join(', ') || 'none'} (${n.why})`);
|
|
176
|
+
} else fail(`unknown action ${action}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (process.argv[1] && path.resolve(process.argv[1]).endsWith('batch_state.mjs')) main();
|
|
@@ -339,10 +339,14 @@ export function setupSite(target, hosts, app, testId, record, dryRun, envFile =
|
|
|
339
339
|
console.log(` ${'.env'.padEnd(15)} sut/${name}/.env: ${status}`);
|
|
340
340
|
}
|
|
341
341
|
const ignore = ['.ui-map/', ...(hosts.includes('claude-code') ? ['.claude/settings.local.json'] : [])];
|
|
342
|
-
|
|
342
|
+
// An existing suite's files stay as they are: its local ignore list (.git/info/exclude) keeps these out of git
|
|
343
|
+
// without a change to its tracked .gitignore. A new project (sut/<site>/) uses the repo's .gitignore.
|
|
344
|
+
const ignoreFile = envFile && isDir(path.join(target, '.git')) ? '.git/info/exclude' : '.gitignore';
|
|
345
|
+
if (ignoreFile !== '.gitignore' && !dryRun) fs.mkdirSync(path.join(target, '.git', 'info'), { recursive: true });
|
|
346
|
+
const added = appendLines(path.join(target, ignoreFile), ignore);
|
|
343
347
|
const ignored = [...new Set([...((record.browser || {}).gitignore || []), ...added])].sort();
|
|
344
348
|
if (added.length) {
|
|
345
|
-
console.log(` ${
|
|
349
|
+
console.log(` ${ignoreFile.padEnd(15)} ${added.join(', ')} added (browser output and local settings stay out of git)`);
|
|
346
350
|
}
|
|
347
351
|
const [, off] = browserTools();
|
|
348
352
|
const written = new Set((record.browser || {}).files || []);
|
|
@@ -356,7 +360,7 @@ export function setupSite(target, hosts, app, testId, record, dryRun, envFile =
|
|
|
356
360
|
if (snippet) console.log(snippet);
|
|
357
361
|
}
|
|
358
362
|
for (const n of notes) console.log(` note: ${n}`);
|
|
359
|
-
return [{ browser: { site: name, files: [...written].sort(), gitignore: ignored, ...(suiteEnv ? { secrets: suiteEnv } : {}) } }, warnings];
|
|
363
|
+
return [{ browser: { site: name, files: [...written].sort(), gitignore: ignored, ...(ignoreFile !== '.gitignore' ? { ignoreFile } : {}), ...(suiteEnv ? { secrets: suiteEnv } : {}) } }, warnings];
|
|
360
364
|
}
|
|
361
365
|
|
|
362
366
|
function withoutEntry(p, target) {
|
|
@@ -410,16 +414,17 @@ export function removeBrowser(target, record, dryRun) {
|
|
|
410
414
|
else fs.rmSync(p);
|
|
411
415
|
}
|
|
412
416
|
}
|
|
413
|
-
const
|
|
417
|
+
const giRel = info.ignoreFile || '.gitignore';
|
|
418
|
+
const gi = path.join(target, giRel);
|
|
414
419
|
const lines = info.gitignore || [];
|
|
415
420
|
if (lines.length && isFile(gi)) {
|
|
416
421
|
const have = splitlines(readText(gi));
|
|
417
422
|
const rest = have.filter((l) => !lines.includes(l));
|
|
418
423
|
if (rest.length !== have.length) {
|
|
419
|
-
console.log(` browser
|
|
420
|
-
+ (rest.length ? '' : ' (the file too: nothing else in it)'));
|
|
424
|
+
console.log(` browser ${giRel}: ${dryRun ? 'would remove' : 'removed'} ${lines.join(', ')}`
|
|
425
|
+
+ (rest.length || giRel !== '.gitignore' ? '' : ' (the file too: nothing else in it)'));
|
|
421
426
|
if (!dryRun) {
|
|
422
|
-
if (rest.length) fs.writeFileSync(gi, `${rest.join('\n')}\n`);
|
|
427
|
+
if (rest.length || giRel !== '.gitignore') fs.writeFileSync(gi, rest.length ? `${rest.join('\n')}\n` : '');
|
|
423
428
|
else fs.rmSync(gi);
|
|
424
429
|
}
|
|
425
430
|
}
|