@planu/cli 7.1.0 → 7.1.1

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.
Files changed (33) hide show
  1. package/README.md +60 -67
  2. package/dist/sdd-engine/canonical-tools.d.ts +2 -0
  3. package/dist/sdd-engine/canonical-tools.js +12 -0
  4. package/dist/sdd-engine/contracts.d.ts +1 -0
  5. package/dist/sdd-engine/contracts.js +1 -0
  6. package/dist/sdd-engine/index.d.ts +2 -0
  7. package/dist/sdd-engine/index.js +2 -0
  8. package/dist/sdd-engine/lock-integrity.d.ts +3 -0
  9. package/dist/sdd-engine/lock-integrity.js +52 -0
  10. package/dist/sdd-engine/server.js +14 -5
  11. package/dist/sdd-engine/task-window.js +16 -0
  12. package/dist/sdd-engine/tools/execution-tools.js +6 -7
  13. package/dist/sdd-engine/tools/format-result.d.ts +1 -2
  14. package/dist/sdd-engine/tools/workspace-tools.js +6 -4
  15. package/dist/sdd-engine/workspace-root.d.ts +2 -0
  16. package/dist/sdd-engine/workspace-root.js +20 -0
  17. package/dist/types/sdd-engine.d.ts +19 -1
  18. package/package.json +30 -50
  19. package/templates/AGENTS.md +35 -0
  20. package/templates/en/hu.md +58 -0
  21. package/templates/es/hu.md +58 -0
  22. package/templates/postmortem.md +37 -0
  23. package/templates/pt/hu.md +58 -0
  24. package/templates/skills/git-janitor.md +21 -0
  25. package/templates/skills/legacy-migrator.md +29 -0
  26. package/templates/skills/lib-sync.md +38 -0
  27. package/templates/skills/reconciler.md +26 -0
  28. package/templates/skills/spec-architect.md +48 -0
  29. package/templates/skills/spec-executor.md +32 -0
  30. package/dist/types/common/primitives.d.ts +0 -42
  31. package/dist/types/common/primitives.js +0 -2
  32. package/scripts/check-reliability-policies.mjs +0 -504
  33. package/scripts/lib/portable-paths.mjs +0 -55
