@cassiomc1/forgeloop 2.0.0-rc.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.cursor/rules/project-loop.mdc +1 -1
  2. package/.github/copilot-instructions.md +1 -1
  3. package/AGENTS.md +1 -1
  4. package/CLAUDE.md +1 -1
  5. package/CONTRIBUTING.md +3 -1
  6. package/DOCS_INDEX.md +2 -0
  7. package/ENG/accessibility-eng.md +6 -6
  8. package/ENG/clean-code-eng.md +2 -2
  9. package/ENG/design-code-eng.md +17 -15
  10. package/ENG/documentation-quality-eng.md +10 -2
  11. package/ENG/dotnet-aspnetcore-development-eng.md +8 -4
  12. package/ENG/flutter-development-eng.md +38 -59
  13. package/ENG/games-code-design-web-eng.md +2 -2
  14. package/ENG/nodejs-backend-development-eng.md +7 -4
  15. package/ENG/perf-code-eng.md +3 -3
  16. package/ENG/php-development-eng.md +2 -2
  17. package/ENG/premium-sites-studio-eng.md +9 -2
  18. package/ENG/python-development-eng.md +7 -1
  19. package/ENG/rust-development-eng.md +22 -32
  20. package/ENG/sec-code-eng.md +19 -3
  21. package/ENG/sql-development-eng.md +5 -4
  22. package/ENG/taste-frontend-eng.md +125 -4
  23. package/ENG/test-code-eng.md +2 -2
  24. package/GUIDE_ROUTER.md +18 -4
  25. package/PROTOCOL_INTEGRATION.md +21 -0
  26. package/README.md +15 -13
  27. package/THIRD_PARTY_NOTICES.md +60 -6
  28. package/docs/AGENT_PROTOCOL_SUMMARY.md +1 -1
  29. package/docs/AGENT_SKILL.md +16 -0
  30. package/docs/DOCUMENTATION_GUIDE.md +6 -0
  31. package/docs/FORGELOOP_AUDIT.md +1 -1
  32. package/docs/GETTING_STARTED.md +8 -1
  33. package/docs/GUIDE_MAINTENANCE.md +106 -0
  34. package/docs/PACKAGE_CONTENTS.md +22 -5
  35. package/docs/RELEASE_CHECKLIST.md +68 -35
  36. package/docs/REVENUE_CENTRIC_DESIGN.md +69 -0
  37. package/docs/SECURITY_AUDIT_SKILL.md +131 -0
  38. package/docs/SECURITY_REVIEW.md +6 -0
  39. package/docs/STABLE_2_ACCEPTANCE.md +127 -0
  40. package/docs/TROUBLESHOOTING.md +171 -0
  41. package/docs/documentation-manifest.json +244 -0
  42. package/package.json +12 -7
  43. package/scripts/generate-forgeloop-skill.mjs +8 -0
  44. package/scripts/verify-revenue-design-skill.mjs +37 -0
  45. package/scripts/verify-security-audit-skill.mjs +68 -0
  46. package/skills/forgeloop/SKILL.md +8 -0
  47. package/skills/forgeloop/references/revenue-centric-design/LICENSE +30 -0
  48. package/skills/forgeloop/references/revenue-centric-design/PIN.json +14 -0
  49. package/skills/forgeloop/references/revenue-centric-design/SKILL.md +64 -0
  50. package/skills/forgeloop/references/revenue-centric-design/references/playbook.md +36 -0
  51. package/skills/security-audit/AI-AND-LLM.md +83 -0
  52. package/skills/security-audit/ATTACK-CLASSES.md +130 -0
  53. package/skills/security-audit/CLIENT-SIDE.md +83 -0
  54. package/skills/security-audit/CLOUD-AND-DEPLOYMENT.md +86 -0
  55. package/skills/security-audit/DATA-ISOLATION-AND-LIFECYCLE.md +84 -0
  56. package/skills/security-audit/DESKTOP-MOBILE-AND-LOCAL-IPC.md +89 -0
  57. package/skills/security-audit/HUNTING.md +251 -0
  58. package/skills/security-audit/LICENSE +21 -0
  59. package/skills/security-audit/MEMORY-SAFETY-AND-BINARY.md +101 -0
  60. package/skills/security-audit/PIN.json +30 -0
  61. package/skills/security-audit/PROTOCOLS-RPC-AND-MESSAGING.md +81 -0
  62. package/skills/security-audit/RECONNAISSANCE.md +156 -0
  63. package/skills/security-audit/RESOURCE-EXHAUSTION-AND-AVAILABILITY.md +78 -0
  64. package/skills/security-audit/SKILL.md +192 -0
  65. package/skills/security-audit/SUPPLY-CHAIN-AND-RELEASE.md +73 -0
  66. package/skills/security-audit/VALIDATION-AND-REPORTING.md +186 -0
  67. package/skills/security-audit/WEB-PROTOCOL-AND-AUTH.md +105 -0
  68. package/skills/security-audit/report-schema.json +461 -0
  69. package/skills/security-audit/validate-coverage-ledger.cjs +872 -0
  70. package/skills/security-audit/validate-coverage-ledger.test.cjs +740 -0
  71. package/skills/security-audit/validate-findings.cjs +773 -0
  72. package/skills/security-audit/validate-findings.test.cjs +652 -0
  73. package/src/core/completion-artifacts.js +4 -7
  74. package/src/core/diagnosis.js +3 -5
  75. package/src/core/diagnostic-record.js +4 -4
  76. package/src/core/error-codes.js +180 -2
  77. package/src/core/next-action-recovery-phases.js +3 -0
  78. package/src/core/next-action-review-correction.js +26 -0
  79. package/src/core/next-action-review-phase.js +25 -15
  80. package/src/core/parsers/dotnet-project.js +221 -0
  81. package/src/core/parsers/limits.js +9 -0
  82. package/src/core/parsers/pubspec.js +307 -0
  83. package/src/core/parsers/shared.js +4 -0
  84. package/src/core/project-detection.js +6 -527
  85. package/src/core/reconcile-closure.js +5 -0
  86. package/src/core/review-correction.js +51 -0
  87. package/src/storage/capabilities.js +1 -1
