@gitpagedocs/tools 1.1.61 → 1.1.63

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.
Files changed (58) hide show
  1. package/README.md +33 -33
  2. package/package.json +1 -1
  3. package/src/ai/bootstrap.ts +50 -50
  4. package/src/ai/catalog.ts +188 -188
  5. package/src/ai/factory.ts +14 -14
  6. package/src/ai/http/streaming.ts +60 -60
  7. package/src/ai/index.ts +27 -27
  8. package/src/ai/legacy-adapter.ts +33 -33
  9. package/src/ai/model-registry.ts +13 -13
  10. package/src/ai/providers/anthropic-provider.ts +83 -83
  11. package/src/ai/providers/cohere-provider.ts +66 -66
  12. package/src/ai/providers/gemini-provider.ts +84 -84
  13. package/src/ai/providers/ollama-provider.ts +69 -69
  14. package/src/ai/providers/openai-compatible-provider.ts +75 -75
  15. package/src/ai/providers/shared.ts +72 -72
  16. package/src/ai/registry.ts +29 -29
  17. package/src/cache/file-cache.ts +86 -86
  18. package/src/cache/index.ts +9 -9
  19. package/src/cache/memory-cache.ts +47 -47
  20. package/src/cache/web-storage-cache.ts +91 -91
  21. package/src/config/config-loader.ts +59 -59
  22. package/src/config/index.ts +1 -1
  23. package/src/constants/config.ts +8 -8
  24. package/src/constants/index.ts +1 -1
  25. package/src/crypto/doc-access.ts +62 -62
  26. package/src/crypto/index.ts +4 -4
  27. package/src/crypto/node-crypto-service.ts +87 -87
  28. package/src/crypto/web-crypto-service.ts +102 -102
  29. package/src/crypto/web.ts +4 -4
  30. package/src/documentation/doc-generator.ts +74 -74
  31. package/src/documentation/doc-updater.ts +47 -47
  32. package/src/documentation/index.ts +18 -18
  33. package/src/documentation/marker-patcher.ts +33 -33
  34. package/src/documentation/sections.ts +84 -84
  35. package/src/errors/app-error.ts +84 -84
  36. package/src/errors/index.ts +1 -1
  37. package/src/filesystem/file-service.ts +121 -121
  38. package/src/filesystem/index.ts +2 -2
  39. package/src/index.ts +25 -25
  40. package/src/logger/index.ts +2 -2
  41. package/src/logger/logger.ts +73 -73
  42. package/src/logger/redaction.ts +43 -43
  43. package/src/platform/index.ts +1 -1
  44. package/src/platform/user-config-dir.ts +48 -48
  45. package/src/ports/ai.ts +109 -109
  46. package/src/ports/cache.ts +16 -16
  47. package/src/ports/config.ts +21 -21
  48. package/src/ports/crypto.ts +33 -33
  49. package/src/ports/index.ts +15 -15
  50. package/src/ports/logger.ts +23 -23
  51. package/src/ports/security.ts +42 -42
  52. package/src/security/credential-vault.ts +117 -117
  53. package/src/security/file-vault-storage.ts +25 -25
  54. package/src/security/index.ts +8 -8
  55. package/src/security/migrate-plaintext-key.ts +38 -38
  56. package/src/security/password-gate.ts +62 -62
  57. package/src/security/web-storage-vault-storage.ts +23 -23
  58. package/src/security/web.ts +9 -9
