@gitpagedocs/tools 0.0.2 → 0.0.4

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.
package/README.md CHANGED
@@ -7,7 +7,7 @@ The **shared business-logic core** of the [Git Page Docs](../README.md) monorepo
7
7
  | Module | Responsibility |
8
8
  |---|---|
9
9
  | `ai/` | 14-provider AI system — data-driven `PROVIDER_CATALOG`, registry + factory (no switch chains), 5 family adapters (OpenAI-compatible, Anthropic, Gemini, Ollama, Cohere), SSE/NDJSON streaming, legacy↔catalog id mapping |
10
- | `security/` | `EncryptedCredentialVault` (AES-256-GCM, PBKDF2-HMAC-SHA-256 key derivation), `SessionPasswordGate`, plaintext migration; `WebStorageVaultStorage` (site `localStorage` vault) + `FileVaultStorage` (the CLI `.gitpagedocsvault` file) adapters |
10
+ | `security/` | `EncryptedCredentialVault` (AES-256-GCM, PBKDF2-HMAC-SHA-256 key derivation), `SessionPasswordGate`; `WebStorageVaultStorage` (site `localStorage` vault) + `FileVaultStorage` (the CLI `.gitpagedocsvault` file) adapters |
11
11
  | `crypto/` | `NodeCryptoService` + `WebCryptoService` (SHA-256, PBKDF2, AES-256-GCM, masking, secure wipe); `deriveDocAccessKeys` / `verifyDocAccess` (double-hash documentation password gate shared by the CLI `password` command and the frontend gate) |
12
12
  | `cache/` | `MemoryCache`, `FileCache`, `WebStorageCache` (Strategy over one `Cache` port) |
13
13
  | `config/` | `GitPageDocsConfigLoader` (`.json` / `.js` / `.ts`) |
@@ -15,7 +15,7 @@ The **shared business-logic core** of the [Git Page Docs](../README.md) monorepo
15
15
  | `errors/` | `AppError` + typed subclasses |
16
16
  | `filesystem/` | `FileService` (root-bounded list/read/write/search) |
17
17
  | `documentation/` | `DocumentationService`, `patchManagedRegion`, `DocUpdater` |
18
- | `i18n/` | Language bundles (`site.languages` toggles in `config.json` + `langs/<lang>.json`): `loadConfigLanguageBundles`, `applyLanguageBundles` (fold into legacy `site.langmenu` / `translations`), `filterEnabledLanguages`, `splitLanguageBundles` (generator side); browser-safe |
18
+ | `i18n/` | Language bundles (`site.languages` toggles in `config.json` + `langs/<lang>.json`): `loadConfigLanguageBundles`, `applyLanguageBundles` (fold into `site.langmenu` / `translations`), `filterEnabledLanguages`, `splitLanguageBundles` (generator side); browser-safe |
19
19
  | `ports/` | Type-only contracts (logger, cache, crypto, security, config, ai) |
20
20
 
21
21
  ## Entry points (`exports`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitpagedocs/tools",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "description": "Shared business-logic core for Git Page Docs (consumed by frontend, cli and mcp). Ships TypeScript source; consume via tsx or a TS-aware bundler.",
6
6
  "main": "./src/index.ts",
@@ -10,6 +10,7 @@
10
10
  "./ai": "./src/ai/index.ts",
11
11
  "./errors": "./src/errors/index.ts",
12
12
  "./i18n": "./src/i18n/index.ts",
13
+ "./config-format": "./src/config-format/index.ts",
13
14
  "./ports": "./src/ports/index.ts",
14
15
  "./crypto/web": "./src/crypto/web.ts",
15
16
  "./security/web": "./src/security/web.ts",