@@ -32,6 +32,12 @@ import { inspectJavaProject } from "./java-project.js";
32
32
  import { inspectNativeProject, nativeFrameworkForSource } from "./c-cpp-project.js";
33
33
  import { inspectSwiftProject, swiftSourceLooksExecutable } from "./swift-project.js";
34
34
  import { looksLikeSql, parseSqlProject } from "./sql-project.js";
35
+ import { PROJECT_DETECTION_LIMITS } from "./parsers/limits.js";
36
+ import { DOTNET_SDKS, parseDotNetProject, parseXmlStructure } from "./parsers/dotnet-project.js";
37
+ import { parsePubspec, splitTopLevel } from "./parsers/pubspec.js";
38
+ import { uniqueSorted } from "./parsers/shared.js";
39
+
40
+ export { PROJECT_DETECTION_LIMITS, parseDotNetProject, parsePubspec };
35
41
 
36
42
  export const PROJECT_EVIDENCE_SCHEMA_VERSION = 1;
37
43
 
@@ -42,22 +48,11 @@ export const PROJECT_EVIDENCE_SCOPES = Object.freeze([
42
48
  "NONE",
43
49
  ]);
44
50
 
45
- export const PROJECT_DETECTION_LIMITS = Object.freeze({
46
- maxManifests: 256,
47
- maxSolutionFiles: 64,
48
- maxManifestBytes: 1024 * 1024,
49
- maxSourceFiles: 256,
50
- maxSourceBytes: 512 * 1024,
51
- maxVisitedDirectories: 4096,
52
- maxVisitedEntries: 20000,
53
- });
54
51
  const MAX_MANIFESTS = PROJECT_DETECTION_LIMITS.maxManifests;
55
52
  const MAX_SOLUTION_FILES = PROJECT_DETECTION_LIMITS.maxSolutionFiles;
56
53
  const MAX_MANIFEST_BYTES = PROJECT_DETECTION_LIMITS.maxManifestBytes;
57
54
  const MAX_SOURCE_FILES = PROJECT_DETECTION_LIMITS.maxSourceFiles;
58
55
  const MAX_SOURCE_BYTES = PROJECT_DETECTION_LIMITS.maxSourceBytes;