@@ -1,504 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { readFile, readdir, stat } from 'node:fs/promises';
4
- import { extname, join, relative, resolve } from 'node:path';
5
- let ts;
6
- try {
7
- ts = (await import('typescript')).default;
8
- } catch {
9
- ts = undefined;
10
- }
11
-
12
- const rootArgIndex = process.argv.indexOf('--root');
13
- const ROOT = resolve(rootArgIndex >= 0 ? (process.argv[rootArgIndex + 1] ?? '') : process.cwd());
14
- const JSON_MODE = process.argv.includes('--json');
15
- const PROTECTED = [
16
- // Persistence and lifecycle transitions are correctness boundaries in their
17
- // entirety. Keeping directories here prevents new stores or transition gates
18
- // from silently escaping the policy as the codebase evolves.
19
- 'src/storage',
20
- 'src/tools/update-status',
21
- 'src/security',
22
- 'src/engine/execution',
23
- 'src/engine/validation',
24
- 'src/engine/safety',
25
- 'src/engine/core-bridge.ts',
26
- ];
27
- const RELEASE_SCRIPTS = [];
28
- const CLASSIFICATION = /reliability-(?:optional|cleanup|compat):\s*[A-Z][A-Z0-9_-]{2,63}/u;
29
- const violations = [];
30
- const structuredViolations = [];
31
-
32
- await stat(ROOT);
33
-
34
- if (process.argv.includes('--print-protected-dirs')) {
35
- process.stdout.write(`${JSON.stringify(PROTECTED)}\n`);
36
- process.exit(0);
37
- }
38
-
39
- for (const root of PROTECTED) {
40
- for (const path of await walk(join(ROOT, root))) {
41
- if (!['.ts', '.tsx', '.js', '.mjs'].includes(extname(path))) continue;
42
- inspectSource(path, await readFile(path, 'utf8'));
43
- }
44
- }
45
- for (const path of RELEASE_SCRIPTS) {
46
- inspectShell(join(ROOT, path), await readFile(join(ROOT, path), 'utf8'));
47
- }
48
-
49
- if (violations.length > 0) {
50
- if (JSON_MODE) {
51
- process.stdout.write(`${JSON.stringify(structuredViolations)}\n`);
52
- } else {
53
- process.stderr.write(
54
- `Reliability policy violations (${violations.length}):\n${violations.join('\n')}\n`,
55
- );
56
- }
57
- process.exit(1);
58
- }
59
- process.stdout.write(JSON_MODE ? '[]\n' : 'Reliability policies passed.\n');
60
-
61
- function inspectSource(path, source) {
62
- if (!ts) {
63
- inspectSourceWithoutCompiler(path, source);
64
- return;
65
- }
66
- const file = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);
67
- const visit = (node) => {
68
- if (ts.isCatchClause(node)) {
69
- const body = node.block;
70
- const bodyText = source.slice(body.getStart(file), body.end);
71
- if (body.statements.length === 0) {
72
- report(path, file, node, 'empty catch is forbidden; add an explicit observable action');
73
- } else if (
74
- !hasThrow(body) &&
75
- !hasTypedDegradation(body) &&
76
- !isExplicitNotFoundBranch(bodyText) &&
77
- !hasClassifiedReport(body)
78
- ) {
79
- report(
80
- path,
81
- file,
82
- node,
83
- 'catch must throw, return a typed failure, handle ENOENT explicitly, or classify and report degradation',
84
- );
85
- }
86
- }
87
- if (
88
- ts.isCallExpression(node) &&
89
- ts.isPropertyAccessExpression(node.expression) &&
90
- node.expression.name.text === 'catch'
91
- ) {
92
- const handler = node.arguments[0];
93
- if (!handler || (!ts.isArrowFunction(handler) && !ts.isFunctionExpression(handler))) {
94
- report(path, file, node, 'Promise.catch must use an auditable inline handler');
95
- } else if (!ts.isBlock(handler.body)) {
96
- report(path, file, node, 'expression Promise.catch suppression is forbidden');
97
- } else if (
98
- !hasThrow(handler.body) &&
99
- !hasTypedDegradation(handler.body) &&
100
- !hasClassifiedReport(handler.body)
101
- ) {
102
- report(
103
- path,
104
- file,
105
- node,
106
- 'Promise.catch must throw, return typed failure, or classify and report',
107
- );
108
- }
109
- }
110
- ts.forEachChild(node, visit);
111
- };
112
- visit(file);
113
- }
114
-
115
- function inspectSourceWithoutCompiler(path, source) {
116
- const structural = maskCommentsAndStrings(source);
117
- for (const block of findCatchBlocks(structural)) {
118
- const bodyText = source.slice(block.bodyStart, block.bodyEnd);
119
- if (bodyText.trim().length === 0) {
120
- reportOffset(
121
- path,
122
- source,
123
- block.catchOffset,
124
- 'empty catch is forbidden; add an explicit observable action',
125
- );
126
- continue;
127
- }
128
- if (!fallbackBodyIsObservable(bodyText)) {
129
- reportOffset(
130
- path,
131
- source,
132
- block.catchOffset,
133
- 'catch must throw, return a typed failure, handle ENOENT explicitly, or classify and report degradation',
134
- );
135
- }
136
- }
137
- for (const handler of findPromiseCatchHandlers(structural)) {
138
- if (handler.kind === 'non-inline') {
139
- reportOffset(
140
- path,
141
- source,
142
- handler.catchOffset,
143
- 'Promise.catch must use an auditable inline handler',
144
- );
145
- continue;
146
- }
147
- if (handler.kind === 'expression') {
148
- reportOffset(
149
- path,
150
- source,
151
- handler.catchOffset,
152
- 'expression Promise.catch suppression is forbidden',
153
- );
154
- continue;
155
- }
156
- const bodyText = source.slice(handler.bodyStart, handler.bodyEnd);
157
- if (!fallbackBodyIsObservable(bodyText)) {
158
- reportOffset(
159
- path,
160
- source,
161
- handler.catchOffset,
162
- 'Promise.catch must throw, return typed failure, or classify and report',
163
- );
164
- }
165
- }
166
- }
167
-
168
- function maskCommentsAndStrings(source) {
169
- const chars = source.split('');
170
- let state = 'code';
171
- const templateExpressionDepth = [];
172
- let regexCharacterClass = false;
173
- for (let index = 0; index < chars.length; index += 1) {
174
- const char = chars[index];
175
- const next = chars[index + 1];
176
- if (state === 'code') {
177
- if (char === '/' && next === '/') {
178
- chars[index] = chars[index + 1] = ' ';
179
- state = 'line-comment';
180
- index += 1;
181
- } else if (char === '/' && next === '*') {
182
- chars[index] = chars[index + 1] = ' ';
183
- state = 'block-comment';
184
- index += 1;
185
- } else if (char === '/' && isRegexLiteralStart(source, index)) {
186
- chars[index] = ' ';
187
- regexCharacterClass = false;
188
- state = 'regex';
189
- } else if (char === "'" || char === '"') {
190
- chars[index] = ' ';
191
- state = char;
192
- } else if (char === '`') {
193
- chars[index] = ' ';
194
- state = 'template';
195
- } else if (templateExpressionDepth.length > 0 && char === '{') {
196
- templateExpressionDepth[templateExpressionDepth.length - 1] += 1;
197
- } else if (templateExpressionDepth.length > 0 && char === '}') {
198
- const last = templateExpressionDepth.length - 1;
199
- templateExpressionDepth[last] -= 1;
200
- if (templateExpressionDepth[last] === 0) {
201
- templateExpressionDepth.pop();
202
- chars[index] = ' ';
203
- state = 'template';
204
- }
205
- }
206
- } else if (state === 'line-comment') {
207
- if (char === '\n') state = 'code';
208
- else chars[index] = ' ';
209
- } else if (state === 'block-comment') {
210
- if (char === '*' && next === '/') {
211
- chars[index] = chars[index + 1] = ' ';
212
- state = 'code';
213
- index += 1;
214
- } else if (char !== '\n') chars[index] = ' ';
215
- } else if (state === 'template') {
216
- if (char === '\\') {
217
- chars[index] = ' ';
218
- if (next !== undefined && next !== '\n') {
219
- chars[index + 1] = ' ';
220
- index += 1;
221
- }
222
- } else if (char === '`') {
223
- chars[index] = ' ';
224
- state = 'code';
225
- } else if (char === '$' && next === '{') {
226
- chars[index] = chars[index + 1] = ' ';
227
- templateExpressionDepth.push(1);
228
- state = 'code';
229
- index += 1;
230
- } else if (char !== '\n') {
231
- chars[index] = ' ';
232
- }
233
- } else if (state === 'regex') {
234
- chars[index] = char === '\n' ? '\n' : ' ';
235
- if (char === '\\' && next !== undefined && next !== '\n') {
236
- chars[index + 1] = ' ';
237
- index += 1;
238
- } else if (char === '[') {
239
- regexCharacterClass = true;
240
- } else if (char === ']') {
241
- regexCharacterClass = false;
242
- } else if (char === '/' && !regexCharacterClass) {
243
- while (/[A-Za-z]/u.test(source[index + 1] ?? '')) {
244
- chars[index + 1] = ' ';
245
- index += 1;
246
- }
247
- state = 'code';
248
- }
249
- } else if (char === '\\') {
250
- chars[index] = ' ';
251
- if (next !== undefined && next !== '\n') {
252
- chars[index + 1] = ' ';
253
- index += 1;
254
- }
255
- } else if (char === state) {
256
- chars[index] = ' ';
257
- state = 'code';
258
- } else if (char !== '\n') {
259
- chars[index] = ' ';
260
- }
261
- }
262
- return chars.join('');
263
- }
264
-
265
- function isRegexLiteralStart(source, slashIndex) {
266
- const before = source.slice(0, slashIndex);
267
- const tokens = before.match(/\+\+|--|=>|[A-Za-z_$][\w$]*|\S/gu);
268
- const token = tokens?.at(-1);
269
- if (!token) return true;
270
- if (token === '++' || token === '--') return false;
271
- return (
272
- /^[([{,:;=!?&|+*%^~<>-]$/u.test(token) ||
273
- /^(?:return|case|throw|delete|void|typeof|instanceof|in|of|yield|await)$/u.test(token) ||
274
- token === '=>'
275
- );
276
- }
277
-
278
- function findCatchBlocks(source) {
279
- const blocks = [];
280
- const catchPattern = /\bcatch\s*(?:\([^)]*\))?\s*\{/gu;
281
- for (const match of source.matchAll(catchPattern)) {
282
- const open = match.index + match[0].lastIndexOf('{');
283
- let depth = 1;
284
- let cursor = open + 1;
285
- for (; cursor < source.length && depth > 0; cursor += 1) {
286
- if (source[cursor] === '{') depth += 1;
287
- else if (source[cursor] === '}') depth -= 1;
288
- }
289
- if (depth === 0) {
290
- blocks.push({ catchOffset: match.index, bodyStart: open + 1, bodyEnd: cursor - 1 });
291
- }
292
- }
293
- return blocks;
294
- }
295
-
296
- function findPromiseCatchHandlers(source) {
297
- const handlers = [];
298
- const catchPattern = /\.catch\b/gu;
299
- const callablePattern =
300
- /^\(\s*(?:(?:async\s+)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>|function(?:\s+[A-Za-z_$][\w$]*)?\s*\([^)]*\))/u;
301
- const blockPattern = new RegExp(`${callablePattern.source}\\s*\\{`, 'u');
302
- for (const match of source.matchAll(catchPattern)) {
303
- let callStart = match.index + match[0].length;
304
- callStart = skipWhitespace(source, callStart);
305
- if (source.startsWith('?.', callStart)) callStart = skipWhitespace(source, callStart + 2);
306
- if (source[callStart] === '<') {
307
- const typeArgumentsEnd = findBalancedTypeArgumentsEnd(source, callStart);
308
- if (typeArgumentsEnd === null) continue;
309
- callStart = skipWhitespace(source, typeArgumentsEnd + 1);
310
- }
311
- if (source[callStart] !== '(') continue;
312
- const remainder = source.slice(callStart);
313
- const blockHeader = blockPattern.exec(remainder);
314
- if (!blockHeader) {
315
- handlers.push({
316
- catchOffset: match.index,
317
- kind: callablePattern.test(remainder) ? 'expression' : 'non-inline',
318
- });
319
- continue;
320
- }
321
- const open = callStart + blockHeader[0].lastIndexOf('{');
322
- const close = findBalancedBlockEnd(source, open);
323
- if (close === null) {
324
- handlers.push({ catchOffset: match.index, kind: 'non-inline' });
325
- continue;
326
- }
327
- handlers.push({
328
- bodyEnd: close,
329
- bodyStart: open + 1,
330
- catchOffset: match.index,
331
- kind: 'block',
332
- });
333
- }
334
- return handlers;
335
- }
336
-
337
- function skipWhitespace(source, start) {
338
- let cursor = start;
339
- while (/\s/u.test(source[cursor] ?? '')) cursor += 1;
340
- return cursor;
341
- }
342
-
343
- function findBalancedTypeArgumentsEnd(source, open) {
344
- let depth = 1;
345
- for (let cursor = open + 1; cursor < source.length; cursor += 1) {
346
- if (source[cursor] === '<') depth += 1;
347
- else if (source[cursor] === '>' && source[cursor - 1] !== '=') depth -= 1;
348
- if (depth === 0) return cursor;
349
- }
350
- return null;
351
- }
352
-
353
- function findBalancedBlockEnd(source, open) {
354
- let depth = 1;
355
- for (let cursor = open + 1; cursor < source.length; cursor += 1) {
356
- if (source[cursor] === '{') depth += 1;
357
- else if (source[cursor] === '}') depth -= 1;
358
- if (depth === 0) return cursor;
359
- }
360
- return null;
361
- }
362
-
363
- function fallbackBodyIsObservable(bodyText) {
364
- const structural = maskCommentsAndStrings(bodyText);
365
- if (/\bthrow\b/u.test(structural)) return true;
366
- if (/(?:ENOENT|ESRCH|isNotFound|notFound)/u.test(structural) && /\breturn\b/u.test(structural)) {
367
- return true;
368
- }
369
- const classified =
370
- /\b(?:reportClassifiedDegradation|emitClassifiedDegradation)\s*\(\s*['"][A-Z][A-Z0-9_-]{2,63}['"]/gu;
371
- for (const match of bodyText.matchAll(classified)) {
372
- if (
373
- /^(?:reportClassifiedDegradation|emitClassifiedDegradation)\b/u.test(
374
- structural.slice(match.index),
375
- )
376
- ) {
377
- return true;
378
- }
379
- }
380
- if (
381
- /\breturn\s*\{[\s\S]*?(?:(?:ok|valid)\s*:\s*false|(?:blocked|isError)\s*:\s*true)/u.test(
382
- structural,
383
- )
384
- ) {
385
- return true;
386
- }
387
- const typedStatus = /\bstatus\s*:\s*['"](?:failed|degraded|invalid)['"]/gu;
388
- for (const match of bodyText.matchAll(typedStatus)) {
389
- if (/^status\s*:/u.test(structural.slice(match.index))) return true;
390
- }
391
- return false;
392
- }
393
-
394
- function hasThrow(node) {
395
- let found = false;
396
- const visit = (child) => {
397
- if (ts.isThrowStatement(child)) {
398
- found = true;
399
- return;
400
- }
401
- ts.forEachChild(child, visit);
402
- };
403
- visit(node);
404
- return found;
405
- }
406
-
407
- function hasClassifiedReport(node) {
408
- let found = false;
409
- const visit = (child) => {
410
- if (
411
- ts.isCallExpression(child) &&
412
- ts.isIdentifier(child.expression) &&
413
- ['reportClassifiedDegradation', 'emitClassifiedDegradation'].includes(
414
- child.expression.text,
415
- ) &&
416
- child.arguments.length > 0 &&
417
- ts.isStringLiteral(child.arguments[0]) &&
418
- /^[A-Z][A-Z0-9_-]{2,63}$/u.test(child.arguments[0].text)
419
- ) {
420
- found = true;
421
- return;
422
- }
423
- ts.forEachChild(child, visit);
424
- };
425
- visit(node);
426
- return found;
427
- }
428
-
429
- function hasTypedDegradation(node) {
430
- let found = false;
431
- const visit = (child) => {
432
- if (
433
- ts.isReturnStatement(child) &&
434
- child.expression &&
435
- ts.isObjectLiteralExpression(child.expression)
436
- ) {
437
- found = child.expression.properties.some((property) => {
438
- if (!ts.isPropertyAssignment(property)) return false;
439
- const name = property.name.getText();
440
- const value = property.initializer.getText();
441
- return (
442
- ((name === 'ok' || name === 'valid') && value === 'false') ||
443
- ((name === 'blocked' || name === 'isError') && value === 'true') ||
444
- (name === 'status' && /^['"](?:failed|degraded|invalid)['"]$/u.test(value))
445
- );
446
- });
447
- if (found) return;
448
- }
449
- ts.forEachChild(child, visit);
450
- };
451
- visit(node);
452
- return found;
453
- }
454
-
455
- function isExplicitNotFoundBranch(text) {
456
- return /(?:ENOENT|ESRCH|isNotFound|notFound)/u.test(text) && /\breturn\b/u.test(text);
457
- }
458
-
459
- function inspectShell(path, source) {
460
- const lines = source.split('\n');
461
- lines.forEach((line, index) => {
462
- if (!/\|\|\s*true/u.test(line)) return;
463
- const context = `${lines[index - 1] ?? ''}\n${line}`;
464
- if (!CLASSIFICATION.test(context)) {
465
- const relPath = relative(ROOT, path);
466
- const lineNumber = index + 1;
467
- const rule = 'unclassified shell suppression';
468
- violations.push(`${relPath}:${String(lineNumber)} ${rule}`);
469
- structuredViolations.push({ file: relPath, line: lineNumber, rule });
470
- }
471
- });
472
- }
473
-
474
- function report(path, file, node, message) {
475
- const position = file.getLineAndCharacterOfPosition(node.getStart(file));
476
- const relPath = relative(ROOT, path);
477
- const line = position.line + 1;
478
- violations.push(`${relPath}:${String(line)} ${message}`);
479
- structuredViolations.push({ file: relPath, line, rule: message });
480
- }
481
-
482
- function reportOffset(path, source, offset, message) {
483
- const relPath = relative(ROOT, path);
484
- const line = source.slice(0, offset).split('\n').length;
485
- violations.push(`${relPath}:${String(line)} ${message}`);
486
- structuredViolations.push({ file: relPath, line, rule: message });
487
- }
488
-
489
- async function walk(path) {
490
- let metadata;
491
- try {
492
- metadata = await stat(path);
493
- } catch (error) {
494
- if (error?.code === 'ENOENT') return [];
495
- throw error;
496
- }
497
- if (metadata.isFile()) return [path];
498
- const paths = [];
499
- for (const entry of await readdir(path, { withFileTypes: true })) {
500
- if (entry.name === 'node_modules' || entry.name === 'dist') continue;
501
- paths.push(...(await walk(join(path, entry.name))));
502
- }
503
- return paths;
504
- }
@@ -1,55 +0,0 @@
1
- import { homedir } from 'node:os';
2
- import { join } from 'node:path';
3
-
4
- function escapeRegExp(value) {
5
- return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
6
- }
7
-
8
- function pathExpression(path) {
9
- return escapeRegExp(path).replaceAll('/', '[\\\\/]');
10
- }
11
-
12
- function pathSegmentCount(path) {
13
- return path.split(/[\\/]/u).filter(Boolean).length;
14
- }
15
-
16
- function planuDataDirectory(home, env, platform) {
17
- if (platform === 'win32') {
18
- const local = env.LOCALAPPDATA?.trim() || join(home, 'AppData', 'Local');
19
- return join(local, 'Planu', 'data');
20
- }
21
- if (platform === 'darwin') {
22
- return join(home, 'Library', 'Application Support', 'Planu', 'data');
23
- }
24
- const dataHome = env.XDG_DATA_HOME?.trim() || join(home, '.local', 'share');
25
- return join(dataHome, 'planu');
26
- }
27
-
28
- export function portablePathPatterns({
29
- root,
30
- homeDirectory = homedir(),
31
- env = process.env,
32
- platform = process.platform,
33
- } = {}) {
34
- const home = homeDirectory.replace(/[\\/]$/u, '');
35
- const candidates = [
36
- { path: planuDataDirectory(home, env, platform), replacement: '<planu-data-dir>' },
37
- { path: root, replacement: '<repo-root>' },
38
- { path: home, replacement: '<home>' },
39
- ].filter(
40
- (candidate) => typeof candidate.path === 'string' && pathSegmentCount(candidate.path) >= 2,
41
- );
42
- candidates.sort((left, right) => right.path.length - left.path.length);
43
- return candidates.map(({ path, replacement }) => ({
44
- pattern: new RegExp(`(?:file:)?${pathExpression(path)}(?![A-Za-z0-9._-])`, 'giu'),
45
- replacement,
46
- }));
47
- }
48
-
49
- export function redactPortablePaths(text, options = {}) {
50
- if (typeof text !== 'string') return text;
51
- return portablePathPatterns(options).reduce(
52
- (redacted, { pattern, replacement }) => redacted.replace(pattern, replacement),
53
- text,
54
- );
55
- }