@lssm/bundle.contractspec-workspace 0.0.0-canary-20251217060834 → 0.0.0-canary-20251217072406
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/dist/_virtual/rolldown_runtime.js +22 -1
- package/dist/adapters/ai.js +82 -1
- package/dist/adapters/factory.js +36 -1
- package/dist/adapters/fs.js +118 -1
- package/dist/adapters/git.js +54 -1
- package/dist/adapters/index.js +7 -1
- package/dist/adapters/logger.js +80 -1
- package/dist/adapters/watcher.js +69 -1
- package/dist/adapters/workspace.js +190 -2
- package/dist/ai/agents/claude-code-agent.js +146 -9
- package/dist/ai/agents/cursor-agent.js +286 -17
- package/dist/ai/agents/index.js +5 -1
- package/dist/ai/agents/openai-codex-agent.js +140 -8
- package/dist/ai/agents/orchestrator.js +142 -1
- package/dist/ai/agents/simple-agent.js +80 -4
- package/dist/ai/client.js +162 -1
- package/dist/ai/index.js +27 -1
- package/dist/ai/prompts/code-generation.js +55 -13
- package/dist/ai/prompts/index.js +12 -1
- package/dist/ai/prompts/spec-creation.js +61 -20
- package/dist/ai/providers.js +40 -1
- package/dist/formatters/index.js +18 -1
- package/dist/formatters/json.js +71 -1
- package/dist/formatters/sarif.js +163 -1
- package/dist/formatters/text.js +208 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.js +81 -1
- package/dist/libs/ai-providers/dist/factory.js +154 -0
- package/dist/libs/ai-providers/dist/index.js +4 -0
- package/dist/libs/ai-providers/dist/legacy.js +72 -0
- package/dist/libs/ai-providers/dist/models.js +287 -0
- package/dist/libs/ai-providers/dist/validation.js +1 -0
- package/dist/libs/contracts/dist/capabilities/openbanking.js +88 -0
- package/dist/libs/contracts/dist/client/index.js +5 -0
- package/dist/libs/contracts/dist/client/react/feature-render.js +2 -0
- package/dist/libs/contracts/dist/client/react/form-render.js +4 -0
- package/dist/libs/contracts/dist/client/react/index.js +4 -0
- package/dist/libs/contracts/dist/contract-registry/index.js +1 -0
- package/dist/libs/contracts/dist/contract-registry/schemas.js +60 -0
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/index.js +29 -0
- package/dist/libs/contracts/dist/docs/presentations.js +71 -0
- package/dist/libs/contracts/dist/docs/registry.js +44 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +80 -0
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +57 -0
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +357 -0
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -0
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +79 -0
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +84 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +45 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -0
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +40 -0
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +69 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +62 -0
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +155 -0
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +101 -0
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -0
- package/dist/libs/contracts/dist/events.js +8 -0
- package/dist/libs/contracts/dist/experiments/evaluator.js +1 -0
- package/dist/libs/contracts/dist/index.js +72 -0
- package/dist/libs/contracts/dist/install.js +2 -0
- package/dist/libs/contracts/dist/integrations/contracts.js +377 -0
- package/dist/libs/contracts/dist/integrations/index.js +18 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +159 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +3 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -0
- package/dist/libs/contracts/dist/integrations/openbanking/models.js +242 -0
- package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +13 -0
- package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +52 -0
- package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +75 -0
- package/dist/libs/contracts/dist/integrations/providers/gmail.js +87 -0
- package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +66 -0
- package/dist/libs/contracts/dist/integrations/providers/index.js +11 -0
- package/dist/libs/contracts/dist/integrations/providers/mistral.js +68 -0
- package/dist/libs/contracts/dist/integrations/providers/postmark.js +68 -0
- package/dist/libs/contracts/dist/integrations/providers/powens.js +116 -0
- package/dist/libs/contracts/dist/integrations/providers/qdrant.js +73 -0
- package/dist/libs/contracts/dist/integrations/providers/registry.js +10 -0
- package/dist/libs/contracts/dist/integrations/providers/stripe.js +83 -0
- package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +61 -0
- package/dist/libs/contracts/dist/jsonschema.js +24 -0
- package/dist/libs/contracts/dist/knowledge/contracts.js +306 -0
- package/dist/libs/contracts/dist/knowledge/index.js +7 -0
- package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +34 -0
- package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +34 -0
- package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +38 -0
- package/dist/libs/contracts/dist/knowledge/spaces/index.js +6 -0
- package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +34 -0
- package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +37 -0
- package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -0
- package/dist/libs/contracts/dist/llm/exporters.js +352 -0
- package/dist/libs/contracts/dist/llm/index.js +2 -0
- package/dist/libs/contracts/dist/llm/prompts.js +211 -0
- package/dist/libs/contracts/dist/onboarding-base.js +196 -0
- package/dist/libs/contracts/dist/openapi.js +75 -0
- package/dist/libs/contracts/dist/ownership.js +21 -0
- package/dist/libs/contracts/dist/presentations.js +1 -0
- package/dist/libs/contracts/dist/presentations.v2.js +11 -0
- package/dist/libs/contracts/dist/prompt.js +1 -0
- package/dist/libs/contracts/dist/promptRegistry.js +1 -0
- package/dist/libs/contracts/dist/regenerator/index.js +2 -0
- package/dist/libs/contracts/dist/regenerator/service.js +92 -0
- package/dist/libs/contracts/dist/regenerator/utils.js +51 -0
- package/dist/libs/contracts/dist/registry.js +208 -0
- package/dist/libs/contracts/dist/resources.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/EnumType.js +2 -0
- package/dist/libs/contracts/dist/schema/dist/FieldType.js +49 -0
- package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -0
- package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +34 -0
- package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/entity/index.js +2 -0
- package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/index.js +6 -0
- package/dist/libs/contracts/dist/server/graphql-pothos.js +6 -0
- package/dist/libs/contracts/dist/server/index.js +8 -0
- package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +4 -0
- package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +2 -0
- package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/registerResources.js +2 -0
- package/dist/libs/contracts/dist/server/mcp/registerTools.js +1 -0
- package/dist/libs/contracts/dist/server/provider-mcp.js +1 -0
- package/dist/libs/contracts/dist/server/rest-elysia.js +1 -0
- package/dist/libs/contracts/dist/server/rest-express.js +1 -0
- package/dist/libs/contracts/dist/server/rest-generic.js +1 -0
- package/dist/libs/contracts/dist/server/rest-next-app.js +1 -0
- package/dist/libs/contracts/dist/server/rest-next-pages.js +1 -0
- package/dist/libs/contracts/dist/spec.js +35 -0
- package/dist/libs/contracts/dist/telemetry/index.js +1 -0
- package/dist/libs/contracts/dist/telemetry/tracker.js +1 -0
- package/dist/libs/contracts/dist/tests/index.js +1 -0
- package/dist/libs/contracts/dist/tests/runner.js +150 -0
- package/dist/libs/contracts/dist/workflow/index.js +1 -0
- package/dist/libs/contracts/dist/workflow/runner.js +1 -0
- package/dist/libs/contracts-transformers/dist/common/utils.js +47 -0
- package/dist/libs/contracts-transformers/dist/openapi/exporter.js +1 -0
- package/dist/libs/contracts-transformers/dist/openapi/importer.js +255 -0
- package/dist/libs/contracts-transformers/dist/openapi/index.js +4 -0
- package/dist/libs/contracts-transformers/dist/openapi/parser.js +231 -0
- package/dist/libs/contracts-transformers/dist/openapi/schema-converter.js +201 -0
- package/dist/modules/contractspec-workspace/dist/ai/code-generation.js +137 -0
- package/dist/modules/contractspec-workspace/dist/ai/spec-creation.js +101 -0
- package/dist/modules/contractspec-workspace/dist/analysis/deps/graph.js +84 -0
- package/dist/modules/contractspec-workspace/dist/analysis/deps/parse-imports.js +30 -0
- package/dist/modules/contractspec-workspace/dist/analysis/diff/semantic.js +96 -0
- package/dist/modules/contractspec-workspace/dist/analysis/feature-scan.js +151 -0
- package/dist/modules/contractspec-workspace/dist/analysis/spec-scan.js +344 -0
- package/dist/modules/contractspec-workspace/dist/analysis/validate/spec-structure.js +122 -0
- package/dist/modules/contractspec-workspace/dist/templates/app-config.js +105 -0
- package/dist/modules/contractspec-workspace/dist/templates/data-view.js +68 -0
- package/dist/modules/contractspec-workspace/dist/templates/event.js +38 -0
- package/dist/modules/contractspec-workspace/dist/templates/experiment.js +87 -0
- package/dist/modules/contractspec-workspace/dist/templates/handler.js +95 -0
- package/dist/modules/contractspec-workspace/dist/templates/integration-utils.js +104 -0
- package/dist/modules/contractspec-workspace/dist/templates/integration.js +62 -0
- package/dist/modules/contractspec-workspace/dist/templates/knowledge.js +68 -0
- package/dist/modules/contractspec-workspace/dist/templates/migration.js +60 -0
- package/dist/modules/contractspec-workspace/dist/templates/operation.js +100 -0
- package/dist/modules/contractspec-workspace/dist/templates/presentation.js +78 -0
- package/dist/modules/contractspec-workspace/dist/templates/telemetry.js +89 -0
- package/dist/modules/contractspec-workspace/dist/templates/utils.js +38 -0
- package/dist/modules/contractspec-workspace/dist/templates/workflow-runner.js +48 -0
- package/dist/modules/contractspec-workspace/dist/templates/workflow.js +67 -0
- package/dist/modules/contractspec-workspace/dist/types/generation-types.js +20 -0
- package/dist/services/agent-guide/adapters/claude-code.js +144 -3
- package/dist/services/agent-guide/adapters/cursor-cli.js +135 -3
- package/dist/services/agent-guide/adapters/generic-mcp.js +159 -3
- package/dist/services/agent-guide/adapters/index.js +30 -1
- package/dist/services/agent-guide/agent-guide-service.js +148 -1
- package/dist/services/agent-guide/index.js +5 -1
- package/dist/services/build.js +140 -1
- package/dist/services/ci-check/ci-check-service.js +393 -1
- package/dist/services/ci-check/index.js +2 -1
- package/dist/services/ci-check/types.js +28 -1
- package/dist/services/clean.js +71 -1
- package/dist/services/config.js +76 -1
- package/dist/services/deps.js +62 -1
- package/dist/services/diff.js +33 -1
- package/dist/services/doctor/checks/ai.js +118 -2
- package/dist/services/doctor/checks/cli.js +146 -1
- package/dist/services/doctor/checks/config.js +170 -1
- package/dist/services/doctor/checks/deps.js +180 -1
- package/dist/services/doctor/checks/index.js +6 -1
- package/dist/services/doctor/checks/mcp.js +144 -1
- package/dist/services/doctor/checks/workspace.js +243 -1
- package/dist/services/doctor/doctor-service.js +115 -2
- package/dist/services/doctor/index.js +2 -1
- package/dist/services/doctor/types.js +26 -1
- package/dist/services/implementation/discovery.js +143 -2
- package/dist/services/implementation/index.js +2 -1
- package/dist/services/implementation/resolver.js +223 -1
- package/dist/services/index.js +53 -1
- package/dist/services/integrity-diagram.js +274 -6
- package/dist/services/integrity.js +272 -1
- package/dist/services/list.js +35 -1
- package/dist/services/openapi/export-service.js +51 -2
- package/dist/services/openapi/import-service.js +75 -1
- package/dist/services/openapi/index.js +4 -1
- package/dist/services/openapi/sync-service.js +121 -1
- package/dist/services/openapi/validate-service.js +130 -1
- package/dist/services/regenerator.js +23 -1
- package/dist/services/registry.js +73 -1
- package/dist/services/setup/config-generators.js +113 -26
- package/dist/services/setup/file-merger.js +60 -2
- package/dist/services/setup/index.js +4 -1
- package/dist/services/setup/setup-service.js +95 -1
- package/dist/services/setup/targets/agents-md.js +46 -1
- package/dist/services/setup/targets/cli-config.js +59 -1
- package/dist/services/setup/targets/cursor-rules.js +47 -1
- package/dist/services/setup/targets/mcp-claude.js +59 -1
- package/dist/services/setup/targets/mcp-cursor.js +58 -1
- package/dist/services/setup/targets/vscode-settings.js +62 -1
- package/dist/services/setup/types.js +26 -1
- package/dist/services/sync.js +62 -1
- package/dist/services/test.js +30 -1
- package/dist/services/validate-implementation.js +69 -1
- package/dist/services/validate.js +47 -1
- package/dist/services/verification-cache/adapters/filesystem.js +121 -1
- package/dist/services/verification-cache/adapters/in-memory.js +45 -1
- package/dist/services/verification-cache/adapters/index.js +3 -1
- package/dist/services/verification-cache/adapters/workspace-state.js +90 -1
- package/dist/services/verification-cache/cache-service.js +255 -1
- package/dist/services/verification-cache/index.js +6 -1
- package/dist/services/verification-cache/types.js +15 -1
- package/dist/services/verify/ai-verifier.js +336 -9
- package/dist/services/verify/behavior-verifier.js +185 -1
- package/dist/services/verify/index.js +4 -1
- package/dist/services/verify/structure-verifier.js +195 -2
- package/dist/services/verify/verify-service.js +203 -3
- package/dist/services/watch.js +31 -1
- package/dist/services/workspace-info.js +102 -2
- package/dist/templates/app-config.template.js +101 -28
- package/dist/templates/data-view.template.js +42 -27
- package/dist/templates/event.template.js +29 -14
- package/dist/templates/experiment.template.js +77 -51
- package/dist/templates/handler.template.js +53 -17
- package/dist/templates/index.js +36 -1
- package/dist/templates/integration.template.js +134 -50
- package/dist/templates/knowledge.template.js +62 -21
- package/dist/templates/migration.template.js +50 -26
- package/dist/templates/operation.template.js +44 -28
- package/dist/templates/presentation.template.js +46 -20
- package/dist/templates/telemetry.template.js +74 -53
- package/dist/templates/workflow-runner.template.js +12 -6
- package/dist/templates/workflow.template.js +51 -24
- package/package.json +13 -9
- package/dist/adapters/index.d.ts +0 -7
- package/dist/ports/index.d.ts +0 -5
- package/dist/services/agent-guide/index.d.ts +0 -6
- package/dist/services/ci-check/index.d.ts +0 -2
- package/dist/services/doctor/index.d.ts +0 -2
- package/dist/services/implementation/index.d.ts +0 -3
- package/dist/services/index.d.ts +0 -56
- package/dist/services/openapi/index.d.ts +0 -5
- package/dist/services/verification-cache/adapters/index.d.ts +0 -3
- package/dist/services/verification-cache/index.d.ts +0 -6
- package/dist/services/verify/index.d.ts +0 -5
|
@@ -1 +1,69 @@
|
|
|
1
|
-
import{scanSpecSource
|
|
1
|
+
import { scanSpecSource } from "../modules/contractspec-workspace/dist/analysis/spec-scan.js";
|
|
2
|
+
|
|
3
|
+
//#region src/services/validate-implementation.ts
|
|
4
|
+
/**
|
|
5
|
+
* Implementation validation service (handlers + tests).
|
|
6
|
+
*
|
|
7
|
+
* Deterministic, static checks intended for reuse across CLI/VSCode/web tooling.
|
|
8
|
+
* This does NOT execute spec modules.
|
|
9
|
+
*/
|
|
10
|
+
function toKebabCase(value) {
|
|
11
|
+
return value.replace(/\./g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
function toPascalCase(value) {
|
|
14
|
+
return value.split(/[-_.]/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
15
|
+
}
|
|
16
|
+
async function validateImplementationFiles(specFile, adapters, config, options = {}) {
|
|
17
|
+
const { fs } = adapters;
|
|
18
|
+
const errors = [];
|
|
19
|
+
const warnings = [];
|
|
20
|
+
if (!await fs.exists(specFile)) return {
|
|
21
|
+
valid: false,
|
|
22
|
+
errors: [`Spec file not found: ${specFile}`],
|
|
23
|
+
warnings: [],
|
|
24
|
+
expected: {}
|
|
25
|
+
};
|
|
26
|
+
const scan = scanSpecSource(await fs.readFile(specFile), specFile);
|
|
27
|
+
const specName = scan.name ?? fs.basename(specFile).replace(/\.[jt]s$/, "");
|
|
28
|
+
const outRoot = options.outputDir ?? config.outputDir ?? "./src";
|
|
29
|
+
const kebab = toKebabCase(specName);
|
|
30
|
+
const expected = {};
|
|
31
|
+
if (scan.specType === "operation") {
|
|
32
|
+
expected.handlerPath = fs.join(outRoot, "handlers", `${kebab}.handler.ts`);
|
|
33
|
+
expected.handlerTestPath = fs.join(outRoot, "handlers", `${kebab}.handler.test.ts`);
|
|
34
|
+
}
|
|
35
|
+
if (scan.specType === "presentation") {
|
|
36
|
+
expected.componentPath = fs.join(outRoot, "components", `${kebab}.tsx`);
|
|
37
|
+
expected.componentTestPath = fs.join(outRoot, "components", `${kebab}.test.tsx`);
|
|
38
|
+
}
|
|
39
|
+
if (scan.specType === "form") {
|
|
40
|
+
expected.formPath = fs.join(outRoot, "forms", `${kebab}.form.tsx`);
|
|
41
|
+
expected.formTestPath = fs.join(outRoot, "forms", `${kebab}.form.test.tsx`);
|
|
42
|
+
}
|
|
43
|
+
if (options.checkHandlers && expected.handlerPath) if (!await fs.exists(expected.handlerPath)) errors.push(`Missing handler file: ${expected.handlerPath}`);
|
|
44
|
+
else {
|
|
45
|
+
const handlerCode = await fs.readFile(expected.handlerPath);
|
|
46
|
+
const expectedSpecVar = `${toPascalCase(specName.split(".").pop() ?? specName)}Spec`;
|
|
47
|
+
const hasContractHandlerType = /ContractHandler<\s*typeof\s+\w+\s*>/.test(handlerCode);
|
|
48
|
+
const referencesExpectedSpec = (/* @__PURE__ */ new RegExp(`typeof\\s+${expectedSpecVar}\\b`)).test(handlerCode);
|
|
49
|
+
if (!hasContractHandlerType) warnings.push(`Handler does not appear to type itself as ContractHandler<typeof Spec>: ${expected.handlerPath}`);
|
|
50
|
+
else if (!referencesExpectedSpec) warnings.push(`Handler ContractHandler typing does not reference expected spec var (${expectedSpecVar}): ${expected.handlerPath}`);
|
|
51
|
+
}
|
|
52
|
+
if (options.checkTests) {
|
|
53
|
+
const candidateTests = [
|
|
54
|
+
expected.handlerTestPath,
|
|
55
|
+
expected.componentTestPath,
|
|
56
|
+
expected.formTestPath
|
|
57
|
+
].filter((p) => typeof p === "string");
|
|
58
|
+
for (const testPath of candidateTests) if (!await fs.exists(testPath)) errors.push(`Missing test file: ${testPath}`);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
valid: errors.length === 0,
|
|
62
|
+
errors,
|
|
63
|
+
warnings,
|
|
64
|
+
expected
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { validateImplementationFiles };
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
import{validateSpecStructure
|
|
1
|
+
import { validateSpecStructure } from "../modules/contractspec-workspace/dist/analysis/validate/spec-structure.js";
|
|
2
|
+
|
|
3
|
+
//#region src/services/validate.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validation service.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validate a spec file.
|
|
9
|
+
*/
|
|
10
|
+
async function validateSpec(specFile, adapters, options = {}) {
|
|
11
|
+
const { fs } = adapters;
|
|
12
|
+
if (!await fs.exists(specFile)) return {
|
|
13
|
+
valid: false,
|
|
14
|
+
errors: [`Spec file not found: ${specFile}`],
|
|
15
|
+
warnings: []
|
|
16
|
+
};
|
|
17
|
+
const specCode = await fs.readFile(specFile);
|
|
18
|
+
const fileName = fs.basename(specFile);
|
|
19
|
+
const allErrors = [];
|
|
20
|
+
const allWarnings = [];
|
|
21
|
+
let structureResult;
|
|
22
|
+
if (!options.skipStructure) {
|
|
23
|
+
structureResult = validateSpecStructure(specCode, fileName);
|
|
24
|
+
allErrors.push(...structureResult.errors);
|
|
25
|
+
allWarnings.push(...structureResult.warnings);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
valid: allErrors.length === 0,
|
|
29
|
+
structureResult,
|
|
30
|
+
errors: allErrors,
|
|
31
|
+
warnings: allWarnings
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate multiple spec files.
|
|
36
|
+
*/
|
|
37
|
+
async function validateSpecs(specFiles, adapters, options = {}) {
|
|
38
|
+
const results = /* @__PURE__ */ new Map();
|
|
39
|
+
for (const specFile of specFiles) {
|
|
40
|
+
const result = await validateSpec(specFile, adapters, options);
|
|
41
|
+
results.set(specFile, result);
|
|
42
|
+
}
|
|
43
|
+
return results;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { validateSpec, validateSpecs };
|
|
@@ -1 +1,121 @@
|
|
|
1
|
-
import{__require
|
|
1
|
+
import { __require } from "../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
4
|
+
|
|
5
|
+
//#region src/services/verification-cache/adapters/filesystem.ts
|
|
6
|
+
/**
|
|
7
|
+
* Filesystem cache storage adapter.
|
|
8
|
+
*
|
|
9
|
+
* Stores cache entries in a JSON file for CLI and CI environments.
|
|
10
|
+
* Uses atomic writes to prevent corruption.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Default cache file location.
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_CACHE_FILE = ".contractspec/verification-cache.json";
|
|
16
|
+
const CURRENT_VERSION = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Filesystem storage adapter.
|
|
19
|
+
*/
|
|
20
|
+
var FileSystemCacheStorage = class {
|
|
21
|
+
filePath;
|
|
22
|
+
cache;
|
|
23
|
+
isDirty = false;
|
|
24
|
+
constructor(filePath, workspaceRoot) {
|
|
25
|
+
const root = workspaceRoot ?? process.cwd();
|
|
26
|
+
this.filePath = filePath ?? join(root, DEFAULT_CACHE_FILE);
|
|
27
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
28
|
+
this.loadSync();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Load cache from disk synchronously.
|
|
32
|
+
*/
|
|
33
|
+
loadSync() {
|
|
34
|
+
try {
|
|
35
|
+
if (!existsSync(this.filePath)) return;
|
|
36
|
+
const content = readFileSync(this.filePath, "utf-8");
|
|
37
|
+
const data = JSON.parse(content);
|
|
38
|
+
if (data.version !== CURRENT_VERSION) return;
|
|
39
|
+
for (const [key, entry] of Object.entries(data.entries)) this.cache.set(key, entry);
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Save cache to disk.
|
|
44
|
+
*/
|
|
45
|
+
saveSync() {
|
|
46
|
+
if (!this.isDirty) return;
|
|
47
|
+
try {
|
|
48
|
+
const dir = dirname(this.filePath);
|
|
49
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
50
|
+
const data = {
|
|
51
|
+
version: CURRENT_VERSION,
|
|
52
|
+
entries: Object.fromEntries(this.cache.entries())
|
|
53
|
+
};
|
|
54
|
+
const tempPath = `${this.filePath}.tmp`;
|
|
55
|
+
writeFileSync(tempPath, JSON.stringify(data, null, 2), "utf-8");
|
|
56
|
+
const { renameSync } = __require("fs");
|
|
57
|
+
renameSync(tempPath, this.filePath);
|
|
58
|
+
this.isDirty = false;
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
61
|
+
async get(key) {
|
|
62
|
+
return this.cache.get(key) ?? null;
|
|
63
|
+
}
|
|
64
|
+
async set(key, entry) {
|
|
65
|
+
this.cache.set(key, entry);
|
|
66
|
+
this.isDirty = true;
|
|
67
|
+
this.saveSync();
|
|
68
|
+
}
|
|
69
|
+
async delete(key) {
|
|
70
|
+
const existed = this.cache.delete(key);
|
|
71
|
+
if (existed) {
|
|
72
|
+
this.isDirty = true;
|
|
73
|
+
this.saveSync();
|
|
74
|
+
}
|
|
75
|
+
return existed;
|
|
76
|
+
}
|
|
77
|
+
async has(key) {
|
|
78
|
+
return this.cache.has(key);
|
|
79
|
+
}
|
|
80
|
+
async keys() {
|
|
81
|
+
return Array.from(this.cache.keys());
|
|
82
|
+
}
|
|
83
|
+
async clear() {
|
|
84
|
+
this.cache.clear();
|
|
85
|
+
this.isDirty = true;
|
|
86
|
+
this.saveSync();
|
|
87
|
+
}
|
|
88
|
+
async stats() {
|
|
89
|
+
let fileSize = 0;
|
|
90
|
+
try {
|
|
91
|
+
if (existsSync(this.filePath)) fileSize = statSync(this.filePath).size;
|
|
92
|
+
} catch {}
|
|
93
|
+
return {
|
|
94
|
+
entryCount: this.cache.size,
|
|
95
|
+
memoryUsage: fileSize
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Force save any pending changes.
|
|
100
|
+
*/
|
|
101
|
+
flush() {
|
|
102
|
+
this.saveSync();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Reload cache from disk.
|
|
106
|
+
*/
|
|
107
|
+
reload() {
|
|
108
|
+
this.cache.clear();
|
|
109
|
+
this.loadSync();
|
|
110
|
+
this.isDirty = false;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Create a filesystem cache storage adapter.
|
|
115
|
+
*/
|
|
116
|
+
function createFileSystemCacheStorage(filePath, workspaceRoot) {
|
|
117
|
+
return new FileSystemCacheStorage(filePath, workspaceRoot);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { FileSystemCacheStorage, createFileSystemCacheStorage };
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/services/verification-cache/adapters/in-memory.ts
|
|
2
|
+
/**
|
|
3
|
+
* In-memory storage adapter using a Map.
|
|
4
|
+
*/
|
|
5
|
+
var InMemoryCacheStorage = class {
|
|
6
|
+
cache = /* @__PURE__ */ new Map();
|
|
7
|
+
async get(key) {
|
|
8
|
+
return this.cache.get(key) ?? null;
|
|
9
|
+
}
|
|
10
|
+
async set(key, entry) {
|
|
11
|
+
this.cache.set(key, entry);
|
|
12
|
+
}
|
|
13
|
+
async delete(key) {
|
|
14
|
+
return this.cache.delete(key);
|
|
15
|
+
}
|
|
16
|
+
async has(key) {
|
|
17
|
+
return this.cache.has(key);
|
|
18
|
+
}
|
|
19
|
+
async keys() {
|
|
20
|
+
return Array.from(this.cache.keys());
|
|
21
|
+
}
|
|
22
|
+
async clear() {
|
|
23
|
+
this.cache.clear();
|
|
24
|
+
}
|
|
25
|
+
async stats() {
|
|
26
|
+
let memoryUsage = 0;
|
|
27
|
+
for (const [key, value] of this.cache.entries()) {
|
|
28
|
+
memoryUsage += key.length * 2;
|
|
29
|
+
memoryUsage += JSON.stringify(value).length * 2;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
entryCount: this.cache.size,
|
|
33
|
+
memoryUsage
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Create an in-memory cache storage adapter.
|
|
39
|
+
*/
|
|
40
|
+
function createInMemoryCacheStorage() {
|
|
41
|
+
return new InMemoryCacheStorage();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { InMemoryCacheStorage, createInMemoryCacheStorage };
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{InMemoryCacheStorage
|
|
1
|
+
import { InMemoryCacheStorage, createInMemoryCacheStorage } from "./in-memory.js";
|
|
2
|
+
import { FileSystemCacheStorage, createFileSystemCacheStorage } from "./filesystem.js";
|
|
3
|
+
import { WorkspaceStateCacheStorage, createWorkspaceStateCacheStorage } from "./workspace-state.js";
|
|
@@ -1 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/services/verification-cache/adapters/workspace-state.ts
|
|
2
|
+
/**
|
|
3
|
+
* Cache key prefix to avoid collisions.
|
|
4
|
+
*/
|
|
5
|
+
const CACHE_PREFIX = "contractspec.verification-cache.";
|
|
6
|
+
/**
|
|
7
|
+
* Index key for tracking all cache keys.
|
|
8
|
+
*/
|
|
9
|
+
const INDEX_KEY = `${CACHE_PREFIX}__index__`;
|
|
10
|
+
/**
|
|
11
|
+
* Workspace state storage adapter.
|
|
12
|
+
*/
|
|
13
|
+
var WorkspaceStateCacheStorage = class {
|
|
14
|
+
store;
|
|
15
|
+
keyIndex;
|
|
16
|
+
constructor(store) {
|
|
17
|
+
this.store = store;
|
|
18
|
+
this.keyIndex = new Set(this.loadKeyIndex());
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Load the key index from storage.
|
|
22
|
+
*/
|
|
23
|
+
loadKeyIndex() {
|
|
24
|
+
try {
|
|
25
|
+
return this.store.get(INDEX_KEY) ?? [];
|
|
26
|
+
} catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save the key index to storage.
|
|
32
|
+
*/
|
|
33
|
+
async saveKeyIndex() {
|
|
34
|
+
await this.store.update(INDEX_KEY, Array.from(this.keyIndex));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the storage key for a cache key.
|
|
38
|
+
*/
|
|
39
|
+
getStorageKey(key) {
|
|
40
|
+
return `${CACHE_PREFIX}${key}`;
|
|
41
|
+
}
|
|
42
|
+
async get(key) {
|
|
43
|
+
const storageKey = this.getStorageKey(key);
|
|
44
|
+
return this.store.get(storageKey) ?? null;
|
|
45
|
+
}
|
|
46
|
+
async set(key, entry) {
|
|
47
|
+
const storageKey = this.getStorageKey(key);
|
|
48
|
+
await this.store.update(storageKey, entry);
|
|
49
|
+
if (!this.keyIndex.has(key)) {
|
|
50
|
+
this.keyIndex.add(key);
|
|
51
|
+
await this.saveKeyIndex();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async delete(key) {
|
|
55
|
+
const storageKey = this.getStorageKey(key);
|
|
56
|
+
const existed = this.keyIndex.has(key);
|
|
57
|
+
if (existed) {
|
|
58
|
+
await this.store.update(storageKey, void 0);
|
|
59
|
+
this.keyIndex.delete(key);
|
|
60
|
+
await this.saveKeyIndex();
|
|
61
|
+
}
|
|
62
|
+
return existed;
|
|
63
|
+
}
|
|
64
|
+
async has(key) {
|
|
65
|
+
return this.keyIndex.has(key);
|
|
66
|
+
}
|
|
67
|
+
async keys() {
|
|
68
|
+
return Array.from(this.keyIndex);
|
|
69
|
+
}
|
|
70
|
+
async clear() {
|
|
71
|
+
for (const key of this.keyIndex) {
|
|
72
|
+
const storageKey = this.getStorageKey(key);
|
|
73
|
+
await this.store.update(storageKey, void 0);
|
|
74
|
+
}
|
|
75
|
+
this.keyIndex.clear();
|
|
76
|
+
await this.saveKeyIndex();
|
|
77
|
+
}
|
|
78
|
+
async stats() {
|
|
79
|
+
return { entryCount: this.keyIndex.size };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Create a workspace state cache storage adapter.
|
|
84
|
+
*/
|
|
85
|
+
function createWorkspaceStateCacheStorage(store) {
|
|
86
|
+
return new WorkspaceStateCacheStorage(store);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { WorkspaceStateCacheStorage, createWorkspaceStateCacheStorage };
|
|
@@ -1 +1,255 @@
|
|
|
1
|
-
import{DEFAULT_CACHE_CONFIG
|
|
1
|
+
import { DEFAULT_CACHE_CONFIG } from "./types.js";
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
|
|
4
|
+
//#region src/services/verification-cache/cache-service.ts
|
|
5
|
+
/**
|
|
6
|
+
* Verification cache service.
|
|
7
|
+
*
|
|
8
|
+
* Provides content-hash based caching for verification results
|
|
9
|
+
* to avoid redundant checks and reduce AI costs.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Compute SHA256 hash of content.
|
|
13
|
+
*/
|
|
14
|
+
function computeContentHash(content) {
|
|
15
|
+
return createHash("sha256").update(content).digest("hex");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert cache key to string for storage.
|
|
19
|
+
*/
|
|
20
|
+
function cacheKeyToString(key) {
|
|
21
|
+
const parts = [
|
|
22
|
+
`spec:${key.specHash.substring(0, 16)}`,
|
|
23
|
+
`impl:${key.implHash.substring(0, 16)}`,
|
|
24
|
+
`tier:${key.tier}`
|
|
25
|
+
];
|
|
26
|
+
if (key.aiModelVersion) parts.push(`model:${key.aiModelVersion}`);
|
|
27
|
+
return parts.join("|");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse cache key string back to object.
|
|
31
|
+
*/
|
|
32
|
+
function stringToCacheKey(str) {
|
|
33
|
+
try {
|
|
34
|
+
const parts = str.split("|");
|
|
35
|
+
const keyMap = /* @__PURE__ */ new Map();
|
|
36
|
+
for (const part of parts) {
|
|
37
|
+
const [prefix, value] = part.split(":");
|
|
38
|
+
if (prefix && value) keyMap.set(prefix, value);
|
|
39
|
+
}
|
|
40
|
+
const specHash = keyMap.get("spec");
|
|
41
|
+
const implHash = keyMap.get("impl");
|
|
42
|
+
const tier = keyMap.get("tier");
|
|
43
|
+
if (!specHash || !implHash || !tier) return null;
|
|
44
|
+
return {
|
|
45
|
+
specHash,
|
|
46
|
+
implHash,
|
|
47
|
+
tier,
|
|
48
|
+
aiModelVersion: keyMap.get("model")
|
|
49
|
+
};
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get TTL for a specific tier.
|
|
56
|
+
*/
|
|
57
|
+
function getTtlForTier(tier, config) {
|
|
58
|
+
switch (tier) {
|
|
59
|
+
case "structure": return config.structureTtlMs;
|
|
60
|
+
case "behavior": return config.behaviorTtlMs;
|
|
61
|
+
case "ai_review": return config.aiTtlMs;
|
|
62
|
+
default: return config.defaultTtlMs;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Verification cache service.
|
|
67
|
+
*/
|
|
68
|
+
var VerificationCacheService = class {
|
|
69
|
+
storage;
|
|
70
|
+
config;
|
|
71
|
+
stats;
|
|
72
|
+
constructor(storage, config = {}) {
|
|
73
|
+
this.storage = storage;
|
|
74
|
+
this.config = {
|
|
75
|
+
...DEFAULT_CACHE_CONFIG,
|
|
76
|
+
...config
|
|
77
|
+
};
|
|
78
|
+
this.stats = {
|
|
79
|
+
hits: 0,
|
|
80
|
+
misses: 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a cache key from spec and implementation content.
|
|
85
|
+
*/
|
|
86
|
+
createKey(specContent, implContent, tier, aiModelVersion) {
|
|
87
|
+
return {
|
|
88
|
+
specHash: computeContentHash(specContent),
|
|
89
|
+
implHash: computeContentHash(implContent),
|
|
90
|
+
tier,
|
|
91
|
+
aiModelVersion: tier === "ai_review" ? aiModelVersion : void 0
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Look up a cached verification result.
|
|
96
|
+
*/
|
|
97
|
+
async lookup(key) {
|
|
98
|
+
const keyStr = cacheKeyToString(key);
|
|
99
|
+
const entry = await this.storage.get(keyStr);
|
|
100
|
+
if (!entry) {
|
|
101
|
+
this.stats.misses++;
|
|
102
|
+
return {
|
|
103
|
+
hit: false,
|
|
104
|
+
reason: "not_found"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (entry.meta.expiresAt) {
|
|
108
|
+
const expiresAt = new Date(entry.meta.expiresAt).getTime();
|
|
109
|
+
if (Date.now() > expiresAt) {
|
|
110
|
+
this.stats.misses++;
|
|
111
|
+
await this.storage.delete(keyStr);
|
|
112
|
+
return {
|
|
113
|
+
hit: false,
|
|
114
|
+
reason: "expired"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (entry.key.specHash !== key.specHash) {
|
|
119
|
+
this.stats.misses++;
|
|
120
|
+
return {
|
|
121
|
+
hit: false,
|
|
122
|
+
reason: "spec_changed"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (entry.key.implHash !== key.implHash) {
|
|
126
|
+
this.stats.misses++;
|
|
127
|
+
return {
|
|
128
|
+
hit: false,
|
|
129
|
+
reason: "impl_changed"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (key.tier === "ai_review" && key.aiModelVersion && entry.key.aiModelVersion !== key.aiModelVersion) {
|
|
133
|
+
this.stats.misses++;
|
|
134
|
+
return {
|
|
135
|
+
hit: false,
|
|
136
|
+
reason: "model_changed"
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
this.stats.hits++;
|
|
140
|
+
return {
|
|
141
|
+
hit: true,
|
|
142
|
+
entry
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Store a verification result in cache.
|
|
147
|
+
*/
|
|
148
|
+
async store(key, result, options = {}) {
|
|
149
|
+
const keyStr = cacheKeyToString(key);
|
|
150
|
+
const ttl = getTtlForTier(key.tier, this.config);
|
|
151
|
+
const entry = {
|
|
152
|
+
key,
|
|
153
|
+
result,
|
|
154
|
+
meta: {
|
|
155
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
156
|
+
expiresAt: new Date(Date.now() + ttl).toISOString(),
|
|
157
|
+
dependencies: options.dependencies ?? [],
|
|
158
|
+
specName: options.specName,
|
|
159
|
+
implPath: options.implPath
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
await this.storage.set(keyStr, entry);
|
|
163
|
+
await this.pruneIfNeeded();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Invalidate cache entries for a specific file.
|
|
167
|
+
* Used when a file changes to invalidate dependent caches.
|
|
168
|
+
*/
|
|
169
|
+
async invalidateForFile(filePath) {
|
|
170
|
+
if (!this.config.transitiveInvalidation) return 0;
|
|
171
|
+
const keys = await this.storage.keys();
|
|
172
|
+
let invalidated = 0;
|
|
173
|
+
for (const keyStr of keys) {
|
|
174
|
+
const entry = await this.storage.get(keyStr);
|
|
175
|
+
if (!entry) continue;
|
|
176
|
+
if (entry.meta.dependencies.includes(filePath)) {
|
|
177
|
+
await this.storage.delete(keyStr);
|
|
178
|
+
invalidated++;
|
|
179
|
+
}
|
|
180
|
+
if (entry.meta.specName === filePath || entry.meta.implPath === filePath) {
|
|
181
|
+
await this.storage.delete(keyStr);
|
|
182
|
+
invalidated++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return invalidated;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Invalidate all cache entries for a specific spec.
|
|
189
|
+
*/
|
|
190
|
+
async invalidateForSpec(specHash) {
|
|
191
|
+
const keys = await this.storage.keys();
|
|
192
|
+
let invalidated = 0;
|
|
193
|
+
for (const keyStr of keys) {
|
|
194
|
+
const parsed = stringToCacheKey(keyStr);
|
|
195
|
+
if (parsed && parsed.specHash.startsWith(specHash.substring(0, 16))) {
|
|
196
|
+
await this.storage.delete(keyStr);
|
|
197
|
+
invalidated++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return invalidated;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Clear all cache entries.
|
|
204
|
+
*/
|
|
205
|
+
async clear() {
|
|
206
|
+
await this.storage.clear();
|
|
207
|
+
this.stats = {
|
|
208
|
+
hits: 0,
|
|
209
|
+
misses: 0
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get cache statistics.
|
|
214
|
+
*/
|
|
215
|
+
async getStats() {
|
|
216
|
+
const storageStats = await this.storage.stats?.();
|
|
217
|
+
return {
|
|
218
|
+
totalEntries: storageStats?.entryCount ?? (await this.storage.keys()).length,
|
|
219
|
+
hits: this.stats.hits,
|
|
220
|
+
misses: this.stats.misses,
|
|
221
|
+
hitRate: this.stats.hits + this.stats.misses > 0 ? Math.round(this.stats.hits / (this.stats.hits + this.stats.misses) * 100) : 0,
|
|
222
|
+
memoryUsage: storageStats?.memoryUsage
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Prune cache if over the maximum entry limit.
|
|
227
|
+
*/
|
|
228
|
+
async pruneIfNeeded() {
|
|
229
|
+
const keys = await this.storage.keys();
|
|
230
|
+
if (keys.length <= this.config.maxEntries) return;
|
|
231
|
+
const entries = [];
|
|
232
|
+
for (const keyStr of keys) {
|
|
233
|
+
const entry = await this.storage.get(keyStr);
|
|
234
|
+
if (entry) entries.push({
|
|
235
|
+
key: keyStr,
|
|
236
|
+
createdAt: new Date(entry.meta.createdAt).getTime()
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
entries.sort((a, b) => a.createdAt - b.createdAt);
|
|
240
|
+
const toRemove = entries.length - this.config.maxEntries;
|
|
241
|
+
for (let i = 0; i < toRemove; i++) {
|
|
242
|
+
const entry = entries[i];
|
|
243
|
+
if (entry) await this.storage.delete(entry.key);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Create a verification cache service with the given storage adapter.
|
|
249
|
+
*/
|
|
250
|
+
function createVerificationCacheService(storage, config) {
|
|
251
|
+
return new VerificationCacheService(storage, config);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//#endregion
|
|
255
|
+
export { VerificationCacheService, cacheKeyToString, computeContentHash, createVerificationCacheService, stringToCacheKey };
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DEFAULT_CACHE_CONFIG } from "./types.js";
|
|
2
|
+
import { VerificationCacheService, cacheKeyToString, computeContentHash, createVerificationCacheService, stringToCacheKey } from "./cache-service.js";
|
|
3
|
+
import { InMemoryCacheStorage, createInMemoryCacheStorage } from "./adapters/in-memory.js";
|
|
4
|
+
import { FileSystemCacheStorage, createFileSystemCacheStorage } from "./adapters/filesystem.js";
|
|
5
|
+
import { WorkspaceStateCacheStorage, createWorkspaceStateCacheStorage } from "./adapters/workspace-state.js";
|
|
6
|
+
import "./adapters/index.js";
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/services/verification-cache/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Default cache configuration.
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULT_CACHE_CONFIG = {
|
|
6
|
+
maxEntries: 1e3,
|
|
7
|
+
defaultTtlMs: 1440 * 60 * 1e3,
|
|
8
|
+
structureTtlMs: 10080 * 60 * 1e3,
|
|
9
|
+
behaviorTtlMs: 1440 * 60 * 1e3,
|
|
10
|
+
aiTtlMs: 1440 * 60 * 1e3,
|
|
11
|
+
transitiveInvalidation: true
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { DEFAULT_CACHE_CONFIG };
|