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.
Files changed (203) hide show
  1. package/README.math-mvp.md +28 -0
  2. package/README.md +37 -2
  3. package/dist/admin/adminRoutes.d.ts +10 -0
  4. package/dist/admin/adminRoutes.js +194 -0
  5. package/dist/admin/adminRoutes.js.map +1 -0
  6. package/dist/admin/index.d.ts +2 -0
  7. package/dist/admin/index.js +4 -0
  8. package/dist/admin/index.js.map +1 -0
  9. package/dist/admin/workspaceAdmin.d.ts +417 -0
  10. package/dist/admin/workspaceAdmin.js +569 -0
  11. package/dist/admin/workspaceAdmin.js.map +1 -0
  12. package/dist/analytics/index.d.ts +1 -0
  13. package/dist/analytics/index.js +3 -0
  14. package/dist/analytics/index.js.map +1 -0
  15. package/dist/analytics/metrics.d.ts +105 -0
  16. package/dist/analytics/metrics.js +837 -0
  17. package/dist/analytics/metrics.js.map +1 -0
  18. package/dist/audit/index.d.ts +4 -0
  19. package/dist/audit/index.js +6 -0
  20. package/dist/audit/index.js.map +1 -0
  21. package/dist/audit/pipeline.d.ts +90 -0
  22. package/dist/audit/pipeline.js +424 -0
  23. package/dist/audit/pipeline.js.map +1 -0
  24. package/dist/audit/receiptSchema.d.ts +441 -0
  25. package/dist/audit/receiptSchema.js +208 -0
  26. package/dist/audit/receiptSchema.js.map +1 -0
  27. package/dist/audit/stageA.d.ts +50 -0
  28. package/dist/audit/stageA.js +218 -0
  29. package/dist/audit/stageA.js.map +1 -0
  30. package/dist/audit/stageB.d.ts +48 -0
  31. package/dist/audit/stageB.js +113 -0
  32. package/dist/audit/stageB.js.map +1 -0
  33. package/dist/auth/agentAuth.d.ts +18 -0
  34. package/dist/auth/agentAuth.js +59 -0
  35. package/dist/auth/agentAuth.js.map +1 -0
  36. package/dist/auth/agentCardSigner.d.ts +55 -0
  37. package/dist/auth/agentCardSigner.js +188 -0
  38. package/dist/auth/agentCardSigner.js.map +1 -0
  39. package/dist/billing/billingRoutes.d.ts +11 -0
  40. package/dist/billing/billingRoutes.js +303 -0
  41. package/dist/billing/billingRoutes.js.map +1 -0
  42. package/dist/billing/bountyRoutes.d.ts +9 -0
  43. package/dist/billing/bountyRoutes.js +332 -0
  44. package/dist/billing/bountyRoutes.js.map +1 -0
  45. package/dist/billing/index.d.ts +3 -0
  46. package/dist/billing/index.js +4 -0
  47. package/dist/billing/index.js.map +1 -0
  48. package/dist/billing/subscriptions.d.ts +226 -0
  49. package/dist/billing/subscriptions.js +673 -0
  50. package/dist/billing/subscriptions.js.map +1 -0
  51. package/dist/cli/caissonCli.d.ts +10 -0
  52. package/dist/cli/caissonCli.js +471 -0
  53. package/dist/cli/caissonCli.js.map +1 -0
  54. package/dist/cli/inviteCard.d.ts +12 -0
  55. package/dist/cli/inviteCard.js +49 -0
  56. package/dist/cli/inviteCard.js.map +1 -0
  57. package/dist/cli/mcpProxy.d.ts +36 -0
  58. package/dist/cli/mcpProxy.js +292 -0
  59. package/dist/cli/mcpProxy.js.map +1 -0
  60. package/dist/config.d.ts +19 -0
  61. package/dist/config.js +28 -0
  62. package/dist/config.js.map +1 -0
  63. package/dist/db/adapter.d.ts +210 -0
  64. package/dist/db/adapter.js +769 -0
  65. package/dist/db/adapter.js.map +1 -0
  66. package/dist/db/sqlite.d.ts +7 -0
  67. package/dist/db/sqlite.js +60 -0
  68. package/dist/db/sqlite.js.map +1 -0
  69. package/dist/db/telemetry.d.ts +11 -0
  70. package/dist/db/telemetry.js +9 -0
  71. package/dist/db/telemetry.js.map +1 -0
  72. package/dist/economy/bountyEngine.d.ts +248 -0
  73. package/dist/economy/bountyEngine.js +836 -0
  74. package/dist/economy/bountyEngine.js.map +1 -0
  75. package/dist/economy/index.d.ts +5 -0
  76. package/dist/economy/index.js +6 -0
  77. package/dist/economy/index.js.map +1 -0
  78. package/dist/economy/scLedger.d.ts +183 -0
  79. package/dist/economy/scLedger.js +528 -0
  80. package/dist/economy/scLedger.js.map +1 -0
  81. package/dist/economy/scMinting.d.ts +177 -0
  82. package/dist/economy/scMinting.js +659 -0
  83. package/dist/economy/scMinting.js.map +1 -0
  84. package/dist/economy/scSinks.d.ts +135 -0
  85. package/dist/economy/scSinks.js +314 -0
  86. package/dist/economy/scSinks.js.map +1 -0
  87. package/dist/economy/usdLedger.d.ts +211 -0
  88. package/dist/economy/usdLedger.js +604 -0
  89. package/dist/economy/usdLedger.js.map +1 -0
  90. package/dist/mcp/handlers.d.ts +134 -0
  91. package/dist/mcp/handlers.js +781 -0
  92. package/dist/mcp/handlers.js.map +1 -0
  93. package/dist/mcp/httpServer.d.ts +25 -0
  94. package/dist/mcp/httpServer.js +368 -0
  95. package/dist/mcp/httpServer.js.map +1 -0
  96. package/dist/mcp/serverFactory.d.ts +4 -0
  97. package/dist/mcp/serverFactory.js +53 -0
  98. package/dist/mcp/serverFactory.js.map +1 -0
  99. package/dist/mcp/stdioServer.d.ts +2 -0
  100. package/dist/mcp/stdioServer.js +24 -0
  101. package/dist/mcp/stdioServer.js.map +1 -0
  102. package/dist/mcp/toolMetadata.d.ts +15 -0
  103. package/dist/mcp/toolMetadata.js +73 -0
  104. package/dist/mcp/toolMetadata.js.map +1 -0
  105. package/dist/memo/artifactIndex.d.ts +51 -0
  106. package/dist/memo/artifactIndex.js +162 -0
  107. package/dist/memo/artifactIndex.js.map +1 -0
  108. package/dist/memo/dependencyBundle.d.ts +33 -0
  109. package/dist/memo/dependencyBundle.js +86 -0
  110. package/dist/memo/dependencyBundle.js.map +1 -0
  111. package/dist/memo/embeddings.d.ts +110 -0
  112. package/dist/memo/embeddings.js +672 -0
  113. package/dist/memo/embeddings.js.map +1 -0
  114. package/dist/packs/foundryEvm.d.ts +21 -0
  115. package/dist/packs/foundryEvm.js +274 -0
  116. package/dist/packs/foundryEvm.js.map +1 -0
  117. package/dist/packs/index.d.ts +8 -0
  118. package/dist/packs/index.js +19 -0
  119. package/dist/packs/index.js.map +1 -0
  120. package/dist/packs/mathLean4.d.ts +7 -0
  121. package/dist/packs/mathLean4.js +145 -0
  122. package/dist/packs/mathLean4.js.map +1 -0
  123. package/dist/packs/rustKani.d.ts +17 -0
  124. package/dist/packs/rustKani.js +257 -0
  125. package/dist/packs/rustKani.js.map +1 -0
  126. package/dist/packs/sdk.d.ts +314 -0
  127. package/dist/packs/sdk.js +271 -0
  128. package/dist/packs/sdk.js.map +1 -0
  129. package/dist/preflight/leanTripwire.d.ts +19 -0
  130. package/dist/preflight/leanTripwire.js +105 -0
  131. package/dist/preflight/leanTripwire.js.map +1 -0
  132. package/dist/storage/blobStore.d.ts +11 -0
  133. package/dist/storage/blobStore.js +39 -0
  134. package/dist/storage/blobStore.js.map +1 -0
  135. package/dist/storage/gitStore.d.ts +68 -0
  136. package/dist/storage/gitStore.js +228 -0
  137. package/dist/storage/gitStore.js.map +1 -0
  138. package/dist/types/errors.d.ts +16 -0
  139. package/dist/types/errors.js +23 -0
  140. package/dist/types/errors.js.map +1 -0
  141. package/dist/types/schemas.d.ts +453 -0
  142. package/dist/types/schemas.js +197 -0
  143. package/dist/types/schemas.js.map +1 -0
  144. package/dist/web/discoveryRoutes.d.ts +20 -0
  145. package/dist/web/discoveryRoutes.js +456 -0
  146. package/dist/web/discoveryRoutes.js.map +1 -0
  147. package/dist/web/explorer/dagLayout.d.ts +41 -0
  148. package/dist/web/explorer/dagLayout.js +183 -0
  149. package/dist/web/explorer/dagLayout.js.map +1 -0
  150. package/dist/web/explorer/index.d.ts +45 -0
  151. package/dist/web/explorer/index.js +512 -0
  152. package/dist/web/explorer/index.js.map +1 -0
  153. package/dist/web/explorer/renderers.d.ts +35 -0
  154. package/dist/web/explorer/renderers.js +397 -0
  155. package/dist/web/explorer/renderers.js.map +1 -0
  156. package/dist/web/repoBrowser.d.ts +19 -0
  157. package/dist/web/repoBrowser.js +128 -0
  158. package/dist/web/repoBrowser.js.map +1 -0
  159. package/dist/worker/executionAdapter.d.ts +14 -0
  160. package/dist/worker/executionAdapter.js +162 -0
  161. package/dist/worker/executionAdapter.js.map +1 -0
  162. package/dist/worker/finalize.d.ts +21 -0
  163. package/dist/worker/finalize.js +146 -0
  164. package/dist/worker/finalize.js.map +1 -0
  165. package/dist/worker/firecrackerAdapter.d.ts +180 -0
  166. package/dist/worker/firecrackerAdapter.js +421 -0
  167. package/dist/worker/firecrackerAdapter.js.map +1 -0
  168. package/dist/worker/loop.d.ts +56 -0
  169. package/dist/worker/loop.js +239 -0
  170. package/dist/worker/loop.js.map +1 -0
  171. package/dist/worker/postMergeSync.d.ts +17 -0
  172. package/dist/worker/postMergeSync.js +52 -0
  173. package/dist/worker/postMergeSync.js.map +1 -0
  174. package/dist/worker/prepareInput.d.ts +41 -0
  175. package/dist/worker/prepareInput.js +130 -0
  176. package/dist/worker/prepareInput.js.map +1 -0
  177. package/dist/worker/queue.d.ts +83 -0
  178. package/dist/worker/queue.js +278 -0
  179. package/dist/worker/queue.js.map +1 -0
  180. package/dist/worker/sandbox.d.ts +2 -0
  181. package/dist/worker/sandbox.js +3 -0
  182. package/dist/worker/sandbox.js.map +1 -0
  183. package/dist/worker/webhook.d.ts +14 -0
  184. package/dist/worker/webhook.js +110 -0
  185. package/dist/worker/webhook.js.map +1 -0
  186. package/migrations/001_init.sql +193 -0
  187. package/migrations/002_epic3_scale.sql +34 -0
  188. package/migrations/003_swarm_credits.sql +153 -0
  189. package/migrations/004_usd_bounties.sql +216 -0
  190. package/migrations_pg/001_init.sql +229 -0
  191. package/migrations_pg/002_multitenant_rls.sql +63 -0
  192. package/migrations_pg/003_swarm_credits.sql +135 -0
  193. package/migrations_pg/004_usd_bounties.sql +201 -0
  194. package/package.json +55 -4
  195. package/packs/foundry-evm/pack.json +60 -0
  196. package/packs/foundry-evm/verifier/Dockerfile +9 -0
  197. package/packs/foundry-evm/verifier/run.py +160 -0
  198. package/packs/math-lean4/pack.json +68 -0
  199. package/packs/rust-kani/pack.json +53 -0
  200. package/packs/rust-kani/verifier/Dockerfile +7 -0
  201. package/packs/rust-kani/verifier/run.py +159 -0
  202. package/public/.well-known/agent-card.json +153 -0
  203. package/public/llms.txt +35 -0
