feat: source attribution para funciones externas
Sistema de extracción de funciones desde repos externos. Agrega campos source_repo, source_license y source_file en functions y types (migración 006). Incluye manifest sources/sources.yaml, regla sources.md, parser con campos de atribución, y template actualizado con los nuevos campos. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
## Extraccion de funciones desde repos externos (`sources/`)
|
||||||
|
|
||||||
|
### Workflow
|
||||||
|
|
||||||
|
1. Clonar repo en `sources/<nombre>` (gitignored, solo el manifest `sources/sources.yaml` se versiona)
|
||||||
|
2. El agente analiza el repo y propone funciones candidatas
|
||||||
|
3. Las funciones se **copian y adaptan** al formato del registry (.go/.py/.sh/.ts + .md con frontmatter)
|
||||||
|
4. `fn index` las registra. El manifest se actualiza con las funciones extraidas.
|
||||||
|
|
||||||
|
### Filtro de calidad (obligatorio antes de extraer)
|
||||||
|
|
||||||
|
Una funcion externa solo se extrae si cumple TODOS estos criterios:
|
||||||
|
|
||||||
|
- **Firma generica**: no depende de tipos internos del repo origen ni de config hardcodeada
|
||||||
|
- **Sin estado global**: no usa variables globales, singletons, ni init() con side effects
|
||||||
|
- **Dependencias minimas**: solo stdlib o dependencias ya presentes en fn_registry
|
||||||
|
- **Pura si es posible**: si la funcion puede ser pura, debe extraerse como pura
|
||||||
|
- **Sin credenciales**: no contiene secrets, API keys, ni paths absolutos
|
||||||
|
- **Testeable**: la logica debe poder validarse con tests unitarios
|
||||||
|
- **No duplicada**: consultar registry.db con FTS5 antes de extraer para evitar duplicados
|
||||||
|
- **Licencia compatible**: el repo debe tener licencia permisiva (MIT, Apache 2.0, BSD, etc.)
|
||||||
|
|
||||||
|
### Adaptacion al extraer
|
||||||
|
|
||||||
|
- Renombrar a snake_case siguiendo la convencion del registry
|
||||||
|
- Adaptar firma para usar tipos nativos (no tipos internos del repo)
|
||||||
|
- Crear .md con frontmatter completo incluyendo `source_repo`, `source_license`, `source_file`
|
||||||
|
- Actualizar `sources/sources.yaml` con la extraccion
|
||||||
|
|
||||||
|
### Campos de atribucion en frontmatter
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
source_repo: "https://github.com/user/project"
|
||||||
|
source_license: "MIT"
|
||||||
|
source_file: "pkg/original_file.go"
|
||||||
|
```
|
||||||
|
|
||||||
|
Estos campos se indexan en registry.db y permiten consultar:
|
||||||
|
```sql
|
||||||
|
SELECT id, source_repo, source_license FROM functions WHERE source_repo != '';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lenguajes soportados para extraccion
|
||||||
|
|
||||||
|
Cualquier lenguaje puede analizarse como fuente. El destino depende de la naturaleza de la funcion:
|
||||||
|
- Algoritmos/logica pura → Go (functions/{domain}/) o Python (python/functions/{domain}/)
|
||||||
|
- Scripts/utilidades sistema → Bash (bash/functions/{domain}/)
|
||||||
|
- UI/frontend → TypeScript (frontend/functions/{domain}/)
|
||||||
|
- C/Rust/otros → Traducir a Go o Python, manteniendo la semantica original
|
||||||
@@ -37,6 +37,9 @@ python/.venv/
|
|||||||
# Node / pnpm
|
# Node / pnpm
|
||||||
**/node_modules/
|
**/node_modules/
|
||||||
|
|
||||||
|
# Sources — repos externos clonados (solo se versiona el manifest)
|
||||||
|
sources/*/
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|||||||
Vendored
+4
@@ -18,6 +18,10 @@ tested: false
|
|||||||
tests: []
|
tests: []
|
||||||
test_file_path: ""
|
test_file_path: ""
|
||||||
file_path: "functions/core/filter_slice.go"
|
file_path: "functions/core/filter_slice.go"
|
||||||
|
# Source attribution (solo para funciones extraidas de repos externos)
|
||||||
|
# source_repo: "https://github.com/user/project"
|
||||||
|
# source_license: "MIT"
|
||||||
|
# source_file: "pkg/utils.go"
|
||||||
---
|
---
|
||||||
|
|
||||||
## Ejemplo
|
## Ejemplo
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
-- Source attribution for functions extracted from external repositories.
|
||||||
|
ALTER TABLE functions ADD COLUMN source_repo TEXT NOT NULL DEFAULT '';
|
||||||
|
ALTER TABLE functions ADD COLUMN source_license TEXT NOT NULL DEFAULT '';
|
||||||
|
ALTER TABLE functions ADD COLUMN source_file TEXT NOT NULL DEFAULT '';
|
||||||
|
|
||||||
|
ALTER TABLE types ADD COLUMN source_repo TEXT NOT NULL DEFAULT '';
|
||||||
|
ALTER TABLE types ADD COLUMN source_license TEXT NOT NULL DEFAULT '';
|
||||||
|
ALTER TABLE types ADD COLUMN source_file TEXT NOT NULL DEFAULT '';
|
||||||
+16
-2
@@ -32,6 +32,11 @@ type rawFunction struct {
|
|||||||
TestFilePath string `yaml:"test_file_path"`
|
TestFilePath string `yaml:"test_file_path"`
|
||||||
FilePath string `yaml:"file_path"`
|
FilePath string `yaml:"file_path"`
|
||||||
|
|
||||||
|
// Source attribution
|
||||||
|
SourceRepo string `yaml:"source_repo"`
|
||||||
|
SourceLicense string `yaml:"source_license"`
|
||||||
|
SourceFile string `yaml:"source_file"`
|
||||||
|
|
||||||
// Component fields
|
// Component fields
|
||||||
Props []PropDef `yaml:"props"`
|
Props []PropDef `yaml:"props"`
|
||||||
Emits []string `yaml:"emits"`
|
Emits []string `yaml:"emits"`
|
||||||
@@ -50,8 +55,11 @@ type rawType struct {
|
|||||||
Definition string `yaml:"definition"`
|
Definition string `yaml:"definition"`
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
Tags []string `yaml:"tags"`
|
Tags []string `yaml:"tags"`
|
||||||
UsesTypes []string `yaml:"uses_types"`
|
UsesTypes []string `yaml:"uses_types"`
|
||||||
FilePath string `yaml:"file_path"`
|
FilePath string `yaml:"file_path"`
|
||||||
|
SourceRepo string `yaml:"source_repo"`
|
||||||
|
SourceLicense string `yaml:"source_license"`
|
||||||
|
SourceFile string `yaml:"source_file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// rawApp mirrors the YAML frontmatter of an app .md file.
|
// rawApp mirrors the YAML frontmatter of an app .md file.
|
||||||
@@ -146,6 +154,9 @@ func ParseFunctionMD(path string, root string) (*Function, error) {
|
|||||||
HasState: raw.HasState,
|
HasState: raw.HasState,
|
||||||
Framework: raw.Framework,
|
Framework: raw.Framework,
|
||||||
Variant: raw.Variant,
|
Variant: raw.Variant,
|
||||||
|
SourceRepo: raw.SourceRepo,
|
||||||
|
SourceLicense: raw.SourceLicense,
|
||||||
|
SourceFile: raw.SourceFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
if root != "" && raw.FilePath != "" {
|
if root != "" && raw.FilePath != "" {
|
||||||
@@ -196,6 +207,9 @@ func ParseTypeMD(path string, root string) (*Type, error) {
|
|||||||
Description: raw.Description,
|
Description: raw.Description,
|
||||||
Tags: raw.Tags,
|
Tags: raw.Tags,
|
||||||
UsesTypes: raw.UsesTypes,
|
UsesTypes: raw.UsesTypes,
|
||||||
|
SourceRepo: raw.SourceRepo,
|
||||||
|
SourceLicense: raw.SourceLicense,
|
||||||
|
SourceFile: raw.SourceFile,
|
||||||
Examples: sections.example,
|
Examples: sections.example,
|
||||||
Notes: sections.notes,
|
Notes: sections.notes,
|
||||||
Documentation: sections.documentation,
|
Documentation: sections.documentation,
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Manifest de repositorios externos para extraccion de funciones.
|
||||||
|
# Cada entrada registra un repo clonado en sources/ y las funciones extraidas.
|
||||||
|
#
|
||||||
|
# Formato:
|
||||||
|
# - repo: https://github.com/user/project
|
||||||
|
# license: MIT
|
||||||
|
# cloned_dir: project # nombre del directorio en sources/
|
||||||
|
# extracted: # funciones ya extraidas (el agente las registra)
|
||||||
|
# - id: func_name_go_core
|
||||||
|
# source_file: pkg/utils.go # path relativo dentro del repo original
|
||||||
|
# date: 2026-03-29
|
||||||
|
#
|
||||||
|
# Workflow:
|
||||||
|
# 1. Clonar repo en sources/: git clone <url> sources/<nombre>
|
||||||
|
# 2. Invocar agente extractor para analizar y proponer funciones
|
||||||
|
# 3. El agente copia, adapta, crea .go + .md con atribucion
|
||||||
|
# 4. fn index para registrar en registry.db
|
||||||
|
# 5. Actualizar este manifest con las funciones extraidas
|
||||||
|
|
||||||
|
repos: []
|
||||||
Reference in New Issue
Block a user