@sun-asterisk/sungen 3.2.24-beta.2 → 3.2.24-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +2 -13
- package/dist/cli/commands/audit.js.map +1 -1
- package/dist/cli/commands/capability.d.ts.map +1 -1
- package/dist/cli/commands/capability.js +11 -12
- package/dist/cli/commands/capability.js.map +1 -1
- package/dist/cli/commands/challenge.d.ts.map +1 -1
- package/dist/cli/commands/challenge.js +2 -10
- package/dist/cli/commands/challenge.js.map +1 -1
- package/dist/cli/commands/depth-lint.d.ts.map +1 -1
- package/dist/cli/commands/depth-lint.js +2 -12
- package/dist/cli/commands/depth-lint.js.map +1 -1
- package/dist/cli/commands/gate.d.ts.map +1 -1
- package/dist/cli/commands/gate.js +2 -47
- package/dist/cli/commands/gate.js.map +1 -1
- package/dist/cli/commands/journey.d.ts.map +1 -1
- package/dist/cli/commands/journey.js +2 -12
- package/dist/cli/commands/journey.js.map +1 -1
- package/dist/cli/commands/manifest.d.ts.map +1 -1
- package/dist/cli/commands/manifest.js +2 -10
- package/dist/cli/commands/manifest.js.map +1 -1
- package/dist/cli/commands/next.d.ts +14 -0
- package/dist/cli/commands/next.d.ts.map +1 -0
- package/dist/cli/commands/next.js +130 -0
- package/dist/cli/commands/next.js.map +1 -0
- package/dist/cli/index.js +34 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/resolve-unit.d.ts +22 -0
- package/dist/cli/resolve-unit.d.ts.map +1 -0
- package/dist/cli/resolve-unit.js +101 -0
- package/dist/cli/resolve-unit.js.map +1 -0
- package/dist/harness/audit.d.ts.map +1 -1
- package/dist/harness/audit.js +9 -1
- package/dist/harness/audit.js.map +1 -1
- package/dist/harness/capability-plan.d.ts +12 -1
- package/dist/harness/capability-plan.d.ts.map +1 -1
- package/dist/harness/capability-plan.js +16 -2
- package/dist/harness/capability-plan.js.map +1 -1
- package/dist/harness/capability.d.ts +12 -0
- package/dist/harness/capability.d.ts.map +1 -1
- package/dist/harness/capability.js +16 -0
- package/dist/harness/capability.js.map +1 -1
- package/dist/harness/catalog/drivers.yaml +5 -0
- package/dist/harness/next-step.d.ts +40 -0
- package/dist/harness/next-step.d.ts.map +1 -0
- package/dist/harness/next-step.js +242 -0
- package/dist/harness/next-step.js.map +1 -0
- package/dist/orchestrator/templates/ai-src/commands/create-test.md +14 -6
- package/dist/orchestrator/templates/ai-src/commands/run-test.md +6 -0
- package/package.json +3 -3
- package/src/cli/commands/audit.ts +2 -11
- package/src/cli/commands/capability.ts +11 -10
- package/src/cli/commands/challenge.ts +2 -8
- package/src/cli/commands/depth-lint.ts +2 -10
- package/src/cli/commands/gate.ts +2 -10
- package/src/cli/commands/journey.ts +2 -10
- package/src/cli/commands/manifest.ts +2 -8
- package/src/cli/commands/next.ts +96 -0
- package/src/cli/index.ts +31 -0
- package/src/cli/resolve-unit.ts +72 -0
- package/src/harness/audit.ts +9 -1
- package/src/harness/capability-plan.ts +23 -3
- package/src/harness/capability.ts +22 -0
- package/src/harness/catalog/drivers.yaml +5 -0
- package/src/harness/next-step.ts +237 -0
- package/src/orchestrator/templates/ai-src/commands/create-test.md +14 -6
- package/src/orchestrator/templates/ai-src/commands/run-test.md +6 -0
|
@@ -3,16 +3,8 @@ import * as path from 'path';
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { runDepthLint, renderDepthLint } from '../../harness/depth-lint';
|
|
5
5
|
import { reportSlug } from '../../harness/unit-paths';
|
|
6
|
+
import { findUnitDir } from '../resolve-unit';
|
|
6
7
|
|
|
7
|
-
function findScreenDir(name: string): string | null {
|
|
8
|
-
const candidates = [
|
|
9
|
-
path.join(process.cwd(), 'qa', 'screens', name),
|
|
10
|
-
path.join(process.cwd(), 'qa', 'flows', name),
|
|
11
|
-
path.join(process.cwd(), 'qa', 'api', name),
|
|
12
|
-
];
|
|
13
|
-
for (const c of candidates) if (fs.existsSync(c)) return c;
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
8
|
|
|
17
9
|
export function registerDepthLintCommand(program: Command): void {
|
|
18
10
|
program
|
|
@@ -24,7 +16,7 @@ export function registerDepthLintCommand(program: Command): void {
|
|
|
24
16
|
try {
|
|
25
17
|
const name = options.screen;
|
|
26
18
|
if (!name) throw new Error('Provide --screen <name>');
|
|
27
|
-
const dir =
|
|
19
|
+
const dir = findUnitDir(name);
|
|
28
20
|
if (!dir) throw new Error(`Not found: qa/screens/${name} or qa/flows/${name}`);
|
|
29
21
|
|
|
30
22
|
const report = runDepthLint(dir, name);
|
package/src/cli/commands/gate.ts
CHANGED
|
@@ -2,16 +2,8 @@ import { Command } from 'commander';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { runGate, renderGate, GatePhase } from '../../harness/journey';
|
|
5
|
+
import { findUnitDir } from '../resolve-unit';
|
|
5
6
|
|
|
6
|
-
function findScreenDir(name: string): string | null {
|
|
7
|
-
const candidates = [
|
|
8
|
-
path.join(process.cwd(), 'qa', 'screens', name),
|
|
9
|
-
path.join(process.cwd(), 'qa', 'flows', name),
|
|
10
|
-
path.join(process.cwd(), 'qa', 'api', name),
|
|
11
|
-
];
|
|
12
|
-
for (const c of candidates) if (fs.existsSync(c)) return c;
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
7
|
|
|
16
8
|
const PHASES: GatePhase[] = ['create', 'run', 'deliver'];
|
|
17
9
|
|
|
@@ -28,7 +20,7 @@ export function registerGateCommand(program: Command): void {
|
|
|
28
20
|
if (!name) throw new Error('Provide --screen <name>');
|
|
29
21
|
const phase = options.phase as GatePhase;
|
|
30
22
|
if (!PHASES.includes(phase)) throw new Error(`Provide --phase <${PHASES.join('|')}>`);
|
|
31
|
-
if (!
|
|
23
|
+
if (!findUnitDir(name)) throw new Error(`Not found: qa/screens/${name}, qa/flows/${name}, or qa/api/${name}`);
|
|
32
24
|
|
|
33
25
|
const verdict = runGate(process.cwd(), name, phase);
|
|
34
26
|
if (options.json) console.log(JSON.stringify(verdict, null, 2));
|
|
@@ -3,16 +3,8 @@ import * as path from 'path';
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { runJourney, waive, signoff, renderJourneyBoard, rollupJourney, renderRollupBoard } from '../../harness/journey';
|
|
5
5
|
import { reportSlug } from '../../harness/unit-paths';
|
|
6
|
+
import { findUnitDir } from '../resolve-unit';
|
|
6
7
|
|
|
7
|
-
function findScreenDir(name: string): string | null {
|
|
8
|
-
const candidates = [
|
|
9
|
-
path.join(process.cwd(), 'qa', 'screens', name),
|
|
10
|
-
path.join(process.cwd(), 'qa', 'flows', name),
|
|
11
|
-
path.join(process.cwd(), 'qa', 'api', name),
|
|
12
|
-
];
|
|
13
|
-
for (const c of candidates) if (fs.existsSync(c)) return c;
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
8
|
|
|
17
9
|
export function registerJourneyCommand(program: Command): void {
|
|
18
10
|
program
|
|
@@ -41,7 +33,7 @@ export function registerJourneyCommand(program: Command): void {
|
|
|
41
33
|
|
|
42
34
|
const name = options.screen;
|
|
43
35
|
if (!name) throw new Error('Provide --screen <name> (or --all for the roll-up)');
|
|
44
|
-
if (!
|
|
36
|
+
if (!findUnitDir(name)) throw new Error(`Not found: qa/screens/${name}, qa/flows/${name}, or qa/api/${name}`);
|
|
45
37
|
|
|
46
38
|
const report = options.waive
|
|
47
39
|
? waive(process.cwd(), name, options.waive, options.reason || '')
|
|
@@ -2,14 +2,8 @@ import { Command } from 'commander';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { buildManifest, diffManifest, loadManifest, saveManifest } from '../../harness/manifest';
|
|
5
|
+
import { findUnitDir } from '../resolve-unit';
|
|
5
6
|
|
|
6
|
-
function findScreenDir(name: string): string | null {
|
|
7
|
-
for (const p of ['screens', 'flows', 'api']) {
|
|
8
|
-
const d = path.join(process.cwd(), 'qa', p, name);
|
|
9
|
-
if (fs.existsSync(d)) return d;
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
7
|
|
|
14
8
|
export function registerManifestCommand(program: Command): void {
|
|
15
9
|
program
|
|
@@ -24,7 +18,7 @@ export function registerManifestCommand(program: Command): void {
|
|
|
24
18
|
try {
|
|
25
19
|
const name = options.screen || options.api || options.area;
|
|
26
20
|
if (!name) throw new Error('Provide --screen <name> (or --api <area>)');
|
|
27
|
-
const dir =
|
|
21
|
+
const dir = findUnitDir(name);
|
|
28
22
|
if (!dir) throw new Error(`Not found: qa/screens|flows|api/${name}`);
|
|
29
23
|
|
|
30
24
|
if (options.diff) {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sungen next [unit]` — the hand-back every command ends with.
|
|
3
|
+
*
|
|
4
|
+
* The next step is derived from what the project HOLDS, not from which command just ran, so a
|
|
5
|
+
* session cannot lose the thread by finishing somewhere that has no footer of its own (#597).
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { readUnitState, UnitState } from '../../harness/next-step';
|
|
11
|
+
import { resolveUnit, resolveUnitCandidates, AmbiguousUnitError } from '../resolve-unit';
|
|
12
|
+
|
|
13
|
+
/** Every unit the project holds, so `sungen next` with no argument still answers. */
|
|
14
|
+
function allUnits(cwd: string): Array<{ name: string; kind: UnitState['kind']; dir: string }> {
|
|
15
|
+
const out: Array<{ name: string; kind: UnitState['kind']; dir: string }> = [];
|
|
16
|
+
for (const [dir, kind] of [['screens', 'screen'], ['flows', 'flow'], ['api', 'api']] as const) {
|
|
17
|
+
const base = path.join(cwd, 'qa', dir);
|
|
18
|
+
try {
|
|
19
|
+
for (const e of fs.readdirSync(base, { withFileTypes: true })) {
|
|
20
|
+
if (e.isDirectory()) out.push({ name: e.name, kind, dir: path.join(base, e.name) });
|
|
21
|
+
}
|
|
22
|
+
} catch { /* the project may not use this unit kind */ }
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function render(s: UnitState): void {
|
|
28
|
+
const L = console.log;
|
|
29
|
+
L('');
|
|
30
|
+
L(`━━━ Next steps: ${s.unit} (${s.kind}) ━━━`);
|
|
31
|
+
L('');
|
|
32
|
+
const held = [
|
|
33
|
+
s.hasSpec && 'spec', s.hasViewpoint && 'viewpoint',
|
|
34
|
+
s.kind === 'flow' && s.hasContract && (s.hasFlowInventory ? 'contract+inventory' : 'contract (phases only)'),
|
|
35
|
+
s.scenarioCount > 0 && `${s.scenarioCount} scenarios`,
|
|
36
|
+
s.hasSelectors && (s.selectorsArePlaceholder ? 'selectors (placeholder)' : 'selectors'),
|
|
37
|
+
s.compiled && 'compiled', s.hasResults && 'results', s.hasDeliverable && 'deliverable',
|
|
38
|
+
].filter(Boolean);
|
|
39
|
+
L(` state: ${held.length ? held.join(' · ') : '(nothing yet)'}`);
|
|
40
|
+
if (s.audit) L(` audit: ${s.audit.overall}/10 [${s.audit.gateStatus}] · ${s.audit.findings.length} finding(s)`);
|
|
41
|
+
L('');
|
|
42
|
+
for (const st of s.steps) {
|
|
43
|
+
const mark = st.kind === 'blocked' ? '⛔' : st.kind === 'optional' ? '○' : '→';
|
|
44
|
+
L(` ${mark} ${st.command}`);
|
|
45
|
+
L(` ${st.because}`);
|
|
46
|
+
}
|
|
47
|
+
L('');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function registerNextCommand(program: Command): void {
|
|
51
|
+
program
|
|
52
|
+
.command('next [unit]')
|
|
53
|
+
.description('What to do next for a unit (or every unit), derived from the project state')
|
|
54
|
+
.option('--json', 'Machine-readable output')
|
|
55
|
+
.action((unit: string | undefined, o: { json?: boolean }) => {
|
|
56
|
+
try {
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
let states: UnitState[];
|
|
59
|
+
if (unit) {
|
|
60
|
+
const resolved = resolveUnit(unit, cwd);
|
|
61
|
+
if (!resolved) {
|
|
62
|
+
console.error(`Error: no unit named "${unit}" under qa/screens, qa/flows or qa/api.`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
states = [readUnitState(cwd, resolved.dir, unit, resolved.kind)];
|
|
66
|
+
} else {
|
|
67
|
+
const units = allUnits(cwd);
|
|
68
|
+
if (units.length === 0) {
|
|
69
|
+
console.error('Error: this project holds no units yet — run `sungen add --screen <name> --path <url>` or `sungen add-flow --flow <name> --path <url>`.');
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
// A name in two places is ambiguous; report it rather than answering for one of them.
|
|
73
|
+
states = units.map((u) => {
|
|
74
|
+
if (resolveUnitCandidates(u.name, cwd).length > 1) throw new AmbiguousUnitError(u.name, resolveUnitCandidates(u.name, cwd));
|
|
75
|
+
return readUnitState(cwd, u.dir, u.name, u.kind);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (o.json) {
|
|
79
|
+
console.log(JSON.stringify(states.length === 1 ? states[0] : states, null, 2));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const s of states) render(s);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error(`Error: ${e instanceof Error ? e.message : e}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The one-line hand-back every command prints last. Kept deliberately small: it points at the
|
|
92
|
+
* resolver instead of restating a next step, so no command can drift from the real state.
|
|
93
|
+
*/
|
|
94
|
+
export function printHandBack(unit?: string): void {
|
|
95
|
+
console.log(`Next: sungen next${unit ? ` ${unit}` : ''}`);
|
|
96
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { registerFeedbackCommand } from './commands/feedback';
|
|
|
27
27
|
import { registerQaFeedbackCommand } from './commands/qa-feedback';
|
|
28
28
|
import { registerScriptCheckCommand } from './commands/script-check';
|
|
29
29
|
import { registerTraceCommand } from './commands/trace';
|
|
30
|
+
import { registerNextCommand } from './commands/next';
|
|
30
31
|
import { registerChallengeCommand } from './commands/challenge';
|
|
31
32
|
import { registerBlindspotCommand } from './commands/blindspot';
|
|
32
33
|
import { registerCapabilityCommand } from './commands/capability';
|
|
@@ -74,6 +75,7 @@ async function main() {
|
|
|
74
75
|
registerQaFeedbackCommand(program);
|
|
75
76
|
registerScriptCheckCommand(program);
|
|
76
77
|
registerTraceCommand(program);
|
|
78
|
+
registerNextCommand(program);
|
|
77
79
|
registerChallengeCommand(program);
|
|
78
80
|
registerBlindspotCommand(program);
|
|
79
81
|
registerCapabilityCommand(program);
|
|
@@ -96,6 +98,35 @@ async function main() {
|
|
|
96
98
|
// say so (stderr, so `--json` output stays parseable).
|
|
97
99
|
program.hook('preAction', () => { warnAssetsDrift(process.cwd()); });
|
|
98
100
|
|
|
101
|
+
// #597 — the hand-back, once, for EVERY command. It used to be hardcoded per command and only
|
|
102
|
+
// two of twenty-nine printed one, so a run that finished anywhere else finished in silence:
|
|
103
|
+
// `capability add` ended with a blank line and the session stopped mid-workflow. Adding a
|
|
104
|
+
// footer to the other twenty-seven would repeat the mistake in bulk.
|
|
105
|
+
//
|
|
106
|
+
// It hangs off `process.on('exit')` rather than a postAction hook because several commands
|
|
107
|
+
// exit with a MEANINGFUL code (`depth-lint` returns 2 when there are deepen candidates) and
|
|
108
|
+
// `process.exit` skips commander's hooks entirely — a postAction version printed for `audit`
|
|
109
|
+
// and silently not for `depth-lint`, which is the same class of gap all over again.
|
|
110
|
+
//
|
|
111
|
+
// It points at `sungen next` instead of restating a step, so it can never drift from the real
|
|
112
|
+
// project state. Skipped on a hard error (code 1): there the error message is the actionable
|
|
113
|
+
// thing, and burying it under a footer helps nobody. `--json` keeps stdout parseable.
|
|
114
|
+
let handBack: { unit?: string; json: boolean } | null = null;
|
|
115
|
+
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
116
|
+
if (actionCommand.name() === 'next') return; // `next` IS the answer
|
|
117
|
+
const opts = actionCommand.opts() as Record<string, unknown>;
|
|
118
|
+
const unit = [opts.screen, opts.flow, opts.area].find((v) => typeof v === 'string' && v)
|
|
119
|
+
?? (typeof actionCommand.args?.[0] === 'string' ? actionCommand.args[0] : undefined);
|
|
120
|
+
handBack = { unit: unit as string | undefined, json: opts.json === true };
|
|
121
|
+
});
|
|
122
|
+
process.on('exit', (code) => {
|
|
123
|
+
if (!handBack || code === 1) return;
|
|
124
|
+
const line = `\nNext: sungen next${handBack.unit ? ` ${handBack.unit}` : ''}`;
|
|
125
|
+
// stderr under --json so the hand-back never lands in the parsed payload.
|
|
126
|
+
if (handBack.json) process.stderr.write(`${line}\n`);
|
|
127
|
+
else process.stdout.write(`${line}\n`);
|
|
128
|
+
});
|
|
129
|
+
|
|
99
130
|
await program.parseAsync(process.argv);
|
|
100
131
|
}
|
|
101
132
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One resolver for "which unit does this name mean?", shared by every command.
|
|
3
|
+
*
|
|
4
|
+
* Seven commands each had their own copy, and all seven searched `qa/screens/` FIRST. So a
|
|
5
|
+
* directory at `qa/screens/<name>/` SHADOWED a real flow of the same name — and the failure was
|
|
6
|
+
* silent, not loud: `sungen audit` resolved to the phantom screen, found no feature file, and
|
|
7
|
+
* reported 0 scenarios with no contract and no scored axis. A run that dropped the entire quality
|
|
8
|
+
* gate looked like a suite with nothing in it.
|
|
9
|
+
*
|
|
10
|
+
* That shape is not hypothetical: the mock driver resolves its catalog from
|
|
11
|
+
* `qa/screens/<unit>/mock/mocks.yaml` only, so making a mock work for a flow means creating
|
|
12
|
+
* exactly that phantom directory (#597).
|
|
13
|
+
*
|
|
14
|
+
* A name resolving to two units is ambiguous, and ambiguity is reported rather than resolved by
|
|
15
|
+
* search order.
|
|
16
|
+
*/
|
|
17
|
+
import * as fs from 'fs';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
|
|
20
|
+
export type UnitKind = 'screen' | 'flow' | 'api';
|
|
21
|
+
|
|
22
|
+
const KINDS: Array<{ kind: UnitKind; dir: string }> = [
|
|
23
|
+
{ kind: 'screen', dir: 'screens' },
|
|
24
|
+
{ kind: 'flow', dir: 'flows' },
|
|
25
|
+
{ kind: 'api', dir: 'api' }, // qa/api/<area> or qa/api/flows/<flow>
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export interface ResolvedUnit {
|
|
29
|
+
dir: string;
|
|
30
|
+
kind: UnitKind;
|
|
31
|
+
/** Catalog unit id relative to qa/: `<screen>` · `flows/<f>` · `api/<a>` · `api/flows/<f>`. */
|
|
32
|
+
unitId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Every unit directory this name matches, in `screens, flows, api` order. */
|
|
36
|
+
export function resolveUnitCandidates(name: string, cwd = process.cwd()): ResolvedUnit[] {
|
|
37
|
+
const out: ResolvedUnit[] = [];
|
|
38
|
+
for (const { kind, dir } of KINDS) {
|
|
39
|
+
const p = path.join(cwd, 'qa', dir, name);
|
|
40
|
+
if (!fs.existsSync(p)) continue;
|
|
41
|
+
out.push({ dir: p, kind, unitId: kind === 'screen' ? name : `${dir}/${name}` });
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class AmbiguousUnitError extends Error {
|
|
47
|
+
constructor(public readonly name: string, public readonly candidates: ResolvedUnit[]) {
|
|
48
|
+
super(
|
|
49
|
+
`"${name}" names ${candidates.length} units: ${candidates.map((c) => `qa/${c.kind === 'screen' ? 'screens/' : ''}${c.unitId}`).join(' and ')}.\n`
|
|
50
|
+
+ ' Resolving this by search order silently picks one and drops the other unit\'s feature,\n'
|
|
51
|
+
+ ' contract and scored axes — a report with 0 scenarios rather than an error. Rename one,\n'
|
|
52
|
+
+ ' or remove the directory that should not exist (a stray `qa/screens/<flow-name>/`\n'
|
|
53
|
+
+ ' created to satisfy a screen-only driver is the usual cause).',
|
|
54
|
+
);
|
|
55
|
+
this.name = 'AmbiguousUnitError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The single unit this name means. Throws `AmbiguousUnitError` when several match; returns null
|
|
61
|
+
* when none do (callers report "unit not found" with their own guidance).
|
|
62
|
+
*/
|
|
63
|
+
export function resolveUnit(name: string, cwd = process.cwd()): ResolvedUnit | null {
|
|
64
|
+
const found = resolveUnitCandidates(name, cwd);
|
|
65
|
+
if (found.length > 1) throw new AmbiguousUnitError(name, found);
|
|
66
|
+
return found[0] ?? null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Back-compat shape for the callers that only want the directory. */
|
|
70
|
+
export function findUnitDir(name: string, cwd = process.cwd()): string | null {
|
|
71
|
+
return resolveUnit(name, cwd)?.dir ?? null;
|
|
72
|
+
}
|
package/src/harness/audit.ts
CHANGED
|
@@ -586,11 +586,19 @@ export function runAudit(screenDir: string, screenName: string): AuditReport {
|
|
|
586
586
|
// TQ-10 — surface the Capability Planner recommendation (recommend-only; never installs). Silenced
|
|
587
587
|
// by `capability_suggestions: off` in qa/context.md. Reuses the planner (trustworthy after TQ-9).
|
|
588
588
|
if (intent.capabilitySuggestions) {
|
|
589
|
-
|
|
589
|
+
// The catalog unit id (`flows/<f>`, `api/<a>`) carries the unit KIND, which gates which
|
|
590
|
+
// drivers can serve it at all.
|
|
591
|
+
const plan = buildPlan(screenDir, screenName, catalogScreenName);
|
|
590
592
|
if (plan.recommendations.length) {
|
|
591
593
|
const recs = plan.recommendations.map((r) => `\`sungen capability add ${r.driver}\` (automates ${r.count})`).join(' · ');
|
|
592
594
|
findings.push(`CAPABILITY-SUGGESTION: ${plan.capabilityManual} @manual scenario(s) are capability-manual (a driver could automate them) — ${recs}. Recommend-only: nothing is installed automatically; the ${plan.judgmentManual} judgment-manual (M6/M8/M9) correctly stay manual.`);
|
|
593
595
|
}
|
|
596
|
+
// Named, not dropped: without this the scenarios read as "nothing could help", and the
|
|
597
|
+
// operator's only clue was an install that dead-ends (#597).
|
|
598
|
+
if (plan.unavailable.length) {
|
|
599
|
+
const un = plan.unavailable.map((r) => `${r.driver} (would automate ${r.count})`).join(' · ');
|
|
600
|
+
findings.push(`CAPABILITY-UNAVAILABLE: ${un} — ${plan.unavailable.length === 1 ? 'that driver does' : 'those drivers do'} not support a ${plan.unavailable[0].unitKind} unit, so ${plan.unavailable.length === 1 ? 'it' : 'they'} cannot automate these scenarios here. Do NOT install: the scenarios stay @manual until the driver gains ${plan.unavailable[0].unitKind} support. Automating the same behaviour on the owning SCREEN unit is the available route today.`);
|
|
601
|
+
}
|
|
594
602
|
}
|
|
595
603
|
// TQ-11b — automation-ready (pending capability): @requires:<cap> scenarios whose cap isn't enabled.
|
|
596
604
|
// They are NOT manual (real steps, compiled the moment the cap is added) — surface them distinctly.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import * as path from 'path';
|
|
11
|
-
import { loadDriverCatalog } from './capability';
|
|
11
|
+
import { loadDriverCatalog, unitKindOf, driverServesUnit } from './capability';
|
|
12
12
|
import { readTextFile } from './read-text';
|
|
13
13
|
import { featureFilesFor } from './unit-paths';
|
|
14
14
|
|
|
@@ -190,12 +190,21 @@ export interface CapabilityPlan {
|
|
|
190
190
|
crossScreen: number; // automatable via a flow — not a single-screen driver gap
|
|
191
191
|
capabilityManualPct: number;
|
|
192
192
|
recommendations: { driver: string; pkg: string; reason: string; count: number; scenarios: string[] }[];
|
|
193
|
+
/**
|
|
194
|
+
* Drivers that WOULD have been recommended but cannot serve this unit kind. Surfaced, never
|
|
195
|
+
* dropped: the scenarios stay manual for a reason the operator needs to know, and a silent
|
|
196
|
+
* omission would read as "nothing could help here" (#597).
|
|
197
|
+
*/
|
|
198
|
+
unavailable: { driver: string; reason: string; count: number; unitKind: string }[];
|
|
193
199
|
keep: { code: string; count: number }[];
|
|
194
200
|
}
|
|
195
201
|
|
|
196
|
-
export function buildPlan(screenDir: string, screenName: string): CapabilityPlan {
|
|
202
|
+
export function buildPlan(screenDir: string, screenName: string, unitId = screenName): CapabilityPlan {
|
|
197
203
|
const scenarios = featureFilesFor(screenDir, screenName).flatMap(parseScenarios);
|
|
198
204
|
const catalog = loadDriverCatalog();
|
|
205
|
+
// Recommending a driver that cannot serve this unit KIND costs an install, a dead end and a
|
|
206
|
+
// manual rollback — which is exactly what the mock driver (screen-only) did on a flow (#597).
|
|
207
|
+
const unitKind = unitKindOf(unitId);
|
|
199
208
|
|
|
200
209
|
const modes: Record<string, number> = {};
|
|
201
210
|
const byReason: Record<string, number> = {};
|
|
@@ -230,7 +239,17 @@ export function buildPlan(screenDir: string, screenName: string): CapabilityPlan
|
|
|
230
239
|
}
|
|
231
240
|
}
|
|
232
241
|
|
|
233
|
-
const
|
|
242
|
+
const servable = [...recByDriver.entries()].filter(([d]) => driverServesUnit(d, unitKind));
|
|
243
|
+
const unavailable = [...recByDriver.entries()]
|
|
244
|
+
.filter(([d]) => !driverServesUnit(d, unitKind))
|
|
245
|
+
.map(([driver, v]) => ({
|
|
246
|
+
driver,
|
|
247
|
+
reason: v.reason,
|
|
248
|
+
count: v.scenarios.length,
|
|
249
|
+
unitKind,
|
|
250
|
+
}))
|
|
251
|
+
.sort((a, b) => b.count - a.count);
|
|
252
|
+
const recommendations = servable
|
|
234
253
|
.map(([driver, v]) => ({
|
|
235
254
|
driver,
|
|
236
255
|
pkg: catalog[driver]?.package || `@sungen/driver-${driver}`,
|
|
@@ -252,6 +271,7 @@ export function buildPlan(screenDir: string, screenName: string): CapabilityPlan
|
|
|
252
271
|
crossScreen,
|
|
253
272
|
capabilityManualPct: manualTotal ? Math.round((capabilityManual / manualTotal) * 100) : 0,
|
|
254
273
|
recommendations,
|
|
274
|
+
unavailable,
|
|
255
275
|
keep: Object.entries(keepCount).map(([code, count]) => ({ code, count })).sort((a, b) => b.count - a.count),
|
|
256
276
|
};
|
|
257
277
|
}
|
|
@@ -73,6 +73,28 @@ export interface DriverMeta {
|
|
|
73
73
|
bundled?: boolean; // shipped as a core dependency — present without `capability add`
|
|
74
74
|
capabilities: string[];
|
|
75
75
|
unblocks?: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Unit kinds this driver can actually serve. Absent = all kinds.
|
|
78
|
+
*
|
|
79
|
+
* A driver that only resolves its config from one unit shape must say so, or the capability
|
|
80
|
+
* planner recommends it for a unit it can never serve — which is what happened with the mock
|
|
81
|
+
* driver on a flow: install, dead end, manual rollback (#597).
|
|
82
|
+
*/
|
|
83
|
+
units?: Array<'screen' | 'flow' | 'api'>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The unit kind of a catalog unit id: `flows/<f>` → flow, `api/<a>` → api, else screen. */
|
|
87
|
+
export function unitKindOf(catalogUnitId: string): 'screen' | 'flow' | 'api' {
|
|
88
|
+
const seg = catalogUnitId.split('/')[0];
|
|
89
|
+
if (seg === 'api') return 'api';
|
|
90
|
+
if (seg === 'flows') return 'flow';
|
|
91
|
+
return 'screen';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Can this driver serve that unit kind? Unknown driver → assume yes (nothing to gate on). */
|
|
95
|
+
export function driverServesUnit(driverId: string, kind: 'screen' | 'flow' | 'api'): boolean {
|
|
96
|
+
const units = driverMeta(driverId)?.units;
|
|
97
|
+
return !units || units.includes(kind);
|
|
76
98
|
}
|
|
77
99
|
|
|
78
100
|
export function capabilitiesPath(cwd: string): string {
|
|
@@ -61,6 +61,11 @@ drivers:
|
|
|
61
61
|
status: shipped
|
|
62
62
|
capabilities: ["@mock", "@network"]
|
|
63
63
|
unblocks: [M3]
|
|
64
|
+
# `units:` is the unit KINDS this driver can actually serve. Absent → all kinds.
|
|
65
|
+
# The mock driver resolves its catalog from qa/screens/<unit>/mock/mocks.yaml only
|
|
66
|
+
# (mockCatalogPath is hardcoded to that shape), so it cannot serve a flow. Recommending
|
|
67
|
+
# it for one sent an operator through an install, a dead end and a manual rollback (#597).
|
|
68
|
+
units: [screen]
|
|
64
69
|
mail-file:
|
|
65
70
|
kind: capability
|
|
66
71
|
package: "@sungen/driver-mail-file"
|