@@ -0,0 +1,211 @@
1
+ import type Database from 'better-sqlite3';
2
+ /** Integer cent scale: 1 USD = 100 cents (exact integer arithmetic, zero float drift). */
3
+ export declare const USD_CENTS_PER_DOLLAR = 100;
4
+ /** Default human funding bounds: $1.00 min, $1,000,000.00 max per deposit. */
5
+ export declare const MIN_USD_DEPOSIT_CENTS = 100;
6
+ export declare const MAX_USD_DEPOSIT_CENTS = 100000000;
7
+ export declare const USD_SYSTEM_FUNDING_ACCOUNT = "usd_sys:stripe_funding";
8
+ export declare const USD_SYSTEM_REVENUE_ACCOUNT = "usd_sys:platform_revenue";
9
+ export declare const USD_SYSTEM_SLASH_POOL_ACCOUNT = "usd_sys:slash_pool";
10
+ export declare const USD_SYSTEM_PAYOUT_ACCOUNT = "usd_sys:payout_clearing";
11
+ export type UsdAccountType = 'operator' | 'bounty_escrow' | 'stake_escrow' | 'system_funding' | 'system_revenue' | 'system_slash_pool' | 'system_payout';
12
+ export type UsdEntryType = 'stripe_deposit' | 'sponsor_funding' | 'bounty_escrow_lock' | 'bounty_escrow_refund' | 'bounty_settlement' | 'stake_lock' | 'stake_refund' | 'stake_slash' | 'payout_withdrawal';
13
+ export type UsdFundingSource = 'stripe_checkout' | 'sponsor_grant' | 'wire_transfer';
14
+ export interface UsdAccountRecord {
15
+ account_id: string;
16
+ account_type: UsdAccountType;
17
+ operator_id: string | null;
18
+ currency: 'USD';
19
+ balance_cents: number;
20
+ balance_usd: number;
21
+ lifetime_funded_cents: number;
22
+ lifetime_earned_cents: number;
23
+ created_at: string;
24
+ updated_at: string;
25
+ }
26
+ export interface UsdLedgerLegInput {
27
+ accountId: string;
28
+ deltaCents: number;
29
+ /** Optional accounting flags for operator lifetime totals. */
30
+ countAsFunded?: boolean;
31
+ countAsEarned?: boolean;
32
+ }
33
+ export interface UsdLedgerLineRecord {
34
+ id: string;
35
+ entry_id: string;
36
+ account_id: string;
37
+ delta_cents: number;
38
+ delta_usd: number;
39
+ balance_after_cents: number;
40
+ balance_after_usd: number;
41
+ created_at: string;
42
+ }
43
+ export interface UsdJournalEntryRecord {
44
+ id: string;
45
+ idempotency_key: string | null;
46
+ entry_type: UsdEntryType;
47
+ currency: 'USD';
48
+ workspace_id: string | null;
49
+ bounty_id: string | null;
50
+ reference_type: string | null;
51
+ reference_id: string | null;
52
+ memo: string;
53
+ metadata: Record<string, unknown>;
54
+ created_at: string;
55
+ lines: UsdLedgerLineRecord[];
56
+ }
57
+ export interface UsdLedgerIntegrityReport {
58
+ ok: boolean;
59
+ currency: 'USD';
60
+ firewall_intact: boolean;
61
+ total_accounts: number;
62
+ total_entries: number;
63
+ total_lines: number;
64
+ trial_balance_cents: number;
65
+ total_funded_cents: number;
66
+ total_funded_usd: number;
67
+ operator_balances_cents: number;
68
+ operator_balances_usd: number;
69
+ escrowed_bounties_cents: number;
70
+ escrowed_bounties_usd: number;
71
+ locked_stakes_cents: number;
72
+ locked_stakes_usd: number;
73
+ platform_revenue_cents: number;
74
+ platform_revenue_usd: number;
75
+ slash_pool_cents: number;
76
+ slash_pool_usd: number;
77
+ payout_clearing_cents: number;
78
+ payout_clearing_usd: number;
79
+ violations: string[];
80
+ }
81
+ export interface AgentSpendCapStatus {
82
+ agent_id: string;
83
+ operator_id: string;
84
+ per_task_spend_cap_cents: number;
85
+ per_task_spend_cap_usd: number;
86
+ task_key?: string;
87
+ task_spent_cents?: number;
88
+ task_remaining_cents?: number;
89
+ }
90
+ /** Converts a decimal USD dollar amount to exact integer cents (`1 USD = 100 cents`). */
91
+ export declare function usdToCents(usd: number): number;
92
+ /** Converts integer cents to a decimal USD amount (2 decimal places). */
93
+ export declare function centsToUsd(cents: number): number;
94
+ /** Canonical USD account ID for a human operator. */
95
+ export declare function usdOperatorAccountId(operatorId: string): string;
96
+ /** Canonical USD account ID for a bounty escrow hold. */
97
+ export declare function usdBountyEscrowAccountId(bountyId: string): string;
98
+ /** Canonical USD account ID for an anti-slop submission stake hold. */
99
+ export declare function usdStakeEscrowAccountId(stakeId: string): string;
100
+ /**
101
+ * Dual-Ledger Firewall guard (USD side): permanently blocks any non-USD currency,
102
+ * Swarm Credit account prefix, or SC↔USD conversion reference.
103
+ */
104
+ export declare function assertUsdLedgerFirewall(currency?: string, accountId?: string, referenceType?: string | null, actionDescription?: string): void;
105
+ /** Explicitly rejects any attempt to convert USD Prepaid Credits into Swarm Credits (or vice versa). */
106
+ export declare function rejectScToUsdConversion(): never;
107
+ /** Ensures all four USD system contra accounts exist idempotently. */
108
+ export declare function ensureUsdSystemAccounts(db: Database.Database, now?: string): void;
109
+ /** Idempotently creates or retrieves an operator's Prepaid USD account. */
110
+ export declare function ensureUsdOperatorAccount(db: Database.Database, operatorId: string, opts?: {
111
+ now?: string;
112
+ }): UsdAccountRecord;
113
+ /** Idempotently creates or retrieves a bounty escrow USD account. */
114
+ export declare function ensureUsdBountyEscrowAccount(db: Database.Database, bountyId: string, opts?: {
115
+ now?: string;
116
+ }): UsdAccountRecord;
117
+ /** Idempotently creates or retrieves an anti-slop stake escrow USD account. */
118
+ export declare function ensureUsdStakeEscrowAccount(db: Database.Database, stakeId: string, opts?: {
119
+ now?: string;
120
+ }): UsdAccountRecord;
121
+ /** Returns an operator's Prepaid USD account (materializing a read-only zero view if not yet created). */
122
+ export declare function getUsdOperatorAccount(db: Database.Database, operatorId: string): UsdAccountRecord;
123
+ /** Returns an operator's current Prepaid USD balance in integer cents and decimal dollars. */
124
+ export declare function getUsdOperatorBalance(db: Database.Database, operatorId: string): {
125
+ operator_id: string;
126
+ currency: 'USD';
127
+ balance_cents: number;
128
+ balance_usd: number;
129
+ };
130
+ /**
131
+ * Posts an atomic double-entry USD journal transaction into the immutable USD ledger.
132
+ * Enforces:
133
+ * - Strict zero-sum across all legs (`sum(deltaCents) === 0`)
134
+ * - Hard Dual-Ledger Firewall (`currency === 'USD'`, `usd_*` account namespace, no SC refs)
135
+ * - Non-negative balance on all `operator`, `bounty_escrow`, and `stake_escrow` accounts
136
+ * - Idempotency via `idempotencyKey`
137
+ */
138
+ export declare function postUsdJournalEntry(db: Database.Database, params: {
139
+ entryType: UsdEntryType;
140
+ currency?: string;
141
+ workspaceId?: string | null;
142
+ bountyId?: string | null;
143
+ referenceType?: string | null;
144
+ referenceId?: string | null;
145
+ memo?: string;
146
+ metadata?: Record<string, unknown>;
147
+ idempotencyKey?: string | null;
148
+ legs: UsdLedgerLegInput[];
149
+ now?: string;
150
+ }): UsdJournalEntryRecord;
151
+ /**
152
+ * Credits a human-funded USD deposit into an operator's Prepaid USD account.
153
+ * Strictly prohibits Swarm Credit funding sources (Dual-Ledger Firewall).
154
+ */
155
+ export declare function depositUsdCredits(db: Database.Database, params: {
156
+ operatorId: string;
157
+ amountCents: number;
158
+ fundingSource: UsdFundingSource;
159
+ currency?: string;
160
+ stripeSessionId?: string | null;
161
+ stripePaymentIntentId?: string | null;
162
+ memo?: string;
163
+ metadata?: Record<string, unknown>;
164
+ idempotencyKey?: string;
165
+ now?: string;
166
+ }): UsdJournalEntryRecord;
167
+ /**
168
+ * Initiates a USD payout/withdrawal from an operator's earned/prepaid USD balance to payout clearing.
169
+ */
170
+ export declare function requestUsdPayout(db: Database.Database, params: {
171
+ operatorId: string;
172
+ amountCents: number;
173
+ destinationRef?: string;
174
+ memo?: string;
175
+ idempotencyKey?: string;
176
+ now?: string;
177
+ }): UsdJournalEntryRecord;
178
+ /** Sets a scoped agent's `per_task_spend_cap` (in integer USD cents). */
179
+ export declare function setAgentSpendCap(db: Database.Database, agentId: string, perTaskSpendCapCents: number): AgentSpendCapStatus;
180
+ /** Reads a scoped agent's `per_task_spend_cap` and optional cumulative spend for a specific task key. */
181
+ export declare function getAgentSpendCapStatus(db: Database.Database, agentId: string, taskKey?: string): AgentSpendCapStatus;
182
+ /**
183
+ * Enforces `agent_identities.per_task_spend_cap` before a scoped agent commits USD funds
184
+ * (for funding a bounty or posting an anti-slop submission stake).
185
+ * Tracks cumulative spend per `(agent_id, task_key)` to prevent split-spend cap bypasses.
186
+ */
187
+ export declare function assertAndRecordAgentTaskSpend(db: Database.Database, params: {
188
+ agentId: string;
189
+ taskKey: string;
190
+ amountCents: number;
191
+ now?: string;
192
+ record?: boolean;
193
+ }): AgentSpendCapStatus;
194
+ /** Releases previously reserved per-task spend when a refundable hold (e.g., passing stake or canceled bounty) returns. */
195
+ export declare function releaseAgentTaskSpend(db: Database.Database, params: {
196
+ agentId: string;
197
+ taskKey: string;
198
+ amountCents: number;
199
+ now?: string;
200
+ }): void;
201
+ /** Lists recent USD journal entries affecting a specific operator (newest first). */
202
+ export declare function listOperatorUsdLedgerEntries(db: Database.Database, operatorId: string, limit?: number): UsdJournalEntryRecord[];
203
+ /**
204
+ * Audits full USD double-entry ledger integrity & Dual-Ledger Firewall isolation:
205
+ * - Every USD journal entry sums to 0 cents with >= 2 legs
206
+ * - Every USD account's stored `balance_cents` equals the exact sum of its immutable lines
207
+ * - Global trial balance across all USD accounts equals 0 cents
208
+ * - No operator, bounty_escrow, or stake_escrow account has negative balance
209
+ * - Zero SC accounts or non-USD currencies exist anywhere in USD ledger tables
210
+ */
211
+ export declare function verifyUsdLedgerIntegrity(db: Database.Database): UsdLedgerIntegrityReport;