@mytechtoday/augment-extensions 1.4.0 → 1.5.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 (307) hide show
  1. package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
  2. package/augment-extensions/coding-standards/c/LICENSE +22 -0
  3. package/augment-extensions/coding-standards/c/README.md +167 -0
  4. package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
  5. package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
  6. package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
  7. package/augment-extensions/coding-standards/c/config/schema.json +244 -0
  8. package/augment-extensions/coding-standards/c/docs/API.md +613 -0
  9. package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
  10. package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
  11. package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
  12. package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
  13. package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
  14. package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
  15. package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
  16. package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
  17. package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
  18. package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
  19. package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
  20. package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
  21. package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
  22. package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
  23. package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
  24. package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
  25. package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
  26. package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
  27. package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
  28. package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
  29. package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
  30. package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
  31. package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
  32. package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
  33. package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
  34. package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
  35. package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
  36. package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
  37. package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
  38. package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
  39. package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
  40. package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
  41. package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
  42. package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
  43. package/augment-extensions/coding-standards/c/module.json +149 -0
  44. package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
  45. package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
  46. package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
  47. package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
  48. package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
  49. package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
  50. package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
  51. package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
  52. package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
  53. package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
  54. package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
  55. package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
  56. package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
  57. package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
  58. package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
  59. package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
  60. package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
  61. package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
  62. package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
  63. package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
  64. package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
  65. package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
  66. package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
  67. package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
  68. package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
  69. package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
  70. package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
  71. package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
  72. package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
  73. package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
  74. package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
  75. package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
  76. package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
  77. package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
  78. package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
  79. package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
  80. package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
  81. package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
  82. package/augment-extensions/coding-standards/go/README.md +200 -0
  83. package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
  84. package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
  85. package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
  86. package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
  87. package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
  88. package/augment-extensions/coding-standards/go/config/schema.json +110 -0
  89. package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
  90. package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
  91. package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
  92. package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
  93. package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
  94. package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
  95. package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
  96. package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
  97. package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
  98. package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
  99. package/augment-extensions/coding-standards/go/module.json +139 -0
  100. package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
  101. package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
  102. package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
  103. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
  104. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
  105. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
  106. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
  107. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
  108. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
  109. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
  110. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
  111. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
  112. package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
  113. package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
  114. package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
  115. package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
  116. package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
  117. package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
  118. package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
  119. package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
  120. package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
  121. package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
  122. package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
  123. package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
  124. package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
  125. package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
  126. package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
  127. package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
  128. package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
  129. package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
  130. package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
  131. package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
  132. package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
  133. package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
  134. package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
  135. package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
  136. package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
  137. package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
  138. package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
  139. package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
  140. package/cli/dist/analysis/ast-parser.d.ts +47 -0
  141. package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
  142. package/cli/dist/analysis/ast-parser.js +161 -0
  143. package/cli/dist/analysis/ast-parser.js.map +1 -0
  144. package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
  145. package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
  146. package/cli/dist/analysis/complexity-analyzer.js +189 -0
  147. package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
  148. package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
  149. package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
  150. package/cli/dist/analysis/dependency-analyzer.js +237 -0
  151. package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
  152. package/cli/dist/analysis/index.d.ts +9 -0
  153. package/cli/dist/analysis/index.d.ts.map +1 -0
  154. package/cli/dist/analysis/index.js +25 -0
  155. package/cli/dist/analysis/index.js.map +1 -0
  156. package/cli/dist/analysis/security-scanner.d.ts +11 -0
  157. package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
  158. package/cli/dist/analysis/security-scanner.js +294 -0
  159. package/cli/dist/analysis/security-scanner.js.map +1 -0
  160. package/cli/dist/analysis/types.d.ts +151 -0
  161. package/cli/dist/analysis/types.d.ts.map +1 -0
  162. package/cli/dist/analysis/types.js +6 -0
  163. package/cli/dist/analysis/types.js.map +1 -0
  164. package/cli/dist/cli.js +24 -0
  165. package/cli/dist/cli.js.map +1 -1
  166. package/cli/dist/commands/code-analysis.d.ts +11 -0
  167. package/cli/dist/commands/code-analysis.d.ts.map +1 -0
  168. package/cli/dist/commands/code-analysis.js +412 -0
  169. package/cli/dist/commands/code-analysis.js.map +1 -0
  170. package/modules.md +99 -3
  171. package/package.json +14 -2
  172. package/cli/dist/commands/agent.d.ts +0 -37
  173. package/cli/dist/commands/agent.d.ts.map +0 -1
  174. package/cli/dist/commands/agent.js +0 -222
  175. package/cli/dist/commands/agent.js.map +0 -1
  176. package/cli/dist/commands/beads.d.ts +0 -64
  177. package/cli/dist/commands/beads.d.ts.map +0 -1
  178. package/cli/dist/commands/beads.js +0 -377
  179. package/cli/dist/commands/beads.js.map +0 -1
  180. package/cli/dist/commands/change.d.ts +0 -54
  181. package/cli/dist/commands/change.d.ts.map +0 -1
  182. package/cli/dist/commands/change.js +0 -243
  183. package/cli/dist/commands/change.js.map +0 -1
  184. package/cli/dist/commands/clean.d.ts +0 -15
  185. package/cli/dist/commands/clean.d.ts.map +0 -1
  186. package/cli/dist/commands/clean.js +0 -63
  187. package/cli/dist/commands/clean.js.map +0 -1
  188. package/cli/dist/commands/clone.d.ts +0 -15
  189. package/cli/dist/commands/clone.d.ts.map +0 -1
  190. package/cli/dist/commands/clone.js +0 -49
  191. package/cli/dist/commands/clone.js.map +0 -1
  192. package/cli/dist/commands/config.d.ts +0 -33
  193. package/cli/dist/commands/config.d.ts.map +0 -1
  194. package/cli/dist/commands/config.js +0 -166
  195. package/cli/dist/commands/config.js.map +0 -1
  196. package/cli/dist/commands/context.d.ts +0 -38
  197. package/cli/dist/commands/context.d.ts.map +0 -1
  198. package/cli/dist/commands/context.js +0 -205
  199. package/cli/dist/commands/context.js.map +0 -1
  200. package/cli/dist/commands/create.d.ts +0 -18
  201. package/cli/dist/commands/create.d.ts.map +0 -1
  202. package/cli/dist/commands/create.js +0 -178
  203. package/cli/dist/commands/create.js.map +0 -1
  204. package/cli/dist/commands/diff.d.ts +0 -19
  205. package/cli/dist/commands/diff.d.ts.map +0 -1
  206. package/cli/dist/commands/diff.js +0 -104
  207. package/cli/dist/commands/diff.js.map +0 -1
  208. package/cli/dist/commands/doctor.d.ts +0 -14
  209. package/cli/dist/commands/doctor.d.ts.map +0 -1
  210. package/cli/dist/commands/doctor.js +0 -62
  211. package/cli/dist/commands/doctor.js.map +0 -1
  212. package/cli/dist/commands/export.d.ts +0 -28
  213. package/cli/dist/commands/export.d.ts.map +0 -1
  214. package/cli/dist/commands/export.js +0 -135
  215. package/cli/dist/commands/export.js.map +0 -1
  216. package/cli/dist/commands/import.d.ts +0 -23
  217. package/cli/dist/commands/import.d.ts.map +0 -1
  218. package/cli/dist/commands/import.js +0 -118
  219. package/cli/dist/commands/import.js.map +0 -1
  220. package/cli/dist/commands/prompt.d.ts +0 -45
  221. package/cli/dist/commands/prompt.d.ts.map +0 -1
  222. package/cli/dist/commands/prompt.js +0 -223
  223. package/cli/dist/commands/prompt.js.map +0 -1
  224. package/cli/dist/commands/spec.d.ts +0 -57
  225. package/cli/dist/commands/spec.d.ts.map +0 -1
  226. package/cli/dist/commands/spec.js +0 -279
  227. package/cli/dist/commands/spec.js.map +0 -1
  228. package/cli/dist/commands/stats.d.ts +0 -18
  229. package/cli/dist/commands/stats.d.ts.map +0 -1
  230. package/cli/dist/commands/stats.js +0 -85
  231. package/cli/dist/commands/stats.js.map +0 -1
  232. package/cli/dist/commands/task.d.ts +0 -65
  233. package/cli/dist/commands/task.d.ts.map +0 -1
  234. package/cli/dist/commands/task.js +0 -282
  235. package/cli/dist/commands/task.js.map +0 -1
  236. package/cli/dist/commands/template.d.ts +0 -17
  237. package/cli/dist/commands/template.d.ts.map +0 -1
  238. package/cli/dist/commands/template.js +0 -55
  239. package/cli/dist/commands/template.js.map +0 -1
  240. package/cli/dist/utils/agent-config.d.ts +0 -129
  241. package/cli/dist/utils/agent-config.d.ts.map +0 -1
  242. package/cli/dist/utils/agent-config.js +0 -297
  243. package/cli/dist/utils/agent-config.js.map +0 -1
  244. package/cli/dist/utils/beads-graph.d.ts +0 -17
  245. package/cli/dist/utils/beads-graph.d.ts.map +0 -1
  246. package/cli/dist/utils/beads-graph.js +0 -150
  247. package/cli/dist/utils/beads-graph.js.map +0 -1
  248. package/cli/dist/utils/beads-integration.d.ts +0 -112
  249. package/cli/dist/utils/beads-integration.d.ts.map +0 -1
  250. package/cli/dist/utils/beads-integration.js +0 -312
  251. package/cli/dist/utils/beads-integration.js.map +0 -1
  252. package/cli/dist/utils/beads-reporter.d.ts +0 -17
  253. package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
  254. package/cli/dist/utils/beads-reporter.js +0 -160
  255. package/cli/dist/utils/beads-reporter.js.map +0 -1
  256. package/cli/dist/utils/cache-manager.d.ts +0 -55
  257. package/cli/dist/utils/cache-manager.d.ts.map +0 -1
  258. package/cli/dist/utils/cache-manager.js +0 -150
  259. package/cli/dist/utils/cache-manager.js.map +0 -1
  260. package/cli/dist/utils/change-manager.d.ts +0 -70
  261. package/cli/dist/utils/change-manager.d.ts.map +0 -1
  262. package/cli/dist/utils/change-manager.js +0 -412
  263. package/cli/dist/utils/change-manager.js.map +0 -1
  264. package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
  265. package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
  266. package/cli/dist/utils/config-manager-enhanced.js +0 -77
  267. package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
  268. package/cli/dist/utils/context-manager.d.ts +0 -96
  269. package/cli/dist/utils/context-manager.d.ts.map +0 -1
  270. package/cli/dist/utils/context-manager.js +0 -258
  271. package/cli/dist/utils/context-manager.js.map +0 -1
  272. package/cli/dist/utils/diff-engine.d.ts +0 -78
  273. package/cli/dist/utils/diff-engine.d.ts.map +0 -1
  274. package/cli/dist/utils/diff-engine.js +0 -233
  275. package/cli/dist/utils/diff-engine.js.map +0 -1
  276. package/cli/dist/utils/export-system.d.ts +0 -101
  277. package/cli/dist/utils/export-system.d.ts.map +0 -1
  278. package/cli/dist/utils/export-system.js +0 -289
  279. package/cli/dist/utils/export-system.js.map +0 -1
  280. package/cli/dist/utils/health-checker.d.ts +0 -66
  281. package/cli/dist/utils/health-checker.d.ts.map +0 -1
  282. package/cli/dist/utils/health-checker.js +0 -285
  283. package/cli/dist/utils/health-checker.js.map +0 -1
  284. package/cli/dist/utils/import-system.d.ts +0 -74
  285. package/cli/dist/utils/import-system.d.ts.map +0 -1
  286. package/cli/dist/utils/import-system.js +0 -317
  287. package/cli/dist/utils/import-system.js.map +0 -1
  288. package/cli/dist/utils/module-cloner.d.ts +0 -40
  289. package/cli/dist/utils/module-cloner.d.ts.map +0 -1
  290. package/cli/dist/utils/module-cloner.js +0 -136
  291. package/cli/dist/utils/module-cloner.js.map +0 -1
  292. package/cli/dist/utils/prompt-manager.d.ts +0 -90
  293. package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
  294. package/cli/dist/utils/prompt-manager.js +0 -302
  295. package/cli/dist/utils/prompt-manager.js.map +0 -1
  296. package/cli/dist/utils/spec-manager.d.ts +0 -65
  297. package/cli/dist/utils/spec-manager.d.ts.map +0 -1
  298. package/cli/dist/utils/spec-manager.js +0 -329
  299. package/cli/dist/utils/spec-manager.js.map +0 -1
  300. package/cli/dist/utils/stats-collector.d.ts +0 -74
  301. package/cli/dist/utils/stats-collector.d.ts.map +0 -1
  302. package/cli/dist/utils/stats-collector.js +0 -164
  303. package/cli/dist/utils/stats-collector.js.map +0 -1
  304. package/cli/dist/utils/template-engine.d.ts +0 -47
  305. package/cli/dist/utils/template-engine.d.ts.map +0 -1
  306. package/cli/dist/utils/template-engine.js +0 -204
  307. package/cli/dist/utils/template-engine.js.map +0 -1
