agent-rules-init 0.2.0 → 0.3.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.
@@ -1,7 +1,14 @@
1
+ import { refactorBody, reviewBody, runTestsConvention, summarySentence, testingBody, unknownFrameworkLabel, } from "../core/i18n.js";
1
2
  function detect(signals) {
2
3
  const source = signals.packageSwift;
3
4
  if (!source)
4
5
  return null;
6
+ // A Package.swift alone doesn't guarantee a Swift project: some C/C++ libraries (e.g.
7
+ // nlohmann/json) ship one purely so Swift Package Manager users can link the library,
8
+ // with zero actual Swift source. Require at least one other .swift file to be present.
9
+ const hasSwiftSource = signals.files.some((f) => f.toLowerCase().endsWith(".swift") && !f.endsWith("Package.swift"));
10
+ if (!hasSwiftSource)
11
+ return null;
5
12
  const lower = source.toLowerCase();
6
13
  const framework = lower.includes("vapor")
7
14
  ? { value: "vapor", confidence: "high" }
@@ -14,39 +21,42 @@ function detect(signals) {
14
21
  packageManager: { value: "swift package manager", confidence: "high" },
15
22
  };
16
23
  }
17
- function rules(detection) {
18
- const framework = detection.framework?.value ?? "none";
19
- return {
20
- summary: `Proyecto Swift${framework !== "none" ? ` con ${framework}` : ""} (Swift Package Manager).`,
21
- conventions: [
22
- "Sigue la guía de estilo de la API de Swift (swift.org/documentation/api-design-guidelines).",
23
- "Ejecuta los tests con `swift test` antes de terminar una tarea.",
24
- "Declara toda dependencia nueva en Package.swift, nunca la añadas solo en Xcode.",
25
- ],
26
- architectureNotes: [
24
+ const TEXTS = {
25
+ es: {
26
+ style: "Sigue la guía de estilo de la API de Swift (swift.org/documentation/api-design-guidelines).",
27
+ deps: "Declara toda dependencia nueva en Package.swift, nunca la añadas solo en Xcode.",
28
+ arch: [
27
29
  "Prefiere `struct` sobre `class` salvo que se necesite semántica de referencia.",
28
30
  "Evita forzar el desenvuelto de opcionales (`!`) fuera de contextos donde la invariante esté garantizada.",
29
31
  ],
32
+ reviewFocus: "desenvueltos forzados de opcionales",
33
+ },
34
+ en: {
35
+ style: "Follow the Swift API design guidelines (swift.org/documentation/api-design-guidelines).",
36
+ deps: "Declare every new dependency in Package.swift; never add it only in Xcode.",
37
+ arch: [
38
+ "Prefer `struct` over `class` unless reference semantics are needed.",
39
+ "Avoid force-unwrapping optionals (`!`) outside contexts where the invariant is guaranteed.",
40
+ ],
41
+ reviewFocus: "force-unwrapped optionals",
42
+ },
43
+ };
44
+ function rules(detection, lang) {
45
+ const t = TEXTS[lang];
46
+ const framework = detection.framework?.value !== "none" ? detection.framework?.value : undefined;
47
+ return {
48
+ summary: summarySentence(lang, "Swift", framework, "Swift Package Manager"),
49
+ conventions: [t.style, runTestsConvention(lang, "`swift test`"), t.deps],
50
+ architectureNotes: t.arch,
30
51
  };
31
52
  }
32
- function promptTemplates(detection) {
33
- const framework = detection.framework?.value ?? "el framework del proyecto";
53
+ function promptTemplates(detection, lang) {
54
+ const t = TEXTS[lang];
55
+ const framework = detection.framework?.value !== "none" ? detection.framework.value : unknownFrameworkLabel(lang);
34
56
  return [
35
- {
36
- id: "review",
37
- title: "Code Review (Swift)",
38
- body: `Revisa el diff actual buscando bugs, desenvueltos forzados de opcionales y desviaciones de las convenciones de ${framework}. Señala solo problemas concretos con línea de archivo.`,
39
- },
40
- {
41
- id: "refactor",
42
- title: "Refactor (Swift)",
43
- body: `Propón refactors que reduzcan duplicación y mejoren la legibilidad sin cambiar comportamiento observable.`,
44
- },
45
- {
46
- id: "testing",
47
- title: "Testing (Swift)",
48
- body: `Escribe tests con \`swift test\` para el código señalado. Cubre el camino feliz y al menos un caso límite.`,
49
- },
57
+ { id: "review", title: "Code Review (Swift)", body: reviewBody(lang, t.reviewFocus, framework) },
58
+ { id: "refactor", title: "Refactor (Swift)", body: refactorBody(lang) },
59
+ { id: "testing", title: "Testing (Swift)", body: testingBody(lang, "`swift test`") },
50
60
  ];
51
61
  }
52
62
  export const swiftPack = { id: "swift", detect, rules, promptTemplates };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-rules-init",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Generates CLAUDE.md, AGENTS.md, copilot-instructions.md and prompt files from what your repo actually is.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,7 +39,8 @@
39
39
  "lint": "tsc -p tsconfig.json --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@clack/prompts": "^0.9.1"
42
+ "@clack/prompts": "^0.9.1",
43
+ "yaml": "^2.9.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "typescript": "^5.6.0",