@http-forge/core 0.6.39 → 0.6.41

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.
@@ -19,4 +19,4 @@ import type { EnvSuggestion } from './env-suggester';
19
19
  * @param aiProvider Any IAiProvider (Copilot, OpenAI, Anthropic, …).
20
20
  * @returns Suggestions sorted by occurrence count descending.
21
21
  */
22
- export declare function scanCollectionForEnvVarsWithAi(collection: Collection, aiProvider: IAiProvider): Promise<EnvSuggestion[]>;
22
+ export declare function scanCollectionForEnvVarsWithAi(collection: Collection, aiProvider: IAiProvider, collectionService?: Pick<import('../../types/collection').ICollectionService, 'getRequestDetail'>): Promise<EnvSuggestion[]>;
@@ -14,7 +14,7 @@
14
14
  * user customizations are never silently lost.
15
15
  */
16
16
  /** Current template version. Bump when `buildAgentsMdContent()` changes. */
17
- export declare const AGENTS_MD_VERSION = 1;
17
+ export declare const AGENTS_MD_VERSION = 2;
18
18
  export declare const AGENTS_MD_FILENAME = "AGENTS.md";
19
19
  export declare const AGENTS_MD_BACKUP_FILENAME = "AGENTS.md.bak";
20
20
  /** Absolute path of the guide inside a `.http-forge/` directory. */
