@cspeach/cli 1.1.23 → 1.1.24
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/agent/loop.js +124 -0
- package/dist/classifier/client.js +27 -2
- package/dist/commands/plan-continue.js +11 -1
- package/dist/commands/plan-resume.js +38 -1
- package/dist/lane/app-chain.js +297 -0
- package/dist/lane/app-flow.js +55 -0
- package/dist/lane/card.js +148 -0
- package/dist/lane/chain-token.js +59 -0
- package/dist/lane/inputs.js +459 -0
- package/dist/lane/paths.js +21 -0
- package/dist/lane/resolve.js +109 -0
- package/dist/lane/roots.js +113 -0
- package/dist/lane/signals.js +80 -0
- package/dist/lane/store.js +232 -0
- package/dist/lane/types.js +1 -0
- package/dist/one-shot.js +1 -0
- package/dist/projects/extract-plan.js +46 -6
- package/dist/projects/plan-lane.js +214 -0
- package/dist/projects/plan-schema.js +10 -0
- package/dist/projects/promote-command.js +8 -2
- package/dist/projects/save-command.js +71 -25
- package/dist/projects/workspace.js +10 -0
- package/dist/renderer/tool-labels.js +2 -1
- package/dist/repl/resume-standalone.js +3 -0
- package/dist/repl.js +23 -2
- package/dist/skill-catalog.js +14 -6
- package/dist/skills/bundled-skills.js +61 -54
- package/dist/tools/lane/app-lane-resolve.js +329 -0
- package/dist/tools/local-build.js +4 -0
- package/dist/tools/tool-loading.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const flows = new WeakMap();
|
|
2
|
+
/** Start (or restart) the flow for this session. A restart drops earlier state. */
|
|
3
|
+
export function startAppFlow(session, specToken) {
|
|
4
|
+
flows.set(session, { specToken, expect: 'spec-gap' });
|
|
5
|
+
}
|
|
6
|
+
/** A frozen copy: callers change state only through the setters below. */
|
|
7
|
+
export function getAppFlow(session) {
|
|
8
|
+
const f = flows.get(session);
|
|
9
|
+
if (!f)
|
|
10
|
+
return undefined;
|
|
11
|
+
const copy = { specToken: f.specToken, expect: f.expect };
|
|
12
|
+
if (f.specGapPath !== undefined)
|
|
13
|
+
copy.specGapPath = f.specGapPath;
|
|
14
|
+
if (f.lane)
|
|
15
|
+
copy.lane = Object.freeze({ ...f.lane });
|
|
16
|
+
if (f.queued !== undefined)
|
|
17
|
+
copy.queued = f.queued;
|
|
18
|
+
if (f.gapConfirmed !== undefined)
|
|
19
|
+
copy.gapConfirmed = f.gapConfirmed;
|
|
20
|
+
return Object.freeze(copy);
|
|
21
|
+
}
|
|
22
|
+
/** The spec-gap is saved: the lane step is next. No-op when no flow was started. */
|
|
23
|
+
export function setSpecGap(session, path, queued) {
|
|
24
|
+
const f = flows.get(session);
|
|
25
|
+
if (!f)
|
|
26
|
+
return;
|
|
27
|
+
f.specGapPath = path;
|
|
28
|
+
f.expect = 'lane';
|
|
29
|
+
if (queued !== undefined)
|
|
30
|
+
f.queued = queued;
|
|
31
|
+
else
|
|
32
|
+
delete f.queued;
|
|
33
|
+
}
|
|
34
|
+
/** The lane is decided: the plan step is next. No-op when no flow was started. */
|
|
35
|
+
export function setLane(session, path, sha256, queued) {
|
|
36
|
+
const f = flows.get(session);
|
|
37
|
+
if (!f)
|
|
38
|
+
return;
|
|
39
|
+
f.lane = { path, sha256 };
|
|
40
|
+
f.expect = 'plan';
|
|
41
|
+
if (queued !== undefined)
|
|
42
|
+
f.queued = queued;
|
|
43
|
+
else
|
|
44
|
+
delete f.queued;
|
|
45
|
+
}
|
|
46
|
+
/** M4 — record that the open-items question was confirmed for this spec-gap file. */
|
|
47
|
+
export function setGapConfirmed(session, path) {
|
|
48
|
+
const f = flows.get(session);
|
|
49
|
+
if (!f)
|
|
50
|
+
return;
|
|
51
|
+
f.gapConfirmed = path;
|
|
52
|
+
}
|
|
53
|
+
export function clearAppFlow(session) {
|
|
54
|
+
flows.delete(session);
|
|
55
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { DEFAULT_RAP_REASON, READ_ONLY_ANALYTICAL_REASON, UNVERIFIED_REASON } from './resolve.js';
|
|
2
|
+
import { SIGNAL_KEYS } from './signals.js';
|
|
3
|
+
const MAX_LINE = 300;
|
|
4
|
+
/**
|
|
5
|
+
* Control characters (C0, DEL, C1) and bidi / invisible format characters
|
|
6
|
+
* (soft hyphen, CGJ, ALM, Mongolian vowel separator, zero-width, LRM/RLM, line/para
|
|
7
|
+
* separators, embeddings/overrides, isolates, BOM, interlinear annotation, tag characters).
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line no-control-regex
|
|
10
|
+
const UNSAFE = /[\u{0000}-\u{001F}\u{007F}-\u{009F}\u{00AD}\u{034F}\u{061C}\u{180E}\u{200B}-\u{200F}\u{2028}-\u{202E}\u{2060}-\u{2069}\u{FEFF}\u{FFF9}-\u{FFFB}\u{E0000}-\u{E007F}]/gu;
|
|
11
|
+
/** Strip unsafe characters and cap the line at 300 characters (code points). */
|
|
12
|
+
export function cardLine(text) {
|
|
13
|
+
const clean = text.replace(UNSAFE, '');
|
|
14
|
+
const chars = Array.from(clean);
|
|
15
|
+
return chars.length <= MAX_LINE ? clean : `${chars.slice(0, MAX_LINE - 1).join('')}\u2026`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `@<path>` for a plain line the user reads (never a queued command): quoted
|
|
19
|
+
* when it has whitespace, `<placeholder>` when it cannot be shown as a token.
|
|
20
|
+
*/
|
|
21
|
+
export function shownToken(p, placeholder) {
|
|
22
|
+
const t = p === undefined ? '' : cardLine(p).trim();
|
|
23
|
+
if (t === '' || t.includes('"'))
|
|
24
|
+
return `@<${placeholder}>`;
|
|
25
|
+
return /\s/.test(t) ? `@"${t}"` : `@${t}`;
|
|
26
|
+
}
|
|
27
|
+
/** I4(c) — headless / one-shot: no app flow survives the process, so the chain must be run interactively. */
|
|
28
|
+
export function interactiveRunLine(specToken) {
|
|
29
|
+
return `Run /abap-app ${shownToken(specToken, 'spec file')} in an interactive cspeach session to build with the lane card.`;
|
|
30
|
+
}
|
|
31
|
+
const BACKEND_LABEL = {
|
|
32
|
+
rap: 'on-stack RAP',
|
|
33
|
+
cap: 'CAP (side-by-side)',
|
|
34
|
+
none: 'UI only',
|
|
35
|
+
'abap-report': 'classic report',
|
|
36
|
+
segw: 'SEGW',
|
|
37
|
+
'bopf-generated': 'BOPF-generated',
|
|
38
|
+
};
|
|
39
|
+
const UI_LABEL = {
|
|
40
|
+
'fiori-elements': 'Fiori Elements',
|
|
41
|
+
freestyle: 'freestyle UI5',
|
|
42
|
+
none: '',
|
|
43
|
+
};
|
|
44
|
+
const HINT_WORDS = {
|
|
45
|
+
cap_external_users: 'users outside SAP',
|
|
46
|
+
cap_multi_system: 'data from several systems',
|
|
47
|
+
cap_own_release_cycle: 'its own release cycle',
|
|
48
|
+
cap_ui_on_released_api: 'mostly UI and logic on a released SAP API',
|
|
49
|
+
};
|
|
50
|
+
const hintWords = (k) => HINT_WORDS[k] ?? k.replace(/_/g, ' ');
|
|
51
|
+
const SIGNAL_WORDS = {
|
|
52
|
+
...HINT_WORDS,
|
|
53
|
+
app_requested: 'an app is asked for',
|
|
54
|
+
ui_only_service: 'a UI on a published service',
|
|
55
|
+
report_only: 'list output only',
|
|
56
|
+
analytical: 'charts or KPIs',
|
|
57
|
+
transactional: 'create, change or delete',
|
|
58
|
+
custom_ui: 'a custom UI',
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* One card line per claimed signal (truthy value) with no evidence quote, or
|
|
62
|
+
* whose quote was not found word for word in the spec: it was downgraded to
|
|
63
|
+
* weak (spec §8, Review Focus 1). Pure; lines are sanitised and capped.
|
|
64
|
+
*/
|
|
65
|
+
export function quoteNotFoundFacts(signals) {
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const k of SIGNAL_KEYS) {
|
|
68
|
+
const s = signals[k];
|
|
69
|
+
const claimed = typeof s.value === 'string' ? s.value.trim() !== '' : s.value === true;
|
|
70
|
+
if (!claimed || s.quoteFound)
|
|
71
|
+
continue;
|
|
72
|
+
const why = (s.evidence ?? '').trim() === '' ? 'no quote given' : 'quote not found';
|
|
73
|
+
out.push(cardLine(`Weak signal, ${why}: ${SIGNAL_WORDS[k] ?? k}`));
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
const NEUTRAL_DEFAULT = 'No strong signal. Default is on-stack RAP + Fiori Elements.';
|
|
78
|
+
const NEUTRAL_ANALYTICAL = 'No strong side-by-side signal. Recommended: on-stack RAP with an analytical app (ALP).';
|
|
79
|
+
function laneName(backend, ui) {
|
|
80
|
+
const u = UI_LABEL[ui];
|
|
81
|
+
return u ? `${BACKEND_LABEL[backend]} + ${u}` : BACKEND_LABEL[backend];
|
|
82
|
+
}
|
|
83
|
+
function decidedByLine(d) {
|
|
84
|
+
const path = d.decidedByPath ?? 'unknown file';
|
|
85
|
+
if (d.decidedBy === 'pin')
|
|
86
|
+
return `Decided by: project pin (${path})`;
|
|
87
|
+
if (d.decidedBy === 'standards')
|
|
88
|
+
return `Decided by: standards file (${path})`;
|
|
89
|
+
if (d.decidedBy === 'developer')
|
|
90
|
+
return 'Decided by: the developer';
|
|
91
|
+
return 'Decided by: the spec and the rules';
|
|
92
|
+
}
|
|
93
|
+
/** The lane card. Pure: builds the request from the decision, never mutates it. */
|
|
94
|
+
export function laneCardRequest(decision) {
|
|
95
|
+
// Card-only de-duplication: the neutral line restates the default, the
|
|
96
|
+
// "System not checked." line restates the unverified reason. The decision is untouched.
|
|
97
|
+
const reasons = decision.reasons.filter((r) => !(decision.neutral && r === DEFAULT_RAP_REASON) && !(decision.unverified && r === UNVERIFIED_REASON));
|
|
98
|
+
const facts = [...reasons, decidedByLine(decision)];
|
|
99
|
+
if (decision.neutral) {
|
|
100
|
+
const analytical = decision.reasons.includes(READ_ONLY_ANALYTICAL_REASON);
|
|
101
|
+
facts.push(analytical ? NEUTRAL_ANALYTICAL : NEUTRAL_DEFAULT);
|
|
102
|
+
if (decision.weakHints.length > 0) {
|
|
103
|
+
facts.push(`Weak hints toward CAP: ${decision.weakHints.map(hintWords).join(', ')}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const c of decision.crossedOut)
|
|
107
|
+
facts.push(`✗ ${BACKEND_LABEL[c.lane] ?? c.lane}: ${c.reason}`);
|
|
108
|
+
if (decision.unverified)
|
|
109
|
+
facts.push('System not checked.');
|
|
110
|
+
const choices = [];
|
|
111
|
+
const allowed = [...new Set(decision.allowed)];
|
|
112
|
+
const recommended = !decision.noAppLane && decision.backend && allowed.includes(decision.backend) ? decision.backend : null;
|
|
113
|
+
if (recommended) {
|
|
114
|
+
choices.push({ value: 'confirm', label: `Use ${laneName(recommended, decision.ui)}` });
|
|
115
|
+
}
|
|
116
|
+
for (const lane of allowed) {
|
|
117
|
+
if (lane === recommended)
|
|
118
|
+
continue;
|
|
119
|
+
choices.push({ value: `switch:${lane}`, label: `Switch to ${BACKEND_LABEL[lane]}` });
|
|
120
|
+
}
|
|
121
|
+
choices.push({ value: 'cancel', label: 'Cancel' });
|
|
122
|
+
const title = recommended
|
|
123
|
+
? `Build lane: ${laneName(recommended, decision.ui)}`
|
|
124
|
+
: 'No app lane is available on this system';
|
|
125
|
+
return {
|
|
126
|
+
id: 'app-lane',
|
|
127
|
+
tag: 'QUESTION',
|
|
128
|
+
title: cardLine(title),
|
|
129
|
+
facts: facts.map(cardLine),
|
|
130
|
+
choices: choices.map((c) => ({ ...c, label: cardLine(c.label) })),
|
|
131
|
+
initial: 0,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The runtime card for a CAP lane whose runtime is not known yet. Pure. */
|
|
135
|
+
export function runtimeCardRequest() {
|
|
136
|
+
return {
|
|
137
|
+
id: 'app-lane-runtime',
|
|
138
|
+
tag: 'QUESTION',
|
|
139
|
+
title: 'Where will this CAP app run?',
|
|
140
|
+
choices: [
|
|
141
|
+
{ value: 'btp', label: 'SAP BTP' },
|
|
142
|
+
{ value: 'own-server', label: 'Our own server' },
|
|
143
|
+
{ value: 'none', label: "Only on the developer's laptop for now" },
|
|
144
|
+
],
|
|
145
|
+
initial: 0,
|
|
146
|
+
footnote: 'Saved to .cspeach/conventions.toml',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Task 7 review round 1, R10 — the ONE place that turns the session's saved
|
|
2
|
+
// spec-gap path into the `@<path>` token of a queued `--from` command. Used by
|
|
3
|
+
// afterSpecGapSave (`/abap-app --from …`) and app_lane_resolve
|
|
4
|
+
// (`/abap-plan --from …`), so the two can never disagree about the save root.
|
|
5
|
+
//
|
|
6
|
+
// Input is CLI state only (the app flow's specGapPath, from the save hook),
|
|
7
|
+
// never a tool argument. Refused (undefined) unless:
|
|
8
|
+
// - the name is a saved spec-gap envelope (projectFilename shape, with the
|
|
9
|
+
// optional `-N` collision suffix saveProject adds);
|
|
10
|
+
// - the path has no `"` and no control character (it rides in a command);
|
|
11
|
+
// - the real file exists inside realpath(cwd) or realpath(workspace folder),
|
|
12
|
+
// so a link out of the save root is refused.
|
|
13
|
+
// Round trip: parseFromFlag reads `@"…"` / `@\S+`; resolveAtTokenAsync takes a
|
|
14
|
+
// path with a separator or an absolute path verbatim; coerceDocFromFlagToAttachment
|
|
15
|
+
// leaves `.cspeach.json` alone.
|
|
16
|
+
import { promises as fs } from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import { assertRealPathContained } from '../tools/_filesystem-shared.js';
|
|
19
|
+
import { workspaceFolderFor } from './roots.js';
|
|
20
|
+
/** `<slug>-spec-gap-<4 hex>-v<N>[-<n>].cspeach.json` — titleSlug is `[a-z0-9-]`, possibly empty. */
|
|
21
|
+
export const SPEC_GAP_NAME_RE = /^[a-z0-9-]*-spec-gap-[0-9a-f]{4}-v\d+(?:-\d+)?\.cspeach\.json$/;
|
|
22
|
+
// eslint-disable-next-line no-control-regex
|
|
23
|
+
const UNSAFE = /["\u0000-\u001f\u007f-\u009f]/;
|
|
24
|
+
/** A segment after whitespace (or at the start) that begins with `--`. */
|
|
25
|
+
const FLAG_LIKE = /(?:^|\s)--/;
|
|
26
|
+
async function containedIn(abs, root) {
|
|
27
|
+
if (!root)
|
|
28
|
+
return false;
|
|
29
|
+
try {
|
|
30
|
+
const realRoot = await fs.realpath(root);
|
|
31
|
+
await assertRealPathContained(abs, realRoot);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function chainFromToken(cwd, savedPath) {
|
|
39
|
+
if (typeof savedPath !== 'string' || savedPath.trim() === '' || UNSAFE.test(savedPath))
|
|
40
|
+
return undefined;
|
|
41
|
+
if (!SPEC_GAP_NAME_RE.test(path.basename(savedPath)))
|
|
42
|
+
return undefined;
|
|
43
|
+
const root = path.resolve(cwd);
|
|
44
|
+
const abs = path.resolve(root, savedPath);
|
|
45
|
+
if (UNSAFE.test(abs))
|
|
46
|
+
return undefined;
|
|
47
|
+
const ws = await workspaceFolderFor(cwd).catch(() => undefined);
|
|
48
|
+
if (!(await containedIn(abs, root)) && !(await containedIn(abs, ws)))
|
|
49
|
+
return undefined;
|
|
50
|
+
const rel = path.relative(root, abs);
|
|
51
|
+
let p = rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel) ? rel.split(path.sep).join('/') : abs;
|
|
52
|
+
if (!path.isAbsolute(p) && !p.includes('/'))
|
|
53
|
+
p = `./${p}`;
|
|
54
|
+
// Review round 2 — a whitespace-separated piece that looks like a flag
|
|
55
|
+
// (`w --resume --guarded`) would be read as one by quote-unaware parsers.
|
|
56
|
+
if (FLAG_LIKE.test(p) || FLAG_LIKE.test(abs))
|
|
57
|
+
return undefined;
|
|
58
|
+
return { token: /\s/.test(p) ? `@"${p}"` : `@${p}`, path: p };
|
|
59
|
+
}
|