59
- const MAX_XML_TEXT_LENGTH = 4096;
60
- const UNSUPPORTED_YAML_VALUE = Symbol("unsupported-yaml-value");
61
56
  const IGNORED_DIRECTORIES = new Set([
62
57
  ".dart_tool",
63
58
  ".forgeloop",
@@ -84,20 +79,6 @@ const IGNORED_DIRECTORIES = new Set([
84
79
  "third_party",
85
80
  ]);
86
81
  const DOTNET_PROJECT_EXTENSIONS = new Set([".csproj", ".fsproj", ".vbproj"]);
87
- const DOTNET_SDKS = new Set([
88
- "Microsoft.NET.Sdk",
89
- "Microsoft.NET.Sdk.Web",
90
- "Microsoft.NET.Sdk.Worker",
91
- "Microsoft.NET.Sdk.Razor",
92
- "Microsoft.NET.Sdk.BlazorWebAssembly",
93
- "Aspire.AppHost.Sdk",
94
- "MSTest.Sdk",
95
- ]);
96
- const ASPNETCORE_SDKS = new Set([
97
- "Microsoft.NET.Sdk.Web",
98
- "Microsoft.NET.Sdk.Razor",
99
- "Microsoft.NET.Sdk.BlazorWebAssembly",
100
- ]);
101
82
  const SHARED_DOTNET_FILES = new Set([
102
83
  "directory.build.props",
103
84
  "directory.build.targets",
@@ -247,308 +228,6 @@ function portableRelative(root, absolutePath) {
247
228
  return relative === "" ? "." : relative;
248
229
  }
249
230
 
250
- function uniqueSorted(values) {
251
- return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))]
252
- .sort((left, right) => left.localeCompare(right));
253
- }
254
-
255
- function stripYamlComment(value) {
256
- let quote = null;
257
- let braceDepth = 0;
258
- let bracketDepth = 0;
259
- for (let index = 0; index < value.length; index += 1) {
260
- const character = value[index];
261
- if (quote === "\"") {
262
- if (character === "\\") index += 1;
263
- else if (character === "\"") quote = null;
264
- continue;
265
- }
266
- if (quote === "'") {
267
- if (character === "'" && value[index + 1] === "'") index += 1;
268
- else if (character === "'") quote = null;
269
- continue;
270
- }
271
- if (character === "\"" || character === "'") {
272
- quote = character;
273
- continue;
274
- }
275
- if (character === "{") braceDepth += 1;
276
- else if (character === "}") braceDepth = Math.max(0, braceDepth - 1);
277
- else if (character === "[") bracketDepth += 1;
278
- else if (character === "]") bracketDepth = Math.max(0, bracketDepth - 1);
279
- else if (character === "#" && braceDepth === 0 && bracketDepth === 0
280
- && (index === 0 || /\s/u.test(value[index - 1]))) {
281
- return value.slice(0, index).trimEnd();
282
- }
283
- }
284
- return value.trimEnd();
285
- }
286
-
287
- function findTopLevelColon(value) {
288
- let quote = null;
289
- let braceDepth = 0;
290
- let bracketDepth = 0;
291
- for (let index = 0; index < value.length; index += 1) {
292
- const character = value[index];
293
- if (quote === "\"") {
294
- if (character === "\\") index += 1;
295
- else if (character === "\"") quote = null;
296
- continue;
297
- }
298
- if (quote === "'") {
299
- if (character === "'" && value[index + 1] === "'") index += 1;
300
- else if (character === "'") quote = null;
301
- continue;
302
- }
303
- if (character === "\"" || character === "'") {
304
- quote = character;
305
- continue;
306
- }
307
- if (character === "{") braceDepth += 1;
308
- else if (character === "}") braceDepth = Math.max(0, braceDepth - 1);
309
- else if (character === "[") bracketDepth += 1;
310
- else if (character === "]") bracketDepth = Math.max(0, bracketDepth - 1);
311
- else if (character === ":" && braceDepth === 0 && bracketDepth === 0) return index;
312
- }
313
- return -1;
314
- }
315
-
316
- function unquoteYamlScalar(value) {
317
- const trimmed = value.trim();
318
- if (trimmed.length < 2) return trimmed;
319
- if (trimmed.startsWith("\"") && trimmed.endsWith("\"")) {
320
- try {
321
- return JSON.parse(trimmed);
322
- } catch {
323
- return null;
324
- }
325
- }
326
- if (trimmed.startsWith("'") && trimmed.endsWith("'")) {
327
- return trimmed.slice(1, -1).replaceAll("''", "'");
328
- }
329
- return trimmed;
330
- }
331
-
332
- function splitTopLevel(value, delimiter = ",") {
333
- const parts = [];
334
- let start = 0;
335
- let quote = null;
336
- let braceDepth = 0;
337
- let bracketDepth = 0;
338
- for (let index = 0; index < value.length; index += 1) {
339
- const character = value[index];
340
- if (quote === "\"") {
341
- if (character === "\\") index += 1;
342
- else if (character === "\"") quote = null;
343
- continue;
344
- }
345
- if (quote === "'") {
346
- if (character === "'" && value[index + 1] === "'") index += 1;
347
- else if (character === "'") quote = null;
348
- continue;
349
- }
350
- if (character === "\"" || character === "'") {
351
- quote = character;
352
- continue;
353
- }
354
- if (character === "{") braceDepth += 1;
355
- else if (character === "}") braceDepth = Math.max(0, braceDepth - 1);
356
- else if (character === "[") bracketDepth += 1;
357
- else if (character === "]") bracketDepth = Math.max(0, bracketDepth - 1);
358
- else if (character === delimiter && braceDepth === 0 && bracketDepth === 0) {
359
- parts.push(value.slice(start, index).trim());
360
- start = index + 1;
361
- }
362
- }
363
- parts.push(value.slice(start).trim());
364
- return parts.filter(Boolean);
365
- }
366
-
367
- function parseInlineMap(value) {
368
- const trimmed = value.trim();
369
- if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) return null;
370
- const body = trimmed.slice(1, -1).trim();
371
- if (body === "") return {};
372
- const result = {};
373
- for (const pair of splitTopLevel(body)) {
374
- const separator = findTopLevelColon(pair);
375
- if (separator <= 0) return null;
376
- const key = unquoteYamlScalar(pair.slice(0, separator));
377
- const rawValue = pair.slice(separator + 1).trim();
378
- if (!key || rawValue === "" || Object.prototype.hasOwnProperty.call(result, key)) return null;
379
- const parsedValue = parseYamlValue(rawValue);
380
- if (parsedValue === null) return null;
381
- result[key] = parsedValue;
382
- }
383
- return result;
384
- }
385
-
386
- function parseYamlValue(value) {
387
- const withoutComment = stripYamlComment(value).trim();
388
- if (withoutComment === "") return "";
389
- if (withoutComment.startsWith("{")) {
390
- return withoutComment.endsWith("}") ? parseInlineMap(withoutComment) : null;
391
- }
392
- if (withoutComment.startsWith("[")) return UNSUPPORTED_YAML_VALUE;
393
- return unquoteYamlScalar(withoutComment);
394
- }
395
-
396
- function containsUnsupportedYamlValue(value) {
397
- if (value === UNSUPPORTED_YAML_VALUE) return true;
398
- if (!value || typeof value !== "object") return false;
399
- return Object.values(value).some(containsUnsupportedYamlValue);
400
- }
401
-
402
- function parseYamlLine(line) {
403
- if (/^\t/u.test(line)) return { invalid: true };
404
- const indent = line.match(/^ */u)?.[0].length ?? 0;
405
- const content = stripYamlComment(line.slice(indent)).trim();
406
- if (content === "" || content === "---" || content === "..." || content.startsWith("#")) {
407
- return null;
408
- }
409
- if (content.startsWith("- ") || content === "-") return { indent, sequence: true };
410
- const separator = findTopLevelColon(content);
411
- if (separator <= 0) return null;
412
- const key = unquoteYamlScalar(content.slice(0, separator));
413
- if (!key) return null;
414
- const rawValue = content.slice(separator + 1).trim();
415
- const value = rawValue === "" ? "" : parseYamlValue(rawValue);
416
- if (value === null) return { invalid: true };
417
- return { indent, key, value };
418
- }
419
-
420
- function dependencySdkValue(entry) {
421
- if (!entry) return null;
422
- if (entry.value && typeof entry.value === "object" && !Array.isArray(entry.value)) {
423
- return entry.value.sdk === "flutter" ? "flutter" : null;
424
- }
425
- return entry.value === "" ? null : null;
426
- }
427
-
428
- function parseYamlLines(lines) {
429
- const parsedLines = [];
430
- let valid = true;
431
- for (const line of lines) {
432
- const parsed = parseYamlLine(line);
433
- if (parsed?.invalid) valid = false;
434
- parsedLines.push(parsed);
435
- }
436
- return { parsedLines, valid };
437
- }
438
-
439
- function findSectionIndexes(parsedLines, sectionName) {
440
- const sectionIndexes = [];
441
- for (let index = 0; index < parsedLines.length; index += 1) {
442
- const parsed = parsedLines[index];
443
- if (parsed?.indent === 0 && parsed.key === sectionName) sectionIndexes.push(index);
444
- }
445
- return sectionIndexes;
446
- }
447
-
448
- function dependencyEntriesFromInline(value) {
449
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
450
- return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, { value: entryValue }]));
451
- }
452
-
453
- function findSectionIndent(parsedLines, sectionIndex) {
454
- for (let index = sectionIndex + 1; index < parsedLines.length; index += 1) {
455
- const parsed = parsedLines[index];
456
- if (!parsed) continue;
457
- if (parsed.indent === 0) break;
458
- return parsed.indent;
459
- }
460
- return null;
461
- }
462
-
463
- function readNestedDependencyMap(parsedLines, entryIndex, parentIndent) {
464
- let nestedIndent = null;
465
- const nested = {};
466
- for (let index = entryIndex + 1; index < parsedLines.length; index += 1) {
467
- const parsed = parsedLines[index];
468
- if (!parsed) continue;
469
- if (parsed.invalid) return null;
470
- if (parsed.sequence) {
471
- if (parsed.indent > parentIndent) return null;
472
- break;
473
- }
474
- if (parsed.indent <= parentIndent) break;
475
- if (containsUnsupportedYamlValue(parsed.value)) return null;
476
- nestedIndent ??= parsed.indent;
477
- if (parsed.indent !== nestedIndent) continue;
478
- if (Object.prototype.hasOwnProperty.call(nested, parsed.key)) return null;
479
- nested[parsed.key] = parsed.value;
480
- }
481
- return nested;
482
- }
483
-
484
- function readBlockDependencyEntries(parsedLines, sectionIndex, sectionIndent) {
485
- const entries = {};
486
- for (let index = sectionIndex + 1; index < parsedLines.length; index += 1) {
487
- const parsed = parsedLines[index];
488
- if (!parsed) continue;
489
- if (parsed.invalid) return null;
490
- if (parsed.indent === 0) break;
491
- if (parsed.sequence || containsUnsupportedYamlValue(parsed.value)) return null;
492
- if (parsed.indent !== sectionIndent) continue;
493
- if (Object.prototype.hasOwnProperty.call(entries, parsed.key)) return null;
494
- const entry = { value: parsed.value };
495
- if (parsed.value === "") {
496
- const nested = readNestedDependencyMap(parsedLines, index, parsed.indent);
497
- if (nested === null) return null;
498
- entry.value = nested;
499
- }
500
- entries[parsed.key] = entry;
501
- }
502
- return entries;
503
- }
504
-
505
- function readDependencySection(lines, sectionName) {
506
- const { parsedLines, valid } = parseYamlLines(lines);
507
- const sectionIndexes = findSectionIndexes(parsedLines, sectionName);
508
- if (sectionIndexes.length > 1) return { present: true, valid: false, entries: {} };
509
- if (sectionIndexes.length === 0) return { present: false, valid, entries: {} };
510
-
511
- const sectionIndex = sectionIndexes[0];
512
- const section = parsedLines[sectionIndex];
513
- const entries = {};
514
- if (section.value !== "") {
515
- if (containsUnsupportedYamlValue(section.value)) {
516
- return { present: true, valid: false, entries: {} };
517
- }
518
- const inlineEntries = dependencyEntriesFromInline(section.value);
519
- if (inlineEntries === null) {
520
- return { present: true, valid: false, entries: {} };
521
- }
522
- return { present: true, valid, entries: inlineEntries };
523
- }
524
-
525
- const sectionIndent = findSectionIndent(parsedLines, sectionIndex);
526
- if (sectionIndent === null) return { present: true, valid, entries };
527
- const blockEntries = readBlockDependencyEntries(parsedLines, sectionIndex, sectionIndent);
528
- if (blockEntries === null) return { present: true, valid: false, entries: {} };
529
- return { present: true, valid, entries: blockEntries };
530
- }
531
-
532
- export function parsePubspec(text) {
533
- if (typeof text !== "string" || text.length > MAX_MANIFEST_BYTES || /\r(?!\n)/u.test(text)) {
534
- return { valid: false, primary: false, flutterTest: false, override: false };
535
- }
536
- const lines = text.replaceAll("\r\n", "\n").split("\n");
537
- const dependencies = readDependencySection(lines, "dependencies");
538
- const devDependencies = readDependencySection(lines, "dev_dependencies");
539
- const dependencyOverrides = readDependencySection(lines, "dependency_overrides");
540
- const valid = dependencies.valid && devDependencies.valid && dependencyOverrides.valid;
541
- const primary = valid && dependencySdkValue(dependencies.entries.flutter) === "flutter";
542
- const flutterTest = valid && dependencySdkValue(devDependencies.entries.flutter_test) === "flutter";
543
- const override = valid && dependencySdkValue(dependencyOverrides.entries.flutter) === "flutter";
544
- return {
545
- valid,
546
- primary,
547
- flutterTest,
548
- override,
549
- };
550
- }
551
-
552
231
  function invalidNodePackage() {
553
232
  return {
554
233
  valid: false,
@@ -790,206 +469,6 @@ export function parsePackageJson(text) {
790
469
  };
791
470
  }
792
471
 
793
- function invalidDotNetProject() {
794
- return {
795
- valid: false,
796
- sdkStyle: false,
797
- projectSdks: [],
798
- targetFrameworks: [],
799
- frameworkReferences: [],
800
- packageReferences: [],
801
- projectReferences: [],
802
- dotnet: false,
803
- aspnetcore: false,
804
- abp: false,
805
- };
806
- }
807
-
808
- function findXmlTagEnd(text, start) {
809
- let quote = null;
810
- for (let index = start; index < text.length; index += 1) {
811
- const character = text[index];
812
- if (quote) {
813
- if (character === quote) quote = null;
814
- } else if (character === "\"" || character === "'") {
815
- quote = character;
816
- } else if (character === ">") {
817
- return index;
818
- }
819
- }
820
- return -1;
821
- }
822
-
823
- function parseXmlAttributes(text) {
824
- const attributes = {};
825
- let index = 0;
826
- while (index < text.length) {
827
- while (index < text.length && /\s/u.test(text[index])) index += 1;
828
- if (index >= text.length) break;
829
- const name = text.slice(index).match(/^[A-Za-z_][A-Za-z0-9_.:-]*/u)?.[0];
830
- if (!name) return null;
831
- index += name.length;
832
- while (index < text.length && /\s/u.test(text[index])) index += 1;
833
- if (text[index] !== "=") return null;
834
- index += 1;
835
- while (index < text.length && /\s/u.test(text[index])) index += 1;
836
- const quote = text[index];
837
- if (quote !== "\"" && quote !== "'") return null;
838
- index += 1;
839
- const end = text.indexOf(quote, index);
840
- if (end < 0 || Object.prototype.hasOwnProperty.call(attributes, name)) return null;
841
- attributes[name] = text.slice(index, end);
842
- index = end + 1;
843
- }
844
- return attributes;
845
- }
846
-
847
- function appendXmlText(stack, value) {
848
- if (value === "") return true;
849
- const current = stack[stack.length - 1];
850
- if (!current) return value.trim() === "";
851
- current.textParts.push(value);
852
- return true;
853
- }
854
-
855
- function consumeXmlSpecialToken(text, tagStart, stack) {
856
- if (text.startsWith("<!--", tagStart)) {
857
- const end = text.indexOf("-->", tagStart + 4);
858
- return end < 0 ? { valid: false } : { valid: true, nextIndex: end + 3 };
859
- }
860
- if (text.startsWith("<![CDATA[", tagStart)) {
861
- const end = text.indexOf("]]>", tagStart + 9);
862
- if (end < 0 || stack.length === 0) return { valid: false };
863
- stack[stack.length - 1].textParts.push(text.slice(tagStart + 9, end));
864
- return { valid: true, nextIndex: end + 3 };
865
- }
866
- if (text.startsWith("<?", tagStart)) {
867
- const end = text.indexOf("?>", tagStart + 2);
868
- return end < 0 ? { valid: false } : { valid: true, nextIndex: end + 2 };
869
- }
870
- if (text.startsWith("<!", tagStart)) return { valid: false };
871
- return null;
872
- }
873
-
874
- function closeXmlNode(raw, state) {
875
- const closing = raw.slice(1).trim().match(/^([A-Za-z_][A-Za-z0-9_.:-]*)\s*$/u)?.[1];
876
- const open = state.stack.pop();
877
- if (!closing || !open || open.name !== closing) return false;
878
- open.text = open.textParts.join("");
879
- if (state.stack.length === 0) {
880
- if (state.rootClosed || open !== state.root) return false;
881
- state.rootClosed = true;
882
- }
883
- return true;
884
- }
885
-
886
- function openXmlNode(raw, state) {
887
- const selfClosing = /\/\s*$/u.test(raw);
888
- const body = selfClosing ? raw.replace(/\/\s*$/u, "").trimEnd() : raw;
889
- const name = body.match(/^([A-Za-z_][A-Za-z0-9_.:-]*)/u)?.[1];
890
- if (!name) return false;
891
- if (state.stack.length === 0 && (state.root || state.rootClosed)) return false;
892
- if (!state.root && state.expectedRoot && name !== state.expectedRoot) return false;
893
- const attributes = parseXmlAttributes(body.slice(name.length).trim());
894
- if (!attributes) return false;
895
- const node = { name, attributes, textParts: [], children: [], text: "" };
896
- state.nodes.push(node);
897
- if (state.stack.length > 0) state.stack[state.stack.length - 1].children.push(node);
898
- if (!state.root) state.root = node;
899
- if (!selfClosing) state.stack.push(node);
900
- else if (node === state.root) state.rootClosed = true;
901
- return true;
902
- }
903
-
904
- function consumeXmlTag(text, tagStart, state) {
905
- const tagEnd = findXmlTagEnd(text, tagStart + 1);
906
- if (tagEnd < 0) return null;
907
- const raw = text.slice(tagStart + 1, tagEnd).trim();
908
- if (raw === "") return null;
909
- const valid = raw.startsWith("/") ? closeXmlNode(raw, state) : openXmlNode(raw, state);
910
- return { valid, nextIndex: tagEnd + 1 };
911
- }
912
-
913
- function parseXmlStructure(text, expectedRoot = null) {
914
- if (typeof text !== "string" || text.length > MAX_MANIFEST_BYTES || /\r(?!\n)/u.test(text)) return null;
915
- const state = { nodes: [], stack: [], root: null, rootClosed: false, expectedRoot };
916
- let index = 0;
917
- while (index < text.length) {
918
- const tagStart = text.indexOf("<", index);
919
- if (tagStart < 0) break;
920
- if (!appendXmlText(state.stack, text.slice(index, tagStart))) return null;
921
- const special = consumeXmlSpecialToken(text, tagStart, state.stack);
922
- if (special) {
923
- if (!special.valid) return null;
924
- index = special.nextIndex;
925
- continue;
926
- }
927
- const tag = consumeXmlTag(text, tagStart, state);
928
- if (!tag?.valid) return null;
929
- index = tag.nextIndex;
930
- }
931
- if (!appendXmlText(state.stack, text.slice(index))) return null;
932
- if (!state.root || state.stack.length > 0 || !state.rootClosed) return null;
933
- return { root: state.root, nodes: state.nodes };
934
- }
935
-
936
- function normalizeSdkName(value) {
937
- return typeof value === "string" ? value.trim().split("/")[0] : "";
938
- }
939
-
940
- function xmlValues(nodes, name, attribute = "Include") {
941
- return uniqueSorted(nodes
942
- .filter((node) => node.name === name && typeof node.attributes?.[attribute] === "string")
943
- .map((node) => node.attributes[attribute].trim())
944
- .filter(Boolean));
945
- }
946
-
947
- function targetFrameworkValues(nodes) {
948
- return uniqueSorted(nodes
949
- .filter((node) => (node.name === "TargetFramework" || node.name === "TargetFrameworks")
950
- && node.children.length === 0
951
- && node.text.length <= MAX_XML_TEXT_LENGTH)
952
- .flatMap((node) => node.text.split(";"))
953
- .map((value) => value.trim())
954
- .filter(Boolean));
955
- }
956
-
957
- export function parseDotNetProject(text) {
958
- const invalid = invalidDotNetProject();
959
- if (typeof text !== "string" || text.length > MAX_MANIFEST_BYTES) return invalid;
960
- const document = parseXmlStructure(text, "Project");
961
- if (!document) return invalid;
962
-
963
- const sdkValues = [
964
- document.root.attributes.Sdk ?? "",
965
- ...document.nodes.filter((node) => node.name === "Sdk").map((node) => node.attributes.Name ?? ""),
966
- ];
967
- const projectSdks = uniqueSorted(sdkValues
968
- .flatMap((value) => value.split(";"))
969
- .map(normalizeSdkName)
970
- .filter(Boolean));
971
- const recognizedSdks = projectSdks.filter((sdk) => DOTNET_SDKS.has(sdk));
972
- const frameworkReferences = xmlValues(document.nodes, "FrameworkReference");
973
- const packageReferences = xmlValues(document.nodes, "PackageReference");
974
- const projectReferences = xmlValues(document.nodes, "ProjectReference");
975
- const dotnet = recognizedSdks.length > 0;
976
- const aspnetcore = dotnet && (recognizedSdks.some((sdk) => ASPNETCORE_SDKS.has(sdk))
977
- || frameworkReferences.some((reference) => reference.toLowerCase() === "microsoft.aspnetcore.app"));
978
- const abp = dotnet && packageReferences.some((reference) => reference.toLowerCase().startsWith("volo.abp."));
979
- return {
980
- valid: true,
981
- sdkStyle: dotnet,
982
- projectSdks,
983
- targetFrameworks: targetFrameworkValues(document.nodes),
984
- frameworkReferences,
985
- packageReferences,
986
- projectReferences,
987
- dotnet,
988
- aspnetcore,
989
- abp,
990
- };
991
- }
992
-
993
472
  function createTraversalBudget(limits = {}) {
994
473
  const positiveLimit = (value, fallback) => Number.isInteger(value) && value > 0 ? value : fallback;
995
474
  return {
@@ -13,6 +13,7 @@ import { classifyLoadedWorkState, readWorkState, mutateWorkState } from "./work-
13
13
  import { classifyRequirement } from "./evidence-readiness.js";
14
14
  import { assertDiagnosingToCorrectingTransition } from "./phase.js";
15
15
  import { resolveCurrentCycleDiagnostic } from "./diagnostic-projection.js";
16
+ import { hasCurrentReview } from "./review-correction.js";
16
17
 
17
18
  export const RECONCILE_EVENT = "CHECKPOINT_RECONCILED";
18
19
 
@@ -214,6 +215,10 @@ async function rebindReconciliationState(target, {
214
215
  // reconcile itself records the cycle diagnosis below (provenance bound to
215
216
  // the passed evidence execution).
216
217
  const cycleDiagnosis = resolveCurrentCycleDiagnostic(ledger.events, state.taskId, state.verificationCycle ?? 1);
218
+ // Refresh only the repository binding for a task that entered correction
219
+ // from review before recording its new finding. No diagnosis is invented;
220
+ // advance to VERIFYING still requires one from this cycle.
221
+ if (state.phase === "CORRECTING" && !cycleDiagnosis && hasCurrentReview(state, ledger.events)) return state;
217
222
  if (state.phase === "DIAGNOSING" && !cycleDiagnosis) {
218
223
  return { ...state, undiagnosedDiagnosingRebind: true };
219
224
  }
@@ -0,0 +1,51 @@
1
+ export function isReviewCorrection(state) {
2
+ return state.phase === "REVIEWING"
3
+ || (state.phase === "CORRECTING" && state.previousPhase === "REVIEWING");
4
+ }
5
+
6
+ export function hasCurrentReview(state, events) {
7
+ return isReviewCorrection(state) && events.some((event) => event.taskId === state.taskId
8
+ && event.event === "REVIEW_STARTED"
9
+ && event.details?.verificationCycle === state.verificationCycle);
10
+ }
11
+
12
+ export function reviewFailures(state) {
13
+ return (state.checks ?? []).filter((check) => check.details?.verificationCycle === state.verificationCycle
14
+ && ((check.status === "failed" && check.evidenceKind === "OBSERVED")
15
+ || (check.status === "blocked" && check.evidenceKind === "BLOCKED")));
16
+ }
17
+
18
+ function prerequisite(code, message, artifacts = []) {
19
+ return Object.assign(new Error(message), { code, artifacts });
20
+ }
21
+
22
+ export function assertCheckPhase(state, status, evidenceKind, stateRel) {
23
+ const reviewFinding = isReviewCorrection(state) && ((status === "failed" && evidenceKind === "OBSERVED")
24
+ || (status === "blocked" && evidenceKind === "BLOCKED"));
25
+ if (state.phase !== "VERIFYING" && !reviewFinding) {
26
+ throw prerequisite("E_PHASE_PREREQUISITE_MISSING", `record-check requires VERIFYING or a negative review finding; found ${state.phase}`, [stateRel]);
27
+ }
28
+ return reviewFinding;
29
+ }
30
+
31
+ export function assertDiagnosisPhase(state) {
32
+ if (state.phase !== "DIAGNOSING" && !isReviewCorrection(state)) {
33
+ throw prerequisite("E_PHASE_PREREQUISITE_MISSING", `Recording a diagnosis requires DIAGNOSING or a review finding, currently ${state.phase}`);
34
+ }
35
+ }
36
+
37
+ export function assertReviewChronology(state, events, artifacts = []) {
38
+ if (isReviewCorrection(state) && !hasCurrentReview(state, events)) {
39
+ throw prerequisite("E_PHASE_CHRONOLOGY_INVALID", "Review findings require REVIEW_STARTED in the current verification cycle", artifacts);
40
+ }
41
+ }
42
+
43
+ export function requiresFailureBinding(state, failureClass) {
44
+ return failureClass === "VERIFICATION_FAILURE" || isReviewCorrection(state);
45
+ }
46
+
47
+ export function assertReviewRequirement(state, requirement, canonicalRequirement) {
48
+ if (isReviewCorrection(state) && !canonicalRequirement) {
49
+ throw prerequisite("E_CHECK_INVALID", `Review finding must reference a required contract or guide check: ${requirement}`);
50
+ }
51
+ }
@@ -6,7 +6,7 @@ export function getStorageCapabilities() {
6
6
  return {
7
7
  version: 1,
8
8
  defaultBackend: "sqlite",
9
- soleSQLiteWriter: false,
9
+ soleSQLiteWriter: true,
10
10
  sqlite: {
11
11
  format: STORAGE_FORMAT,
12
12
  formatVersion: STORAGE_FORMAT_VERSION,