@@ -43,6 +43,11 @@ export declare class CollectionService implements ICollectionService {
43
43
  constructor(configService: IConfigService, fileWatcherFactory?: IFileWatcherFactory | undefined);
44
44
  private ensureCollectionsDir;
45
45
  private loadCollections;
46
+ /**
47
+ * Load heavy request detail on demand (body, scripts, schemas, doc).
48
+ * No-op for stores without lazy support (e.g. JSON format) — falls back to `findRequest`.
49
+ */
50
+ getRequestDetail(collectionId: string, requestId: string): CollectionRequestItem | undefined;
46
51
  private setupFileWatcher;
47
52
  getAllCollections(): Collection[];
48
53
  getCollection(id: string): Collection | undefined;
@@ -82,7 +82,29 @@ export interface ICollectionStore {
82
82
  * Get the disk path of an item (folder or request) within a collection
83
83
  */
84
84
  getItemPath(collectionId: string, itemId: string): string | undefined;
85
+ /**
86
+ * Load heavy request detail (body, scripts, schemas, doc) on demand.
87
+ * Used to keep `loadAll()` light for tree view and defer I/O until a request is opened/executed.
88
+ */
89
+ loadRequestDetail?(collectionId: string, requestId: string): CollectionItem | undefined;
90
+ /**
91
+ * Load all collections in light mode (cheap metadata only, no body/scripts/schemas/doc).
92
+ * Optimized for tree view and startup.
93
+ */
94
+ loadAllLight?(): Collection[];
95
+ }
96
+ /**
97
+ * In-memory marker for requests loaded via `loadAllLight()`.
98
+ * Never persisted to disk — set only on the in-memory item and cleared by
99
+ * `loadRequestDetail()` once heavy fields are enriched (or enrichment is attempted).
100
+ */
101
+ export interface LightLoadedRequest {
102
+ _light?: boolean;
85
103
  }
104
+ /** True when the item still needs on-demand heavy-field enrichment. */
105
+ export declare function isLightLoaded(item: CollectionItem): boolean;
106
+ /** Mark an item as fully loaded (enriched, or enrichment attempted). */
107
+ export declare function markDetailLoaded(item: CollectionItem): void;
86
108
  /**
87
109
  * Metadata stored in collection.json for folder format
88
110
  */
@@ -36,6 +36,11 @@ export declare class FolderCollectionStore implements ICollectionStore {
36
36
  private cache;
37
37
  private slugToIdMap;
38
38
  private idToSlugMap;
39
+ /**
40
+ * When true, `loadRequestFromDir` delegates to the light loader
41
+ * (metadata only). Set only inside `loadAllLight()`; never left on.
42
+ */
43
+ private lightLoad;
39
44
  constructor(collectionsDir: string);
40
45
  /**
41
46
  * Get collection/item slug from ID
@@ -90,31 +95,26 @@ export declare class FolderCollectionStore implements ICollectionStore {
90
95
  * Load a folder from directory
91
96
  */
92
97
  private loadFolderFromDir;
98
+ /**
99
+ * Load a request from directory — light mode (cheap metadata only, no heavy I/O).
100
+ * Used by `loadAllLight()` for tree view / startup optimization.
101
+ */
102
+ private loadRequestFromDirLight;
103
+ /**
104
+ * Load heavy request detail on demand (body, scripts, schemas, doc).
105
+ * Populates the cached collection item in-place when found.
106
+ * Idempotent: items that are already fully loaded are returned without disk I/O.
107
+ */
108
+ loadRequestDetail(collectionId: string, requestId: string): CollectionItem | undefined;
109
+ /**
110
+ * Load all collections in light mode (no heavy I/O) — optimized for startup/tree view.
111
+ */
112
+ loadAllLight(): Collection[];
93
113
  /**
94
114
  * Load a request from directory
95
115
  *
96
- * TODO(perf/memory): This method eagerly loads ALL heavy fields for every request at
97
- * startup (called by loadAll()). With thousands of requests, body, scripts, schemas,
98
- * and docs can consume hundreds of MB of heap.
99
- *
100
- * The fix is to load only cheap metadata here (url, method, headers, auth, settings,
101
- * name, description, deprecated) and introduce an on-demand
102
- * `loadRequestDetail(requestPath)` that reads the heavy fields only when a request is
103
- * actually opened or executed.
104
- *
105
- * Heavy fields to defer:
106
- * - body (readBodyFromDir) — up to 100 KB+
107
- * - scripts (loadScriptsFromDir) — pre/post JS source, up to 20 KB
108
- * - responseSchema (readSchemaFile) — OpenAPI JSON, up to 1 MB+
109
- * - bodySchema (readSchemaFile) — OpenAPI JSON, up to 1 MB+
110
- * - doc (fs.readFileSync doc.md) — markdown, up to 50 KB
111
- *
112
- * Callers that need the heavy fields:
113
- * - CollectionRequestExecutor (body, scripts)
114
- * - RequestExecutionHandler (body, scripts)
115
- * - SchemaHandler (responseSchema, bodySchema)
116
- * - PanelDataProvider.getInitialData() (sends full request to webview)
117
- * - MCP direct-execution: runRequest / runCollection (body, scripts)
116
+ * Heavy fields are loaded eagerly here for backward compatibility (direct execution, tests).
117
+ * For startup optimization, use `loadAllLight()` + `loadRequestDetail()` on demand.
118
118
  */
119
119
  private loadRequestFromDir;
120
120
  /**
@@ -193,6 +193,19 @@ export declare class FolderCollectionStore implements ICollectionStore {
193
193
  * Load scripts for a specific item
194
194
  */
195
195
  loadScripts(collectionId: string, itemId: string): RequestScripts | undefined;
196
+ /**
197
+ * Hydrate light-loaded requests in place before a disk write.
198
+ * Saving a light item would otherwise persist metadata without its heavy
199
+ * files (e.g. overwrite body.json with empty content). The cache holds the
200
+ * same object references the service works with, so in-place enrichment
201
+ * fixes both the write and any live readers.
202
+ */
203
+ private hydrateLightItems;
204
+ /**
205
+ * Resolve the request to persist: a detached light copy carries no heavy
206
+ * fields, so prefer the enriched cached item when available.
207
+ */
208
+ private resolveWritableRequest;
196
209
  /**
197
210
  * Update collection metadata only
198
211
  */
@@ -23,7 +23,10 @@ export declare class ConfigService implements IConfigService {
23
23
  private configPath;
24
24
  private configDir;
25
25
  private fileWatchers;
26
+ private _standaloneProbeCache?;
27
+ private _cachedWorkspaceNormalization?;
26
28
  constructor(workspacePath: string, fileWatcherFactory?: IFileWatcherFactory | undefined, notifications?: INotificationService | undefined);
29
+ private isStandaloneLayoutCached;
27
30
  private normalizeWorkspacePath;
28
31
  private resolveConfigPath;
29
32
  /**
@@ -0,0 +1,7 @@
1
+ /**
2
+ * QA check report rendering — table output for humans.
3
+ * JSON output is `JSON.stringify(report, null, 2)` at the call site.
4
+ */
5
+ import type { QaCheckReport } from './qa-service';
6
+ /** Render a QA check report as a human-readable summary table. */
7
+ export declare function renderQaReportTable(report: QaCheckReport): string;
@@ -0,0 +1,125 @@
1
+ /**
2
+ * QA Check service — one-shot API quality gate.
3
+ *
4
+ * Orchestrates the discover → generate → run → report loop in a single call:
5
+ * source-code discovery, idempotent request creation (reuse by endpoint key,
6
+ * never duplicate), deterministic suite generation, live execution, and a
7
+ * machine-readable report with CI-friendly status.
8
+ *
9
+ * All stage logic lives in its existing module (drift-engine, discovery
10
+ * providers, test-generator, suite executor). This module only sequences them.
11
+ */
12
+ import type { IConfigService } from '../config';
13
+ import type { ICollectionService } from '../../types/collection';
14
+ import type { ITestSuiteService } from '../test-suite/interfaces';
15
+ import type { DiscoveredApi } from '../api-discovery';
16
+ import type { IAiProvider } from '../ai/ai-provider';
17
+ /** Services the QA check is sequenced over (narrow interface — no container). */
18
+ export interface QaCheckServices {
19
+ collection: ICollectionService;
20
+ testSuite: ITestSuiteService;
21
+ /** Optional: discovery tuning. Defaults apply when absent (e.g. MCP). */
22
+ config?: IConfigService;
23
+ }
24
+ /** Options for a QA check run. */
25
+ export interface QaCheckOptions {
26
+ /** Backend project root to scan. */
27
+ projectPath: string;
28
+ /** Target collection (id, slug, or name). Requests are created/reused here. */
29
+ collectionRef: string;
30
+ /** Running server to execute against. Required unless `dryRun`. */
31
+ baseUrl?: string;
32
+ /** Environment name for variable resolution. */
33
+ environment?: string;
34
+ /** Extra variables injected into every request (e.g. auth tokens). */
35
+ variables?: Record<string, unknown>;
36
+ /** Restrict discovery to one framework (express, nestjs, fastify, lambda, spring, fastapi). */
37
+ framework?: string;
38
+ /** Preview only: no requests created, nothing saved, no network calls. */
39
+ dryRun?: boolean;
40
+ /** Return `drift` status instead of proceeding when the project moved. */
41
+ failOnDrift?: boolean;
42
+ /** Git HEAD from a prior scan (enables git-based drift comparison). */
43
+ storedGitHash?: string;
44
+ /** Scan time from a prior scan (enables mtime-based drift comparison). */
45
+ storedScannedAt?: string;
46
+ /** Also assert JSON array response bodies in generated suites. */
47
+ assertBodySchema?: boolean;
48
+ /** Request an AI assertion pass after the deterministic run (needs `aiProvider`). */
49
+ aiAssertions?: boolean;
50
+ /** AI backend for the assertion pass. Without it, the flag is noted and skipped. */
51
+ aiProvider?: IAiProvider;
52
+ /** Max AI suggestions per endpoint (default 5). */
53
+ aiMaxSuggestions?: number;
54
+ }
55
+ /** Terminal status of a QA check (maps to CLI exit codes 0/1/3/2). */
56
+ export type QaCheckStatus = 'pass' | 'fail' | 'drift' | 'infra' | 'dry-run';
57
+ /** Per-endpoint row of the QA report. */
58
+ export interface QaEndpointResult {
59
+ /** Stable endpoint key: `METHOD /resolved/path`. */
60
+ endpointKey: string;
61
+ method: string;
62
+ path: string;
63
+ confidence: DiscoveredApi['confidence'];
64
+ requestId: string;
65
+ requestName: string;
66
+ /** True when an existing collection request was reused. */
67
+ reused: boolean;
68
+ statusExpected: number;
69
+ statusGot?: number;
70
+ passed?: boolean;
71
+ duration?: string;
72
+ failures?: string[];
73
+ error?: string;
74
+ /** AI-suggested assertions (only when the `aiAssertions` pass ran for this endpoint). */
75
+ suggestions?: Array<{
76
+ snippet: string;
77
+ rationale: string;
78
+ }>;
79
+ }
80
+ /** Machine-readable QA check report (JSON-serializable). */
81
+ export interface QaCheckReport {
82
+ status: QaCheckStatus;
83
+ project: {
84
+ path: string;
85
+ gitHash?: string;
86
+ frameworks: string[];
87
+ };
88
+ drift: {
89
+ status: 'current' | 'stale' | 'unknown';
90
+ reason?: string;
91
+ };
92
+ discovered: number;
93
+ reused: number;
94
+ created: number;
95
+ updatedUrls: number;
96
+ suite?: {
97
+ id: string;
98
+ name: string;
99
+ };
100
+ results: {
101
+ passed: number;
102
+ failed: number;
103
+ skipped: number;
104
+ };
105
+ endpoints: QaEndpointResult[];
106
+ /** Low-confidence discoveries are reported, never silently dropped. */
107
+ lowConfidence: string[];
108
+ /** Outcome of the optional AI assertion pass. */
109
+ aiAssertions: {
110
+ requested: boolean;
111
+ applied: boolean;
112
+ note?: string;
113
+ };
114
+ checkedAt: string;
115
+ }
116
+ /** Stable endpoint identity across runs: method + resolved path. */
117
+ export declare function qaEndpointKey(ep: Pick<DiscoveredApi, 'method' | 'resolvedPath' | 'pathExpression'>): string;
118
+ /**
119
+ * Run the QA check pipeline: freshness → discover → generate → run → report.
120
+ *
121
+ * Idempotent: reruns reuse existing requests matched by endpoint key and
122
+ * overwrite the deterministic QA suite, so repeated runs create nothing new
123
+ * unless the source changed.
124
+ */
125
+ export declare function runQaCheck(services: QaCheckServices, workspaceFolder: string, options: QaCheckOptions): Promise<QaCheckReport>;
@@ -2,5 +2,13 @@
2
2
  * AI-native tool handlers — scaffold/openapi, suggestions, coverage, and the
3
3
  * "task" tools that instruct the calling LLM to take follow-up actions.
4
4
  */
5
+ import type { IAiProvider } from '../../infrastructure/ai/ai-provider';
6
+ import type { CollectionRequestItem } from '../../types/collection';
5
7
  import type { McpToolHandler } from './types';
8
+ export interface AssertionSuggestion {
9
+ snippet: string;
10
+ rationale: string;
11
+ }
12
+ /** Ask an LLM for tailored pm.test() assertions, returning [] on any failure. */
13
+ export declare function suggestAssertionsWithAi(provider: IAiProvider, req: CollectionRequestItem, latestResult: Record<string, unknown> | undefined, maxSuggestions: number, workspaceKnowledge?: string): Promise<AssertionSuggestion[]>;
6
14
  export declare const aiHandlers: McpToolHandler[];
@@ -16,6 +16,13 @@ export declare function resolveCollectionByLabel(label: unknown, collections: Co
16
16
  * name/substring.
17
17
  */
18
18
  export declare function resolveRequestByLabel(label: unknown, col: Collection): CollectionRequestItem;
19
+ /**
20
+ * Hydrate a tree-resolved request with heavy fields (body/scripts/schemas/doc).
21
+ * Collections load light (metadata only); single-request readers must call this
22
+ * before touching heavy fields. Falls back to the passed item on stores
23
+ * without lazy support. List/match paths keep using light refs untouched.
24
+ */
25
+ export declare function hydrateRequest(services: McpDispatchServices, collectionId: string, req: CollectionRequestItem): CollectionRequestItem;
19
26
  /**
20
27
  * Find a folder item in a collection tree by its ID.
21
28
  *
@@ -0,0 +1,9 @@
1
+ /**
2
+ * QA tool handler — one-shot discover → generate → run → report quality gate.
3
+ *
4
+ * Thin adapter over the core QA service (`infrastructure/qa/qa-service`):
5
+ * argument validation only. Reruns are idempotent (requests matched by
6
+ * method + path and reused), so agents can safely re-run after fixing code.
7
+ */
8
+ import type { McpToolHandler } from './types';
9
+ export declare const qaHandlers: McpToolHandler[];
@@ -225,6 +225,7 @@ export declare const GENERIC_TOOL_NAMES: {
225
225
  readonly generateWorkflow: "generate_workflow";
226
226
  readonly checkDrift: "check_drift";
227
227
  readonly proposeUpdate: "propose_update";
228
+ readonly qaApi: "qa_api";
228
229
  readonly reviewSuite: "review_suite";
229
230
  readonly getRequestScript: "get_request_script";
230
231
  readonly setRequestScript: "set_request_script";
@@ -66,6 +66,11 @@ export interface ICollectionReader {
66
66
  getCollectionById(id: string): Collection | undefined;
67
67
  getCollectionByName(name: string): Collection | undefined;
68
68
  findRequest(collectionId: string, requestId: string): CollectionRequestItem | undefined;
69
+ /**
70
+ * Load heavy request detail (body, scripts, schemas, doc) on demand.
71
+ * Falls back to `findRequest` on stores without lazy support.
72
+ */
73
+ getRequestDetail(collectionId: string, requestId: string): CollectionRequestItem | undefined;
69
74
  getCollectionVariables(collectionId: string): Record<string, string>;
70
75
  }
71
76
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@http-forge/core",
3
- "version": "0.6.39",
3
+ "version": "0.6.41",
4
4
  "description": "Headless Postman-compatible API testing engine for Node.js, CI/CD, OpenAPI workflows, and HTTP Forge automation",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",