rootkid0-initializer 0.1.1 → 0.1.2

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.
@@ -26,11 +26,12 @@ El initializer NO instala ni modifica MCP global.
26
26
 
27
27
  Validacion minima del bootstrap:
28
28
 
29
- - `~/.config/opencode/mcp-servers.json`
29
+ - `~/.config/opencode/opencode.json` (preferido)
30
+ - `~/.config/opencode/mcp-servers.json` (legacy)
30
31
 
31
32
  Condicion minima requerida:
32
33
 
33
- - Debe existir entrada `notion` en el archivo global.
34
+ - Debe existir entrada `notion` en el archivo global usado.
34
35
 
35
36
  Si falta, el init falla con mensaje de correccion porque el setup Notion es automatico en P1.
36
37
 
package/README.md CHANGED
@@ -70,7 +70,7 @@ El script crea una carpeta nueva con la estructura actual del repositorio, exclu
70
70
  El init ejecuta bootstrap Notion automaticamente despues de crear el proyecto. Requisitos obligatorios:
71
71
 
72
72
  - MCP Notion preinstalado/configurado por el usuario (el initializer no instala ni modifica MCP global).
73
- - Archivo global `~/.config/opencode/mcp-servers.json` con entrada `notion`.
73
+ - Archivo global `~/.config/opencode/opencode.json` (preferido) o `~/.config/opencode/mcp-servers.json` (legacy), con entrada `notion`.
74
74
  - Credencial de Notion resuelta desde MCP Notion (o `NOTION_TOKEN` si la defines manualmente).
75
75
  - Variables opcionales:
76
76
  - `NOTION_PARENT_PAGE_ID` (recomendado para crear bajo una raiz definida)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rootkid0-initializer",