@@ -1,43 +1,43 @@
1
- /**
2
- * Secret redaction. Applied to every log record before it reaches a sink so
3
- * API keys and other credentials can never appear in logs.
4
- */
5
- const SENSITIVE_KEY_PATTERN = /(api[_-]?key|secret|token|password|passwd|authorization|bearer|x-api-key)/i;
6
-
7
- /** Token-like values: long opaque strings, optionally with a provider prefix. */
8
- const TOKEN_VALUE_PATTERN = /\b((?:sk|pk|gsk|xai|or|hf|ghp|gho|github_pat|AIza)[-_][A-Za-z0-9-_]{8,}|[A-Za-z0-9-_]{32,})\b/g;
9
-
10
- export const REDACTED = "[REDACTED]";
11
-
12
- /** Mask a string value, keeping a short, non-reversible hint. */
13
- function maskValue(value: string): string {
14
- if (value.length <= 8) return REDACTED;
15
- return `${value.slice(0, 3)}…${value.slice(-4)}`;
16
- }
17
-
18
- function redactString(input: string): string {
19
- return input.replace(TOKEN_VALUE_PATTERN, (match) => maskValue(match));
20
- }
21
-
22
- /** Recursively redact a value: sensitive keys are masked, strings scrubbed. */
23
- export function redact(value: unknown, keyHint?: string): unknown {
24
- if (typeof value === "string") {
25
- if (keyHint && SENSITIVE_KEY_PATTERN.test(keyHint)) return maskValue(value);
26
- return redactString(value);
27
- }
28
- if (Array.isArray(value)) {
29
- return value.map((item) => redact(item));
30
- }
31
- if (value && typeof value === "object") {
32
- const out: Record<string, unknown> = {};
33
- for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
34
- out[k] = SENSITIVE_KEY_PATTERN.test(k) && typeof v === "string" ? maskValue(v) : redact(v, k);
35
- }
36
- return out;
37
- }
38
- return value;
39
- }
40
-
41
- export function redactFields(fields: Record<string, unknown>): Record<string, unknown> {
42
- return redact(fields) as Record<string, unknown>;
43
- }
1
+ /**
2
+ * Secret redaction. Applied to every log record before it reaches a sink so
3
+ * API keys and other credentials can never appear in logs.
4
+ */
5
+ const SENSITIVE_KEY_PATTERN = /(api[_-]?key|secret|token|password|passwd|authorization|bearer|x-api-key)/i;
6
+
7
+ /** Token-like values: long opaque strings, optionally with a provider prefix. */
8
+ const TOKEN_VALUE_PATTERN = /\b((?:sk|pk|gsk|xai|or|hf|ghp|gho|github_pat|AIza)[-_][A-Za-z0-9-_]{8,}|[A-Za-z0-9-_]{32,})\b/g;
9
+
10
+ export const REDACTED = "[REDACTED]";
11
+
12
+ /** Mask a string value, keeping a short, non-reversible hint. */
13
+ function maskValue(value: string): string {
14
+ if (value.length <= 8) return REDACTED;
15
+ return `${value.slice(0, 3)}…${value.slice(-4)}`;
16
+ }
17
+
18
+ function redactString(input: string): string {
19
+ return input.replace(TOKEN_VALUE_PATTERN, (match) => maskValue(match));
20
+ }
21
+
22
+ /** Recursively redact a value: sensitive keys are masked, strings scrubbed. */
23
+ export function redact(value: unknown, keyHint?: string): unknown {
24
+ if (typeof value === "string") {
25
+ if (keyHint && SENSITIVE_KEY_PATTERN.test(keyHint)) return maskValue(value);
26
+ return redactString(value);
27
+ }
28
+ if (Array.isArray(value)) {
29
+ return value.map((item) => redact(item));
30
+ }
31
+ if (value && typeof value === "object") {
32
+ const out: Record<string, unknown> = {};
33
+ for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
34
+ out[k] = SENSITIVE_KEY_PATTERN.test(k) && typeof v === "string" ? maskValue(v) : redact(v, k);
35
+ }
36
+ return out;
37
+ }
38
+ return value;
39
+ }
40
+
41
+ export function redactFields(fields: Record<string, unknown>): Record<string, unknown> {
42
+ return redact(fields) as Record<string, unknown>;
43
+ }
@@ -1 +1 @@
1
- export * from "./user-config-dir";
1
+ export * from "./user-config-dir";
@@ -1,48 +1,48 @@
1
- import os from "node:os";
2
- import path from "node:path";
3
-
4
- /** Environment variable that overrides the resolved user config directory. */
5
- export const USER_CONFIG_DIR_ENV_VAR = "GITPAGEDOCS_CONFIG_DIR";
6
-
7
- /** Directory name that holds gitpagedocs user-level configuration. */
8
- export const USER_CONFIG_APP_DIR = "gitpagedocs";
9
-
10
- export interface UserConfigDirContext {
11
- /** Platform id (defaults to `process.platform`). */
12
- platform?: NodeJS.Platform;
13
- /** Environment map (defaults to `process.env`). */
14
- env?: NodeJS.ProcessEnv;
15
- /** User home directory (defaults to `os.homedir()`). */
16
- homeDir?: string;
17
- }
18
-
19
- /**
20
- * Resolve the per-user gitpagedocs configuration directory following each
21
- * platform's convention:
22
- *
23
- * - Windows: `%APPDATA%\gitpagedocs`
24
- * - macOS: `~/Library/Application Support/gitpagedocs`
25
- * - Linux and others: `$XDG_CONFIG_HOME/gitpagedocs` or `~/.config/gitpagedocs`
26
- *
27
- * The `GITPAGEDOCS_CONFIG_DIR` environment variable overrides all of the above.
28
- */
29
- export function resolveUserConfigDir(context: UserConfigDirContext = {}): string {
30
- const env = context.env ?? process.env;
31
- const override = env[USER_CONFIG_DIR_ENV_VAR]?.trim();
32
- if (override) return path.resolve(override);
33
-
34
- const platform = context.platform ?? process.platform;
35
- const homeDir = context.homeDir ?? os.homedir();
36
-
37
- if (platform === "win32") {
38
- const appData = env.APPDATA?.trim() || path.join(homeDir, "AppData", "Roaming");
39
- return path.join(appData, USER_CONFIG_APP_DIR);
40
- }
41
-
42
- if (platform === "darwin") {
43
- return path.join(homeDir, "Library", "Application Support", USER_CONFIG_APP_DIR);
44
- }
45
-
46
- const configHome = env.XDG_CONFIG_HOME?.trim() || path.join(homeDir, ".config");
47
- return path.join(configHome, USER_CONFIG_APP_DIR);
48
- }
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+
4
+ /** Environment variable that overrides the resolved user config directory. */
5
+ export const USER_CONFIG_DIR_ENV_VAR = "GITPAGEDOCS_CONFIG_DIR";
6
+
7
+ /** Directory name that holds gitpagedocs user-level configuration. */
8
+ export const USER_CONFIG_APP_DIR = "gitpagedocs";
9
+
10
+ export interface UserConfigDirContext {
11
+ /** Platform id (defaults to `process.platform`). */
12
+ platform?: NodeJS.Platform;
13
+ /** Environment map (defaults to `process.env`). */
14
+ env?: NodeJS.ProcessEnv;
15
+ /** User home directory (defaults to `os.homedir()`). */
16
+ homeDir?: string;
17
+ }
18
+
19
+ /**
20
+ * Resolve the per-user gitpagedocs configuration directory following each
21
+ * platform's convention:
22
+ *
23
+ * - Windows: `%APPDATA%\gitpagedocs`
24
+ * - macOS: `~/Library/Application Support/gitpagedocs`
25
+ * - Linux and others: `$XDG_CONFIG_HOME/gitpagedocs` or `~/.config/gitpagedocs`
26
+ *
27
+ * The `GITPAGEDOCS_CONFIG_DIR` environment variable overrides all of the above.
28
+ */
29
+ export function resolveUserConfigDir(context: UserConfigDirContext = {}): string {
30
+ const env = context.env ?? process.env;
31
+ const override = env[USER_CONFIG_DIR_ENV_VAR]?.trim();
32
+ if (override) return path.resolve(override);
33
+
34
+ const platform = context.platform ?? process.platform;
35
+ const homeDir = context.homeDir ?? os.homedir();
36
+
37
+ if (platform === "win32") {
38
+ const appData = env.APPDATA?.trim() || path.join(homeDir, "AppData", "Roaming");
39
+ return path.join(appData, USER_CONFIG_APP_DIR);
40
+ }
41
+
42
+ if (platform === "darwin") {
43
+ return path.join(homeDir, "Library", "Application Support", USER_CONFIG_APP_DIR);
44
+ }
45
+
46
+ const configHome = env.XDG_CONFIG_HOME?.trim() || path.join(homeDir, ".config");
47
+ return path.join(configHome, USER_CONFIG_APP_DIR);
48
+ }
package/src/ports/ai.ts CHANGED
@@ -1,109 +1,109 @@
1
- /**
2
- * AI ports (Strategy + Registry + Factory). Implemented in Phase 5 in
3
- * tools/src/ai, unifying the current browser (src/features/ask-ai) and CLI
4
- * (src/cli/infrastructure/llm) provider implementations behind one contract.
5
- */
6
- export type AiProviderId =
7
- | "openai"
8
- | "anthropic"
9
- | "gemini"
10
- | "openrouter"
11
- | "ollama"
12
- | "azure-openai"
13
- | "mistral"
14
- | "deepseek"
15
- | "cohere"
16
- | "groq"
17
- | "xai"
18
- | "together"
19
- | "fireworks"
20
- | "perplexity";
21
-
22
- export type AiRole = "system" | "user" | "assistant";
23
-
24
- export interface AiAttachment {
25
- readonly kind: "image" | "audio";
26
- readonly mimeType: string;
27
- /** Base64-encoded data. */
28
- readonly data: string;
29
- }
30
-
31
- export interface AiMessage {
32
- readonly role: AiRole;
33
- readonly content: string;
34
- readonly attachments?: readonly AiAttachment[];
35
- }
36
-
37
- export interface ModelDescriptor {
38
- readonly id: string;
39
- readonly label?: string;
40
- readonly contextWindow?: number;
41
- readonly supportsStreaming?: boolean;
42
- readonly supportsVision?: boolean;
43
- readonly supportsAudio?: boolean;
44
- }
45
-
46
- export interface ProviderConfig {
47
- readonly providerId: AiProviderId;
48
- readonly model: string;
49
- readonly apiKey?: string;
50
- /** For self-hosted/proxy providers (e.g. Ollama, Azure). */
51
- readonly baseUrl?: string;
52
- readonly extraHeaders?: Readonly<Record<string, string>>;
53
- }
54
-
55
- export interface GenerateRequest {
56
- readonly messages: readonly AiMessage[];
57
- readonly system?: string;
58
- readonly temperature?: number;
59
- readonly maxTokens?: number;
60
- readonly signal?: AbortSignal;
61
- }
62
-
63
- export interface GenerateResponse {
64
- readonly text: string;
65
- readonly model: string;
66
- readonly finishReason?: string;
67
- }
68
-
69
- /** Streaming responses surface as an async iterable of text deltas. */
70
- export type StreamResponse = AsyncIterable<string>;
71
-
72
- export interface ProviderCapabilities {
73
- readonly streaming: boolean;
74
- readonly vision: boolean;
75
- readonly audio: boolean;
76
- }
77
-
78
- /** A single provider strategy. */
79
- export interface AIProvider {
80
- readonly id: AiProviderId;
81
- readonly capabilities: ProviderCapabilities;
82
- generate(request: GenerateRequest, config: ProviderConfig): Promise<GenerateResponse>;
83
- stream(request: GenerateRequest, config: ProviderConfig): StreamResponse;
84
- }
85
-
86
- /** Provider metadata + factory registration (Registry pattern). */
87
- export interface ProviderRegistration {
88
- readonly id: AiProviderId;
89
- readonly label: string;
90
- readonly defaultModel: string;
91
- readonly capabilities: ProviderCapabilities;
92
- create(): AIProvider;
93
- }
94
-
95
- export interface ProviderRegistry {
96
- register(registration: ProviderRegistration): void;
97
- has(id: AiProviderId): boolean;
98
- get(id: AiProviderId): ProviderRegistration | undefined;
99
- list(): readonly ProviderRegistration[];
100
- }
101
-
102
- export interface ProviderFactory {
103
- create(id: AiProviderId): AIProvider;
104
- }
105
-
106
- export interface ModelRegistry {
107
- list(providerId: AiProviderId): readonly ModelDescriptor[];
108
- defaultModel(providerId: AiProviderId): string | undefined;
109
- }
1
+ /**
2
+ * AI ports (Strategy + Registry + Factory). Implemented in Phase 5 in
3
+ * tools/src/ai, unifying the current browser (src/features/ask-ai) and CLI
4
+ * (src/cli/infrastructure/llm) provider implementations behind one contract.
5
+ */
6
+ export type AiProviderId =
7
+ | "openai"
8
+ | "anthropic"
9
+ | "gemini"
10
+ | "openrouter"
11
+ | "ollama"
12
+ | "azure-openai"
13
+ | "mistral"
14
+ | "deepseek"
15
+ | "cohere"
16
+ | "groq"
17
+ | "xai"
18
+ | "together"
19
+ | "fireworks"
20
+ | "perplexity";
21
+
22
+ export type AiRole = "system" | "user" | "assistant";
23
+
24
+ export interface AiAttachment {
25
+ readonly kind: "image" | "audio";
26
+ readonly mimeType: string;
27
+ /** Base64-encoded data. */
28
+ readonly data: string;
29
+ }
30
+
31
+ export interface AiMessage {
32
+ readonly role: AiRole;
33
+ readonly content: string;
34
+ readonly attachments?: readonly AiAttachment[];
35
+ }
36
+
37
+ export interface ModelDescriptor {
38
+ readonly id: string;
39
+ readonly label?: string;
40
+ readonly contextWindow?: number;
41
+ readonly supportsStreaming?: boolean;
42
+ readonly supportsVision?: boolean;
43
+ readonly supportsAudio?: boolean;
44
+ }
45
+
46
+ export interface ProviderConfig {
47
+ readonly providerId: AiProviderId;
48
+ readonly model: string;
49
+ readonly apiKey?: string;
50
+ /** For self-hosted/proxy providers (e.g. Ollama, Azure). */
51
+ readonly baseUrl?: string;
52
+ readonly extraHeaders?: Readonly<Record<string, string>>;
53
+ }
54
+
55
+ export interface GenerateRequest {
56
+ readonly messages: readonly AiMessage[];
57
+ readonly system?: string;
58
+ readonly temperature?: number;
59
+ readonly maxTokens?: number;
60
+ readonly signal?: AbortSignal;
61
+ }
62
+
63
+ export interface GenerateResponse {
64
+ readonly text: string;
65
+ readonly model: string;
66
+ readonly finishReason?: string;
67
+ }
68
+
69
+ /** Streaming responses surface as an async iterable of text deltas. */
70
+ export type StreamResponse = AsyncIterable<string>;
71
+
72
+ export interface ProviderCapabilities {
73
+ readonly streaming: boolean;
74
+ readonly vision: boolean;
75
+ readonly audio: boolean;
76
+ }
77
+
78
+ /** A single provider strategy. */
79
+ export interface AIProvider {
80
+ readonly id: AiProviderId;
81
+ readonly capabilities: ProviderCapabilities;
82
+ generate(request: GenerateRequest, config: ProviderConfig): Promise<GenerateResponse>;
83
+ stream(request: GenerateRequest, config: ProviderConfig): StreamResponse;
84
+ }
85
+
86
+ /** Provider metadata + factory registration (Registry pattern). */
87
+ export interface ProviderRegistration {
88
+ readonly id: AiProviderId;
89
+ readonly label: string;
90
+ readonly defaultModel: string;
91
+ readonly capabilities: ProviderCapabilities;
92
+ create(): AIProvider;
93
+ }
94
+
95
+ export interface ProviderRegistry {
96
+ register(registration: ProviderRegistration): void;
97
+ has(id: AiProviderId): boolean;
98
+ get(id: AiProviderId): ProviderRegistration | undefined;
99
+ list(): readonly ProviderRegistration[];
100
+ }
101
+
102
+ export interface ProviderFactory {
103
+ create(id: AiProviderId): AIProvider;
104
+ }
105
+
106
+ export interface ModelRegistry {
107
+ list(providerId: AiProviderId): readonly ModelDescriptor[];
108
+ defaultModel(providerId: AiProviderId): string | undefined;
109
+ }
@@ -1,16 +1,16 @@
1
- /**
2
- * Cache port (Strategy). Implemented in Phase 4 by MemoryCache, FileCache,
3
- * LocalStorageCache and SessionStorageCache.
4
- */
5
- export interface CacheEntryOptions {
6
- /** Time-to-live in milliseconds. Omitted = no expiry. */
7
- readonly ttlMs?: number;
8
- }
9
-
10
- export interface Cache<TValue = unknown> {
11
- get(key: string): Promise<TValue | undefined>;
12
- set(key: string, value: TValue, options?: CacheEntryOptions): Promise<void>;
13
- has(key: string): Promise<boolean>;
14
- delete(key: string): Promise<void>;
15
- clear(): Promise<void>;
16
- }
1
+ /**
2
+ * Cache port (Strategy). Implemented in Phase 4 by MemoryCache, FileCache,
3
+ * LocalStorageCache and SessionStorageCache.
4
+ */
5
+ export interface CacheEntryOptions {
6
+ /** Time-to-live in milliseconds. Omitted = no expiry. */
7
+ readonly ttlMs?: number;
8
+ }
9
+
10
+ export interface Cache<TValue = unknown> {
11
+ get(key: string): Promise<TValue | undefined>;
12
+ set(key: string, value: TValue, options?: CacheEntryOptions): Promise<void>;
13
+ has(key: string): Promise<boolean>;
14
+ delete(key: string): Promise<void>;
15
+ clear(): Promise<void>;
16
+ }
@@ -1,21 +1,21 @@
1
- /**
2
- * Config-loading port. Implemented in Phase 4 by relocating the shared loader
3
- * logic currently in src/entities/docs/api/io/config-loader.ts. Must preserve
4
- * the legacy CONFIG_EXTENSIONS = [".json", ".js", ".ts"] contract.
5
- */
6
- export type ConfigExtension = ".json" | ".js" | ".ts";
7
-
8
- export interface LoadedConfig<TConfig = Record<string, unknown>> {
9
- readonly config: TConfig;
10
- /** Absolute path the config was resolved from. */
11
- readonly sourcePath: string;
12
- readonly extension: ConfigExtension;
13
- }
14
-
15
- export interface ConfigLoader {
16
- /** Resolve gitpagedocs/config.{json,js,ts} relative to a working directory. */
17
- resolveConfigPath(cwd: string): Promise<string | undefined>;
18
- loadGitPageDocsConfig<TConfig = Record<string, unknown>>(
19
- cwd: string,
20
- ): Promise<LoadedConfig<TConfig>>;
21
- }
1
+ /**
2
+ * Config-loading port. Implemented in Phase 4 by relocating the shared loader
3
+ * logic currently in src/entities/docs/api/io/config-loader.ts. Must preserve
4
+ * the legacy CONFIG_EXTENSIONS = [".json", ".js", ".ts"] contract.
5
+ */
6
+ export type ConfigExtension = ".json" | ".js" | ".ts";
7
+
8
+ export interface LoadedConfig<TConfig = Record<string, unknown>> {
9
+ readonly config: TConfig;
10
+ /** Absolute path the config was resolved from. */
11
+ readonly sourcePath: string;
12
+ readonly extension: ConfigExtension;
13
+ }
14
+
15
+ export interface ConfigLoader {
16
+ /** Resolve gitpagedocs/config.{json,js,ts} relative to a working directory. */
17
+ resolveConfigPath(cwd: string): Promise<string | undefined>;
18
+ loadGitPageDocsConfig<TConfig = Record<string, unknown>>(
19
+ cwd: string,
20
+ ): Promise<LoadedConfig<TConfig>>;
21
+ }
@@ -1,33 +1,33 @@
1
- /**
2
- * Crypto port. Implemented in Phase 4/5 with Node `crypto` and Web Crypto
3
- * adapters. Powers the password-gated, encrypted credential vault.
4
- */
5
- export interface KeyDerivationParams {
6
- /** Base64/hex salt. Generated per vault, persisted alongside the ciphertext. */
7
- readonly salt: string;
8
- /** Iteration count (PBKDF2) or cost parameter (scrypt). */
9
- readonly iterations: number;
10
- }
11
-
12
- export interface EncryptedPayload {
13
- /** Base64 ciphertext. */
14
- readonly ciphertext: string;
15
- /** Base64 initialization vector / nonce. */
16
- readonly iv: string;
17
- /** Authentication tag for AEAD ciphers (base64). */
18
- readonly authTag?: string;
19
- readonly kdf: KeyDerivationParams;
20
- }
21
-
22
- export interface CryptoService {
23
- /** Hex-encoded SHA-256 digest of the input. */
24
- sha256(input: string): Promise<string>;
25
- /** Derive a symmetric key from a password + KDF params. */
26
- deriveKey(password: string, params: KeyDerivationParams): Promise<Uint8Array>;
27
- encrypt(plaintext: string, password: string): Promise<EncryptedPayload>;
28
- decrypt(payload: EncryptedPayload, password: string): Promise<string>;
29
- /** Non-reversible display mask, e.g. "sk-…a1b2" — never reveals the secret. */
30
- mask(secret: string): string;
31
- /** Best-effort secure wipe of an in-memory buffer. */
32
- wipe(buffer: Uint8Array): void;
33
- }
1
+ /**
2
+ * Crypto port. Implemented in Phase 4/5 with Node `crypto` and Web Crypto
3
+ * adapters. Powers the password-gated, encrypted credential vault.
4
+ */
5
+ export interface KeyDerivationParams {
6
+ /** Base64/hex salt. Generated per vault, persisted alongside the ciphertext. */
7
+ readonly salt: string;
8
+ /** Iteration count (PBKDF2) or cost parameter (scrypt). */
9
+ readonly iterations: number;
10
+ }
11
+
12
+ export interface EncryptedPayload {
13
+ /** Base64 ciphertext. */
14
+ readonly ciphertext: string;
15
+ /** Base64 initialization vector / nonce. */
16
+ readonly iv: string;
17
+ /** Authentication tag for AEAD ciphers (base64). */
18
+ readonly authTag?: string;
19
+ readonly kdf: KeyDerivationParams;
20
+ }
21
+
22
+ export interface CryptoService {
23
+ /** Hex-encoded SHA-256 digest of the input. */
24
+ sha256(input: string): Promise<string>;
25
+ /** Derive a symmetric key from a password + KDF params. */
26
+ deriveKey(password: string, params: KeyDerivationParams): Promise<Uint8Array>;
27
+ encrypt(plaintext: string, password: string): Promise<EncryptedPayload>;
28
+ decrypt(payload: EncryptedPayload, password: string): Promise<string>;
29
+ /** Non-reversible display mask, e.g. "sk-…a1b2" — never reveals the secret. */
30
+ mask(secret: string): string;
31
+ /** Best-effort secure wipe of an in-memory buffer. */
32
+ wipe(buffer: Uint8Array): void;
33
+ }
@@ -1,15 +1,15 @@
1
- /**
2
- * Public port interfaces for @gitpagedocs/tools.
3
- *
4
- * These are the stable contracts that the frontend, CLI and MCP server consume.
5
- * Implementations are added in Phase 4 (core) and Phase 5 (AI + security)
6
- * behind these types, so consumers never depend on concrete modules.
7
- *
8
- * Type-only: importing this file pulls in no runtime code.
9
- */
10
- export type * from "./logger";
11
- export type * from "./cache";
12
- export type * from "./crypto";
13
- export type * from "./security";
14
- export type * from "./config";
15
- export type * from "./ai";
1
+ /**
2
+ * Public port interfaces for @gitpagedocs/tools.
3
+ *
4
+ * These are the stable contracts that the frontend, CLI and MCP server consume.
5
+ * Implementations are added in Phase 4 (core) and Phase 5 (AI + security)
6
+ * behind these types, so consumers never depend on concrete modules.
7
+ *
8
+ * Type-only: importing this file pulls in no runtime code.
9
+ */
10
+ export type * from "./logger";
11
+ export type * from "./cache";
12
+ export type * from "./crypto";
13
+ export type * from "./security";
14
+ export type * from "./config";
15
+ export type * from "./ai";
@@ -1,23 +1,23 @@
1
- /**
2
- * Logging port. Implemented in Phase 4 (tools/src/logger).
3
- * The implementation MUST redact secrets (API keys) before any sink write.
4
- */
5
- export type LogLevel = "debug" | "info" | "warn" | "error";
6
-
7
- export interface LogFields {
8
- readonly [key: string]: unknown;
9
- }
10
-
11
- export interface Logger {
12
- debug(message: string, fields?: LogFields): void;
13
- info(message: string, fields?: LogFields): void;
14
- warn(message: string, fields?: LogFields): void;
15
- error(message: string, fields?: LogFields): void;
16
- /** Returns a child logger that merges the given fields into every record. */
17
- child(fields: LogFields): Logger;
18
- }
19
-
20
- /** A destination for log records. */
21
- export interface LogSink {
22
- write(level: LogLevel, message: string, fields: LogFields): void;
23
- }
1
+ /**
2
+ * Logging port. Implemented in Phase 4 (tools/src/logger).
3
+ * The implementation MUST redact secrets (API keys) before any sink write.
4
+ */
5
+ export type LogLevel = "debug" | "info" | "warn" | "error";
6
+
7
+ export interface LogFields {
8
+ readonly [key: string]: unknown;
9
+ }
10
+
11
+ export interface Logger {
12
+ debug(message: string, fields?: LogFields): void;
13
+ info(message: string, fields?: LogFields): void;
14
+ warn(message: string, fields?: LogFields): void;
15
+ error(message: string, fields?: LogFields): void;
16
+ /** Returns a child logger that merges the given fields into every record. */
17
+ child(fields: LogFields): Logger;
18
+ }
19
+
20
+ /** A destination for log records. */
21
+ export interface LogSink {
22
+ write(level: LogLevel, message: string, fields: LogFields): void;
23
+ }