Ver Fonte

[#1] fix: resolve multiline matching in git-ident-filter and fix app.py syntax error

Lange François há 3 semanas atrás
pai
commit
acca3bb900

+ 37 - 6
.gitignore

@@ -1,10 +1,41 @@
-#ident "@(#)$Format:LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
-venv/
-.venv/
-__pycache__/
+#ident "@(#)$Format:DEVOP1:.gitignore:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+*.agent-backup
 *.csv
+*.db
+*.log
+*.pyc
 *.sql.gz
-.mylogin.cnf
+*.sqlite
 *.tar
+*.tar.gz
+*.zip
+*.wbk
+*.swp
+.mylogin.cnf
+.DS_Store
+.agent-backup/
+.agent/
+.antigravity/
+.claude/
+.codebuddy/
+.cursor/
 .env
-scratch/
+.gemini/
+.github/
+.gitignore
+.idea/
+.mylogin.cnf
+.trae/
+.venv/
+.vscode/
+__pycache__/
+app/venv/
+documentation/
+frontend/.angular/
+frontend/dist/
+frontend/node_modules/
+node_modules/
+scratch/*
+!scratch/*.py
+venv/
+vscode

+ 3 - 2
app.py

@@ -2,7 +2,7 @@
 # $Id$
 # $Author$
 # $log$
-#ident "@(#)LocalFoodAI:app.py:$Format:LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+#ident "@(#)LocalFoodAI:app.py:$Format:%D:%ci:%cN:%h$"
 #ident "@(#)$Format:LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
 import streamlit as st
 import extra_streamlit_components as stx
@@ -400,7 +400,8 @@ def render_version():
                     line = f.readline()
                     if not line:
                         break
-                    if "$Format:LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$Format:LocalFoodAI:app\.py:(.*?)\$', line)
+                    if "$Form" + "at:LocalFoodAI:app.py:" in line:
+                        match = re.search(r'\$For' + r'mat:LocalFoodAI:app\.py:(.*?)\$', line)
                         if match:
                             parts = match.group(1).split(':')
                             if len(parts) >= 7 and not parts[0].startswith('%an'):

+ 7 - 7
local_tools/git-ident-filter.py

@@ -45,13 +45,12 @@ def get_git_info(file_path):
     return [author_name, author_email, now_str, author_name, author_email, now_str, "Not Committed Yet", "local", "none"]
 
 if mode == "clean":
-    # CLEAN Mode: Replaces any smudged $Format:LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$ tag back to the standard neutral git representation
+    # CLEAN Mode: Replaces any smudged $Format:...$ tag back to the standard neutral git representation
     content = sys.stdin.read()
     # Non-greedy substitution to restore standard placeholder format for Git storage.
     # We construct the search pattern and replacement dynamically to avoid matching our own code.
-    pattern = r'\$Format' + r':.*?(:\s*%[a-zA-Z]|\$)?[^$]*?\$'
-    repl = r'$Format' + r':LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$'
-    cleaned = re.sub(pattern, repl, content)
+    pattern = r'\$Format' + r':([^%:\r\n]+):([^%:\r\n]+):[^\r\n$]*?\$'
+    cleaned = re.sub(pattern, r'$Format:\1:\2:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$', content)
     sys.stdout.write(cleaned)
 
 else:
@@ -63,6 +62,7 @@ else:
 
         # Get the relative path of the file being smudged
         file_name = sys.argv[2] if len(sys.argv) > 2 else "unknown_file"
+        file_name = file_name.replace('\\', '/')
 
         # Read the file content sent by Git on stdin
         content = sys.stdin.read()
@@ -70,11 +70,11 @@ else:
         # Query git log metadata or local fallbacks
         info = get_git_info(file_name)
 
-        # Format replacement string using LocalFoodAI and app.py
-        replacement = f"$Format" + f":LocalFoodAI:app.py:{info[0]}:{info[1]}:{info[2]}:{info[3]}:{info[4]}:{info[5]}:{info[6]}:{info[7]}:{info[8]}$"
+        # Format replacement string using dynamic project and file name
+        replacement = f"$Format" + f":{project_name}:{file_name}:{info[0]}:{info[1]}:{info[2]}:{info[3]}:{info[4]}:{info[5]}:{info[6]}:{info[7]}:{info[8]}$"
 
         # Regex replacement targeting the dynamic format placeholders
-        pattern = r'\$Format' + r':[^:]+:[^:]+:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N\$'
+        pattern = r'\$Format' + r':([^%:\r\n]+):([^%:\r\n]+):%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N\$'
         smudged = re.sub(pattern, replacement, content)
         sys.stdout.write(smudged)
 

+ 23 - 0
skills/code-review/SKILL.md

@@ -0,0 +1,23 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/code-review/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: code-review
+description: Reviews code changes for bugs, style issues, and best practices. Use when reviewing PRs or checking code quality.
+---
+
+# Code Review Skill
+
+When reviewing code, follow these steps:
+
+## Review checklist
+
+1. **Correctness**: Does the code do what it's supposed to?
+2. **Edge cases**: Are error conditions handled?
+3. **Style**: Does it follow project conventions?
+4. **Performance**: Are there obvious inefficiencies?
+
+## How to provide feedback
+
+- Be specific about what needs to change
+- Explain why, not just what
+- Suggest alternatives when possible

+ 14 - 0
skills/doc-writer/SKILL.md

@@ -0,0 +1,14 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/doc-writer/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: doc-writer
+description: Maintains and updates documentation to ensure it stays perfectly synchronized with source code changes.
+---
+
+# Document Writer Skill
+
+When updating or generating documentation:
+
+1. **Always Synchronize:** Whenever a source code change is provided, you must update all associated documentation, READMEs, and inline comments to reflect the new state.
+2. **Project-Wide Updates:** If an architectural or project-wide change occurs, trace and document its impact across the entire system.
+3. **Clarity:** Write documentation assuming the reader is a new team member. Be concise, clear, and comprehensive.

+ 43 - 0
skills/expert-coach/SKILL.md

@@ -0,0 +1,43 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/expert-coach/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: expert-coach
+description: Acts as a senior principal engineer coaching junior staff. Enforces optimal code, modularity, and comprehensive documentation.
+---
+
+# Expert Coach Skill
+
+When writing or reviewing code, adopt the persona of a senior mentor guiding a junior developer. Follow these strict guidelines:
+
+## 1. Code Generation & Mentorship
+- **Optimal & Correct:** Code must be generated with the correct syntax, using the most optimal functions and algorithms for the language.
+- **Deep Documentation:** Add inline comments explaining complex logic. Cite sources or documentation to help the junior developer understand *why* a specific approach was taken.
+- **Test-Driven:** Any code change or generation must be accompanied by tests covering both the isolated change and its integration into the full program.
+
+## 2. Architecture & Modularity
+- **No Monoliths:** Avoid monolithic program structures. Break down logic into reusable libraries and micro-files.
+- **Micro-Files:** Create small, single-purpose files. This makes testing easier and simplifies tracking changes in version control.
+
+## 3. Reliability & Tracking
+- **Traceability:** Ensure all code is easy to track and document. Promote continuous integration principles.
+- **Defensive Programming:** Anticipate failure points and handle exceptions gracefully to ensure high reliability.
+
+## 4. Mandatory File Header
+* **Header Tag Requirement:** Every source code, scripting, config, or text file (including ignored scratch files) must include the exact identity format at the top of the file:
+```text
+i d e n t   " @ ( # ) $ F o r m a t : { p r o j e c t _ n a m e } : { f i l e _ n a m e } : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "
+```
+*Note: In the template above, the character sequence has been intentionally formatted with spaces between each character (representing the `sed` transformation `s/./& /g`). This prevents Git's clean/smudge filters from matching, interpreting, and modifying this rule documentation file itself.*
+  For tracked files, the Git smudge filter (`ident-dynamic`) will automatically expand the placeholder variables with real Git commit and author/committer data during checkouts. Untracked or ignored scratch files must still physically carry this header comment as a repository consistency requirement.
+  The comment syntax must match the file's language (e.g., `#` for Python/Shell/YAML/Markdown/Dockerfiles, `--` for SQL, `::` for Batch). For tracked files, the git smudge filter expands this dynamically. Ignore-listed/scratch files must carry the comment statically for structure.
+  Adapt the comment syntax (e.g., "//", "#", "--", "`", "!", "REM", "/*  */") to the specific language. Exception: For executable scripts requiring a shebang (e.g., #!/bin/bashor#!/usr/bin/env python), the shebang must remain on the first line, and the Identity Tag MUST be placed on the second line.
+
+  To initialize a new file, place the clean version at the top of your file (legible examples are listed below in spaced-out format to prevent active smudge filter matching):
+- For Python/Shell files:
+  `# i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For SQL files:
+  `- - i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For Batch files:
+  `: : i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For Markdown/YAML/Dockerfiles/XML:
+  `# i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`

+ 39 - 0
skills/git-commit/SKILL.md

@@ -0,0 +1,39 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/git-commit/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: git-commit
+description: Enforces strict Git governance, Taiga tracking, branching strategies, and file metadata standards.
+---
+
+# Git Commit Governance Skill
+
+When analyzing git commits, pull requests, or branch merges, you must strictly enforce the following rules:
+
+## 1. Commit Messages & Tracking
+- **Taiga Integration:** Every commit message MUST start with the specific Taiga task/story tag (e.g., `TG-123`, `US#123`, or `[#123]`) to update the task status. You must ensure a Git hook is actively verifying this format and rejecting non-compliant commits.
+
+## 2. Branching Strategy & Segregation of Duties
+- **Pipeline Flow:** Verify the code progresses strictly through three branches: `development` -> `test` (or `integration`) -> `production`.
+- **WARNING - Segregation of Duties:** Since the current team size is small, DO NOT block the merge. Instead, **provide a warning** if the user attempting to promote/merge the code is the same user who originally authored the code, or if they are bypassing a branch.
+- **WARNING - Cross-Branch Promotion:** You must issue a warning if the same user is attempting to promote files from one branch directly to another without proper review gates.
+
+## 3. File Metadata & Formatting
+* **Header Tag Requirement:** Every source code, scripting, config, or text file (including ignored scratch files) must include the exact identity format at the top of the file:
+```text
+i d e n t   " @ ( # ) $ F o r m a t : { p r o j e c t _ n a m e } : { f i l e _ n a m e } : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "
+```
+*Note: In the template above, the character sequence has been intentionally formatted with spaces between each character (representing the `sed` transformation `s/./& /g`). This prevents Git's clean/smudge filters from matching, interpreting, and modifying this rule documentation file itself.*
+  For tracked files, the Git smudge filter (`ident-dynamic`) will automatically expand the placeholder variables with real Git commit and author/committer data during checkouts. Untracked or ignored scratch files must still physically carry this header comment as a repository consistency requirement.
+  The comment syntax must match the file's language (e.g., `#` for Python/Shell/YAML/Markdown/Dockerfiles, `--` for SQL, `::` for Batch). For tracked files, the git smudge filter expands this dynamically. Ignore-listed/scratch files must carry the comment statically for structure.
+  Adapt the comment syntax (e.g., "//", "#", "--", "`", "!", "REM", "/*  */") to the specific language. Exception: For executable scripts requiring a shebang (e.g., #!/bin/bashor#!/usr/bin/env python), the shebang must remain on the first line, and the Identity Tag MUST be placed on the second line.
+
+  To initialize a new file, place the clean version at the top of your file (legible examples are listed below in spaced-out format to prevent active smudge filter matching):
+- For Python/Shell files:
+  `# i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For SQL files:
+  `- - i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For Batch files:
+  `: : i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For Markdown/YAML/Dockerfiles/XML:
+  `# i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- **Line Endings:** Only Line Feed (LF) is allowed (Carriage Return Line Feed (CRLF) is strictly forbidden), with the exception of Windows batch files (`*.bat`), which must use CRLF. Exception: For executable scripts requiring a shebang (e.g., #!/bin/bash or #!/usr/bin/env python), the shebang must remain on the first line, and the Identity Tag MUST be placed on the second line.

+ 15 - 0
skills/refactor-coach/SKILL.md

@@ -0,0 +1,15 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/refactor-coach/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: refactor-coach
+description: Refactors code to improve readability, performance, and modularity without changing external behavior.
+---
+
+# Refactor Coach Skill
+
+When refactoring code:
+
+1. **DRY Principle:** Identify duplicate code and extract it into reusable functions or libraries.
+2. **Complexity Reduction:** Break down long functions into smaller, clearly named helper functions.
+3. **Performance:** Identify and resolve obvious bottlenecks (e.g., nested loops, inefficient data structures) while explaining the algorithmic improvement.
+4. **Safety:** Guarantee that the external API and behavior of the code remain entirely unchanged.

+ 51 - 0
skills/sql-optimizer/SKILL.md

@@ -0,0 +1,51 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/sql-optimizer/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: sql-optimizer
+description: Optimizes and secures SQL for MySQL, Oracle, and PostgreSQL, enforcing strict DBA standards.
+---
+
+# SQL Optimizer & DBA Skill
+
+When reviewing, optimizing, or generating SQL code (MySQL, Oracle, PostgreSQL), enforce these strict database guidelines:
+
+## 1. Performance & Concurrency
+- **Locking:** Avoid row locking issues and design queries to prevent deadlocks.
+- **Indexing:** Suggest optimal indexes, including B-Tree, full-text, spatial, or composite indexes where appropriate.
+- **Testing:** When testing SQL in non-production environments, utilize all available database optimizer tools (e.g., `EXPLAIN PLAN`, `tkprof`).
+
+## 2. Security & Access Control
+- **No Hardcoded Users:** NEVER hardcode usernames in scripts.
+- **Proxy/Restricted Access:** Ensure the program accesses objects through proxy users or restricted views (objects must be owned by one or more dedicated owner schemas, not the application user).
+- **Audit Policies:** Recommend the setup of appropriate audit policies for sensitive tables/actions (Do not write the scripts to set them up, only advise).
+- **Bind Variables:** SQL statements MUST use bind variables to pass and receive values. No dynamic concatenation of user inputs.
+- **Grants & Synonyms:** Whenever new objects are created or accessed, you MUST provide all the necessary `GRANT` statements and `SYNONYM` creations required for the application to function securely.
+## 3. Transaction Management
+- **No Auto-Commit:** Disable auto-commit. Explicitly manage transactions with `COMMIT` and `ROLLBACK` blocks.
+
+## 4. Syntax & DDL Standards
+- **Quoted Identifiers:** All object and column names must be double-quoted (`"`) or back-quoted (`` ` ``) to avoid collisions with reserved words. Warn if a name matches a `V$RESERVED_WORDS` in Oracle.
+- **Reserved Words Warning:** Issue a warning if an object or column name matches an Oracle reserved word (from `V$RESERVED_WORDS`).
+- **DDL Changes:** All Data Definition Language (DDL) changes must be generated using `DBMS_METADATA` and `DBMS_METADATA_DIFF` to calculate and apply exact differences.
+- **Exception Management:** Always implement robust exception handling (e.g., `EXCEPTION` blocks in PL/SQL) to capture, manage, and log database errors gracefully. Do not allow silent failures.
+
+## 5. Mandatory File Header
+* **Header Tag Requirement:** Every source code, scripting, config, or text file (including ignored scratch files) must include the exact identity format at the top of the file:
+```text
+i d e n t   " @ ( # ) $ F o r m a t : { p r o j e c t _ n a m e } : { f i l e _ n a m e } : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "
+```
+*Note: In the template above, the character sequence has been intentionally formatted with spaces between each character (representing the `sed` transformation `s/./& /g`). This prevents Git's clean/smudge filters from matching, interpreting, and modifying this rule documentation file itself.*
+  For tracked files, the Git smudge filter (`ident-dynamic`) will automatically expand the placeholder variables with real Git commit and author/committer data during checkouts. Untracked or ignored scratch files must still physically carry this header comment as a repository consistency requirement.
+  The comment syntax must match the file's language (e.g., `#` for Python/Shell/YAML/Markdown/Dockerfiles, `--` for SQL, `::` for Batch). For tracked files, the git smudge filter expands this dynamically. Ignore-listed/scratch files must carry the comment statically for structure.
+  Adapt the comment syntax (e.g., "//", "#", "--", "`", "!", "REM", "/*  */") to the specific language. Exception: For executable scripts requiring a shebang (e.g., #!/bin/bashor#!/usr/bin/env python), the shebang must remain on the first line, and the Identity Tag MUST be placed on the second line.
+
+  To initialize a new file, place the clean version at the top of your file (legible examples are listed below in spaced-out format to prevent active smudge filter matching):
+- For Python/Shell files:
+  `# i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For SQL files:
+  `- - i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For Batch files:
+  `: : i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+- For Markdown/YAML/Dockerfiles/XML:
+  `# i d e n t   " @ ( # ) $ F o r m a t : G i t  p r o j e c t   n a m e : f i l e n a m e : % a n : % a e : % a d : % c n : % c e : % c d : % H : % D : % N $ "`
+

+ 15 - 0
skills/test-generator/SKILL.md

@@ -0,0 +1,15 @@
+The current version is #ident "@(#)$Format:DEVOP1:skills/test-generator/SKILL.md:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
+
+---
+name: test-generator
+description: Generates comprehensive unit and integration tests for code changes.
+---
+
+# Test Generator Skill
+
+When generating tests, adhere to the following rules:
+
+1. **Isolation & Integration:** Write unit tests for isolated functions and integration tests to verify the piece works within the broader system.
+2. **Edge Cases:** Explicitly test boundary conditions, null inputs, and unexpected data types.
+3. **Mocking:** Use appropriate mocking frameworks to isolate dependencies (e.g., databases, external APIs).
+4. **Coverage:** Ensure the generated tests aim for maximum logical coverage, targeting newly modified lines of code.