Refactor: migrate POSIX scaffolding to CBOR and JSONC

This commit is contained in:
MangoPig
2026-07-06 13:06:32 +01:00
parent 2c8338d1cd
commit 58bc285748
14 changed files with 860 additions and 268 deletions
@@ -26,7 +26,7 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
return fmt.Errorf("create POSIX root: %w", err)
}
if err := writeJSONFile(filepath.Join(rootPath, "settings.json"), map[string]any{
if err := writeCBORFile(filepath.Join(rootPath, posixSettingsFileName), map[string]any{
"installation": map[string]any{
"id": installation.ID,
"name": installation.Name,
@@ -42,17 +42,17 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
"slug": organization.Slug,
},
}); err != nil {
return fmt.Errorf("write tenant settings.json: %w", err)
return fmt.Errorf("write tenant %s: %w", posixSettingsFileName, err)
}
if err := writeJSONFile(filepath.Join(rootPath, "layout.json"), map[string]any{
if err := writeCBORFile(filepath.Join(rootPath, posixLayoutFileName), map[string]any{
"version": 1,
"type": "tenant-layout",
"home": map[string]any{
"defaultProjectSlug": project.Slug,
},
}); err != nil {
return fmt.Errorf("write tenant layout.json: %w", err)
return fmt.Errorf("write tenant %s: %w", posixLayoutFileName, err)
}
if err := os.MkdirAll(filepath.Join(rootPath, "catalog", "packs"), 0o755); err != nil {
@@ -63,6 +63,67 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
return fmt.Errorf("create catalog standalone root: %w", err)
}
corePackPath := filepath.Join(rootPath, "catalog", "packs", "pack-core")
corePackEntriesPath := filepath.Join(corePackPath, "entries")
coreAppEntryPath := filepath.Join(corePackEntriesPath, "app-shell")
standaloneAppPath := filepath.Join(rootPath, "catalog", "standalone", "app-shell")
for _, dirPath := range []string{corePackPath, corePackEntriesPath, coreAppEntryPath, standaloneAppPath} {
if err := os.MkdirAll(dirPath, 0o755); err != nil {
return fmt.Errorf("create catalog directory %s: %w", dirPath, err)
}
}
if err := writeJSONCFile(filepath.Join(corePackPath, posixManifestFileName), map[string]any{
"id": "pack-core",
"slug": "core",
"type": "pack",
"name": "Core Pack",
"version": "0.1.0",
"description": "First-party shared package of starter Moku surfaces.",
"entries": []map[string]any{{
"slug": "app-shell",
"path": "entries/app-shell",
}},
"capabilities": []string{"first-party", "bootstrap", "catalog-pack"},
}); err != nil {
return fmt.Errorf("write catalog pack %s: %w", posixManifestFileName, err)
}
if err := writeJSONCFile(filepath.Join(coreAppEntryPath, posixManifestFileName), map[string]any{
"id": "app-shell",
"slug": "app-shell",
"type": "app",
"name": "App Shell",
"version": "0.1.0",
"description": "Primary shell surface for navigating the installation.",
"source": "pack-core",
"runtime": map[string]any{
"kind": "route",
"path": "/v1/app-shell",
},
"capabilities": []string{"shell", "navigation", "workspace"},
}); err != nil {
return fmt.Errorf("write catalog entry %s: %w", posixManifestFileName, err)
}
if err := writeJSONCFile(filepath.Join(standaloneAppPath, posixManifestFileName), map[string]any{
"id": "app-shell",
"slug": "app-shell",
"type": "app",
"name": "App Shell",
"version": "0.1.0",
"description": "Standalone registration for the primary shell surface.",
"source": "standalone",
"runtime": map[string]any{
"kind": "route",
"path": "/v1/app-shell",
},
"capabilities": []string{"shell", "navigation", "standalone"},
}); err != nil {
return fmt.Errorf("write standalone entry %s: %w", posixManifestFileName, err)
}
departmentPath := filepath.Join(rootPath, "departments", slugDir("department", department.Slug))
teamPath := filepath.Join(departmentPath, "teams", slugDir("team", team.Slug))
projectPath := filepath.Join(rootPath, "projects", slugDir("project", project.Slug))
@@ -89,107 +150,107 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
}
}
if err := writeJSONFile(filepath.Join(departmentPath, "settings.json"), map[string]any{
if err := writeCBORFile(filepath.Join(departmentPath, posixSettingsFileName), map[string]any{
"id": department.ID,
"name": department.Name,
"slug": department.Slug,
"type": "department",
}); err != nil {
return fmt.Errorf("write department settings.json: %w", err)
return fmt.Errorf("write department %s: %w", posixSettingsFileName, err)
}
if err := writeJSONFile(filepath.Join(departmentPath, "users.json"), map[string]any{
if err := writeCBORFile(filepath.Join(departmentPath, posixUsersFileName), map[string]any{
"owners": []map[string]string{{
"id": admin.ID,
"email": admin.Email,
"displayName": admin.DisplayName,
}},
}); err != nil {
return fmt.Errorf("write department users.json: %w", err)
return fmt.Errorf("write department %s: %w", posixUsersFileName, err)
}
if err := writeJSONFile(filepath.Join(teamPath, "settings.json"), map[string]any{
if err := writeCBORFile(filepath.Join(teamPath, posixSettingsFileName), map[string]any{
"id": team.ID,
"name": team.Name,
"slug": team.Slug,
"type": "team",
}); err != nil {
return fmt.Errorf("write team settings.json: %w", err)
return fmt.Errorf("write team %s: %w", posixSettingsFileName, err)
}
if err := writeJSONFile(filepath.Join(teamPath, "users.json"), map[string]any{
if err := writeCBORFile(filepath.Join(teamPath, posixUsersFileName), map[string]any{
"owners": []map[string]string{{
"id": admin.ID,
"email": admin.Email,
"displayName": admin.DisplayName,
}},
}); err != nil {
return fmt.Errorf("write team users.json: %w", err)
return fmt.Errorf("write team %s: %w", posixUsersFileName, err)
}
if err := writeJSONFile(filepath.Join(projectPath, "settings.json"), map[string]any{
if err := writeCBORFile(filepath.Join(projectPath, posixSettingsFileName), map[string]any{
"id": project.ID,
"name": project.Name,
"slug": project.Slug,
"type": "project",
}); err != nil {
return fmt.Errorf("write project settings.json: %w", err)
return fmt.Errorf("write project %s: %w", posixSettingsFileName, err)
}
if err := writeJSONFile(filepath.Join(projectPath, "home.json"), map[string]any{
if err := writeCBORFile(filepath.Join(projectPath, posixHomeFileName), map[string]any{
"type": "project-home",
"title": project.Name,
}); err != nil {
return fmt.Errorf("write project home.json: %w", err)
return fmt.Errorf("write project %s: %w", posixHomeFileName, err)
}
if err := writeJSONFile(filepath.Join(projectPath, "acl.json"), map[string]any{
if err := writeCBORFile(filepath.Join(projectPath, posixACLFileName), map[string]any{
"version": 1,
"inherits": true,
"rules": []any{},
}); err != nil {
return fmt.Errorf("write project acl.json: %w", err)
return fmt.Errorf("write project %s: %w", posixACLFileName, err)
}
if err := writeJSONFile(filepath.Join(usersPath, "settings.json"), map[string]any{
if err := writeCBORFile(filepath.Join(usersPath, posixSettingsFileName), map[string]any{
"primaryAdminId": admin.ID,
}); err != nil {
return fmt.Errorf("write users settings.json: %w", err)
return fmt.Errorf("write users %s: %w", posixSettingsFileName, err)
}
if err := writeJSONFile(filepath.Join(usersPath, "data.json"), map[string]any{
if err := writeCBORFile(filepath.Join(usersPath, posixDataFileName), map[string]any{
"admins": []map[string]string{{
"id": admin.ID,
"email": admin.Email,
"displayName": admin.DisplayName,
}},
}); err != nil {
return fmt.Errorf("write users data.json: %w", err)
return fmt.Errorf("write users %s: %w", posixDataFileName, err)
}
if err := writeJSONFile(filepath.Join(personalHomePath, "settings.json"), map[string]any{
if err := writeCBORFile(filepath.Join(personalHomePath, posixSettingsFileName), map[string]any{
"type": "personal",
"name": personalName,
"slug": personalSlug,
}); err != nil {
return fmt.Errorf("write personal settings.json: %w", err)
return fmt.Errorf("write personal %s: %w", posixSettingsFileName, err)
}
if err := writeJSONFile(filepath.Join(personalHomePath, "layout.json"), map[string]any{
if err := writeCBORFile(filepath.Join(personalHomePath, posixLayoutFileName), map[string]any{
"version": 1,
"type": "personal-layout",
"home": map[string]any{
"defaultProjectSlug": project.Slug,
},
}); err != nil {
return fmt.Errorf("write personal layout.json: %w", err)
return fmt.Errorf("write personal %s: %w", posixLayoutFileName, err)
}
if err := writeJSONFile(filepath.Join(personalHomePath, "home.json"), map[string]any{
if err := writeCBORFile(filepath.Join(personalHomePath, posixHomeFileName), map[string]any{
"type": "personal-home",
"title": personalHomeTitle(personalName),
}); err != nil {
return fmt.Errorf("write personal home.json: %w", err)
return fmt.Errorf("write personal %s: %w", posixHomeFileName, err)
}
return nil