robisie 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/README.md +109 -14
- package/dist/active-recovery.d.ts +58 -0
- package/dist/active-recovery.js +143 -0
- package/dist/agents.d.ts +34 -0
- package/dist/agents.js +77 -16
- package/dist/attempt-identity.d.ts +21 -0
- package/dist/attempt-identity.js +39 -0
- package/dist/ci-failure-result.d.ts +23 -0
- package/dist/ci-failure-result.js +90 -0
- package/dist/claude-headless.d.ts +7 -0
- package/dist/claude-headless.js +28 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.js +54 -14
- package/dist/commands.d.ts +18 -0
- package/dist/commands.js +195 -88
- package/dist/constants.d.ts +32 -0
- package/dist/constants.js +3 -3
- package/dist/context.d.ts +24 -0
- package/dist/context.js +22 -6
- package/dist/dependency-readiness.d.ts +13 -0
- package/dist/dependency-readiness.js +80 -0
- package/dist/dispatch-scope.d.ts +18 -0
- package/dist/dispatch-scope.js +46 -0
- package/dist/done-evidence.d.ts +31 -0
- package/dist/done-evidence.js +216 -0
- package/dist/engine-config.d.ts +65 -0
- package/dist/engine-config.js +139 -0
- package/dist/fsops.d.ts +87 -0
- package/dist/fsops.js +117 -24
- package/dist/helpers.d.ts +15 -0
- package/dist/helpers.js +268 -45
- package/dist/intent-rules/admission.d.ts +10 -0
- package/dist/intent-rules/admission.js +35 -0
- package/dist/intent-rules/done-when-roles.d.ts +21 -0
- package/dist/intent-rules/done-when-roles.js +101 -0
- package/dist/intent-rules/hooks.d.ts +29 -0
- package/dist/intent-rules/hooks.js +23 -0
- package/dist/k3-codex-role.d.ts +20 -0
- package/dist/k3-codex-role.js +68 -0
- package/dist/manifest.d.ts +41 -0
- package/dist/manifest.js +59 -14
- package/dist/mcp.d.ts +18 -0
- package/dist/mcp.js +117 -40
- package/dist/opencode-result.d.ts +19 -0
- package/dist/opencode-result.js +136 -0
- package/dist/opencode-review-guard.d.ts +1 -0
- package/dist/opencode-review-guard.js +19 -0
- package/dist/opencode-session-export.d.ts +5 -0
- package/dist/opencode-session-export.js +28 -0
- package/dist/outcome-moves.d.ts +15 -0
- package/dist/outcome-moves.js +39 -0
- package/dist/planer-client.d.ts +214 -0
- package/dist/planer-client.js +351 -0
- package/dist/restart-recovery.d.ts +47 -0
- package/dist/restart-recovery.js +70 -0
- package/dist/review-source-packet.d.ts +17 -0
- package/dist/review-source-packet.js +44 -0
- package/dist/role-registry.d.ts +25 -0
- package/dist/role-registry.js +91 -0
- package/dist/role-results.d.ts +15 -0
- package/dist/role-results.js +42 -0
- package/dist/roles.d.ts +30 -0
- package/dist/roles.js +20 -16
- package/dist/seed-validation.d.ts +28 -0
- package/dist/seed-validation.js +294 -0
- package/dist/selection-result.d.ts +44 -0
- package/dist/selection-result.js +144 -0
- package/dist/sparse-policy.d.ts +8 -0
- package/dist/sparse-policy.js +49 -0
- package/dist/tester-identity.d.ts +11 -0
- package/dist/tester-identity.js +53 -0
- package/dist/worker-env.d.ts +5 -0
- package/dist/worker-env.js +34 -0
- package/docs/ENGINE-API.md +88 -0
- package/docs/ENGINE-CONFIG.md +113 -0
- package/docs/README.en.md +142 -20
- package/docs/README.md +144 -20
- package/docs/RELEASE-0.1.0.md +81 -8
- package/docs/RELEASE-0.1.1.md +110 -0
- package/helpers/ceo-client-launcher-mcp.mjs +36 -8
- package/helpers/client-spawn-session.sh +181 -0
- package/helpers/client-spawn.sh +825 -0
- package/package.json +9 -4
- package/roles/ceo-client.md +3 -2
- package/roles/manager-builder-client.md +18 -4
- package/roles/quality-officer-client.md +20 -6
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// Walidator pakietu karty siewcy — odpowiednik docs/zrodla/walidator/seed-card-validate.sh w Node.
|
|
2
|
+
// Te same kontrole, progi i komunikaty; bez bash/awk/grep. Jedyna różnica: odbiorca w markerze „Efekt dla …”
|
|
3
|
+
// pochodzi z konfiguracji (effectFor), a nie jest wbity na sztywno. Git jest wołany bezpośrednio (execFileSync, bez powłoki)
|
|
4
|
+
// tylko w kontroli §5, gdy SCOPE ma sekcję **Write-set.
|
|
5
|
+
//
|
|
6
|
+
// Świadoma granica (jak T1): sprawdza OBECNOŚĆ + FORMAT (nasze markery), NIE głębię/mądrość.
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { accessSync, constants, readFileSync, statSync } from 'node:fs';
|
|
9
|
+
import { join, resolve } from 'node:path';
|
|
10
|
+
export const SEED_FILES = { scope: '20-scope.md', spec: '25-spec.md', brief: '30-brief.md' };
|
|
11
|
+
export const VALIDATE_USAGE = 'użycie: robisie-intent validate-seed <katalog-pakietu> [--repo katalog-repo] [--config robisie.config.json] [--efekt-dla <dopełniacz>]';
|
|
12
|
+
/** Domyślny odbiorca efektu w SCOPE (dopełniacz), gdy instancja nie poda własnego (roles.owner.genitive). */
|
|
13
|
+
export const DEFAULT_EFFECT_FOR = 'właściciela';
|
|
14
|
+
/** Marker SCOPE „Efekt dla <odbiorca>” — to samo źródło dla szablonu Siewcy ({{WLASCICIEL}}) i walidatora. */
|
|
15
|
+
export function effectMarker(effectFor = DEFAULT_EFFECT_FOR) {
|
|
16
|
+
return `Efekt dla ${effectFor}`;
|
|
17
|
+
}
|
|
18
|
+
function readable(file) {
|
|
19
|
+
try {
|
|
20
|
+
if (!statSync(file).isFile())
|
|
21
|
+
return false;
|
|
22
|
+
accessSync(file, constants.R_OK);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Linie pliku tak, jak widzi je grep/awk (bez pustego segmentu po końcowym \n). */
|
|
30
|
+
function fileLines(file) {
|
|
31
|
+
const text = readFileSync(file, 'utf8');
|
|
32
|
+
const lines = text.split('\n');
|
|
33
|
+
if (lines.length && lines[lines.length - 1] === '')
|
|
34
|
+
lines.pop();
|
|
35
|
+
return lines;
|
|
36
|
+
}
|
|
37
|
+
function hasFixed(file, needle) {
|
|
38
|
+
return readable(file) && fileLines(file).some(line => line.includes(needle));
|
|
39
|
+
}
|
|
40
|
+
function hasRegex(file, pattern) {
|
|
41
|
+
return readable(file) && fileLines(file).some(line => pattern.test(line));
|
|
42
|
+
}
|
|
43
|
+
// [[:space:]] w lokalizacji C (mawk/grep bez UTF-8): spacja, \t, \n, \v, \f, \r.
|
|
44
|
+
const SPACE = ' \\t\\n\\v\\f\\r';
|
|
45
|
+
const BLANK_LINE = new RegExp(`^[${SPACE}]*$`);
|
|
46
|
+
function git(root, args) {
|
|
47
|
+
try {
|
|
48
|
+
const stdout = execFileSync('git', ['-C', root, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], shell: false });
|
|
49
|
+
return { ok: true, stdout };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return { ok: false, stdout: '' };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function gitRoot(repo) {
|
|
56
|
+
const result = git(repo, ['rev-parse', '--show-toplevel']);
|
|
57
|
+
return result.ok ? result.stdout.replace(/\n+$/, '') : '';
|
|
58
|
+
}
|
|
59
|
+
/** Kolejność `sort -u` w lokalizacji C (po jednostkach kodu). */
|
|
60
|
+
function sortUnique(values) {
|
|
61
|
+
return [...new Set(values)].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
62
|
+
}
|
|
63
|
+
function writeSetPaths(scopeLines) {
|
|
64
|
+
const paths = [];
|
|
65
|
+
let inside = false;
|
|
66
|
+
for (const line of scopeLines) {
|
|
67
|
+
if (/^\*\*Write-set/.test(line)) {
|
|
68
|
+
inside = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (inside && (/^\*\*/.test(line) || /^## /.test(line)))
|
|
72
|
+
break;
|
|
73
|
+
if (inside && /^- /.test(line)) {
|
|
74
|
+
for (const match of line.matchAll(/`[^`]+`/g)) {
|
|
75
|
+
const token = match[0].slice(1, -1);
|
|
76
|
+
if (!new RegExp(`[${SPACE}]`).test(token) && /[/.]/.test(token))
|
|
77
|
+
paths.push(token);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return paths;
|
|
82
|
+
}
|
|
83
|
+
function outText(scopeLines) {
|
|
84
|
+
const out = [];
|
|
85
|
+
let inside = false;
|
|
86
|
+
for (const line of scopeLines) {
|
|
87
|
+
if (/^\*\*Świadomie POZA/.test(line)) {
|
|
88
|
+
inside = true;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (inside && /^## /.test(line))
|
|
92
|
+
break;
|
|
93
|
+
if (inside)
|
|
94
|
+
out.push(line);
|
|
95
|
+
}
|
|
96
|
+
return out.join('\n');
|
|
97
|
+
}
|
|
98
|
+
function envTokens(lines) {
|
|
99
|
+
const tokens = [];
|
|
100
|
+
for (const line of lines) {
|
|
101
|
+
const envline = /(^|[^A-Za-z0-9_])\.?env([^A-Za-z0-9_]|$)|zmienn/.test(line.toLowerCase());
|
|
102
|
+
for (const match of line.matchAll(/[A-Z][A-Z0-9]*(_[A-Z0-9]+)+/g)) {
|
|
103
|
+
const t = match[0];
|
|
104
|
+
if (envline || line.includes('process.env.' + t) || line.includes(t + '='))
|
|
105
|
+
tokens.push(t);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return sortUnique(tokens);
|
|
109
|
+
}
|
|
110
|
+
function runtimeNames(lines, root) {
|
|
111
|
+
const kept = [];
|
|
112
|
+
const token = new RegExp(`\`[^\`]+\`|[^${SPACE}\`]+`, 'g');
|
|
113
|
+
const externalPath = /^\/([^/]+\/)*[A-Z][A-Z0-9_-]*\.(md|json|jsonl|log|txt)$/;
|
|
114
|
+
const notExternal = new RegExp(`\\/\\.\\.?\\/|[${SPACE}]\\/|\\/[${SPACE}]`);
|
|
115
|
+
for (const line of lines) {
|
|
116
|
+
const raws = [];
|
|
117
|
+
let last = 0;
|
|
118
|
+
for (const match of line.matchAll(token)) {
|
|
119
|
+
const raw = match[0];
|
|
120
|
+
const prefix = line.slice(last, match.index);
|
|
121
|
+
let path = raw;
|
|
122
|
+
if (/^`.*`$/.test(path))
|
|
123
|
+
path = path.slice(1, -1);
|
|
124
|
+
else
|
|
125
|
+
path = path.replace(/[.,;:)]*$/, '');
|
|
126
|
+
const external = !/`$/.test(prefix) && externalPath.test(path) && !notExternal.test(path) && !path.startsWith(root + '/');
|
|
127
|
+
if (!external)
|
|
128
|
+
raws.push(raw);
|
|
129
|
+
last = match.index + raw.length;
|
|
130
|
+
}
|
|
131
|
+
const joined = raws.map(raw => raw + ' ').join('');
|
|
132
|
+
// Alternatywa jsonl przed json: grep -o wybiera najdłuższe dopasowanie, JS — pierwsze.
|
|
133
|
+
for (const match of joined.matchAll(/`maszynista\/[A-Za-z0-9._-]+`|[A-Z][A-Z0-9_-]*\.(md|jsonl|json|log|txt)|`\.[a-z][a-z0-9-]+`/g)) {
|
|
134
|
+
kept.push(match[0].split('`').join(''));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return sortUnique(kept);
|
|
138
|
+
}
|
|
139
|
+
function doneWhenNumbers(scopeLines) {
|
|
140
|
+
const numbers = [];
|
|
141
|
+
let inside = false;
|
|
142
|
+
for (const line of scopeLines) {
|
|
143
|
+
if (new RegExp(`^##[${SPACE}]*done.?when`).test(line.toLowerCase())) {
|
|
144
|
+
inside = true;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (inside && /^## /.test(line))
|
|
148
|
+
break;
|
|
149
|
+
const match = inside ? /^[0-9]+\./.exec(line) : null;
|
|
150
|
+
if (match)
|
|
151
|
+
numbers.push(match[0].slice(0, -1));
|
|
152
|
+
}
|
|
153
|
+
return numbers;
|
|
154
|
+
}
|
|
155
|
+
function mapNumbers(specLines) {
|
|
156
|
+
const numbers = [];
|
|
157
|
+
let inside = false;
|
|
158
|
+
const row = new RegExp(`^\\|[${SPACE}]*[0-9]+[${SPACE}]*\\|`);
|
|
159
|
+
const nonBlank = new RegExp(`[^${SPACE}]`);
|
|
160
|
+
for (const line of specLines) {
|
|
161
|
+
if (/[Mm]apa kryterium/.test(line))
|
|
162
|
+
inside = true;
|
|
163
|
+
if (!inside || !row.test(line))
|
|
164
|
+
continue;
|
|
165
|
+
const cols = line.split('|');
|
|
166
|
+
// awk: cols[3..5] = kolumny kryterium, rozwiązanie, sprawdzenie (JS: indeksy 2..4).
|
|
167
|
+
if ([2, 3, 4].some(i => !nonBlank.test(cols[i] ?? '')))
|
|
168
|
+
continue;
|
|
169
|
+
numbers.push(line.replace(new RegExp(`^\\|[${SPACE}]*`), '').replace(new RegExp(`[${SPACE}]*\\|[\\s\\S]*`), ''));
|
|
170
|
+
}
|
|
171
|
+
return numbers;
|
|
172
|
+
}
|
|
173
|
+
/** Waliduje trzy artefakty siania (kolejność kanoniczna SCOPE → SPEC → BRIEF). */
|
|
174
|
+
export function validateSeedFiles(scope, spec, brief, options = {}) {
|
|
175
|
+
const gaps = [];
|
|
176
|
+
const warnings = [];
|
|
177
|
+
// ── 1. Istnienie trzech artefaktów (czytelny plik; katalog/nieczytelny = jawna luka) ──
|
|
178
|
+
if (!readable(scope))
|
|
179
|
+
gaps.push(`SCOPE nie istnieje lub nie jest czytelnym plikiem: ${scope}`);
|
|
180
|
+
if (!readable(brief))
|
|
181
|
+
gaps.push(`BRIEF nie istnieje lub nie jest czytelnym plikiem: ${brief}`);
|
|
182
|
+
if (!readable(spec))
|
|
183
|
+
gaps.push(`SPEC nie istnieje lub nie jest czytelnym plikiem: ${spec}`);
|
|
184
|
+
// ── 2. BRIEF — kanon MB ──
|
|
185
|
+
if (readable(brief)) {
|
|
186
|
+
if (!hasFixed(brief, 'scopeRef:'))
|
|
187
|
+
gaps.push("BRIEF: brak 'scopeRef:' (brama T1 rozwija scopeRef → SCOPE)");
|
|
188
|
+
if (!hasFixed(brief, 'designRef:'))
|
|
189
|
+
gaps.push("BRIEF: brak 'designRef:' (brama T1 rozwija designRef → SPEC)");
|
|
190
|
+
const markers = ['specialist:', 'acceptance_criteria_wiring:', '## Skill (REQUIRED)', '## Done When', 'Example Mapping'];
|
|
191
|
+
const miss = markers.filter(marker => !hasFixed(brief, marker));
|
|
192
|
+
const hits = markers.length - miss.length;
|
|
193
|
+
if (hits < 3)
|
|
194
|
+
gaps.push(`BRIEF: za mało markerów kanonu MB (${hits}/5, wymagane ≥3) — brakuje: ${miss.join(' ')}`);
|
|
195
|
+
}
|
|
196
|
+
// ── 3. SCOPE — Wzór scope (≥4 z 6) ──
|
|
197
|
+
if (readable(scope)) {
|
|
198
|
+
const checks = [
|
|
199
|
+
['Cel', hasFixed(scope, 'Cel')],
|
|
200
|
+
[effectMarker(options.effectFor), hasFixed(scope, effectMarker(options.effectFor))],
|
|
201
|
+
// „Granice + lane:” liczone jako jeden marker; 'lane[: =]' by NIE łapać „Planer”.
|
|
202
|
+
['Granice/lane', hasRegex(scope, new RegExp(`lane[${SPACE}]*[:=]`, 'i')) || hasFixed(scope, 'Granice')],
|
|
203
|
+
['Done-When', hasRegex(scope, /Done.?When/i)],
|
|
204
|
+
['specialist', hasRegex(scope, /specialist/i)],
|
|
205
|
+
// servesGoal = SŁOWO 'servesGoal', nie samo '#N'.
|
|
206
|
+
['servesGoal', hasFixed(scope, 'servesGoal')],
|
|
207
|
+
];
|
|
208
|
+
const miss = checks.filter(([, hit]) => !hit).map(([name]) => name);
|
|
209
|
+
const hits = checks.length - miss.length;
|
|
210
|
+
if (hits < 4)
|
|
211
|
+
gaps.push(`SCOPE: za mało markerów Wzoru scope (${hits}/6, wymagane ≥4) — brakuje: ${miss.join(' ')}`);
|
|
212
|
+
}
|
|
213
|
+
// ── 4. SPEC — istnienie + niepustość (≥15 linii treści) ──
|
|
214
|
+
if (readable(spec)) {
|
|
215
|
+
const specLines = fileLines(spec).filter(line => !BLANK_LINE.test(line)).length;
|
|
216
|
+
if (specLines < 15)
|
|
217
|
+
gaps.push(`SPEC: za krótki (${specLines} linii treści, wymagane ≥15) — design rationale, nie zaślepka`);
|
|
218
|
+
}
|
|
219
|
+
// ── 5. Spójność write-setu z treścią SPEC/BRIEF; to NIE marker T1. ──
|
|
220
|
+
if (readable(scope) && readable(spec) && readable(brief)) {
|
|
221
|
+
const scopeLines = fileLines(scope);
|
|
222
|
+
if (scopeLines.some(line => /^\*\*Write-set/.test(line))) {
|
|
223
|
+
const root = gitRoot(resolve(options.repo ?? '.'));
|
|
224
|
+
if (!root || !readable(join(root, '.env.example')) || !git(root, ['ls-files']).ok) {
|
|
225
|
+
gaps.push('write-set: nie mogę odczytać repo lub .env.example — sprawdź git i repo');
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
const ws = writeSetPaths(scopeLines);
|
|
229
|
+
const inWs = (path) => ws.includes(path);
|
|
230
|
+
const out = outText(scopeLines);
|
|
231
|
+
if (!ws.length)
|
|
232
|
+
gaps.push('write-set: sekcja Write-set bez ścieżek plikowych — wpisz ścieżki w backtickach');
|
|
233
|
+
const contentLines = [...fileLines(spec), ...fileLines(brief)];
|
|
234
|
+
const envExample = fileLines(join(root, '.env.example'));
|
|
235
|
+
for (const token of envTokens(contentLines)) {
|
|
236
|
+
const inExample = envExample.some(line => new RegExp(`^#? *${token}(=|$)`).test(line));
|
|
237
|
+
if (!inWs('.env.example') && !inExample
|
|
238
|
+
&& !git(root, ['grep', '-qF', '-e', token, '--', '.', ':!.env.example', ':!docs', ':!*.md']).ok) {
|
|
239
|
+
gaps.push(`write-set: nowa zmienna env ${token} nie ma wpisu w .env.example — dopisz .env.example do write-setu`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const name of runtimeNames(contentLines, root)) {
|
|
243
|
+
const [path, bare] = name.startsWith('maszynista/') ? [name, ''] : [`maszynista/${name}`, name];
|
|
244
|
+
if (inWs(path))
|
|
245
|
+
continue;
|
|
246
|
+
if (git(root, ['ls-files', '--error-unmatch', '--', path]).ok)
|
|
247
|
+
continue;
|
|
248
|
+
if (git(root, ['check-ignore', '-q', '--', path]).ok)
|
|
249
|
+
continue;
|
|
250
|
+
if (bare && git(root, ['ls-files', '--', `*/${bare}`, bare]).stdout !== '')
|
|
251
|
+
continue;
|
|
252
|
+
if (!inWs('.gitignore'))
|
|
253
|
+
gaps.push(`write-set: nowy plik runtime ${path} nie jest ignorowany przez git — dopisz .gitignore do write-setu`);
|
|
254
|
+
}
|
|
255
|
+
if (contentLines.some(line => /`[^`]*(State|parseState)[^`]*`/.test(line)) && !out.includes('parseState') && !inWs('maszynista/lib.ts')) {
|
|
256
|
+
gaps.push('write-set: stan taktu (State/parseState) zmieniany bez maszynista/lib.ts — parser gubi nowe pola; dopisz maszynista/lib.ts albo wymień parseState w OUT');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// ── 6. Mapa kryterium → rozwiązanie → sprawdzenie ──
|
|
262
|
+
if (readable(scope) && readable(spec)) {
|
|
263
|
+
const dw = doneWhenNumbers(fileLines(scope));
|
|
264
|
+
if (dw.length) {
|
|
265
|
+
const map = mapNumbers(fileLines(spec));
|
|
266
|
+
const missing = dw.filter(n => !map.includes(n));
|
|
267
|
+
if (missing.length) {
|
|
268
|
+
const list = missing.join(',');
|
|
269
|
+
if (hasFixed(scope, 'reksio/propozycja')) {
|
|
270
|
+
gaps.push(`mapa: brak wiersza mapy kryterium→rozwiązanie→sprawdzenie dla done_when #${list} (SPEC.md, sekcja 'Mapa kryterium')`);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
warnings.push(`⚠️ mapa: brak wiersza mapy dla done_when #${list} (SCOPE bez markera reksio/propozycja — ostrzeżenie, nie blokuje)`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// ── Werdykt ──
|
|
279
|
+
const warningText = warnings.map(w => w + '\n').join('');
|
|
280
|
+
if (gaps.length) {
|
|
281
|
+
const stderr = warningText + [
|
|
282
|
+
'🐾 STOP — kroku 4 (sekretarz) NIE odpalać: komplet artefaktów niespełniony.',
|
|
283
|
+
`Braki (${gaps.length}):`,
|
|
284
|
+
...gaps.map(g => ` ✗ ${g}`),
|
|
285
|
+
'Uzupełnij brakujące artefakty/markery (kroki 2-3), potem ponów walidator.',
|
|
286
|
+
].map(line => line + '\n').join('');
|
|
287
|
+
return { exitCode: 2, gaps, warnings, stdout: '', stderr };
|
|
288
|
+
}
|
|
289
|
+
return { exitCode: 0, gaps, warnings, stdout: '✓ komplet 3 artefaktów + markery NASZYCH szablonów — gotowe na sekretarza (krok 4).\n', stderr: warningText };
|
|
290
|
+
}
|
|
291
|
+
/** Waliduje katalog pakietu karty: 20-scope.md, 25-spec.md, 30-brief.md. */
|
|
292
|
+
export function validateSeedPackage(directory, options = {}) {
|
|
293
|
+
return validateSeedFiles(join(directory, SEED_FILES.scope), join(directory, SEED_FILES.spec), join(directory, SEED_FILES.brief), options);
|
|
294
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type Goal = {
|
|
2
|
+
canon: string;
|
|
3
|
+
};
|
|
4
|
+
export type CardQualification = {
|
|
5
|
+
effort: "low" | "medium" | "high" | null;
|
|
6
|
+
trackName: string | null;
|
|
7
|
+
reasons: string[];
|
|
8
|
+
};
|
|
9
|
+
export type QualifyCard = (card: {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
details: {
|
|
13
|
+
scope: string[];
|
|
14
|
+
};
|
|
15
|
+
}) => CardQualification;
|
|
16
|
+
export type Proposal = {
|
|
17
|
+
title: string;
|
|
18
|
+
servesGoal: string;
|
|
19
|
+
servesNS: string | null;
|
|
20
|
+
ns_proof: string;
|
|
21
|
+
goal_ref: string;
|
|
22
|
+
why_now: string;
|
|
23
|
+
done_when: string[];
|
|
24
|
+
scope: string[];
|
|
25
|
+
out: string[];
|
|
26
|
+
codex_effort: NonNullable<CardQualification["effort"]>;
|
|
27
|
+
proposed_track: NonNullable<CardQualification["trackName"]>;
|
|
28
|
+
qualification: CardQualification;
|
|
29
|
+
};
|
|
30
|
+
export declare function stripFence(text: string): string;
|
|
31
|
+
export declare function extractJsonObject(raw: string): string | null;
|
|
32
|
+
export type ProposalParseResult = {
|
|
33
|
+
ok: Proposal[];
|
|
34
|
+
rejected: Array<{
|
|
35
|
+
title: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
}>;
|
|
38
|
+
warnings: string[];
|
|
39
|
+
rawCount: number;
|
|
40
|
+
prose: string;
|
|
41
|
+
empty_reason?: string;
|
|
42
|
+
error?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function parseProposals(raw: string, goals: Goal[], nsIds: string[] | undefined, qualifyCard: QualifyCard): ProposalParseResult;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
function record(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
3
|
+
? value
|
|
4
|
+
: null;
|
|
5
|
+
}
|
|
6
|
+
export function stripFence(text) {
|
|
7
|
+
let s = text.trim();
|
|
8
|
+
const lead = s.match(/^```(?:[a-zA-Z0-9]+)?\n?/);
|
|
9
|
+
if (lead)
|
|
10
|
+
s = s.slice(lead[0].length);
|
|
11
|
+
const trail = s.match(/\n?```\s*$/);
|
|
12
|
+
if (trail)
|
|
13
|
+
s = s.slice(0, s.length - trail[0].length);
|
|
14
|
+
return s.trim();
|
|
15
|
+
}
|
|
16
|
+
export function extractJsonObject(raw) {
|
|
17
|
+
const stripped = stripFence(raw);
|
|
18
|
+
try {
|
|
19
|
+
JSON.parse(stripped);
|
|
20
|
+
return stripped;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Odpowiedź może zawierać prozę przed właściwym obiektem.
|
|
24
|
+
}
|
|
25
|
+
const starts = [];
|
|
26
|
+
const marker = /\{\s*"proposals"\s*:/g;
|
|
27
|
+
for (let match = marker.exec(stripped); match; match = marker.exec(stripped))
|
|
28
|
+
starts.push(match.index);
|
|
29
|
+
for (let candidateIndex = starts.length - 1; candidateIndex >= 0; candidateIndex -= 1) {
|
|
30
|
+
const start = starts[candidateIndex];
|
|
31
|
+
let depth = 0;
|
|
32
|
+
let inString = false;
|
|
33
|
+
let escaped = false;
|
|
34
|
+
for (let index = start; index < stripped.length; index += 1) {
|
|
35
|
+
const char = stripped[index];
|
|
36
|
+
if (inString) {
|
|
37
|
+
if (escaped)
|
|
38
|
+
escaped = false;
|
|
39
|
+
else if (char === "\\")
|
|
40
|
+
escaped = true;
|
|
41
|
+
else if (char === '"')
|
|
42
|
+
inString = false;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (char === '"') {
|
|
46
|
+
inString = true;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (char === "{")
|
|
50
|
+
depth += 1;
|
|
51
|
+
else if (char === "}")
|
|
52
|
+
depth -= 1;
|
|
53
|
+
if (depth !== 0)
|
|
54
|
+
continue;
|
|
55
|
+
const candidate = stripped.slice(start, index + 1);
|
|
56
|
+
try {
|
|
57
|
+
const parsed = record(JSON.parse(candidate));
|
|
58
|
+
if (parsed && Array.isArray(parsed["proposals"]))
|
|
59
|
+
return candidate;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
export function parseProposals(raw, goals, nsIds = [], qualifyCard) {
|
|
70
|
+
const jsonText = extractJsonObject(raw);
|
|
71
|
+
if (jsonText === null)
|
|
72
|
+
return { ok: [], rejected: [], warnings: [], rawCount: 0, prose: raw.trim(), error: "nie-JSON: brak obiektu proposals" };
|
|
73
|
+
const stripped = stripFence(raw);
|
|
74
|
+
const proseIndex = stripped.lastIndexOf(jsonText);
|
|
75
|
+
const prose = proseIndex > 0 ? stripped.slice(0, proseIndex).trim() : "";
|
|
76
|
+
let parsed;
|
|
77
|
+
try {
|
|
78
|
+
parsed = JSON.parse(jsonText);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return { ok: [], rejected: [], warnings: [], rawCount: 0, prose, error: `nie-JSON: ${error instanceof Error ? error.message : String(error)}` };
|
|
82
|
+
}
|
|
83
|
+
const parsedRecord = record(parsed);
|
|
84
|
+
const arr = parsedRecord?.["proposals"];
|
|
85
|
+
if (!Array.isArray(arr))
|
|
86
|
+
return { ok: [], rejected: [], warnings: [], rawCount: 0, prose, error: "brak pola proposals[]" };
|
|
87
|
+
const emptyReason = typeof parsedRecord?.["empty_reason"] === "string" ? parsedRecord["empty_reason"].trim() : "";
|
|
88
|
+
if (arr.length === 0 && !emptyReason && !prose)
|
|
89
|
+
return { ok: [], rejected: [], warnings: [], rawCount: 0, prose, error: "brak empty_reason dla zera" };
|
|
90
|
+
const canon = new Set(goals.map((g) => g.canon));
|
|
91
|
+
const nsCanon = new Set(nsIds.map((id) => id.trim().toUpperCase()).filter(Boolean));
|
|
92
|
+
const ok = [];
|
|
93
|
+
const rejected = [];
|
|
94
|
+
const warnings = [];
|
|
95
|
+
for (const it of arr) {
|
|
96
|
+
if (typeof it !== "object" || it === null || Array.isArray(it)) {
|
|
97
|
+
rejected.push({ title: "", reason: "propozycja nie jest obiektem" });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const p = it;
|
|
101
|
+
const title = String(p.title ?? "").trim();
|
|
102
|
+
if (title.length < 10) {
|
|
103
|
+
rejected.push({ title, reason: "tytuł < 10 znaków" });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!canon.has(String(p.servesGoal))) {
|
|
107
|
+
rejected.push({ title, reason: `servesGoal "${String(p.servesGoal)}" poza kanonem ${[...canon].join("|")}` });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const goalRef = String(p.goal_ref ?? "").trim();
|
|
111
|
+
if (!goalRef) {
|
|
112
|
+
rejected.push({ title, reason: "brak goal_ref" });
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const dw = Array.isArray(p.done_when) ? p.done_when.map(String).filter((s) => s.trim().length > 5) : [];
|
|
116
|
+
if (dw.length === 0) {
|
|
117
|
+
rejected.push({ title, reason: "brak mierzalnego done_when" });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const scope = Array.isArray(p.scope) ? p.scope.map(String) : [];
|
|
121
|
+
const qualification = qualifyCard({ id: "selector-proposal", title, details: { scope } });
|
|
122
|
+
if (!qualification.effort || !qualification.trackName) {
|
|
123
|
+
rejected.push({ title, reason: qualification.reasons.join("; ") });
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const requestedNS = typeof p.servesNS === "string" ? p.servesNS.trim().toUpperCase() : "";
|
|
127
|
+
const servesNS = requestedNS && nsCanon.has(requestedNS) ? requestedNS : null;
|
|
128
|
+
if (servesNS === null) {
|
|
129
|
+
rejected.push({ title, reason: "brak servesNS z kanonu North Star" });
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const nsProof = typeof p.ns_proof === "string" ? p.ns_proof.trim() : "";
|
|
133
|
+
if (!nsProof) {
|
|
134
|
+
rejected.push({ title, reason: "brak ns_proof" });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
ok.push({
|
|
138
|
+
title, servesGoal: String(p.servesGoal), servesNS, ns_proof: nsProof, goal_ref: goalRef, why_now: String(p.why_now ?? "").trim(),
|
|
139
|
+
done_when: dw, scope, out: Array.isArray(p.out) ? p.out.map(String) : [],
|
|
140
|
+
codex_effort: qualification.effort, proposed_track: qualification.trackName, qualification,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return { ok, rejected, warnings, rawCount: arr.length, prose, ...(emptyReason ? { empty_reason: emptyReason } : {}) };
|
|
144
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Null oznacza nieczytelny/pusty scope i zachowanie pełnego checkoutu. Pusta tablica = tylko pliki korzeniowe. */
|
|
2
|
+
export declare function sparseDirectoriesFromScope(scope: unknown): string[] | null;
|
|
3
|
+
/** Odczyt całego HEAD nie rezerwuje zakresu zapisu karty. */
|
|
4
|
+
export declare const SPARSE_EXCLUDED_DIRS: readonly [];
|
|
5
|
+
export declare function sparseReadSet(scope: unknown, topLevelDirectories: readonly string[]): string[] | null;
|
|
6
|
+
export declare function sparseDirectoryError(directory: string): string;
|
|
7
|
+
/** Chroni przed plikiem-widmem utworzonym w katalogu, którego karta nie materializuje. */
|
|
8
|
+
export declare function sparseScopeWriteError(scope: unknown, untrackedPaths: readonly string[]): string | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/** Null oznacza nieczytelny/pusty scope i zachowanie pełnego checkoutu. Pusta tablica = tylko pliki korzeniowe. */
|
|
3
|
+
export function sparseDirectoriesFromScope(scope) {
|
|
4
|
+
if (!Array.isArray(scope) || scope.length === 0 || scope.some((entry) => typeof entry !== "string"))
|
|
5
|
+
return null;
|
|
6
|
+
const directories = new Set();
|
|
7
|
+
for (const entry of scope) {
|
|
8
|
+
const token = entry.trim().split(/\s+/, 1)[0].replace(/`/g, "").replace(/:\d+(?:[-:]\d+)*$/, "");
|
|
9
|
+
if (!token || path.posix.isAbsolute(token))
|
|
10
|
+
return null;
|
|
11
|
+
const normalized = path.posix.normalize(token);
|
|
12
|
+
if (normalized === "." || normalized === ".." || normalized.startsWith("../"))
|
|
13
|
+
return null;
|
|
14
|
+
if (token.includes("/"))
|
|
15
|
+
directories.add(normalized.split("/", 1)[0]);
|
|
16
|
+
}
|
|
17
|
+
return [...directories].sort();
|
|
18
|
+
}
|
|
19
|
+
/** Odczyt całego HEAD nie rezerwuje zakresu zapisu karty. */
|
|
20
|
+
export const SPARSE_EXCLUDED_DIRS = [];
|
|
21
|
+
export function sparseReadSet(scope, topLevelDirectories) {
|
|
22
|
+
const scopedDirectories = sparseDirectoriesFromScope(scope);
|
|
23
|
+
if (scopedDirectories === null)
|
|
24
|
+
return null;
|
|
25
|
+
const excluded = new Set(SPARSE_EXCLUDED_DIRS);
|
|
26
|
+
const readSet = new Set(topLevelDirectories.filter((directory) => directory && !excluded.has(directory)));
|
|
27
|
+
for (const directory of scopedDirectories)
|
|
28
|
+
readSet.add(directory);
|
|
29
|
+
return [...readSet].sort();
|
|
30
|
+
}
|
|
31
|
+
export function sparseDirectoryError(directory) {
|
|
32
|
+
return `katalog \`${directory}/\` poza sparse checkout — dopisz go do \`details.scope\` karty`;
|
|
33
|
+
}
|
|
34
|
+
/** Chroni przed plikiem-widmem utworzonym w katalogu, którego karta nie materializuje. */
|
|
35
|
+
export function sparseScopeWriteError(scope, untrackedPaths) {
|
|
36
|
+
const allowed = sparseDirectoriesFromScope(scope);
|
|
37
|
+
if (allowed === null)
|
|
38
|
+
return null;
|
|
39
|
+
const allowedSet = new Set(allowed);
|
|
40
|
+
for (const candidate of untrackedPaths) {
|
|
41
|
+
const normalized = path.posix.normalize(candidate);
|
|
42
|
+
if (path.posix.isAbsolute(normalized) || normalized === ".." || normalized.startsWith("../"))
|
|
43
|
+
continue;
|
|
44
|
+
const segments = normalized.split("/");
|
|
45
|
+
if (segments.length > 1 && !allowedSet.has(segments[0]))
|
|
46
|
+
return sparseDirectoryError(segments[0]);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type CardLike = {
|
|
2
|
+
id: string;
|
|
3
|
+
details?: Record<string, unknown> | null;
|
|
4
|
+
};
|
|
5
|
+
export declare const TESTER_IDENTITY_DETAILS_KEYS: readonly ["landed", "land_receipt", "decision_queue"];
|
|
6
|
+
export declare const TESTER_IDENTITY_EVENT_FIELDS: readonly ["card_id", "event_type", "proof"];
|
|
7
|
+
/** Recover only a unique receipt or a card-labelled commit already on main. No fetch. */
|
|
8
|
+
export declare function resolveTesterLandedSha(card: CardLike, git: (args: string[]) => string): string | null;
|
|
9
|
+
export declare function validTestSha(value: unknown): value is string;
|
|
10
|
+
export declare function landedSha(card: CardLike): string | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const TESTER_IDENTITY_DETAILS_KEYS = ["landed", "land_receipt", "decision_queue"];
|
|
2
|
+
export const TESTER_IDENTITY_EVENT_FIELDS = ["card_id", "event_type", "proof"];
|
|
3
|
+
const recordValue = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
4
|
+
/** Recover only a unique receipt or a card-labelled commit already on main. No fetch. */
|
|
5
|
+
export function resolveTesterLandedSha(card, git) {
|
|
6
|
+
const existing = landedSha(card);
|
|
7
|
+
if (existing)
|
|
8
|
+
return existing;
|
|
9
|
+
try {
|
|
10
|
+
const details = card.details ?? {};
|
|
11
|
+
const landed = recordValue(details.landed);
|
|
12
|
+
const candidates = [recordValue(landed.receipt).sha, landed.merge_sha, landed.merge_commit, recordValue(details.land_receipt).sha];
|
|
13
|
+
for (const raw of Object.values(recordValue(details.decision_queue))) {
|
|
14
|
+
const event = recordValue(raw);
|
|
15
|
+
const proof = recordValue(event.proof);
|
|
16
|
+
if (event.card_id === card.id && event.event_type === "land" && proof.key === "landed")
|
|
17
|
+
candidates.push(recordValue(proof.value).sha);
|
|
18
|
+
}
|
|
19
|
+
const receipts = [...new Set(candidates.filter((value) => validTestSha(value)))];
|
|
20
|
+
if (receipts.length > 1)
|
|
21
|
+
return null;
|
|
22
|
+
if (receipts.length === 1) {
|
|
23
|
+
git(["merge-base", "--is-ancestor", receipts[0], "origin/main"]);
|
|
24
|
+
return receipts[0];
|
|
25
|
+
}
|
|
26
|
+
const branch = `masz-${card.id.slice(0, 8)}`;
|
|
27
|
+
// Bound visited commits, not grep matches: --grep could walk all of main.
|
|
28
|
+
const parts = git(["log", "origin/main", "--first-parent", "--max-count=200", "--format=%H%x00%B%x00"]).split("\0");
|
|
29
|
+
const escaped = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
30
|
+
const matches = new RegExp(`(^|[^a-zA-Z0-9_-])(?:${escaped(card.id)}|${escaped(branch)})(?=$|[^a-zA-Z0-9_-])`);
|
|
31
|
+
const commits = [];
|
|
32
|
+
for (let index = 0; index + 1 < parts.length; index += 2) {
|
|
33
|
+
const sha = parts[index].trim(), message = parts[index + 1];
|
|
34
|
+
if (validTestSha(sha) && matches.test(message))
|
|
35
|
+
commits.push(sha);
|
|
36
|
+
}
|
|
37
|
+
return commits.length === 1 ? commits[0] : null;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`tester identity ${card.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function validTestSha(value) {
|
|
45
|
+
return typeof value === "string" && /^[a-f0-9]{7,40}$/i.test(value);
|
|
46
|
+
}
|
|
47
|
+
export function landedSha(card) {
|
|
48
|
+
const landed = card.details?.landed;
|
|
49
|
+
return record(landed) && validTestSha(landed.sha) ? landed.sha : null;
|
|
50
|
+
}
|
|
51
|
+
function record(value) {
|
|
52
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
53
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function makeWorkerTmpdir(base?: string, identity?: string): string;
|
|
2
|
+
/** The brief and child process must use this same path, with no per-command override. */
|
|
3
|
+
export declare function workerTmpdirForBrief(env: NodeJS.ProcessEnv): string;
|
|
4
|
+
/** Pass an already allocated directory only when retaining a task's existing ownership. */
|
|
5
|
+
export declare function workerEnv(base: NodeJS.ProcessEnv, tmp?: string): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { mkdtempSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// Darwin's sockaddr_un has a 104-byte path budget, including the trailing NUL.
|
|
4
|
+
const SOCKET_SUFFIX = `/tsx-4294967295/${"x".repeat(40)}`;
|
|
5
|
+
export function makeWorkerTmpdir(base = "/tmp", identity = "") {
|
|
6
|
+
try {
|
|
7
|
+
if (!path.isAbsolute(base))
|
|
8
|
+
throw new Error("wymagana absolutna ścieżka bazowa");
|
|
9
|
+
if (identity && !/^[a-f0-9]{8}$/.test(identity))
|
|
10
|
+
throw new Error("niepoprawna tożsamość katalogu");
|
|
11
|
+
const prefix = path.join(base, `rw-${identity ? `${identity}-` : ""}`);
|
|
12
|
+
if (Buffer.byteLength(`${prefix}XXXXXX${SOCKET_SUFFIX}`) >= 104)
|
|
13
|
+
throw new Error("ścieżka za długa dla gniazda Unix");
|
|
14
|
+
// mkdtemp creates a unique directory with mode 0700, independently of the worktree.
|
|
15
|
+
return mkdtempSync(prefix);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(`ACTIONABLE: TMPDIR Workera: ${error instanceof Error ? error.message : String(error)}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The brief and child process must use this same path, with no per-command override. */
|
|
22
|
+
export function workerTmpdirForBrief(env) {
|
|
23
|
+
const tmp = env.TMPDIR;
|
|
24
|
+
if (!tmp || !path.isAbsolute(tmp) || env.TMP !== tmp || env.TEMP !== tmp) {
|
|
25
|
+
throw new Error("ACTIONABLE: sprzeczne TMPDIR/TMP/TEMP Workera");
|
|
26
|
+
}
|
|
27
|
+
return tmp;
|
|
28
|
+
}
|
|
29
|
+
/** Pass an already allocated directory only when retaining a task's existing ownership. */
|
|
30
|
+
export function workerEnv(base, tmp = makeWorkerTmpdir()) {
|
|
31
|
+
const env = { ...base, TMPDIR: tmp, TMP: tmp, TEMP: tmp };
|
|
32
|
+
workerTmpdirForBrief(env);
|
|
33
|
+
return env;
|
|
34
|
+
}
|