@http-forge/core 0.6.1 → 0.6.5

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
@@ -53,7 +53,119 @@ For current programmatic runtime APIs, see [RUNTIME-API.md](RUNTIME-API.md):
53
53
 
54
54
  This covers direct execution, embeddable MCP runtime lifecycle, response include options, and report behavior.
55
55
 
56
- ## ⚡ Quick Start
56
+ ---
57
+
58
+ ## 🤖 AI & Analysis APIs
59
+
60
+ All AI features use the `IAiProvider` abstraction — bring any LLM (GitHub Copilot, OpenAI, Anthropic) without changing the core logic.
61
+
62
+ ### `IAiProvider`
63
+
64
+ ```typescript
65
+ interface IAiProvider {
66
+ complete(prompt: string): Promise<string>;
67
+ }
68
+ ```
69
+
70
+ Implement this interface for any LLM backend. The package ships no concrete provider — callers supply one:
71
+
72
+ | Package | Provider class |
73
+ |---|---|
74
+ | `http-forge` (VS Code extension) | `CopilotAiProvider` (wraps `vscode.lm`) |
75
+ | `@http-forge/cli` | `OpenAiProvider`, `AnthropicProvider`, `createCliAiProvider()` |
76
+
77
+ ### `enhanceCollection`
78
+
79
+ Enhance a collection with AI-written example bodies and `pm.test()` assertion scripts.
80
+
81
+ ```typescript
82
+ import { enhanceCollection } from '@http-forge/core';
83
+
84
+ await enhanceCollection(
85
+ collection, // Collection to enhance
86
+ collectionService, // ICollectionService
87
+ aiProvider, // IAiProvider
88
+ (msg, increment) => console.log(msg) // optional progress callback
89
+ );
90
+ ```
91
+
92
+ Processes requests in batches of 10. Saves after each batch. Skips requests that already have a body and test script.
93
+
94
+ ### `scanCollectionForEnvVarsWithAi`
95
+
96
+ AI-powered scan for hardcoded values (API keys, tokens, base URLs, tenant IDs).
97
+
98
+ ```typescript
99
+ import { scanCollectionForEnvVarsWithAi } from '@http-forge/core';
100
+
101
+ const suggestions = await scanCollectionForEnvVarsWithAi(collection, aiProvider);
102
+ // Returns EnvSuggestion[] — same shape as detectEnvSuggestions,
103
+ // so applyEnvSuggestionsToItems works for both.
104
+ ```
105
+
106
+ Returns `EnvSuggestion[]` sorted by occurrence count descending.
107
+
108
+ ### `detectEnvSuggestions` (heuristic, no LLM)
109
+
110
+ Rule-based detection — no AI dependency. Flags `Authorization` headers, common sensitive header/query names, shared base URLs, and long opaque strings.
111
+
112
+ ```typescript
113
+ import { detectEnvSuggestions, applyEnvSuggestionsToItems } from '@http-forge/core';
114
+
115
+ const suggestions = detectEnvSuggestions(collection, /* minOccurrences */ 1);
116
+ const counts = applyEnvSuggestionsToItems(collection.items, suggestions);
117
+ await collectionService.saveCollection(collection);
118
+ ```
119
+
120
+ ### `parseCurlCommand`
121
+
122
+ Parse a shell curl command string into a `ParsedCurlRequest` object ready to persist as a collection request.
123
+
124
+ ```typescript
125
+ import { parseCurlCommand } from '@http-forge/core';
126
+
127
+ const parsed = parseCurlCommand(
128
+ `curl -X POST https://api.example.com/users ` +
129
+ `-H 'Authorization: Bearer sk-abc123' ` +
130
+ `-d '{"name":"Alice"}'`
131
+ );
132
+ // parsed.name, .method, .url, .headers, .queryParams, .body, .suggestedVars
133
+ ```
134
+
135
+ `suggestedVars` contains heuristically-detected values that should become environment variables (e.g. the Bearer token above).
136
+
137
+ ---
138
+
139
+ ## 🔌 MCP Tools — AI Agent Integration
140
+
141
+ When the MCP server is running, AI agents (Claude, Copilot, etc.) can call these tools in addition to the standard run/inspect tools:
142
+
143
+ ### Agentic AI tools (no LLM config needed)
144
+
145
+ These tools use the **calling AI as the analysis engine** — no API keys required on the server side.
146
+
147
+ | Tool | Description |
148
+ |---|---|
149
+ | `ai_suggest_env_vars` | Returns request data + instructions; AI finds hardcoded values and calls `apply_env_vars`. One-shot. |
150
+ | `ai_enhance_collection` | Returns paginated requests + instructions; AI writes bodies and test scripts and calls `apply_request_enhancements`. Self-continues. |
151
+ | `ai_analyze_coverage` | Returns coverage gaps + instructions; AI calls `ai_enhance_collection` for unasserted requests and `generate_scenarios` for untested operations. |
152
+ | `generate_request_from_intent` | Takes a plain-English intent; AI calls `create_request` + `set_request_script` in one shot. |
153
+ | `generate_scenarios` | Returns request list + instructions; AI creates negative/edge-case variants (400/401/403/404/boundary) per request. Self-continues. |
154
+ | `heal_assertions` | Returns current script + last run response; AI rewrites stale assertions and calls `set_request_script`. |
155
+ | `generate_iteration_data` | Returns request schema + instructions; AI produces N varied test rows as a JSON array. |
156
+
157
+ ### Data tools (read → you analyze → write)
158
+
159
+ | Tool | Description |
160
+ |---|---|
161
+ | `suggest_env_vars` | Returns heuristic suggestions + full request summary for manual or AI review |
162
+ | `apply_env_vars` | Replaces `{value, varName}[]` throughout the collection; optionally writes originals to env |
163
+ | `get_requests_for_enhancement` | Returns paginated request details (body, test script, headers) |
164
+ | `apply_request_enhancements` | Applies AI-written bodies and `pm.test()` scripts to the specified requests |
165
+ | `analyze_coverage` | Per-request assertion count + collection-level %. Optional OpenAPI spec comparison. No LLM. |
166
+ | `validate_against_spec` | Compares collection against an OpenAPI 3.0 spec: untested operations, unasserted requests, extra requests. No LLM. |
167
+
168
+ ---
57
169
 
58
170
  ### Basic Usage
59
171
 
@@ -900,6 +1012,16 @@ MIT © Henry Huang
900
1012
 
901
1013
  ## 📝 Changelog
902
1014
 
1015
+ ### 0.7.0 (AI & Analysis)
1016
+
1017
+ - ✅ **`IAiProvider`** — Platform-agnostic LLM interface; bring Copilot, OpenAI, Anthropic, or any other LLM
1018
+ - ✅ **`enhanceCollection`** — Batch-enhances collection requests with AI-written example bodies and `pm.test()` scripts
1019
+ - ✅ **`scanCollectionForEnvVarsWithAi`** — AI-powered scan for hardcoded values (keys, tokens, base URLs)
1020
+ - ✅ **`detectEnvSuggestions`** / **`applyEnvSuggestionsToItems`** — Heuristic env var detection (no LLM)
1021
+ - ✅ **`parseCurlCommand`** — Tokenising shell curl parser producing a ready-to-persist `ParsedCurlRequest`
1022
+ - ✅ **MCP agentic tools** — `ai_suggest_env_vars`, `ai_enhance_collection`, `suggest_env_vars`, `apply_env_vars`, `get_requests_for_enhancement`, `apply_request_enhancements`
1023
+ - ✅ **MCP gap-closure tools** — `analyze_coverage`, `ai_analyze_coverage`, `validate_against_spec`, `generate_request_from_intent`, `generate_scenarios`, `heal_assertions`, `generate_iteration_data`
1024
+
903
1025
  ### 0.2.16 (Duplicate Collection & Folder)
904
1026
 
905
1027
  - ✅ **`duplicateCollection(sourceId, newName)`** — Duplicates a collection including all nested folders, requests, scripts, and schemas
@@ -7,11 +7,11 @@
7
7
  * The core bootstrap uses these adapters to wire up services
8
8
  * without depending on any specific platform.
9
9
  */
10
- import type { IConsoleService } from '../types/console-service';
11
- import type { IApplicationInfo, IExternalBrowserService, IFileSystem, IFileWatcherFactory, IHttpClient, IKeyValueStore, INotificationService, ISecretStore } from '../types/platform';
12
10
  import type { IHttpExecutor } from '../ports/executors/http-executor.interface';
13
11
  import type { IScriptExecutor } from '../ports/executors/script-executor.interface';
14
12
  import type { ILogger } from '../ports/external/logger.interface';
13
+ import type { IConsoleService } from '../types/console-service';
14
+ import type { IApplicationInfo, IExternalBrowserService, IFileSystem, IFileWatcherFactory, IHttpClient, IKeyValueStore, INotificationService, ISecretStore } from '../types/platform';
15
15
  /**
16
16
  * Platform adapters required by core service bootstrap.
17
17
  *
@@ -41,8 +41,8 @@ export interface PlatformAdapters {
41
41
  fileWatcherFactory: IFileWatcherFactory;
42
42
  /** Notification service — shows info/warning/error messages (ConfigService) */
43
43
  notificationService: INotificationService;
44
- /** Per-workspace key-value store (EnvironmentConfigService) */
45
- workspaceStore: IKeyValueStore;
44
+ /** Per-workspace key-value store (EnvironmentConfigService). Optional — CLI/Node runs without it. */
45
+ workspaceStore?: IKeyValueStore;
46
46
  /** Global key-value store (CookieService) */
47
47
  globalStore: IKeyValueStore;
48
48
  /** Secret storage for tokens (OAuth2TokenManager). Optional — OAuth2 disabled if absent. */
@@ -53,6 +53,13 @@ export interface PlatformAdapters {
53
53
  applicationInfo?: IApplicationInfo;
54
54
  /** Structured logging service. Optional — a no-op console is used if absent. */
55
55
  consoleService?: IConsoleService;
56
+ /**
57
+ * Whether script-written environment overrides (pm.environment.set) should be
58
+ * persisted to the workspace store between runs.
59
+ * - `true` (default) — VS Code extension: Current Values survive restarts.
60
+ * - `false` — CLI/Node: overrides are in-memory only, runs are stateless.
61
+ */
62
+ persistOverrides?: boolean;
56
63
  /** File system adapter */
57
64
  fileSystem?: IFileSystem;
58
65
  /** Logger adapter */
package/dist/index.d.ts CHANGED
@@ -24,6 +24,8 @@ export { countRequests, enumerateFolders, flattenRequests } from './runtime/mcp-
24
24
  export type { FlatRequest } from './runtime/mcp-collection-utils';
25
25
  export { CACHE_BUSTING_TOOLS, dispatchGenericTool } from './runtime/mcp-dispatcher';
26
26
  export type { McpDispatchServices, McpRunCallbacks } from './runtime/mcp-dispatcher';
27
+ export { buildPromptResult, MCP_PROMPTS } from './runtime/mcp-prompts';
28
+ export type { McpPromptArg, McpPromptDef, PromptResult } from './runtime/mcp-prompts';
27
29
  export { McpRunStore } from './runtime/mcp-run-store';
28
30
  export type { McpRunRecord } from './runtime/mcp-run-store';
29
31
  export { buildMcpToolList, decodeCursor, dedupeToolsByName, encodeCursor } from './runtime/mcp-tool-builder';
@@ -79,6 +81,14 @@ export { generateSlug } from './infrastructure/collection/folder-io';
79
81
  export { ParserRegistry } from './infrastructure/collection/parser-registry';
80
82
  export { JsonCollectionLoader } from './infrastructure/collection/json-collection-loader';
81
83
  export type { Collection, CollectionFolderItem, CollectionItem, CollectionRequestItem, ICollectionService } from './types/collection';
84
+ export { parseCurlCommand } from './infrastructure/parsers/curl-parser';
85
+ export type { ParsedCurlRequest } from './infrastructure/parsers/curl-parser';
86
+ export type { IAiProvider } from './infrastructure/ai/ai-provider';
87
+ export { enhanceCollection } from './infrastructure/analysis/collection-enhancer';
88
+ export type { EnhanceProgressCallback } from './infrastructure/analysis/collection-enhancer';
89
+ export { scanCollectionForEnvVarsWithAi } from './infrastructure/analysis/ai-env-suggester';
90
+ export { applyEnvSuggestionsToItems, detectEnvSuggestions } from './infrastructure/analysis/env-suggester';
91
+ export type { EnvSuggestion } from './infrastructure/analysis/env-suggester';
82
92
  export { AmbiguousRefError, resolveCollectionRef, resolveFolderRef, resolveRequestRef } from './runtime/ref-resolver';
83
93
  export type { RefCandidate, RefKind, RefTier, ResolutionInfo } from './runtime/ref-resolver';
84
94
  export { EnvironmentConfigService } from './infrastructure/environment/environment-config-service';