3
- "version": "0.1.1",
4
- "description": "CLI para inicializar proyectos rootkid0.",
3
+ "version": "0.1.2",
4
+ "description": "CLI para inicializar el flujo de proyectos al estilo rootkid0.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "bin": {
@@ -28,7 +28,15 @@ function Resolve-NotionToken([string]$McpFile) {
28
28
 
29
29
  try {
30
30
  $raw = Get-Content -Path $McpFile -Raw | ConvertFrom-Json
31
- $fromConfig = $raw.servers.notion.env.NOTION_TOKEN
31
+ if ($null -ne $raw.servers) {
32
+ $fromConfig = $raw.servers.notion.env.NOTION_TOKEN
33
+ }
34
+ elseif ($null -ne $raw.mcp -and $null -ne $raw.mcp.servers) {
35
+ $fromConfig = $raw.mcp.servers.notion.env.NOTION_TOKEN
36
+ }
37
+ else {
38
+ $fromConfig = ""
39
+ }
32
40
  }
33
41
  catch {
34
42
  $fromConfig = ""
@@ -50,6 +58,37 @@ function Resolve-NotionToken([string]$McpFile) {
50
58
  Fail "No se pudo resolver credencial de Notion. Define NOTION_TOKEN o configura servers.notion.env.NOTION_TOKEN en $McpFile."
51
59
  }
52
60
 
61
+ function Resolve-McpConfigFile() {
62
+ $opencodeFile = Join-Path $HOME ".config/opencode/opencode.json"
63
+ $legacyFile = Join-Path $HOME ".config/opencode/mcp-servers.json"
64
+
65
+ if (Test-Path -LiteralPath $opencodeFile) {
66
+ return $opencodeFile
67
+ }
68
+
69
+ if (Test-Path -LiteralPath $legacyFile) {
70
+ return $legacyFile
71
+ }
72
+
73
+ Fail "Prerequisito faltante: MCP Notion no disponible. Debe existir $opencodeFile (preferido) o $legacyFile con entrada notion antes de ejecutar init-project."
74
+ }
75
+
76
+ function Has-NotionServer([string]$McpFile) {
77
+ try {
78
+ $raw = Get-Content -Path $McpFile -Raw | ConvertFrom-Json
79
+ if ($null -ne $raw.servers -and $null -ne $raw.servers.notion) {
80
+ return $true
81
+ }
82
+ if ($null -ne $raw.mcp -and $null -ne $raw.mcp.servers -and $null -ne $raw.mcp.servers.notion) {
83
+ return $true
84
+ }
85
+ return $false
86
+ }
87
+ catch {
88
+ return $false
89
+ }
90
+ }
91
+
53
92
  function Get-NotionPagePayload([string]$ParentMode, [string]$ParentValue, [string]$Title) {
54
93
  if ($ParentMode -eq "page") {
55
94
  return @{
@@ -117,13 +156,9 @@ if (-not (Test-Path -LiteralPath $ProjectDir)) {
117
156
  Fail "No existe el directorio de proyecto: $ProjectDir"
118
157
  }
119
158
 
120
- $mcpFile = Join-Path $HOME ".config/opencode/mcp-servers.json"
121
-
122
- if (-not (Test-Path -LiteralPath $mcpFile)) {
123
- Fail "Prerequisito faltante: MCP Notion no disponible. Debe existir $mcpFile con entrada notion antes de ejecutar init-project."
124
- }
159
+ $mcpFile = Resolve-McpConfigFile
125
160
 
126
- if (-not (Select-String -Path $mcpFile -Pattern '"notion"' -Quiet)) {
161
+ if (-not (Has-NotionServer -McpFile $mcpFile)) {
127
162
  Fail "Prerequisito faltante: MCP Notion no disponible. Agrega entrada notion en $mcpFile y vuelve a ejecutar init-project."
128
163
  }
129
164
 
@@ -35,14 +35,39 @@ pick_python() {
35
35
  }
36
36
 
37
37
  validate_mcp_config() {
38
- local mcp_file="$HOME/.config/opencode/mcp-servers.json"
38
+ local mcp_file="$1"
39
+ local py_bin
40
+ local has_notion=""
39
41
 
40
42
  if [[ ! -f "$mcp_file" ]]; then
41
- fail "Prerequisito faltante: MCP Notion no disponible. Debe existir $mcp_file con entrada 'notion' antes de ejecutar init-project."
43
+ fail "Prerequisito faltante: MCP Notion no disponible. Debe existir $mcp_file con entrada notion antes de ejecutar init-project."
42
44
  fi
43
45
 
44
- if ! grep -q '"notion"' "$mcp_file"; then
45
- fail "Prerequisito faltante: MCP Notion no disponible. Agrega la entrada 'notion' en $mcp_file y vuelve a ejecutar init-project."
46
+ py_bin="$(pick_python || true)"
47
+ if [[ -n "$py_bin" ]]; then
48
+ has_notion="$($py_bin - "$mcp_file" <<'PY'
49
+ import json
50
+ import sys
51
+
52
+ with open(sys.argv[1], "r", encoding="utf-8") as f:
53
+ data = json.load(f)
54
+
55
+ servers = {}
56
+ if isinstance(data, dict):
57
+ if isinstance(data.get("servers"), dict):
58
+ servers = data.get("servers", {})
59
+ elif isinstance(data.get("mcp"), dict) and isinstance(data["mcp"].get("servers"), dict):
60
+ servers = data["mcp"]["servers"]
61
+
62
+ print("yes" if "notion" in servers else "no")
63
+ PY
64
+ )"
65
+ else
66
+ has_notion="$(grep -q '"notion"' "$mcp_file" && echo yes || echo no)"
67
+ fi
68
+
69
+ if [[ "$has_notion" != "yes" ]]; then
70
+ fail "Prerequisito faltante: MCP Notion no disponible. Agrega la entrada notion en $mcp_file y vuelve a ejecutar init-project."
46
71
  fi
47
72
  }
48
73
 
@@ -63,7 +88,7 @@ require_command() {
63
88
  }
64
89
 
65
90
  resolve_notion_token() {
66
- local mcp_file="$HOME/.config/opencode/mcp-servers.json"
91
+ local mcp_file="$1"
67
92
  local token="${NOTION_TOKEN:-}"
68
93
  local py_bin
69
94
 
@@ -84,7 +109,13 @@ with open(sys.argv[1], "r", encoding="utf-8") as f:
84
109
  data = json.load(f)
85
110
 
86
111
  value = ""
87
- servers = data.get("servers", {})
112
+ servers = {}
113
+ if isinstance(data, dict):
114
+ if isinstance(data.get("servers"), dict):
115
+ servers = data.get("servers", {})
116
+ elif isinstance(data.get("mcp"), dict) and isinstance(data["mcp"].get("servers"), dict):
117
+ servers = data["mcp"]["servers"]
118
+
88
119
  notion = servers.get("notion", {}) if isinstance(servers, dict) else {}
89
120
  env = notion.get("env", {}) if isinstance(notion, dict) else {}
90
121
 
@@ -109,6 +140,23 @@ PY
109
140
  printf '%s' "$token"
110
141
  }
111
142
 
143
+ resolve_mcp_config_file() {
144
+ local opencode_file="$HOME/.config/opencode/opencode.json"
145
+ local legacy_file="$HOME/.config/opencode/mcp-servers.json"
146
+
147
+ if [[ -f "$opencode_file" ]]; then
148
+ printf '%s' "$opencode_file"
149
+ return 0
150
+ fi
151
+
152
+ if [[ -f "$legacy_file" ]]; then
153
+ printf '%s' "$legacy_file"
154
+ return 0
155
+ fi
156
+
157
+ fail "Prerequisito faltante: MCP Notion no disponible. Debe existir $opencode_file (preferido) o $legacy_file con entrada notion antes de ejecutar init-project."
158
+ }
159
+
112
160
  build_page_payload() {
113
161
  local parent_mode="$1"
114
162
  local parent_value="$2"
@@ -214,9 +262,10 @@ if [[ ! -d "$PROJECT_DIR" ]]; then
214
262
  fail "No existe el directorio de proyecto: $PROJECT_DIR"
215
263
  fi
216
264
 
217
- validate_mcp_config
265
+ mcp_config_file="$(resolve_mcp_config_file)"
266
+ validate_mcp_config "$mcp_config_file"
218
267
  require_command "curl"
219
- NOTION_AUTH_TOKEN="$(resolve_notion_token)"
268
+ NOTION_AUTH_TOKEN="$(resolve_notion_token "$mcp_config_file")"
220
269
 
221
270
  NOTION_WORKSPACE_NAME="${NOTION_WORKSPACE_NAME:-}"
222
271
  NOTION_PARENT_PAGE_ID="${NOTION_PARENT_PAGE_ID:-}"