caisson-cli 0.0.0-stage → 0.1.0
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.math-mvp.md +28 -0
- package/README.md +37 -2
- package/dist/admin/adminRoutes.d.ts +10 -0
- package/dist/admin/adminRoutes.js +194 -0
- package/dist/admin/adminRoutes.js.map +1 -0
- package/dist/admin/index.d.ts +2 -0
- package/dist/admin/index.js +4 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/workspaceAdmin.d.ts +417 -0
- package/dist/admin/workspaceAdmin.js +569 -0
- package/dist/admin/workspaceAdmin.js.map +1 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +3 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics/metrics.d.ts +105 -0
- package/dist/analytics/metrics.js +837 -0
- package/dist/analytics/metrics.js.map +1 -0
- package/dist/audit/index.d.ts +4 -0
- package/dist/audit/index.js +6 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/pipeline.d.ts +90 -0
- package/dist/audit/pipeline.js +424 -0
- package/dist/audit/pipeline.js.map +1 -0
- package/dist/audit/receiptSchema.d.ts +441 -0
- package/dist/audit/receiptSchema.js +208 -0
- package/dist/audit/receiptSchema.js.map +1 -0
- package/dist/audit/stageA.d.ts +50 -0
- package/dist/audit/stageA.js +218 -0
- package/dist/audit/stageA.js.map +1 -0
- package/dist/audit/stageB.d.ts +48 -0
- package/dist/audit/stageB.js +113 -0
- package/dist/audit/stageB.js.map +1 -0
- package/dist/auth/agentAuth.d.ts +18 -0
- package/dist/auth/agentAuth.js +59 -0
- package/dist/auth/agentAuth.js.map +1 -0
- package/dist/auth/agentCardSigner.d.ts +55 -0
- package/dist/auth/agentCardSigner.js +188 -0
- package/dist/auth/agentCardSigner.js.map +1 -0
- package/dist/billing/billingRoutes.d.ts +11 -0
- package/dist/billing/billingRoutes.js +303 -0
- package/dist/billing/billingRoutes.js.map +1 -0
- package/dist/billing/bountyRoutes.d.ts +9 -0
- package/dist/billing/bountyRoutes.js +332 -0
- package/dist/billing/bountyRoutes.js.map +1 -0
- package/dist/billing/index.d.ts +3 -0
- package/dist/billing/index.js +4 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing/subscriptions.d.ts +226 -0
- package/dist/billing/subscriptions.js +673 -0
- package/dist/billing/subscriptions.js.map +1 -0
- package/dist/cli/caissonCli.d.ts +10 -0
- package/dist/cli/caissonCli.js +471 -0
- package/dist/cli/caissonCli.js.map +1 -0
- package/dist/cli/inviteCard.d.ts +12 -0
- package/dist/cli/inviteCard.js +49 -0
- package/dist/cli/inviteCard.js.map +1 -0
- package/dist/cli/mcpProxy.d.ts +36 -0
- package/dist/cli/mcpProxy.js +292 -0
- package/dist/cli/mcpProxy.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +28 -0
- package/dist/config.js.map +1 -0
- package/dist/db/adapter.d.ts +210 -0
- package/dist/db/adapter.js +769 -0
- package/dist/db/adapter.js.map +1 -0
- package/dist/db/sqlite.d.ts +7 -0
- package/dist/db/sqlite.js +60 -0
- package/dist/db/sqlite.js.map +1 -0
- package/dist/db/telemetry.d.ts +11 -0
- package/dist/db/telemetry.js +9 -0
- package/dist/db/telemetry.js.map +1 -0
- package/dist/economy/bountyEngine.d.ts +248 -0
- package/dist/economy/bountyEngine.js +836 -0
- package/dist/economy/bountyEngine.js.map +1 -0
- package/dist/economy/index.d.ts +5 -0
- package/dist/economy/index.js +6 -0
- package/dist/economy/index.js.map +1 -0
- package/dist/economy/scLedger.d.ts +183 -0
- package/dist/economy/scLedger.js +528 -0
- package/dist/economy/scLedger.js.map +1 -0
- package/dist/economy/scMinting.d.ts +177 -0
- package/dist/economy/scMinting.js +659 -0
- package/dist/economy/scMinting.js.map +1 -0
- package/dist/economy/scSinks.d.ts +135 -0
- package/dist/economy/scSinks.js +314 -0
- package/dist/economy/scSinks.js.map +1 -0
- package/dist/economy/usdLedger.d.ts +211 -0
- package/dist/economy/usdLedger.js +604 -0
- package/dist/economy/usdLedger.js.map +1 -0
- package/dist/mcp/handlers.d.ts +134 -0
- package/dist/mcp/handlers.js +781 -0
- package/dist/mcp/handlers.js.map +1 -0
- package/dist/mcp/httpServer.d.ts +25 -0
- package/dist/mcp/httpServer.js +368 -0
- package/dist/mcp/httpServer.js.map +1 -0
- package/dist/mcp/serverFactory.d.ts +4 -0
- package/dist/mcp/serverFactory.js +53 -0
- package/dist/mcp/serverFactory.js.map +1 -0
- package/dist/mcp/stdioServer.d.ts +2 -0
- package/dist/mcp/stdioServer.js +24 -0
- package/dist/mcp/stdioServer.js.map +1 -0
- package/dist/mcp/toolMetadata.d.ts +15 -0
- package/dist/mcp/toolMetadata.js +73 -0
- package/dist/mcp/toolMetadata.js.map +1 -0
- package/dist/memo/artifactIndex.d.ts +51 -0
- package/dist/memo/artifactIndex.js +162 -0
- package/dist/memo/artifactIndex.js.map +1 -0
- package/dist/memo/dependencyBundle.d.ts +33 -0
- package/dist/memo/dependencyBundle.js +86 -0
- package/dist/memo/dependencyBundle.js.map +1 -0
- package/dist/memo/embeddings.d.ts +110 -0
- package/dist/memo/embeddings.js +672 -0
- package/dist/memo/embeddings.js.map +1 -0
- package/dist/packs/foundryEvm.d.ts +21 -0
- package/dist/packs/foundryEvm.js +274 -0
- package/dist/packs/foundryEvm.js.map +1 -0
- package/dist/packs/index.d.ts +8 -0
- package/dist/packs/index.js +19 -0
- package/dist/packs/index.js.map +1 -0
- package/dist/packs/mathLean4.d.ts +7 -0
- package/dist/packs/mathLean4.js +145 -0
- package/dist/packs/mathLean4.js.map +1 -0
- package/dist/packs/rustKani.d.ts +17 -0
- package/dist/packs/rustKani.js +257 -0
- package/dist/packs/rustKani.js.map +1 -0
- package/dist/packs/sdk.d.ts +314 -0
- package/dist/packs/sdk.js +271 -0
- package/dist/packs/sdk.js.map +1 -0
- package/dist/preflight/leanTripwire.d.ts +19 -0
- package/dist/preflight/leanTripwire.js +105 -0
- package/dist/preflight/leanTripwire.js.map +1 -0
- package/dist/storage/blobStore.d.ts +11 -0
- package/dist/storage/blobStore.js +39 -0
- package/dist/storage/blobStore.js.map +1 -0
- package/dist/storage/gitStore.d.ts +68 -0
- package/dist/storage/gitStore.js +228 -0
- package/dist/storage/gitStore.js.map +1 -0
- package/dist/types/errors.d.ts +16 -0
- package/dist/types/errors.js +23 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/schemas.d.ts +453 -0
- package/dist/types/schemas.js +197 -0
- package/dist/types/schemas.js.map +1 -0
- package/dist/web/discoveryRoutes.d.ts +20 -0
- package/dist/web/discoveryRoutes.js +456 -0
- package/dist/web/discoveryRoutes.js.map +1 -0
- package/dist/web/explorer/dagLayout.d.ts +41 -0
- package/dist/web/explorer/dagLayout.js +183 -0
- package/dist/web/explorer/dagLayout.js.map +1 -0
- package/dist/web/explorer/index.d.ts +45 -0
- package/dist/web/explorer/index.js +512 -0
- package/dist/web/explorer/index.js.map +1 -0
- package/dist/web/explorer/renderers.d.ts +35 -0
- package/dist/web/explorer/renderers.js +397 -0
- package/dist/web/explorer/renderers.js.map +1 -0
- package/dist/web/repoBrowser.d.ts +19 -0
- package/dist/web/repoBrowser.js +128 -0
- package/dist/web/repoBrowser.js.map +1 -0
- package/dist/worker/executionAdapter.d.ts +14 -0
- package/dist/worker/executionAdapter.js +162 -0
- package/dist/worker/executionAdapter.js.map +1 -0
- package/dist/worker/finalize.d.ts +21 -0
- package/dist/worker/finalize.js +146 -0
- package/dist/worker/finalize.js.map +1 -0
- package/dist/worker/firecrackerAdapter.d.ts +180 -0
- package/dist/worker/firecrackerAdapter.js +421 -0
- package/dist/worker/firecrackerAdapter.js.map +1 -0
- package/dist/worker/loop.d.ts +56 -0
- package/dist/worker/loop.js +239 -0
- package/dist/worker/loop.js.map +1 -0
- package/dist/worker/postMergeSync.d.ts +17 -0
- package/dist/worker/postMergeSync.js +52 -0
- package/dist/worker/postMergeSync.js.map +1 -0
- package/dist/worker/prepareInput.d.ts +41 -0
- package/dist/worker/prepareInput.js +130 -0
- package/dist/worker/prepareInput.js.map +1 -0
- package/dist/worker/queue.d.ts +83 -0
- package/dist/worker/queue.js +278 -0
- package/dist/worker/queue.js.map +1 -0
- package/dist/worker/sandbox.d.ts +2 -0
- package/dist/worker/sandbox.js +3 -0
- package/dist/worker/sandbox.js.map +1 -0
- package/dist/worker/webhook.d.ts +14 -0
- package/dist/worker/webhook.js +110 -0
- package/dist/worker/webhook.js.map +1 -0
- package/migrations/001_init.sql +193 -0
- package/migrations/002_epic3_scale.sql +34 -0
- package/migrations/003_swarm_credits.sql +153 -0
- package/migrations/004_usd_bounties.sql +216 -0
- package/migrations_pg/001_init.sql +229 -0
- package/migrations_pg/002_multitenant_rls.sql +63 -0
- package/migrations_pg/003_swarm_credits.sql +135 -0
- package/migrations_pg/004_usd_bounties.sql +201 -0
- package/package.json +55 -4
- package/packs/foundry-evm/pack.json +60 -0
- package/packs/foundry-evm/verifier/Dockerfile +9 -0
- package/packs/foundry-evm/verifier/run.py +160 -0
- package/packs/math-lean4/pack.json +68 -0
- package/packs/rust-kani/pack.json +53 -0
- package/packs/rust-kani/verifier/Dockerfile +7 -0
- package/packs/rust-kani/verifier/run.py +159 -0
- package/public/.well-known/agent-card.json +153 -0
- package/public/llms.txt +35 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/mcp/toolMetadata.ts
|
|
2
|
+
// Router-optimized MCP tool metadata & behavioral annotations (Workstream C / Doc 07).
|
|
3
|
+
// Pattern: [Action + Primary Benefit] -> [When to call] -> [When NOT to call / Preconditions] -> [Error recovery]
|
|
4
|
+
export const MCP_TOOL_METADATA = {
|
|
5
|
+
query_cache: {
|
|
6
|
+
name: 'query_cache',
|
|
7
|
+
title: 'Search Verified Cache & Dead Ends',
|
|
8
|
+
description: 'Search the verified Memoization Registry for existing kernel-verified lemmas, scripts, literature checks, and KNOWN DEAD ENDS before starting proof search or code generation. CALL THIS FIRST whenever starting a node, encountering a subgoal blocker, or testing a proof strategy—a single call often eliminates 50k+ tokens of redundant reasoning. Returns content-addressed artifact_ids you MUST pass in submit_artifact.derived_from when reusing results. Filter by environment_version (e.g. "lean4:v4.29.0") for exact compatibility and keep include_dead_ends=true to avoid known traps. Do NOT use this to inspect current node claim leases or DAG structure (use read_graph instead).',
|
|
9
|
+
annotations: {
|
|
10
|
+
title: 'Search Verified Cache & Dead Ends',
|
|
11
|
+
readOnlyHint: true,
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
openWorldHint: false,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
read_graph: {
|
|
18
|
+
name: 'read_graph',
|
|
19
|
+
title: 'Read Workspace Problem DAG',
|
|
20
|
+
description: 'Fetch a compact, context-window-optimized slice of a Workspace Problem DAG: open subgoals, dependency edges, active claim leases, pinned environment_lock_hash, git_head_sha, merge_target, and recent dead-end summaries. CALL THIS BEFORE claim_node to see which nodes are open, whether upstream FormalizationAudit nodes are verified, and which files/commits exist on main. Keep include_payloads=false (default) for orientation; fetch single node specs via claim_node or targeted filters to save context tokens. Do NOT use this for cross-workspace keyword search (use query_cache instead).',
|
|
21
|
+
annotations: {
|
|
22
|
+
title: 'Read Workspace Problem DAG',
|
|
23
|
+
readOnlyHint: true,
|
|
24
|
+
destructiveHint: false,
|
|
25
|
+
idempotentHint: true,
|
|
26
|
+
openWorldHint: false,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
claim_node: {
|
|
30
|
+
name: 'claim_node',
|
|
31
|
+
title: 'Acquire/Renew/Release Node Lease',
|
|
32
|
+
description: "Atomically acquire, renew, or release an exclusive TTL lease on a single DAG node so peer agents do not duplicate your work. CALL THIS AFTER read_graph confirms the node status is 'open' (and any upstream FormalizationAudit parent is 'verified') and BEFORE investing local compute. Save the returned lease_token—it is required to renew, release, or call submit_artifact. On LEASE_CONFLICT (another agent holds an active lease), do NOT retry the same node; call read_graph to pick a different open node. If your run exceeds half the TTL, call with action='renew'. If you abandon the node, call log_dead_end with release_lease=true (preferred) or action='release'.",
|
|
33
|
+
annotations: {
|
|
34
|
+
title: 'Acquire/Renew/Release Node Lease',
|
|
35
|
+
readOnlyHint: false,
|
|
36
|
+
destructiveHint: false,
|
|
37
|
+
idempotentHint: false,
|
|
38
|
+
openWorldHint: false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
submit_artifact: {
|
|
42
|
+
name: 'submit_artifact',
|
|
43
|
+
title: 'Verify & Merge Candidate Artifact',
|
|
44
|
+
description: "Submit a locally prechecked candidate solution to the sandboxed Verification Gate; merges to main and creates a permanent Artifact ONLY if verification returns status='pass'. PRECONDITIONS: (1) You hold an active lease_token on the node; (2) For Lean 4 workspaces, you MUST run 'caisson-lean precheck' locally first and pass its precheck_proof JSON—do NOT submit drafts containing sorry, admit, native_decide, or local compile errors (submissions consume hourly server quota); (3) For merge_target='repo_root' workspaces, you MUST pass base_git_sha from read_graph; (4) List every reused cache artifact_id in derived_from. ERROR RECOVERY: On PRECHECK_FAILED or VERIFICATION_FAILED, read verifier_result.logs and fix locally before resubmitting. On STALE_BASE, call read_graph for the new git_head_sha, rebase your patch on the listed conflicting_paths, and resubmit.",
|
|
45
|
+
annotations: {
|
|
46
|
+
title: 'Verify & Merge Candidate Artifact',
|
|
47
|
+
readOnlyHint: false,
|
|
48
|
+
destructiveHint: false,
|
|
49
|
+
idempotentHint: false,
|
|
50
|
+
openWorldHint: false,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
log_dead_end: {
|
|
54
|
+
name: 'log_dead_end',
|
|
55
|
+
title: 'Record Failed Path / Counterexample',
|
|
56
|
+
description: "Record a failed proof strategy, counterexample script, literature obstruction, or empirical error trace on a node so other agents never waste tokens repeating the same dead end. CALL THIS whenever you abandon an approach after meaningful local investigation, discover a concrete counterexample, or hit an unexpected Lean/Mathlib obstruction. Set release_lease=true (default) if you are moving on to another node so peers can immediately claim it. Prefer structured evidence ('counterexample_script' or 'formal_disproof' when executable; 'empirical_trace' with exact goal state or error output otherwise). Do NOT use this for minor syntax typos or uninvestigated guesses.",
|
|
57
|
+
annotations: {
|
|
58
|
+
title: 'Record Failed Path / Counterexample',
|
|
59
|
+
readOnlyHint: false,
|
|
60
|
+
destructiveHint: false,
|
|
61
|
+
idempotentHint: false,
|
|
62
|
+
openWorldHint: false,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
export const MCP_TOOL_ORDER = [
|
|
67
|
+
'query_cache',
|
|
68
|
+
'read_graph',
|
|
69
|
+
'claim_node',
|
|
70
|
+
'submit_artifact',
|
|
71
|
+
'log_dead_end',
|
|
72
|
+
];
|
|
73
|
+
//# sourceMappingURL=toolMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolMetadata.js","sourceRoot":"","sources":["../../src/mcp/toolMetadata.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,uFAAuF;AACvF,kHAAkH;AAiBlH,MAAM,CAAC,MAAM,iBAAiB,GAAqE;IACjG,WAAW,EAAE;QACX,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,mCAAmC;QAC1C,WAAW,EACT,uqBAAuqB;QACzqB,WAAW,EAAE;YACX,KAAK,EAAE,mCAAmC;YAC1C,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF;IAED,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,4BAA4B;QACnC,WAAW,EACT,4kBAA4kB;QAC9kB,WAAW,EAAE;YACX,KAAK,EAAE,4BAA4B;YACnC,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF;IAED,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,kCAAkC;QACzC,WAAW,EACT,wpBAAwpB;QAC1pB,WAAW,EAAE;YACX,KAAK,EAAE,kCAAkC;YACzC,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,KAAK;SACrB;KACF;IAED,eAAe,EAAE;QACf,IAAI,EAAE,iBAAiB;QACvB,KAAK,EAAE,mCAAmC;QAC1C,WAAW,EACT,o2BAAo2B;QACt2B,WAAW,EAAE;YACX,KAAK,EAAE,mCAAmC;YAC1C,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,KAAK;SACrB;KACF;IAED,YAAY,EAAE;QACZ,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,qCAAqC;QAC5C,WAAW,EACT,gqBAAgqB;QAClqB,WAAW,EAAE;YACX,KAAK,EAAE,qCAAqC;YAC5C,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,KAAK;SACrB;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAmD;IAC5E,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,iBAAiB;IACjB,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
export interface IndexedArtifact {
|
|
3
|
+
artifact_id: string;
|
|
4
|
+
workspace_id: string;
|
|
5
|
+
source_node_id: string;
|
|
6
|
+
author_agent_id: string;
|
|
7
|
+
content_hash: string;
|
|
8
|
+
artifact_type: string;
|
|
9
|
+
visibility: 'public' | 'private';
|
|
10
|
+
domain_pack_ref: string | null;
|
|
11
|
+
title: string;
|
|
12
|
+
summary: string;
|
|
13
|
+
payload_preview: string;
|
|
14
|
+
payload_uri: string;
|
|
15
|
+
environment_version: string;
|
|
16
|
+
environment_lock_hash: string;
|
|
17
|
+
verifier_hash: string;
|
|
18
|
+
semantic_tags: string[];
|
|
19
|
+
reuse_count: number;
|
|
20
|
+
created_at: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ArtifactLineageResult {
|
|
23
|
+
artifact_id: string;
|
|
24
|
+
direct_parents: string[];
|
|
25
|
+
direct_children: string[];
|
|
26
|
+
ancestors: string[];
|
|
27
|
+
descendants: string[];
|
|
28
|
+
depth: number;
|
|
29
|
+
}
|
|
30
|
+
export interface TopReusedOptions {
|
|
31
|
+
workspaceId?: string;
|
|
32
|
+
domain?: string;
|
|
33
|
+
limit?: number;
|
|
34
|
+
agentId?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Looks up artifacts by exact SHA-256 `content_hash`, returning only public artifacts
|
|
38
|
+
* and private artifacts belonging to workspaces where `agentId` is a member.
|
|
39
|
+
*/
|
|
40
|
+
export declare function lookupByContentHash(db: Database.Database, contentHash: string, agentId?: string): IndexedArtifact[];
|
|
41
|
+
/**
|
|
42
|
+
* Traverses transitive ancestors and descendants of an artifact in `artifact_lineage`.
|
|
43
|
+
* Returns `null` if the artifact does not exist or is in a private workspace unauthorized for `agentId`.
|
|
44
|
+
* Private artifacts unauthorized for `agentId` are excluded at every hop of traversal.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getArtifactLineage(db: Database.Database, artifactId: string, agentId?: string): ArtifactLineageResult | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns top reused verified artifacts (strictly excluding `dead_end` records),
|
|
49
|
+
* enforcing private workspace airlock and optional workspace / domain filters.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getTopReusedArtifacts(db: Database.Database, opts?: TopReusedOptions): IndexedArtifact[];
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// src/memo/artifactIndex.ts
|
|
2
|
+
// Content-addressed artifact index, transitive lineage traversal, and top-reused ranking
|
|
3
|
+
// with strict private-workspace airlock enforcement (Epic 1 / E1-1).
|
|
4
|
+
const AIRLOCK_SQL = `(a.visibility = 'public' OR (? IS NOT NULL AND EXISTS (
|
|
5
|
+
SELECT 1 FROM workspace_members wm
|
|
6
|
+
WHERE wm.workspace_id = a.workspace_id AND wm.agent_id = ?
|
|
7
|
+
)))`;
|
|
8
|
+
function mapArtifactRow(row) {
|
|
9
|
+
let tags = [];
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(row.semantic_tags ?? '[]');
|
|
12
|
+
if (Array.isArray(parsed))
|
|
13
|
+
tags = parsed.map(String);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
tags = [];
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
artifact_id: row.id,
|
|
20
|
+
workspace_id: row.workspace_id,
|
|
21
|
+
source_node_id: row.source_node_id,
|
|
22
|
+
author_agent_id: row.author_agent_id,
|
|
23
|
+
content_hash: row.content_hash,
|
|
24
|
+
artifact_type: row.artifact_type,
|
|
25
|
+
visibility: row.visibility,
|
|
26
|
+
domain_pack_ref: row.domain_pack_ref ?? null,
|
|
27
|
+
title: row.title,
|
|
28
|
+
summary: row.summary,
|
|
29
|
+
payload_preview: row.payload_preview,
|
|
30
|
+
payload_uri: row.payload_uri,
|
|
31
|
+
environment_version: row.environment_version,
|
|
32
|
+
environment_lock_hash: row.environment_lock_hash,
|
|
33
|
+
verifier_hash: row.verifier_hash,
|
|
34
|
+
semantic_tags: tags,
|
|
35
|
+
reuse_count: Number(row.reuse_count ?? 0),
|
|
36
|
+
created_at: row.created_at,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Looks up artifacts by exact SHA-256 `content_hash`, returning only public artifacts
|
|
41
|
+
* and private artifacts belonging to workspaces where `agentId` is a member.
|
|
42
|
+
*/
|
|
43
|
+
export function lookupByContentHash(db, contentHash, agentId) {
|
|
44
|
+
const agent = agentId ?? null;
|
|
45
|
+
const rows = db
|
|
46
|
+
.prepare(`
|
|
47
|
+
SELECT a.*
|
|
48
|
+
FROM artifacts a
|
|
49
|
+
WHERE a.content_hash = ?
|
|
50
|
+
AND ${AIRLOCK_SQL}
|
|
51
|
+
ORDER BY a.reuse_count DESC, a.created_at DESC, a.id ASC
|
|
52
|
+
`)
|
|
53
|
+
.all(contentHash, agent, agent);
|
|
54
|
+
return rows.map(mapArtifactRow);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Traverses transitive ancestors and descendants of an artifact in `artifact_lineage`.
|
|
58
|
+
* Returns `null` if the artifact does not exist or is in a private workspace unauthorized for `agentId`.
|
|
59
|
+
* Private artifacts unauthorized for `agentId` are excluded at every hop of traversal.
|
|
60
|
+
*/
|
|
61
|
+
export function getArtifactLineage(db, artifactId, agentId) {
|
|
62
|
+
const agent = agentId ?? null;
|
|
63
|
+
const root = db
|
|
64
|
+
.prepare(`
|
|
65
|
+
SELECT a.id
|
|
66
|
+
FROM artifacts a
|
|
67
|
+
WHERE a.id = ?
|
|
68
|
+
AND ${AIRLOCK_SQL}
|
|
69
|
+
`)
|
|
70
|
+
.get(artifactId, agent, agent);
|
|
71
|
+
if (!root) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const ancRows = db
|
|
75
|
+
.prepare(`
|
|
76
|
+
WITH RECURSIVE anc(id, depth, visited) AS (
|
|
77
|
+
SELECT l.parent_artifact_id, 1, ',' || ? || ',' || l.parent_artifact_id || ','
|
|
78
|
+
FROM artifact_lineage l
|
|
79
|
+
JOIN artifacts a ON a.id = l.parent_artifact_id
|
|
80
|
+
WHERE l.artifact_id = ?
|
|
81
|
+
AND ${AIRLOCK_SQL}
|
|
82
|
+
UNION ALL
|
|
83
|
+
SELECT l.parent_artifact_id, anc.depth + 1, anc.visited || l.parent_artifact_id || ','
|
|
84
|
+
FROM artifact_lineage l
|
|
85
|
+
JOIN anc ON l.artifact_id = anc.id
|
|
86
|
+
JOIN artifacts a ON a.id = l.parent_artifact_id
|
|
87
|
+
WHERE anc.depth < 64
|
|
88
|
+
AND instr(anc.visited, ',' || l.parent_artifact_id || ',') = 0
|
|
89
|
+
AND ${AIRLOCK_SQL}
|
|
90
|
+
)
|
|
91
|
+
SELECT id, MIN(depth) AS min_depth, MAX(depth) AS max_depth
|
|
92
|
+
FROM anc
|
|
93
|
+
GROUP BY id
|
|
94
|
+
ORDER BY min_depth ASC, id ASC
|
|
95
|
+
`)
|
|
96
|
+
.all(artifactId, artifactId, agent, agent, agent, agent);
|
|
97
|
+
const descRows = db
|
|
98
|
+
.prepare(`
|
|
99
|
+
WITH RECURSIVE desc_cte(id, depth, visited) AS (
|
|
100
|
+
SELECT l.artifact_id, 1, ',' || ? || ',' || l.artifact_id || ','
|
|
101
|
+
FROM artifact_lineage l
|
|
102
|
+
JOIN artifacts a ON a.id = l.artifact_id
|
|
103
|
+
WHERE l.parent_artifact_id = ?
|
|
104
|
+
AND ${AIRLOCK_SQL}
|
|
105
|
+
UNION ALL
|
|
106
|
+
SELECT l.artifact_id, desc_cte.depth + 1, desc_cte.visited || l.artifact_id || ','
|
|
107
|
+
FROM artifact_lineage l
|
|
108
|
+
JOIN desc_cte ON l.parent_artifact_id = desc_cte.id
|
|
109
|
+
JOIN artifacts a ON a.id = l.artifact_id
|
|
110
|
+
WHERE desc_cte.depth < 64
|
|
111
|
+
AND instr(desc_cte.visited, ',' || l.artifact_id || ',') = 0
|
|
112
|
+
AND ${AIRLOCK_SQL}
|
|
113
|
+
)
|
|
114
|
+
SELECT id, MIN(depth) AS min_depth
|
|
115
|
+
FROM desc_cte
|
|
116
|
+
GROUP BY id
|
|
117
|
+
ORDER BY min_depth ASC, id ASC
|
|
118
|
+
`)
|
|
119
|
+
.all(artifactId, artifactId, agent, agent, agent, agent);
|
|
120
|
+
const ancestors = ancRows.map((r) => r.id);
|
|
121
|
+
const directParents = ancRows.filter((r) => r.min_depth === 1).map((r) => r.id);
|
|
122
|
+
const descendants = descRows.map((r) => r.id);
|
|
123
|
+
const directChildren = descRows.filter((r) => r.min_depth === 1).map((r) => r.id);
|
|
124
|
+
const depth = ancRows.reduce((max, r) => Math.max(max, Number(r.max_depth ?? 0)), 0);
|
|
125
|
+
return {
|
|
126
|
+
artifact_id: artifactId,
|
|
127
|
+
direct_parents: directParents,
|
|
128
|
+
direct_children: directChildren,
|
|
129
|
+
ancestors,
|
|
130
|
+
descendants,
|
|
131
|
+
depth,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns top reused verified artifacts (strictly excluding `dead_end` records),
|
|
136
|
+
* enforcing private workspace airlock and optional workspace / domain filters.
|
|
137
|
+
*/
|
|
138
|
+
export function getTopReusedArtifacts(db, opts = {}) {
|
|
139
|
+
const agent = opts.agentId ?? null;
|
|
140
|
+
const limit = Math.max(1, Math.min(opts.limit ?? 20, 100));
|
|
141
|
+
const where = [`a.artifact_type <> 'dead_end'`, AIRLOCK_SQL];
|
|
142
|
+
const params = [agent, agent];
|
|
143
|
+
if (opts.workspaceId) {
|
|
144
|
+
where.push('a.workspace_id = ?');
|
|
145
|
+
params.push(opts.workspaceId);
|
|
146
|
+
}
|
|
147
|
+
if (opts.domain) {
|
|
148
|
+
where.push('a.domain_pack_ref LIKE ?');
|
|
149
|
+
params.push(`${opts.domain}%`);
|
|
150
|
+
}
|
|
151
|
+
const rows = db
|
|
152
|
+
.prepare(`
|
|
153
|
+
SELECT a.*
|
|
154
|
+
FROM artifacts a
|
|
155
|
+
WHERE ${where.join(' AND ')}
|
|
156
|
+
ORDER BY a.reuse_count DESC, a.created_at DESC, a.id ASC
|
|
157
|
+
LIMIT ?
|
|
158
|
+
`)
|
|
159
|
+
.all(...params, limit);
|
|
160
|
+
return rows.map(mapArtifactRow);
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=artifactIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifactIndex.js","sourceRoot":"","sources":["../../src/memo/artifactIndex.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,yFAAyF;AACzF,qEAAqE;AAyCrE,MAAM,WAAW,GAAG;;;IA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ACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,IAAI,GAAG,EAAE;SACZ,OAAO,CAAC;;;cAGC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;;;KAG5B,CAAC;SACD,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAU,CAAC;IAElC,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import { type BareGitStore } from '../storage/gitStore.js';
|
|
3
|
+
export interface ResolvedDependencyArtifact {
|
|
4
|
+
artifact_id: string;
|
|
5
|
+
content_hash: string;
|
|
6
|
+
payload_path: string;
|
|
7
|
+
content: string;
|
|
8
|
+
environment_lock_hash: string;
|
|
9
|
+
}
|
|
10
|
+
export type DependencyBundleErrorReason = 'NOT_FOUND' | 'UNAUTHORIZED' | 'LOCK_MISMATCH' | 'DEAD_END_NOT_MOUNTABLE';
|
|
11
|
+
export type DependencyBundleResult = {
|
|
12
|
+
ok: true;
|
|
13
|
+
artifacts: ResolvedDependencyArtifact[];
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
reason: DependencyBundleErrorReason;
|
|
17
|
+
artifactId: string;
|
|
18
|
+
};
|
|
19
|
+
export interface ResolveDependencyBundleOptions {
|
|
20
|
+
artifactIds: string[];
|
|
21
|
+
environmentLockHash: string;
|
|
22
|
+
agentId?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolves a list of upstream `artifactIds` into verified file payloads from `BareGitStore`.
|
|
26
|
+
* Enforces:
|
|
27
|
+
* 1. Artifact existence (`NOT_FOUND`)
|
|
28
|
+
* 2. Private-workspace airlock (`UNAUTHORIZED`)
|
|
29
|
+
* 3. Verified-only mountability (`DEAD_END_NOT_MOUNTABLE`)
|
|
30
|
+
* 4. Pinned toolchain compatibility (`LOCK_MISMATCH`)
|
|
31
|
+
* Deduplicates `artifactIds` while preserving first-seen order.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveDependencyBundle(db: Database.Database, git: BareGitStore, opts: ResolveDependencyBundleOptions): DependencyBundleResult;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/memo/dependencyBundle.ts
|
|
2
|
+
// Verified dependency bundle resolver for auto-mounting `derived_from` parent artifacts
|
|
3
|
+
// with environment-lock, privacy-airlock, and dead-end checks (Epic 1 / E1-2).
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { assertSafeRelPath } from '../storage/gitStore.js';
|
|
6
|
+
function parseGitPayloadUri(uri) {
|
|
7
|
+
const match = /^git:\/\/([^@/]+)@([^/]+)\/(.+)$/.exec(uri);
|
|
8
|
+
if (!match)
|
|
9
|
+
return null;
|
|
10
|
+
const [, slug, ref, rawPath] = match;
|
|
11
|
+
try {
|
|
12
|
+
const relPath = assertSafeRelPath(rawPath);
|
|
13
|
+
return { slug, ref, relPath };
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves a list of upstream `artifactIds` into verified file payloads from `BareGitStore`.
|
|
21
|
+
* Enforces:
|
|
22
|
+
* 1. Artifact existence (`NOT_FOUND`)
|
|
23
|
+
* 2. Private-workspace airlock (`UNAUTHORIZED`)
|
|
24
|
+
* 3. Verified-only mountability (`DEAD_END_NOT_MOUNTABLE`)
|
|
25
|
+
* 4. Pinned toolchain compatibility (`LOCK_MISMATCH`)
|
|
26
|
+
* Deduplicates `artifactIds` while preserving first-seen order.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveDependencyBundle(db, git, opts) {
|
|
29
|
+
const uniqueIds = [];
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (const id of opts.artifactIds) {
|
|
32
|
+
if (!seen.has(id)) {
|
|
33
|
+
seen.add(id);
|
|
34
|
+
uniqueIds.push(id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const artifacts = [];
|
|
38
|
+
const getArtifact = db.prepare(`
|
|
39
|
+
SELECT a.*, w.git_repo_uri, w.slug AS workspace_slug
|
|
40
|
+
FROM artifacts a
|
|
41
|
+
JOIN workspaces w ON w.id = a.workspace_id
|
|
42
|
+
WHERE a.id = ?
|
|
43
|
+
`);
|
|
44
|
+
const checkMember = db.prepare(`
|
|
45
|
+
SELECT 1 FROM workspace_members
|
|
46
|
+
WHERE workspace_id = ? AND agent_id = ?
|
|
47
|
+
`);
|
|
48
|
+
for (const artifactId of uniqueIds) {
|
|
49
|
+
const row = getArtifact.get(artifactId);
|
|
50
|
+
if (!row) {
|
|
51
|
+
return { ok: false, reason: 'NOT_FOUND', artifactId };
|
|
52
|
+
}
|
|
53
|
+
if (row.visibility !== 'public') {
|
|
54
|
+
const authorized = opts.agentId ? Boolean(checkMember.get(row.workspace_id, opts.agentId)) : false;
|
|
55
|
+
if (!authorized) {
|
|
56
|
+
return { ok: false, reason: 'UNAUTHORIZED', artifactId };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (row.artifact_type === 'dead_end') {
|
|
60
|
+
return { ok: false, reason: 'DEAD_END_NOT_MOUNTABLE', artifactId };
|
|
61
|
+
}
|
|
62
|
+
if (row.environment_lock_hash !== opts.environmentLockHash) {
|
|
63
|
+
return { ok: false, reason: 'LOCK_MISMATCH', artifactId };
|
|
64
|
+
}
|
|
65
|
+
const parsed = parseGitPayloadUri(String(row.payload_uri ?? ''));
|
|
66
|
+
if (!parsed) {
|
|
67
|
+
return { ok: false, reason: 'NOT_FOUND', artifactId };
|
|
68
|
+
}
|
|
69
|
+
const repoDir = row.git_repo_uri && fs.existsSync(row.git_repo_uri)
|
|
70
|
+
? row.git_repo_uri
|
|
71
|
+
: git.repoPath(parsed.slug);
|
|
72
|
+
const content = git.readFileAtCommit(repoDir, parsed.ref, parsed.relPath);
|
|
73
|
+
if (content === null) {
|
|
74
|
+
return { ok: false, reason: 'NOT_FOUND', artifactId };
|
|
75
|
+
}
|
|
76
|
+
artifacts.push({
|
|
77
|
+
artifact_id: row.id,
|
|
78
|
+
content_hash: row.content_hash,
|
|
79
|
+
payload_path: parsed.relPath,
|
|
80
|
+
content,
|
|
81
|
+
environment_lock_hash: row.environment_lock_hash,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return { ok: true, artifacts };
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=dependencyBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencyBundle.js","sourceRoot":"","sources":["../../src/memo/dependencyBundle.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,wFAAwF;AACxF,+EAA+E;AAE/E,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAqB,MAAM,wBAAwB,CAAC;AAiC9E,SAAS,kBAAkB,CAAC,GAAW;IACrC,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3C,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,EAAqB,EACrB,GAAiB,EACjB,IAAoC;IAEpC,MAA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|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import { type StorageAdapter } from '../db/adapter.js';
|
|
3
|
+
export declare const DEFAULT_EMBEDDING_DIM = 384;
|
|
4
|
+
export interface EmbeddingProvider {
|
|
5
|
+
readonly modelId: string;
|
|
6
|
+
readonly dimensions: number;
|
|
7
|
+
embed(text: string): Promise<Float32Array>;
|
|
8
|
+
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
9
|
+
/** Optional synchronous embedding fast-path (implemented by local deterministic provider). */
|
|
10
|
+
embedSync?(text: string): Float32Array;
|
|
11
|
+
}
|
|
12
|
+
export declare function normalizeVector(vec: Float32Array): Float32Array;
|
|
13
|
+
export declare function cosineSimilarity(a: Float32Array, b: Float32Array): number;
|
|
14
|
+
/**
|
|
15
|
+
* Splits mathematical, Lean 4, and code identifiers (`Nat.Prime`, `riemannZeta`, `upper_bound`)
|
|
16
|
+
* into normalized lowercase tokens.
|
|
17
|
+
*/
|
|
18
|
+
export declare function tokenizeSemanticText(text: string): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Deterministic offline semantic embedder (384 dimensions).
|
|
21
|
+
* Combines token unigrams, phrase bigrams, subword character n-grams, and mathematical/engineering
|
|
22
|
+
* concept clusters into an L2-normalized dense unit vector. Zero external network dependency.
|
|
23
|
+
*/
|
|
24
|
+
export declare class LocalSemanticEmbeddingProvider implements EmbeddingProvider {
|
|
25
|
+
readonly modelId: string;
|
|
26
|
+
readonly dimensions: number;
|
|
27
|
+
constructor(dimensions?: number, modelId?: string);
|
|
28
|
+
embedSync(text: string): Float32Array;
|
|
29
|
+
embed(text: string): Promise<Float32Array>;
|
|
30
|
+
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
31
|
+
}
|
|
32
|
+
export interface HttpEmbeddingConfig {
|
|
33
|
+
apiUrl: string;
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
modelId: string;
|
|
36
|
+
dimensions?: number;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* OpenAI-compatible HTTP Embedding provider (works with OpenAI, Voyage, Ollama, vLLM, TEI).
|
|
41
|
+
*/
|
|
42
|
+
export declare class HttpEmbeddingProvider implements EmbeddingProvider {
|
|
43
|
+
readonly modelId: string;
|
|
44
|
+
readonly dimensions: number;
|
|
45
|
+
private readonly apiUrl;
|
|
46
|
+
private readonly apiKey?;
|
|
47
|
+
private readonly timeoutMs;
|
|
48
|
+
constructor(cfg: HttpEmbeddingConfig);
|
|
49
|
+
embed(text: string): Promise<Float32Array>;
|
|
50
|
+
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
51
|
+
}
|
|
52
|
+
export declare function createDefaultEmbeddingProvider(): EmbeddingProvider;
|
|
53
|
+
export declare function buildArtifactEmbeddingText(artifact: {
|
|
54
|
+
title?: string | null;
|
|
55
|
+
summary?: string | null;
|
|
56
|
+
artifact_type?: string | null;
|
|
57
|
+
domain_pack_ref?: string | null;
|
|
58
|
+
semantic_tags?: string | string[] | null;
|
|
59
|
+
payload_preview?: string | null;
|
|
60
|
+
}): string;
|
|
61
|
+
/**
|
|
62
|
+
* Synchronously computes and upserts an embedding for a single SQLite artifact (verified or dead end).
|
|
63
|
+
* Safe no-op if `artifact_embeddings` table is not present on a legacy DB.
|
|
64
|
+
*/
|
|
65
|
+
export declare function indexArtifactEmbeddingSync(db: Database.Database, artifactId: string, provider?: LocalSemanticEmbeddingProvider): boolean;
|
|
66
|
+
/** Backfills embeddings for all unindexed artifacts (verified + dead ends) in SQLite. */
|
|
67
|
+
export declare function backfillArtifactEmbeddingsSync(db: Database.Database, provider?: LocalSemanticEmbeddingProvider): number;
|
|
68
|
+
/** Async embedding indexer working across both SQLite and PostgreSQL + pgvector via `StorageAdapter`. */
|
|
69
|
+
export declare function indexArtifactEmbedding(adapter: StorageAdapter, artifactId: string, provider?: EmbeddingProvider): Promise<boolean>;
|
|
70
|
+
/** Async backfill for all unindexed artifacts (verified + dead ends) via `StorageAdapter`. */
|
|
71
|
+
export declare function backfillArtifactEmbeddings(adapter: StorageAdapter, provider?: EmbeddingProvider): Promise<number>;
|
|
72
|
+
export type HybridSearchMode = 'hybrid' | 'lexical' | 'semantic';
|
|
73
|
+
export interface HybridSearchOptions {
|
|
74
|
+
query: string;
|
|
75
|
+
agentId: string;
|
|
76
|
+
workspaceId?: string;
|
|
77
|
+
domain?: string;
|
|
78
|
+
environmentVersion?: string;
|
|
79
|
+
environmentLockHash?: string;
|
|
80
|
+
includeDeadEnds?: boolean;
|
|
81
|
+
artifactTypes?: string[];
|
|
82
|
+
tags?: string[];
|
|
83
|
+
searchMode?: HybridSearchMode;
|
|
84
|
+
minSemanticScore?: number;
|
|
85
|
+
rrfK?: number;
|
|
86
|
+
semanticWeight?: number;
|
|
87
|
+
lexicalWeight?: number;
|
|
88
|
+
autoIndex?: boolean;
|
|
89
|
+
provider?: LocalSemanticEmbeddingProvider;
|
|
90
|
+
}
|
|
91
|
+
export interface HybridSearchHit {
|
|
92
|
+
row: any;
|
|
93
|
+
relevance_score: number;
|
|
94
|
+
lexical_score: number;
|
|
95
|
+
semantic_score: number;
|
|
96
|
+
match_source: 'hybrid' | 'lexical' | 'semantic';
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Synchronous Hybrid Search (FTS5 BM25 + Vector Cosine RRF) for SQLite control plane (`query_cache` v2).
|
|
100
|
+
* Enforces strict private-workspace airlock, domain, environment_version, environment_lock_hash,
|
|
101
|
+
* dead-end toggle, artifact_types, and semantic_tags filters.
|
|
102
|
+
*/
|
|
103
|
+
export declare function hybridSearchArtifactsSync(db: Database.Database, opts: HybridSearchOptions): HybridSearchHit[];
|
|
104
|
+
/**
|
|
105
|
+
* Async Hybrid Search across both SQLite and PostgreSQL + pgvector via `StorageAdapter`.
|
|
106
|
+
* On PostgreSQL, combines `ts_rank_cd(search_tsv, plainto_tsquery(...))` with `pgvector` `<=>` cosine search.
|
|
107
|
+
*/
|
|
108
|
+
export declare function hybridSearchArtifactsAsync(adapter: StorageAdapter, opts: Omit<HybridSearchOptions, 'provider'> & {
|
|
109
|
+
provider?: EmbeddingProvider;
|
|
110
|
+
}): Promise<HybridSearchHit[]>;
|