@@ -0,0 +1,586 @@
1
+ # Rule: Systems Programming
2
+
3
+ ## Metadata
4
+ - **ID**: category-systems
5
+ - **Category**: systems
6
+ - **Severity**: ERROR
7
+ - **Standard**: POSIX.1-2017, SUSv4
8
+ - **Version**: 1.0.0
9
+
10
+ ## Description
11
+ Systems programming rules for POSIX-compliant code including system calls, IPC, signal handling, and process management.
12
+
13
+ ## Rationale
14
+ Systems programming requires strict adherence to POSIX standards, proper error handling of system calls, and careful management of system resources. Failure to follow these practices leads to resource leaks, race conditions, and undefined behavior.
15
+
16
+ ## Applies To
17
+ - C Standards: c99, c11, c17, c23
18
+ - Categories: systems
19
+ - Platforms: POSIX-compliant systems (Linux, Unix, macOS, BSD)
20
+
21
+ ## Rule Details
22
+
23
+ ### 1. POSIX Compliance
24
+ - Use POSIX-defined feature test macros
25
+ - Follow POSIX API specifications
26
+ - Handle platform-specific differences
27
+ - Use standard POSIX types (pid_t, size_t, ssize_t)
28
+
29
+ ### 2. System Call Error Checking
30
+ - **ALWAYS** check return values of system calls
31
+ - Use errno for error diagnosis
32
+ - Provide meaningful error messages with perror() or strerror()
33
+ - Handle EINTR (interrupted system calls) appropriately
34
+
35
+ ### 3. Signal Handling
36
+ - Use sigaction() instead of signal()
37
+ - Make signal handlers async-signal-safe
38
+ - Use volatile sig_atomic_t for shared variables
39
+ - Block signals during critical sections
40
+
41
+ ### 4. Inter-Process Communication (IPC)
42
+ - Choose appropriate IPC mechanism (pipes, FIFOs, message queues, shared memory, sockets)
43
+ - Properly synchronize access to shared resources
44
+ - Clean up IPC resources on exit
45
+ - Handle partial reads/writes
46
+
47
+ ### 5. Process Management
48
+ - Check fork() return value for all three cases (parent, child, error)
49
+ - Use exec() family correctly
50
+ - Reap child processes to avoid zombies
51
+ - Handle process termination signals
52
+
53
+ ## Examples
54
+
55
+ ### ✅ Example 1: Proper System Call Error Checking
56
+
57
+ ```c
58
+ #include <unistd.h>
59
+ #include <errno.h>
60
+ #include <string.h>
61
+ #include <stdio.h>
62
+
63
+ ssize_t safe_write(int fd, const void *buf, size_t count) {
64
+ ssize_t written = 0;
65
+ ssize_t result;
66
+
67
+ while (written < count) {
68
+ result = write(fd, (char*)buf + written, count - written);
69
+
70
+ if (result < 0) {
71
+ if (errno == EINTR) {
72
+ continue; // Interrupted, retry
73
+ }
74
+ perror("write");
75
+ return -1;
76
+ }
77
+
78
+ written += result;
79
+ }
80
+
81
+ return written;
82
+ }
83
+ ```
84
+
85
+ ### ❌ Example 1: Missing Error Checking
86
+
87
+ ```c
88
+ // WRONG: No error checking
89
+ void unsafe_write(int fd, const void *buf, size_t count) {
90
+ write(fd, buf, count); // Ignores return value and errors
91
+ }
92
+ ```
93
+
94
+ ### ✅ Example 2: Proper Signal Handling with sigaction()
95
+
96
+ ```c
97
+ #include <signal.h>
98
+ #include <stdio.h>
99
+
100
+ volatile sig_atomic_t got_signal = 0;
101
+
102
+ void signal_handler(int signo) {
103
+ // Async-signal-safe: only set flag
104
+ got_signal = signo;
105
+ }
106
+
107
+ int setup_signal_handler(void) {
108
+ struct sigaction sa;
109
+
110
+ sa.sa_handler = signal_handler;
111
+ sigemptyset(&sa.sa_mask);
112
+ sa.sa_flags = SA_RESTART; // Restart interrupted system calls
113
+
114
+ if (sigaction(SIGINT, &sa, NULL) < 0) {
115
+ perror("sigaction");
116
+ return -1;
117
+ }
118
+
119
+ return 0;
120
+ }
121
+ ```
122
+
123
+ ### ❌ Example 2: Unsafe Signal Handling
124
+
125
+ ```c
126
+ // WRONG: Using deprecated signal(), non-async-signal-safe operations
127
+ void bad_handler(int signo) {
128
+ printf("Got signal %d\n", signo); // printf is NOT async-signal-safe!
129
+ signal(SIGINT, bad_handler); // Deprecated, race conditions
130
+ }
131
+ ```
132
+
133
+ ### ✅ Example 3: Proper fork() Usage
134
+
135
+ ```c
136
+ #include <sys/types.h>
137
+ #include <sys/wait.h>
138
+ #include <unistd.h>
139
+ #include <stdio.h>
140
+ #include <stdlib.h>
141
+
142
+ int spawn_child_process(void) {
143
+ pid_t pid = fork();
144
+
145
+ if (pid < 0) {
146
+ // Fork failed
147
+ perror("fork");
148
+ return -1;
149
+ } else if (pid == 0) {
150
+ // Child process
151
+ execl("/bin/ls", "ls", "-l", NULL);
152
+ perror("execl"); // Only reached if exec fails
153
+ exit(EXIT_FAILURE);
154
+ } else {
155
+ // Parent process
156
+ int status;
157
+ if (waitpid(pid, &status, 0) < 0) {
158
+ perror("waitpid");
159
+ return -1;
160
+ }
161
+
162
+ if (WIFEXITED(status)) {
163
+ printf("Child exited with status %d\n", WEXITSTATUS(status));
164
+ }
165
+ }
166
+
167
+ return 0;
168
+ }
169
+ ```
170
+
171
+ ### ❌ Example 3: Improper fork() Usage
172
+
173
+ ```c
174
+ // WRONG: Not checking all cases, creating zombie processes
175
+ void bad_fork(void) {
176
+ if (fork() == 0) {
177
+ execl("/bin/ls", "ls", NULL);
178
+ }
179
+ // Missing: error check, parent doesn't wait (zombie!)
180
+ }
181
+ ```
182
+
183
+ ### ✅ Example 4: Pipe Communication
184
+
185
+ ```c
186
+ #include <unistd.h>
187
+ #include <string.h>
188
+ #include <stdio.h>
189
+
190
+ int pipe_communication_example(void) {
191
+ int pipefd[2];
192
+ pid_t pid;
193
+ char buf[256];
194
+
195
+ if (pipe(pipefd) < 0) {
196
+ perror("pipe");
197
+ return -1;
198
+ }
199
+
200
+ pid = fork();
201
+ if (pid < 0) {
202
+ perror("fork");
203
+ close(pipefd[0]);
204
+ close(pipefd[1]);
205
+ return -1;
206
+ }
207
+
208
+ if (pid == 0) {
209
+ // Child: write to pipe
210
+ close(pipefd[0]); // Close read end
211
+ const char *msg = "Hello from child";
212
+ write(pipefd[1], msg, strlen(msg) + 1);
213
+ close(pipefd[1]);
214
+ exit(0);
215
+ } else {
216
+ // Parent: read from pipe
217
+ close(pipefd[1]); // Close write end
218
+ ssize_t n = read(pipefd[0], buf, sizeof(buf));
219
+ if (n > 0) {
220
+ printf("Parent received: %s\n", buf);
221
+ }
222
+ close(pipefd[0]);
223
+ wait(NULL);
224
+ }
225
+
226
+ return 0;
227
+ }
228
+ ```
229
+
230
+ ### ✅ Example 5: File Descriptor Management
231
+
232
+ ```c
233
+ #include <fcntl.h>
234
+ #include <unistd.h>
235
+ #include <stdio.h>
236
+
237
+ int safe_file_operations(const char *filename) {
238
+ int fd = open(filename, O_RDONLY);
239
+ if (fd < 0) {
240
+ perror("open");
241
+ return -1;
242
+ }
243
+
244
+ // Set close-on-exec flag to prevent fd leaks
245
+ int flags = fcntl(fd, F_GETFD);
246
+ if (flags < 0) {
247
+ perror("fcntl F_GETFD");
248
+ close(fd);
249
+ return -1;
250
+ }
251
+
252
+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
253
+ perror("fcntl F_SETFD");
254
+ close(fd);
255
+ return -1;
256
+ }
257
+
258
+ // Use the file descriptor...
259
+
260
+ close(fd);
261
+ return 0;
262
+ }
263
+ ```
264
+
265
+ ### ✅ Example 6: POSIX Feature Test Macros
266
+
267
+ ```c
268
+ // At the top of the file, before any includes
269
+ #define _POSIX_C_SOURCE 200809L // POSIX.1-2008
270
+
271
+ #include <unistd.h>
272
+ #include <time.h>
273
+
274
+ // Now we can use POSIX.1-2008 features
275
+ int use_posix_features(void) {
276
+ struct timespec ts;
277
+
278
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
279
+ return -1;
280
+ }
281
+
282
+ return 0;
283
+ }
284
+ ```
285
+
286
+ ### ✅ Example 7: Shared Memory IPC
287
+
288
+ ```c
289
+ #include <sys/mman.h>
290
+ #include <sys/stat.h>
291
+ #include <fcntl.h>
292
+ #include <unistd.h>
293
+ #include <string.h>
294
+ #include <stdio.h>
295
+
296
+ #define SHM_NAME "/my_shm"
297
+ #define SHM_SIZE 4096
298
+
299
+ int create_shared_memory(void) {
300
+ int fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666);
301
+ if (fd < 0) {
302
+ perror("shm_open");
303
+ return -1;
304
+ }
305
+
306
+ if (ftruncate(fd, SHM_SIZE) < 0) {
307
+ perror("ftruncate");
308
+ close(fd);
309
+ shm_unlink(SHM_NAME);
310
+ return -1;
311
+ }
312
+
313
+ void *ptr = mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE,
314
+ MAP_SHARED, fd, 0);
315
+ if (ptr == MAP_FAILED) {
316
+ perror("mmap");
317
+ close(fd);
318
+ shm_unlink(SHM_NAME);
319
+ return -1;
320
+ }
321
+
322
+ // Use shared memory...
323
+ strcpy(ptr, "Hello, shared memory!");
324
+
325
+ // Cleanup
326
+ munmap(ptr, SHM_SIZE);
327
+ close(fd);
328
+ shm_unlink(SHM_NAME);
329
+
330
+ return 0;
331
+ }
332
+ ```
333
+
334
+ ### ✅ Example 8: Signal Blocking During Critical Section
335
+
336
+ ```c
337
+ #include <signal.h>
338
+ #include <stdio.h>
339
+
340
+ int critical_section_with_signal_blocking(void) {
341
+ sigset_t new_mask, old_mask;
342
+
343
+ // Block SIGINT and SIGTERM during critical section
344
+ sigemptyset(&new_mask);
345
+ sigaddset(&new_mask, SIGINT);
346
+ sigaddset(&new_mask, SIGTERM);
347
+
348
+ if (sigprocmask(SIG_BLOCK, &new_mask, &old_mask) < 0) {
349
+ perror("sigprocmask");
350
+ return -1;
351
+ }
352
+
353
+ // Critical section - signals are blocked
354
+ // ... perform critical operations ...
355
+
356
+ // Restore original signal mask
357
+ if (sigprocmask(SIG_SETMASK, &old_mask, NULL) < 0) {
358
+ perror("sigprocmask");
359
+ return -1;
360
+ }
361
+
362
+ return 0;
363
+ }
364
+ ```
365
+
366
+ ### ✅ Example 9: Proper errno Usage
367
+
368
+ ```c
369
+ #include <errno.h>
370
+ #include <string.h>
371
+ #include <stdio.h>
372
+ #include <fcntl.h>
373
+
374
+ int open_file_with_error_handling(const char *path) {
375
+ int fd;
376
+
377
+ errno = 0; // Clear errno before system call
378
+ fd = open(path, O_RDONLY);
379
+
380
+ if (fd < 0) {
381
+ int saved_errno = errno; // Save errno immediately
382
+
383
+ fprintf(stderr, "Failed to open '%s': %s (errno=%d)\n",
384
+ path, strerror(saved_errno), saved_errno);
385
+
386
+ // Handle specific errors
387
+ switch (saved_errno) {
388
+ case ENOENT:
389
+ fprintf(stderr, "File does not exist\n");
390
+ break;
391
+ case EACCES:
392
+ fprintf(stderr, "Permission denied\n");
393
+ break;
394
+ case EMFILE:
395
+ fprintf(stderr, "Too many open files\n");
396
+ break;
397
+ default:
398
+ fprintf(stderr, "Unknown error\n");
399
+ }
400
+
401
+ return -1;
402
+ }
403
+
404
+ return fd;
405
+ }
406
+ ```
407
+
408
+ ### ✅ Example 10: POSIX Message Queues
409
+
410
+ ```c
411
+ #include <mqueue.h>
412
+ #include <fcntl.h>
413
+ #include <sys/stat.h>
414
+ #include <stdio.h>
415
+ #include <string.h>
416
+
417
+ #define QUEUE_NAME "/my_queue"
418
+ #define MAX_MSG_SIZE 256
419
+
420
+ int message_queue_example(void) {
421
+ mqd_t mq;
422
+ struct mq_attr attr;
423
+ char buffer[MAX_MSG_SIZE];
424
+
425
+ // Set queue attributes
426
+ attr.mq_flags = 0;
427
+ attr.mq_maxmsg = 10;
428
+ attr.mq_msgsize = MAX_MSG_SIZE;
429
+ attr.mq_curmsgs = 0;
430
+
431
+ // Create message queue
432
+ mq = mq_open(QUEUE_NAME, O_CREAT | O_RDWR, 0666, &attr);
433
+ if (mq == (mqd_t)-1) {
434
+ perror("mq_open");
435
+ return -1;
436
+ }
437
+
438
+ // Send message
439
+ const char *msg = "Test message";
440
+ if (mq_send(mq, msg, strlen(msg) + 1, 0) < 0) {
441
+ perror("mq_send");
442
+ mq_close(mq);
443
+ mq_unlink(QUEUE_NAME);
444
+ return -1;
445
+ }
446
+
447
+ // Receive message
448
+ ssize_t bytes_read = mq_receive(mq, buffer, MAX_MSG_SIZE, NULL);
449
+ if (bytes_read < 0) {
450
+ perror("mq_receive");
451
+ mq_close(mq);
452
+ mq_unlink(QUEUE_NAME);
453
+ return -1;
454
+ }
455
+
456
+ printf("Received: %s\n", buffer);
457
+
458
+ // Cleanup
459
+ mq_close(mq);
460
+ mq_unlink(QUEUE_NAME);
461
+
462
+ return 0;
463
+ }
464
+ ```
465
+
466
+ ### ✅ Example 11: Process Resource Limits
467
+
468
+ ```c
469
+ #include <sys/resource.h>
470
+ #include <stdio.h>
471
+
472
+ int set_resource_limits(void) {
473
+ struct rlimit limit;
474
+
475
+ // Get current file descriptor limit
476
+ if (getrlimit(RLIMIT_NOFILE, &limit) < 0) {
477
+ perror("getrlimit");
478
+ return -1;
479
+ }
480
+
481
+ printf("Current limits: soft=%lu, hard=%lu\n",
482
+ limit.rlim_cur, limit.rlim_max);
483
+
484
+ // Increase soft limit (cannot exceed hard limit)
485
+ limit.rlim_cur = limit.rlim_max;
486
+
487
+ if (setrlimit(RLIMIT_NOFILE, &limit) < 0) {
488
+ perror("setrlimit");
489
+ return -1;
490
+ }
491
+
492
+ return 0;
493
+ }
494
+ ```
495
+
496
+ ### ✅ Example 12: Daemon Process Creation
497
+
498
+ ```c
499
+ #include <unistd.h>
500
+ #include <sys/stat.h>
501
+ #include <fcntl.h>
502
+ #include <stdio.h>
503
+ #include <stdlib.h>
504
+
505
+ int daemonize(void) {
506
+ pid_t pid;
507
+
508
+ // Fork and exit parent
509
+ pid = fork();
510
+ if (pid < 0) {
511
+ return -1;
512
+ }
513
+ if (pid > 0) {
514
+ exit(EXIT_SUCCESS); // Parent exits
515
+ }
516
+
517
+ // Create new session
518
+ if (setsid() < 0) {
519
+ return -1;
520
+ }
521
+
522
+ // Fork again to prevent acquiring controlling terminal
523
+ pid = fork();
524
+ if (pid < 0) {
525
+ return -1;
526
+ }
527
+ if (pid > 0) {
528
+ exit(EXIT_SUCCESS);
529
+ }
530
+
531
+ // Change working directory to root
532
+ if (chdir("/") < 0) {
533
+ return -1;
534
+ }
535
+
536
+ // Close all file descriptors
537
+ for (int fd = sysconf(_SC_OPEN_MAX); fd >= 0; fd--) {
538
+ close(fd);
539
+ }
540
+
541
+ // Redirect stdin, stdout, stderr to /dev/null
542
+ int fd = open("/dev/null", O_RDWR);
543
+ if (fd < 0) {
544
+ return -1;
545
+ }
546
+ dup2(fd, STDIN_FILENO);
547
+ dup2(fd, STDOUT_FILENO);
548
+ dup2(fd, STDERR_FILENO);
549
+ if (fd > STDERR_FILENO) {
550
+ close(fd);
551
+ }
552
+
553
+ return 0;
554
+ }
555
+ ```
556
+
557
+ ## References
558
+
559
+ - POSIX.1-2017 (IEEE Std 1003.1-2017)
560
+ - The Single UNIX Specification, Version 4 (SUSv4)
561
+ - Advanced Programming in the UNIX Environment (Stevens & Rago)
562
+ - The Linux Programming Interface (Michael Kerrisk)
563
+ - POSIX System Calls and Subroutines using C
564
+
565
+ ## Related Rules
566
+
567
+ - universal-error-handling
568
+ - universal-memory-safety
569
+ - universal-documentation
570
+
571
+ ## Configuration
572
+
573
+ Enable in `.augment/c-standards.json`:
574
+
575
+ ```json
576
+ {
577
+ "categories": ["systems"],
578
+ "category_overrides": {
579
+ "systems": {
580
+ "require_posix_compliance": true,
581
+ "check_system_call_errors": true
582
+ }
583
+ }
584
+ }
585
+ ```
586
+