package/src/ai/catalog.ts CHANGED
@@ -38,8 +38,11 @@ const TEXT: ProviderCapabilities = { streaming: true, vision: false, audio: fals
38
38
  const VISION: ProviderCapabilities = { streaming: true, vision: true, audio: false };
39
39
  const VISION_AUDIO: ProviderCapabilities = { streaming: true, vision: true, audio: true };
40
40
 
41
- function models(...ids: string[]): ModelDescriptor[] {
42
- return ids.map((id) => ({ id }));
41
+ type ModelEntry = string | readonly [id: string, label: string];
42
+
43
+ /** Catalog rows: a bare id, or `[id, label]` when a human-readable name exists for menus. */
44
+ function models(...entries: ModelEntry[]): ModelDescriptor[] {
45
+ return entries.map((entry) => (typeof entry === "string" ? { id: entry } : { id: entry[0], label: entry[1] }));
43
46
  }
44
47
 
45
48
  export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
@@ -52,7 +55,7 @@ export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
52
55
  baseUrl: "https://api.openai.com/v1",
53
56
  auth: "bearer",
54
57
  capabilities: VISION,
55
- models: models("gpt-4o", "gpt-4o-mini", "o3-mini", "o1"),
58
+ models: models(["gpt-4o", "GPT-4o"], ["gpt-4o-mini", "GPT-4o mini"], ["o3-mini", "o3-mini"], ["o1", "o1"]),
56
59
  },
57
60
  anthropic: {
58
61
  id: "anthropic",
@@ -64,7 +67,11 @@ export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
64
67
  baseUrl: "https://api.anthropic.com/v1",
65
68
  auth: "x-api-key",
66
69
  capabilities: VISION,
67
- models: models("claude-opus-4-8", "claude-sonnet-4-6", "claude-haiku-4-5-20251001"),
70
+ models: models(
71
+ ["claude-opus-4-8", "Opus 4.8"],
72
+ ["claude-sonnet-4-6", "Sonnet 4.6"],
73
+ ["claude-haiku-4-5-20251001", "Haiku 4.5"],
74
+ ),
68
75
  },
69
76
  gemini: {
70
77
  id: "gemini",
@@ -75,7 +82,7 @@ export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
75
82
  baseUrl: "https://generativelanguage.googleapis.com/v1beta/models",
76
83
  auth: "query-key",
77
84
  capabilities: VISION_AUDIO,
78
- models: models("gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.0-flash"),
85
+ models: models(["gemini-2.5-flash", "2.5 Flash"], ["gemini-2.5-pro", "2.5 Pro"], ["gemini-2.0-flash", "2.0 Flash"]),
79
86
  },
80
87
  openrouter: {
81
88
  id: "openrouter",
@@ -98,7 +105,7 @@ export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
98
105
  requiresBaseUrl: false,
99
106
  auth: "none",
100
107
  capabilities: VISION,
101
- models: models("llama3", "llama3.1", "mistral", "qwen2.5"),
108
+ models: models(["llama3", "Llama 3"], ["llama3.1", "Llama 3.1"], ["mistral", "Mistral"], ["qwen2.5", "Qwen 2.5"]),
102
109
  },
103
110
  "azure-openai": {
104
111
  id: "azure-openai",
@@ -0,0 +1,13 @@
1
+ // Browser-safe: compact config formats written by the generator and expanded by the viewer.
2
+ export {
3
+ SITE_ICONS_KEY,
4
+ compactSiteIcons,
5
+ expandSiteIcons,
6
+ } from "./site-icons";
7
+ export type { CompactSiteIcons, SiteIconField, SiteIconSpec, SiteIconValue } from "./site-icons";
8
+ export {
9
+ ROUTE_DEFAULTS_KEY,
10
+ ROUTE_LIST_KEYS,
11
+ applyRouteDefaults,
12
+ factorRouteDefaults,
13
+ } from "./route-defaults";
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Shared route settings written once per config.
3
+ *
4
+ * Routes of a version config repeat the same presentation settings (title and
5
+ * description CSS, positions, visibility, margins, flags). `factorRouteDefaults`
6
+ * moves every setting that all routes share into `routeDefaults`, and
7
+ * `applyRouteDefaults` puts it back: `{ ...routeDefaults, ...route }`, so a value
8
+ * written on a route always wins.
9
+ */
10
+
11
+ type ConfigRecord = Record<string, unknown>;
12
+
13
+ export const ROUTE_DEFAULTS_KEY = "routeDefaults";
14
+
15
+ /** Every route list a config can carry (`routes` is the markdown alias). */
16
+ export const ROUTE_LIST_KEYS = [
17
+ "routes-md",
18
+ "routes-source-viewer",
19
+ "routes-html",
20
+ "routes-video",
21
+ "routes-audio",
22
+ "routes",
23
+ ] as const;
24
+
25
+ /** Per-route identity: never shared, even when two routes happen to agree. */
26
+ const ROUTE_IDENTITY_KEYS: ReadonlySet<string> = new Set(["id", "title", "description", "path", "url"]);
27
+
28
+ /** Fewer routes than this leave nothing worth sharing. */
29
+ const MIN_ROUTES_TO_FACTOR = 2;
30
+
31
+ function isPlainObject(value: unknown): value is ConfigRecord {
32
+ return typeof value === "object" && value !== null && !Array.isArray(value);
33
+ }
34
+
35
+ function routeLists(config: ConfigRecord): ConfigRecord[][] {
36
+ return ROUTE_LIST_KEYS.flatMap((key) => {
37
+ const list = config[key];
38
+ return Array.isArray(list) ? [list.filter(isPlainObject)] : [];
39
+ });
40
+ }
41
+
42
+ function sameValue(a: unknown, b: unknown): boolean {
43
+ return JSON.stringify(a) === JSON.stringify(b);
44
+ }
45
+
46
+ /** Settings present with the same value on every route. */
47
+ function sharedSettings(routes: ConfigRecord[]): ConfigRecord {
48
+ const [first, ...rest] = routes;
49
+ const shared: ConfigRecord = {};
50
+ for (const [key, value] of Object.entries(first)) {
51
+ if (ROUTE_IDENTITY_KEYS.has(key)) continue;
52
+ if (rest.every((route) => key in route && sameValue(route[key], value))) shared[key] = value;
53
+ }
54
+ return shared;
55
+ }
56
+
57
+ function mapRouteLists(config: ConfigRecord, mapRoute: (route: ConfigRecord) => ConfigRecord): ConfigRecord {
58
+ const out: ConfigRecord = { ...config };
59
+ for (const key of ROUTE_LIST_KEYS) {
60
+ const list = config[key];
61
+ if (Array.isArray(list)) out[key] = list.map((route) => (isPlainObject(route) ? mapRoute(route) : route));
62
+ }
63
+ return out;
64
+ }
65
+
66
+ /** Moves the settings every route shares into `routeDefaults` (placed before the first route list). */
67
+ export function factorRouteDefaults<T>(config: T): ConfigRecord | T {
68
+ if (!isPlainObject(config) || ROUTE_DEFAULTS_KEY in config) return config;
69
+ const routes = routeLists(config).flat();
70
+ if (routes.length < MIN_ROUTES_TO_FACTOR) return config;
71
+ const shared = sharedSettings(routes);
72
+ const sharedKeys = Object.keys(shared);
73
+ if (sharedKeys.length === 0) return config;
74
+
75
+ const stripped = mapRouteLists(config, (route) =>
76
+ Object.fromEntries(Object.entries(route).filter(([key]) => !sharedKeys.includes(key))),
77
+ );
78
+ const out: ConfigRecord = {};
79
+ for (const [key, value] of Object.entries(stripped)) {
80
+ if (!(ROUTE_DEFAULTS_KEY in out) && (ROUTE_LIST_KEYS as readonly string[]).includes(key)) out[ROUTE_DEFAULTS_KEY] = shared;
81
+ out[key] = value;
82
+ }
83
+ return out;
84
+ }
85
+
86
+ /** Applies `routeDefaults` under every route and drops the key; configs without it are returned as is. */
87
+ export function applyRouteDefaults<T>(config: T): ConfigRecord | T {
88
+ if (!isPlainObject(config)) return config;
89
+ const defaults = config[ROUTE_DEFAULTS_KEY];
90
+ if (!isPlainObject(defaults)) return config;
91
+ const applied = mapRouteLists(config, (route) => ({ ...defaults, ...route }));
92
+ delete applied[ROUTE_DEFAULTS_KEY];
93
+ return applied;
94
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Compact form of the `site` icon settings.
3
+ *
4
+ * Flat form (what the viewer reads): nine keys per icon, e.g.
5
+ * IconSearchReactIcones, IconSearchReactIconesTag, IconSearchReactIconesTagColorDark, …
6
+ * Compact form (what config.json stores): the values every icon shares once, and
7
+ * per icon only what differs:
8
+ * "icons": { "defaults": { "reactIcon": true, "size": "25px", … }, "Search": { "tag": "FiSearch" } }
9
+ *
10
+ * A field set to `null` in an icon entry means "this icon has no such key", so
11
+ * `expandSiteIcons(compactSiteIcons(site))` reproduces the flat site exactly.
12
+ */
13
+
14
+ type SiteRecord = Record<string, unknown>;
15
+
16
+ /** Compact field name -> suffix of the flat key (`Icon<Name><Suffix>`). */
17
+ const ICON_FIELD_SUFFIX = {
18
+ reactIcon: "ReactIcones",
19
+ tag: "ReactIconesTag",
20
+ colorDark: "ReactIconesTagColorDark",
21
+ colorLight: "ReactIconesTagColorLight",
22
+ size: "ReactIconesTagSize",
23
+ imgDark: "DarkImg",
24
+ imgLight: "LightImg",
25
+ imgWidth: "ImgWidth",
26
+ imgHeight: "ImgHeight",
27
+ } as const;
28
+
29
+ export type SiteIconField = keyof typeof ICON_FIELD_SUFFIX;
30
+ export type SiteIconValue = string | number | boolean | null;
31
+ export type SiteIconSpec = Partial<Record<SiteIconField, SiteIconValue>>;
32
+
33
+ export interface CompactSiteIcons {
34
+ defaults: SiteIconSpec;
35
+ [iconName: string]: SiteIconSpec;
36
+ }
37
+
38
+ export const SITE_ICONS_KEY = "icons";
39
+ const DEFAULTS_KEY = "defaults";
40
+ const ICON_KEY_PREFIX = "Icon";
41
+ /** A value becomes a shared default only when at least this many icons use it. */
42
+ const MIN_SHARED_COUNT = 2;
43
+ /** Fields that identify the icon: always written on the icon, never shared. */
44
+ const ICON_IDENTITY_FIELDS: ReadonlySet<SiteIconField> = new Set<SiteIconField>(["tag"]);
45
+
46
+ const FIELDS = Object.keys(ICON_FIELD_SUFFIX) as SiteIconField[];
47
+ /** Longest suffix first, so `ReactIconesTagColorDark` never matches as `ReactIcones`. */
48
+ const FIELDS_BY_SUFFIX_LENGTH = [...FIELDS].sort((a, b) => ICON_FIELD_SUFFIX[b].length - ICON_FIELD_SUFFIX[a].length);
49
+
50
+ function isPlainObject(value: unknown): value is SiteRecord {
51
+ return typeof value === "object" && value !== null && !Array.isArray(value);
52
+ }
53
+
54
+ function isIconValue(value: unknown): value is SiteIconValue {
55
+ return value === null || ["string", "number", "boolean"].includes(typeof value);
56
+ }
57
+
58
+ /** `IconSearchReactIconesTag` -> `{ name: "Search", field: "tag" }`; undefined for any other key. */
59
+ function parseIconKey(key: string): { name: string; field: SiteIconField } | undefined {
60
+ if (!key.startsWith(ICON_KEY_PREFIX)) return undefined;
61
+ const body = key.slice(ICON_KEY_PREFIX.length);
62
+ const field = FIELDS_BY_SUFFIX_LENGTH.find((candidate) => body.endsWith(ICON_FIELD_SUFFIX[candidate]));
63
+ if (!field) return undefined;
64
+ const name = body.slice(0, -ICON_FIELD_SUFFIX[field].length);
65
+ return name ? { name, field } : undefined;
66
+ }
67
+
68
+ function iconKey(name: string, field: SiteIconField): string {
69
+ return `${ICON_KEY_PREFIX}${name}${ICON_FIELD_SUFFIX[field]}`;
70
+ }
71
+
72
+ /** Most frequent value shared by at least two icons; the first one seen wins a tie. */
73
+ function mostCommonValue(values: SiteIconValue[]): SiteIconValue | undefined {
74
+ const counts = new Map<string, { value: SiteIconValue; count: number }>();
75
+ for (const value of values) {
76
+ const key = JSON.stringify(value);
77
+ const entry = counts.get(key) ?? { value, count: 0 };
78
+ entry.count += 1;
79
+ counts.set(key, entry);
80
+ }
81
+ let best: { value: SiteIconValue; count: number } | undefined;
82
+ for (const entry of counts.values()) {
83
+ if (!best || entry.count > best.count) best = entry;
84
+ }
85
+ return best && best.count >= MIN_SHARED_COUNT ? best.value : undefined;
86
+ }
87
+
88
+ function collectIcons(site: SiteRecord): Map<string, SiteIconSpec> {
89
+ const icons = new Map<string, SiteIconSpec>();
90
+ for (const [key, value] of Object.entries(site)) {
91
+ const parsed = parseIconKey(key);
92
+ if (!parsed || !isIconValue(value)) continue;
93
+ const spec = icons.get(parsed.name) ?? {};
94
+ spec[parsed.field] = value;
95
+ icons.set(parsed.name, spec);
96
+ }
97
+ return icons;
98
+ }
99
+
100
+ function sharedDefaults(icons: Map<string, SiteIconSpec>): SiteIconSpec {
101
+ const defaults: SiteIconSpec = {};
102
+ for (const field of FIELDS) {
103
+ if (ICON_IDENTITY_FIELDS.has(field)) continue;
104
+ const values = [...icons.values()].flatMap((spec) => (field in spec ? [spec[field] as SiteIconValue] : []));
105
+ const common = mostCommonValue(values);
106
+ if (common !== undefined) defaults[field] = common;
107
+ }
108
+ return defaults;
109
+ }
110
+
111
+ function iconDifferences(spec: SiteIconSpec, defaults: SiteIconSpec): SiteIconSpec {
112
+ const entry: SiteIconSpec = {};
113
+ for (const field of FIELDS) {
114
+ const hasOwn = field in spec;
115
+ if (!hasOwn && field in defaults) entry[field] = null;
116
+ else if (hasOwn && spec[field] !== defaults[field]) entry[field] = spec[field];
117
+ }
118
+ return entry;
119
+ }
120
+
121
+ /** Replaces the flat `Icon*` keys with one `icons` object (placed where the first icon key was). */
122
+ export function compactSiteIcons<T>(site: T): SiteRecord | T {
123
+ if (!isPlainObject(site)) return site;
124
+ const icons = collectIcons(site);
125
+ if (icons.size === 0) return site;
126
+ const defaults = sharedDefaults(icons);
127
+ const compact: CompactSiteIcons = { defaults };
128
+ for (const [name, spec] of icons) compact[name] = iconDifferences(spec, defaults);
129
+
130
+ const out: SiteRecord = {};
131
+ for (const [key, value] of Object.entries(site)) {
132
+ if (parseIconKey(key) && isIconValue(value)) {
133
+ if (!(SITE_ICONS_KEY in out)) out[SITE_ICONS_KEY] = compact;
134
+ continue;
135
+ }
136
+ out[key] = value;
137
+ }
138
+ return out;
139
+ }
140
+
141
+ function expandIcon(name: string, entry: SiteIconSpec, defaults: SiteIconSpec): SiteRecord {
142
+ const flat: SiteRecord = {};
143
+ for (const field of FIELDS) {
144
+ const value = field in entry ? entry[field] : defaults[field];
145
+ if (value !== null && value !== undefined) flat[iconKey(name, field)] = value;
146
+ }
147
+ return flat;
148
+ }
149
+
150
+ /**
151
+ * Turns `site.icons` back into the flat `Icon*` keys the viewer reads. Flat keys
152
+ * already present in the site win over the compact form.
153
+ */
154
+ export function expandSiteIcons<T>(site: T): SiteRecord | T {
155
+ if (!isPlainObject(site)) return site;
156
+ const compact = site[SITE_ICONS_KEY];
157
+ if (!isPlainObject(compact)) return site;
158
+ const defaults = isPlainObject(compact[DEFAULTS_KEY]) ? (compact[DEFAULTS_KEY] as SiteIconSpec) : {};
159
+
160
+ const expanded: SiteRecord = {};
161
+ for (const [name, entry] of Object.entries(compact)) {
162
+ if (name === DEFAULTS_KEY || !isPlainObject(entry)) continue;
163
+ Object.assign(expanded, expandIcon(name, entry as SiteIconSpec, defaults));
164
+ }
165
+
166
+ const out: SiteRecord = {};
167
+ for (const [key, value] of Object.entries(site)) {
168
+ if (key !== SITE_ICONS_KEY) {
169
+ out[key] = value;
170
+ continue;
171
+ }
172
+ for (const [flatKey, flatValue] of Object.entries(expanded)) {
173
+ if (!(flatKey in site)) out[flatKey] = flatValue;
174
+ }
175
+ }
176
+ return out;
177
+ }
package/src/i18n/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export {
2
2
  DEFAULT_LANGS_DIR,
3
- DEFAULT_LANGS_MANIFEST_PATH,
4
3
  LANGS_DIRNAME,
5
- LANGS_MANIFEST_FILENAME,
6
4
  applyLanguageBundles,
7
5
  buildLanguageToggles,
8
6
  filterEnabledLanguages,
@@ -14,7 +12,6 @@ export {
14
12
  loadConfigLanguageBundles,
15
13
  loadLanguageBundles,
16
14
  parseLanguageBundle,
17
- parseLanguageManifest,
18
15
  parseLanguageToggles,
19
16
  resolveBundleLanguages,
20
17
  splitLanguageBundles,
@@ -26,7 +23,6 @@ export type {
26
23
  JsonReader,
27
24
  LanguageBundle,
28
25
  LanguageBundleMap,
29
- LanguageManifest,
30
26
  LanguageStrings,
31
27
  LanguageToggles,
32
28
  LoadLanguageBundlesOptions,
@@ -10,20 +10,13 @@
10
10
  * language selector, even when its docs exist. A language the map does not
11
11
  * mention stays enabled, so old configs keep every content language they ship.
12
12
  *
13
- * Historically the strings lived inline in `config.json` (`site.langmenu` keyed
14
- * by language and `translations.<section>.<key>` keyed by language), and
15
- * release 1.1.68 listed the languages in a separate `gitpagedocs/langs.json`
16
- * manifest. Both still load: `applyLanguageBundles` folds the bundles back into
17
- * the inline shape, so every consumer keeps reading `site.langmenu` /
18
- * `translations` unchanged, and the manifest is read only when `config.json`
19
- * carries no `site.languages`. Bundles win over inline strings.
13
+ * `applyLanguageBundles` folds the loaded bundles into `site.langmenu` (keyed
14
+ * by language) and `translations.<section>.<key>` (keyed by language), the
15
+ * shape every consumer reads.
20
16
  */
21
17
 
22
18
  export const LANGS_DIRNAME = "langs";
23
19
  export const DEFAULT_LANGS_DIR = `gitpagedocs/${LANGS_DIRNAME}`;
24
- /** Legacy (1.1.68) manifest; superseded by `site.languages` in config.json. */
25
- export const LANGS_MANIFEST_FILENAME = "langs.json";
26
- export const DEFAULT_LANGS_MANIFEST_PATH = `gitpagedocs/${LANGS_MANIFEST_FILENAME}`;
27
20
 
28
21
  /** Language codes become file names, so they are kept to a safe alphabet. */
29
22
  const LANGUAGE_CODE_PATTERN = /^[A-Za-z0-9]{2,8}(?:[-_][A-Za-z0-9]{1,8})?$/;
@@ -34,11 +27,6 @@ export type TranslationSections = Record<string, LanguageStrings>;
34
27
  /** `site.languages`: language code → enabled flag, in menu order. */
35
28
  export type LanguageToggles = Record<string, boolean>;
36
29
 
37
- /** Legacy `gitpagedocs/langs.json` shape. */
38
- export interface LanguageManifest {
39
- languages: string[];
40
- }
41
-
42
30
  export interface LanguageBundle {
43
31
  langmenu?: LanguageStrings;
44
32
  translations?: TranslationSections;
@@ -47,7 +35,7 @@ export interface LanguageBundle {
47
35
  export type LanguageBundleMap = Record<string, LanguageBundle>;
48
36
 
49
37
  /**
50
- * Legacy inline shapes: `langmenu[lang][key]` and `translations[section][key][lang]`.
38
+ * Folded shapes: `langmenu[lang][key]` and `translations[section][key][lang]`.
51
39
  * Sections and keys may be absent, matching the optional fields of typed configs.
52
40
  */
53
41
  export type InlineLangMenu = Record<string, LanguageStrings>;
@@ -136,18 +124,12 @@ export function getSiteLanguageToggles(config: LocalizableConfig): LanguageToggl
136
124
  return parseLanguageToggles(config.site?.languages);
137
125
  }
138
126
 
139
- /** The bundles a config asks for: its enabled toggles, or null when it has none (legacy). */
127
+ /** The bundles a config asks for: its enabled toggles, or null when it has none. */
140
128
  export function resolveBundleLanguages(config: LocalizableConfig): string[] | null {
141
129
  const toggles = getSiteLanguageToggles(config);
142
130
  return toggles ? getEnabledLanguages(toggles) : null;
143
131
  }
144
132
 
145
- export function parseLanguageManifest(raw: unknown): LanguageManifest | null {
146
- if (!isPlainObject(raw) || !Array.isArray(raw.languages)) return null;
147
- const languages = Array.from(new Set(raw.languages.filter(isLanguageCode)));
148
- return languages.length > 0 ? { languages } : null;
149
- }
150
-
151
133
  function parseTranslationSections(raw: unknown): TranslationSections | undefined {
152
134
  if (!isPlainObject(raw)) return undefined;
153
135
  const sections: TranslationSections = {};
@@ -167,29 +149,21 @@ export function parseLanguageBundle(raw: unknown): LanguageBundle | null {
167
149
  }
168
150
 
169
151
  export interface LoadLanguageBundlesOptions {
170
- /** Languages to load (the enabled `site.languages`). Without it the legacy manifest is consulted. */
152
+ /** Languages to load (the enabled `site.languages`). */
171
153
  languages?: readonly string[];
172
- manifestPath?: string;
173
154
  langsDir?: string;
174
155
  }
175
156
 
176
- async function readLegacyManifestLanguages(readJson: JsonReader, manifestPath: string): Promise<string[] | null> {
177
- const manifest = parseLanguageManifest(await readJson(manifestPath));
178
- return manifest ? manifest.languages : null;
179
- }
180
-
181
157
  /**
182
158
  * Loads one bundle per requested language. Resolves null when nothing is
183
- * requested (legacy inline config without a manifest); bundles that are
184
- * missing or malformed are skipped so one broken file never takes the other
185
- * languages down.
159
+ * requested; bundles that are missing or malformed are skipped so one broken
160
+ * file never takes the other languages down.
186
161
  */
187
162
  export async function loadLanguageBundles(
188
163
  readJson: JsonReader,
189
164
  options: LoadLanguageBundlesOptions = {},
190
165
  ): Promise<LanguageBundleMap | null> {
191
- const languages =
192
- options.languages ?? (await readLegacyManifestLanguages(readJson, options.manifestPath ?? DEFAULT_LANGS_MANIFEST_PATH));
166
+ const { languages } = options;
193
167
  if (!languages || languages.length === 0) return null;
194
168
 
195
169
  const entries = await Promise.all(
@@ -206,7 +180,7 @@ export async function loadLanguageBundles(
206
180
  return Object.keys(bundles).length > 0 ? bundles : null;
207
181
  }
208
182
 
209
- /** Loads the bundles `config.json` enables through `site.languages` (legacy manifest as fallback). */
183
+ /** Loads the bundles `config.json` enables through `site.languages`. */
210
184
  export function loadConfigLanguageBundles(
211
185
  config: LocalizableConfig,
212
186
  readJson: JsonReader,
package/src/index.ts CHANGED
@@ -21,6 +21,9 @@ export * from "./i18n";
21
21
  // Phase 5 — shared AI system.
22
22
  export * from "./ai";
23
23
 
24
+ // Compact config formats (icons + route defaults).
25
+ export * from "./config-format";
26
+
24
27
  // Phase 7 — filesystem + documentation services.
25
28
  export * from "./filesystem";
26
29
  export * from "./documentation";
@@ -4,5 +4,3 @@ export { SessionPasswordGate } from "./password-gate";
4
4
  export type { PasswordPrompt, SessionPasswordGateOptions } from "./password-gate";
5
5
  export { FileVaultStorage } from "./file-vault-storage";
6
6
  export { WebStorageVaultStorage } from "./web-storage-vault-storage";
7
- export { migratePlaintextKey } from "./migrate-plaintext-key";
8
- export type { PlaintextMigrationInput, PlaintextMigrationResult } from "./migrate-plaintext-key";
@@ -1,9 +1,7 @@
1
- // Browser-safe security entry: encrypted vault + web storage + migration.
1
+ // Browser-safe security entry: encrypted vault + web storage.
2
2
  // Excludes FileVaultStorage (node:fs).
3
3
  export { EncryptedCredentialVault } from "./credential-vault";
4
4
  export type { VaultStorage } from "./credential-vault";
5
5
  export { SessionPasswordGate } from "./password-gate";
6
6
  export type { PasswordPrompt, SessionPasswordGateOptions } from "./password-gate";
7
7
  export { WebStorageVaultStorage } from "./web-storage-vault-storage";
8
- export { migratePlaintextKey } from "./migrate-plaintext-key";
9
- export type { PlaintextMigrationInput, PlaintextMigrationResult } from "./migrate-plaintext-key";
@@ -1,38 +0,0 @@
1
- import type { CredentialVault } from "../ports/security";
2
-
3
- export interface PlaintextMigrationInput {
4
- readonly vault: CredentialVault;
5
- readonly password: string;
6
- /** Catalog provider id the key belongs to (e.g. "anthropic"). */
7
- readonly providerId: string;
8
- /** The legacy plaintext secret to import. */
9
- readonly plaintextKey: string;
10
- /** Clears the legacy plaintext store once the key is sealed. */
11
- readonly clearPlaintext: () => void | Promise<void>;
12
- }
13
-
14
- export interface PlaintextMigrationResult {
15
- readonly migrated: boolean;
16
- readonly initializedVault: boolean;
17
- }
18
-
19
- /**
20
- * Move a legacy plaintext API key into the encrypted vault, then wipe the
21
- * plaintext source. Initializes the vault on first run. Idempotent: a blank key
22
- * is a no-op.
23
- */
24
- export async function migratePlaintextKey(
25
- input: PlaintextMigrationInput,
26
- ): Promise<PlaintextMigrationResult> {
27
- if (!input.plaintextKey) {
28
- return { migrated: false, initializedVault: false };
29
- }
30
- let initializedVault = false;
31
- if (!(await input.vault.isInitialized())) {
32
- await input.vault.initialize(input.password);
33
- initializedVault = true;
34
- }
35
- await input.vault.setCredential(input.password, input.providerId, input.plaintextKey);
36
- await input.clearPlaintext();
37
- return { migrated: true, initializedVault };
38
- }